Просмотр исходного кода

Moved generic emulated functions to mhd_compat.h/.c, removed "platform" dir,
removed "w32functions.h/.c"

Evgeny Grin (Karlson2k) 9 лет назад
Родитель
Сommit
47bfec25d8

+ 0 - 1
configure.ac

@@ -1076,7 +1076,6 @@ doc/examples/Makefile
 m4/Makefile
 src/Makefile
 src/include/Makefile
-src/platform/Makefile
 src/microhttpd/Makefile
 src/examples/Makefile
 src/testcurl/Makefile

+ 1 - 1
src/Makefile.am

@@ -8,7 +8,7 @@ endif
 endif
 endif
 
-SUBDIRS = include platform microhttpd $(curltests) $(zzuftests) .
+SUBDIRS = include microhttpd $(curltests) $(zzuftests) .
 
 if BUILD_EXAMPLES
 SUBDIRS += examples

+ 1 - 1
src/include/Makefile.am

@@ -3,4 +3,4 @@ SUBDIRS = .
 
 include_HEADERS = microhttpd.h 
 
-EXTRA_DIST = platform.h platform_interface.h w32functions.h autoinit_funcs.h
+EXTRA_DIST = platform.h autoinit_funcs.h

+ 0 - 55
src/include/w32functions.h

@@ -1,55 +0,0 @@
-/*
-  This file is part of libmicrohttpd
-  Copyright (C) 2014 Karlson2k (Evgeny Grin)
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library.
-  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file include/w32functions.h
- * @brief  internal functions for W32 systems
- * @author Karlson2k (Evgeny Grin)
- */
-
-#ifndef MHD_W32FUNCTIONS_H
-#define MHD_W32FUNCTIONS_H
-#ifndef _WIN32
-#error w32functions.h is designed only for W32 systems
-#endif
-
-#include "platform.h"
-#include <errno.h>
-#include <winsock2.h>
-#include "platform_interface.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * Generate 31-bit pseudo random number.
- * Function initialize itself at first call to current time.
- * @return 31-bit pseudo random number.
- */
-int MHD_W32_random_(void);
-
-/* Emulate snprintf function on W32 */
-int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* MHD_W32FUNCTIONS_H */

+ 6 - 13
src/microhttpd/Makefile.am

@@ -5,10 +5,6 @@ AM_CPPFLAGS = \
 
 AM_CFLAGS = $(HIDDEN_VISIBILITY_CFLAGS)
 
-if HAVE_W32
-MHD_W32_LIB = $(top_builddir)/src/platform/libplatform_interface.la
-endif
-
 lib_LTLIBRARIES = \
   libmicrohttpd.la
 
@@ -71,6 +67,7 @@ libmicrohttpd_la_SOURCES = \
   mhd_locks.h \
   mhd_sockets.c mhd_sockets.h \
   mhd_itc.c mhd_itc.h \
+  mhd_compat.c mhd_compat.h \
   response.c response.h
 libmicrohttpd_la_CPPFLAGS = \
   $(AM_CPPFLAGS) $(MHD_LIB_CPPFLAGS) \
@@ -82,9 +79,7 @@ libmicrohttpd_la_LDFLAGS = \
   $(W32_MHD_LIB_LDFLAGS) \
   -version-info @LIB_VERSION_CURRENT@:@LIB_VERSION_REVISION@:@LIB_VERSION_AGE@
 libmicrohttpd_la_LIBADD = \
-  $(MHD_W32_LIB) $(MHD_LIBDEPS)
-libmicrohttpd_la_DEPENDENCIES = \
-  $(MHD_W32_LIB)
+  $(MHD_LIBDEPS)
 
 if HAVE_W32
 MHD_DLL_RES_SRC = microhttpd_dll_res.rc
@@ -172,12 +167,11 @@ test_daemon_LDADD = \
   $(top_builddir)/src/microhttpd/libmicrohttpd.la
 
 test_postprocessor_SOURCES = \
-  test_postprocessor.c
+  test_postprocessor.c mhd_compat.c
 test_postprocessor_CPPFLAGS = \
   $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS)
 test_postprocessor_LDADD = \
