summaryrefslogtreecommitdiff
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
parente3994e2a7f7a3aa2766f5494fbd6d8b05e475772 (diff)
address #4614: mark translatable strings with _-macro
-rw-r--r--ChangeLog3
-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
14 files changed, 758 insertions, 389 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e0f8a7a..48d0ec25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+Wed Sep 7 00:28:59 CEST 2016
+ Adding remaining "_"-markups for i18n (#4614). -CG
+
Tue Sep 6 23:39:56 CEST 2016
Allow out-of-order nonces for digest authentication (#4636). -CG
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)
#endif
#endif
+
#ifdef HAVE_MESSAGES
/**
* fprintf-like helper function for logging debug
* messages.
*/
void
-MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...)
+MHD_DLOG (const struct MHD_Daemon *daemon,
+ const char *format,
+ ...)
{
va_list va;
if (0 == (daemon->options & MHD_USE_DEBUG))
return;
va_start (va, format);
- daemon->custom_error_log (daemon->custom_error_log_cls, format, va);
+ daemon->custom_error_log (daemon->custom_error_log_cls,
+ format,
+ va);
va_end (va);
}
#endif
@@ -141,7 +146,9 @@ MHD_http_unescape (char *val)
switch (*rpos)
{
case '%':
- if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 2, &num))
+ if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
+ 2,
+ &num))
{
*wpos = (char)((unsigned char) num);
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)
pool->memory = MAP_FAILED;
else
#if defined(MAP_ANONYMOUS) && !defined(_WIN32)
- pool->memory = mmap (NULL, max, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ pool->memory = mmap (NULL,
+ max,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ -1,
+ 0);
#elif defined(_WIN32)
- pool->memory = VirtualAlloc(NULL, max, MEM_COMMIT | MEM_RESERVE,
- PAGE_READWRITE);
+ pool->memory = VirtualAlloc (NULL,
+ max,
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
#endif
#else
pool->memory = MAP_FAILED;
#endif
- if ((pool->memory == MAP_FAILED) || (pool->memory == NULL))
+ if ( (MAP_FAILED == pool->memory) ||
+ (NULL == pool->memory))
{
pool->memory = malloc (max);
- if (pool->memory == NULL)
+ if (NULL == pool->memory)
{
free (pool);
return NULL;
@@ -134,17 +141,20 @@ MHD_pool_create (size_t max)
void
MHD_pool_destroy (struct MemoryPool *pool)
{
- if (pool == NULL)
+ if (NULL == pool)
return;
- if (pool->is_mmap == MHD_NO)
+ if (MHD_NO == pool->is_mmap)
free (pool->memory);
else
#if defined(MAP_ANONYMOUS) && !defined(_WIN32)
- munmap (pool->memory, pool->size);
+ munmap (pool->memory,
+ pool->size);
#elif defined(_WIN32)
- VirtualFree(pool->memory, 0, MEM_RELEASE);
+ VirtualFree (pool->memory,
+ 0,
+ MEM_RELEASE);
#else
- abort();
+ abort ();
#endif
free (pool);
}
@@ -229,9 +239,11 @@ MHD_pool_reallocate (struct MemoryPool *pool,
size_t asize;
asize = ROUND_TO_ALIGN (new_size);
- if ( (0 == asize) && (0 != new_size) )
+ if ( (0 == asize) &&
+ (0 != new_size) )
return NULL; /* new_size too close to SIZE_MAX */
- if ((pool->end < old_size) || (pool->end < asize))
+ if ( (pool->end < old_size) ||
+ (pool->end < asize) )
return NULL; /* unsatisfiable or bogus request */
if ( (pool->pos >= old_size) &&
@@ -243,7 +255,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
/* fits */
pool->pos += asize - old_size;
if (asize < old_size) /* shrinking - zero again! */
- memset (&pool->memory[pool->pos], 0, old_size - asize);
+ memset (&pool->memory[pool->pos],
+ 0,
+ old_size - asize);
return old;
}
/* does not fit */
@@ -257,7 +271,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
/* fits */
ret = &pool->memory[pool->pos];
if (0 != old_size)
- memmove (ret, old, old_size);
+ memmove (ret,
+ old,
+ old_size);
pool->pos += asize;
return ret;
}
@@ -285,16 +301,14 @@ MHD_pool_reset (struct MemoryPool *pool,
size_t copy_bytes,
size_t new_size)
{
- if (NULL != keep)
+ if ( (NULL != keep) &&
+ (keep != pool->memory) )
{
- if (keep != pool->memory)
- {
- if (0 != copy_bytes)
- memmove (pool->memory,
- keep,
- copy_bytes);
- keep = pool->memory;
- }
+ if (0 != copy_bytes)
+ memmove (pool->memory,
+ keep,
+ copy_bytes);
+ keep = pool->memory;
}
pool->end = pool->size;
/* 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 @@
#ifndef HAVE_SNPRINTF
/* Emulate snprintf function on W32 */
int
-W32_snprintf(char *__restrict s,
- size_t n,
- const char *__restrict format,
- ...)
+W32_snprintf (char *__restrict s,
+ size_t n,
+ const char *__restrict format,
+ ...)
{
int ret;
va_list args;
- if (0 != n && NULL != s )
+
+ if ( (0 != n) &&
+ (NULL != s) )
{
- va_start(args, format);
- ret = _vsnprintf(s, n, format, args);
- va_end(args);
+ va_start (args,
+ format);
+ ret = _vsnprintf (s,
+ n,
+ format,
+ args);
+ va_end (args);
if ((int)n == ret)
s[n - 1] = 0;
if (ret >= 0)
return ret;
}
- va_start(args, format);
- ret = _vscprintf(format, args);
+ va_start(args,
+ format);
+ ret = _vscprintf (format,
+ args);
va_end(args);
- if (0 <= ret && 0 != n && NULL == s)
+ if ( (0 <= ret) &&
+ (0 != n) &&
+ (NULL == s) )
return -1;
return ret;
}
+
#endif /* HAVE_SNPRINTF */
#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)
{
int flags;
- flags = fcntl (fd, F_GETFL);
+ flags = fcntl (fd,
+ F_GETFL);
if (-1 == flags)
return 0;
if ( ((flags | O_NONBLOCK) != flags) &&
- (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) )
+ (0 != fcntl (fd,
+ F_SETFL,
+ flags | O_NONBLOCK)) )
return 0;
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
_MHD_CLOCK_PERFCOUNTER
};
+
/**
* Initialise monotonic seconds counter.
*/
@@ -149,74 +150,91 @@ MHD_monotonic_sec_counter_init (void)
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
#endif /* HAVE_CLOCK_GET_TIME */
+ /* just a little syntactic trick to get the
+ various following ifdef's to work out nicely */
if (0)
- {
- } else
+ {
+ }
+ else
#ifdef HAVE_CLOCK_GETTIME
#ifdef CLOCK_MONOTONIC_COARSE
/* Linux-specific fast value-getting clock */
/* Can be affected by frequency adjustment and don't count time in suspend, */
/* but preferred since it's fast */
- if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_COARSE;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_COARSE */
#ifdef CLOCK_MONOTONIC_FAST
/* FreeBSD/DragonFly fast value-getting clock */
/* Can be affected by frequency adjustment, but preferred since it's fast */
- if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_FAST,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_FAST;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_COARSE */
#ifdef CLOCK_MONOTONIC_RAW
/* Linux-specific clock */
/* Not affected by frequency adjustment, but don't count time in suspend */
- if (0 == clock_gettime (CLOCK_MONOTONIC_RAW , &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_RAW,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_RAW;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_RAW */
#ifdef CLOCK_BOOTTIME
/* Linux-specific clock */
/* Count time in suspend so it's real monotonic on Linux, */
/* but can be slower value-getting than other clocks */
- if (0 == clock_gettime(CLOCK_BOOTTIME, &ts))
+ if (0 == clock_gettime (CLOCK_BOOTTIME,
+ &ts))
{
mono_clock_id = CLOCK_BOOTTIME;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_BOOTTIME */
#ifdef CLOCK_MONOTONIC
/* Monotonic clock */
/* Widely supported, may be affected by frequency adjustment */
/* On Linux it's not truly monotonic as it doesn't count time in suspend */
- if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_BOOTTIME */
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_CLOCK_GET_TIME
/* Darwin-specific monotonic clock */
/* Should be monotonic as clock_set_time function always unconditionally */
/* failed on latest kernels */
- if (KERN_SUCCESS == host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &mono_clock_service) &&
- KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time))
+ if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self(),
+ SYSTEM_CLOCK,
+ &mono_clock_service)) &&
+ (KERN_SUCCESS == clock_get_time (mono_clock_service,
+ &cur_time)) )
{
mono_clock_start = cur_time.tv_sec;
mono_clock_source = _MHD_CLOCK_GET_TIME;
- } else
+ }
+ else
#endif /* HAVE_CLOCK_GET_TIME */
#ifdef _WIN32
#if _WIN32_WINNT >= 0x0600
@@ -224,33 +242,39 @@ MHD_monotonic_sec_counter_init (void)
/* Available since Vista, ~15ms accuracy */
if (1)
{
- tick_start = GetTickCount64();
+ tick_start = GetTickCount64 ();
mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64;
- } else
+ }
+ else
#else /* _WIN32_WINNT < 0x0600 */
/* W32 specific monotonic clock */
/* Available on Windows 2000 and later */
if (1)
{
- LARGE_INTEGER freq, perf_counter;
- QueryPerformanceFrequency(&freq); /* never fail on XP and later */
- QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */
+ LARGE_INTEGER freq;
+ LARGE_INTEGER perf_counter;
+
+ QueryPerformanceFrequency (&freq); /* never fail on XP and later */
+ QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
perf_freq = freq.QuadPart;
perf_start = perf_counter.QuadPart;
mono_clock_source = _MHD_CLOCK_PERFCOUNTER;
- } else
+ }
+ else
#endif /* _WIN32_WINNT < 0x0600 */
#endif /* _WIN32 */
#ifdef HAVE_CLOCK_GETTIME
#ifdef CLOCK_HIGHRES
/* Solaris-specific monotonic high-resolution clock */
/* Not preferred due to be potentially resource-hungry */
- if (0 == clock_gettime (CLOCK_HIGHRES, &ts))
+ if (0 == clock_gettime (CLOCK_HIGHRES,
+ &ts))
{
mono_clock_id = CLOCK_HIGHRES;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_HIGHRES */
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_GETHRTIME
@@ -258,9 +282,10 @@ MHD_monotonic_sec_counter_init (void)
/* Not preferred due to be potentially resource-hungry */
if (1)
{
- hrtime_start = gethrtime();
+ hrtime_start = gethrtime ();
mono_clock_source = _MHD_CLOCK_GETHRTIME;
- } else
+ }
+ else
#endif /* HAVE_GETHRTIME */
{
/* no suitable clock source was found */
@@ -272,7 +297,8 @@ MHD_monotonic_sec_counter_init (void)
(_MHD_INVALID_CLOCK_SERV != mono_clock_service) )
{
/* clock service was initialised but clock_get_time failed */
- mach_port_deallocate (mach_task_self(), mono_clock_service);
+ mach_port_deallocate (mach_task_self(),
+ mono_clock_service);
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
}
#else
@@ -292,12 +318,14 @@ MHD_monotonic_sec_counter_finish (void)
#ifdef HAVE_CLOCK_GET_TIME
if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
{
- mach_port_deallocate(mach_task_self(), mono_clock_service);
+ mach_port_deallocate (mach_task_self(),
+ mono_clock_service);
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
}
#endif /* HAVE_CLOCK_GET_TIME */
}
+
/**
* Monotonic seconds counter, useful for timeout calculation.
* Tries to be not affected by manually setting the system real time
@@ -311,15 +339,18 @@ MHD_monotonic_sec_counter (void)
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
- if (_MHD_UNWANTED_CLOCK != mono_clock_id &&
- 0 == clock_gettime (mono_clock_id , &ts))
+ if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) &&
+ (0 == clock_gettime (mono_clock_id ,
+ &ts)) )
return ts.tv_sec - mono_clock_start;
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_CLOCK_GET_TIME
if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
{
mach_timespec_t cur_time;
- if (KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time))
+
+ if (KERN_SUCCESS == clock_get_time(mono_clock_service,
+ &cur_time))
return cur_time.tv_sec - mono_clock_start;
}
#endif /* HAVE_CLOCK_GET_TIME */
@@ -331,14 +362,15 @@ MHD_monotonic_sec_counter (void)
if (0 != perf_freq)
{
LARGE_INTEGER perf_counter;
- QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */
+
+ QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq);
}
#endif /* _WIN32_WINNT < 0x0600 */
#endif /* _WIN32 */
#ifdef HAVE_GETHRTIME
if (1)
- return (time_t)(((uint64_t)(gethrtime() - hrtime_start)) / 1000000000);
+ return (time_t)(((uint64_t) (gethrtime () - hrtime_start)) / 1000000000);
#endif /* HAVE_GETHRTIME */
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)
* @param sockets_pair array to receive resulted sockets
* @return non-zero if succeeded, zero otherwise
*/
-int MHD_W32_socket_pair_(SOCKET sockets_pair[2])
+int
+MHD_W32_socket_pair_(SOCKET sockets_pair[2])
{
int i;
- if (!sockets_pair)
+
+ if (! sockets_pair)
{
- WSASetLastError(WSAEFAULT);
+ WSASetLastError (WSAEFAULT);
return 0;
}
@@ -261,52 +263,86 @@ int MHD_W32_socket_pair_(SOCKET sockets_pair[2])
int addr_len = c_addinlen;
int opt = 1;
- listen_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ listen_s = socket (AF_INET,
+ SOCK_STREAM,
+ IPPROTO_TCP);
if (INVALID_SOCKET == listen_s)
break; /* can't create even single socket */
listen_addr.sin_family = AF_INET;
listen_addr.sin_port = 0; /* same as htons(0) */
listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- if (0 == bind(listen_s, (struct sockaddr*) &listen_addr, c_addinlen)
- && 0 == listen(listen_s, 1)
- && 0 == getsockname(listen_s, (struct sockaddr*) &listen_addr,
- &addr_len))
+ if ( (0 == bind (listen_s,
+ (struct sockaddr*) &listen_addr,
+ c_addinlen) &&
+ (0 == listen (listen_s,
+ 1) )
+ (0 == getsockname (listen_s,
+ (struct sockaddr*) &listen_addr,
+ &addr_len))) )
{
- SOCKET client_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (INVALID_SOCKET != client_s)
+ SOCKET client_s = socket(AF_INET,
+ SOCK_STREAM,
+ IPPROTO_TCP);
+ struct sockaddr_in accepted_from_addr;
+ struct sockaddr_in client_addr;
+ SOCKET server_s;
+
+ if (INVALID_SOCKET == client_s)
+ {
+ /* try again */
+ closesocket (listen_s);
+ continue;
+ }
+
+ if ( (0 != ioctlsocket (client_s,
+ FIONBIO,
+ (u_long*) &opt)) ||
+ ( (0 != connect (client_s,
+ (struct sockaddr*) &listen_addr,
+ c_addinlen)) &&
+ (WSAGetLastError() != WSAEWOULDBLOCK)) )
+ {
+ /* try again */
+ closesocket (listen_s);
+ closesocket (client_s);
+ continue;
+ }
+
+ addr_len = c_addinlen;
+ server_s = accept (listen_s,
+ (struct sockaddr*) &accepted_from_addr,
+ &addr_len);
+ if (INVALID_SOCKET == server_s)
+ {
+ /* try again */
+ closesocket (listen_s);
+ closesocket (client_s);
+ continue;
+ }
+
+ addr_len = c_addinlen;
+ opt = 0;
+ if ( (0 == getsockname (client_s,
+ (struct sockaddr*) &client_addr,
+ &addr_len)) &&
+ (accepted_from_addr.sin_family == client_addr.sin_family) &&
+ (accepted_from_addr.sin_port == client_addr.sin_port) &&
+ (accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr) &&
+ (0 == ioctlsocket(client_s,
+ FIONBIO,
+ (u_long*) &opt)) &&
+ (0 == ioctlsocket(server_s,
+ FIONBIO,
+ (u_long*) &opt)) )
{
- if (0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt)
- && (0 == connect(client_s, (struct sockaddr*) &listen_addr, c_addinlen)
- || WSAGetLastError() == WSAEWOULDBLOCK))
- {
- struct sockaddr_in accepted_from_addr;
- SOCKET server_s;
- addr_len = c_addinlen;
- server_s = accept(listen_s,
- (struct sockaddr*) &accepted_from_addr, &addr_len);
- if (INVALID_SOCKET != server_s)
- {
- struct sockaddr_in client_addr;
- addr_len = c_addinlen;
- opt = 0;
- if (0 == getsockname(client_s, (struct sockaddr*) &client_addr, &addr_len)
- && accepted_from_addr.sin_family == client_addr.sin_family
- && accepted_from_addr.sin_port == client_addr.sin_port
- && accepted_from_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr
- && 0 == ioctlsocket(client_s, FIONBIO, (u_long*) &opt)
- && 0 == ioctlsocket(server_s, FIONBIO, (u_long*) &opt))
- {
- closesocket(listen_s);
- sockets_pair[0] = client_s;
- sockets_pair[1] = server_s;
- return !0;
- }
- closesocket(server_s);
- }
- }
- closesocket(client_s);
+ closesocket (listen_s);
+ sockets_pair[0] = client_s;
+ sockets_pair[1] = server_s;
+ return !0;
}
+ closesocket (server_s);
+ closesocket (client_s);
}
closesocket(listen_s);
}
@@ -367,17 +403,22 @@ MHD_socket_nonblocking_ (MHD_socket sock)
#if defined(MHD_POSIX_SOCKETS)
int flags;
- flags = fcntl (sock, F_GETFL);
+ flags = fcntl (sock,
+ F_GETFL);
if (-1 == flags)
return 0;
if ( ((flags | O_NONBLOCK) != flags) &&
- (0 != fcntl (sock, F_SETFL, flags | O_NONBLOCK)) )
+ (0 != fcntl (sock,
+ F_SETFL,
+ flags | O_NONBLOCK)) )
return 0;
#elif defined(MHD_WINSOCK_SOCKETS)
unsigned long flags = 1;
- if (0 != ioctlsocket (sock, FIONBIO, &flags))
+ if (0 != ioctlsocket (sock,
+ FIONBIO,
+ &flags))
return 0;
#endif /* MHD_WINSOCK_SOCKETS */
return !0;
@@ -397,15 +438,20 @@ MHD_socket_noninheritable_ (MHD_socket sock)
#if defined(MHD_POSIX_SOCKETS)
int flags;
- flags = fcntl (sock, F_GETFD);
+ flags = fcntl (sock,
+ F_GETFD);
if (-1 == flags)
return 0;
if ( ((flags | FD_CLOEXEC) != flags) &&
- (0 != fcntl (sock, F_SETFD, flags | FD_CLOEXEC)) )
+ (0 != fcntl (sock,
+ F_SETFD,
+ flags | FD_CLOEXEC)) )
return 0;
#elif defined(MHD_WINSOCK_SOCKETS)
- if (!SetHandleInformation ((HANDLE)sock, HANDLE_FLAG_INHERIT, 0))
+ if (! SetHandleInformation ((HANDLE)sock,
+ HANDLE_FLAG_INHERIT,
+ 0))
return 0;
#endif /* MHD_WINSOCK_SOCKETS */
return !0;
@@ -437,32 +483,45 @@ MHD_socket_create_listen_ (int use_ipv6)
#endif /* ! HAVE_INET6 */
#if defined(MHD_POSIX_SOCKETS) && defined(SOCK_CLOEXEC)
- fd = socket (domain, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ fd = socket (domain,
+ SOCK_STREAM | SOCK_CLOEXEC,
+ 0);
cloexec_set = !0;
#elif defined(MHD_WINSOCK_SOCKETS) && defined (WSA_FLAG_NO_HANDLE_INHERIT)
- fd = WSASocketW (domain, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_NO_HANDLE_INHERIT);
+ fd = WSASocketW (domain,
+ SOCK_STREAM,
+ 0,
+ NULL,
+ 0,
+ WSA_FLAG_NO_HANDLE_INHERIT);
cloexec_set = !0;
#else /* !SOCK_CLOEXEC */
fd = MHD_INVALID_SOCKET;
#endif /* !SOCK_CLOEXEC */
if (MHD_INVALID_SOCKET == fd)
{
- fd = socket (domain, SOCK_STREAM, 0);
+ fd = socket (domain,
+ SOCK_STREAM,
+ 0);
cloexec_set = 0;
}
if (MHD_INVALID_SOCKET == fd)
return MHD_INVALID_SOCKET;
#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
- if(0 != setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &on_val, sizeof(on_val)))
+ if(0 != setsockopt(fd,
+ SOL_SOCKET,
+ SO_NOSIGPIPE,
+ &on_val,
+ sizeof (on_val)))
{
- int err = MHD_socket_get_error_();
- MHD_socket_close_(fd);
- MHD_socket_fset_error_(err);
+ int err = MHD_socket_get_error_ ();
+ MHD_socket_close_ (fd);
+ MHD_socket_fset_error_ (err);
return MHD_INVALID_SOCKET;
}
#endif
- if (!cloexec_set)
- (void)MHD_socket_noninheritable_(fd);
+ if (! cloexec_set)
+ (void) MHD_socket_noninheritable_ (fd);
return fd;
}
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 @@
#ifdef _MHD_inline
#undef _MHD_inline
#endif /* _MHD_inline */
-/* Do not force inlining and do not use macro functions, use normal static
+/* Do not force inlining and do not use macro functions, use normal static
functions instead.
This may give more flexibility for size optimizations. */
#define _MHD_inline static
@@ -52,28 +52,33 @@
#ifdef INLINE_FUNC
/**
* Check whether character is lower case letter in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is lower case letter, zero otherwise
*/
_MHD_inline _MHD_bool
isasciilower (char c)
{
- return c >= 'a' && c <= 'z';
+ return (c >= 'a') && (c <= 'z');
}
+
/**
* Check whether character is upper case letter in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is upper case letter, zero otherwise
*/
_MHD_inline _MHD_bool
isasciiupper (char c)
{
- return c >= 'A' && c <= 'Z';
+ return (c >= 'A') && (c <= 'Z');
}
+
/**
* Check whether character is letter in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is letter in US-ASCII, zero otherwise
*/
@@ -83,19 +88,23 @@ isasciialpha (char c)
return isasciilower (c) || isasciiupper (c);
}
+
/**
* Check whether character is decimal digit in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is decimal digit, zero otherwise
*/
_MHD_inline _MHD_bool
isasciidigit (char c)
{
- return c >= '0' && c <= '9';
+ return (c >= '0') && (c <= '9');
}
+
/**
* Check whether character is hexadecimal digit in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is decimal digit, zero otherwise
*/
@@ -103,12 +112,14 @@ _MHD_inline _MHD_bool
isasciixdigit (char c)
{
return isasciidigit (c) ||
- (c >= 'A' && c <= 'F') ||
- (c >= 'a' && c <= 'f');
+ ( (c >= 'A') && (c <= 'F') ) ||
+ ( (c >= 'a') && (c <= 'f') );
}
+
/**
* Check whether character is decimal digit or letter in US-ASCII
+ *
* @param c character to check
* @return non-zero if character is decimal digit or letter, zero otherwise
*/
@@ -118,11 +129,13 @@ isasciialnum (char c)
return isasciialpha (c) || isasciidigit (c);
}
+
/**
* Convert US-ASCII character to lower case.
* If character is upper case letter in US-ASCII than it's converted to lower
* case analog. If character is NOT upper case letter than it's returned
* unmodified.
+ *
* @param c character to convert
* @return converted to lower case character
*/
@@ -132,11 +145,13 @@ toasciilower (char c)
return isasciiupper (c) ? (c - 'A' + 'a') : c;
}
+
/**
* Convert US-ASCII character to upper case.
* If character is lower case letter in US-ASCII than it's converted to upper
* case analog. If character is NOT lower case letter than it's returned
* unmodified.
+ *
* @param c character to convert
* @return converted to upper case character
*/
@@ -146,8 +161,10 @@ toasciiupper (char c)
return isasciilower (c) ? (c - 'a' + 'A') : c;
}
+
/**
* Convert US-ASCII decimal digit to its value.
+ *
* @param c character to convert
* @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
*/
@@ -160,8 +177,10 @@ todigitvalue (char c)
return -1;
}
+
/**
* Convert US-ASCII hexadecimal digit to its value.
+ *
* @param c character to convert
* @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
*/
@@ -170,49 +189,59 @@ toxdigitvalue (char c)
{
if (isasciidigit (c))
return (unsigned char)(c - '0');
- if (c >= 'A' && c <= 'F')
+ if ( (c >= 'A') && (c <= 'F') )
return (unsigned char)(c - 'A' + 10);
- if (c >= 'a' && c <= 'f')
+ if ( (c >= 'a') && (c <= 'f') )
return (unsigned char)(c - 'a' + 10);
return -1;
}
#else /* !INLINE_FUNC */
+
/**
* Checks whether character is lower case letter in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is lower case letter,
* boolean false otherwise
*/
#define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z')
+
/**
* Checks whether character is upper case letter in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is upper case letter,
* boolean false otherwise
*/
#define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z')
+
/**
* Checks whether character is letter in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is letter, boolean false
* otherwise
*/
#define isasciialpha(c) (isasciilower(c) || isasciiupper(c))
+
/**
* Check whether character is decimal digit in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is decimal digit, boolean false
* otherwise
*/
#define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9')
+
/**
* Check whether character is hexadecimal digit in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is hexadecimal digit,
* boolean false otherwise
@@ -221,41 +250,50 @@ toxdigitvalue (char c)
(((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \
(((char)(c)) >= 'a' && ((char)(c)) <= 'f') )
+
/**
* Check whether character is decimal digit or letter in US-ASCII
+ *
* @param c character to check
* @return boolean true if character is decimal digit or letter,
* boolean false otherwise
*/
#define isasciialnum(c) (isasciialpha(c) || isasciidigit(c))
+
/**
* Convert US-ASCII character to lower case.
* If character is upper case letter in US-ASCII than it's converted to lower
* case analog. If character is NOT upper case letter than it's returned
* unmodified.
+ *
* @param c character to convert
* @return converted to lower case character
*/
#define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c)))
+
/**
* Convert US-ASCII character to upper case.
* If character is lower case letter in US-ASCII than it's converted to upper
* case analog. If character is NOT lower case letter than it's returned
* unmodified.
+ *
* @param c character to convert
* @return converted to upper case character
*/
#define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c)))
+
/**
* Convert US-ASCII decimal digit to its value.
+ *
* @param c character to convert
* @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit
*/
#define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1))
+
/**
* Convert US-ASCII hexadecimal digit to its value.
* @param c character to convert
@@ -268,21 +306,25 @@ toxdigitvalue (char c)
(int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) )))
#endif /* !INLINE_FUNC */
+
#ifndef MHD_FAVOR_SMALL_CODE
/**
* Check two string for equality, ignoring case of US-ASCII letters.
+ *
* @param str1 first string to compare
* @param str2 second string to compare
* @return non-zero if two strings are equal, zero otherwise.
*/
int
-MHD_str_equal_caseless_ (const char * str1, const char * str2)
+MHD_str_equal_caseless_ (const char * str1,
+ const char * str2)
{
while (0 != (*str1))
{
const char c1 = *str1;
const char c2 = *str2;
- if (c1 != c2 && toasciilower (c1) != toasciilower (c2))
+ if ( (c1 != c2) &&
+ (toasciilower (c1) != toasciilower (c2)) )
return 0;
str1++;
str2++;
@@ -297,22 +339,27 @@ MHD_str_equal_caseless_ (const char * str1, const char * str2)
* checking not more than @a maxlen characters.
* Compares up to first terminating null character, but not more than
* first @a maxlen characters.
+ *
* @param str1 first string to compare
* @param str2 second string to compare
* @param maxlen maximum number of characters to compare
* @return non-zero if two strings are equal, zero otherwise.
*/
int
-MHD_str_equal_caseless_n_ (const char * const str1, const char * const str2, size_t maxlen)
+MHD_str_equal_caseless_n_ (const char * const str1,
+ const char * const str2,
+ size_t maxlen)
{
size_t i;
+
for (i = 0; i < maxlen; ++i)
{
const char c1 = str1[i];
const char c2 = str2[i];
if (0 == c2)
return 0 == c1;
- if (c1 != c2 && toasciilower (c1) != toasciilower (c2))
+ if ( (c1 != c2) &&
+ (toasciilower (c1) != toasciilower (c2)) )
return 0;
}
return !0;
@@ -324,17 +371,20 @@ MHD_str_equal_caseless_n_ (const char * const str1, const char * const str2, siz
/**
* Convert decimal US-ASCII digits in string to number in uint64_t.
* Conversion stopped at first non-digit character.
+ *
* @param str string to convert
- * @param out_val pointer to uint64_t to store result of conversion
+ * @param[out] out_val pointer to uint64_t to store result of conversion
* @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint64_t or @a out_val is NULL
*/
-size_t
-MHD_str_to_uint64_ (const char * str, uint64_t * out_val)
+size_t
+MHD_str_to_uint64_ (const char *str,
+ uint64_t *out_val)
{
const char * const start = str;
uint64_t res;
+
if (!str || !out_val || !isasciidigit(str[0]))
return 0;
@@ -343,7 +393,8 @@ MHD_str_to_uint64_ (const char * str, uint64_t * out_val)
{
const int digit = (unsigned char)(*str) - '0';
if ( (res > (UINT64_MAX / 10)) ||
- (res == (UINT64_MAX / 10) && (uint64_t)digit > (UINT64_MAX % 10)) )
+ ( (res == (UINT64_MAX / 10)) &&
+ ((uint64_t)digit > (UINT64_MAX % 10)) ) )
return 0;
res *= 10;
@@ -359,20 +410,24 @@ MHD_str_to_uint64_ (const char * str, uint64_t * out_val)
/**
* Convert not more then @a maxlen decimal US-ASCII digits in string to
* number in uint64_t.
- * Conversion stopped at first non-digit character or after @a maxlen
+ * Conversion stopped at first non-digit character or after @a maxlen
* digits.
+ *
* @param str string to convert
* @param maxlen maximum number of characters to process
- * @param out_val pointer to uint64_t to store result of conversion
+ * @param[out] out_val pointer to uint64_t to store result of conversion
* @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint64_t or @a out_val is NULL
*/
size_t
-MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
+MHD_str_to_uint64_n_ (const char * str,
+ size_t maxlen,
+ uint64_t *out_val)
{
uint64_t res;
size_t i;
+
if (!str || !maxlen || !out_val || !isasciidigit (str[0]))
return 0;
@@ -381,14 +436,17 @@ MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
do
{
const int digit = (unsigned char)str[i] - '0';
+
if ( (res > (UINT64_MAX / 10)) ||
- (res == (UINT64_MAX / 10) && (uint64_t)digit > (UINT64_MAX % 10)) )
+ ( (res == (UINT64_MAX / 10)) &&
+ ((uint64_t)digit > (UINT64_MAX % 10)) ) )
return 0;
res *= 10;
res += digit;
- i++;
- } while(i < maxlen && isasciidigit(str[i]));
+ i++;
+ } while ( (i < maxlen) &&
+ isasciidigit (str[i]) );
*out_val= res;
return i;
@@ -398,18 +456,21 @@ MHD_str_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
/**
* Convert hexadecimal US-ASCII digits in string to number in size_t.
* Conversion stopped at first non-digit character.
+ *
* @param str string to convert
- * @param out_val pointer to size_t to store result of conversion
- * @return non-zero number of characters processed on succeed,
+ * @param[out] out_val pointer to size_t to store result of conversion
+ * @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in size_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_sizet_ (const char * str, size_t * out_val)
+MHD_strx_to_sizet_ (const char *str,
+ size_t *out_val)
{
const char * const start = str;
size_t res;
int digit;
+
if (!str || !out_val)
return 0;
@@ -418,7 +479,8 @@ MHD_strx_to_sizet_ (const char * str, size_t * out_val)
while (digit >= 0)
{
if ( (res < (SIZE_MAX / 16)) ||
- (res == (SIZE_MAX / 16) && (size_t)digit <= (SIZE_MAX % 16)) )
+ ( (res == (SIZE_MAX / 16)) &&
+ ((size_t)digit <= (SIZE_MAX % 16)) ) )
{
res *= 16;
res += digit;
@@ -438,30 +500,35 @@ MHD_strx_to_sizet_ (const char * str, size_t * out_val)
/**
* Convert not more then @a maxlen hexadecimal US-ASCII digits in string
* to number in size_t.
- * Conversion stopped at first non-digit character or after @a maxlen
+ * Conversion stopped at first non-digit character or after @a maxlen
* digits.
+ *
* @param str string to convert
* @param maxlen maximum number of characters to process
- * @param out_val pointer to size_t to store result of conversion
+ * @param[out] out_val pointer to size_t to store result of conversion
* @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in size_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_sizet_n_ (const char * str, size_t maxlen, size_t * out_val)
+MHD_strx_to_sizet_n_ (const char * str,
+ size_t maxlen,
+ size_t *out_val)
{
size_t i;
size_t res;
int digit;
if (!str || !out_val)
return 0;
-
+
res = 0;
i = 0;
- while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
+ while ( (i < maxlen) &&
+ ((digit = toxdigitvalue (str[i])) >= 0) )
{
if ( (res > (SIZE_MAX / 16)) ||
- (res == (SIZE_MAX / 16) && (size_t)digit > (SIZE_MAX % 16)) )
+ ( (res == (SIZE_MAX / 16)) &&
+ ((size_t)digit > (SIZE_MAX % 16)) ) )
return 0;
res *= 16;
@@ -478,18 +545,21 @@ MHD_strx_to_sizet_n_ (const char * str, size_t maxlen, size_t * out_val)
/**
* Convert hexadecimal US-ASCII digits in string to number in uint32_t.
* Conversion stopped at first non-digit character.
+ *
* @param str string to convert
- * @param out_val pointer to uint32_t to store result of conversion
- * @return non-zero number of characters processed on succeed,
+ * @param[out] out_val pointer to uint32_t to store result of conversion
+ * @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint32_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_uint32_ (const char * str, uint32_t * out_val)
+MHD_strx_to_uint32_ (const char * str,
+ uint32_t *out_val)
{
const char * const start = str;
uint32_t res;
int digit;
+
if (!str || !out_val)
return 0;
@@ -518,24 +588,27 @@ MHD_strx_to_uint32_ (const char * str, uint32_t * out_val)
/**
* Convert not more then @a maxlen hexadecimal US-ASCII digits in string
* to number in uint32_t.
- * Conversion stopped at first non-digit character or after @a maxlen
+ * Conversion stopped at first non-digit character or after @a maxlen
* digits.
+ *
* @param str string to convert
* @param maxlen maximum number of characters to process
- * @param out_val pointer to uint32_t to store result of conversion
+ * @param[out] out_val pointer to uint32_t to store result of conversion
* @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint32_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_uint32_n_ (const char * str, size_t maxlen, uint32_t * out_val)
+MHD_strx_to_uint32_n_ (const char *str,
+ size_t maxlen,
+ uint32_t *out_val)
{
size_t i;
uint32_t res;
int digit;
if (!str || !out_val)
return 0;
-
+
res = 0;
i = 0;
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)
/**
* Convert hexadecimal US-ASCII digits in string to number in uint64_t.
* Conversion stopped at first non-digit character.
+ *
* @param str string to convert
- * @param out_val pointer to uint64_t to store result of conversion
- * @return non-zero number of characters processed on succeed,
+ * @param[out] out_val pointer to uint64_t to store result of conversion
+ * @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint64_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_uint64_ (const char * str, uint64_t * out_val)
+MHD_strx_to_uint64_ (const char *str,
+ uint64_t *out_val)
{
const char * const start = str;
uint64_t res;
@@ -598,24 +673,27 @@ MHD_strx_to_uint64_ (const char * str, uint64_t * out_val)
/**
* Convert not more then @a maxlen hexadecimal US-ASCII digits in string
* to number in uint64_t.
- * Conversion stopped at first non-digit character or after @a maxlen
+ * Conversion stopped at first non-digit character or after @a maxlen
* digits.
+ *
* @param str string to convert
* @param maxlen maximum number of characters to process
- * @param out_val pointer to uint64_t to store result of conversion
+ * @param[out] out_val pointer to uint64_t to store result of conversion
* @return non-zero number of characters processed on succeed,
* zero if no digit is found, resulting value is larger
* then possible to store in uint64_t or @a out_val is NULL
*/
size_t
-MHD_strx_to_uint64_n_ (const char * str, size_t maxlen, uint64_t * out_val)
+MHD_strx_to_uint64_n_ (const char * str,
+ size_t maxlen,
+ uint64_t *out_val)
{
size_t i;
uint64_t res;
int digit;
if (!str || !out_val)
return 0;
-
+
res = 0;
i = 0;
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)
/**
* Generic function for converting not more then @a maxlen
* hexadecimal or decimal US-ASCII digits in string to number.
- * Conversion stopped at first non-digit character or after @a maxlen
+ * Conversion stopped at first non-digit character or after @a maxlen
* digits.
* To be used only within macro.
+ *
* @param str the string to convert
* @param maxlen the maximum number of characters to process
* @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)
* then @max_val, @val_size is not 16/32 or @a out_val is NULL
*/
size_t
-MHD_str_to_uvalue_n_ (const char * str, size_t maxlen,
- void * out_val, size_t val_size, uint64_t max_val, int base)
+MHD_str_to_uvalue_n_ (const char *str,
+ size_t maxlen,
+ void * out_val,
+ size_t val_size,
+ uint64_t max_val,
+ int base)
{
size_t i;
uint64_t res;
@@ -664,6 +747,7 @@ MHD_str_to_uvalue_n_ (const char * str, size_t maxlen,
/* 'digit->value' must be function, not macro */
int (*const dfunc)(char) = (base == 16) ?
toxdigitvalue : todigitvalue;
+
if ( !str || !out_val ||
(base != 16 && base != 10) )
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_;
#if defined(MHD_USE_POSIX_THREADS)
#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
|| defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
+
/**
* Set thread name
+ *
* @param thread_id ID of thread
* @param thread_name name to set
* @return non-zero on success, zero otherwise
*/
-static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name)
+static int
+MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
+ const char *thread_name)
{
if (NULL == thread_name)
return 0;
@@ -110,11 +114,14 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre
#else /* _MSC_FULL_VER */
/**
* Set thread name
+ *
* @param thread_id ID of thread, -1 for current thread
* @param thread_name name to set
* @return non-zero on success, zero otherwise
*/
-static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thread_name)
+static int
+MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
+ const char *thread_name)
{
static const DWORD VC_SETNAME_EXC = 0x406D1388;
#pragma pack(push,8)
@@ -137,7 +144,10 @@ static int MHD_set_thread_name_(const MHD_thread_ID_ thread_id, const char *thre
__try
{ /* This exception is intercepted by debugger */
- RaiseException(VC_SETNAME_EXC, 0, sizeof(thread_info) / sizeof(ULONG_PTR), (ULONG_PTR*)&thread_info);
+ RaiseException (VC_SETNAME_EXC,
+ 0,
+ sizeof (thread_info) / sizeof(ULONG_PTR),
+ (ULONG_PTR *) &thread_info);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{}
@@ -182,15 +192,21 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
res = pthread_attr_init (&attr);
if (0 == res)
{
- res = pthread_attr_setstacksize (&attr, stack_size);
+ res = pthread_attr_setstacksize (&attr,
+ stack_size);
if (0 == res)
- res = pthread_create (thread, &attr,
- start_routine, arg);
+ res = pthread_create (thread,
+ &attr,
+ start_routine,
+ arg);
pthread_attr_destroy (&attr);
}
}
else
- res = pthread_create (thread, NULL, start_routine, arg);
+ res = pthread_create (thread,
+ NULL,
+ start_routine,
+ arg);
if (0 != res)
errno = res;
@@ -205,8 +221,12 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
}
#endif /* SIZE_MAX != UINT_MAX */
- *thread = (HANDLE)_beginthreadex(NULL, (unsigned)stack_size, start_routine,
- arg, 0, NULL);
+ *thread = (HANDLE) _beginthreadex (NULL,
+ (unsigned int) stack_size,
+ start_routine,
+ arg,
+ 0,
+ NULL);
if ((MHD_thread_handle_)-1 == (*thread))
return 0;
@@ -234,6 +254,7 @@ struct MHD_named_helper_param_
const char *name;
};
+
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
named_thread_starter (void *data)
{
@@ -245,7 +266,7 @@ named_thread_starter (void *data)
if (NULL == data)
return (MHD_THRD_RTRN_TYPE_)0;
- MHD_set_cur_thread_name_(param->name);
+ MHD_set_cur_thread_name_ (param->name);
arg = param->arg;
thr_func = param->start_routine;
@@ -255,7 +276,6 @@ named_thread_starter (void *data)
}
-
/**
* Create a named thread and set the attributes according to our options.
*
@@ -273,7 +293,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
MHD_THREAD_START_ROUTINE_ start_routine,
void *arg)
{
- struct MHD_named_helper_param_ * param;
+ struct MHD_named_helper_param_ *param;
if (NULL == thread_name)
{
@@ -281,7 +301,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
return 0;
}
- param = malloc(sizeof(struct MHD_named_helper_param_));
+ param = malloc (sizeof (struct MHD_named_helper_param_));
if (NULL == param)
return 0;
@@ -292,9 +312,12 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
/* Set thread name in thread itself to avoid problems with
* threads which terminated before name is set in other thread.
*/
- if (!MHD_create_thread_(thread, stack_size, &named_thread_starter, (void*)param))
+ if (! MHD_create_thread_(thread,
+ stack_size,
+ &named_thread_starter,
+ (void*)param))
{
- free(param);
+ free (param);
return 0;
}
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
size_t buffer_pos;
/**
- * Current position in xbuf.
+ * Current position in @e xbuf.
*/
size_t xbuf_pos;
@@ -272,26 +272,34 @@ struct MHD_PostProcessor
struct MHD_PostProcessor *
MHD_create_post_processor (struct MHD_Connection *connection,
size_t buffer_size,
- MHD_PostDataIterator iter, void *iter_cls)
+ MHD_PostDataIterator iter,
+ void *iter_cls)
{
struct MHD_PostProcessor *ret;
const char *encoding;
const char *boundary;
size_t blen;
- if ((buffer_size < 256) || (connection == NULL) || (iter == NULL))
- mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
+ if ( (buffer_size < 256) ||
+ (NULL == connection) ||
+ (NULL == iter))
+ mhd_panic (mhd_panic_cls,
+ __FILE__,
+ __LINE__,
+ NULL);
encoding = MHD_lookup_connection_value (connection,
MHD_HEADER_KIND,
MHD_HTTP_HEADER_CONTENT_TYPE);
- if (encoding == NULL)
+ if (NULL == encoding)
return NULL;
boundary = NULL;
- if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding,
- strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
+ if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
+ encoding,
+ strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
{
- if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
- strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
+ if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
+ encoding,
+ strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
return NULL;
boundary =
&encoding[strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
@@ -301,9 +309,11 @@ MHD_create_post_processor (struct MHD_Connection *connection,
return NULL; /* failed to determine boundary */
boundary += strlen ("boundary=");
blen = strlen (boundary);
- if ((blen == 0) || (blen * 2 + 2 > buffer_size))
+ if ( (blen == 0) ||
+ (blen * 2 + 2 > buffer_size) )
return NULL; /* (will be) out of memory or invalid boundary */
- if ( (boundary[0] == '"') && (boundary[blen - 1] == '"') )
+ if ( (boundary[0] == '"') &&
+ (boundary[blen - 1] == '"') )
{
/* remove enclosing quotes */
++boundary;
@@ -317,7 +327,9 @@ MHD_create_post_processor (struct MHD_Connection *connection,
/* add +1 to ensure we ALWAYS have a zero-termination at the end */
if (NULL == (ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1)))
return NULL;
- memset (ret, 0, sizeof (struct MHD_PostProcessor) + buffer_size + 1);
+ memset (ret,
+ 0,
+ sizeof (struct MHD_PostProcessor) + buffer_size + 1);
ret->connection = connection;
ret->ikvi = iter;
ret->cls = iter_cls;
@@ -420,16 +432,20 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
if so, exclude those from processing (reduce delta to point at
end of processed region) */
delta = xoff;
- if ((delta > 0) && (xbuf[delta - 1] == '%'))
+ if ((delta > 0) &&
+ ('%' == xbuf[delta - 1]))
delta--;
- else if ((delta > 1) && (xbuf[delta - 2] == '%'))
+ else if ((delta > 1) &&
+ ('%' == xbuf[delta - 2]))
delta -= 2;
/* if we have an incomplete escape sequence, save it to
pp->xbuf for later */
if (delta < xoff)
{
- memcpy (pp->xbuf, &xbuf[delta], xoff - delta);
+ memcpy (pp->xbuf,
+ &xbuf[delta],
+ xoff - delta);
pp->xbuf_pos = xoff - delta;
xoff = delta;
}
@@ -437,7 +453,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
/* If we have nothing to do (delta == 0) and
not just because the value is empty (are
waiting for more data), go for next iteration */
- if ((xoff == 0) && (poff == post_data_len))
+ if ( (0 == xoff) &&
+ (poff == post_data_len))
continue;
/* unescape */
@@ -446,8 +463,14 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
xoff = MHD_http_unescape (xbuf);
/* finally: call application! */
pp->must_ikvi = MHD_NO;
- if (MHD_NO == pp->ikvi (pp->cls, MHD_POSTDATA_KIND, (const char *) &pp[1], /* key */
- NULL, NULL, NULL, xbuf, pp->value_offset,
+ if (MHD_NO == pp->ikvi (pp->cls,
+ MHD_POSTDATA_KIND,
+ (const char *) &pp[1], /* key */
+ NULL,
+ NULL,
+ NULL,
+ xbuf,
+ pp->value_offset,
xoff))
{
pp->state = PP_Error;
@@ -459,11 +482,12 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
if (end_of_value_found)
{
/* we found the end of the value! */
- if ((post_data[poff] == '\n') || (post_data[poff] == '\r'))
+ if ( ('\n' == post_data[poff]) ||
+ ('\r' == post_data[poff]) )
{
pp->state = PP_ExpectNewLine;
}
- else if (post_data[poff] == '&')
+ else if ('&' == post_data[poff])
{
poff++; /* skip '&' */
pp->state = PP_Init;
@@ -471,7 +495,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
}
break;
case PP_ExpectNewLine:
- if ((post_data[poff] == '\n') || (post_data[poff] == '\r'))
+ if ( ('\n' == post_data[poff]) ||
+ ('\r' == post_data[poff]) )
{
poff++;
/* we are done, report error if we receive any more... */
@@ -480,7 +505,10 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
}
return MHD_NO;
default:
- mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */
+ mhd_panic (mhd_panic_cls,
+ __FILE__,
+ __LINE__,
+ NULL); /* should never happen! */
}
}
return MHD_YES;
@@ -497,13 +525,17 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
* @return #MHD_YES if there was a match, #MHD_NO if not
*/
static int
-try_match_header (const char *prefix, char *line, char **suffix)
+try_match_header (const char *prefix,
+ char *line,
+ char **suffix)
{
if (NULL != *suffix)
return MHD_NO;
- while (*line != 0)
+ while (0 != *line)
{
- if (MHD_str_equal_caseless_n_ (prefix, line, strlen (prefix)))
+ if (MHD_str_equal_caseless_n_ (prefix,
+ line,
+ strlen (prefix)))
{
*suffix = strdup (&line[strlen (prefix)]);
return MHD_YES;
@@ -532,7 +564,8 @@ find_boundary (struct MHD_PostProcessor *pp,
const char *boundary,
size_t blen,
size_t *ioffptr,
- enum PP_State next_state, enum PP_State next_dash_state)
+ enum PP_State next_state,
+ enum PP_State next_dash_state)
{
char *buf = (char *) &pp[1];
const char *dash;
@@ -544,7 +577,12 @@ find_boundary (struct MHD_PostProcessor *pp,
/* ++(*ioffptr); */
return MHD_NO; /* not enough data */
}
- if ((0 != memcmp ("--", buf, 2)) || (0 != memcmp (&buf[2], boundary, blen)))
+ if ( (0 != memcmp ("--",
+ buf,
+ 2)) ||
+ (0 != memcmp (&buf[2],
+ boundary,
+ blen)))
{
if (pp->state != PP_Init)
{
@@ -554,7 +592,9 @@ find_boundary (struct MHD_PostProcessor *pp,
else
{
/* skip over garbage (RFC 2046, 5.1.1) */
- dash = memchr (buf, '-', pp->buffer_pos);
+ dash = memchr (buf,
+ '-',
+ pp->buffer_pos);
if (NULL == dash)
(*ioffptr) += pp->buffer_pos; /* skip entire buffer */
else
@@ -598,7 +638,9 @@ try_get_value (const char *buf,
klen = strlen (key);
while (NULL != (spos = strstr (bpos, key)))
{
- if ((spos[klen] != '=') || ((spos != buf) && (spos[-1] != ' ')))
+ if ( (spos[klen] != '=') ||
+ ( (spos != buf) &&
+ (spos[-1] != ' ') ) )
{
/* no match */
bpos = spos + 1;
@@ -606,14 +648,17 @@ try_get_value (const char *buf,
}
if (spos[klen + 1] != '"')
return; /* not quoted */
- if (NULL == (endv = strchr (&spos[klen + 2], '\"')))
+ if (NULL == (endv = strchr (&spos[klen + 2],
+ '\"')))
return; /* no end-quote */
vlen = endv - spos - klen - 1;
*destination = malloc (vlen);
if (NULL == *destination)
return; /* out of memory */
(*destination)[vlen - 1] = '\0';
- memcpy (*destination, &spos[klen + 2], vlen - 1);
+ memcpy (*destination,
+ &spos[klen + 2],
+ vlen - 1);
return; /* success */
}
}
@@ -636,14 +681,16 @@ try_get_value (const char *buf,
*/
static int
process_multipart_headers (struct MHD_PostProcessor *pp,
- size_t *ioffptr, enum PP_State next_state)
+ size_t *ioffptr,
+ enum PP_State next_state)
{
char *buf = (char *) &pp[1];
size_t newline;
newline = 0;
- while ((newline < pp->buffer_pos) &&
- (buf[newline] != '\r') && (buf[newline] != '\n'))
+ while ( (newline < pp->buffer_pos) &&
+ (buf[newline] != '\r') &&
+ (buf[newline] != '\n') )
newline++;
if (newline == pp->buffer_size)
{
@@ -664,18 +711,24 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
pp->skip_rn = RN_OptN;
buf[newline] = '\0';
if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
- buf, strlen ("Content-disposition: ")))
+ buf,
+ strlen ("Content-disposition: ")))
{
try_get_value (&buf[strlen ("Content-disposition: ")],
- "name", &pp->content_name);
+ "name",
+ &pp->content_name);
try_get_value (&buf[strlen ("Content-disposition: ")],
- "filename", &pp->content_filename);
+ "filename",
+ &pp->content_filename);
}
else
{
- try_match_header ("Content-type: ", buf, &pp->content_type);
+ try_match_header ("Content-type: ",
+ buf,
+ &pp->content_type);
try_match_header ("Content-Transfer-Encoding: ",
- buf, &pp->content_transfer_encoding);
+ buf,
+ &pp->content_transfer_encoding);
}
(*ioffptr) += newline + 1;
return MHD_YES;
@@ -717,21 +770,27 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
{
while (newline + 4 < pp->buffer_pos)
{
- r = memchr (&buf[newline], '\r', pp->buffer_pos - newline - 4);
+ r = memchr (&buf[newline],
+ '\r',
+ pp->buffer_pos - newline - 4);
if (NULL == r)
{
newline = pp->buffer_pos - 4;
break;
}
newline = r - buf;
- if (0 == memcmp ("\r\n--", &buf[newline], 4))
+ if (0 == memcmp ("\r\n--",
+ &buf[newline],
+ 4))
break;
newline++;
}
if (newline + pp->blen + 4 <= pp->buffer_pos)
{
/* can check boundary */
- if (0 != memcmp (&buf[newline + 4], boundary, pp->blen))
+ if (0 != memcmp (&buf[newline + 4],
+ boundary,
+ pp->blen))
{
/* no boundary, "\r\n--" is part of content, skip */
newline += 4;
@@ -754,7 +813,8 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
/* cannot check for boundary, process content that
we have and check again later; except, if we have
no content, abort (out of memory) */
- if ((0 == newline) && (pp->buffer_pos == pp->buffer_size))
+ if ( (0 == newline) &&
+ (pp->buffer_pos == pp->buffer_size) )
{
pp->state = PP_Error;
return MHD_NO;
@@ -773,7 +833,9 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
pp->content_filename,
pp->content_type,
pp->content_transfer_encoding,
- buf, pp->value_offset, newline)) )
+ buf,
+ pp->value_offset,
+ newline)) )
{
pp->state = PP_Error;
return MHD_NO;
@@ -792,24 +854,26 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
static void
free_unmarked (struct MHD_PostProcessor *pp)
{
- if ((NULL != pp->content_name) && (0 == (pp->have & NE_content_name)))
+ if ( (NULL != pp->content_name) &&
+ (0 == (pp->have & NE_content_name)) )
{
free (pp->content_name);
pp->content_name = NULL;
}
- if ((NULL != pp->content_type) && (0 == (pp->have & NE_content_type)))
+ if ( (NULL != pp->content_type) &&
+ (0 == (pp->have & NE_content_type)) )
{
free (pp->content_type);
pp->content_type = NULL;
}
- if ((NULL != pp->content_filename) &&
- (0 == (pp->have & NE_content_filename)))
+ if ( (NULL != pp->content_filename) &&
+ (0 == (pp->have & NE_content_filename)) )
{
free (pp->content_filename);
pp->content_filename = NULL;
}
- if ((NULL != pp->content_transfer_encoding) &&
- (0 == (pp->have & NE_content_transfer_encoding)))
+ if ( (NULL != pp->content_transfer_encoding) &&
+ (0 == (pp->have & NE_content_transfer_encoding)) )
{
free (pp->content_transfer_encoding);
pp->content_transfer_encoding = NULL;
@@ -840,18 +904,23 @@ post_process_multipart (struct MHD_PostProcessor *pp,
ioff = 0;
poff = 0;
state_changed = 1;
- while ((poff < post_data_len) ||
- ((pp->buffer_pos > 0) && (state_changed != 0)))
+ while ( (poff < post_data_len) ||
+ ( (pp->buffer_pos > 0) &&
+ (0 != state_changed) ) )
{
/* first, move as much input data
as possible to our internal buffer */
max = pp->buffer_size - pp->buffer_pos;
if (max > post_data_len - poff)
max = post_data_len - poff;
- memcpy (&buf[pp->buffer_pos], &post_data[poff], max);
+ memcpy (&buf[pp->buffer_pos],
+ &post_data[poff],
+ max);
poff += max;
pp->buffer_pos += max;
- if ((max == 0) && (state_changed == 0) && (poff < post_data_len))
+ if ( (0 == max) &&
+ (0 == state_changed) &&
+ (poff < post_data_len) )
{
pp->state = PP_Error;
return MHD_NO; /* out of memory */
@@ -883,7 +952,8 @@ post_process_multipart (struct MHD_PostProcessor *pp,
case RN_Full:
if (buf[0] == '\r')
{
- if ((pp->buffer_pos > 1) && (buf[1] == '\n'))
+ if ( (pp->buffer_pos > 1) &&
+ ('\n' == buf[1]) )
{
pp->skip_rn = RN_Inactive;
ioff += 2;
@@ -941,14 +1011,16 @@ post_process_multipart (struct MHD_PostProcessor *pp,
pp->boundary,
pp->blen,
&ioff,
- PP_ProcessEntryHeaders, PP_Done);
+ PP_ProcessEntryHeaders,
+ PP_Done);
break;
case PP_NextBoundary:
if (MHD_NO == find_boundary (pp,
pp->boundary,
pp->blen,
&ioff,
- PP_ProcessEntryHeaders, PP_Done))
+ PP_ProcessEntryHeaders,
+ PP_Done))
{
if (pp->state == PP_Error)
return MHD_NO;
@@ -958,7 +1030,9 @@ post_process_multipart (struct MHD_PostProcessor *pp,
case PP_ProcessEntryHeaders:
pp->must_ikvi = MHD_YES;
if (MHD_NO ==
- process_multipart_headers (pp, &ioff, PP_PerformCheckMultipart))
+ process_multipart_headers (pp,
+ &ioff,
+ PP_PerformCheckMultipart))
{
if (pp->state == PP_Error)
return MHD_NO;
@@ -968,20 +1042,21 @@ post_process_multipart (struct MHD_PostProcessor *pp,
state_changed = 1;
break;
case PP_PerformCheckMultipart:
- if ((pp->content_type != NULL) &&
- (MHD_str_equal_caseless_n_ (pp->content_type,
- "multipart/mixed",
- strlen ("multipart/mixed"))))
+ if ( (NULL != pp->content_type) &&
+ (MHD_str_equal_caseless_n_ (pp->content_type,
+ "multipart/mixed",
+ strlen ("multipart/mixed"))))
{
- pp->nested_boundary = strstr (pp->content_type, "boundary=");
- if (pp->nested_boundary == NULL)
+ pp->nested_boundary = strstr (pp->content_type,
+ "boundary=");
+ if (NULL == pp->nested_boundary)
{
pp->state = PP_Error;
return MHD_NO;
}
pp->nested_boundary =
strdup (&pp->nested_boundary[strlen ("boundary=")]);
- if (pp->nested_boundary == NULL)
+ if (NULL == pp->nested_boundary)
{
/* out of memory */
pp->state = PP_Error;
@@ -1017,7 +1092,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
/* clean up state of one multipart form-data element! */
pp->have = NE_none;
free_unmarked (pp);
- if (pp->nested_boundary != NULL)
+ if (NULL != pp->nested_boundary)
{
free (pp->nested_boundary);
pp->nested_boundary = NULL;
@@ -1026,7 +1101,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
state_changed = 1;
break;
case PP_Nested_Init:
- if (pp->nested_boundary == NULL)
+ if (NULL == pp->nested_boundary)
{
pp->state = PP_Error;
return MHD_NO;
@@ -1047,13 +1122,13 @@ post_process_multipart (struct MHD_PostProcessor *pp,
/* remember what headers were given
globally */
pp->have = NE_none;
- if (pp->content_name != NULL)
+ if (NULL != pp->content_name)
pp->have |= NE_content_name;
- if (pp->content_type != NULL)
+ if (NULL != pp->content_type)
pp->have |= NE_content_type;
- if (pp->content_filename != NULL)
+ if (NULL != pp->content_filename)
pp->have |= NE_content_filename;
- if (pp->content_transfer_encoding != NULL)
+ if (NULL != pp->content_transfer_encoding)
pp->have |= NE_content_transfer_encoding;
pp->state = PP_Nested_ProcessEntryHeaders;
state_changed = 1;
@@ -1061,7 +1136,8 @@ post_process_multipart (struct MHD_PostProcessor *pp,
case PP_Nested_ProcessEntryHeaders:
pp->value_offset = 0;
if (MHD_NO ==
- process_multipart_headers (pp, &ioff,
+ process_multipart_headers (pp,
+ &ioff,
PP_Nested_ProcessValueToBoundary))
{
if (pp->state == PP_Error)
@@ -1090,21 +1166,28 @@ post_process_multipart (struct MHD_PostProcessor *pp,
state_changed = 1;
break;
default:
- mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); /* should never happen! */
+ mhd_panic (mhd_panic_cls,
+ __FILE__,
+ __LINE__,
+ NULL); /* should never happen! */
}
AGAIN:
if (ioff > 0)
{
- memmove (buf, &buf[ioff], pp->buffer_pos - ioff);
+ memmove (buf,
+ &buf[ioff],
+ pp->buffer_pos - ioff);
pp->buffer_pos -= ioff;
ioff = 0;
state_changed = 1;
}
}
END:
- if (ioff != 0)
+ if (0 != ioff)
{
- memmove (buf, &buf[ioff], pp->buffer_pos - ioff);
+ memmove (buf,
+ &buf[ioff],
+ pp->buffer_pos - ioff);
pp->buffer_pos -= ioff;
}
if (poff < post_data_len)
@@ -1131,18 +1214,25 @@ END:
*/
int
MHD_post_process (struct MHD_PostProcessor *pp,
- const char *post_data, size_t post_data_len)
+ const char *post_data,
+ size_t post_data_len)
{
if (0 == post_data_len)
return MHD_YES;
if (NULL == pp)
return MHD_NO;
- if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, pp->encoding,
- strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
- return post_process_urlencoded (pp, post_data, post_data_len);
- if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, pp->encoding,
- strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
- return post_process_multipart (pp, post_data, post_data_len);
+ if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
+ pp->encoding,
+ strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
+ return post_process_urlencoded (pp,
+ post_data,
+ post_data_len);
+ if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
+ pp->encoding,
+ strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
+ return post_process_multipart (pp,
+ post_data,
+ post_data_len);
/* this should never be reached */
return MHD_NO;
}
@@ -1170,20 +1260,22 @@ MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
/* key without terminated value left at the end of the
buffer; fake receiving a termination character to
ensure it is also processed */
- post_process_urlencoded (pp, "\n", 1);
+ post_process_urlencoded (pp,
+ "\n",
+ 1);
}
/* These internal strings need cleaning up since
the post-processing may have been interrupted
at any stage */
- if ((pp->xbuf_pos > 0) ||
- ( (pp->state != PP_Done) &&
- (pp->state != PP_ExpectNewLine)))
+ if ( (pp->xbuf_pos > 0) ||
+ ( (pp->state != PP_Done) &&
+ (pp->state != PP_ExpectNewLine) ) )
ret = MHD_NO;
else
ret = MHD_YES;
pp->have = NE_none;
free_unmarked (pp);
- if (pp->nested_boundary != NULL)
+ if (NULL != pp->nested_boundary)
free (pp->nested_boundary);
free (pp);
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 @@
#define NULL (void*)0
#endif
-static const char *invalid_hundred[] = { NULL };
+static const char *invalid_hundred[] = {
+ NULL
+};
static const char *const one_hundred[] = {
"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,
struct MHD_HTTP_Header *pos;
struct MHD_HTTP_Header *prev;
- if ( (NULL == header) || (NULL == content) )
+ if ( (NULL == header) ||
+ (NULL == content) )
return MHD_NO;
prev = NULL;
pos = response->first_header;
while (pos != NULL)
{
- if ((0 == strcmp (header, pos->header)) &&
- (0 == strcmp (content, pos->value)))
+ if ((0 == strcmp (header,
+ pos->header)) &&
+ (0 == strcmp (content,
+ pos->value)))
{
free (pos->header);
free (pos->value);
@@ -228,7 +231,8 @@ MHD_get_response_header (struct MHD_Response *response,
if (NULL == key)
return NULL;
for (pos = response->first_header; NULL != pos; pos = pos->next)
- if (0 == strcmp (key, pos->header))
+ if (0 == strcmp (key,
+ pos->header))
return pos->value;
return NULL;
}
@@ -263,11 +267,13 @@ MHD_create_response_from_callback (uint64_t size,
return NULL;
if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size)))
return NULL;
- memset (response, 0, sizeof (struct MHD_Response));
+ memset (response,
+ 0,
+ sizeof (struct MHD_Response));
response->fd = -1;
response->data = (void *) &response[1];
response->data_buffer_size = block_size;
- if (!MHD_mutex_init_ (&response->mutex))
+ if (! MHD_mutex_init_ (&response->mutex))
{
free (response);
return NULL;
@@ -372,7 +378,7 @@ file_reader (void *cls,
n = read (response->fd,
buf,
- (unsigned int)max);
+ (unsigned int) max);
#endif /* _WIN32 */
if (0 == n)
@@ -646,7 +652,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
if (MHD_INVALID_SOCKET != urh->app.socket)
{
if (0 != MHD_socket_close_ (urh->app.socket))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
urh->app.socket = MHD_INVALID_SOCKET;
}
return MHD_YES;
@@ -688,7 +694,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Invalid response for upgrade: application failed to set the 'Upgrade' header!\n");
+ _("Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
#endif
return MHD_NO;
}
@@ -720,7 +726,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Failed to make read side of inter-thread control channel non-blocking: %s\n",
+ _("Failed to make read side of inter-thread control channel non-blocking: %s\n"),
MHD_pipe_last_strerror_ ());
#endif
}
@@ -729,14 +735,14 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Socketpair descriptor larger than FD_SETSIZE: %d > %d\n",
+ _("Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
(int) sv[1],
(int) FD_SETSIZE);
#endif
if (0 != MHD_socket_close_ (sv[0]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
if (0 != MHD_socket_close_ (sv[1]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
free (urh);
return MHD_NO;
}
@@ -803,13 +809,13 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Call to epoll_ctl failed: %s\n",
+ _("Call to epoll_ctl failed: %s\n"),
MHD_socket_last_strerr_ ());
#endif
if (0 != MHD_socket_close_ (sv[0]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
if (0 != MHD_socket_close_ (sv[1]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
free (urh);
return MHD_NO;
}
@@ -828,16 +834,16 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
EPOLL_CTL_DEL,
connection->socket_fd,
&event))
- MHD_PANIC ("Error cleaning up while handling epoll error");
+ MHD_PANIC (_("Error cleaning up while handling epoll error"));
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Call to epoll_ctl failed: %s\n",
+ _("Call to epoll_ctl failed: %s\n"),
MHD_socket_last_strerr_ ());
#endif
if (0 != MHD_socket_close_ (sv[0]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
if (0 != MHD_socket_close_ (sv[1]))
- MHD_PANIC ("close failed\n");
+ MHD_PANIC (_("close failed\n"));
free (urh);
return MHD_NO;
}
@@ -875,7 +881,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- "Failed to create semaphore for upgrade handling\n");
+ _("Failed to create semaphore for upgrade handling\n"));
#endif
MHD_connection_close_ (connection,
MHD_REQUEST_TERMINATED_WITH_ERROR);
@@ -989,7 +995,7 @@ MHD_destroy_response (struct MHD_Response *response)
}
(void) MHD_mutex_unlock_ (&response->mutex);
(void) MHD_mutex_destroy_ (&response->mutex);
- if (response->crfc != NULL)
+ if (NULL != response->crfc)
response->crfc (response->crc_cls);
while (NULL != response->first_header)
{
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 @@
#include "tsearch.h"
#include <stdlib.h>
-typedef struct node {
+
+typedef struct node
+{
const void *key;
- struct node *llink, *rlink;
+ struct node *llink;
+ struct node *rlink;
} node_t;
+
/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */
/* find or insert datum into search tree */
void *
-tsearch(const void *vkey, /* key to be located */
- void **vrootp, /* address of tree root */
- int (*compar)(const void *, const void *))
+tsearch (const void *vkey, /* key to be located */
+ void **vrootp, /* address of tree root */
+ int (*compar)(const void *, const void *))
{
- node_t *q;
- node_t **rootp = (node_t **)vrootp;
-
- if (rootp == NULL)
- return NULL;
-
- while (*rootp != NULL) { /* Knuth's T1: */
- int r;
-
- if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
- return *rootp; /* we found it! */
-
- rootp = (r < 0) ?
- &(*rootp)->llink : /* T3: follow left branch */
- &(*rootp)->rlink; /* T4: follow right branch */
- }
-
- q = malloc(sizeof(node_t)); /* T5: key not found */
- if (q) { /* make new node */
- *rootp = q; /* link new node to old */
- q->key = vkey; /* initialize new node */
- q->llink = q->rlink = NULL;
- }
- return q;
+ node_t *q;
+ node_t **rootp = (node_t **)vrootp;
+
+ if (NULL == rootp)
+ return NULL;
+
+ while (*rootp != NULL)
+ { /* Knuth's T1: */
+ int r;
+
+ if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
+ return *rootp; /* we found it! */
+
+ rootp = (r < 0) ?
+ &(*rootp)->llink : /* T3: follow left branch */
+ &(*rootp)->rlink; /* T4: follow right branch */
+ }
+
+ q = malloc (sizeof(node_t)); /* T5: key not found */
+ if (q)
+ { /* make new node */
+ *rootp = q; /* link new node to old */
+ q->key = vkey; /* initialize new node */
+ q->llink = q->rlink = NULL;
+ }
+ return q;
}
+
/* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */
/* find a node, or return NULL */
void *
-tfind(const void *vkey, /* key to be found */
- void * const *vrootp, /* address of the tree root */
- int (*compar)(const void *, const void *))
+tfind (const void *vkey, /* key to be found */
+ void * const *vrootp, /* address of the tree root */
+ int (*compar)(const void *, const void *))
{
- node_t * const *rootp = (node_t * const*)vrootp;
-
- if (rootp == NULL)
- return NULL;
-
- while (*rootp != NULL) { /* T1: */
- int r;
-
- if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
- return *rootp; /* key found */
- rootp = (r < 0) ?
- &(*rootp)->llink : /* T3: follow left branch */
- &(*rootp)->rlink; /* T4: follow right branch */
- }
- return NULL;
+ node_t * const *rootp = (node_t * const*)vrootp;
+
+ if (NULL == rootp)
+ return NULL;
+
+ while (*rootp != NULL)
+ { /* T1: */
+ int r;
+
+ if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */
+ return *rootp; /* key found */
+ rootp = (r < 0) ?
+ &(*rootp)->llink : /* T3: follow left branch */
+ &(*rootp)->rlink; /* T4: follow right branch */
+ }
+ return NULL;
}
+
/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */
/*
* delete node with given key
@@ -83,42 +92,52 @@ tfind(const void *vkey, /* key to be found */
* compar: function to carry out node comparisons
*/
void *
-tdelete(const void * __restrict vkey, void ** __restrict vrootp,
- int (*compar)(const void *, const void *))
+tdelete (const void * __restrict vkey,
+ void ** __restrict vrootp,
+ int (*compar)(const void *, const void *))
{
- node_t **rootp = (node_t **)vrootp;
- node_t *p, *q, *r;
- int cmp;
-
- if (rootp == NULL || (p = *rootp) == NULL)
- return NULL;
-
- while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) {
- p = *rootp;
- rootp = (cmp < 0) ?
- &(*rootp)->llink : /* follow llink branch */
- &(*rootp)->rlink; /* follow rlink branch */
- if (*rootp == NULL)
- return NULL; /* key not found */
- }
- r = (*rootp)->rlink; /* D1: */
- if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
- q = r;
- else if (r != NULL) { /* Right link is NULL? */
- if (r->llink == NULL) { /* D2: Find successor */
- r->llink = q;
- q = r;
- } else { /* D3: Find NULL link */
- for (q = r->llink; q->llink != NULL; q = r->llink)
- r = q;
- r->llink = q->rlink;
- q->llink = (*rootp)->llink;
- q->rlink = (*rootp)->rlink;
- }
- }
- free(*rootp); /* D4: Free node */
- *rootp = q; /* link parent to new node */
- return p;
+ node_t **rootp = (node_t **)vrootp;
+ node_t *p;
+ node_t *q;
+ node_t *r;
+ int cmp;
+
+ if (rootp == NULL || (p = *rootp) == NULL)
+ return NULL;
+
+ while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0)
+ {
+ p = *rootp;
+ rootp = (cmp < 0) ?
+ &(*rootp)->llink : /* follow llink branch */
+ &(*rootp)->rlink; /* follow rlink branch */
+ if (*rootp == NULL)
+ return NULL; /* key not found */
+ }
+ r = (*rootp)->rlink; /* D1: */
+ if ((q = (*rootp)->llink) == NULL) /* Left NULL? */
+ {
+ q = r;
+ }
+ else if (r != NULL)
+ { /* Right link is NULL? */
+ if (r->llink == NULL)
+ { /* D2: Find successor */
+ r->llink = q;
+ q = r;
+ }
+ else
+ { /* D3: Find NULL link */
+ for (q = r->llink; q->llink != NULL; q = r->llink)
+ r = q;
+ r->llink = q->rlink;
+ q->llink = (*rootp)->llink;
+ q->rlink = (*rootp)->rlink;
+ }
+ }
+ free(*rootp); /* D4: Free node */
+ *rootp = q; /* link parent to new node */
+ return p;
}
/* 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 @@
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
-void *tdelete(const void * __restrict, void ** __restrict,
- int (*)(const void *, const void *));
-void *tfind(const void *, void * const *,
- int (*)(const void *, const void *));
-void *tsearch(const void *, void **, int (*)(const void *, const void *));
+
+
+void *
+tdelete (const void * __restrict,
+ void ** __restrict,
+ int (*)(const void *, const void *));
+
+
+void *
+tfind (const void *,
+ void * const *,
+ int (*)(const void *, const void *));
+
+
+void *
+tsearch (const void *,
+ void **,
+ int (*)(const void *, const void *));
+
#if defined(__cplusplus)
};
#endif /* __cplusplus */