diff options
-rw-r--r-- | src/include/microhttpd.h | 2 | ||||
-rw-r--r-- | src/microhttpd/Makefile.am | 1 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 69 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 45 | ||||
-rw-r--r-- | src/microhttpd/mhd_panic.c | 101 | ||||
-rw-r--r-- | src/microhttpd/mhd_panic.h | 82 | ||||
-rw-r--r-- | w32/common/libmicrohttpd-files.vcxproj | 2 | ||||
-rw-r--r-- | w32/common/libmicrohttpd-filters.vcxproj | 6 |
8 files changed, 196 insertions, 112 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 87d2f86e..23ce06c7 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -3150,7 +3150,7 @@ MHD_set_connection_value_n (struct MHD_Connection *connection, | |||
3150 | * simply prints an error message and calls `abort()`. Alternative | 3150 | * simply prints an error message and calls `abort()`. Alternative |
3151 | * implementations might call `exit()` or other similar functions. | 3151 | * implementations might call `exit()` or other similar functions. |
3152 | * | 3152 | * |
3153 | * @param cb new error handler | 3153 | * @param cb new error handler or NULL to use default handler |
3154 | * @param cls passed to @a cb | 3154 | * @param cls passed to @a cb |
3155 | * @ingroup logging | 3155 | * @ingroup logging |
3156 | */ | 3156 | */ |
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am index ba52b740..f5125ef3 100644 --- a/src/microhttpd/Makefile.am +++ b/src/microhttpd/Makefile.am | |||
@@ -88,6 +88,7 @@ libmicrohttpd_la_SOURCES = \ | |||
88 | mhd_sockets.c mhd_sockets.h \ | 88 | mhd_sockets.c mhd_sockets.h \ |
89 | mhd_itc.c mhd_itc.h mhd_itc_types.h \ | 89 | mhd_itc.c mhd_itc.h mhd_itc_types.h \ |
90 | mhd_compat.c mhd_compat.h \ | 90 | mhd_compat.c mhd_compat.h \ |
91 | mhd_panic.c mhd_panic.h \ | ||
91 | response.c response.h | 92 | response.c response.h |
92 | 93 | ||
93 | if USE_POSIX_THREADS | 94 | if USE_POSIX_THREADS |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 1ddbd83e..e58a1caa 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -117,47 +117,6 @@ MHD_epoll (struct MHD_Daemon *daemon, | |||
117 | #endif /* EPOLL_SUPPORT */ | 117 | #endif /* EPOLL_SUPPORT */ |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Default implementation of the panic function, | ||
121 | * prints an error message and aborts. | ||
122 | * | ||
123 | * @param cls unused | ||
124 | * @param file name of the file with the problem | ||
125 | * @param line line number with the problem | ||
126 | * @param reason error message with details | ||
127 | */ | ||
128 | _MHD_NORETURN static void | ||
129 | mhd_panic_std (void *cls, | ||
130 | const char *file, | ||
131 | unsigned int line, | ||
132 | const char *reason) | ||
133 | { | ||
134 | (void) cls; /* Mute compiler warning. */ | ||
135 | #ifdef HAVE_MESSAGES | ||
136 | fprintf (stderr, | ||
137 | _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"), | ||
138 | file, | ||
139 | line, | ||
140 | reason); | ||
141 | #else /* ! HAVE_MESSAGES */ | ||
142 | (void) file; /* Mute compiler warning. */ | ||
143 | (void) line; /* Mute compiler warning. */ | ||
144 | (void) reason; /* Mute compiler warning. */ | ||
145 | #endif | ||
146 | abort (); | ||
147 | } | ||
148 | |||
149 | |||
150 | /** | ||
151 | * Handler for fatal errors. | ||
152 | */ | ||
153 | MHD_PanicCallback mhd_panic = (MHD_PanicCallback) NULL; | ||
154 | |||
155 | /** | ||
156 | * Closure argument for #mhd_panic. | ||
157 | */ | ||
158 | void *mhd_panic_cls = NULL; | ||
159 | |||
160 | /** | ||
161 | * Globally initialise library. | 120 | * Globally initialise library. |
162 | */ | 121 | */ |
163 | void | 122 | void |
@@ -7889,31 +7848,6 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
7889 | 7848 | ||
7890 | 7849 | ||
7891 | /** | 7850 | /** |
7892 | * Sets the global error handler to a different implementation. @a cb | ||
7893 | * will only be called in the case of typically fatal, serious | ||
7894 | * internal consistency issues. These issues should only arise in the | ||
7895 | * case of serious memory corruption or similar problems with the | ||
7896 | * architecture. While @a cb is allowed to return and MHD will then | ||
7897 | * try to continue, this is never safe. | ||
7898 | * | ||
7899 | * The default implementation that is used if no panic function is set | ||
7900 | * simply prints an error message and calls `abort()`. Alternative | ||
7901 | * implementations might call `exit()` or other similar functions. | ||
7902 | * | ||
7903 | * @param cb new error handler | ||
7904 | * @param cls passed to @a cb | ||
7905 | * @ingroup logging | ||
7906 | */ | ||
7907 | void | ||
7908 | MHD_set_panic_func (MHD_PanicCallback cb, | ||
7909 | void *cls) | ||
7910 | { | ||
7911 | mhd_panic = cb; | ||
7912 | mhd_panic_cls = cls; | ||
7913 | } | ||
7914 | |||
7915 | |||
7916 | /** | ||
7917 | * Obtain the version of this library | 7851 | * Obtain the version of this library |
7918 | * | 7852 | * |
7919 | * @return static version string, e.g. "0.9.9" | 7853 | * @return static version string, e.g. "0.9.9" |
@@ -8175,8 +8109,7 @@ MHD_init (void) | |||
8175 | WSADATA wsd; | 8109 | WSADATA wsd; |
8176 | #endif /* MHD_WINSOCK_SOCKETS */ | 8110 | #endif /* MHD_WINSOCK_SOCKETS */ |
8177 | 8111 | ||
8178 | if (NULL == mhd_panic) | 8112 | MHD_set_panic_func (NULL, NULL); |
8179 | mhd_panic = &mhd_panic_std; | ||
8180 | 8113 | ||
8181 | #if defined(MHD_WINSOCK_SOCKETS) | 8114 | #if defined(MHD_WINSOCK_SOCKETS) |
8182 | if (0 != WSAStartup (MAKEWORD (2, 2), &wsd)) | 8115 | if (0 != WSAStartup (MAKEWORD (2, 2), &wsd)) |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 3c1a889d..277510d8 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -53,28 +53,8 @@ | |||
53 | #define PRIu64 "llu" | 53 | #define PRIu64 "llu" |
54 | #endif /* ! PRIu64 */ | 54 | #endif /* ! PRIu64 */ |
55 | 55 | ||
56 | #ifdef MHD_PANIC | 56 | /* Must be included before other internal headers! */ |
57 | /* Override any defined MHD_PANIC macro with proper one */ | 57 | #include "mhd_panic.h" |
58 | #undef MHD_PANIC | ||
59 | #endif /* MHD_PANIC */ | ||
60 | |||
61 | #ifdef HAVE_MESSAGES | ||
62 | /** | ||
63 | * Trigger 'panic' action based on fatal errors. | ||
64 | * | ||
65 | * @param msg error message (const char *) | ||
66 | */ | ||
67 | #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \ | ||
68 | BUILTIN_NOT_REACHED; } while (0) | ||
69 | #else | ||
70 | /** | ||
71 | * Trigger 'panic' action based on fatal errors. | ||
72 | * | ||
73 | * @param msg error message (const char *) | ||
74 | */ | ||
75 | #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \ | ||
76 | BUILTIN_NOT_REACHED; } while (0) | ||
77 | #endif | ||
78 | 58 | ||
79 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 59 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
80 | #include "mhd_threads.h" | 60 | #include "mhd_threads.h" |
@@ -147,27 +127,6 @@ | |||
147 | */ | 127 | */ |
148 | #define MHD_BUF_INC_SIZE 1024 | 128 | #define MHD_BUF_INC_SIZE 1024 |
149 | 129 | ||
150 | |||
151 | /** | ||
152 | * Handler for fatal errors. | ||
153 | */ | ||
154 | extern MHD_PanicCallback mhd_panic; | ||
155 | |||
156 | /** | ||
157 | * Closure argument for "mhd_panic". | ||
158 | */ | ||
159 | extern void *mhd_panic_cls; | ||
160 | |||
161 | /* If we have Clang or gcc >= 4.5, use __builtin_unreachable() */ | ||
162 | #if defined(__clang__) || (__GNUC__ > 4) || \ | ||
163 | (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | ||
164 | #define BUILTIN_NOT_REACHED __builtin_unreachable () | ||
165 | #elif defined(_MSC_FULL_VER) | ||
166 | #define BUILTIN_NOT_REACHED __assume (0) | ||
167 | #else | ||
168 | #define BUILTIN_NOT_REACHED | ||
169 | #endif | ||
170 | |||
171 | #ifndef MHD_STATICSTR_LEN_ | 130 | #ifndef MHD_STATICSTR_LEN_ |
172 | /** | 131 | /** |
173 | * Determine length of static string / macro strings at compile time. | 132 | * Determine length of static string / macro strings at compile time. |
diff --git a/src/microhttpd/mhd_panic.c b/src/microhttpd/mhd_panic.c new file mode 100644 index 00000000..1efba20d --- /dev/null +++ b/src/microhttpd/mhd_panic.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | Copyright (C) 2014-2022 Evgeny Grin (Karlson2k) | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Lesser General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2.1 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Lesser General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with this library; if not, write to the Free Software | ||
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file microhttpd/mhd_panic.h | ||
23 | * @brief MHD_panic() function and helpers | ||
24 | * @author Daniel Pittman | ||
25 | * @author Christian Grothoff | ||
26 | * @author Karlson2k (Evgeny Grin) | ||
27 | */ | ||
28 | |||
29 | #include "mhd_panic.h" | ||
30 | #include "platform.h" | ||
31 | #include "microhttpd.h" | ||
32 | |||
33 | /** | ||
34 | * Handler for fatal errors. | ||
35 | */ | ||
36 | MHD_PanicCallback mhd_panic = (MHD_PanicCallback) NULL; | ||
37 | |||
38 | /** | ||
39 | * Closure argument for #mhd_panic. | ||
40 | */ | ||
41 | void *mhd_panic_cls = NULL; | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Default implementation of the panic function, | ||
46 | * prints an error message and aborts. | ||
47 | * | ||
48 | * @param cls unused | ||
49 | * @param file name of the file with the problem | ||
50 | * @param line line number with the problem | ||
51 | * @param reason error message with details | ||
52 | */ | ||
53 | _MHD_NORETURN static void | ||
54 | mhd_panic_std (void *cls, | ||
55 | const char *file, | ||
56 | unsigned int line, | ||
57 | const char *reason) | ||
58 | { | ||
59 | (void) cls; /* Mute compiler warning. */ | ||
60 | #ifdef HAVE_MESSAGES | ||
61 | fprintf (stderr, | ||
62 | _ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"), | ||
63 | file, | ||
64 | line, | ||
65 | reason); | ||
66 | #else /* ! HAVE_MESSAGES */ | ||
67 | (void) file; /* Mute compiler warning. */ | ||
68 | (void) line; /* Mute compiler warning. */ | ||
69 | (void) reason; /* Mute compiler warning. */ | ||
70 | #endif | ||
71 | abort (); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Sets the global error handler to a different implementation. @a cb | ||
77 | * will only be called in the case of typically fatal, serious | ||
78 | * internal consistency issues. These issues should only arise in the | ||
79 | * case of serious memory corruption or similar problems with the | ||
80 | * architecture. While @a cb is allowed to return and MHD will then | ||
81 | * try to continue, this is never safe. | ||
82 | * | ||
83 | * The default implementation that is used if no panic function is set | ||
84 | * simply prints an error message and calls `abort()`. Alternative | ||
85 | * implementations might call `exit()` or other similar functions. | ||
86 | * | ||
87 | * @param cb new error handler or NULL to use default handler | ||
88 | * @param cls passed to @a cb | ||
89 | * @ingroup logging | ||
90 | */ | ||
91 | void | ||
92 | MHD_set_panic_func (MHD_PanicCallback cb, | ||
93 | void *cls) | ||
94 | { | ||
95 | if ((MHD_PanicCallback) NULL != cb) | ||
96 | mhd_panic = cb; | ||
97 | else | ||
98 | mhd_panic = &mhd_panic_std; | ||
99 | |||
100 | mhd_panic_cls = cls; | ||
101 | } | ||
diff --git a/src/microhttpd/mhd_panic.h b/src/microhttpd/mhd_panic.h new file mode 100644 index 00000000..623639b4 --- /dev/null +++ b/src/microhttpd/mhd_panic.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | Copyright (C) 2014-2022 Evgeny Grin (Karlson2k) | ||
5 | |||
6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Lesser General Public | ||
8 | License as published by the Free Software Foundation; either | ||
9 | version 2.1 of the License, or (at your option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Lesser General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with this library; if not, write to the Free Software | ||
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file microhttpd/mhd_panic.h | ||
23 | * @brief Declaration and macros for MHD_panic() | ||
24 | * @author Daniel Pittman | ||
25 | * @author Christian Grothoff | ||
26 | * @author Karlson2k (Evgeny Grin) | ||
27 | */ | ||
28 | |||
29 | #ifndef MHD_PANIC_H | ||
30 | #define MHD_PANIC_H 1 | ||
31 | |||
32 | #include "mhd_options.h" | ||
33 | |||
34 | #ifdef MHD_PANIC | ||
35 | /* Override any possible defined MHD_PANIC macro with proper one */ | ||
36 | #undef MHD_PANIC | ||
37 | #endif /* MHD_PANIC */ | ||
38 | |||
39 | /* If we have Clang or gcc >= 4.5, use __builtin_unreachable() */ | ||
40 | #if defined(__clang__) || (__GNUC__ > 4) || \ | ||
41 | (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | ||
42 | #define BUILTIN_NOT_REACHED __builtin_unreachable () | ||
43 | #elif defined(_MSC_FULL_VER) | ||
44 | #define BUILTIN_NOT_REACHED __assume (0) | ||
45 | #else | ||
46 | #define BUILTIN_NOT_REACHED | ||
47 | #endif | ||
48 | |||
49 | /* The MHD_PanicCallback type, but without main header. */ | ||
50 | /** | ||
51 | * Handler for fatal errors. | ||
52 | */ | ||
53 | extern void | ||
54 | (*mhd_panic) (void *cls, | ||
55 | const char *file, | ||
56 | unsigned int line, | ||
57 | const char *reason); | ||
58 | |||
59 | /** | ||
60 | * Closure argument for "mhd_panic". | ||
61 | */ | ||
62 | extern void *mhd_panic_cls; | ||
63 | |||
64 | #ifdef HAVE_MESSAGES | ||
65 | /** | ||
66 | * Trigger 'panic' action based on fatal errors. | ||
67 | * | ||
68 | * @param msg error message (const char *) | ||
69 | */ | ||
70 | #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \ | ||
71 | BUILTIN_NOT_REACHED; } while (0) | ||
72 | #else | ||
73 | /** | ||
74 | * Trigger 'panic' action based on fatal errors. | ||
75 | * | ||
76 | * @param msg error message (const char *) | ||
77 | */ | ||
78 | #define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \ | ||
79 | BUILTIN_NOT_REACHED; } while (0) | ||
80 | #endif | ||
81 | |||
82 | #endif /* MHD_PANIC_H */ | ||
diff --git a/w32/common/libmicrohttpd-files.vcxproj b/w32/common/libmicrohttpd-files.vcxproj index b6dfb363..e4b6eb14 100644 --- a/w32/common/libmicrohttpd-files.vcxproj +++ b/w32/common/libmicrohttpd-files.vcxproj | |||
@@ -24,6 +24,7 @@ | |||
24 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c"> | 24 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c"> |
25 | <ExcludedFromBuild Condition="'$(PlatformToolsetVersion)'>='140'">true</ExcludedFromBuild> | 25 | <ExcludedFromBuild Condition="'$(PlatformToolsetVersion)'>='140'">true</ExcludedFromBuild> |
26 | </ClCompile> | 26 | </ClCompile> |
27 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_panic.c" /> | ||
27 | </ItemGroup> | 28 | </ItemGroup> |
28 | <ItemGroup> | 29 | <ItemGroup> |
29 | <ClInclude Include="$(MhdSrc)include\autoinit_funcs.h" /> | 30 | <ClInclude Include="$(MhdSrc)include\autoinit_funcs.h" /> |
@@ -53,6 +54,7 @@ | |||
53 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" /> | 54 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" /> |
54 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h" /> | 55 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h" /> |
55 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" /> | 56 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" /> |
57 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_panic.h" /> | ||
56 | <ClInclude Include="$(MhdW32Common)MHD_config.h" /> | 58 | <ClInclude Include="$(MhdW32Common)MHD_config.h" /> |
57 | </ItemGroup> | 59 | </ItemGroup> |
58 | <ItemGroup> | 60 | <ItemGroup> |
diff --git a/w32/common/libmicrohttpd-filters.vcxproj b/w32/common/libmicrohttpd-filters.vcxproj index ceea92fe..fd19a0b0 100644 --- a/w32/common/libmicrohttpd-filters.vcxproj +++ b/w32/common/libmicrohttpd-filters.vcxproj | |||
@@ -109,6 +109,9 @@ | |||
109 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h"> | 109 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h"> |
110 | <Filter>Internal Headers</Filter> | 110 | <Filter>Internal Headers</Filter> |
111 | </ClInclude> | 111 | </ClInclude> |
112 | <ClInclude Include="$(MhdSrc)microhttpd\mhd_panic.h"> | ||
113 | <Filter>Internal Headers</Filter> | ||
114 | </ClInclude> | ||
112 | </ItemGroup> | 115 | </ItemGroup> |
113 | <ItemGroup> | 116 | <ItemGroup> |
114 | <ClCompile Include="$(MhdSrc)microhttpd\base64.c"> | 117 | <ClCompile Include="$(MhdSrc)microhttpd\base64.c"> |
@@ -174,6 +177,9 @@ | |||
174 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c"> | 177 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c"> |
175 | <Filter>Source Files</Filter> | 178 | <Filter>Source Files</Filter> |
176 | </ClCompile> | 179 | </ClCompile> |
180 | <ClCompile Include="$(MhdSrc)microhttpd\mhd_panic.c"> | ||
181 | <Filter>Source Files</Filter> | ||
182 | </ClCompile> | ||
177 | </ItemGroup> | 183 | </ItemGroup> |
178 | <ItemGroup> | 184 | <ItemGroup> |
179 | <ResourceCompile Include="$(MhdW32Common)microhttpd_dll_res_vc.rc"> | 185 | <ResourceCompile Include="$(MhdW32Common)microhttpd_dll_res_vc.rc"> |