-  $(top_builddir)/src/microhttpd/libmicrohttpd.la \
-  $(MHD_W32_LIB)
+  $(top_builddir)/src/microhttpd/libmicrohttpd.la
 
 test_postprocessor_amp_SOURCES = \
   test_postprocessor_amp.c
@@ -187,12 +181,11 @@ test_postprocessor_amp_LDADD = \
   $(top_builddir)/src/microhttpd/libmicrohttpd.la
 
 test_postprocessor_large_SOURCES = \
-  test_postprocessor_large.c
+  test_postprocessor_large.c mhd_compat.c
 test_postprocessor_large_CPPFLAGS = \
   $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS)
 test_postprocessor_large_LDADD = \
-  $(top_builddir)/src/microhttpd/libmicrohttpd.la \
-  $(MHD_W32_LIB)
+  $(top_builddir)/src/microhttpd/libmicrohttpd.la
 
 test_shutdown_select_SOURCES = \
   test_shutdown_select.c

+ 1 - 0
src/microhttpd/basicauth.c

@@ -26,6 +26,7 @@
 #include <limits.h>
 #include "internal.h"
 #include "base64.h"
+#include "mhd_compat.h"
 
 /**
  * Beginning string for any valid Basic authentication header.

+ 1 - 0
src/microhttpd/connection.c

@@ -33,6 +33,7 @@
 #include "mhd_str.h"
 #include "mhd_locks.h"
 #include "mhd_sockets.h"
+#include "mhd_compat.h"
 
 
 /**

+ 1 - 0
src/microhttpd/daemon.c

@@ -36,6 +36,7 @@
 #include "mhd_locks.h"
 #include "mhd_sockets.h"
 #include "mhd_itc.h"
+#include "mhd_compat.h"
 
 #if HAVE_SEARCH_H
 #include <search.h>

+ 1 - 0
src/microhttpd/digestauth.c

@@ -28,6 +28,7 @@
 #include "md5.h"
 #include "mhd_mono_clock.h"
 #include "mhd_str.h"
+#include "mhd_compat.h"
 
 #if defined(_WIN32) && defined(MHD_W32_MUTEX_)
 #ifndef WIN32_LEAN_AND_MEAN

+ 0 - 1
src/microhttpd/internal.h

@@ -29,7 +29,6 @@
 
 #include "platform.h"
 #include "microhttpd.h"
-#include "platform_interface.h"
 #if HTTPS_SUPPORT
 #include <gnutls/gnutls.h>
 #if GNUTLS_VERSION_MAJOR >= 3

+ 28 - 7
src/platform/w32functions.c → src/microhttpd/mhd_compat.c

@@ -1,6 +1,6 @@
 /*
   This file is part of libmicrohttpd
-  Copyright (C) 2014 Karlson2k (Evgeny Grin)
+  Copyright (C) 2014-2016 Karlson2k (Evgeny Grin)
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -13,27 +13,44 @@
   Lesser General Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with this library. 
-  If not, see <http://www.gnu.org/licenses/>.
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
 /**
- * @file platform/w32functions.h
- * @brief  internal functions for W32 systems
+ * @file microhttpd/mhd_compat.c
+ * @brief  Implementation of platform missing functions.
  * @author Karlson2k (Evgeny Grin)
  */
 
-#include "w32functions.h"
-#include <string.h>
+#include "mhd_compat.h"
+#if defined(_WIN32) && !defined(__CYGWIN__)
 #include <stdint.h>
 #include <time.h>
+#ifndef HAVE_SNPRINTF
 #include <stdio.h>
 #include <stdarg.h>
+#endif  /* HAVE_SNPRINTF */
+#endif /* _WIN32  && !__CYGWIN__ */
+
 
+/**
+ * Dummy function to silent compiler warning on empty file
+ * @return zero
+ */
+static int
+static_dummy_func(void)
+{
+  return 0;
+}
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
 /**
  * Static variable used by pseudo random number generator
  */
 static int32_t rnd_val = 0;
