libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 4f9c53c222ce07b4f02474ddcc45000d6638250f
parent c461ee5489068066b9752ef9de179f3ccf75015b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 12 Jun 2015 07:45:50 +0000

-fix compiler warnings

Diffstat:
Mdoc/examples/sessions.c | 71+++++++++++++++++++++++++++++++++++------------------------------------
Msrc/microhttpd/daemon.c | 8++++++--
2 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c @@ -98,7 +98,7 @@ struct Session struct Session *next; /** - * Unique ID for this session. + * Unique ID for this session. */ char sid[33]; @@ -144,7 +144,7 @@ struct Request struct MHD_PostProcessor *pp; /** - * URL to serve in response to this POST (if this request + * URL to serve in response to this POST (if this request * was a 'POST') */ const char *post_url; @@ -162,7 +162,7 @@ static struct Session *sessions; /** - * Return the session handle for this connection, or + * Return the session handle for this connection, or * create one if this is a new user. */ static struct Session * @@ -193,9 +193,9 @@ get_session (struct MHD_Connection *connection) /* create fresh session */ ret = calloc (1, sizeof (struct Session)); if (NULL == ret) - { + { fprintf (stderr, "calloc error: %s\n", strerror (errno)); - return NULL; + return NULL; } /* not a super-secure way to generate a random session ID, but should do for a simple example... */ @@ -206,7 +206,7 @@ get_session (struct MHD_Connection *connection) (unsigned int) rand (), (unsigned int) rand (), (unsigned int) rand ()); - ret->rc++; + ret->rc++; ret->start = time (NULL); ret->next = sessions; sessions = ret; @@ -231,7 +231,7 @@ typedef int (*PageHandler)(const void *cls, /** * Entry we generate for each page served. - */ + */ struct Page { /** @@ -251,7 +251,7 @@ struct Page /** * Extra argument to handler. - */ + */ const void *handler_cls; }; @@ -261,7 +261,7 @@ struct Page * * @param session session to use * @param response response to modify - */ + */ static void add_session_cookie (struct Session *session, struct MHD_Response *response) @@ -272,12 +272,12 @@ add_session_cookie (struct Session *session, "%s=%s", COOKIE_NAME, session->sid); - if (MHD_NO == + if (MHD_NO == MHD_add_response_header (response, MHD_HTTP_HEADER_SET_COOKIE, cstr)) { - fprintf (stderr, + fprintf (stderr, "Failed to set session cookie header!\n"); } } @@ -289,7 +289,7 @@ add_session_cookie (struct Session *session, * * @param cls a 'const char *' with the HTML webpage to return * @param mime mime type to use - * @param session session handle + * @param session session handle * @param connection connection to use */ static int @@ -310,8 +310,8 @@ serve_simple_form (const void *cls, MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_ENCODING, mime); - ret = MHD_queue_response (connection, - MHD_HTTP_OK, + ret = MHD_queue_response (connection, + MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; @@ -323,7 +323,7 @@ serve_simple_form (const void *cls, * * @param cls a 'const char *' with the HTML webpage to return * @param mime mime type to use - * @param session session handle + * @param session session handle * @param connection connection to use */ static int @@ -352,8 +352,8 @@ fill_v1_form (const void *cls, MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_ENCODING, mime); - ret = MHD_queue_response (connection, - MHD_HTTP_OK, + ret = MHD_queue_response (connection, + MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; @@ -365,7 +365,7 @@ fill_v1_form (const void *cls, * * @param cls a 'const char *' with the HTML webpage to return * @param mime mime type to use - * @param session session handle + * @param session session handle * @param connection connection to use */ static int @@ -395,8 +395,8 @@ fill_v1_v2_form (const void *cls, MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_ENCODING, mime); - ret = MHD_queue_response (connection, - MHD_HTTP_OK, + ret = MHD_queue_response (connection, + MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; @@ -408,7 +408,7 @@ fill_v1_v2_form (const void *cls, * * @param cls a 'const char *' with the HTML webpage to return * @param mime mime type to use - * @param session session handle + * @param session session handle * @param connection connection to use */ static int @@ -424,8 +424,8 @@ not_found_page (const void *cls, response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR), (void *) NOT_FOUND_ERROR, MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_response (connection, - MHD_HTTP_NOT_FOUND, + ret = MHD_queue_response (connection, + MHD_HTTP_NOT_FOUND, response); MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_ENCODING, @@ -438,7 +438,7 @@ not_found_page (const void *cls, /** * List of all pages served by this HTTP server. */ -static struct Page pages[] = +static struct Page pages[] = { { "/", "text/html", &fill_v1_form, MAIN_PAGE }, { "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE }, @@ -556,7 +556,7 @@ create_response (void *cls, const char *url, const char *method, const char *version, - const char *upload_data, + const char *upload_data, size_t *upload_data_size, void **ptr) { @@ -602,7 +602,7 @@ create_response (void *cls, session = request->session; session->start = time (NULL); if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) - { + { /* evaluate POST data */ MHD_post_process (request->pp, upload_data, @@ -628,7 +628,7 @@ create_response (void *cls, while ( (pages[i].url != NULL) && (0 != strcmp (pages[i].url, url)) ) i++; - ret = pages[i].handler (pages[i].handler_cls, + ret = pages[i].handler (pages[i].handler_cls, pages[i].mime, session, connection); if (ret != MHD_YES) @@ -640,8 +640,8 @@ create_response (void *cls, response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), (void *) METHOD_ERROR, MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_response (connection, - MHD_HTTP_METHOD_NOT_ACCEPTABLE, + ret = MHD_queue_response (connection, + MHD_HTTP_NOT_ACCEPTABLE, response); MHD_destroy_response (response); return ret; @@ -705,7 +705,7 @@ expire_sessions () else prev = pos; pos = next; - } + } } @@ -734,8 +734,8 @@ main (int argc, char *const *argv) srand ((unsigned int) time (NULL)); d = MHD_start_daemon (MHD_USE_DEBUG, atoi (argv[1]), - NULL, NULL, - &create_response, NULL, + NULL, NULL, + &create_response, NULL, MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, MHD_OPTION_END); @@ -750,18 +750,18 @@ main (int argc, char *const *argv) FD_ZERO (&es); if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) break; /* fatal internal error */ - if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES) + if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES) { tv.tv_sec = mhd_timeout / 1000; tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000; - tvp = &tv; + tvp = &tv; } else tvp = NULL; if (-1 == select (max + 1, &rs, &ws, &es, tvp)) { if (EINTR != errno) - fprintf (stderr, + fprintf (stderr, "Aborting due to error during select: %s\n", strerror (errno)); break; @@ -771,4 +771,3 @@ main (int argc, char *const *argv) MHD_stop_daemon (d); return 0; } - diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -1037,7 +1037,9 @@ recv_param_adapter (struct MHD_Connection *connection, size_t i) { ssize_t ret; +#if EPOLL_SUPPORT const size_t requested_size = i; +#endif if ( (MHD_INVALID_SOCKET == connection->socket_fd) || (MHD_CONNECTION_CLOSED == connection->state) ) @@ -1055,7 +1057,7 @@ recv_param_adapter (struct MHD_Connection *connection, ret = recv(connection->socket_fd, other, i, MSG_NOSIGNAL); #if EPOLL_SUPPORT - if (0 > ret || requested_size > (size_t) ret) + if ( (0 > ret) || (requested_size > (size_t) ret)) { /* partial read --- no longer read-ready */ connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY; @@ -1079,7 +1081,9 @@ send_param_adapter (struct MHD_Connection *connection, size_t i) { ssize_t ret; +#if EPOLL_SUPPORT const size_t requested_size = i; +#endif #if LINUX MHD_socket fd; #endif @@ -1151,7 +1155,7 @@ send_param_adapter (struct MHD_Connection *connection, #endif ret = send (connection->socket_fd, other, i, MSG_NOSIGNAL); #if EPOLL_SUPPORT - if (0 > ret || requested_size > (size_t) ret) + if ( (0 > ret) || (requested_size > (size_t) ret) ) { /* partial write --- no longer write-ready */ connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;