From 05f894a55d9547c1bc08580d6a1b50bcc5a119f7 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 16 Jun 2007 07:33:00 +0000 Subject: removing whitespace --- src/daemon/daemon.c | 108 +++++++++++++++++++++---------------------- src/daemon/daemontest.c | 28 +++++------ src/daemon/daemontest_get.c | 62 ++++++++++++------------- src/daemon/daemontest_post.c | 64 ++++++++++++------------- src/daemon/daemontest_put.c | 70 ++++++++++++++-------------- src/daemon/internal.c | 2 +- src/daemon/internal.h | 22 ++++----- src/daemon/minimal_example.c | 2 +- src/daemon/response.c | 38 +++++++-------- src/daemon/session.c | 100 +++++++++++++++++++-------------------- src/daemon/session.h | 8 ++-- 11 files changed, 252 insertions(+), 252 deletions(-) diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 8d5c3459..379e3cf9 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -29,26 +29,26 @@ #include "response.h" #include "session.h" -#define MHD_MAX_CONNECTIONS FD_SETSIZE -4 +#define MHD_MAX_CONNECTIONS FD_SETSIZE -4 /** * Register an access handler for all URIs beginning with uri_prefix. * - * @param uri_prefix + * @param uri_prefix * @return MRI_NO if a handler for this exact prefix * already exists */ -int +int MHD_register_handler(struct MHD_Daemon * daemon, const char * uri_prefix, MHD_AccessHandlerCallback dh, void * dh_cls) { struct MHD_Access_Handler * ah; - if ( (daemon == NULL) || + if ( (daemon == NULL) || (uri_prefix == NULL) || - (dh == NULL) ) + (dh == NULL) ) return MHD_NO; ah = daemon->handlers; while (ah != NULL) { @@ -71,11 +71,11 @@ MHD_register_handler(struct MHD_Daemon * daemon, * Unregister an access handler for the URIs beginning with * uri_prefix. * - * @param uri_prefix + * @param uri_prefix * @return MHD_NO if a handler for this exact prefix * is not known for this daemon */ -int +int MHD_unregister_handler(struct MHD_Daemon * daemon, const char * uri_prefix, MHD_AccessHandlerCallback dh, @@ -83,9 +83,9 @@ MHD_unregister_handler(struct MHD_Daemon * daemon, struct MHD_Access_Handler * prev; struct MHD_Access_Handler * pos; - if ( (daemon == NULL) || + if ( (daemon == NULL) || (uri_prefix == NULL) || - (dh == NULL) ) + (dh == NULL) ) return MHD_NO; pos = daemon->handlers; prev = NULL; @@ -114,7 +114,7 @@ MHD_unregister_handler(struct MHD_Daemon * daemon, * daemon was not started with the right * options for this call. */ -int +int MHD_get_fdset(struct MHD_Daemon * daemon, fd_set * read_fd_set, fd_set * write_fd_set, @@ -123,13 +123,13 @@ MHD_get_fdset(struct MHD_Daemon * daemon, struct MHD_Session * pos; if ( (daemon == NULL) || - (read_fd_set == NULL) || + (read_fd_set == NULL) || (write_fd_set == NULL) || (except_fd_set == NULL) || (max_fd == NULL) || ( (daemon->options & MHD_USE_THREAD_PER_CONNECTION) != 0) ) return MHD_NO; - FD_SET(daemon->socket_fd, + FD_SET(daemon->socket_fd, read_fd_set); if ( (*max_fd) < daemon->socket_fd) *max_fd = daemon->socket_fd; @@ -159,14 +159,14 @@ MHD_handle_connection(void * data) { fd_set ws; fd_set es; int max; - + if (con == NULL) abort(); while ( (! con->daemon->shutdown) && - (con->socket_fd != -1) ) { + (con->socket_fd != -1) ) { FD_ZERO(&rs); - FD_ZERO(&ws); - FD_ZERO(&es); + FD_ZERO(&ws); + FD_ZERO(&es); max = 0; MHD_session_get_fdset(con, &rs, @@ -174,9 +174,9 @@ MHD_handle_connection(void * data) { &es, &max); num_ready = SELECT(max + 1, - &rs, + &rs, &ws, - &es, + &es, NULL); if (num_ready <= 0) { if (errno == EINTR) @@ -192,7 +192,7 @@ MHD_handle_connection(void * data) { if ( (con->headersReceived == 1) && (con->response == NULL) ) MHD_call_session_handler(con); - } + } if (con->socket_fd != -1) { CLOSE(con->socket_fd); con->socket_fd = -1; @@ -214,10 +214,10 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { int s; addrlen = sizeof(struct sockaddr); - memset(&addr, + memset(&addr, 0, sizeof(struct sockaddr)); - s = ACCEPT(daemon->socket_fd, + s = ACCEPT(daemon->socket_fd, &addr, &addrlen); if ( (s < 0) || @@ -246,8 +246,8 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { session->daemon = daemon; if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) && (0 != pthread_create(&session->pid, - NULL, - &MHD_handle_connection, + NULL, + &MHD_handle_connection, session)) ) { MHD_DLOG(daemon, "Failed to create a thread: %s\n", @@ -273,7 +273,7 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { * calling the application again with upload data when * the upload data buffer is full). */ -static void +static void MHD_cleanup_sessions(struct MHD_Daemon * daemon) { struct MHD_Session * pos; struct MHD_Session * prev; @@ -316,14 +316,14 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) { else pos = prev->next; continue; - } + } if ( (pos->headersReceived == 1) && (pos->response == NULL) ) MHD_call_session_handler(pos); - + prev = pos; - pos = pos->next; + pos = pos->next; } } @@ -345,14 +345,14 @@ MHD_select(struct MHD_Daemon * daemon, int max; struct timeval timeout; int ds; - + timeout.tv_sec = 0; timeout.tv_usec = 0; - if(daemon == NULL) + if(daemon == NULL) abort(); FD_ZERO(&rs); - FD_ZERO(&ws); - FD_ZERO(&es); + FD_ZERO(&ws); + FD_ZERO(&es); max = 0; if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { @@ -372,21 +372,21 @@ MHD_select(struct MHD_Daemon * daemon, &rs, &ws, &es, - may_block == MHD_NO ? &timeout : NULL); - if (num_ready < 0) { + may_block == MHD_NO ? &timeout : NULL); + if (num_ready < 0) { if (errno == EINTR) return MHD_YES; MHD_DLOG(daemon, "Select failed: %s\n", STRERROR(errno)); - return MHD_NO; + return MHD_NO; } ds = daemon->socket_fd; if (ds == -1) return MHD_YES; if (FD_ISSET(ds, - &rs)) - MHD_accept_connection(daemon); + &rs)) + MHD_accept_connection(daemon); if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { /* do not have a thread per connection, process all connections now */ pos = daemon->connections; @@ -396,7 +396,7 @@ MHD_select(struct MHD_Daemon * daemon, pos = pos->next; continue; } - if (FD_ISSET(ds, &rs)) + if (FD_ISSET(ds, &rs)) MHD_session_handle_read(pos); if (FD_ISSET(ds, &ws)) MHD_session_handle_write(pos); @@ -411,7 +411,7 @@ MHD_select(struct MHD_Daemon * daemon, * Run webserver operations (without blocking unless * in client callbacks). This method should be called * by clients in combination with MHD_get_fdset - * if the client-controlled select method is used. + * if the client-controlled select method is used. * * @return MHD_YES on success, MHD_NO if this * daemon was not started with the right @@ -466,12 +466,12 @@ MHD_start_daemon(unsigned int options, int socket_fd; struct sockaddr_in servaddr; - if ((options & MHD_USE_SSL) != 0) - return NULL; - if ((options & MHD_USE_IPv6) != 0) - return NULL; - if ((options & MHD_USE_IPv4) == 0) - return NULL; + if ((options & MHD_USE_SSL) != 0) + return NULL; + if ((options & MHD_USE_IPv6) != 0) + return NULL; + if ((options & MHD_USE_IPv4) == 0) + return NULL; if ( (port == 0) || (dh == NULL) ) return NULL; @@ -486,11 +486,11 @@ MHD_start_daemon(unsigned int options, /* FIXME: setsockopt: SO_REUSEADDR? */ memset(&servaddr, 0, - sizeof(struct sockaddr_in)); + sizeof(struct sockaddr_in)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port); - if (BIND(socket_fd, - (struct sockaddr *)&servaddr, + if (BIND(socket_fd, + (struct sockaddr *)&servaddr, sizeof(struct sockaddr_in)) < 0) { if ( (options & MHD_USE_DEBUG) != 0) fprintf(stderr, @@ -506,7 +506,7 @@ MHD_start_daemon(unsigned int options, "Failed to listen for connections: %s\n", STRERROR(errno)); CLOSE(socket_fd); - return NULL; + return NULL; } retVal = malloc(sizeof(struct MHD_Daemon)); memset(retVal, @@ -524,15 +524,15 @@ MHD_start_daemon(unsigned int options, if ( ( (0 != (options & MHD_USE_THREAD_PER_CONNECTION)) || (0 != (options & MHD_USE_SELECT_INTERNALLY)) ) && (0 != pthread_create(&retVal->pid, - NULL, - &MHD_select_thread, + NULL, + &MHD_select_thread, retVal)) ) { MHD_DLOG(retVal, "Failed to create listen thread: %s\n", STRERROR(errno)); free(retVal); CLOSE(socket_fd); - return NULL; + return NULL; } return retVal; } @@ -544,12 +544,12 @@ void MHD_stop_daemon(struct MHD_Daemon * daemon) { void * unused; - if (daemon == NULL) - return; + if (daemon == NULL) + return; daemon->shutdown = 1; CLOSE(daemon->socket_fd); daemon->socket_fd = -1; - if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || + if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { pthread_kill(daemon->pid, SIGALRM); pthread_join(daemon->pid, &unused); diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c index 9e86e389..10e7229d 100644 --- a/src/daemon/daemontest.c +++ b/src/daemon/daemontest.c @@ -35,7 +35,7 @@ static int testStartError() { struct MHD_Daemon * d; d = MHD_start_daemon(MHD_USE_DEBUG, 0, NULL, NULL, NULL, NULL); - if (d != NULL) + if (d != NULL) return 1; return 0; } @@ -70,8 +70,8 @@ static int testStartStop() { NULL, &ahc_nothing, NULL); - if (d == NULL) - return 2; + if (d == NULL) + return 2; MHD_stop_daemon(d); return 0; } @@ -89,8 +89,8 @@ static int testExternalRun() { &ahc_nothing, NULL); - if (d == NULL) - return 4; + if (d == NULL) + return 4; i = 0; while(i < 15) { maxfd = 0; @@ -115,9 +115,9 @@ static int testThread() { &ahc_nothing, NULL); - if (d == NULL) - return 16; - if (MHD_run(d) != MHD_NO) + if (d == NULL) + return 16; + if (MHD_run(d) != MHD_NO) return 32; MHD_stop_daemon(d); return 0; @@ -132,11 +132,11 @@ static int testMultithread() { &ahc_nothing, NULL); - if (d == NULL) - return 64; - if (MHD_run(d) != MHD_NO) + if (d == NULL) + return 64; + if (MHD_run(d) != MHD_NO) return 128; - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 0; } @@ -149,8 +149,8 @@ int main(int argc, errorCount += testThread(); errorCount += testMultithread(); if (errorCount != 0) - fprintf(stderr, - "Error (code: %u)\n", + fprintf(stderr, + "Error (code: %u)\n", errorCount); return errorCount != 0; /* 0 == pass */ } diff --git a/src/daemon/daemontest_get.c b/src/daemon/daemontest_get.c index d3b6c5bc..d4030b06 100644 --- a/src/daemon/daemontest_get.c +++ b/src/daemon/daemontest_get.c @@ -125,18 +125,18 @@ static int testInternalGet() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 2; - } - curl_easy_cleanup(c); + } + curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { MHD_stop_daemon(d); return 4; } - + if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -144,7 +144,7 @@ static int testInternalGet() { return 8; } MHD_stop_daemon(d); - + return 0; } @@ -189,16 +189,16 @@ static int testMultithreadedGet() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 32; } curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 64; - } + } if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -206,7 +206,7 @@ static int testMultithreadedGet() { return 128; } MHD_stop_daemon(d); - + return 0; } @@ -263,20 +263,20 @@ static int testExternalGet() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); multi = curl_multi_init(); if (multi == NULL) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 512; } mret = curl_multi_add_handle(multi, c); if (mret != CURLM_OK) { curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 1024; } start = time(NULL); @@ -295,9 +295,9 @@ static int testExternalGet() { if (mret != CURLM_OK) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); - return 2048; + curl_easy_cleanup(c); + MHD_stop_daemon(d); + return 2048; } if (MHD_YES != MHD_get_fdset(d, &rs, @@ -306,8 +306,8 @@ static int testExternalGet() { &max)) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 4096; } tv.tv_sec = 0; @@ -316,7 +316,7 @@ static int testExternalGet() { &rs, &ws, &es, - &tv); + &tv); curl_multi_perform(multi, &running); if (running == 0) { msg = curl_multi_info_read(multi, @@ -341,15 +341,15 @@ static int testExternalGet() { } if (multi != NULL) { curl_multi_remove_handle(multi, c); - curl_easy_cleanup(c); + curl_easy_cleanup(c); curl_multi_cleanup(multi); } MHD_stop_daemon(d); - if (cbc.pos != strlen("/hello_world")) + if (cbc.pos != strlen("/hello_world")) return 8192; if (0 != strncmp("/hello_world", cbc.buf, - strlen("/hello_world"))) + strlen("/hello_world"))) return 16384; return 0; } @@ -360,14 +360,14 @@ int main(int argc, char * const * argv) { unsigned int errorCount = 0; - if (0 != curl_global_init(CURL_GLOBAL_WIN32)) - return 2; + if (0 != curl_global_init(CURL_GLOBAL_WIN32)) + return 2; errorCount += testInternalGet(); - errorCount += testMultithreadedGet(); + errorCount += testMultithreadedGet(); errorCount += testExternalGet(); if (errorCount != 0) - fprintf(stderr, - "Error (code: %u)\n", + fprintf(stderr, + "Error (code: %u)\n", errorCount); curl_global_cleanup(); return errorCount != 0; /* 0 == pass */ diff --git a/src/daemon/daemontest_post.c b/src/daemon/daemontest_post.c index 5e46bac3..c74a3a02 100644 --- a/src/daemon/daemontest_post.c +++ b/src/daemon/daemontest_post.c @@ -21,7 +21,7 @@ /** * @file daemontest_post.c * @brief Testcase for libmicrohttpd POST operations - * TODO: use curl_formadd to produce POST data and + * TODO: use curl_formadd to produce POST data and * add that to the CURL operation; then check * on the server side if the headers arrive * nicely (need to implement parsing POST data @@ -137,18 +137,18 @@ static int testInternalPost() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 2; - } - curl_easy_cleanup(c); + } + curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { MHD_stop_daemon(d); return 4; } - + if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -156,7 +156,7 @@ static int testInternalPost() { return 8; } MHD_stop_daemon(d); - + return 0; } @@ -207,17 +207,17 @@ static int testMultithreadedPost() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { curl_easy_cleanup(c); - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 32; } curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 64; - } + } if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -225,7 +225,7 @@ static int testMultithreadedPost() { return 128; } MHD_stop_daemon(d); - + return 0; } @@ -288,20 +288,20 @@ static int testExternalPost() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); multi = curl_multi_init(); if (multi == NULL) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 512; } mret = curl_multi_add_handle(multi, c); if (mret != CURLM_OK) { curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 1024; } start = time(NULL); @@ -320,9 +320,9 @@ static int testExternalPost() { if (mret != CURLM_OK) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); - return 2048; + curl_easy_cleanup(c); + MHD_stop_daemon(d); + return 2048; } if (MHD_YES != MHD_get_fdset(d, &rs, @@ -331,8 +331,8 @@ static int testExternalPost() { &max)) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 4096; } tv.tv_sec = 0; @@ -341,7 +341,7 @@ static int testExternalPost() { &rs, &ws, &es, - &tv); + &tv); curl_multi_perform(multi, &running); if (running == 0) { msg = curl_multi_info_read(multi, @@ -366,15 +366,15 @@ static int testExternalPost() { } if (multi != NULL) { curl_multi_remove_handle(multi, c); - curl_easy_cleanup(c); + curl_easy_cleanup(c); curl_multi_cleanup(multi); } MHD_stop_daemon(d); - if (cbc.pos != strlen("/hello_world")) + if (cbc.pos != strlen("/hello_world")) return 8192; if (0 != strncmp("/hello_world", cbc.buf, - strlen("/hello_world"))) + strlen("/hello_world"))) return 16384; return 0; } @@ -385,14 +385,14 @@ int main(int argc, char * const * argv) { unsigned int errorCount = 0; - if (0 != curl_global_init(CURL_GLOBAL_WIN32)) - return 2; + if (0 != curl_global_init(CURL_GLOBAL_WIN32)) + return 2; errorCount += testInternalPost(); - errorCount += testMultithreadedPost(); + errorCount += testMultithreadedPost(); errorCount += testExternalPost(); if (errorCount != 0) - fprintf(stderr, - "Error (code: %u)\n", + fprintf(stderr, + "Error (code: %u)\n", errorCount); curl_global_cleanup(); return errorCount != 0; /* 0 == pass */ diff --git a/src/daemon/daemontest_put.c b/src/daemon/daemontest_put.c index 822f44a1..00538757 100644 --- a/src/daemon/daemontest_put.c +++ b/src/daemon/daemontest_put.c @@ -86,11 +86,11 @@ static int ahc_echo(void * cls, struct MHD_Response * response; int ret; - if (0 != strcmp("PUT", method)) - return MHD_NO; /* unexpected method */ + if (0 != strcmp("PUT", method)) + return MHD_NO; /* unexpected method */ if ((*done) == 0) { - if (*upload_data_size != 8) - return MHD_YES; /* not yet ready */ + if (*upload_data_size != 8) + return MHD_YES; /* not yet ready */ if (0 == memcmp(upload_data, "Hello123", 8)) { @@ -170,18 +170,18 @@ static int testInternalPut() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 2; - } - curl_easy_cleanup(c); + } + curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { MHD_stop_daemon(d); return 4; } - + if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -189,7 +189,7 @@ static int testInternalPut() { return 8; } MHD_stop_daemon(d); - + return 0; } @@ -248,17 +248,17 @@ static int testMultithreadedPut() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); if (CURLE_OK != curl_easy_perform(c)) { curl_easy_cleanup(c); - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 32; } curl_easy_cleanup(c); if (cbc.pos != strlen("/hello_world")) { - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 64; - } + } if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) { @@ -266,7 +266,7 @@ static int testMultithreadedPut() { return 128; } MHD_stop_daemon(d); - + return 0; } @@ -337,20 +337,20 @@ static int testExternalPut() { // crashes on my system! curl_easy_setopt(c, CURLOPT_NOSIGNAL, - 1); + 1); multi = curl_multi_init(); if (multi == NULL) { - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 512; } mret = curl_multi_add_handle(multi, c); if (mret != CURLM_OK) { curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 1024; } start = time(NULL); @@ -369,9 +369,9 @@ static int testExternalPut() { if (mret != CURLM_OK) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); - return 2048; + curl_easy_cleanup(c); + MHD_stop_daemon(d); + return 2048; } if (MHD_YES != MHD_get_fdset(d, &rs, @@ -380,8 +380,8 @@ static int testExternalPut() { &max)) { curl_multi_remove_handle(multi, c); curl_multi_cleanup(multi); - curl_easy_cleanup(c); - MHD_stop_daemon(d); + curl_easy_cleanup(c); + MHD_stop_daemon(d); return 4096; } tv.tv_sec = 0; @@ -390,7 +390,7 @@ static int testExternalPut() { &rs, &ws, &es, - &tv); + &tv); curl_multi_perform(multi, &running); if (running == 0) { msg = curl_multi_info_read(multi, @@ -415,15 +415,15 @@ static int testExternalPut() { } if (multi != NULL) { curl_multi_remove_handle(multi, c); - curl_easy_cleanup(c); + curl_easy_cleanup(c); curl_multi_cleanup(multi); } MHD_stop_daemon(d); - if (cbc.pos != strlen("/hello_world")) + if (cbc.pos != strlen("/hello_world")) return 8192; if (0 != strncmp("/hello_world", cbc.buf, - strlen("/hello_world"))) + strlen("/hello_world"))) return 16384; return 0; } @@ -434,14 +434,14 @@ int main(int argc, char * const * argv) { unsigned int errorCount = 0; - if (0 != curl_global_init(CURL_GLOBAL_WIN32)) - return 2; + if (0 != curl_global_init(CURL_GLOBAL_WIN32)) + return 2; errorCount += testInternalPut(); - errorCount += testMultithreadedPut(); + errorCount += testMultithreadedPut(); errorCount += testExternalPut(); if (errorCount != 0) - fprintf(stderr, - "Error (code: %u)\n", + fprintf(stderr, + "Error (code: %u)\n", errorCount); curl_global_cleanup(); return errorCount != 0; /* 0 == pass */ diff --git a/src/daemon/internal.c b/src/daemon/internal.c index 9ec1f623..eed1acba 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c @@ -36,7 +36,7 @@ void MHD_DLOG(const struct MHD_Daemon * daemon, const char * format, ...) { va_list va; - + if ( (daemon->options & MHD_USE_DEBUG) == 0) return; va_start(va, format); diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 971ebb00..8d125a01 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h @@ -90,7 +90,7 @@ struct MHD_Access_Handler { /** * Representation of a response. - */ + */ struct MHD_Response { /** @@ -109,9 +109,9 @@ struct MHD_Response { /** * Closure to give to the content reader * free callback. - */ + */ void * crc_cls; - + /** * How do we get more data? NULL if we are * given all of the data up front. @@ -135,7 +135,7 @@ struct MHD_Response { * once the counter hits zero. */ unsigned int reference_count; - + /** * Set to -1 if size is not known. */ @@ -151,7 +151,7 @@ struct MHD_Response { * beginning of data located? */ size_t data_start; - + }; @@ -162,7 +162,7 @@ struct MHD_Session { struct MHD_Daemon * daemon; struct MHD_HTTP_Header * headers_received; - + struct MHD_Response * response; /** @@ -184,7 +184,7 @@ struct MHD_Session { * Buffer for writing response. */ char * write_buffer; - + /** * Foreign address (of length addr_len). */ @@ -237,19 +237,19 @@ struct MHD_Session { * we are done sending our response. */ int read_close; - + /** * Have we finished receiving all of the headers yet? * Set to 1 once we are done processing all of the * headers. Note that due to pipelining, it is - * possible that the NEXT request is already + * possible that the NEXT request is already * (partially) waiting in the read buffer. */ int headersReceived; /** * Have we finished receiving the data from a - * potential file-upload? + * potential file-upload? */ int bodyReceived; @@ -275,7 +275,7 @@ struct MHD_Daemon { struct MHD_Access_Handler default_handler; struct MHD_Session * connections; - + MHD_AcceptPolicyCallback apc; void * apc_cls; diff --git a/src/daemon/minimal_example.c b/src/daemon/minimal_example.c index 6dad8180..b25ad106 100644 --- a/src/daemon/minimal_example.c +++ b/src/daemon/minimal_example.c @@ -82,7 +82,7 @@ int main(int argc, if (d == NULL) return 1; sleep(atoi(argv[2])); - MHD_stop_daemon(d); + MHD_stop_daemon(d); return 0; } diff --git a/src/daemon/response.c b/src/daemon/response.c index e0942700..4bbe0f36 100644 --- a/src/daemon/response.c +++ b/src/daemon/response.c @@ -38,11 +38,11 @@ MHD_add_response_header(struct MHD_Response * response, const char * header, const char * content) { struct MHD_HTTP_Header * hdr; - - if ( (response == NULL) || - (header == NULL) || + + if ( (response == NULL) || + (header == NULL) || (content == NULL) || - (strlen(header) == 0) || + (strlen(header) == 0) || (strlen(content) == 0) || (NULL != strstr(header, "\t")) || (NULL != strstr(header, "\r")) || @@ -72,14 +72,14 @@ MHD_del_response_header(struct MHD_Response * response, struct MHD_HTTP_Header * pos; struct MHD_HTTP_Header * prev; - if ( (header == NULL) || - (content == NULL) ) - return MHD_NO; + if ( (header == NULL) || + (content == NULL) ) + 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); if (prev == NULL) @@ -102,7 +102,7 @@ MHD_del_response_header(struct MHD_Response * response, * maybe NULL (then just count headers) * @param iterator_cls extra argument to iterator * @return number of entries iterated over - */ + */ int MHD_get_response_headers(struct MHD_Response * response, MHD_KeyValueIterator iterator, @@ -129,7 +129,7 @@ MHD_get_response_headers(struct MHD_Response * response, * * @param key which header to get * @return NULL if header does not exist - */ + */ const char * MHD_get_response_header(struct MHD_Response * response, const char * key) { @@ -162,7 +162,7 @@ MHD_create_response_from_callback(size_t size, MHD_ContentReaderFreeCallback crfc) { struct MHD_Response * retVal; - if (crc == NULL) + if (crc == NULL) return NULL; retVal = malloc(sizeof(struct MHD_Response)); memset(retVal, @@ -187,7 +187,7 @@ MHD_create_response_from_callback(size_t size, * @param size size of the data portion of the response * @param data the data itself * @param must_free libmicrohttpd should free data when done - * @param must_copy libmicrohttpd must make a copy of data + * @param must_copy libmicrohttpd must make a copy of data * right away, the data maybe released anytime after * this call returns * @return NULL on error (i.e. invalid arguments, out of memory) @@ -199,7 +199,7 @@ MHD_create_response_from_data(size_t size, int must_copy) { struct MHD_Response * retVal; void * tmp; - + if ( (data == NULL) && (size > 0) ) return NULL; @@ -215,11 +215,11 @@ MHD_create_response_from_data(size_t size, (size > 0) ) { tmp = malloc(size); memcpy(tmp, - data, + data, size); must_free = 1; data = tmp; - } + } retVal->crc = NULL; retVal->crfc = must_free ? &free : NULL; retVal->crc_cls = must_free ? data : NULL; @@ -240,10 +240,10 @@ void MHD_destroy_response(struct MHD_Response * response) { struct MHD_HTTP_Header * pos; - if (response == NULL) + if (response == NULL) return; pthread_mutex_lock(&response->mutex); - if (0 != --response->reference_count) { + if (0 != --response->reference_count) { pthread_mutex_unlock(&response->mutex); return; } @@ -252,7 +252,7 @@ MHD_destroy_response(struct MHD_Response * response) { if (response->crfc != NULL) response->crfc(response->crc_cls); while (response->first_header != NULL) { - pos = response->first_header; + pos = response->first_header; response->first_header = pos->next; free(pos->header); free(pos->value); diff --git a/src/daemon/session.c b/src/daemon/session.c index f69ec1ed..edcbb04f 100644 --- a/src/daemon/session.c +++ b/src/daemon/session.c @@ -37,7 +37,7 @@ * maybe NULL (then just count headers) * @param iterator_cls extra argument to iterator * @return number of entries iterated over - */ + */ int MHD_get_session_values(struct MHD_Session * session, enum MHD_ValueKind kind, @@ -46,7 +46,7 @@ MHD_get_session_values(struct MHD_Session * session, int ret; struct MHD_HTTP_Header * pos; - if (session == NULL) + if (session == NULL) return -1; ret = 0; pos = session->headers_received; @@ -54,11 +54,11 @@ MHD_get_session_values(struct MHD_Session * session, if (0 != (pos->kind & kind)) { ret++; if ( (iterator != NULL) && - (MHD_YES != iterator(iterator_cls, - kind, - pos->header, - pos->value)) ) - return ret; + (MHD_YES != iterator(iterator_cls, + kind, + pos->header, + pos->value)) ) + return ret; } pos = pos->next; } @@ -72,14 +72,14 @@ MHD_get_session_values(struct MHD_Session * session, * * @param key the header to look for * @return NULL if no such item was found - */ + */ const char * MHD_lookup_session_value(struct MHD_Session * session, enum MHD_ValueKind kind, const char * key) { struct MHD_HTTP_Header * pos; - if (session == NULL) + if (session == NULL) return NULL; pos = session->headers_received; while (pos != NULL) { @@ -95,18 +95,18 @@ MHD_lookup_session_value(struct MHD_Session * session, /** * Queue a response to be transmitted to the client (as soon as * possible). - * + * * @param session the session identifying the client * @param status_code HTTP status code (i.e. 200 for OK) * @param response response to transmit * @return MHD_NO on error (i.e. reply already sent), * MHD_YES on success or if message has been queued */ -int +int MHD_queue_response(struct MHD_Session * session, unsigned int status_code, struct MHD_Response * response) { - if ( (session == NULL) || + if ( (session == NULL) || (response == NULL) || (session->response != NULL) || (session->bodyReceived == 0) || @@ -124,7 +124,7 @@ MHD_queue_response(struct MHD_Session * session, * * @return MHD_YES on success */ -int +int MHD_session_get_fdset(struct MHD_Session * session, fd_set * read_fd_set, fd_set * write_fd_set, @@ -135,11 +135,11 @@ MHD_session_get_fdset(struct MHD_Session * session, fd = session->socket_fd; if (fd == -1) return MHD_YES; - if ( (session->read_close == 0) && + if ( (session->read_close == 0) && ( (session->headersReceived == 0) || (session->readLoc < session->read_buffer_size) ) ) FD_SET(fd, read_fd_set); - if (session->response != NULL) + if (session->response != NULL) FD_SET(fd, write_fd_set); if ( (fd > *max_fd) && ( (session->headersReceived == 0) || @@ -157,7 +157,7 @@ MHD_session_get_fdset(struct MHD_Session * session, * found (incomplete, buffer too small, line too long), * return NULL. Otherwise return a copy of the line. */ -static char * +static char * MHD_get_next_header_line(struct MHD_Session * session) { char * rbuf; size_t pos; @@ -201,10 +201,10 @@ MHD_get_next_header_line(struct MHD_Session * session) { session->read_buffer, pos); rbuf[pos] = '\0'; - if ( (session->read_buffer[pos] == '\r') && + if ( (session->read_buffer[pos] == '\r') && (session->read_buffer[pos+1] == '\n') ) pos++; /* skip both r and n */ - pos++; + pos++; memmove(session->read_buffer, &session->read_buffer[pos], session->readLoc - pos); @@ -212,7 +212,7 @@ MHD_get_next_header_line(struct MHD_Session * session) { return rbuf; } -static void +static void MHD_session_add_header(struct MHD_Session * session, const char * key, const char * value, @@ -227,7 +227,7 @@ MHD_session_add_header(struct MHD_Session * session, session->headers_received = hdr; } -static void +static void MHD_http_unescape(char * val) { char * esc; unsigned int num; @@ -248,7 +248,7 @@ MHD_http_unescape(char * val) { } } -static void +static void MHD_parse_arguments(struct MHD_Session * session, char * args) { char * equals; @@ -264,7 +264,7 @@ MHD_parse_arguments(struct MHD_Session * session, if (amper != NULL) { amper[0] = '\0'; amper++; - } + } MHD_http_unescape(args); MHD_http_unescape(equals); MHD_session_add_header(session, @@ -278,7 +278,7 @@ MHD_parse_arguments(struct MHD_Session * session, /** * Parse the cookie header (see RFC 2109). */ -static void +static void MHD_parse_cookie_header(struct MHD_Session * session) { const char * hdr; char * cpy; @@ -336,7 +336,7 @@ MHD_parse_cookie_header(struct MHD_Session * session) { * This function is designed to parse the input buffer of a given session. * * Once the header is complete, it should have set the - * headers_received, url and method values and set + * headers_received, url and method values and set * headersReceived to 1. If no body is expected, it should * also set "bodyReceived" to 1. Otherwise, it should * set "uploadSize" to the expected size of the body. If the @@ -354,7 +354,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { if (session->bodyReceived == 1) abort(); - while (NULL != (line = MHD_get_next_header_line(session))) { + while (NULL != (line = MHD_get_next_header_line(session))) { if (session->url == NULL) { /* line must be request line */ uri = strstr(line, " "); @@ -387,7 +387,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { MHD_HEADER_KIND, "Content-Length"); if (clen != NULL) { - if (1 != sscanf(clen, + if (1 != sscanf(clen, "%llu", &cval)) { MHD_DLOG(session->daemon, @@ -409,7 +409,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { session->bodyReceived = 0; } } - break; + break; } /* line should be normal header line, find colon */ colon = strstr(line, ": "); @@ -438,8 +438,8 @@ MHD_parse_session_headers(struct MHD_Session * session) { /** * Find the handler responsible for this request. - */ -static struct MHD_Access_Handler * + */ +static struct MHD_Access_Handler * MHD_find_access_handler(struct MHD_Session * session) { struct MHD_Access_Handler * pos; @@ -455,7 +455,7 @@ MHD_find_access_handler(struct MHD_Session * session) { /** * Call the handler of the application for this - * session. + * session. */ void MHD_call_session_handler(struct MHD_Session * session) { @@ -484,7 +484,7 @@ MHD_call_session_handler(struct MHD_Session * session) { &session->read_buffer[session->readLoc - processed], processed); if (session->uploadSize != -1) - session->uploadSize -= (session->readLoc - processed); + session->uploadSize -= (session->readLoc - processed); session->readLoc = processed; if ( (session->uploadSize == 0) || ( (session->readLoc == 0) && @@ -503,13 +503,13 @@ MHD_call_session_handler(struct MHD_Session * session) { * This function handles a particular connection when it has been * determined that there is data to be read off a socket. All implementations * (multithreaded, external select, internal select) call this function - * to handle reads. + * to handle reads. */ int MHD_session_handle_read(struct MHD_Session * session) { int bytes_read; void * tmp; - + if ( (session->readLoc >= session->read_buffer_size) && (session->headersReceived == 0) ) { /* need to grow read buffer */ @@ -526,7 +526,7 @@ MHD_session_handle_read(struct MHD_Session * session) { MHD_DLOG(session->daemon, "Unexpected call to %s.\n", __FUNCTION__); - return MHD_NO; + return MHD_NO; } bytes_read = RECV(session->socket_fd, &session->read_buffer[session->readLoc], @@ -544,15 +544,15 @@ MHD_session_handle_read(struct MHD_Session * session) { } if (bytes_read == 0) { /* other side closed connection */ - if (session->readLoc > 0) - MHD_call_session_handler(session); + if (session->readLoc > 0) + MHD_call_session_handler(session); shutdown(session->socket_fd, SHUT_RD); return MHD_YES; } session->readLoc += bytes_read; - if (session->headersReceived == 0) + if (session->headersReceived == 0) MHD_parse_session_headers(session); - if (session->headersReceived == 1) + if (session->headersReceived == 1) MHD_call_session_handler(session); return MHD_YES; } @@ -561,7 +561,7 @@ MHD_session_handle_read(struct MHD_Session * session) { * Check if we need to set some additional headers * for http-compiliance. */ -static void +static void MHD_add_extra_headers(struct MHD_Session * session) { const char * have; char buf[128]; @@ -600,7 +600,7 @@ MHD_build_header_response(struct MHD_Session * session) { MHD_add_extra_headers(session); SPRINTF(code, - "HTTP/1.1 %u\r\n", + "HTTP/1.1 %u\r\n", session->responseCode); off = strlen(code); /* estimate size */ @@ -627,10 +627,10 @@ MHD_build_header_response(struct MHD_Session * session) { sprintf(&data[off], "\r\n"); off += 2; - if (off != size) + if (off != size) abort(); session->write_buffer = data; - session->write_buffer_size = size; + session->write_buffer_size = size; } /** @@ -654,7 +654,7 @@ MHD_session_handle_write(struct MHD_Session * session) { if (! session->headersSent) { if (session->write_buffer == NULL) MHD_build_header_response(session); - ret = SEND(session->socket_fd, + ret = SEND(session->socket_fd, &session->write_buffer[session->writeLoc], session->write_buffer_size - session->writeLoc, 0); @@ -678,10 +678,10 @@ MHD_session_handle_write(struct MHD_Session * session) { } return MHD_YES; } - if (response->total_size <= session->messagePos) + if (response->total_size <= session->messagePos) abort(); /* internal error */ if (response->crc != NULL) - pthread_mutex_lock(&response->mutex); + pthread_mutex_lock(&response->mutex); /* prepare send buffer */ if ( (response->data == NULL) || @@ -708,16 +708,16 @@ MHD_session_handle_write(struct MHD_Session * session) { response->data_start = session->messagePos; response->data_size = ret; if (ret == 0) - return MHD_YES; + return MHD_YES; } - + /* transmit */ - ret = SEND(session->socket_fd, + ret = SEND(session->socket_fd, &response->data[session->messagePos - response->data_start], response->data_size - (session->messagePos - response->data_start), 0); if (response->crc != NULL) - pthread_mutex_unlock(&response->mutex); + pthread_mutex_unlock(&response->mutex); if (ret < 0) { if (errno == EINTR) return MHD_YES; @@ -729,7 +729,7 @@ MHD_session_handle_write(struct MHD_Session * session) { return MHD_YES; } session->messagePos += ret; - if (session->messagePos > response->data_size) + if (session->messagePos > response->data_size) abort(); /* internal error */ if (session->messagePos == response->data_size) { if ( (session->bodyReceived == 0) || diff --git a/src/daemon/session.h b/src/daemon/session.h index c3abbd7f..269c2f17 100644 --- a/src/daemon/session.h +++ b/src/daemon/session.h @@ -34,7 +34,7 @@ * * @return MHD_YES on success */ -int +int MHD_session_get_fdset(struct MHD_Session * session, fd_set * read_fd_set, fd_set * write_fd_set, @@ -44,7 +44,7 @@ MHD_session_get_fdset(struct MHD_Session * session, /** * Call the handler of the application for this - * session. + * session. */ void MHD_call_session_handler(struct MHD_Session * session); @@ -53,11 +53,11 @@ MHD_call_session_handler(struct MHD_Session * session); * This function handles a particular connection when it has been * determined that there is data to be read off a socket. All implementations * (multithreaded, external select, internal select) call this function - * to handle reads. + * to handle reads. */ int MHD_session_handle_read(struct MHD_Session * session); - + /** * This function was created to handle writes to sockets when it has been -- cgit v1.2.3