+
 /**
  * Generate 31-bit pseudo random number.
  * Function initialize itself at first call to current time.
@@ -49,6 +66,8 @@ int MHD_W32_random_(void)
   return (int)rnd_val;
 }
 
+
+#ifndef HAVE_SNPRINTF
 /* Emulate snprintf function on W32 */
 int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...)
 {
@@ -72,3 +91,5 @@ int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ..
 
   return ret;
 }
+#endif  /* HAVE_SNPRINTF */
+#endif /* _WIN32  && !__CYGWIN__ */

+ 30 - 18
src/include/platform_interface.h → src/microhttpd/mhd_compat.h

@@ -1,6 +1,6 @@
 /*
   This file is part of libmicrohttpd
-  Copyright (C) 2014 Karlson2k (Evgeny Grin)
+  Copyright (C) 2014-2016 Karlson2k (Evgeny Grin)
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -13,33 +13,36 @@
   Lesser General Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with this library.
-  If not, see <http://www.gnu.org/licenses/>.
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
 /**
- * @file include/platform_interface.h
- * @brief  internal platform abstraction functions
+ * @file microhttpd/mhd_compat.h
+ * @brief  Header for platform missing functions.
  * @author Karlson2k (Evgeny Grin)
+ *
+ * Provides compatibility for platforms with some missing
+ * functionality.
+ * Any functions can be implemented as macro on some platforms
+ * unless explicitly marked otherwise.
+ * Any function argument can be skipped in macro, so avoid
+ * variable modification in function parameters.
  */
 
-#ifndef MHD_PLATFORM_INTERFACE_H
-#define MHD_PLATFORM_INTERFACE_H
-
-#include "platform.h"
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#include "w32functions.h"
-#endif
+#ifndef MHD_COMPAT_H
+#define MHD_COMPAT_H 1
 
-/* *****************************
-     General function mapping
-   *****************************/
+#include "mhd_options.h"
 
 /* Platform-independent snprintf name */
 #if defined(HAVE_SNPRINTF)
 #define MHD_snprintf_ snprintf
 #else  /* ! HAVE_SNPRINTF */
 #if defined(_WIN32)
+/* Emulate snprintf function on W32 */
+int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...);
 #define MHD_snprintf_ W32_snprintf
 #else  /* ! _WIN32*/
 #error Your platform does not support snprintf() and MHD does not know how to emulate it on your platform.
@@ -48,8 +51,17 @@
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
 #define MHD_random_() random()
-#else
+#else  /* _WIN32 && !__CYGWIN__ */
 #define MHD_random_() MHD_W32_random_()
-#endif
 
-#endif /* MHD_PLATFORM_INTERFACE_H */
+/**
+ * Generate 31-bit pseudo random number.
+ * Function initialize itself at first call to current time.
+ * @return 31-bit pseudo random number.
+ */
+int MHD_W32_random_(void);
+#endif /* _WIN32 && !__CYGWIN__ */
+
+
+
+#endif /* MHD_COMPAT_H */

+ 1 - 0
src/microhttpd/test_postprocessor.c

@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include "mhd_compat.h"
 
 #ifndef WINDOWS
 #include <unistd.h>

+ 1 - 0
src/microhttpd/test_postprocessor_large.c

@@ -27,6 +27,7 @@
 #include "platform.h"
 #include "microhttpd.h"
 #include "internal.h"
+#include "mhd_compat.h"
 
 #ifndef WINDOWS
 #include <unistd.h>

+ 0 - 20
src/platform/Makefile.am

@@ -1,20 +0,0 @@
-# This Makefile.am is in the public domain
-AM_CPPFLAGS = \
-  -I$(top_srcdir)/src/include
-
-AM_CFLAGS = $(HIDDEN_VISIBILITY_CFLAGS)
-
-if USE_COVERAGE
-  AM_CFLAGS += --coverage
-endif
-
-if HAVE_W32
-noinst_LTLIBRARIES = \
-  libplatform_interface.la
-libplatform_interface_la_CPPFLAGS = \
-  $(AM_CPPFLAGS) \
-  -DBUILDING_MHD_LIB=1
-libplatform_interface_la_SOURCES = \
-  w32functions.c
-endif
-

+ 0 - 16
src/testcurl/Makefile.am

