summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-05 12:15:43 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-05 12:15:43 +0000
commit9c4c3e03db98e2deef59815e02b3bab3879b12b0 (patch)
tree680530c37806c4b8003b562d8d8c13a3d133856d
parent5ef83163f7535b36c9ac5b3c302284a2ccaacb30 (diff)
-remove duplicated socket_start_no_buffering logic in socket_start_no_buffering_flash
-rw-r--r--src/microhttpd/basicauth.c15
-rw-r--r--src/microhttpd/connection.c163
2 files changed, 105 insertions, 73 deletions
diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c
index 30e0d2b0..b25e54fa 100644
--- a/src/microhttpd/basicauth.c
+++ b/src/microhttpd/basicauth.c
@@ -55,7 +55,9 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
if ( (NULL == (header = MHD_lookup_connection_value (connection,
MHD_HEADER_KIND,
MHD_HTTP_HEADER_AUTHORIZATION))) ||
- (0 != strncmp (header, _BASIC_BASE, strlen(_BASIC_BASE))) )
+ (0 != strncmp (header,
+ _BASIC_BASE,
+ strlen (_BASIC_BASE))) )
return NULL;
header += strlen (_BASIC_BASE);
if (NULL == (decode = BASE64Decode (header)))
@@ -67,11 +69,12 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
return NULL;
}
/* Find user:password pattern */
- if (NULL == (separator = strchr (decode, ':')))
+ if (NULL == (separator = strchr (decode,
+ ':')))
{
#ifdef HAVE_MESSAGES
MHD_DLOG(connection->daemon,
- "Basic authentication doesn't contain ':' separator\n");
+ _("Basic authentication doesn't contain ':' separator\n"));
#endif
free (decode);
return NULL;
@@ -89,7 +92,7 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
{
#ifdef HAVE_MESSAGES
MHD_DLOG(connection->daemon,
- "Failed to allocate memory for password\n");
+ _("Failed to allocate memory for password\n"));
#endif
free (decode);
free (user);
@@ -123,7 +126,7 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
size_t hlen = strlen(realm) + strlen("Basic realm=\"\"") + 1;
char *header;
- header = (char*)malloc(hlen);
+ header = (char *) malloc(hlen);
if (NULL == header)
{
#ifdef HAVE_MESSAGES
@@ -152,7 +155,7 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
{
#ifdef HAVE_MESSAGES
MHD_DLOG (connection->daemon,
- "Failed to add Basic auth header\n");
+ _("Failed to add Basic auth header\n"));
#endif /* HAVE_MESSAGES */
}
return ret;
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index bd8af585..43a90ee0 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -154,25 +154,40 @@ socket_start_extra_buffering (struct MHD_Connection *connection)
return MHD_NO;
#if defined(TCP_NOPUSH) && !defined(TCP_CORK)
/* Buffer data before sending */
- res = (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, (const void*)&on_val,
- sizeof (on_val))) ? MHD_YES : MHD_NO;
+ res = (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NOPUSH,
+ (const void *) &on_val,
+ sizeof (on_val)))
+ ? MHD_YES : MHD_NO;
#if defined(TCP_NODELAY)
/* Enable Nagle's algorithm */
/* TCP_NODELAY may interfere with TCP_NOPUSH */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
#endif /* TCP_NODELAY */
#else /* TCP_CORK */
#if defined(TCP_NODELAY)
/* Enable Nagle's algorithm */
/* TCP_NODELAY may prevent enabling TCP_CORK. Resulting buffering mode depends
solely on TCP_CORK result, so ignoring return code here. */
- (void)setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&off_val,
- sizeof (off_val));
+ (void) setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (const void *) &off_val,
+ sizeof (off_val));
#endif /* TCP_NODELAY */
/* Send only full packets */
- res = (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (const void*)&on_val,
- sizeof (on_val))) ? MHD_YES : MHD_NO;
+ res = (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_CORK,
+ (const void *) &on_val,
+ sizeof (on_val)))
+ ? MHD_YES : MHD_NO;
#endif /* TCP_CORK */
#endif /* TCP_CORK || TCP_NOPUSH */
return res;
@@ -180,88 +195,86 @@ socket_start_extra_buffering (struct MHD_Connection *connection)
/**
- * Activate no buffering mode (no delay sending) on connection socket
- * and push to client data pending in socket buffer.
+ * Activate no buffering mode (no delay sending) on connection socket.
*
* @param connection connection to be processed
* @return #MHD_YES on success, #MHD_NO otherwise
*/
static int
-socket_start_no_buffering_flush (struct MHD_Connection *connection)
+socket_start_no_buffering (struct MHD_Connection *connection)
{
-#if defined(TCP_CORK) || defined(TCP_NOPUSH)
- int res = MHD_YES;
- const MHD_SCKT_OPT_BOOL_ off_val = 0;
#if defined(TCP_NODELAY)
+ int res = MHD_YES;
const MHD_SCKT_OPT_BOOL_ on_val = 1;
-#endif /* TCP_NODELAY */
-#if !defined(TCP_CORK)
- const int dummy = 0;
-#endif /* !TCP_CORK */
- if (!connection)
+#if defined(TCP_CORK) || defined(TCP_NOPUSH)
+ const MHD_SCKT_OPT_BOOL_ off_val = 0;
+#endif /* TCP_CORK || TCP_NOPUSH */
+
+ if (NULL == connection)
return MHD_NO;
#if defined(TCP_CORK)
- /* Flush buffered data, allow partial packets */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
+ /* Allow partial packets */
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_CORK,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
#endif /* TCP_CORK */
#if defined(TCP_NODELAY)
- /* Disable Nagle's algorithm */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&on_val,
- sizeof (on_val))) ? MHD_YES : MHD_NO;
+ /* Disable Nagle's algorithm for sending packets without delay */
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (const void *) &on_val,
+ sizeof (on_val)))
+ ? MHD_YES : MHD_NO;
#endif /* TCP_NODELAY */
#if defined(TCP_NOPUSH) && !defined(TCP_CORK)
- /* Send data without extra buffering, may flush pending data on some platforms */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
- /* Force flush data with zero send otherwise Darwin and some BSD systems
- will add 5 seconds delay. Not required with TCP_CORK as switching off
- TCP_CORK always flushes socket buffer. */
- res &= (0 <= send (connection->socket_fd, (const void*)&dummy, 0, 0)) ? MHD_YES : MHD_NO;
-#endif /* TCP_NOPUSH && !TCP_CORK*/
+ /* Disable extra buffering */
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NOPUSH,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
+#endif /* TCP_NOPUSH && !TCP_CORK */
return res;
-#else /* !TCP_CORK && !TCP_NOPUSH */
+#else /* !TCP_NODELAY */
return MHD_NO;
-#endif /* !TCP_CORK && !TCP_NOPUSH */
+#endif /* !TCP_NODELAY */
}
/**
- * Activate no buffering mode (no delay sending) on connection socket.
+ * Activate no buffering mode (no delay sending) on connection socket
+ * and push to client data pending in socket buffer.
*
* @param connection connection to be processed
* @return #MHD_YES on success, #MHD_NO otherwise
*/
static int
-socket_start_no_buffering (struct MHD_Connection *connection)
+socket_start_no_buffering_flush (struct MHD_Connection *connection)
{
-#if defined(TCP_NODELAY)
int res = MHD_YES;
- const MHD_SCKT_OPT_BOOL_ on_val = 1;
-#if defined(TCP_CORK) || defined(TCP_NOPUSH)
- const MHD_SCKT_OPT_BOOL_ off_val = 0;
-#endif /* TCP_CORK || TCP_NOPUSH */
- if (!connection)
+#if defined(TCP_NOPUSH) && !defined(TCP_CORK)
+ const int dummy = 0;
+#endif /* !TCP_CORK */
+
+ if (NULL == connection)
return MHD_NO;
-#if defined(TCP_CORK)
- /* Allow partial packets */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_CORK */
-#if defined(TCP_NODELAY)
- /* Disable Nagle's algorithm for sending packets without delay */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&on_val,
- sizeof (on_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_NODELAY */
+ res = socket_start_no_buffering (connection);
#if defined(TCP_NOPUSH) && !defined(TCP_CORK)
- /* Disable extra buffering */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
-#endif /* TCP_NOPUSH && !TCP_CORK */
+ /* Force flush data with zero send otherwise Darwin and some BSD systems
+ will add 5 seconds delay. Not required with TCP_CORK as switching off
+ TCP_CORK always flushes socket buffer. */
+ res &= (0 <= send (connection->socket_fd,
+ (const void *) &dummy,
+ 0,
+ 0))
+ ? MHD_YES : MHD_NO;
+#endif /* TCP_NOPUSH && !TCP_CORK*/
return res;
-#else /* !TCP_NODELAY */
- return MHD_NO;
-#endif /* !TCP_NODELAY */
}
@@ -287,20 +300,36 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
/* Allow partial packets */
/* Disabling TCP_CORK will flush partial packet even if TCP_CORK wasn't enabled before
so try to check current value of TCP_CORK to prevent unrequested flushing */
- if ( (0 != getsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (void*)&cork_val, &param_size)) ||
+ if ( (0 != getsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_CORK,
+ (void*)&cork_val,
+ &param_size)) ||
(0 != cork_val))
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_CORK,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
#elif defined(TCP_NOPUSH)
/* Disable extra buffering */
/* No need to check current value as disabling TCP_NOPUSH will not flush partial
packet if TCP_NOPUSH wasn't enabled before */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NOPUSH, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NOPUSH,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
#endif /* TCP_NOPUSH && !TCP_CORK */
/* Enable Nagle's algorithm for normal buffering */
- res &= (0 == setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_NODELAY, (const void*)&off_val,
- sizeof (off_val))) ? MHD_YES : MHD_NO;
+ res &= (0 == setsockopt (connection->socket_fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (const void *) &off_val,
+ sizeof (off_val)))
+ ? MHD_YES : MHD_NO;
return res;
#else /* !TCP_NODELAY */
return MHD_NO;