aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-06 22:29:11 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-06 22:29:11 +0000
commit74d383c58105026f05856f38d7f4555bcdfb701c (patch)
treee68de0e282a15b0c8ac039bdaeef519f6309bbe6 /src/microhttpd
parente3994e2a7f7a3aa2766f5494fbd6d8b05e475772 (diff)
downloadlibmicrohttpd-74d383c58105026f05856f38d7f4555bcdfb701c.tar.gz
libmicrohttpd-74d383c58105026f05856f38d7f4555bcdfb701c.zip
address #4614: mark translatable strings with _-macro
Diffstat (limited to 'src/microhttpd')
-rw-r--r--src/microhttpd/internal.c13
-rw-r--r--src/microhttpd/memorypool.c62
-rw-r--r--src/microhttpd/mhd_compat.c33
-rw-r--r--src/microhttpd/mhd_itc.c7
-rw-r--r--src/microhttpd/mhd_mono_clock.c96
-rw-r--r--src/microhttpd/mhd_sockets.c169
-rw-r--r--src/microhttpd/mhd_str.c182
-rw-r--r--src/microhttpd/mhd_threads.c53
-rw-r--r--src/microhttpd/postprocessor.c268
-rw-r--r--src/microhttpd/reason_phrase.c4
-rw-r--r--src/microhttpd/response.c50
-rw-r--r--src/microhttpd/tsearch.c183
-rw-r--r--src/microhttpd/tsearch.h24
13 files changed, 755 insertions, 389 deletions
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index b4ecd069..aa5a3596 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -86,20 +86,25 @@ MHD_state_to_string (enum MHD_CONNECTION_STATE state)
86#endif 86#endif
87#endif 87#endif
88 88
89
89#ifdef HAVE_MESSAGES 90#ifdef HAVE_MESSAGES
90/** 91/**
91 * fprintf-like helper function for logging debug 92 * fprintf-like helper function for logging debug
92 * messages. 93 * messages.
93 */ 94 */
94void 95void
95MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...) 96MHD_DLOG (const struct MHD_Daemon *daemon,
97 const char *format,
98 ...)
96{ 99{
97 va_list va; 100 va_list va;
98 101
99 if (0 == (daemon->options & MHD_USE_DEBUG)) 102 if (0 == (daemon->options & MHD_USE_DEBUG))
100 return; 103 return;
101 va_start (va, format); 104 va_start (va, format);
102 daemon->custom_error_log (daemon->custom_error_log_cls, format, va); 105 daemon->custom_error_log (daemon->custom_error_log_cls,
106 format,
107 va);
103 va_end (va); 108 va_end (va);
104} 109}
105#endif 110#endif
@@ -141,7 +146,9 @@ MHD_http_unescape (char *val)
141 switch (*rpos) 146 switch (*rpos)
142 { 147 {
143 case '%': 148 case '%':
144 if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 2, &num)) 149 if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
150 2,
151 &num))
145 { 152 {
146 *wpos = (char)((unsigned char) num); 153 *wpos = (char)((unsigned char) num);
147 wpos++; 154 wpos++;
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 7cc4f286..1290408b 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -96,19 +96,26 @@ MHD_pool_create (size_t max)
96 pool->memory = MAP_FAILED; 96 pool->memory = MAP_FAILED;
97 else 97 else
98#if defined(MAP_ANONYMOUS) && !defined(_WIN32) 98#if defined(MAP_ANONYMOUS) && !defined(_WIN32)
99 pool->memory = mmap (NULL, max, PROT_READ | PROT_WRITE, 99 pool->memory = mmap (NULL,
100 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 100 max,
101 PROT_READ | PROT_WRITE,
102 MAP_PRIVATE | MAP_ANONYMOUS,
103 -1,
104 0);
101#elif defined(_WIN32) 105#elif defined(_WIN32)
102 pool->memory = VirtualAlloc(NULL, max, MEM_COMMIT | MEM_RESERVE, 106 pool->memory = VirtualAlloc (NULL,
103 PAGE_READWRITE); 107 max,
108 MEM_COMMIT | MEM_RESERVE,
109 PAGE_READWRITE);
104#endif 110#endif
105#else 111#else
106 pool->memory = MAP_FAILED; 112 pool->memory = MAP_FAILED;
107#endif 113#endif
108 if ((pool->memory == MAP_FAILED) || (pool->memory == NULL)) 114 if ( (MAP_FAILED == pool->memory) ||
115 (NULL == pool->memory))
109 { 116 {
110 pool->memory = malloc (max); 117 pool->memory = malloc (max);
111 if (pool->memory == NULL) 118 if (NULL == pool->memory)
112 { 119 {
113 free (pool); 120 free (pool);
114 return NULL; 121 return NULL;
@@ -134,17 +141,20 @@ MHD_pool_create (size_t max)
134void 141void
135MHD_pool_destroy (struct MemoryPool *pool) 142MHD_pool_destroy (struct MemoryPool *pool)
136{ 143{
137 if (pool == NULL) 144 if (NULL == pool)
138 return; 145 return;
139 if (pool->is_mmap == MHD_NO) 146 if (MHD_NO == pool->is_mmap)
140 free (pool->memory); 147 free (pool->memory);
141 else 148 else
142#if defined(MAP_ANONYMOUS) && !defined(_WIN32) 149#if defined(MAP_ANONYMOUS) && !defined(_WIN32)
143 munmap (pool->memory, pool->size); 150 munmap (pool->memory,
151 pool->size);
144#elif defined(_WIN32) 152#elif defined(_WIN32)
145 VirtualFree(pool->memory, 0, MEM_RELEASE); 153 VirtualFree (pool->memory,
154 0,
155 MEM_RELEASE);
146#else 156#else
147 abort(); 157 abort ();
148#endif 158#endif
149 free (pool); 159 free (pool);
150} 160}
@@ -229,9 +239,11 @@ MHD_pool_reallocate (struct MemoryPool *pool,
229 size_t asize; 239 size_t asize;
230 240
231 asize = ROUND_TO_ALIGN (new_size); 241 asize = ROUND_TO_ALIGN (new_size);
232 if ( (0 == asize) && (0 != new_size) ) 242 if ( (0 == asize) &&
243 (0 != new_size) )
233 return NULL; /* new_size too close to SIZE_MAX */ 244 return NULL; /* new_size too close to SIZE_MAX */
234 if ((pool->end < old_size) || (pool->end < asize)) 245 if ( (pool->end < old_size) ||
246 (pool->end < asize) )
235 return NULL; /* unsatisfiable or bogus request */ 247 return NULL; /* unsatisfiable or bogus request */
236 248
237 if ( (pool->pos >= old_size) && 249 if ( (pool->pos >= old_size) &&
@@ -243,7 +255,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
243 /* fits */ 255 /* fits */
244 pool->pos += asize - old_size; 256 pool->pos += asize - old_size;
245 if (asize < old_size) /* shrinking - zero again! */ 257 if (asize < old_size) /* shrinking - zero again! */
246 memset (&pool->memory[pool->pos], 0, old_size - asize); 258 memset (&pool->memory[pool->pos],
259 0,
260 old_size - asize);
247 return old; 261 return old;
248 } 262 }
249 /* does not fit */ 263 /* does not fit */
@@ -257,7 +271,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
257 /* fits */ 271 /* fits */
258 ret = &pool->memory[pool->pos]; 272 ret = &pool->memory[pool->pos];
259 if (0 != old_size) 273 if (0 != old_size)
260 memmove (ret, old, old_size); 274 memmove (ret,
275 old,
276 old_size);
261 pool->pos += asize; 277 pool->pos += asize;
262 return ret; 278 return ret;
263 } 279 }
@@ -285,16 +301,14 @@ MHD_pool_reset (struct MemoryPool *pool,
285 size_t copy_bytes, 301 size_t copy_bytes,
286 size_t new_size) 302 size_t new_size)
287{ 303{
288 if (NULL != keep) 304 if ( (NULL != keep) &&
305 (keep != pool->memory) )
289 { 306 {
290 if (keep != pool->memory) 307 if (0 != copy_bytes)
291 { 308 memmove (pool->memory,
292 if (0 != copy_bytes) 309 keep,
293 memmove (pool->memory, 310 copy_bytes);
294 keep, 311 keep = pool->memory;
295 copy_bytes);
296 keep = pool->memory;
297 }
298 } 312 }
299 pool->end = pool->size; 313 pool->end = pool->size;
300 /* technically not needed, but safer to zero out */ 314 /* technically not needed, but safer to zero out */
diff --git a/src/microhttpd/mhd_compat.c b/src/microhttpd/mhd_compat.c
index 7380af02..976ed03e 100644
--- a/src/microhttpd/mhd_compat.c
+++ b/src/microhttpd/mhd_compat.c
@@ -40,30 +40,41 @@
40#ifndef HAVE_SNPRINTF 40#ifndef HAVE_SNPRINTF
41/* Emulate snprintf function on W32 */ 41/* Emulate snprintf function on W32 */
42int 42int
43W32_snprintf(char *__restrict s, 43W32_snprintf (char *__restrict s,
44 size_t n, 44 size_t n,
45 const char *__restrict format, 45 const char *__restrict format,
46 ...) 46 ...)
47{ 47{
48 int ret; 48 int ret;
49 va_list args; 49 va_list args;
50 if (0 != n && NULL != s ) 50
51 if ( (0 != n) &&
52 (NULL != s) )
51 { 53 {
52 va_start(args, format); 54 va_start (args,
53 ret = _vsnprintf(s, n, format, args); 55 format);
54 va_end(args); 56 ret = _vsnprintf (s,
57 n,
58 format,
59 args);
60 va_end (args);
55 if ((int)n == ret) 61 if ((int)n == ret)
56 s[n - 1] = 0; 62 s[n - 1] = 0;
57 if (ret >= 0) 63 if (ret >= 0)
58 return ret; 64 return ret;
59 } 65 }
60 va_start(args, format); 66 va_start(args,
61 ret = _vscprintf(format, args); 67 format);
68 ret = _vscprintf (format,
69 args);
62 va_end(args); 70 va_end(args);
63 if (0 <= ret && 0 != n && NULL == s) 71 if ( (0 <= ret) &&
72 (0 != n) &&
73 (NULL == s) )
64 return -1; 74 return -1;
65 75
66 return ret; 76 return ret;
67} 77}
78
68#endif /* HAVE_SNPRINTF */ 79#endif /* HAVE_SNPRINTF */
69#endif /* _WIN32 && !__CYGWIN__ */ 80#endif /* _WIN32 && !__CYGWIN__ */
diff --git a/src/microhttpd/mhd_itc.c b/src/microhttpd/mhd_itc.c
index 553bfcf5..4f8cf1b7 100644
--- a/src/microhttpd/mhd_itc.c
+++ b/src/microhttpd/mhd_itc.c
@@ -46,12 +46,15 @@ MHD_itc_nonblocking_ (MHD_pipe fd)
46{ 46{
47 int flags; 47 int flags;
48 48
49 flags = fcntl (fd, F_GETFL); 49 flags = fcntl (fd,
50 F_GETFL);
50 if (-1 == flags) 51 if (-1 == flags)
51 return 0; 52 return 0;
52 53
53 if ( ((flags | O_NONBLOCK) != flags) && 54 if ( ((flags | O_NONBLOCK) != flags) &&
54 (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) ) 55 (0 != fcntl (fd,
56 F_SETFL,
57 flags | O_NONBLOCK)) )
55 return 0; 58 return 0;
56 59
57 return !0; 60 return !0;
diff --git a/src/microhttpd/mhd_mono_clock.c b/src/microhttpd/mhd_mono_clock.c
index a54673d2..353e04c0 100644
--- a/src/microhttpd/mhd_mono_clock.c
+++ b/src/microhttpd/mhd_mono_clock.c
@@ -130,6 +130,7 @@ enum _MHD_mono_clock_source
130 _MHD_CLOCK_PERFCOUNTER 130 _MHD_CLOCK_PERFCOUNTER
131}; 131};
132 132
133
133/** 134/**
134 * Initialise monotonic seconds counter. 135 * Initialise monotonic seconds counter.
135 */ 136 */
@@ -149,74 +150,91 @@ MHD_monotonic_sec_counter_init (void)
149 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 150 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
150#endif /* HAVE_CLOCK_GET_TIME */ 151#endif /* HAVE_CLOCK_GET_TIME */
151 152
153 /* just a little syntactic trick to get the
154 various following ifdef's to work out nicely */
152 if (0) 155 if (0)
153 { 156 {
154 } else 157 }
158 else
155#ifdef HAVE_CLOCK_GETTIME 159#ifdef HAVE_CLOCK_GETTIME
156#ifdef CLOCK_MONOTONIC_COARSE 160#ifdef CLOCK_MONOTONIC_COARSE
157 /* Linux-specific fast value-getting clock */ 161 /* Linux-specific fast value-getting clock */
158 /* Can be affected by frequency adjustment and don't count time in suspend, */ 162 /* Can be affected by frequency adjustment and don't count time in suspend, */
159 /* but preferred since it's fast */ 163 /* but preferred since it's fast */
160 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE, &ts)) 164 if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE,
165 &ts))
161 { 166 {
162 mono_clock_id = CLOCK_MONOTONIC_COARSE; 167 mono_clock_id = CLOCK_MONOTONIC_COARSE;
163 mono_clock_start = ts.tv_sec; 168 mono_clock_start = ts.tv_sec;
164 mono_clock_source = _MHD_CLOCK_GETTIME; 169 mono_clock_source = _MHD_CLOCK_GETTIME;
165 } else 170 }
171 else
166#endif /* CLOCK_MONOTONIC_COARSE */ 172#endif /* CLOCK_MONOTONIC_COARSE */
167#ifdef CLOCK_MONOTONIC_FAST 173#ifdef CLOCK_MONOTONIC_FAST
168 /* FreeBSD/DragonFly fast value-getting clock */ 174 /* FreeBSD/DragonFly fast value-getting clock */
169 /* Can be affected by frequency adjustment, but preferred since it's fast */ 175 /* Can be affected by frequency adjustment, but preferred since it's fast */
170 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, &ts)) 176 if (0 == clock_gettime (CLOCK_MONOTONIC_FAST,
177 &ts))
171 { 178 {
172 mono_clock_id = CLOCK_MONOTONIC_FAST; 179 mono_clock_id = CLOCK_MONOTONIC_FAST;
173 mono_clock_start = ts.tv_sec; 180 mono_clock_start = ts.tv_sec;
174 mono_clock_source = _MHD_CLOCK_GETTIME; 181 mono_clock_source = _MHD_CLOCK_GETTIME;
175 } else 182 }
183 else
176#endif /* CLOCK_MONOTONIC_COARSE */ 184#endif /* CLOCK_MONOTONIC_COARSE */
177#ifdef CLOCK_MONOTONIC_RAW 185#ifdef CLOCK_MONOTONIC_RAW
178 /* Linux-specific clock */ 186 /* Linux-specific clock */
179 /* Not affected by frequency adjustment, but don't count time in suspend */ 187 /* Not affected by frequency adjustment, but don't count time in suspend */
180 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW , &ts)) 188 if (0 == clock_gettime (CLOCK_MONOTONIC_RAW,
189 &ts))
181 { 190 {
182 mono_clock_id = CLOCK_MONOTONIC_RAW; 191 mono_clock_id = CLOCK_MONOTONIC_RAW;
183 mono_clock_start = ts.tv_sec; 192 mono_clock_start = ts.tv_sec;
184 mono_clock_source = _MHD_CLOCK_GETTIME; 193 mono_clock_source = _MHD_CLOCK_GETTIME;
185 } else 194 }
195 else
186#endif /* CLOCK_MONOTONIC_RAW */ 196#endif /* CLOCK_MONOTONIC_RAW */
187#ifdef CLOCK_BOOTTIME 197#ifdef CLOCK_BOOTTIME
188 /* Linux-specific clock */ 198 /* Linux-specific clock */
189 /* Count time in suspend so it's real monotonic on Linux, */ 199 /* Count time in suspend so it's real monotonic on Linux, */
190 /* but can be slower value-getting than other clocks */ 200 /* but can be slower value-getting than other clocks */
191 if (0 == clock_gettime(CLOCK_BOOTTIME, &ts)) 201 if (0 == clock_gettime (CLOCK_BOOTTIME,
202 &ts))
192 { 203 {
193 mono_clock_id = CLOCK_BOOTTIME; 204 mono_clock_id = CLOCK_BOOTTIME;
194 mono_clock_start = ts.tv_sec; 205 mono_clock_start = ts.tv_sec;
195 mono_clock_source = _MHD_CLOCK_GETTIME; 206 mono_clock_source = _MHD_CLOCK_GETTIME;
196 } else 207 }
208 else
197#endif /* CLOCK_BOOTTIME */ 209#endif /* CLOCK_BOOTTIME */
198#ifdef CLOCK_MONOTONIC 210#ifdef CLOCK_MONOTONIC
199 /* Monotonic clock */ 211 /* Monotonic clock */
200 /* Widely supported, may be affected by frequency adjustment */ 212 /* Widely supported, may be affected by frequency adjustment */
201 /* On Linux it's not truly monotonic as it doesn't count time in suspend */ 213 /* On Linux it's not truly monotonic as it doesn't count time in suspend */
202 if (0 == clock_gettime(CLOCK_MONOTONIC, &ts)) 214 if (0 == clock_gettime (CLOCK_MONOTONIC,
215 &ts))
203 { 216 {
204 mono_clock_id = CLOCK_MONOTONIC; 217 mono_clock_id = CLOCK_MONOTONIC;
205 mono_clock_start = ts.tv_sec; 218 mono_clock_start = ts.tv_sec;
206 mono_clock_source = _MHD_CLOCK_GETTIME; 219 mono_clock_source = _MHD_CLOCK_GETTIME;
207 } else 220 }
221 else
208#endif /* CLOCK_BOOTTIME */ 222#endif /* CLOCK_BOOTTIME */
209#endif /* HAVE_CLOCK_GETTIME */ 223#endif /* HAVE_CLOCK_GETTIME */
210#ifdef HAVE_CLOCK_GET_TIME 224#ifdef HAVE_CLOCK_GET_TIME
211 /* Darwin-specific monotonic clock */ 225 /* Darwin-specific monotonic clock */
212 /* Should be monotonic as clock_set_time function always unconditionally */ 226 /* Should be monotonic as clock_set_time function always unconditionally */
213 /* failed on latest kernels */ 227 /* failed on latest kernels */
214 if (KERN_SUCCESS == host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &mono_clock_service) && 228 if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self(),
215 KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time)) 229 SYSTEM_CLOCK,
230 &mono_clock_service)) &&
231 (KERN_SUCCESS == clock_get_time (mono_clock_service,
232 &cur_time)) )
216 { 233 {
217 mono_clock_start = cur_time.tv_sec; 234 mono_clock_start = cur_time.tv_sec;
218 mono_clock_source = _MHD_CLOCK_GET_TIME; 235 mono_clock_source = _MHD_CLOCK_GET_TIME;
219 } else 236 }
237 else
220#endif /* HAVE_CLOCK_GET_TIME */ 238#endif /* HAVE_CLOCK_GET_TIME */
221#ifdef _WIN32 239#ifdef _WIN32
222#if _WIN32_WINNT >= 0x0600 240#if _WIN32_WINNT >= 0x0600
@@ -224,33 +242,39 @@ MHD_monotonic_sec_counter_init (void)
224 /* Available since Vista, ~15ms accuracy */ 242 /* Available since Vista, ~15ms accuracy */
225 if (1) 243 if (1)
226 { 244 {
227 tick_start = GetTickCount64(); 245 tick_start = GetTickCount64 ();
228 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64; 246 mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64;
229 } else 247 }
248 else
230#else /* _WIN32_WINNT < 0x0600 */ 249#else /* _WIN32_WINNT < 0x0600 */
231 /* W32 specific monotonic clock */ 250 /* W32 specific monotonic clock */
232 /* Available on Windows 2000 and later */ 251 /* Available on Windows 2000 and later */
233 if (1) 252 if (1)
234 { 253 {
235 LARGE_INTEGER freq, perf_counter; 254 LARGE_INTEGER freq;
236 QueryPerformanceFrequency(&freq); /* never fail on XP and later */ 255 LARGE_INTEGER perf_counter;
237 QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */ 256
257 QueryPerformanceFrequency (&freq); /* never fail on XP and later */
258 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
238 perf_freq = freq.QuadPart; 259 perf_freq = freq.QuadPart;
239 perf_start = perf_counter.QuadPart; 260 perf_start = perf_counter.QuadPart;
240 mono_clock_source = _MHD_CLOCK_PERFCOUNTER; 261 mono_clock_source = _MHD_CLOCK_PERFCOUNTER;
241 } else 262 }
263 else
242#endif /* _WIN32_WINNT < 0x0600 */ 264#endif /* _WIN32_WINNT < 0x0600 */
243#endif /* _WIN32 */ 265#endif /* _WIN32 */
244#ifdef HAVE_CLOCK_GETTIME 266#ifdef HAVE_CLOCK_GETTIME
245#ifdef CLOCK_HIGHRES 267#ifdef CLOCK_HIGHRES
246 /* Solaris-specific monotonic high-resolution clock */ 268 /* Solaris-specific monotonic high-resolution clock */
247 /* Not preferred due to be potentially resource-hungry */ 269 /* Not preferred due to be potentially resource-hungry */
248 if (0 == clock_gettime (CLOCK_HIGHRES, &ts)) 270 if (0 == clock_gettime (CLOCK_HIGHRES,
271 &ts))
249 { 272 {
250 mono_clock_id = CLOCK_HIGHRES; 273 mono_clock_id = CLOCK_HIGHRES;
251 mono_clock_start = ts.tv_sec; 274 mono_clock_start = ts.tv_sec;
252 mono_clock_source = _MHD_CLOCK_GETTIME; 275 mono_clock_source = _MHD_CLOCK_GETTIME;
253 } else 276 }
277 else
254#endif /* CLOCK_HIGHRES */ 278#endif /* CLOCK_HIGHRES */
255#endif /* HAVE_CLOCK_GETTIME */ 279#endif /* HAVE_CLOCK_GETTIME */
256#ifdef HAVE_GETHRTIME 280#ifdef HAVE_GETHRTIME
@@ -258,9 +282,10 @@ MHD_monotonic_sec_counter_init (void)
258 /* Not preferred due to be potentially resource-hungry */ 282 /* Not preferred due to be potentially resource-hungry */
259 if (1) 283 if (1)
260 { 284 {
261 hrtime_start = gethrtime(); 285 hrtime_start = gethrtime ();
262 mono_clock_source = _MHD_CLOCK_GETHRTIME; 286 mono_clock_source = _MHD_CLOCK_GETHRTIME;
263 } else 287 }
288 else
264#endif /* HAVE_GETHRTIME */ 289#endif /* HAVE_GETHRTIME */
265 { 290 {
266 /* no suitable clock source was found */ 291 /* no suitable clock source was found */
@@ -272,7 +297,8 @@ MHD_monotonic_sec_counter_init (void)
272 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) ) 297 (_MHD_INVALID_CLOCK_SERV != mono_clock_service) )
273 { 298 {
274 /* clock service was initialised but clock_get_time failed */ 299 /* clock service was initialised but clock_get_time failed */
275 mach_port_deallocate (mach_task_self(), mono_clock_service); 300 mach_port_deallocate (mach_task_self(),
301 mono_clock_service);
276 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 302 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
277 } 303 }
278#else 304#else
@@ -292,12 +318,14 @@ MHD_monotonic_sec_counter_finish (void)
292#ifdef HAVE_CLOCK_GET_TIME 318#ifdef HAVE_CLOCK_GET_TIME
293 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 319 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
294 { 320 {
295 mach_port_deallocate(mach_task_self(), mono_clock_service); 321 mach_port_deallocate (mach_task_self(),
322 mono_clock_service);
296 mono_clock_service = _MHD_INVALID_CLOCK_SERV; 323 mono_clock_service = _MHD_INVALID_CLOCK_SERV;
297 } 324 }
298#endif /* HAVE_CLOCK_GET_TIME */ 325#endif /* HAVE_CLOCK_GET_TIME */
299} 326}
300 327
328
301/** 329/**
302 * Monotonic seconds counter, useful for timeout calculation. 330 * Monotonic seconds counter, useful for timeout calculation.
303 * Tries to be not affected by manually setting the system real time 331 * Tries to be not affected by manually setting the system real time
@@ -311,15 +339,18 @@ MHD_monotonic_sec_counter (void)
311#ifdef HAVE_CLOCK_GETTIME 339#ifdef HAVE_CLOCK_GETTIME
312 struct timespec ts; 340 struct timespec ts;
313 341
314 if (_MHD_UNWANTED_CLOCK != mono_clock_id && 342 if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) &&
315 0 == clock_gettime (mono_clock_id , &ts)) 343 (0 == clock_gettime (mono_clock_id ,
344 &ts)) )
316 return ts.tv_sec - mono_clock_start; 345 return ts.tv_sec - mono_clock_start;
317#endif /* HAVE_CLOCK_GETTIME */ 346#endif /* HAVE_CLOCK_GETTIME */
318#ifdef HAVE_CLOCK_GET_TIME 347#ifdef HAVE_CLOCK_GET_TIME
319 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service) 348 if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
320 { 349 {
321 mach_timespec_t cur_time; 350 mach_timespec_t cur_time;
322 if (KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time)) 351
352 if (KERN_SUCCESS == clock_get_time(mono_clock_service,
353 &cur_time))
323 return cur_time.tv_sec - mono_clock_start; 354 return cur_time.tv_sec - mono_clock_start;
324 } 355 }
325#endif /* HAVE_CLOCK_GET_TIME */ 356#endif /* HAVE_CLOCK_GET_TIME */
@@ -331,14 +362,15 @@ MHD_monotonic_sec_counter (void)
331 if (0 != perf_freq) 362 if (0 != perf_freq)
332 { 363 {
333 LARGE_INTEGER perf_counter; 364 LARGE_INTEGER perf_counter;
334 QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */ 365
366 QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
335 return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq); 367 return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq);
336 } 368 }
337#endif /* _WIN32_WINNT < 0x0600 */ 369#endif /* _WIN32_WINNT < 0x0600 */
338#endif /* _WIN32 */ 370#endif /* _WIN32 */
339#ifdef HAVE_GETHRTIME 371#ifdef HAVE_GETHRTIME
340 if (1) 372 if (1)
341 return (time_t)(((uint64_t)(gethrtime() - hrtime_start)) / 1000000000); 373 return (time_t)(((uint64_t) (gethrtime () - hrtime_start)) / 1000000000);
342#endif /* HAVE_GETHRTIME */ 374#endif /* HAVE_GETHRTIME */
343 375
344 return time (NULL) - sys_clock_start; 376 return time (NULL) - sys_clock_start;
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index 1187a2cd..99dccd4c 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -243,12 +243,14 @@ const char* MHD_W32_strerror_winsock_(int err)
243 * @param sockets_pair array to receive resulted sockets 243 * @param sockets_pair array to receive resulted sockets
244 * @return non-zero if succeeded, zero otherwise 244 * @return non-zero if succeeded, zero otherwise
245 */ 245 */
246int MHD_W32_socket_pair_(SOCKET sockets_pair[2]) 246int
247MHD_W32_socket_pair_(SOCKET sockets_pair[2])
247{ 248{
248 int i; 249 int i;
249 if (!sockets_pair) 250
251 if (! sockets_pair)
250 { 252 {
251 WSASetLastError(WSAEFAULT); 253 WSASetLastError (WSAEFAULT);
252 return 0; 254 return 0;
253 } 255 }
254 256
@@ -261,52 +263,86 @@ int MHD_W32_socket_pair_(SOCKET sockets_pair[2])
261 int addr_len = c_addinlen; 263 int addr_len = c_addinlen;
262 int opt = 1; 264 int opt = 1;
263 265
264 listen_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 266 listen_s = socket (AF_INET,
267 SOCK_STREAM,
268 IPPROTO_TCP);
265 if (INVALID_SOCKET == listen_s) 269 if (INVALID_SOCKET == listen_s)
266 break; /* can't create even single socket */ 270 break; /* can't create even single socket */
267 271
268 listen_addr.sin_family = AF_INET; 272 listen_addr.sin_family = AF_INET;
269 listen_addr.sin_port = 0; /* same as htons(0) */ 273 listen_addr.sin_port = 0; /* same as htons(0) */
270 listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 274 listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
271 if (0 == bind(listen_s, (struct sockaddr*) &listen_addr, c_addinlen) 275 if ( (0 == bind (listen_s,
272 && 0 == listen(listen_s, 1) 276 (struct sockaddr*) &listen_addr,
273 && 0 == getsockname(listen_s, (struct sockaddr*) &listen_addr, 277 c_addinlen) &&
274 &addr_len)) 278 (0 == listen (listen_s,
279 1) )
280 (0 == getsockname (listen_s,
281 (struct sockaddr*) &listen_addr,
282 &addr_len))) )
275 { 283 {
276 SOCKET client_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 284 SOCKET client_s = socket(AF_INET,
277 if (INVALID_SOCKET != client_s) 285 SOCK_STREAM,
286 IPPROTO_TCP);
287 struct sockaddr_in accepted_from_addr;
288 struct sockaddr_in client_addr;
289 SOCKET server_s;
290
291 if (INVALID_SOCKET == client_s)
292 {
293 /* try again */
294 closesocket (listen_s);
295 continue;
296 }
297
298 if ( (0 != ioctlsocket (client_s,
299 FIONBIO,
300 (u_long*) &opt)) ||
301 ( (0 != connect (client_s,
302 (struct sockaddr*) &listen_addr,
303 c_addinlen)) &&
304 (WSAGetLastError() != WSAEWOULDBLOCK)) )
305 {
306 /* try again */
307 closesocket (listen_s);
308 closesocket (client_s);
309 continue;
310 }
311
312 addr_len = c_addinlen;
313 server_s = accept (listen_s,
314 (struct sockaddr*) &accepted_from_addr,
315 &addr_len);
316 if (INVALID_SOCKET == server_s)
317 {
318 /* try again */
319 closesocket (listen_s);
320 closesocket (client_s);
321 continue;
322 }
323
324 addr_len = c_addinlen;
325 opt = 0;
326 if ( (0 == getsockname (client_s,
327 (struct sockaddr*) &client_addr,
328 &addr_len)) &&
329 (accepted_from_addr.sin_family == client_addr.sin_family) &&
330 (accepted_from_addr.sin_port == client_addr.sin_port) &&
331 (accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr) &&
332 (0 == ioctlsocket(client_s,
333 FIONBIO,
334 (u_long*) &opt)) &&
335 (0 == ioctlsocket(server_s,
336 FIONBIO,
337 (u_long*) &opt)) )
278 { 338 {
279 if (0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt) 339 closesocket (listen_s);
280 && (0 == connect(client_s, (struct sockaddr*) &listen_addr, c_addinlen) 340 sockets_pair[0] = client_s;
281 || WSAGetLastError() == WSAEWOULDBLOCK)) 341 sockets_pair[1] = server_s;
282 { 342 return !0;
283 struct sockaddr_in accepted_from_addr;
284 SOCKET server_s;
285 addr_len = c_addinlen;
286 server_s = accept(listen_s,
287 (struct sockaddr*) &accepted_from_addr, &addr_len);
288 if (INVALID_SOCKET != server_s)
289 {
290 struct sockaddr_in client_addr;
291 addr_len = c_addinlen;
292 opt = 0;
293 if (0 == getsockname(client_s, (struct sockaddr*) &client_addr, &addr_len)
294 && accepted_from_addr.sin_family == client_addr.sin_family
295 && accepted_from_addr.sin_port == client_addr.sin_port
296 && accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr
297 && 0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt)
298 && 0 == ioctlsocket(server_s, FIONBIO, (u_long*) &opt))
299 {
300 closesocket(listen_s);
301 sockets_pair[0] = client_s;
302 sockets_pair[1] = server_s;
303 return !0;
304 }
305 closesocket(server_s);
306 }
307 }
308 closesocket(client_s);
309 } 343 }
344 closesocket (server_s);
345 closesocket (client_s);
310 } 346 }
311 closesocket(listen_s); 347 closesocket(listen_s);
312 } 348 }
@@ -367,17 +403,22 @@ MHD_socket_nonblocking_ (MHD_socket sock)
367#if defined(MHD_POSIX_SOCKETS) 403#if defined(MHD_POSIX_SOCKETS)
368 int flags; 404 int flags;
369 405
370 flags = fcntl (sock, F_GETFL); 406 flags = fcntl (sock,
407 F_GETFL);
371 if (-1 == flags) 408 if (-1 == flags)
372 return 0; 409 return 0;
373 410
374 if ( ((flags | O_NONBLOCK) != flags) && 411 if ( ((flags | O_NONBLOCK) != flags) &&
375 (0 != fcntl (sock, F_SETFL, flags | O_NONBLOCK)) ) 412 (0 != fcntl (sock,
413 F_SETFL,
414 flags | O_NONBLOCK)) )
376 return 0; 415 return 0;
377#elif defined(MHD_WINSOCK_SOCKETS) 416#elif defined(MHD_WINSOCK_SOCKETS)
378 unsigned long flags = 1; 417 unsigned long flags = 1;
379 418
380 if (0 != ioctlsocket (sock, FIONBIO, &flags)) 419 if (0 != ioctlsocket (sock,
420 FIONBIO,
421 &flags))
381 return 0; 422 return 0;
382#endif /* MHD_WINSOCK_SOCKETS */ 423#endif /* MHD_WINSOCK_SOCKETS */
383 return !0; 424 return !0;
@@ -397,15 +438,20 @@ MHD_socket_noninheritable_ (MHD_socket sock)
397#if defined(MHD_POSIX_SOCKETS) 438#if defined(MHD_POSIX_SOCKETS)
398 int flags; 439 int flags;
399 440
400 flags = fcntl (sock, F_GETFD); 441 flags = fcntl (sock,
442 F_GETFD);
401 if (-1 == flags) 443 if (-1 == flags)
402 return 0; 444 return 0;
403 445
404 if ( ((flags | FD_CLOEXEC) != flags) && 446 if ( ((flags | FD_CLOEXEC) != flags) &&
405 (0 != fcntl (sock, F_SETFD, flags | FD_CLOEXEC)) ) 447 (0 != fcntl (sock,
448 F_SETFD,
449 flags | FD_CLOEXEC)) )
406 return 0; 450 return 0;
407#elif defined(MHD_WINSOCK_SOCKETS) 451#elif defined(MHD_WINSOCK_SOCKETS)
408 if (!SetHandleInformation ((HANDLE)sock, HANDLE_FLAG_INHERIT, 0)) 452 if (! SetHandleInformation ((HANDLE)sock,
453 HANDLE_FLAG_INHERIT,
454 0))
409 return 0; 455 return 0;
410#endif /* MHD_WINSOCK_SOCKETS */ 456#endif /* MHD_WINSOCK_SOCKETS */
411 return !0; 457 return !0;
@@ -437,32 +483,45 @@ MHD_socket_create_listen_ (int use_ipv6)
437#endif /* ! HAVE_INET6 */ 483#endif /* ! HAVE_INET6 */
438 484
439#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC) 485#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC)
440 fd = socket (domain, SOCK_STREAM | SOCK_CLOEXEC, 0); 486 fd = socket (domain,
487 SOCK_STREAM | SOCK_CLOEXEC,
488 0);
441 cloexec_set = !0; 489 cloexec_set = !0;
442#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT) 490#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
443 fd = WSASocketW (domain, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_NO_HANDLE_INHERIT); 491 fd = WSASocketW (domain,
492 SOCK_STREAM,
493 0,
494 NULL,
495 0,
496 WSA_FLAG_NO_HANDLE_INHERIT);
444 cloexec_set = !0; 497 cloexec_set = !0;
445#else /* !SOCK_CLOEXEC */ 498#else /* !SOCK_CLOEXEC */
446 fd = MHD_INVALID_SOCKET; 499 fd = MHD_INVALID_SOCKET;
447#endif /* !SOCK_CLOEXEC */ 500#endif /* !SOCK_CLOEXEC */
448 if (MHD_INVALID_SOCKET == fd) 501 if (MHD_INVALID_SOCKET == fd)
449 { 502 {
450 fd = socket (domain, SOCK_STREAM, 0); 503 fd = socket (domain,
504 SOCK_STREAM,
505 0);
451 cloexec_set = 0; 506 cloexec_set = 0;
452 } 507 }
453 if (MHD_INVALID_SOCKET == fd) 508 if (MHD_INVALID_SOCKET == fd)
454 return MHD_INVALID_SOCKET; 509 return MHD_INVALID_SOCKET;
455#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE) 510#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
456 if(0 != setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &on_val, sizeof(on_val))) 511 if(0 != setsockopt(fd,
512 SOL_SOCKET,
513 SO_NOSIGPIPE,
514 &on_val,
515 sizeof (on_val)))
457 { 516 {
458 int err = MHD_socket_get_error_(); 517 int err = MHD_socket_get_error_ ();
459 MHD_socket_close_(fd); 518 MHD_socket_close_ (fd);
460 MHD_socket_fset_error_(err); 519 MHD_socket_fset_error_ (err);
461 return MHD_INVALID_SOCKET; 520 return MHD_INVALID_SOCKET;
462 } 521 }
463#endif 522#endif
464 if (!cloexec_set) 523 if (! cloexec_set)
465 (void)MHD_socket_noninheritable_(fd); 524 (void) MHD_socket_noninheritable_ (fd);
466 525
467 return fd; 526 return fd;
468} 527}
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 8e6ff92e..1cea69a0 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -35,7 +35,7 @@
35#ifdef _MHD_inline 35#ifdef _MHD_inline
36#undef _MHD_inline 36#undef _MHD_inline
37#endif /* _MHD_inline */ 37#endif /* _MHD_inline */
38/* Do not force inlining and do not use macro functions, use normal static 38/* Do not force inlining and do not use macro functions, use normal static
39 functions instead. 39 functions instead.
40 This may give more flexibility for size optimizations. */ 40 This may give more flexibility for size optimizations. */
41#define _MHD_inline static 41#define _MHD_inline static
@@ -52,28 +52,33 @@
52#ifdef INLINE_FUNC 52#ifdef INLINE_FUNC
53/** 53/**
54 * Check whether character is lower case letter in US-ASCII 54 * Check whether character is lower case letter in US-ASCII
55 *
55 * @param c character to check 56 * @param c character to check
56 * @return non-zero if character is lower case letter, zero otherwise 57 * @return non-zero if character is lower case letter, zero otherwise
57 */ 58 */
58_MHD_inline _MHD_bool 59_MHD_inline _MHD_bool
59isasciilower (char c) 60isasciilower (char c)
60{ 61{
61 return c >= 'a' && c <= 'z'; 62 return (c >= 'a') && (c <= 'z');
62} 63}
63 64
65
64/** 66/**
65 * Check whether character is upper case letter in US-ASCII 67 * Check whether character is upper case letter in US-ASCII
68 *
66 * @param c character to check 69 * @param c character to check
67 * @return non-zero if character is upper case letter, zero otherwise 70 * @return non-zero if character is upper case letter, zero otherwise
68 */ 71 */
69_MHD_inline _MHD_bool 72_MHD_inline _MHD_bool
70isasciiupper (char c) 73isasciiupper (char c)
71{ 74{
72 return c >= 'A' && c <= 'Z'; 75 return (c >= 'A') && (c <= 'Z');
73} 76}
74 77
78
75/** 79/**
76 * Check whether character is letter in US-ASCII 80 * Check whether character is letter in US-ASCII
81 *
77 * @param c character to check 82 * @param c character to check
78 * @return non-zero if character is letter in US-ASCII, zero otherwise 83 * @return non-zero if character is letter in US-ASCII, zero otherwise
79 */ 84 */
@@ -83,19 +88,23 @@ isasciialpha (char c)
83 return isasciilower (c) || isasciiupper (c); 88 return isasciilower (c) || isasciiupper (c);
84} 89}
85 90
91
86/** 92/**
87 * Check whether character is decimal digit in US-ASCII 93 * Check whether character is decimal digit in US-ASCII
94 *
88 * @param c character to check 95 * @param c character to check
89 * @return non-zero if character is decimal digit, zero otherwise 96 * @return non-zero if character is decimal digit, zero otherwise
90 */ 97 */
91_MHD_inline _MHD_bool 98_MHD_inline _MHD_bool
92isasciidigit (char c) 99isasciidigit (char c)
93{ 100{
94 return c >= '0' && c <= '9'; 101 return (c >= '0') && (c <= '9');
95} 102}
96 103
104
97/** 105/**
98 * Check whether character is hexadecimal digit in US-ASCII 106 * Check whether character is hexadecimal digit in US-ASCII
107 *
99 * @param c character to check 108 * @param c character to check
100 * @return non-zero if character is decimal digit, zero otherwise 109 * @return non-zero if character is decimal digit, zero otherwise
101 */ 110 */
@@ -103,12 +112,14 @@ _MHD_inline _MHD_bool
103isasciixdigit (char c) 112isasciixdigit (char c)
104{ 113{
105 return isasciidigit (c) || 114 return isasciidigit (c) ||
106 (c >= 'A' && c <= 'F') || 115 ( (c >= 'A') && (c <= 'F') ) ||
107 (c >= 'a' && c <= 'f'); 116 ( (c >= 'a') && (c <= 'f') );
108} 117}
109 118
119
110/** 120/**
111 * Check whether character is decimal digit or letter in US-ASCII 121 * Check whether character is decimal digit or letter in US-ASCII
122 *
112 * @param c character to check 123 * @param c character to check
113 * @return non-zero if character is decimal digit or letter, zero otherwise 124 * @return non-zero if character is decimal digit or letter, zero otherwise
114 */ 125 */
@@ -118,11 +129,13 @@ isasciialnum (char c)
118 return isasciialpha (c) || isasciidigit (c); 129 return isasciialpha (c) || isasciidigit (c);
119} 130}
120 131
132
121/** 133/**
122 * Convert US-ASCII character to lower case. 134 * Convert US-ASCII character to lower case.
123 * If character is upper case letter in US-ASCII than it's converted to lower 135 * If character is upper case letter in US-ASCII than it's converted to lower
124 * case analog. If character is NOT upper case letter than it's returned 136 * case analog. If character is NOT upper case letter than it's returned
125 * unmodified. 137 * unmodified.
138 *
126 * @param c character to convert 139 * @param c character to convert
127 * @return converted to lower case character 140 * @return converted to lower case character
128 */ 141 */
@@ -132,11 +145,13 @@ toasciilower (char c)
132 return isasciiupper (c) ? (c - 'A' + 'a') : c; 145 return isasciiupper (c) ? (c - 'A' + 'a') : c;
133} 146}
134 147
148
135/** 149/**
136 * Convert US-ASCII character to upper case. 150 * Convert US-ASCII character to upper case.
137 * If character is lower case letter in US-ASCII than it's converted to upper 151 * If character is lower case letter in US-ASCII than it's converted to upper
138 * case analog. If character is NOT lower case letter than it's returned 152 * case analog. If character is NOT lower case letter than it's returned
139 * unmodified. 153 * unmodified.
154 *
140 * @param c character to convert 155 * @param c character to convert
141 * @return converted to upper case character 156 * @return converted to upper case character
142 */ 157 */
@@ -146,8 +161,10 @@ toasciiupper (char c)
146 return isasciilower (c) ? (c - 'a' + 'A') : c; 161 return isasciilower (c) ? (c - 'a' + 'A') : c;
147} 162}
148 163
164
149/** 165/**
150 * Convert US-ASCII decimal digit to its value. 166 * Convert US-ASCII decimal digit to its value.
167 *
151 * @param c character to convert 168 * @param c character to convert
152 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 169 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
153 */ 170 */
@@ -160,8 +177,10 @@ todigitvalue (char c)
160 return -1; 177 return -1;
161} 178}
162 179
180
163/** 181/**
164 * Convert US-ASCII hexadecimal digit to its value. 182 * Convert US-ASCII hexadecimal digit to its value.
183 *
165 * @param c character to convert 184 * @param c character to convert
166 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 185 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
167 */ 186 */
@@ -170,49 +189,59 @@ toxdigitvalue (char c)
170{ 189{
171 if (isasciidigit (c)) 190 if (isasciidigit (c))
172 return (unsigned char)(c - '0'); 191 return (unsigned char)(c - '0');
173 if (c >= 'A' && c <= 'F') 192 if ( (c >= 'A') && (c <= 'F') )
174 return (unsigned char)(c - 'A' + 10); 193 return (unsigned char)(c - 'A' + 10);
175 if (c >= 'a' && c <= 'f') 194 if ( (c >= 'a') && (c <= 'f') )
176 return (unsigned char)(c - 'a' + 10); 195 return (unsigned char)(c - 'a' + 10);
177 196
178 return -1; 197 return -1;
179} 198}
180#else /* !INLINE_FUNC */ 199#else /* !INLINE_FUNC */
181 200
201
182/** 202/**
183 * Checks whether character is lower case letter in US-ASCII 203 * Checks whether character is lower case letter in US-ASCII
204 *
184 * @param c character to check 205 * @param c character to check
185 * @return boolean true if character is lower case letter, 206 * @return boolean true if character is lower case letter,
186 * boolean false otherwise 207 * boolean false otherwise
187 */ 208 */
188#define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z') 209#define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z')
189 210
211
190/** 212/**
191 * Checks whether character is upper case letter in US-ASCII 213 * Checks whether character is upper case letter in US-ASCII
214 *
192 * @param c character to check 215 * @param c character to check
193 * @return boolean true if character is upper case letter, 216 * @return boolean true if character is upper case letter,
194 * boolean false otherwise 217 * boolean false otherwise
195 */ 218 */
196#define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z') 219#define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z')
197 220
221
198/** 222/**
199 * Checks whether character is letter in US-ASCII 223 * Checks whether character is letter in US-ASCII
224 *
200 * @param c character to check 225 * @param c character to check
201 * @return boolean true if character is letter, boolean false 226 * @return boolean true if character is letter, boolean false
202 * otherwise 227 * otherwise
203 */ 228 */
204#define isasciialpha(c) (isasciilower(c) || isasciiupper(c)) 229#define isasciialpha(c) (isasciilower(c) || isasciiupper(c))
205 230
231
206/** 232/**
207 * Check whether character is decimal digit in US-ASCII 233 * Check whether character is decimal digit in US-ASCII
234 *
208 * @param c character to check 235 * @param c character to check
209 * @return boolean true if character is decimal digit, boolean false 236 * @return boolean true if character is decimal digit, boolean false
210 * otherwise 237 * otherwise
211 */ 238 */
212#define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9') 239#define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9')
213 240
241
214/** 242/**
215 * Check whether character is hexadecimal digit in US-ASCII 243 * Check whether character is hexadecimal digit in US-ASCII
244 *
216 * @param c character to check 245 * @param c character to check
217 * @return boolean true if character is hexadecimal digit, 246 * @return boolean true if character is hexadecimal digit,
218 * boolean false otherwise 247 * boolean false otherwise
@@ -221,41 +250,50 @@ toxdigitvalue (char c)
221 (((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \ 250 (((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \
222 (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ) 251 (((char)(c)) >= 'a' && ((char)(c)) <= 'f') )
223 252
253
224/** 254/**
225 * Check whether character is decimal digit or letter in US-ASCII 255 * Check whether character is decimal digit or letter in US-ASCII
256 *
226 * @param c character to check 257 * @param c character to check
227 * @return boolean true if character is decimal digit or letter, 258 * @return boolean true if character is decimal digit or letter,
228 * boolean false otherwise 259 * boolean false otherwise
229 */ 260 */
230#define isasciialnum(c) (isasciialpha(c) || isasciidigit(c)) 261#define isasciialnum(c) (isasciialpha(c) || isasciidigit(c))
231 262
263
232/** 264/**
233 * Convert US-ASCII character to lower case. 265 * Convert US-ASCII character to lower case.
234 * If character is upper case letter in US-ASCII than it's converted to lower 266 * If character is upper case letter in US-ASCII than it's converted to lower
235 * case analog. If character is NOT upper case letter than it's returned 267 * case analog. If character is NOT upper case letter than it's returned
236 * unmodified. 268 * unmodified.
269 *
237 * @param c character to convert 270 * @param c character to convert
238 * @return converted to lower case character 271 * @return converted to lower case character
239 */ 272 */
240#define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c))) 273#define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c)))
241 274
275
242/** 276/**
243 * Convert US-ASCII character to upper case. 277 * Convert US-ASCII character to upper case.
244 * If character is lower case letter in US-ASCII than it's converted to upper 278 * If character is lower case letter in US-ASCII than it's converted to upper
245 * case analog. If character is NOT lower case letter than it's returned 279 * case analog. If character is NOT lower case letter than it's returned
246 * unmodified. 280 * unmodified.
281 *
247 * @param c character to convert 282 * @param c character to convert
248 * @return converted to upper case character 283 * @return converted to upper case character
249 */ 284 */
250#define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c))) 285#define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c)))
251 286
287
252/** 288/**
253 * Convert US-ASCII decimal digit to its value. 289 * Convert US-ASCII decimal digit to its value.
290 *
254 * @param c character to convert 291 * @param c character to convert
255 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit 292 * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
256 */ 293 */
257#define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1)) 294#define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1))
258 295
296
259/** 297/**
260 * Convert US-ASCII hexadecimal digit to its value. 298 * Convert US-ASCII hexadecimal digit to its value.
261 * @param c character to convert 299 * @param c character to convert
@@ -268,21 +306,25 @@ toxdigitvalue (char c)
268 (int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) ))) 306 (int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) )))
269#endif /* !INLINE_FUNC */ 307#endif /* !INLINE_FUNC */
270 308
309
271#ifndef MHD_FAVOR_SMALL_CODE 310#ifndef MHD_FAVOR_SMALL_CODE
272/** 311/**
273 * Check two string for equality, ignoring case of US-ASCII letters. 312 * Check two string for equality, ignoring case of US-ASCII letters.
313 *
274 * @param str1 first string to compare 314 * @param str1 first string to compare
275 * @param str2 second string to compare 315 * @param str2 second string to compare
276 * @return non-zero if two strings are equal, zero otherwise. 316 * @return non-zero if two strings are equal, zero otherwise.
277 */ 317 */
278int 318int
279MHD_str_equal_caseless_ (const char * str1, const char * str2) 319MHD_str_equal_caseless_ (const char * str1,
320 const char * str2)
280{ 321{
281 while (0 != (*str1)) 322 while (0 != (*str1))
282 { 323 {
283 const char c1 = *str1; 324 const char c1 = *str1;
284 const char c2 = *str2; 325 const char c2 = *str2;
285 if (c1 != c2 && toasciilower (c1) != toasciilower (c2)) 326 if ( (c1 != c2) &&
327 (toasciilower (c1) != toasciilower (c2)) )
286 return 0; 328 return 0;
287 str1++; 329 str1++;
288 str2++; 330 str2++;
@@ -297,22 +339,27 @@ MHD_str_equal_caseless_ (const char * str1, const char * str2)
297 * checking not more than @a maxlen characters. 339 * checking not more than @a maxlen characters.
298 * Compares up to first terminating null character, but not more than 340 * Compares up to first terminating null character, but not more than
299 * first @a maxlen characters. 341 * first @a maxlen characters.
342 *
300 * @param str1 first string to compare 343 * @param str1 first string to compare
301 * @param str2 second string to compare 344 * @param str2 second string to compare
302 * @param maxlen maximum number of characters to compare 345 * @param maxlen maximum number of characters to compare
303 * @return non-zero if two strings are equal, zero otherwise. 346 * @return non-zero if two strings are equal, zero otherwise.
304 */ 347 */
305int 348int
306MHD_str_equal_caseless_n_ (const char * const str1, const char * const str2, size_t maxlen) 349MHD_str_equal_caseless_n_ (const char * const str1,
350 const char * const str2,
351 size_t maxlen)
307{ 352{
308 size_t i; 353 size_t i;
354
309 for (i = 0; i < maxlen; ++i) 355 for (i = 0; i < maxlen; ++i)
310 { 356 {
311 const char c1 = str1[i]; 357 const char c1 = str1[i];
312 const char c2 = str2[i]; 358 const char c2 = str2[i];
313 if (0 == c2) 359 if (0 == c2)
314 return 0 == c1; 360 return 0 == c1;
315 if (c1 != c2 && toasciilower (c1) != toasciilower (c2)) 361 if ( (c1 != c2) &&
362 (toasciilower (c1) != toasciilower (c2)) )
316 return 0; 363 return 0;
317 } 364 }
318 return !0; 365 return !0;
@@ -324,17 +371,20 @@ MHD_str_equal_caseless_n_ (const char * const str1, const char * const str2, siz
324/** 371/**
325 * Convert decimal US-ASCII digits in string to number in uint64_t. 372 * Convert decimal US-ASCII digits in string to number in uint64_t.
326 * Conversion stopped at first non-digit character. 373 * Conversion stopped at first non-digit character.
374 *
327 * @param str string to convert 375 * @param str string to convert
328 * @param out_val pointer to uint64_t to store result of conversion 376 * @param[out] out_val pointer to uint64_t to store result of conversion
329 * @return non-zero number of characters processed on succeed, 377 * @return non-zero number of characters processed on succeed,
330 * zero if no digit is found, resulting value is larger 378 * zero if no digit is found, resulting value is larger
331 * then possible to store in uint64_t or @a out_val is NULL 379 * then possible to store in uint64_t or @a out_val is NULL
332 */ 380 */
333size_t 381size_t
334MHD_str_to_uint64_ (const char * str, uint64_t * out_val) 382MHD_str_to_uint64_ (const char *str,
383 uint64_t *out_val)
335{ 384{
336 const char * const start = str; 385 const char * const start = str;
337 uint64_t res; 386 uint64_t res;
387
338 if (!str || !out_val || !isasciidigit(str[0])) 388 if (!str || !out_val || !isasciidigit(str[0]))
339 return 0; 389 return 0;
340 390
@@ -343,7 +393,8 @@ MHD_str_to_uint64_ (const char * str, uint64_t * out_val)
343 { 393 {
344 const int digit = (unsigned char)(*str) - '0'; 394 const int digit = (unsigned char)(*str) - '0';
345 if ( (res > (UINT64_MAX / 10)) || 395 if ( (res > (UINT64_MAX / 10)) ||
346 (res == (UINT64_MAX / 10) && (uint64_t)digit > (UINT64_MAX % 10)) ) 396 ( (res == (UINT64_MAX / 10)) &&
397 ((uint64_t)digit > (UINT64_MAX % 10)) ) )
347 return 0; 398 return 0;
348 399
349 res *= 10; 400 res *= 10;
@@ -359,20 +410,24 @@ MHD_str_to_uint64_ (const char * str, uint64_t * out_val)
359/** 410/**
360 * Convert not more then @a maxlen decimal US-ASCII digits in string to 411 * Convert not more then @a maxlen decimal US-ASCII digits in string to
361 * number in uint64_t. 412 * number in uint64_t.
362 * Conversion stopped at first non-digit character or after @a maxlen 413 * Conversion stopped at first non-digit character or after @a maxlen
363 * digits. 414 * digits.
415 *
364 * @param str string to convert 416 * @param str string to convert
365 * @param maxlen maximum number of characters to process 417 * @param maxlen maximum number of characters to process
366 * @param out_val pointer to uint64_t to store result of conversion 418 * @param[out] out_val pointer to uint64_t to store result of conversion
367 * @return non-zero number of characters processed on succeed, 419 * @return non-zero number of characters processed on succeed,
368 * zero if no digit is found, resulting value is larger 420 * zero if no digit is found, resulting value is larger
369 * then possible to store in uint64_t or @a out_val is NULL 421 * then possible to store in uint64_t or @a out_val is NULL
370 */ 422 */
371size_t 423size_t
372MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val) 424MHD_str_to_uint64_n_ (const char * str,
425 size_t maxlen,
426 uint64_t *out_val)
373{ 427{
374 uint64_t res; 428 uint64_t res;
375 size_t i; 429 size_t i;
430
376 if (!str || !maxlen || !out_val || !isasciidigit (str[0])) 431 if (!str || !maxlen || !out_val || !isasciidigit (str[0]))
377 return 0; 432 return 0;
378 433
@@ -381,14 +436,17 @@ MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
381 do 436 do
382 { 437 {
383 const int digit = (unsigned char)str[i] - '0'; 438 const int digit = (unsigned char)str[i] - '0';
439
384 if ( (res > (UINT64_MAX / 10)) || 440 if ( (res > (UINT64_MAX / 10)) ||
385 (res == (UINT64_MAX / 10) && (uint64_t)digit > (UINT64_MAX % 10)) ) 441 ( (res == (UINT64_MAX / 10)) &&
442 ((uint64_t)digit > (UINT64_MAX % 10)) ) )
386 return 0; 443 return 0;
387 444
388 res *= 10; 445 res *= 10;
389 res += digit; 446 res += digit;
390 i++; 447 i++;
391 } while(i < maxlen && isasciidigit(str[i])); 448 } while ( (i < maxlen) &&
449 isasciidigit (str[i]) );
392 450
393 *out_val= res; 451 *out_val= res;
394 return i; 452 return i;
@@ -398,18 +456,21 @@ MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
398/** 456/**
399 * Convert hexadecimal US-ASCII digits in string to number in size_t. 457 * Convert hexadecimal US-ASCII digits in string to number in size_t.
400 * Conversion stopped at first non-digit character. 458 * Conversion stopped at first non-digit character.
459 *
401 * @param str string to convert 460 * @param str string to convert
402 * @param out_val pointer to size_t to store result of conversion 461 * @param[out] out_val pointer to size_t to store result of conversion
403 * @return non-zero number of characters processed on succeed, 462 * @return non-zero number of characters processed on succeed,
404 * zero if no digit is found, resulting value is larger 463 * zero if no digit is found, resulting value is larger
405 * then possible to store in size_t or @a out_val is NULL 464 * then possible to store in size_t or @a out_val is NULL
406 */ 465 */
407size_t 466size_t
408MHD_strx_to_sizet_ (const char * str, size_t * out_val) 467MHD_strx_to_sizet_ (const char *str,
468 size_t *out_val)
409{ 469{
410 const char * const start = str; 470 const char * const start = str;
411 size_t res; 471 size_t res;
412 int digit; 472 int digit;
473
413 if (!str || !out_val) 474 if (!str || !out_val)
414 return 0; 475 return 0;
415 476
@@ -418,7 +479,8 @@ MHD_strx_to_sizet_ (const char * str, size_t * out_val)
418 while (digit >= 0) 479 while (digit >= 0)
419 { 480 {
420 if ( (res < (SIZE_MAX / 16)) || 481 if ( (res < (SIZE_MAX / 16)) ||
421 (res == (SIZE_MAX / 16) && (size_t)digit <= (SIZE_MAX % 16)) ) 482 ( (res == (SIZE_MAX / 16)) &&
483 ((size_t)digit <= (SIZE_MAX % 16)) ) )
422 { 484 {
423 res *= 16; 485 res *= 16;
424 res += digit; 486 res += digit;
@@ -438,30 +500,35 @@ MHD_strx_to_sizet_ (const char * str, size_t * out_val)
438/** 500/**
439 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 501 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
440 * to number in size_t. 502 * to number in size_t.
441 * Conversion stopped at first non-digit character or after @a maxlen 503 * Conversion stopped at first non-digit character or after @a maxlen
442 * digits. 504 * digits.
505 *
443 * @param str string to convert 506 * @param str string to convert
444 * @param maxlen maximum number of characters to process 507 * @param maxlen maximum number of characters to process
445 * @param out_val pointer to size_t to store result of conversion 508 * @param[out] out_val pointer to size_t to store result of conversion
446 * @return non-zero number of characters processed on succeed, 509 * @return non-zero number of characters processed on succeed,
447 * zero if no digit is found, resulting value is larger 510 * zero if no digit is found, resulting value is larger
448 * then possible to store in size_t or @a out_val is NULL 511 * then possible to store in size_t or @a out_val is NULL
449 */ 512 */
450size_t 513size_t
451MHD_strx_to_sizet_n_ (const char * str, size_t maxlen, size_t * out_val) 514MHD_strx_to_sizet_n_ (const char * str,
515 size_t maxlen,
516 size_t *out_val)
452{ 517{
453 size_t i; 518 size_t i;
454 size_t res; 519 size_t res;
455 int digit; 520 int digit;
456 if (!str || !out_val) 521 if (!str || !out_val)
457 return 0; 522 return 0;
458 523
459 res = 0; 524 res = 0;
460 i = 0; 525 i = 0;
461 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 526 while ( (i < maxlen) &&
527 ((digit = toxdigitvalue (str[i])) >= 0) )
462 { 528 {
463 if ( (res > (SIZE_MAX / 16)) || 529 if ( (res > (SIZE_MAX / 16)) ||
464 (res == (SIZE_MAX / 16) && (size_t)digit > (SIZE_MAX % 16)) ) 530 ( (res == (SIZE_MAX / 16)) &&
531 ((size_t)digit > (SIZE_MAX % 16)) ) )
465 return 0; 532 return 0;
466 533
467 res *= 16; 534 res *= 16;
@@ -478,18 +545,21 @@ MHD_strx_to_sizet_n_ (const char * str, size_t maxlen, size_t * out_val)
478/** 545/**
479 * Convert hexadecimal US-ASCII digits in string to number in uint32_t. 546 * Convert hexadecimal US-ASCII digits in string to number in uint32_t.
480 * Conversion stopped at first non-digit character. 547 * Conversion stopped at first non-digit character.
548 *
481 * @param str string to convert 549 * @param str string to convert
482 * @param out_val pointer to uint32_t to store result of conversion 550 * @param[out] out_val pointer to uint32_t to store result of conversion
483 * @return non-zero number of characters processed on succeed, 551 * @return non-zero number of characters processed on succeed,
484 * zero if no digit is found, resulting value is larger 552 * zero if no digit is found, resulting value is larger
485 * then possible to store in uint32_t or @a out_val is NULL 553 * then possible to store in uint32_t or @a out_val is NULL
486 */ 554 */
487size_t 555size_t
488MHD_strx_to_uint32_ (const char * str, uint32_t * out_val) 556MHD_strx_to_uint32_ (const char * str,
557 uint32_t *out_val)
489{ 558{
490 const char * const start = str; 559 const char * const start = str;
491 uint32_t res; 560 uint32_t res;
492 int digit; 561 int digit;
562
493 if (!str || !out_val) 563 if (!str || !out_val)
494 return 0; 564 return 0;
495 565
@@ -518,24 +588,27 @@ MHD_strx_to_uint32_ (const char * str, uint32_t * out_val)
518/** 588/**
519 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 589 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
520 * to number in uint32_t. 590 * to number in uint32_t.
521 * Conversion stopped at first non-digit character or after @a maxlen 591 * Conversion stopped at first non-digit character or after @a maxlen
522 * digits. 592 * digits.
593 *
523 * @param str string to convert 594 * @param str string to convert
524 * @param maxlen maximum number of characters to process 595 * @param maxlen maximum number of characters to process
525 * @param out_val pointer to uint32_t to store result of conversion 596 * @param[out] out_val pointer to uint32_t to store result of conversion
526 * @return non-zero number of characters processed on succeed, 597 * @return non-zero number of characters processed on succeed,
527 * zero if no digit is found, resulting value is larger 598 * zero if no digit is found, resulting value is larger
528 * then possible to store in uint32_t or @a out_val is NULL 599 * then possible to store in uint32_t or @a out_val is NULL
529 */ 600 */
530size_t 601size_t
531MHD_strx_to_uint32_n_ (const char * str, size_t maxlen, uint32_t * out_val) 602MHD_strx_to_uint32_n_ (const char *str,
603 size_t maxlen,
604 uint32_t *out_val)
532{ 605{
533 size_t i; 606 size_t i;
534 uint32_t res; 607 uint32_t res;
535 int digit; 608 int digit;
536 if (!str || !out_val) 609 if (!str || !out_val)
537 return 0; 610 return 0;
538 611
539 res = 0; 612 res = 0;
540 i = 0; 613 i = 0;
541 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 614 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
@@ -558,14 +631,16 @@ MHD_strx_to_uint32_n_ (const char * str, size_t maxlen, uint32_t * out_val)
558/** 631/**
559 * Convert hexadecimal US-ASCII digits in string to number in uint64_t. 632 * Convert hexadecimal US-ASCII digits in string to number in uint64_t.
560 * Conversion stopped at first non-digit character. 633 * Conversion stopped at first non-digit character.
634 *
561 * @param str string to convert 635 * @param str string to convert
562 * @param out_val pointer to uint64_t to store result of conversion 636 * @param[out] out_val pointer to uint64_t to store result of conversion
563 * @return non-zero number of characters processed on succeed, 637 * @return non-zero number of characters processed on succeed,
564 * zero if no digit is found, resulting value is larger 638 * zero if no digit is found, resulting value is larger
565 * then possible to store in uint64_t or @a out_val is NULL 639 * then possible to store in uint64_t or @a out_val is NULL
566 */ 640 */
567size_t 641size_t
568MHD_strx_to_uint64_ (const char * str, uint64_t * out_val) 642MHD_strx_to_uint64_ (const char *str,
643 uint64_t *out_val)
569{ 644{
570 const char * const start = str; 645 const char * const start = str;
571 uint64_t res; 646 uint64_t res;
@@ -598,24 +673,27 @@ MHD_strx_to_uint64_ (const char * str, uint64_t * out_val)
598/** 673/**
599 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 674 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
600 * to number in uint64_t. 675 * to number in uint64_t.
601 * Conversion stopped at first non-digit character or after @a maxlen 676 * Conversion stopped at first non-digit character or after @a maxlen
602 * digits. 677 * digits.
678 *
603 * @param str string to convert 679 * @param str string to convert
604 * @param maxlen maximum number of characters to process 680 * @param maxlen maximum number of characters to process
605 * @param out_val pointer to uint64_t to store result of conversion 681 * @param[out] out_val pointer to uint64_t to store result of conversion
606 * @return non-zero number of characters processed on succeed, 682 * @return non-zero number of characters processed on succeed,
607 * zero if no digit is found, resulting value is larger 683 * zero if no digit is found, resulting value is larger
608 * then possible to store in uint64_t or @a out_val is NULL 684 * then possible to store in uint64_t or @a out_val is NULL
609 */ 685 */
610size_t 686size_t
611MHD_strx_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val) 687MHD_strx_to_uint64_n_ (const char * str,
688 size_t maxlen,
689 uint64_t *out_val)
612{ 690{
613 size_t i; 691 size_t i;
614 uint64_t res; 692 uint64_t res;
615 int digit; 693 int digit;
616 if (!str || !out_val) 694 if (!str || !out_val)
617 return 0; 695 return 0;
618 696
619 res = 0; 697 res = 0;
620 i = 0; 698 i = 0;
621 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 699 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
@@ -639,9 +717,10 @@ MHD_strx_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
639/** 717/**
640 * Generic function for converting not more then @a maxlen 718 * Generic function for converting not more then @a maxlen
641 * hexadecimal or decimal US-ASCII digits in string to number. 719 * hexadecimal or decimal US-ASCII digits in string to number.
642 * Conversion stopped at first non-digit character or after @a maxlen 720 * Conversion stopped at first non-digit character or after @a maxlen
643 * digits. 721 * digits.
644 * To be used only within macro. 722 * To be used only within macro.
723 *
645 * @param str the string to convert 724 * @param str the string to convert
646 * @param maxlen the maximum number of characters to process 725 * @param maxlen the maximum number of characters to process
647 * @param out_val the pointer to variable to store result of conversion 726 * @param out_val the pointer to variable to store result of conversion
@@ -653,8 +732,12 @@ MHD_strx_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
653 * then @max_val, @val_size is not 16/32 or @a out_val is NULL 732 * then @max_val, @val_size is not 16/32 or @a out_val is NULL
654 */ 733 */
655size_t 734size_t
656MHD_str_to_uvalue_n_ (const char * str, size_t maxlen, 735MHD_str_to_uvalue_n_ (const char *str,
657 void * out_val, size_t val_size, uint64_t max_val, int base) 736 size_t maxlen,
737 void * out_val,
738 size_t val_size,
739 uint64_t max_val,
740 int base)
658{ 741{
659 size_t i; 742 size_t i;
660 uint64_t res; 743 uint64_t res;
@@ -664,6 +747,7 @@ MHD_str_to_uvalue_n_ (const char * str, size_t maxlen,
664 /* 'digit->value' must be function, not macro */ 747 /* 'digit->value' must be function, not macro */
665 int (*const dfunc)(char) = (base == 16) ? 748 int (*const dfunc)(char) = (base == 16) ?
666 toxdigitvalue : todigitvalue; 749 toxdigitvalue : todigitvalue;
750
667 if ( !str || !out_val || 751 if ( !str || !out_val ||
668 (base != 16 && base != 10) ) 752 (base != 16 && base != 10) )
669 return 0; 753 return 0;
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c
index 80a320c8..6f2e34ce 100644
--- a/src/microhttpd/mhd_threads.c
+++ b/src/microhttpd/mhd_threads.c
@@ -56,13 +56,17 @@ typedef DWORD MHD_thread_ID_;
56#if defined(MHD_USE_POSIX_THREADS) 56#if defined(MHD_USE_POSIX_THREADS)
57#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \ 57#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
58 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) 58 || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
59
59/** 60/**
60 * Set thread name 61 * Set thread name
62 *
61 * @param thread_id ID of thread 63 * @param thread_id ID of thread
62 * @param thread_name name to set 64 * @param thread_name name to set
63 * @return non-zero on success, zero otherwise 65 * @return non-zero on success, zero otherwise
64 */ 66 */
65static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name) 67static int
68MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
69 const char *thread_name)
66{ 70{
67 if (NULL == thread_name) 71 if (NULL == thread_name)
68 return 0; 72 return 0;
@@ -110,11 +114,14 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre
110#else /* _MSC_FULL_VER */ 114#else /* _MSC_FULL_VER */
111/** 115/**
112 * Set thread name 116 * Set thread name
117 *
113 * @param thread_id ID of thread, -1 for current thread 118 * @param thread_id ID of thread, -1 for current thread
114 * @param thread_name name to set 119 * @param thread_name name to set
115 * @return non-zero on success, zero otherwise 120 * @return non-zero on success, zero otherwise
116 */ 121 */
117static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name) 122static int
123MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
124 const char *thread_name)
118{ 125{
119 static const DWORD VC_SETNAME_EXC = 0x406D1388; 126 static const DWORD VC_SETNAME_EXC = 0x406D1388;
120#pragma pack(push,8) 127#pragma pack(push,8)
@@ -137,7 +144,10 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre
137 144
138 __try 145 __try
139 { /* This exception is intercepted by debugger */ 146 { /* This exception is intercepted by debugger */
140 RaiseException(VC_SETNAME_EXC, 0, sizeof(thread_info) / sizeof(ULONG_PTR), (ULONG_PTR*)&thread_info); 147 RaiseException (VC_SETNAME_EXC,
148 0,
149 sizeof (thread_info) / sizeof(ULONG_PTR),
150 (ULONG_PTR *) &thread_info);
141 } 151 }
142 __except (EXCEPTION_EXECUTE_HANDLER) 152 __except (EXCEPTION_EXECUTE_HANDLER)
143 {} 153 {}
@@ -182,15 +192,21 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
182 res = pthread_attr_init (&attr); 192 res = pthread_attr_init (&attr);
183 if (0 == res) 193 if (0 == res)
184 { 194 {
185 res = pthread_attr_setstacksize (&attr, stack_size); 195 res = pthread_attr_setstacksize (&attr,
196 stack_size);
186 if (0 == res) 197 if (0 == res)
187 res = pthread_create (thread, &attr, 198 res = pthread_create (thread,
188 start_routine, arg); 199 &attr,
200 start_routine,
201 arg);
189 pthread_attr_destroy (&attr); 202 pthread_attr_destroy (&attr);
190 } 203 }
191 } 204 }
192 else 205 else
193 res = pthread_create (thread, NULL, start_routine, arg); 206 res = pthread_create (thread,
207 NULL,
208 start_routine,
209 arg);
194 210
195 if (0 != res) 211 if (0 != res)
196 errno = res; 212 errno = res;
@@ -205,8 +221,12 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
205 } 221 }
206#endif /* SIZE_MAX != UINT_MAX */ 222#endif /* SIZE_MAX != UINT_MAX */
207 223
208 *thread = (HANDLE)_beginthreadex(NULL, (unsigned)stack_size, start_routine, 224 *thread = (HANDLE) _beginthreadex (NULL,
209 arg, 0, NULL); 225 (unsigned int) stack_size,
226 start_routine,
227 arg,
228 0,
229 NULL);
210 if ((MHD_thread_handle_)-1 == (*thread)) 230 if ((MHD_thread_handle_)-1 == (*thread))
211 return 0; 231 return 0;
212 232
@@ -234,6 +254,7 @@ struct MHD_named_helper_param_
234 const char *name; 254 const char *name;
235}; 255};
236 256
257
237static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ 258static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
238named_thread_starter (void *data) 259named_thread_starter (void *data)
239{ 260{
@@ -245,7 +266,7 @@ named_thread_starter (void *data)
245 if (NULL == data) 266 if (NULL == data)
246 return (MHD_THRD_RTRN_TYPE_)0; 267 return (MHD_THRD_RTRN_TYPE_)0;
247 268
248 MHD_set_cur_thread_name_(param->name); 269 MHD_set_cur_thread_name_ (param->name);
249 270
250 arg = param->arg; 271 arg = param->arg;
251 thr_func = param->start_routine; 272 thr_func = param->start_routine;
@@ -255,7 +276,6 @@ named_thread_starter (void *data)
255} 276}
256 277
257 278
258
259/** 279/**
260 * Create a named thread and set the attributes according to our options. 280 * Create a named thread and set the attributes according to our options.
261 * 281 *
@@ -273,7 +293,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
273 MHD_THREAD_START_ROUTINE_ start_routine, 293 MHD_THREAD_START_ROUTINE_ start_routine,
274 void *arg) 294 void *arg)
275{ 295{
276 struct MHD_named_helper_param_ * param; 296 struct MHD_named_helper_param_ *param;
277 297
278 if (NULL == thread_name) 298 if (NULL == thread_name)
279 { 299 {
@@ -281,7 +301,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
281 return 0; 301 return 0;
282 } 302 }
283 303
284 param = malloc(sizeof(struct MHD_named_helper_param_)); 304 param = malloc (sizeof (struct MHD_named_helper_param_));
285 if (NULL == param) 305 if (NULL == param)
286 return 0; 306 return 0;
287 307
@@ -292,9 +312,12 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
292 /* Set thread name in thread itself to avoid problems with 312 /* Set thread name in thread itself to avoid problems with
293 * threads which terminated before name is set in other thread. 313 * threads which terminated before name is set in other thread.
294 */ 314 */
295 if (!MHD_create_thread_(thread, stack_size, &named_thread_starter, (void*)param)) 315 if (! MHD_create_thread_(thread,
316 stack_size,
317 &named_thread_starter,
318 (void*)param))
296 { 319 {
297 free(param); 320 free (param);
298 return 0; 321 return 0;
299 } 322 }
300 323
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index c8739042..287e03a2 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -187,7 +187,7 @@ struct MHD_PostProcessor
187 size_t buffer_pos; 187 size_t buffer_pos;
188 188
189 /** 189 /**
190 * Current position in xbuf. 190 * Current position in @e xbuf.
191 */ 191 */
192 size_t xbuf_pos; 192 size_t xbuf_pos;
193 193
@@ -272,26 +272,34 @@ struct MHD_PostProcessor
272struct MHD_PostProcessor * 272struct MHD_PostProcessor *
273MHD_create_post_processor (struct MHD_Connection *connection, 273MHD_create_post_processor (struct MHD_Connection *connection,
274 size_t buffer_size, 274 size_t buffer_size,
275 MHD_PostDataIterator iter, void *iter_cls) 275 MHD_PostDataIterator iter,
276 void *iter_cls)
276{ 277{
277 struct MHD_PostProcessor *ret; 278 struct MHD_PostProcessor *ret;
278 const char *encoding; 279 const char *encoding;
279 const char *boundary; 280 const char *boundary;
280 size_t blen; 281 size_t blen;
281 282
282 if ((buffer_size < 256) || (connection == NULL) || (iter == NULL)) 283 if ( (buffer_size < 256) ||
283 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); 284 (NULL == connection) ||
285 (NULL == iter))
286 mhd_panic (mhd_panic_cls,
287 __FILE__,
288 __LINE__,
289 NULL);
284 encoding = MHD_lookup_connection_value (connection, 290 encoding = MHD_lookup_connection_value (connection,
285 MHD_HEADER_KIND, 291 MHD_HEADER_KIND,
286 MHD_HTTP_HEADER_CONTENT_TYPE); 292 MHD_HTTP_HEADER_CONTENT_TYPE);
287 if (encoding == NULL) 293 if (NULL == encoding)
288 return NULL; 294 return NULL;
289 boundary = NULL; 295 boundary = NULL;
290 if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding, 296 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
291 strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 297 encoding,
298 strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
292 { 299 {
293 if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding, 300 if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
294 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 301 encoding,
302 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
295 return NULL; 303 return NULL;
296 boundary = 304 boundary =
297 &encoding[strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)]; 305 &encoding[strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
@@ -301,9 +309,11 @@ MHD_create_post_processor (struct MHD_Connection *connection,
301 return NULL; /* failed to determine boundary */ 309 return NULL; /* failed to determine boundary */
302 boundary += strlen ("boundary="); 310 boundary += strlen ("boundary=");
303 blen = strlen (boundary); 311 blen = strlen (boundary);
304 if ((blen == 0) || (blen * 2 + 2 > buffer_size)) 312 if ( (blen == 0) ||
313 (blen * 2 + 2 > buffer_size) )
305 return NULL; /* (will be) out of memory or invalid boundary */ 314 return NULL; /* (will be) out of memory or invalid boundary */
306 if ( (boundary[0] == '"') && (boundary[blen - 1] == '"') ) 315 if ( (boundary[0] == '"') &&
316 (boundary[blen - 1] == '"') )
307 { 317 {
308 /* remove enclosing quotes */ 318 /* remove enclosing quotes */
309 ++boundary; 319 ++boundary;
@@ -317,7 +327,9 @@ MHD_create_post_processor (struct MHD_Connection *connection,
317 /* add +1 to ensure we ALWAYS have a zero-termination at the end */ 327 /* add +1 to ensure we ALWAYS have a zero-termination at the end */
318 if (NULL == (ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1))) 328 if (NULL == (ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1)))
319 return NULL; 329 return NULL;
320 memset (ret, 0, sizeof (struct MHD_PostProcessor) + buffer_size + 1); 330 memset (ret,
331 0,
332 sizeof (struct MHD_PostProcessor) + buffer_size + 1);
321 ret->connection = connection; 333 ret->connection = connection;
322 ret->ikvi = iter; 334 ret->ikvi = iter;
323 ret->cls = iter_cls; 335 ret->cls = iter_cls;
@@ -420,16 +432,20 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
420 if so, exclude those from processing (reduce delta to point at 432 if so, exclude those from processing (reduce delta to point at
421 end of processed region) */ 433 end of processed region) */
422 delta = xoff; 434 delta = xoff;
423 if ((delta > 0) && (xbuf[delta - 1] == '%')) 435 if ((delta > 0) &&
436 ('%' == xbuf[delta - 1]))
424 delta--; 437 delta--;
425 else if ((delta > 1) && (xbuf[delta - 2] == '%')) 438 else if ((delta > 1) &&
439 ('%' == xbuf[delta - 2]))
426 delta -= 2; 440 delta -= 2;
427 441
428 /* if we have an incomplete escape sequence, save it to 442 /* if we have an incomplete escape sequence, save it to
429 pp->xbuf for later */ 443 pp->xbuf for later */
430 if (delta < xoff) 444 if (delta < xoff)
431 { 445 {
432 memcpy (pp->xbuf, &xbuf[delta], xoff - delta); 446 memcpy (pp->xbuf,
447 &xbuf[delta],
448 xoff - delta);
433 pp->xbuf_pos = xoff - delta; 449 pp->xbuf_pos = xoff - delta;
434 xoff = delta; 450 xoff = delta;
435 } 451 }
@@ -437,7 +453,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
437 /* If we have nothing to do (delta == 0) and 453 /* If we have nothing to do (delta == 0) and
438 not just because the value is empty (are 454 not just because the value is empty (are
439 waiting for more data), go for next iteration */ 455 waiting for more data), go for next iteration */
440 if ((xoff == 0) && (poff == post_data_len)) 456 if ( (0 == xoff) &&
457 (poff == post_data_len))
441 continue; 458 continue;
442 459
443 /* unescape */ 460 /* unescape */
@@ -446,8 +463,14 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
446 xoff = MHD_http_unescape (xbuf); 463 xoff = MHD_http_unescape (xbuf);
447 /* finally: call application! */ 464 /* finally: call application! */
448 pp->must_ikvi = MHD_NO; 465 pp->must_ikvi = MHD_NO;
449 if (MHD_NO == pp->ikvi (pp->cls, MHD_POSTDATA_KIND, (const char *) &pp[1], /* key */ 466 if (MHD_NO == pp->ikvi (pp->cls,
450 NULL, NULL, NULL, xbuf, pp->value_offset, 467 MHD_POSTDATA_KIND,
468 (const char *) &pp[1], /* key */
469 NULL,
470 NULL,
471 NULL,
472 xbuf,
473 pp->value_offset,
451 xoff)) 474 xoff))
452 { 475 {
453 pp->state = PP_Error; 476 pp->state = PP_Error;
@@ -459,11 +482,12 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
459 if (end_of_value_found) 482 if (end_of_value_found)
460 { 483 {
461 /* we found the end of the value! */ 484 /* we found the end of the value! */
462 if ((post_data[poff] == '\n') || (post_data[poff] == '\r')) 485 if ( ('\n' == post_data[poff]) ||
486 ('\r' == post_data[poff]) )
463 { 487 {
464 pp->state = PP_ExpectNewLine; 488 pp->state = PP_ExpectNewLine;
465 } 489 }
466 else if (post_data[poff] == '&') 490 else if ('&' == post_data[poff])
467 { 491 {
468 poff++; /* skip '&' */ 492 poff++; /* skip '&' */
469 pp->state = PP_Init; 493 pp->state = PP_Init;
@@ -471,7 +495,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
471 } 495 }
472 break; 496 break;
473 case PP_ExpectNewLine: 497 case PP_ExpectNewLine:
474 if ((post_data[poff] == '\n') || (post_data[poff] == '\r')) 498 if ( ('\n' == post_data[poff]) ||
499 ('\r' == post_data[poff]) )
475 { 500 {
476 poff++; 501 poff++;
477 /* we are done, report error if we receive any more... */ 502 /* we are done, report error if we receive any more... */
@@ -480,7 +505,10 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
480 } 505 }
481 return MHD_NO; 506 return MHD_NO;
482 default: 507 default:
483 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */ 508 mhd_panic (mhd_panic_cls,
509 __FILE__,
510 __LINE__,
511 NULL); /* should never happen! */
484 } 512 }
485 } 513 }
486 return MHD_YES; 514 return MHD_YES;
@@ -497,13 +525,17 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
497 * @return #MHD_YES if there was a match, #MHD_NO if not 525 * @return #MHD_YES if there was a match, #MHD_NO if not
498 */ 526 */
499static int 527static int
500try_match_header (const char *prefix, char *line, char **suffix) 528try_match_header (const char *prefix,
529 char *line,
530 char **suffix)
501{ 531{
502 if (NULL != *suffix) 532 if (NULL != *suffix)
503 return MHD_NO; 533 return MHD_NO;
504 while (*line != 0) 534 while (0 != *line)
505 { 535 {
506 if (MHD_str_equal_caseless_n_ (prefix, line, strlen (prefix))) 536 if (MHD_str_equal_caseless_n_ (prefix,
537 line,
538 strlen (prefix)))
507 { 539 {
508 *suffix = strdup (&line[strlen (prefix)]); 540 *suffix = strdup (&line[strlen (prefix)]);
509 return MHD_YES; 541 return MHD_YES;
@@ -532,7 +564,8 @@ find_boundary (struct MHD_PostProcessor *pp,
532 const char *boundary, 564 const char *boundary,
533 size_t blen, 565 size_t blen,
534 size_t *ioffptr, 566 size_t *ioffptr,
535 enum PP_State next_state, enum PP_State next_dash_state) 567 enum PP_State next_state,
568 enum PP_State next_dash_state)
536{ 569{
537 char *buf = (char *) &pp[1]; 570 char *buf = (char *) &pp[1];
538 const char *dash; 571 const char *dash;
@@ -544,7 +577,12 @@ find_boundary (struct MHD_PostProcessor *pp,
544 /* ++(*ioffptr); */ 577 /* ++(*ioffptr); */
545 return MHD_NO; /* not enough data */ 578 return MHD_NO; /* not enough data */
546 } 579 }
547 if ((0 != memcmp ("--", buf, 2)) || (0 != memcmp (&buf[2], boundary, blen))) 580 if ( (0 != memcmp ("--",
581 buf,
582 2)) ||
583 (0 != memcmp (&buf[2],
584 boundary,
585 blen)))
548 { 586 {
549 if (pp->state != PP_Init) 587 if (pp->state != PP_Init)
550 { 588 {
@@ -554,7 +592,9 @@ find_boundary (struct MHD_PostProcessor *pp,
554 else 592 else
555 { 593 {
556 /* skip over garbage (RFC 2046, 5.1.1) */ 594 /* skip over garbage (RFC 2046, 5.1.1) */
557 dash = memchr (buf, '-', pp->buffer_pos); 595 dash = memchr (buf,
596 '-',
597 pp->buffer_pos);
558 if (NULL == dash) 598 if (NULL == dash)
559 (*ioffptr) += pp->buffer_pos; /* skip entire buffer */ 599 (*ioffptr) += pp->buffer_pos; /* skip entire buffer */
560 else 600 else
@@ -598,7 +638,9 @@ try_get_value (const char *buf,
598 klen = strlen (key); 638 klen = strlen (key);
599 while (NULL != (spos = strstr (bpos, key))) 639 while (NULL != (spos = strstr (bpos, key)))
600 { 640 {
601 if ((spos[klen] != '=') || ((spos != buf) && (spos[-1] != ' '))) 641 if ( (spos[klen] != '=') ||
642 ( (spos != buf) &&
643 (spos[-1] != ' ') ) )
602 { 644 {
603 /* no match */ 645 /* no match */
604 bpos = spos + 1; 646 bpos = spos + 1;
@@ -606,14 +648,17 @@ try_get_value (const char *buf,
606 } 648 }
607 if (spos[klen + 1] != '"') 649 if (spos[klen + 1] != '"')
608 return; /* not quoted */ 650 return; /* not quoted */
609 if (NULL == (endv = strchr (&spos[klen + 2], '\"'))) 651 if (NULL == (endv = strchr (&spos[klen + 2],
652 '\"')))
610 return; /* no end-quote */ 653 return; /* no end-quote */
611 vlen = endv - spos - klen - 1; 654 vlen = endv - spos - klen - 1;
612 *destination = malloc (vlen); 655 *destination = malloc (vlen);
613 if (NULL == *destination) 656 if (NULL == *destination)
614 return; /* out of memory */ 657 return; /* out of memory */
615 (*destination)[vlen - 1] = '\0'; 658 (*destination)[vlen - 1] = '\0';
616 memcpy (*destination, &spos[klen + 2], vlen - 1); 659 memcpy (*destination,
660 &spos[klen + 2],
661 vlen - 1);
617 return; /* success */ 662 return; /* success */
618 } 663 }
619} 664}
@@ -636,14 +681,16 @@ try_get_value (const char *buf,
636 */ 681 */
637static int 682static int
638process_multipart_headers (struct MHD_PostProcessor *pp, 683process_multipart_headers (struct MHD_PostProcessor *pp,
639 size_t *ioffptr, enum PP_State next_state) 684 size_t *ioffptr,
685 enum PP_State next_state)
640{ 686{
641 char *buf = (char *) &pp[1]; 687 char *buf = (char *) &pp[1];
642 size_t newline; 688 size_t newline;
643 689
644 newline = 0; 690 newline = 0;
645 while ((newline < pp->buffer_pos) && 691 while ( (newline < pp->buffer_pos) &&
646 (buf[newline] != '\r') && (buf[newline] != '\n')) 692 (buf[newline] != '\r') &&
693 (buf[newline] != '\n') )
647 newline++; 694 newline++;
648 if (newline == pp->buffer_size) 695 if (newline == pp->buffer_size)
649 { 696 {
@@ -664,18 +711,24 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
664 pp->skip_rn = RN_OptN; 711 pp->skip_rn = RN_OptN;
665 buf[newline] = '\0'; 712 buf[newline] = '\0';
666 if (MHD_str_equal_caseless_n_ ("Content-disposition: ", 713 if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
667 buf, strlen ("Content-disposition: "))) 714 buf,
715 strlen ("Content-disposition: ")))
668 { 716 {
669 try_get_value (&buf[strlen ("Content-disposition: ")], 717 try_get_value (&buf[strlen ("Content-disposition: ")],
670 "name", &pp->content_name); 718 "name",
719 &pp->content_name);
671 try_get_value (&buf[strlen ("Content-disposition: ")], 720 try_get_value (&buf[strlen ("Content-disposition: ")],
672 "filename", &pp->content_filename); 721 "filename",
722 &pp->content_filename);
673 } 723 }
674 else 724 else
675 { 725 {
676 try_match_header ("Content-type: ", buf, &pp->content_type); 726 try_match_header ("Content-type: ",
727 buf,
728 &pp->content_type);
677 try_match_header ("Content-Transfer-Encoding: ", 729 try_match_header ("Content-Transfer-Encoding: ",
678 buf, &pp->content_transfer_encoding); 730 buf,
731 &pp->content_transfer_encoding);
679 } 732 }
680 (*ioffptr) += newline + 1; 733 (*ioffptr) += newline + 1;
681 return MHD_YES; 734 return MHD_YES;
@@ -717,21 +770,27 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
717 { 770 {
718 while (newline + 4 < pp->buffer_pos) 771 while (newline + 4 < pp->buffer_pos)
719 { 772 {
720 r = memchr (&buf[newline], '\r', pp->buffer_pos - newline - 4); 773 r = memchr (&buf[newline],
774 '\r',
775 pp->buffer_pos - newline - 4);
721 if (NULL == r) 776 if (NULL == r)
722 { 777 {
723 newline = pp->buffer_pos - 4; 778 newline = pp->buffer_pos - 4;
724 break; 779 break;
725 } 780 }
726 newline = r - buf; 781 newline = r - buf;
727 if (0 == memcmp ("\r\n--", &buf[newline], 4)) 782 if (0 == memcmp ("\r\n--",
783 &buf[newline],
784 4))
728 break; 785 break;
729 newline++; 786 newline++;
730 } 787 }
731 if (newline + pp->blen + 4 <= pp->buffer_pos) 788 if (newline + pp->blen + 4 <= pp->buffer_pos)
732 { 789 {
733 /* can check boundary */ 790 /* can check boundary */
734 if (0 != memcmp (&buf[newline + 4], boundary, pp->blen)) 791 if (0 != memcmp (&buf[newline + 4],
792 boundary,
793 pp->blen))
735 { 794 {
736 /* no boundary, "\r\n--" is part of content, skip */ 795 /* no boundary, "\r\n--" is part of content, skip */
737 newline += 4; 796 newline += 4;
@@ -754,7 +813,8 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
754 /* cannot check for boundary, process content that 813 /* cannot check for boundary, process content that
755 we have and check again later; except, if we have 814 we have and check again later; except, if we have
756 no content, abort (out of memory) */ 815 no content, abort (out of memory) */
757 if ((0 == newline) && (pp->buffer_pos == pp->buffer_size)) 816 if ( (0 == newline) &&
817 (pp->buffer_pos == pp->buffer_size) )
758 { 818 {
759 pp->state = PP_Error; 819 pp->state = PP_Error;
760 return MHD_NO; 820 return MHD_NO;
@@ -773,7 +833,9 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
773 pp->content_filename, 833 pp->content_filename,
774 pp->content_type, 834 pp->content_type,
775 pp->content_transfer_encoding, 835 pp->content_transfer_encoding,
776 buf, pp->value_offset, newline)) ) 836 buf,
837 pp->value_offset,
838 newline)) )
777 { 839 {
778 pp->state = PP_Error; 840 pp->state = PP_Error;
779 return MHD_NO; 841 return MHD_NO;
@@ -792,24 +854,26 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
792static void 854static void
793free_unmarked (struct MHD_PostProcessor *pp) 855free_unmarked (struct MHD_PostProcessor *pp)
794{ 856{
795 if ((NULL != pp->content_name) && (0 == (pp->have & NE_content_name))) 857 if ( (NULL != pp->content_name) &&
858 (0 == (pp->have & NE_content_name)) )
796 { 859 {
797 free (pp->content_name); 860 free (pp->content_name);
798 pp->content_name = NULL; 861 pp->content_name = NULL;
799 } 862 }
800 if ((NULL != pp->content_type) && (0 == (pp->have & NE_content_type))) 863 if ( (NULL != pp->content_type) &&
864 (0 == (pp->have & NE_content_type)) )
801 { 865 {
802 free (pp->content_type); 866 free (pp->content_type);
803 pp->content_type = NULL; 867 pp->content_type = NULL;
804 } 868 }
805 if ((NULL != pp->content_filename) && 869 if ( (NULL != pp->content_filename) &&
806 (0 == (pp->have & NE_content_filename))) 870 (0 == (pp->have & NE_content_filename)) )
807 { 871 {
808 free (pp->content_filename); 872 free (pp->content_filename);
809 pp->content_filename = NULL; 873 pp->content_filename = NULL;
810 } 874 }
811 if ((NULL != pp->content_transfer_encoding) && 875 if ( (NULL != pp->content_transfer_encoding) &&
812 (0 == (pp->have & NE_content_transfer_encoding))) 876 (0 == (pp->have & NE_content_transfer_encoding)) )
813 { 877 {
814 free (pp->content_transfer_encoding); 878 free (pp->content_transfer_encoding);
815 pp->content_transfer_encoding = NULL; 879 pp->content_transfer_encoding = NULL;
@@ -840,18 +904,23 @@ post_process_multipart (struct MHD_PostProcessor *pp,
840 ioff = 0; 904 ioff = 0;
841 poff = 0; 905 poff = 0;
842 state_changed = 1; 906 state_changed = 1;
843 while ((poff < post_data_len) || 907 while ( (poff < post_data_len) ||
844 ((pp->buffer_pos > 0) && (state_changed != 0))) 908 ( (pp->buffer_pos > 0) &&
909 (0 != state_changed) ) )
845 { 910 {
846 /* first, move as much input data 911 /* first, move as much input data
847 as possible to our internal buffer */ 912 as possible to our internal buffer */
848 max = pp->buffer_size - pp->buffer_pos; 913 max = pp->buffer_size - pp->buffer_pos;
849 if (max > post_data_len - poff) 914 if (max > post_data_len - poff)
850 max = post_data_len - poff; 915 max = post_data_len - poff;
851 memcpy (&buf[pp->buffer_pos], &post_data[poff], max); 916 memcpy (&buf[pp->buffer_pos],
917 &post_data[poff],
918 max);
852 poff += max; 919 poff += max;
853 pp->buffer_pos += max; 920 pp->buffer_pos += max;
854 if ((max == 0) && (state_changed == 0) && (poff < post_data_len)) 921 if ( (0 == max) &&
922 (0 == state_changed) &&
923 (poff < post_data_len) )
855 { 924 {
856 pp->state = PP_Error; 925 pp->state = PP_Error;
857 return MHD_NO; /* out of memory */ 926 return MHD_NO; /* out of memory */
@@ -883,7 +952,8 @@ post_process_multipart (struct MHD_PostProcessor *pp,
883 case RN_Full: 952 case RN_Full:
884 if (buf[0] == '\r') 953 if (buf[0] == '\r')
885 { 954 {
886 if ((pp->buffer_pos > 1) && (buf[1] == '\n')) 955 if ( (pp->buffer_pos > 1) &&
956 ('\n' == buf[1]) )
887 { 957 {
888 pp->skip_rn = RN_Inactive; 958 pp->skip_rn = RN_Inactive;
889 ioff += 2; 959 ioff += 2;
@@ -941,14 +1011,16 @@ post_process_multipart (struct MHD_PostProcessor *pp,
941 pp->boundary, 1011 pp->boundary,
942 pp->blen, 1012 pp->blen,
943 &ioff, 1013 &ioff,
944 PP_ProcessEntryHeaders, PP_Done); 1014 PP_ProcessEntryHeaders,
1015 PP_Done);
945 break; 1016 break;
946 case PP_NextBoundary: 1017 case PP_NextBoundary:
947 if (MHD_NO == find_boundary (pp, 1018 if (MHD_NO == find_boundary (pp,
948 pp->boundary, 1019 pp->boundary,
949 pp->blen, 1020 pp->blen,
950 &ioff, 1021 &ioff,
951 PP_ProcessEntryHeaders, PP_Done)) 1022 PP_ProcessEntryHeaders,
1023 PP_Done))
952 { 1024 {
953 if (pp->state == PP_Error) 1025 if (pp->state == PP_Error)
954 return MHD_NO; 1026 return MHD_NO;
@@ -958,7 +1030,9 @@ post_process_multipart (struct MHD_PostProcessor *pp,
958 case PP_ProcessEntryHeaders: 1030 case PP_ProcessEntryHeaders:
959 pp->must_ikvi = MHD_YES; 1031 pp->must_ikvi = MHD_YES;
960 if (MHD_NO == 1032 if (MHD_NO ==
961 process_multipart_headers (pp, &ioff, PP_PerformCheckMultipart)) 1033 process_multipart_headers (pp,
1034 &ioff,
1035 PP_PerformCheckMultipart))
962 { 1036 {
963 if (pp->state == PP_Error) 1037 if (pp->state == PP_Error)
964 return MHD_NO; 1038 return MHD_NO;
@@ -968,20 +1042,21 @@ post_process_multipart (struct MHD_PostProcessor *pp,
968 state_changed = 1; 1042 state_changed = 1;
969 break; 1043 break;
970 case PP_PerformCheckMultipart: 1044 case PP_PerformCheckMultipart:
971 if ((pp->content_type != NULL) && 1045 if ( (NULL != pp->content_type) &&
972 (MHD_str_equal_caseless_n_ (pp->content_type, 1046 (MHD_str_equal_caseless_n_ (pp->content_type,
973 "multipart/mixed", 1047 "multipart/mixed",
974 strlen ("multipart/mixed")))) 1048 strlen ("multipart/mixed"))))
975 { 1049 {
976 pp->nested_boundary = strstr (pp->content_type, "boundary="); 1050 pp->nested_boundary = strstr (pp->content_type,
977 if (pp->nested_boundary == NULL) 1051 "boundary=");
1052 if (NULL == pp->nested_boundary)
978 { 1053 {
979 pp->state = PP_Error; 1054 pp->state = PP_Error;
980 return MHD_NO; 1055 return MHD_NO;
981 } 1056 }
982 pp->nested_boundary = 1057 pp->nested_boundary =
983 strdup (&pp->nested_boundary[strlen ("boundary=")]); 1058 strdup (&pp->nested_boundary[strlen ("boundary=")]);
984 if (pp->nested_boundary == NULL) 1059 if (NULL == pp->nested_boundary)
985 { 1060 {
986 /* out of memory */ 1061 /* out of memory */
987 pp->state = PP_Error; 1062 pp->state = PP_Error;
@@ -1017,7 +1092,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
1017 /* clean up state of one multipart form-data element! */ 1092 /* clean up state of one multipart form-data element! */
1018 pp->have = NE_none; 1093 pp->have = NE_none;
1019 free_unmarked (pp); 1094 free_unmarked (pp);
1020 if (pp->nested_boundary != NULL) 1095 if (NULL != pp->nested_boundary)
1021 { 1096 {
1022 free (pp->nested_boundary); 1097 free (pp->nested_boundary);
1023 pp->nested_boundary = NULL; 1098 pp->nested_boundary = NULL;
@@ -1026,7 +1101,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
1026 state_changed = 1; 1101 state_changed = 1;
1027 break; 1102 break;
1028 case PP_Nested_Init: 1103 case PP_Nested_Init:
1029 if (pp->nested_boundary == NULL) 1104 if (NULL == pp->nested_boundary)
1030 { 1105 {
1031 pp->state = PP_Error; 1106 pp->state = PP_Error;
1032 return MHD_NO; 1107 return MHD_NO;
@@ -1047,13 +1122,13 @@ post_process_multipart (struct MHD_PostProcessor *pp,
1047 /* remember what headers were given 1122 /* remember what headers were given
1048 globally */ 1123 globally */
1049 pp->have = NE_none; 1124 pp->have = NE_none;
1050 if (pp->content_name != NULL) 1125 if (NULL != pp->content_name)
1051 pp->have |= NE_content_name; 1126 pp->have |= NE_content_name;
1052 if (pp->content_type != NULL) 1127 if (NULL != pp->content_type)
1053 pp->have |= NE_content_type; 1128 pp->have |= NE_content_type;
1054 if (pp->content_filename != NULL) 1129 if (NULL != pp->content_filename)
1055 pp->have |= NE_content_filename; 1130 pp->have |= NE_content_filename;
1056 if (pp->content_transfer_encoding != NULL) 1131 if (NULL != pp->content_transfer_encoding)
1057 pp->have |= NE_content_transfer_encoding; 1132 pp->have |= NE_content_transfer_encoding;
1058 pp->state = PP_Nested_ProcessEntryHeaders; 1133 pp->state = PP_Nested_ProcessEntryHeaders;
1059 state_changed = 1; 1134 state_changed = 1;
@@ -1061,7 +1136,8 @@ post_process_multipart (struct MHD_PostProcessor *pp,
1061 case PP_Nested_ProcessEntryHeaders: 1136 case PP_Nested_ProcessEntryHeaders:
1062 pp->value_offset = 0; 1137 pp->value_offset = 0;
1063 if (MHD_NO == 1138 if (MHD_NO ==
1064 process_multipart_headers (pp, &ioff, 1139 process_multipart_headers (pp,
1140 &ioff,
1065 PP_Nested_ProcessValueToBoundary)) 1141 PP_Nested_ProcessValueToBoundary))
1066 { 1142 {
1067 if (pp->state == PP_Error) 1143 if (pp->state == PP_Error)
@@ -1090,21 +1166,28 @@ post_process_multipart (struct MHD_PostProcessor *pp,
1090 state_changed = 1; 1166 state_changed = 1;
1091 break; 1167 break;
1092 default: 1168 default:
1093 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */ 1169 mhd_panic (mhd_panic_cls,
1170 __FILE__,
1171 __LINE__,
1172 NULL); /* should never happen! */
1094 } 1173 }
1095 AGAIN: 1174 AGAIN:
1096 if (ioff > 0) 1175 if (ioff > 0)
1097 { 1176 {
1098 memmove (buf, &buf[ioff], pp->buffer_pos - ioff); 1177 memmove (buf,
1178 &buf[ioff],
1179 pp->buffer_pos - ioff);
1099 pp->buffer_pos -= ioff; 1180 pp->buffer_pos -= ioff;
1100 ioff = 0; 1181 ioff = 0;
1101 state_changed = 1; 1182 state_changed = 1;
1102 } 1183 }
1103 } 1184 }
1104END: 1185END:
1105 if (ioff != 0) 1186 if (0 != ioff)
1106 { 1187 {
1107 memmove (buf, &buf[ioff], pp->buffer_pos - ioff); 1188 memmove (buf,
1189 &buf[ioff],
1190 pp->buffer_pos - ioff);
1108 pp->buffer_pos -= ioff; 1191 pp->buffer_pos -= ioff;
1109 } 1192 }
1110 if (poff < post_data_len) 1193 if (poff < post_data_len)
@@ -1131,18 +1214,25 @@ END:
1131 */ 1214 */
1132int 1215int
1133MHD_post_process (struct MHD_PostProcessor *pp, 1216MHD_post_process (struct MHD_PostProcessor *pp,
1134 const char *post_data, size_t post_data_len) 1217 const char *post_data,
1218 size_t post_data_len)
1135{ 1219{
1136 if (0 == post_data_len) 1220 if (0 == post_data_len)
1137 return MHD_YES; 1221 return MHD_YES;
1138 if (NULL == pp) 1222 if (NULL == pp)
1139 return MHD_NO; 1223 return MHD_NO;
1140 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, pp->encoding, 1224 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
1141 strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 1225 pp->encoding,
1142 return post_process_urlencoded (pp, post_data, post_data_len); 1226 strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
1143 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, pp->encoding, 1227 return post_process_urlencoded (pp,
1144 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 1228 post_data,
1145 return post_process_multipart (pp, post_data, post_data_len); 1229 post_data_len);
1230 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
1231 pp->encoding,
1232 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
1233 return post_process_multipart (pp,
1234 post_data,
1235 post_data_len);
1146 /* this should never be reached */ 1236 /* this should never be reached */
1147 return MHD_NO; 1237 return MHD_NO;
1148} 1238}
@@ -1170,20 +1260,22 @@ MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
1170 /* key without terminated value left at the end of the 1260 /* key without terminated value left at the end of the
1171 buffer; fake receiving a termination character to 1261 buffer; fake receiving a termination character to
1172 ensure it is also processed */ 1262 ensure it is also processed */
1173 post_process_urlencoded (pp, "\n", 1); 1263 post_process_urlencoded (pp,
1264 "\n",
1265 1);
1174 } 1266 }
1175 /* These internal strings need cleaning up since 1267 /* These internal strings need cleaning up since
1176 the post-processing may have been interrupted 1268 the post-processing may have been interrupted
1177 at any stage */ 1269 at any stage */
1178 if ((pp->xbuf_pos > 0) || 1270 if ( (pp->xbuf_pos > 0) ||
1179 ( (pp->state != PP_Done) && 1271 ( (pp->state != PP_Done) &&
1180 (pp->state != PP_ExpectNewLine))) 1272 (pp->state != PP_ExpectNewLine) ) )
1181 ret = MHD_NO; 1273 ret = MHD_NO;
1182 else 1274 else
1183 ret = MHD_YES; 1275 ret = MHD_YES;
1184 pp->have = NE_none; 1276 pp->have = NE_none;
1185 free_unmarked (pp); 1277 free_unmarked (pp);
1186 if (pp->nested_boundary != NULL) 1278 if (NULL != pp->nested_boundary)
1187 free (pp->nested_boundary); 1279 free (pp->nested_boundary);
1188 free (pp); 1280 free (pp);
1189 return ret; 1281 return ret;
diff --git a/src/microhttpd/reason_phrase.c b/src/microhttpd/reason_phrase.c
index 82605565..03e741b2 100644
--- a/src/microhttpd/reason_phrase.c
+++ b/src/microhttpd/reason_phrase.c
@@ -30,7 +30,9 @@
30#define NULL (void*)0 30#define NULL (void*)0
31#endif 31#endif
32 32
33static const char *invalid_hundred[] = { NULL }; 33static const char *invalid_hundred[] = {
34 NULL
35};
34 36
35static const char *const one_hundred[] = { 37static const char *const one_hundred[] = {
36 "Continue", 38 "Continue",
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index a1a300ea..3a6b9166 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -154,14 +154,17 @@ MHD_del_response_header (struct MHD_Response *response,
154 struct MHD_HTTP_Header *pos; 154 struct MHD_HTTP_Header *pos;
155 struct MHD_HTTP_Header *prev; 155 struct MHD_HTTP_Header *prev;
156 156
157 if ( (NULL == header) || (NULL == content) ) 157 if ( (NULL == header) ||
158 (NULL == content) )
158 return MHD_NO; 159 return MHD_NO;
159 prev = NULL; 160 prev = NULL;
160 pos = response->first_header; 161 pos = response->first_header;
161 while (pos != NULL) 162 while (pos != NULL)
162 { 163 {
163 if ((0 == strcmp (header, pos->header)) && 164 if ((0 == strcmp (header,
164 (0 == strcmp (content, pos->value))) 165 pos->header)) &&
166 (0 == strcmp (content,
167 pos->value)))
165 { 168 {
166 free (pos->header); 169 free (pos->header);
167 free (pos->value); 170 free (pos->value);
@@ -228,7 +231,8 @@ MHD_get_response_header (struct MHD_Response *response,
228 if (NULL == key) 231 if (NULL == key)
229 return NULL; 232 return NULL;
230 for (pos = response->first_header; NULL != pos; pos = pos->next) 233 for (pos = response->first_header; NULL != pos; pos = pos->next)
231 if (0 == strcmp (key, pos->header)) 234 if (0 == strcmp (key,
235 pos->header))
232 return pos->value; 236 return pos->value;
233 return NULL; 237 return NULL;
234} 238}
@@ -263,11 +267,13 @@ MHD_create_response_from_callback (uint64_t size,
263 return NULL; 267 return NULL;
264 if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size))) 268 if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size)))
265 return NULL; 269 return NULL;
266 memset (response, 0, sizeof (struct MHD_Response)); 270 memset (response,
271 0,
272 sizeof (struct MHD_Response));
267 response->fd = -1; 273 response->fd = -1;
268 response->data = (void *) &response[1]; 274 response->data = (void *) &response[1];
269 response->data_buffer_size = block_size; 275 response->data_buffer_size = block_size;
270 if (!MHD_mutex_init_ (&response->mutex)) 276 if (! MHD_mutex_init_ (&response->mutex))
271 { 277 {
272 free (response); 278 free (response);
273 return NULL; 279 return NULL;
@@ -372,7 +378,7 @@ file_reader (void *cls,
372 378
373 n = read (response->fd, 379 n = read (response->fd,
374 buf, 380 buf,
375 (unsigned int)max); 381 (unsigned int) max);
376#endif /* _WIN32 */ 382#endif /* _WIN32 */
377 383
378 if (0 == n) 384 if (0 == n)
@@ -646,7 +652,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
646 if (MHD_INVALID_SOCKET != urh->app.socket) 652 if (MHD_INVALID_SOCKET != urh->app.socket)
647 { 653 {
648 if (0 != MHD_socket_close_ (urh->app.socket)) 654 if (0 != MHD_socket_close_ (urh->app.socket))
649 MHD_PANIC ("close failed\n"); 655 MHD_PANIC (_("close failed\n"));
650 urh->app.socket = MHD_INVALID_SOCKET; 656 urh->app.socket = MHD_INVALID_SOCKET;
651 } 657 }
652 return MHD_YES; 658 return MHD_YES;
@@ -688,7 +694,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
688 { 694 {
689#ifdef HAVE_MESSAGES 695#ifdef HAVE_MESSAGES
690 MHD_DLOG (daemon, 696 MHD_DLOG (daemon,
691 "Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"); 697 _("Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
692#endif 698#endif
693 return MHD_NO; 699 return MHD_NO;
694 } 700 }
@@ -720,7 +726,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
720 { 726 {
721#ifdef HAVE_MESSAGES 727#ifdef HAVE_MESSAGES
722 MHD_DLOG (daemon, 728 MHD_DLOG (daemon,
723 "Failed to make read side of inter-thread control channel non-blocking: %s\n", 729 _("Failed to make read side of inter-thread control channel non-blocking: %s\n"),
724 MHD_pipe_last_strerror_ ()); 730 MHD_pipe_last_strerror_ ());
725#endif 731#endif
726 } 732 }
@@ -729,14 +735,14 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
729 { 735 {
730#ifdef HAVE_MESSAGES 736#ifdef HAVE_MESSAGES
731 MHD_DLOG (daemon, 737 MHD_DLOG (daemon,
732 "Socketpair descriptor larger than FD_SETSIZE: %d > %d\n", 738 _("Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
733 (int) sv[1], 739 (int) sv[1],
734 (int) FD_SETSIZE); 740 (int) FD_SETSIZE);
735#endif 741#endif
736 if (0 != MHD_socket_close_ (sv[0])) 742 if (0 != MHD_socket_close_ (sv[0]))
737 MHD_PANIC ("close failed\n"); 743 MHD_PANIC (_("close failed\n"));
738 if (0 != MHD_socket_close_ (sv[1])) 744 if (0 != MHD_socket_close_ (sv[1]))
739 MHD_PANIC ("close failed\n"); 745 MHD_PANIC (_("close failed\n"));
740 free (urh); 746 free (urh);
741 return MHD_NO; 747 return MHD_NO;
742 } 748 }
@@ -803,13 +809,13 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
803 { 809 {
804#ifdef HAVE_MESSAGES 810#ifdef HAVE_MESSAGES
805 MHD_DLOG (daemon, 811 MHD_DLOG (daemon,
806 "Call to epoll_ctl failed: %s\n", 812 _("Call to epoll_ctl failed: %s\n"),
807 MHD_socket_last_strerr_ ()); 813 MHD_socket_last_strerr_ ());
808#endif 814#endif
809 if (0 != MHD_socket_close_ (sv[0])) 815 if (0 != MHD_socket_close_ (sv[0]))
810 MHD_PANIC ("close failed\n"); 816 MHD_PANIC (_("close failed\n"));
811 if (0 != MHD_socket_close_ (sv[1])) 817 if (0 != MHD_socket_close_ (sv[1]))
812 MHD_PANIC ("close failed\n"); 818 MHD_PANIC (_("close failed\n"));
813 free (urh); 819 free (urh);
814 return MHD_NO; 820 return MHD_NO;
815 } 821 }
@@ -828,16 +834,16 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
828 EPOLL_CTL_DEL, 834 EPOLL_CTL_DEL,
829 connection->socket_fd, 835 connection->socket_fd,
830 &event)) 836 &event))
831 MHD_PANIC ("Error cleaning up while handling epoll error"); 837 MHD_PANIC (_("Error cleaning up while handling epoll error"));
832#ifdef HAVE_MESSAGES 838#ifdef HAVE_MESSAGES
833 MHD_DLOG (daemon, 839 MHD_DLOG (daemon,
834 "Call to epoll_ctl failed: %s\n", 840 _("Call to epoll_ctl failed: %s\n"),
835 MHD_socket_last_strerr_ ()); 841 MHD_socket_last_strerr_ ());
836#endif 842#endif
837 if (0 != MHD_socket_close_ (sv[0])) 843 if (0 != MHD_socket_close_ (sv[0]))
838 MHD_PANIC ("close failed\n"); 844 MHD_PANIC (_("close failed\n"));
839 if (0 != MHD_socket_close_ (sv[1])) 845 if (0 != MHD_socket_close_ (sv[1]))
840 MHD_PANIC ("close failed\n"); 846 MHD_PANIC (_("close failed\n"));
841 free (urh); 847 free (urh);
842 return MHD_NO; 848 return MHD_NO;
843 } 849 }
@@ -875,7 +881,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
875 { 881 {
876#ifdef HAVE_MESSAGES 882#ifdef HAVE_MESSAGES
877 MHD_DLOG (daemon, 883 MHD_DLOG (daemon,
878 "Failed to create semaphore for upgrade handling\n"); 884 _("Failed to create semaphore for upgrade handling\n"));
879#endif 885#endif
880 MHD_connection_close_ (connection, 886 MHD_connection_close_ (connection,
881 MHD_REQUEST_TERMINATED_WITH_ERROR); 887 MHD_REQUEST_TERMINATED_WITH_ERROR);
@@ -989,7 +995,7 @@ MHD_destroy_response (struct MHD_Response *response)
989 } 995 }
990 (void) MHD_mutex_unlock_ (&response->mutex); 996 (void) MHD_mutex_unlock_ (&response->mutex);
991 (void) MHD_mutex_destroy_ (&response->mutex); 997 (void) MHD_mutex_destroy_ (&response->mutex);
992 if (response->crfc != NULL) 998 if (NULL != response->crfc)
993 response->crfc (response->crc_cls); 999 response->crfc (response->crc_cls);
994 while (NULL != response->first_header) 1000 while (NULL != response->first_header)
995 { 1001 {
diff --git a/src/microhttpd/tsearch.c b/src/microhttpd/tsearch.c
index 0c4d3e37..fe5fcd5b 100644
--- a/src/microhttpd/tsearch.c
+++ b/src/microhttpd/tsearch.c
@@ -12,68 +12,77 @@
12#include "tsearch.h" 12#include "tsearch.h"
13#include <stdlib.h> 13#include <stdlib.h>
14 14
15typedef struct node { 15
16typedef struct node
17{
16 const void *key; 18 const void *key;
17 struct node *llink, *rlink; 19 struct node *llink;
20 struct node *rlink;
18} node_t; 21} node_t;
19 22
23
20/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ 24/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */
21/* find or insert datum into search tree */ 25/* find or insert datum into search tree */
22void * 26void *
23tsearch(const void *vkey, /* key to be located */ 27tsearch (const void *vkey, /* key to be located */
24 void **vrootp, /* address of tree root */ 28 void **vrootp, /* address of tree root */
25 int (*compar)(const void *, const void *)) 29 int (*compar)(const void *, const void *))
26{ 30{
27 node_t *q; 31 node_t *q;
28 node_t **rootp = (node_t **)vrootp; 32 node_t **rootp = (node_t **)vrootp;
29 33
30 if (rootp == NULL) 34 if (NULL == rootp)
31 return NULL; 35 return NULL;
32 36
33 while (*rootp != NULL) { /* Knuth's T1: */ 37 while (*rootp != NULL)
34 int r; 38 { /* Knuth's T1: */
35 39 int r;
36 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 40
37 return *rootp; /* we found it! */ 41 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
38 42 return *rootp; /* we found it! */
39 rootp = (r < 0) ? 43
40 &(*rootp)->llink : /* T3: follow left branch */ 44 rootp = (r < 0) ?
41 &(*rootp)->rlink; /* T4: follow right branch */ 45 &(*rootp)->llink : /* T3: follow left branch */
42 } 46 &(*rootp)->rlink; /* T4: follow right branch */
43 47 }
44 q = malloc(sizeof(node_t)); /* T5: key not found */ 48
45 if (q) { /* make new node */ 49 q = malloc (sizeof(node_t)); /* T5: key not found */
46 *rootp = q; /* link new node to old */ 50 if (q)
47 q->key = vkey; /* initialize new node */ 51 { /* make new node */
48 q->llink = q->rlink = NULL; 52 *rootp = q; /* link new node to old */
49 } 53 q->key = vkey; /* initialize new node */
50 return q; 54 q->llink = q->rlink = NULL;
55 }
56 return q;
51} 57}
52 58
59
53/* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */ 60/* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */
54/* find a node, or return NULL */ 61/* find a node, or return NULL */
55void * 62void *
56tfind(const void *vkey, /* key to be found */ 63tfind (const void *vkey, /* key to be found */
57 void * const *vrootp, /* address of the tree root */ 64 void * const *vrootp, /* address of the tree root */
58 int (*compar)(const void *, const void *)) 65 int (*compar)(const void *, const void *))
59{ 66{
60 node_t * const *rootp = (node_t * const*)vrootp; 67 node_t * const *rootp = (node_t * const*)vrootp;
61 68
62 if (rootp == NULL) 69 if (NULL == rootp)
63 return NULL; 70 return NULL;
64 71
65 while (*rootp != NULL) { /* T1: */ 72 while (*rootp != NULL)
66 int r; 73 { /* T1: */
67 74 int r;
68 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ 75
69 return *rootp; /* key found */ 76 if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
70 rootp = (r < 0) ? 77 return *rootp; /* key found */
71 &(*rootp)->llink : /* T3: follow left branch */ 78 rootp = (r < 0) ?
72 &(*rootp)->rlink; /* T4: follow right branch */ 79 &(*rootp)->llink : /* T3: follow left branch */
73 } 80 &(*rootp)->rlink; /* T4: follow right branch */
74 return NULL; 81 }
82 return NULL;
75} 83}
76 84
85
77/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ 86/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */
78/* 87/*
79 * delete node with given key 88 * delete node with given key
@@ -83,42 +92,52 @@ tfind(const void *vkey, /* key to be found */
83 * compar: function to carry out node comparisons 92 * compar: function to carry out node comparisons
84 */ 93 */
85void * 94void *
86tdelete(const void * __restrict vkey, void ** __restrict vrootp, 95tdelete (const void * __restrict vkey,
87 int (*compar)(const void *, const void *)) 96 void ** __restrict vrootp,
97 int (*compar)(const void *, const void *))
88{ 98{
89 node_t **rootp = (node_t **)vrootp; 99 node_t **rootp = (node_t **)vrootp;
90 node_t *p, *q, *r; 100 node_t *p;
91 int cmp; 101 node_t *q;
92 102 node_t *r;
93 if (rootp == NULL || (p = *rootp) == NULL) 103 int cmp;
94 return NULL; 104
95 105 if (rootp == NULL || (p = *rootp) == NULL)
96 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) { 106 return NULL;
97 p = *rootp; 107
98 rootp = (cmp < 0) ? 108 while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0)
99 &(*rootp)->llink : /* follow llink branch */ 109 {
100 &(*rootp)->rlink; /* follow rlink branch */ 110 p = *rootp;
101 if (*rootp == NULL) 111 rootp = (cmp < 0) ?
102 return NULL; /* key not found */ 112 &(*rootp)->llink : /* follow llink branch */
103 } 113 &(*rootp)->rlink; /* follow rlink branch */
104 r = (*rootp)->rlink; /* D1: */ 114 if (*rootp == NULL)
105 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ 115 return NULL; /* key not found */
106 q = r; 116 }
107 else if (r != NULL) { /* Right link is NULL? */ 117 r = (*rootp)->rlink; /* D1: */
108 if (r->llink == NULL) { /* D2: Find successor */ 118 if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
109 r->llink = q; 119 {
110 q = r; 120 q = r;
111 } else { /* D3: Find NULL link */ 121 }
112 for (q = r->llink; q->llink != NULL; q = r->llink) 122 else if (r != NULL)
113 r = q; 123 { /* Right link is NULL? */
114 r->llink = q->rlink; 124 if (r->llink == NULL)
115 q->llink = (*rootp)->llink; 125 { /* D2: Find successor */
116 q->rlink = (*rootp)->rlink; 126 r->llink = q;
117 } 127 q = r;
118 } 128 }
119 free(*rootp); /* D4: Free node */ 129 else
120 *rootp = q; /* link parent to new node */ 130 { /* D3: Find NULL link */
121 return p; 131 for (q = r->llink; q->llink != NULL; q = r->llink)
132 r = q;
133 r->llink = q->rlink;
134 q->llink = (*rootp)->llink;
135 q->rlink = (*rootp)->rlink;
136 }
137 }
138 free(*rootp); /* D4: Free node */
139 *rootp = q; /* link parent to new node */
140 return p;
122} 141}
123 142
124/* end of tsearch.c */ 143/* end of tsearch.c */
diff --git a/src/microhttpd/tsearch.h b/src/microhttpd/tsearch.h
index 94884555..aa186495 100644
--- a/src/microhttpd/tsearch.h
+++ b/src/microhttpd/tsearch.h
@@ -12,11 +12,25 @@
12#if defined(__cplusplus) 12#if defined(__cplusplus)
13extern "C" { 13extern "C" {
14#endif /* __cplusplus */ 14#endif /* __cplusplus */
15void *tdelete(const void * __restrict, void ** __restrict, 15
16 int (*)(const void *, const void *)); 16
17void *tfind(const void *, void * const *, 17void *
18 int (*)(const void *, const void *)); 18tdelete (const void * __restrict,
19void *tsearch(const void *, void **, int (*)(const void *, const void *)); 19 void ** __restrict,
20 int (*)(const void *, const void *));
21
22
23void *
24tfind (const void *,
25 void * const *,
26 int (*)(const void *, const void *));
27
28
29void *
30tsearch (const void *,
31 void **,
32 int (*)(const void *, const void *));
33
20#if defined(__cplusplus) 34#if defined(__cplusplus)
21}; 35};
22#endif /* __cplusplus */ 36#endif /* __cplusplus */