@@ -152,14 +152,6 @@ test_get_sendfile_SOURCES = \
 test_get_sendfile_LDADD = \
   $(top_builddir)/src/microhttpd/libmicrohttpd.la \
   @LIBCURL@
-test_get_sendfile_DEPENDENCIES =
-
-if HAVE_W32
-test_get_sendfile_LDADD += \
- $(top_builddir)/src/platform/libplatform_interface.la
-test_get_sendfile_DEPENDENCIES += \
- $(top_builddir)/src/platform/libplatform_interface.la
-endif
 
 test_urlparse_SOURCES = \
   test_urlparse.c
@@ -237,14 +229,6 @@ test_get_sendfile11_SOURCES = \
 test_get_sendfile11_LDADD = \
   $(top_builddir)/src/microhttpd/libmicrohttpd.la \
   @LIBCURL@
-test_get_sendfile11_DEPENDENCIES =
-
-if HAVE_W32
-test_get_sendfile11_LDADD += \
-  $(top_builddir)/src/platform/libplatform_interface.la
-test_get_sendfile11_DEPENDENCIES += \
-  $(top_builddir)/src/platform/libplatform_interface.la
-endif
 
 test_post11_SOURCES = \
   test_post.c

+ 0 - 1
src/testcurl/test_get.c

@@ -27,7 +27,6 @@
 
 #include "MHD_config.h"
 #include "platform.h"
-#include "platform_interface.h"
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include <stdlib.h>

+ 0 - 1
src/testcurl/test_get_sendfile.c

@@ -25,7 +25,6 @@
 
 #include "MHD_config.h"
 #include "platform.h"
-#include "platform_interface.h"
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include <stdlib.h>

+ 0 - 1
src/testcurl/test_quiesce.c

@@ -25,7 +25,6 @@
 
 #include "MHD_config.h"
 #include "platform.h"
-#include "platform_interface.h"
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include <stdlib.h>

+ 2 - 3
w32/common/libmicrohttpd-files.vcxproj

@@ -19,15 +19,13 @@
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_threads.c" />
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_sockets.c" />
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_itc.c" />
-    <ClCompile Include="$(MhdSrc)platform\w32functions.c" />
+    <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="$(MhdSrc)include\autoinit_funcs.h" />
     <ClInclude Include="$(MhdSrc)include\microhttpd.h" />
     <ClInclude Include="$(MhdSrc)include\mhd_options.h" />
     <ClInclude Include="$(MhdSrc)include\platform.h" />
-    <ClInclude Include="$(MhdSrc)include\platform_interface.h" />
-    <ClInclude Include="$(MhdSrc)include\w32functions.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\base64.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\connection.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\internal.h" />
@@ -44,6 +42,7 @@
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_locks.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_sockets.h" />
     <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" />
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" />
     <ClInclude Include="$(MhdW32Common)MHD_config.h" />
   </ItemGroup>
   <ItemGroup>

+ 6 - 13
w32/common/libmicrohttpd-filters.vcxproj

@@ -13,10 +13,6 @@
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
     </Filter>
-    <Filter Include="Source Files\platform_interface">
-      <UniqueIdentifier>{af799bf7-9787-4134-8e56-9e5aae50c7e3}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
     <Filter Include="Template Files">
       <UniqueIdentifier>{df5ad836-e372-437b-a0e3-299d3675d6b4}</UniqueIdentifier>
       <Extensions>in</Extensions>
@@ -32,21 +28,12 @@
     <ClInclude Include="$(MhdSrc)include\platform.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="$(MhdSrc)include\platform_interface.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="$(MhdSrc)include\w32functions.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="$(MhdSrc)include\mhd_options.h">
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="$(MhdW32Common)MHD_config.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClCompile Include="$(MhdSrc)platform\w32functions.c">
-      <Filter>Source Files\platform_interface</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="$(MhdSrc)microhttpd\base64.c">
@@ -151,6 +138,12 @@
     <ClCompile Include="$(MhdSrc)microhttpd\mhd_itc.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
+    <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="$(MhdW32Common)microhttpd_dll_res_vc.rc">