From f794d6b09631610e4473d6e356f24b09195105bf Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 16 Dec 2007 10:28:22 +0000 Subject: formatting --- src/daemon/connection.c | 421 +++++++++++++++++++----------------- src/daemon/daemon.c | 24 +- src/daemon/daemontest_post_loop.c | 385 +++++++++++++++++---------------- src/daemon/daemontest_postform.c | 66 +++--- src/daemon/daemontest_put_chunked.c | 38 ++-- src/daemon/postprocessor.c | 8 +- src/daemon/reason_phrase.c | 36 +-- src/daemon/reason_phrase.h | 3 +- 8 files changed, 499 insertions(+), 482 deletions(-) diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 83540622..318439a8 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -152,7 +152,8 @@ MHD_queue_response (struct MHD_Connection *connection, if ((connection == NULL) || (response == NULL) || (connection->response != NULL) || - (connection->have_received_body == MHD_NO) || (connection->have_received_headers == MHD_NO)) + (connection->have_received_body == MHD_NO) + || (connection->have_received_headers == MHD_NO)) return MHD_NO; MHD_increment_response_rc (response); connection->response = response; @@ -184,7 +185,8 @@ MHD_need_100_continue (struct MHD_Connection *connection) MHD_HEADER_KIND, MHD_HTTP_HEADER_EXPECT))) && (0 == strcasecmp (expect, "100-continue")) - && (connection->continue_message_write_offset < strlen (HTTP_100_CONTINUE))); + && (connection->continue_message_write_offset < + strlen (HTTP_100_CONTINUE))); } /** @@ -224,11 +226,12 @@ ready_response (struct MHD_Connection *connection) connection->response_write_position, response->data, MIN (response->data_buffer_size, - response->total_size - connection->response_write_position)); + response->total_size - + connection->response_write_position)); if (ret == -1) { /* end of message, signal other side by closing! */ -#if DEBUG_CLOSE +#if DEBUG_CLOSE #if HAVE_MESSAGES MHD_DLOG (connection->daemon, "Closing connection (end of response)\n"); #endif @@ -608,9 +611,9 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) unsigned long long cval; struct MHD_Response *response; - if ( ( (connection->have_received_body == MHD_YES) && - (connection->have_chunked_upload == MHD_NO) ) || - (connection->have_received_headers == MHD_YES) ) + if (((connection->have_received_body == MHD_YES) && + (connection->have_chunked_upload == MHD_NO)) || + (connection->have_received_headers == MHD_YES)) abort (); colon = NULL; /* make gcc happy */ last = NULL; @@ -689,24 +692,25 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) } else { - if (connection->have_chunked_upload == MHD_NO) - { - connection->remaining_upload_size = -1; /* unknown size */ - if (0 == strcasecmp(MHD_lookup_connection_value(connection, - MHD_HEADER_KIND, - MHD_HTTP_HEADER_TRANSFER_ENCODING), - "chunked")) - connection->have_chunked_upload = MHD_YES; - } - else - { - /* we were actually processing the footers at the - END of a chunked encoding; give connection - handler an extra chance... */ - connection->have_chunked_upload = MHD_NO; /* no more! */ - MHD_call_connection_handler(connection); - } - } + if (connection->have_chunked_upload == MHD_NO) + { + connection->remaining_upload_size = -1; /* unknown size */ + if (0 == + strcasecmp (MHD_lookup_connection_value + (connection, MHD_HEADER_KIND, + MHD_HTTP_HEADER_TRANSFER_ENCODING), + "chunked")) + connection->have_chunked_upload = MHD_YES; + } + else + { + /* we were actually processing the footers at the + END of a chunked encoding; give connection + handler an extra chance... */ + connection->have_chunked_upload = MHD_NO; /* no more! */ + MHD_call_connection_handler (connection); + } + } } if ((0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) && (NULL != connection->version) @@ -807,166 +811,167 @@ MHD_call_connection_handler (struct MHD_Connection *connection) return; /* already queued a response */ if (connection->have_received_headers == MHD_NO) abort (); /* bad timing... */ - do + do { instant_retry = MHD_NO; available = connection->read_buffer_offset; - if (connection->have_chunked_upload == MHD_YES) - { - if ( (connection->current_chunk_offset == connection->current_chunk_size) && - (connection->current_chunk_offset != 0) && - (available >= 2) ) - { - /* skip new line at the *end* of a chunk */ - i = 0; - if ( (connection->read_buffer[i] == '\r') || - (connection->read_buffer[i] == '\n') ) - i++; /* skip 1st part of line feed */ - if ( (connection->read_buffer[i] == '\r') || - (connection->read_buffer[i] == '\n') ) - i++; /* skip 2nd part of line feed */ - if (i == 0) - { - /* malformed encoding */ + if (connection->have_chunked_upload == MHD_YES) + { + if ((connection->current_chunk_offset == + connection->current_chunk_size) + && (connection->current_chunk_offset != 0) && (available >= 2)) + { + /* skip new line at the *end* of a chunk */ + i = 0; + if ((connection->read_buffer[i] == '\r') || + (connection->read_buffer[i] == '\n')) + i++; /* skip 1st part of line feed */ + if ((connection->read_buffer[i] == '\r') || + (connection->read_buffer[i] == '\n')) + i++; /* skip 2nd part of line feed */ + if (i == 0) + { + /* malformed encoding */ #if HAVE_MESSAGES - MHD_DLOG (connection->daemon, - "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); + MHD_DLOG (connection->daemon, + "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); #endif - connection_close_error (connection); - return; - } - connection->read_buffer_offset -= i; - available -= i; - memmove(connection->read_buffer, - &connection->read_buffer[i], - available); - connection->current_chunk_offset = 0; - connection->current_chunk_size = 0; - } - if (connection->current_chunk_offset < connection->current_chunk_size) - { - /* we are in the middle of a chunk, give - as much as possible to the client (without - crossing chunk boundaries) */ - processed = connection->current_chunk_size - connection->current_chunk_offset; - if (processed > available) - processed = available; - available -= processed; - if (available > 0) - instant_retry = MHD_YES; - } - else - { - /* we need to read chunk boundaries */ - i = 0; - while (i < available) - { - if ( (connection->read_buffer[i] == '\r') || - (connection->read_buffer[i] == '\n') ) - break; - i++; - if (i >= 6) - break; - } - if (i >= available) - return; /* need more data... */ - /* The following if-statement is a bit crazy -- we - use the second clause only for the side-effect, - 0-terminating the buffer for the following sscanf - attempts; yes, there should be only a single - "="-sign (assignment!) in the read_buffer[i]-line. */ - if ( (i >= 6) || - ((connection->read_buffer[i] = '\0')) || - ( (1 != sscanf(connection->read_buffer, - "%X", - &connection->current_chunk_size)) && - (1 != sscanf(connection->read_buffer, - "%x", - &connection->current_chunk_size)) ) ) - { - /* malformed encoding */ + connection_close_error (connection); + return; + } + connection->read_buffer_offset -= i; + available -= i; + memmove (connection->read_buffer, + &connection->read_buffer[i], available); + connection->current_chunk_offset = 0; + connection->current_chunk_size = 0; + } + if (connection->current_chunk_offset < + connection->current_chunk_size) + { + /* we are in the middle of a chunk, give + as much as possible to the client (without + crossing chunk boundaries) */ + processed = + connection->current_chunk_size - + connection->current_chunk_offset; + if (processed > available) + processed = available; + available -= processed; + if (available > 0) + instant_retry = MHD_YES; + } + else + { + /* we need to read chunk boundaries */ + i = 0; + while (i < available) + { + if ((connection->read_buffer[i] == '\r') || + (connection->read_buffer[i] == '\n')) + break; + i++; + if (i >= 6) + break; + } + if (i >= available) + return; /* need more data... */ + /* The following if-statement is a bit crazy -- we + use the second clause only for the side-effect, + 0-terminating the buffer for the following sscanf + attempts; yes, there should be only a single + "="-sign (assignment!) in the read_buffer[i]-line. */ + if ((i >= 6) || + ((connection->read_buffer[i] = '\0')) || + ((1 != sscanf (connection->read_buffer, + "%X", + &connection->current_chunk_size)) && + (1 != sscanf (connection->read_buffer, + "%x", &connection->current_chunk_size)))) + { + /* malformed encoding */ #if HAVE_MESSAGES - MHD_DLOG (connection->daemon, - "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); + MHD_DLOG (connection->daemon, + "Received malformed HTTP request (bad chunked encoding), closing connection.\n"); #endif - connection_close_error (connection); - return; - } - i++; - if ( (connection->read_buffer[i] == '\r') || - (connection->read_buffer[i] == '\n') ) - i++; /* skip 2nd part of line feed */ - memmove(connection->read_buffer, - &connection->read_buffer[i], - available - i); - connection->read_buffer_offset -= i; - connection->current_chunk_offset = 0; - instant_retry = MHD_YES; - if (connection->current_chunk_size == 0) - { - /* we're back to reading HEADERS (footers!) */ - connection->have_received_body = MHD_YES; - connection->remaining_upload_size = 0; - connection->have_received_headers = MHD_NO; - MHD_parse_connection_headers(connection); - return; - } - continue; - } - } + connection_close_error (connection); + return; + } + i++; + if ((connection->read_buffer[i] == '\r') || + (connection->read_buffer[i] == '\n')) + i++; /* skip 2nd part of line feed */ + memmove (connection->read_buffer, + &connection->read_buffer[i], available - i); + connection->read_buffer_offset -= i; + connection->current_chunk_offset = 0; + instant_retry = MHD_YES; + if (connection->current_chunk_size == 0) + { + /* we're back to reading HEADERS (footers!) */ + connection->have_received_body = MHD_YES; + connection->remaining_upload_size = 0; + connection->have_received_headers = MHD_NO; + MHD_parse_connection_headers (connection); + return; + } + continue; + } + } else - { - /* no chunked encoding, give all to the client */ - processed = available; - available = 0; - } + { + /* no chunked encoding, give all to the client */ + processed = available; + available = 0; + } used = processed; ah = MHD_find_access_handler (connection); if (MHD_NO == ah->dh (ah->dh_cls, - connection, - connection->url, - connection->method, - connection->version, - connection->read_buffer, &processed, - &connection->client_context)) - { - /* serious internal error, close connection */ + connection, + connection->url, + connection->method, + connection->version, + connection->read_buffer, &processed, + &connection->client_context)) + { + /* serious internal error, close connection */ #if HAVE_MESSAGES - MHD_DLOG (connection->daemon, - "Internal application error, closing connection.\n"); + MHD_DLOG (connection->daemon, + "Internal application error, closing connection.\n"); #endif - connection_close_error (connection); - return; - } + connection_close_error (connection); + return; + } if (processed != 0) - instant_retry = MHD_NO; /* client did not process everything */ + instant_retry = MHD_NO; /* client did not process everything */ used -= processed; - if (connection->have_chunked_upload == MHD_YES) - connection->current_chunk_offset += used; + if (connection->have_chunked_upload == MHD_YES) + connection->current_chunk_offset += used; /* dh left "processed" bytes in buffer for next time... */ if (used > 0) - memmove (connection->read_buffer, - &connection->read_buffer[used], - processed + available); - if (connection->remaining_upload_size != -1) - connection->remaining_upload_size -= used; + memmove (connection->read_buffer, + &connection->read_buffer[used], processed + available); + if (connection->remaining_upload_size != -1) + connection->remaining_upload_size -= used; connection->read_buffer_offset = processed + available; if ((connection->remaining_upload_size == 0) || - ((connection->read_buffer_offset == 0) && - (connection->remaining_upload_size == -1) && (connection->socket_fd == -1))) - { - connection->have_received_body = MHD_YES; - if (connection->read_buffer != NULL) - MHD_pool_reallocate (connection->pool, - connection->read_buffer, - (connection->read_buffer == - NULL) ? 0 : connection->read_buffer_size + 1, - 0); - connection->read_buffer_offset = 0; - connection->read_buffer_size = 0; - connection->read_buffer = NULL; - } - } while (instant_retry == MHD_YES); + ((connection->read_buffer_offset == 0) && + (connection->remaining_upload_size == -1) + && (connection->socket_fd == -1))) + { + connection->have_received_body = MHD_YES; + if (connection->read_buffer != NULL) + MHD_pool_reallocate (connection->pool, + connection->read_buffer, + (connection->read_buffer == + NULL) ? 0 : connection->read_buffer_size + + 1, 0); + connection->read_buffer_offset = 0; + connection->read_buffer_size = 0; + connection->read_buffer = NULL; + } + } + while (instant_retry == MHD_YES); } /** @@ -1023,8 +1028,8 @@ MHD_connection_handle_read (struct MHD_Connection *connection) } bytes_read = RECV (connection->socket_fd, &connection->read_buffer[connection->read_buffer_offset], - connection->read_buffer_size - connection->read_buffer_offset, - MSG_NOSIGNAL); + connection->read_buffer_size - + connection->read_buffer_offset, MSG_NOSIGNAL); if (bytes_read < 0) { if (errno == EINTR) @@ -1040,7 +1045,8 @@ MHD_connection_handle_read (struct MHD_Connection *connection) { /* other side closed connection */ connection->read_close = MHD_YES; - if ((connection->have_received_headers == MHD_YES) && (connection->read_buffer_offset > 0)) + if ((connection->have_received_headers == MHD_YES) + && (connection->read_buffer_offset > 0)) MHD_call_connection_handler (connection); #if DEBUG_CLOSE #if HAVE_MESSAGES @@ -1049,18 +1055,20 @@ MHD_connection_handle_read (struct MHD_Connection *connection) #endif #endif shutdown (connection->socket_fd, SHUT_RD); - if ( (connection->have_received_headers == MHD_NO) || - (connection->have_received_body == MHD_NO) ) { - /* no request => no response! */ - CLOSE (connection->socket_fd); - connection->socket_fd = -1; - } + if ((connection->have_received_headers == MHD_NO) || + (connection->have_received_body == MHD_NO)) + { + /* no request => no response! */ + CLOSE (connection->socket_fd); + connection->socket_fd = -1; + } return MHD_YES; } connection->read_buffer_offset += bytes_read; if (connection->have_received_headers == MHD_NO) MHD_parse_connection_headers (connection); - if ((connection->have_received_headers == MHD_YES) && (connection->method != NULL)) + if ((connection->have_received_headers == MHD_YES) + && (connection->method != NULL)) MHD_call_connection_handler (connection); return MHD_YES; } @@ -1134,8 +1142,9 @@ MHD_build_header_response (struct MHD_Connection *connection) char *data; MHD_add_extra_headers (connection); - const char* reason_phrase = MHD_get_reason_phrase_for(connection->responseCode); - _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, + const char *reason_phrase = + MHD_get_reason_phrase_for (connection->responseCode); + _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, connection->responseCode, reason_phrase); off = strlen (code); /* estimate size */ @@ -1193,14 +1202,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { struct MHD_Response *response; int ret; - const char * end; + const char *end; if (MHD_need_100_continue (connection)) { ret = SEND (connection->socket_fd, - &HTTP_100_CONTINUE[connection->continue_message_write_offset], - strlen (HTTP_100_CONTINUE) - connection->continue_message_write_offset, - MSG_NOSIGNAL); + &HTTP_100_CONTINUE[connection-> + continue_message_write_offset], + strlen (HTTP_100_CONTINUE) - + connection->continue_message_write_offset, MSG_NOSIGNAL); if (ret < 0) { if (errno == EINTR) @@ -1215,7 +1225,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) #if DEBUG_SEND_DATA fprintf (stderr, "Sent 100 continue response: `%.*s'\n", - ret, &HTTP_100_CONTINUE[connection->continue_message_write_offset]); + ret, + &HTTP_100_CONTINUE[connection->continue_message_write_offset]); #endif connection->continue_message_write_offset += ret; return MHD_YES; @@ -1242,9 +1253,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) return MHD_NO; } ret = SEND (connection->socket_fd, - &connection->write_buffer[connection->write_buffer_send_offset], - connection->write_buffer_append_offset - connection->write_buffer_send_offset, - MSG_NOSIGNAL); + &connection->write_buffer[connection-> + write_buffer_send_offset], + connection->write_buffer_append_offset - + connection->write_buffer_send_offset, MSG_NOSIGNAL); if (ret < 0) { if (errno == EINTR) @@ -1259,10 +1271,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection) #if DEBUG_SEND_DATA fprintf (stderr, "Sent HEADER response: `%.*s'\n", - ret, &connection->write_buffer[connection->write_buffer_send_offset]); + ret, + &connection->write_buffer[connection-> + write_buffer_send_offset]); #endif connection->write_buffer_send_offset += ret; - if (connection->write_buffer_append_offset == connection->write_buffer_send_offset) + if (connection->write_buffer_append_offset == + connection->write_buffer_send_offset) { connection->write_buffer_append_offset = 0; connection->write_buffer_send_offset = 0; @@ -1284,17 +1299,18 @@ MHD_connection_handle_write (struct MHD_Connection *connection) if ((response->crc != NULL) && ((response->data_start > connection->response_write_position) || (response->data_start + response->data_size <= - connection->response_write_position)) && (MHD_YES != ready_response (connection))) + connection->response_write_position)) + && (MHD_YES != ready_response (connection))) { pthread_mutex_unlock (&response->mutex); return MHD_YES; } /* transmit */ ret = SEND (connection->socket_fd, - &response->data[connection->response_write_position - response->data_start], + &response->data[connection->response_write_position - + response->data_start], response->data_size - (connection->response_write_position - - response->data_start), - MSG_NOSIGNAL); + response->data_start), MSG_NOSIGNAL); if (response->crc != NULL) pthread_mutex_unlock (&response->mutex); if (ret < 0) @@ -1312,7 +1328,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) fprintf (stderr, "Sent DATA response: `%.*s'\n", ret, - &response->data[connection->response_write_position - response->data_start]); + &response->data[connection->response_write_position - + response->data_start]); #endif connection->response_write_position += ret; if (connection->response_write_position > response->total_size) @@ -1330,8 +1347,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) &connection->client_context, MHD_REQUEST_TERMINATED_COMPLETED_OK); end = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - MHD_HTTP_HEADER_CONNECTION); + MHD_HEADER_KIND, + MHD_HTTP_HEADER_CONNECTION); connection->client_context = NULL; connection->continue_message_write_offset = 0; connection->responseCode = 0; @@ -1343,14 +1360,14 @@ MHD_connection_handle_write (struct MHD_Connection *connection) connection->response_write_position = 0; connection->have_chunked_upload = MHD_NO; connection->method = NULL; - connection->url = NULL; + connection->url = NULL; if ((end != NULL) && (0 == strcasecmp (end, "close"))) - { - /* other side explicitly requested - that we close the connection after - this request */ - connection->read_close = MHD_YES; - } + { + /* other side explicitly requested + that we close the connection after + this request */ + connection->read_close = MHD_YES; + } if ((connection->read_close == MHD_YES) || (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) { diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 09a37255..19c614a1 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -171,7 +171,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon, } #if DEBUG_CONNECT MHD_DLOG (daemon, "Maximum socket in select set: %d\n", *max_fd); -#endif +#endif return MHD_YES; } @@ -264,7 +264,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) socklen_t addrlen; int s; #if OSX - static int on=1; + static int on = 1; #endif @@ -287,7 +287,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) } #if DEBUG_CONNECT MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); -#endif +#endif if (daemon->max_connections == 0) { /* above connection limit - reject */ @@ -314,11 +314,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) #if OSX #ifdef SOL_SOCKET #ifdef SO_NOSIGPIPE - setsockopt(s, - SOL_SOCKET, - SO_NOSIGPIPE, - &on, - sizeof(on)); + setsockopt (s, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof (on)); #endif #endif #endif @@ -437,8 +433,9 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) continue; } - if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - ((pos->have_received_headers == MHD_YES) && (pos->response == NULL)) ) + if ((0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && + ((pos->have_received_headers == MHD_YES) + && (pos->response == NULL))) MHD_call_connection_handler (pos); prev = pos; @@ -680,11 +677,12 @@ MHD_start_daemon (unsigned int options, if ((SETSOCKOPT (socket_fd, SOL_SOCKET, SO_REUSEADDR, - &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) { + &on, sizeof (on)) < 0) && (options & MHD_USE_DEBUG) != 0) + { #if HAVE_MESSAGES - fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); + fprintf (stderr, "setsockopt failed: %s\n", STRERROR (errno)); #endif - } + } if ((options & MHD_USE_IPv6) != 0) { memset (&servaddr6, 0, sizeof (struct sockaddr_in6)); diff --git a/src/daemon/daemontest_post_loop.c b/src/daemon/daemontest_post_loop.c index 588a02d3..f1555c16 100644 --- a/src/daemon/daemontest_post_loop.c +++ b/src/daemon/daemontest_post_loop.c @@ -78,19 +78,17 @@ ahc_echo (void *cls, printf ("METHOD: %s\n", method); return MHD_NO; /* unexpected method */ } - if ( (*mptr != NULL) && - (0 == *upload_data_size) ) { - if (*mptr != &marker) - abort(); - response = MHD_create_response_from_data (2, - "OK", - MHD_NO, MHD_NO); - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); - *mptr = NULL; - return ret; - } - if (strlen(POST_DATA) != *upload_data_size) + if ((*mptr != NULL) && (0 == *upload_data_size)) + { + if (*mptr != &marker) + abort (); + response = MHD_create_response_from_data (2, "OK", MHD_NO, MHD_NO); + ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + *mptr = NULL; + return ret; + } + if (strlen (POST_DATA) != *upload_data_size) return MHD_YES; *upload_data_size = 0; *mptr = ▮ @@ -115,48 +113,49 @@ testInternalPost () 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); if (d == NULL) return 1; - for (i=0;i= 0) ) - timeout = ctimeout; - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - select (max + 1, &rs, &ws, &es, &tv); - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform (multi, &running)); - if (running == 0) - { - msg = curl_multi_info_read (multi, &running); - if (msg == NULL) - break; - if (msg->msg == CURLMSG_DONE) - { - if (msg->data.result != CURLE_OK) - printf ("%s failed at %s:%d: `%s'\n", - "curl_multi_perform", - __FILE__, - __LINE__, curl_easy_strerror (msg->data.result)); - curl_multi_remove_handle (multi, c); - curl_easy_cleanup (c); - c = NULL; - } - } - MHD_run (d); - } - if (c != NULL) { - curl_multi_remove_handle (multi, c); - curl_easy_cleanup (c); + for (i = 0; i < LOOPCOUNT; i++) + { + if (0 == i % 100) + fprintf (stderr, "."); + c = curl_easy_init (); + cbc.pos = 0; + buf[0] = '\0'; + sprintf (url, "http://localhost:1082/hw%d", i); + curl_easy_setopt (c, CURLOPT_URL, url); + curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); + curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); + curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); + curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); + curl_easy_setopt (c, CURLOPT_POST, 1L); + curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); + curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); + if (oneone) + curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + else + curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); + // NOTE: use of CONNECTTIMEOUT without also + // setting NOSIGNAL results in really weird + // crashes on my system! + curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); + mret = curl_multi_add_handle (multi, c); + if (mret != CURLM_OK) + { + curl_multi_cleanup (multi); + curl_easy_cleanup (c); + MHD_stop_daemon (d); + return 1024; + } + start = time (NULL); + while ((time (NULL) - start < 5) && (multi != NULL)) + { + max = 0; + FD_ZERO (&rs); + FD_ZERO (&ws); + FD_ZERO (&es); + while (CURLM_CALL_MULTI_PERFORM == + curl_multi_perform (multi, &running)); + mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); + if (mret != CURLM_OK) + { + curl_multi_remove_handle (multi, c); + curl_multi_cleanup (multi); + curl_easy_cleanup (c); + MHD_stop_daemon (d); + return 2048; + } + if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) + { + curl_multi_remove_handle (multi, c); + curl_multi_cleanup (multi); + curl_easy_cleanup (c); + MHD_stop_daemon (d); + return 4096; + } + if (MHD_NO == MHD_get_timeout (d, &timeout)) + timeout = 1000000; /* 1000s == INFTY */ + if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && + (ctimeout < timeout) && (ctimeout >= 0)) + timeout = ctimeout; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + select (max + 1, &rs, &ws, &es, &tv); + while (CURLM_CALL_MULTI_PERFORM == + curl_multi_perform (multi, &running)); + if (running == 0) + { + msg = curl_multi_info_read (multi, &running); + if (msg == NULL) + break; + if (msg->msg == CURLMSG_DONE) + { + if (msg->data.result != CURLE_OK) + printf ("%s failed at %s:%d: `%s'\n", + "curl_multi_perform", + __FILE__, + __LINE__, curl_easy_strerror (msg->data.result)); + curl_multi_remove_handle (multi, c); + curl_easy_cleanup (c); + c = NULL; + } + } + MHD_run (d); + } + if (c != NULL) + { + curl_multi_remove_handle (multi, c); + curl_easy_cleanup (c); + } + if ((buf[0] != 'O') || (buf[1] != 'K')) + { + curl_multi_cleanup (multi); + MHD_stop_daemon (d); + return 8192; + } } - if ( (buf[0] != 'O') || - (buf[1] != 'K') ) { - curl_multi_cleanup (multi); - MHD_stop_daemon (d); - return 8192; - } - } - curl_multi_cleanup (multi); + curl_multi_cleanup (multi); MHD_stop_daemon (d); - fprintf(stderr, "\n"); + fprintf (stderr, "\n"); return 0; } diff --git a/src/daemon/daemontest_postform.c b/src/daemon/daemontest_postform.c index 0da5a74d..d02e8111 100644 --- a/src/daemon/daemontest_postform.c +++ b/src/daemon/daemontest_postform.c @@ -106,7 +106,7 @@ ahc_echo (void *cls, eok = 0; pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); if (pp == NULL) - abort(); + abort (); *unused = pp; } MHD_post_process (pp, upload_data, *upload_data_size); @@ -125,15 +125,16 @@ ahc_echo (void *cls, return MHD_YES; } -static struct curl_httppost * -make_form() { - struct curl_httppost* post = NULL; - struct curl_httppost* last = NULL; - - curl_formadd(&post, &last, CURLFORM_COPYNAME, "name", - CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END); - curl_formadd(&post, &last, CURLFORM_COPYNAME, "project", - CURLFORM_COPYCONTENTS, "curl", CURLFORM_END); +static struct curl_httppost * +make_form () +{ + struct curl_httppost *post = NULL; + struct curl_httppost *last = NULL; + + curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", + CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END); + curl_formadd (&post, &last, CURLFORM_COPYNAME, "project", + CURLFORM_COPYCONTENTS, "curl", CURLFORM_END); return post; } @@ -146,7 +147,7 @@ testInternalPost () char buf[2048]; struct CBC cbc; CURLcode errornum; - struct curl_httppost * pd; + struct curl_httppost *pd; cbc.buf = buf; cbc.size = 2048; @@ -159,8 +160,8 @@ testInternalPost () curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); - pd = make_form(); - curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); + pd = make_form (); + curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); if (oneone) @@ -178,12 +179,12 @@ testInternalPost () "curl_easy_perform failed: `%s'\n", curl_easy_strerror (errornum)); curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); return 2; } curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); if (cbc.pos != strlen ("/hello_world")) return 4; @@ -200,7 +201,7 @@ testMultithreadedPost () char buf[2048]; struct CBC cbc; CURLcode errornum; - struct curl_httppost * pd; + struct curl_httppost *pd; cbc.buf = buf; cbc.size = 2048; @@ -213,8 +214,8 @@ testMultithreadedPost () curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); - pd = make_form(); - curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); + pd = make_form (); + curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); if (oneone) @@ -232,12 +233,12 @@ testMultithreadedPost () "curl_easy_perform failed: `%s'\n", curl_easy_strerror (errornum)); curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); return 32; } curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); if (cbc.pos != strlen ("/hello_world")) return 64; @@ -264,7 +265,7 @@ testExternalPost () struct CURLMsg *msg; time_t start; struct timeval tv; - struct curl_httppost * pd; + struct curl_httppost *pd; multi = NULL; cbc.buf = buf; @@ -278,8 +279,8 @@ testExternalPost () curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); - pd = make_form(); - curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); + pd = make_form (); + curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L); if (oneone) @@ -297,7 +298,7 @@ testExternalPost () if (multi == NULL) { curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); return 512; } @@ -305,7 +306,7 @@ testExternalPost () if (mret != CURLM_OK) { curl_multi_cleanup (multi); - curl_formfree(pd); + curl_formfree (pd); curl_easy_cleanup (c); MHD_stop_daemon (d); return 1024; @@ -325,7 +326,7 @@ testExternalPost () curl_multi_cleanup (multi); curl_easy_cleanup (c); MHD_stop_daemon (d); - curl_formfree(pd); + curl_formfree (pd); return 2048; } if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) @@ -333,7 +334,7 @@ testExternalPost () curl_multi_remove_handle (multi, c); curl_multi_cleanup (multi); curl_easy_cleanup (c); - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); return 4096; } @@ -368,7 +369,7 @@ testExternalPost () curl_easy_cleanup (c); curl_multi_cleanup (multi); } - curl_formfree(pd); + curl_formfree (pd); MHD_stop_daemon (d); if (cbc.pos != strlen ("/hello_world")) return 8192; @@ -388,10 +389,11 @@ main (int argc, char *const *argv) if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount += testInternalPost (); - if (0) { - errorCount += testMultithreadedPost (); - errorCount += testExternalPost (); - } + if (0) + { + errorCount += testMultithreadedPost (); + errorCount += testExternalPost (); + } if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); curl_global_cleanup (); diff --git a/src/daemon/daemontest_put_chunked.c b/src/daemon/daemontest_put_chunked.c index 2abe4bd2..e4f9aa16 100644 --- a/src/daemon/daemontest_put_chunked.c +++ b/src/daemon/daemontest_put_chunked.c @@ -53,7 +53,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) if (wrt > 8 - (*pos)) wrt = 8 - (*pos); if (wrt > 4) - wrt = 4; /* only send half at first => force multiple chunks! */ + wrt = 4; /* only send half at first => force multiple chunks! */ memcpy (stream, &("Hello123"[*pos]), wrt); (*pos) += wrt; return wrt; @@ -91,19 +91,17 @@ ahc_echo (void *cls, { have = *upload_data_size; if (have + *done > 8) - { + { printf ("Invalid upload data `%8s'!\n", upload_data); return MHD_NO; - } - if (0 == memcmp(upload_data, - &"Hello123"[*done], - have)) - { - *done += have; - *upload_data_size = 0; - } + } + if (0 == memcmp (upload_data, &"Hello123"[*done], have)) + { + *done += have; + *upload_data_size = 0; + } else - { + { printf ("Invalid upload data `%8s'!\n", upload_data); return MHD_NO; } @@ -144,9 +142,9 @@ testInternalPut () curl_easy_setopt (c, CURLOPT_READDATA, &pos); curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); /* - // by not giving the file size, we force chunking! - curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); - */ + // by not giving the file size, we force chunking! + curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); + */ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); @@ -200,9 +198,9 @@ testMultithreadedPut () curl_easy_setopt (c, CURLOPT_READDATA, &pos); curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); /* - // by not giving the file size, we force chunking! - curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); - */ + // by not giving the file size, we force chunking! + curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); + */ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); @@ -268,9 +266,9 @@ testExternalPut () curl_easy_setopt (c, CURLOPT_READDATA, &pos); curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); /* - // by not giving the file size, we force chunking! - curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); - */ + // by not giving the file size, we force chunking! + curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); + */ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c index 3ce715ee..87de25a0 100644 --- a/src/daemon/postprocessor.c +++ b/src/daemon/postprocessor.c @@ -164,7 +164,7 @@ MHD_create_post_processor (struct MHD_Connection *connection, if ((0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding)) && (0 != strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding, - strlen(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))) + strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))) return NULL; ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1); if (ret == NULL) @@ -430,7 +430,7 @@ post_process_multipart (struct MHD_PostProcessor *pp, pp->state = PP_Headers; break; } - /* fall through! */ + /* fall through! */ case PP_Headers: newline = 0; while ((newline + ioff < pp->buffer_pos) && @@ -476,8 +476,8 @@ post_process_multipart (struct MHD_PostProcessor *pp, try_match_header ("Content-Type: ", &buf[ioff], &pp->content_type); try_match_header ("Content-Transfer-Encoding: ", &buf[ioff], &pp->transfer_encoding); - ioff += newline + 1; - pp->state = PP_ExpectNewLineNOPT; + ioff += newline + 1; + pp->state = PP_ExpectNewLineNOPT; break; case PP_SkipRN: if (buf[ioff] == '\r') diff --git a/src/daemon/reason_phrase.c b/src/daemon/reason_phrase.c index 403bd6cf..2dc5a826 100644 --- a/src/daemon/reason_phrase.c +++ b/src/daemon/reason_phrase.c @@ -28,15 +28,15 @@ #include "reason_phrase.h" -static const char * invalid_hundred[] = { }; +static const char *invalid_hundred[] = { }; -static const char * one_hundred[] = { +static const char *one_hundred[] = { "Continue", "Switching Protocols", "Processing" }; -static const char* two_hundred[] = { +static const char *two_hundred[] = { "OK", "Created", "Accepted", @@ -46,7 +46,7 @@ static const char* two_hundred[] = { "Partial Content" }; -static const char* three_hundred[] = { +static const char *three_hundred[] = { "Multiple Choices", "Moved Permanently", "Moved Temporarily", @@ -55,7 +55,7 @@ static const char* three_hundred[] = { "Use Proxy" }; -static const char* four_hundred[] = { +static const char *four_hundred[] = { "Bad Request", "Unauthorized", "Payment Required", @@ -74,7 +74,7 @@ static const char* four_hundred[] = { "Unsupported Media Type" }; -static const char* five_hundred[] = { +static const char *five_hundred[] = { "Internal Server Error", "Bad Gateway", "Service Unavailable", @@ -83,27 +83,27 @@ static const char* five_hundred[] = { }; -struct MHD_Reason_Block { +struct MHD_Reason_Block +{ unsigned int max; - const char ** data; + const char **data; }; #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m } static const struct MHD_Reason_Block reasons[] = { - BLOCK(invalid_hundred), - BLOCK(one_hundred), - BLOCK(two_hundred), - BLOCK(three_hundred), - BLOCK(four_hundred), - BLOCK(five_hundred), + BLOCK (invalid_hundred), + BLOCK (one_hundred), + BLOCK (two_hundred), + BLOCK (three_hundred), + BLOCK (four_hundred), + BLOCK (five_hundred), }; -const char * -MHD_get_reason_phrase_for(unsigned int code) +const char * +MHD_get_reason_phrase_for (unsigned int code) { - if ( (code >= 100 && code < 600) && - (reasons[code / 100].max > code % 100) ) + if ((code >= 100 && code < 600) && (reasons[code / 100].max > code % 100)) return reasons[code / 100].data[code % 100]; return "Unknown"; } diff --git a/src/daemon/reason_phrase.h b/src/daemon/reason_phrase.h index b6376a2f..20c11d52 100644 --- a/src/daemon/reason_phrase.h +++ b/src/daemon/reason_phrase.h @@ -32,7 +32,6 @@ * If we don't have a string for a status code, we give the first * message in that status code class. */ -const char* -MHD_get_reason_phrase_for(unsigned int code); +const char *MHD_get_reason_phrase_for (unsigned int code); #endif -- cgit v1.2.3