libmicrohttpd

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

commit de872dea2d88f183c3f434c694acdcdb373f639c
parent 6347f514aa2388e774d5bf356df8046864e5f73c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  8 Apr 2020 23:36:41 +0200

define and use 'enum MHD_Result'

Diffstat:
MChangeLog | 7++++++-
Mdoc/examples/basicauthentication.c | 62++++++++++++++++++++++++++++++++------------------------------
Mdoc/examples/hellobrowser.c | 25+++++++++++++------------
Mdoc/examples/largepost.c | 302++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mdoc/examples/logging.c | 18+++++++++---------
Mdoc/examples/responseheaders.c | 56++++++++++++++++++++++++++++----------------------------
Mdoc/examples/sessions.c | 561++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mdoc/examples/simplepost.c | 156+++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mdoc/examples/tlsauthentication.c | 150++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/examples/authorization_example.c | 4++--
Msrc/examples/benchmark.c | 2+-
Msrc/examples/benchmark_https.c | 2+-
Msrc/examples/chunked_example.c | 4++--
Msrc/examples/demo.c | 16++++++++--------
Msrc/examples/demo_https.c | 18+++++++++---------
Msrc/examples/digest_auth_example.c | 4++--
Msrc/examples/dual_stack_example.c | 4++--
Msrc/examples/fileserver_example.c | 4++--
Msrc/examples/fileserver_example_dirs.c | 4++--
Msrc/examples/fileserver_example_external_select.c | 4++--
Msrc/examples/http_chunked_compression.c | 8++++----
Msrc/examples/http_compression.c | 10+++++-----
Msrc/examples/https_fileserver_example.c | 4++--
Msrc/examples/minimal_example.c | 4++--
Msrc/examples/minimal_example_comet.c | 4++--
Msrc/examples/minimal_example_empty.c | 4++--
Msrc/examples/minimal_example_empty_tls.c | 4++--
Msrc/examples/post_example.c | 30+++++++++++++++---------------
Msrc/examples/querystring_example.c | 4++--
Msrc/examples/refuse_post_example.c | 4++--
Msrc/examples/suspend_resume_epoll.c | 4++--
Msrc/examples/timeout.c | 4++--
Msrc/examples/upgrade_example.c | 4++--
Msrc/microhttpd/test_daemon.c | 6+++---
Msrc/microhttpd/test_postprocessor.c | 12++++++------
Msrc/microhttpd/test_postprocessor_amp.c | 2+-
Msrc/microhttpd/test_postprocessor_large.c | 2+-
Msrc/microhttpd/test_upgrade.c | 4++--
Msrc/microhttpd/test_upgrade_large.c | 4++--
Msrc/testcurl/https/test_empty_response.c | 4++--
Msrc/testcurl/https/test_https_get.c | 4++--
Msrc/testcurl/https/test_https_get_select.c | 4++--
Msrc/testcurl/https/test_https_session_info.c | 17+++++++++--------
Msrc/testcurl/https/tls_test_common.c | 6+++---
Msrc/testcurl/https/tls_test_common.h | 4++--
Msrc/testcurl/perf_get.c | 4++--
Msrc/testcurl/perf_get_concurrent.c | 4++--
Msrc/testcurl/test_callback.c | 4++--
Msrc/testcurl/test_concurrent_stop.c | 4++--
Msrc/testcurl/test_delete.c | 4++--
Msrc/testcurl/test_digestauth.c | 4++--
Msrc/testcurl/test_digestauth_sha256.c | 4++--
Msrc/testcurl/test_digestauth_with_arguments.c | 4++--
Msrc/testcurl/test_get.c | 8++++----
Msrc/testcurl/test_get_chunked.c | 4++--
Msrc/testcurl/test_get_response_cleanup.c | 4++--
Msrc/testcurl/test_get_sendfile.c | 6+++---
Msrc/testcurl/test_iplimit.c | 4++--
Msrc/testcurl/test_large_put.c | 4++--
Msrc/testcurl/test_long_header.c | 6+++---
Msrc/testcurl/test_parse_cookies.c | 4++--
Msrc/testcurl/test_patch.c | 4++--
Msrc/testcurl/test_post.c | 10+++++-----
Msrc/testcurl/test_post_loop.c | 4++--
Msrc/testcurl/test_postform.c | 6+++---
Msrc/testcurl/test_process_arguments.c | 4++--
Msrc/testcurl/test_process_headers.c | 6+++---
Msrc/testcurl/test_put.c | 4++--
Msrc/testcurl/test_put_chunked.c | 4++--
Msrc/testcurl/test_quiesce.c | 4++--
Msrc/testcurl/test_quiesce_stream.c | 4++--
Msrc/testcurl/test_termination.c | 4++--
Msrc/testcurl/test_timeout.c | 4++--
Msrc/testcurl/test_urlparse.c | 6+++---
Msrc/testzzuf/test_get.c | 4++--
Msrc/testzzuf/test_get_chunked.c | 4++--
Msrc/testzzuf/test_long_header.c | 17++++++++++++++---
Msrc/testzzuf/test_post.c | 6+++---
Msrc/testzzuf/test_post_form.c | 6+++---
Msrc/testzzuf/test_put.c | 4++--
Msrc/testzzuf/test_put_chunked.c | 4++--
Msrc/testzzuf/test_put_large.c | 6++++--
82 files changed, 890 insertions(+), 857 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,5 +1,10 @@ Wed 08 Apr 2020 10:53:01 PM CEST - Introduce `enum MHD_Result` for #MHD_YES/#MHD_NO to avoid using 'int' so much. -CG + Introduce `enum MHD_Result` for #MHD_YES/#MHD_NO to avoid using 'int' so much. + Note that this change WILL cause compiler warnings until (most) MHD callbacks + in application code change their return type from 'int' to 'enum MHD_Result'. + That said, avoiding possible confusions of different enums is going to make + the code more robust in the future. For conditional compilation, test + for "MHD_VERSION >= 0x00097002". -CG Sat 07 Mar 2020 05:20:33 PM CET Fixed #6090 (misc. severe socket handling bugs on OS X). -CG diff --git a/doc/examples/basicauthentication.c b/doc/examples/basicauthentication.c @@ -17,7 +17,7 @@ #define PORT 8888 -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, @@ -28,45 +28,47 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, int fail; int ret; struct MHD_Response *response; - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; if (NULL == *con_cls) - { - *con_cls = connection; - return MHD_YES; - } + { + *con_cls = connection; + return MHD_YES; + } pass = NULL; user = MHD_basic_auth_get_username_password (connection, &pass); fail = ( (NULL == user) || - (0 != strcmp (user, "root")) || - (0 != strcmp (pass, "pa$$w0rd") ) ); - if (NULL != user) MHD_free (user); - if (NULL != pass) MHD_free (pass); + (0 != strcmp (user, "root")) || + (0 != strcmp (pass, "pa$$w0rd") ) ); + if (NULL != user) + MHD_free (user); + if (NULL != pass) + MHD_free (pass); if (fail) - { - const char *page = "<html><body>Go away.</body></html>"; - response = - MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_basic_auth_fail_response (connection, - "my realm", - response); - } + { + const char *page = "<html><body>Go away.</body></html>"; + response = + MHD_create_response_from_buffer (strlen (page), (void *) page, + MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_basic_auth_fail_response (connection, + "my realm", + response); + } else - { - const char *page = "<html><body>A secret.</body></html>"; - response = - MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); - ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - } + { + const char *page = "<html><body>A secret.</body></html>"; + response = + MHD_create_response_from_buffer (strlen (page), (void *) page, + MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + } MHD_destroy_response (response); return ret; } diff --git a/doc/examples/hellobrowser.c b/doc/examples/hellobrowser.c @@ -14,7 +14,7 @@ #define PORT 8888 -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, @@ -22,18 +22,18 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, { const char *page = "<html><body>Hello, browser!</body></html>"; struct MHD_Response *response; - int ret; - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)method; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ - (void)con_cls; /* Unused. Silent compiler warning. */ + enum MHD_Result ret; + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) method; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void) con_cls; /* Unused. Silent compiler warning. */ response = - MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); + MHD_create_response_from_buffer (strlen (page), (void *) page, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); @@ -46,7 +46,8 @@ main (void) { struct MHD_Daemon *daemon; - daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL, + daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, + PORT, NULL, NULL, &answer_to_connection, NULL, MHD_OPTION_END); if (NULL == daemon) return 1; diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c @@ -15,11 +15,11 @@ #ifdef _MSC_VER #ifndef strcasecmp -#define strcasecmp(a,b) _stricmp((a),(b)) +#define strcasecmp(a,b) _stricmp ((a),(b)) #endif /* !strcasecmp */ #endif /* _MSC_VER */ -#if defined(_MSC_VER) && _MSC_VER+0 <= 1800 +#if defined(_MSC_VER) && _MSC_VER + 0 <= 1800 /* Substitution is OK while return value is not used */ #define snprintf _snprintf #endif @@ -29,10 +29,10 @@ #define MAXCLIENTS 2 enum ConnectionType - { - GET = 0, - POST = 1 - }; +{ + GET = 0, + POST = 1 +}; static unsigned int nr_of_uploading_clients = 0; @@ -66,7 +66,8 @@ struct connection_info_struct }; -const char *askpage = "<html><body>\n\ +const char *askpage = + "<html><body>\n\ Upload a file, please!<br>\n\ There are %u clients uploading at the moment.<br>\n\ <form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\ @@ -85,23 +86,23 @@ const char *fileexistspage = "<html><body>This file already exists.</body></html>"; const char *fileioerror = "<html><body>IO error writing to disk.</body></html>"; -const char* const postprocerror = +const char*const postprocerror = "<html><head><title>Error</title></head><body>Error processing POST data</body></html>"; -static int +static enum MHD_Result send_page (struct MHD_Connection *connection, const char *page, int status_code) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; response = MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_MUST_COPY); - if (!response) + MHD_RESPMEM_MUST_COPY); + if (! response) return MHD_NO; MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, @@ -115,7 +116,7 @@ send_page (struct MHD_Connection *connection, } -static int +static enum MHD_Result iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, @@ -128,50 +129,50 @@ iterate_post (void *coninfo_cls, { struct connection_info_struct *con_info = coninfo_cls; FILE *fp; - (void)kind; /* Unused. Silent compiler warning. */ - (void)content_type; /* Unused. Silent compiler warning. */ - (void)transfer_encoding; /* Unused. Silent compiler warning. */ - (void)off; /* Unused. Silent compiler warning. */ + (void) kind; /* Unused. Silent compiler warning. */ + (void) content_type; /* Unused. Silent compiler warning. */ + (void) transfer_encoding; /* Unused. Silent compiler warning. */ + (void) off; /* Unused. Silent compiler warning. */ if (0 != strcmp (key, "file")) + { + con_info->answerstring = servererrorpage; + con_info->answercode = MHD_HTTP_BAD_REQUEST; + return MHD_YES; + } + + if (! con_info->fp) + { + if (0 != con_info->answercode) /* something went wrong */ + return MHD_YES; + if (NULL != (fp = fopen (filename, "rb"))) { - con_info->answerstring = servererrorpage; - con_info->answercode = MHD_HTTP_BAD_REQUEST; + fclose (fp); + con_info->answerstring = fileexistspage; + con_info->answercode = MHD_HTTP_FORBIDDEN; return MHD_YES; } - - if (! con_info->fp) + /* NOTE: This is technically a race with the 'fopen()' above, + but there is no easy fix, short of moving to open(O_EXCL) + instead of using fopen(). For the example, we do not care. */ + con_info->fp = fopen (filename, "ab"); + if (! con_info->fp) { - if (0 != con_info->answercode) /* something went wrong */ - return MHD_YES; - if (NULL != (fp = fopen (filename, "rb"))) - { - fclose (fp); - con_info->answerstring = fileexistspage; - con_info->answercode = MHD_HTTP_FORBIDDEN; - return MHD_YES; - } - /* NOTE: This is technically a race with the 'fopen()' above, - but there is no easy fix, short of moving to open(O_EXCL) - instead of using fopen(). For the example, we do not care. */ - con_info->fp = fopen (filename, "ab"); - if (!con_info->fp) - { - con_info->answerstring = fileioerror; - con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; - return MHD_YES; - } + con_info->answerstring = fileioerror; + con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; + return MHD_YES; } + } if (size > 0) + { + if (! fwrite (data, sizeof (char), size, con_info->fp)) { - if (! fwrite (data, sizeof (char), size, con_info->fp)) - { - con_info->answerstring = fileioerror; - con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; - return MHD_YES; - } + con_info->answerstring = fileioerror; + con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; + return MHD_YES; } + } return MHD_YES; } @@ -184,31 +185,31 @@ request_completed (void *cls, enum MHD_RequestTerminationCode toe) { struct connection_info_struct *con_info = *con_cls; - (void)cls; /* Unused. Silent compiler warning. */ - (void)connection; /* Unused. Silent compiler warning. */ - (void)toe; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) connection; /* Unused. Silent compiler warning. */ + (void) toe; /* Unused. Silent compiler warning. */ if (NULL == con_info) return; if (con_info->connectiontype == POST) + { + if (NULL != con_info->postprocessor) { - if (NULL != con_info->postprocessor) - { - MHD_destroy_post_processor (con_info->postprocessor); - nr_of_uploading_clients--; - } - - if (con_info->fp) - fclose (con_info->fp); + MHD_destroy_post_processor (con_info->postprocessor); + nr_of_uploading_clients--; } + if (con_info->fp) + fclose (con_info->fp); + } + free (con_info); *con_cls = NULL; } -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, @@ -218,109 +219,109 @@ answer_to_connection (void *cls, size_t *upload_data_size, void **con_cls) { - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ if (NULL == *con_cls) - { - /* First call, setup data structures */ - struct connection_info_struct *con_info; + { + /* First call, setup data structures */ + struct connection_info_struct *con_info; + + if (nr_of_uploading_clients >= MAXCLIENTS) + return send_page (connection, + busypage, + MHD_HTTP_SERVICE_UNAVAILABLE); - if (nr_of_uploading_clients >= MAXCLIENTS) - return send_page (connection, - busypage, - MHD_HTTP_SERVICE_UNAVAILABLE); + con_info = malloc (sizeof (struct connection_info_struct)); + if (NULL == con_info) + return MHD_NO; + con_info->answercode = 0; /* none yet */ + con_info->fp = NULL; - con_info = malloc (sizeof (struct connection_info_struct)); - if (NULL == con_info) + if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST)) + { + con_info->postprocessor = + MHD_create_post_processor (connection, + POSTBUFFERSIZE, + &iterate_post, + (void *) con_info); + + if (NULL == con_info->postprocessor) + { + free (con_info); return MHD_NO; - con_info->answercode = 0; /* none yet */ - con_info->fp = NULL; + } - if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST)) - { - con_info->postprocessor = - MHD_create_post_processor (connection, - POSTBUFFERSIZE, - &iterate_post, - (void *) con_info); + nr_of_uploading_clients++; - if (NULL == con_info->postprocessor) - { - free (con_info); - return MHD_NO; - } + con_info->connectiontype = POST; + } + else + { + con_info->connectiontype = GET; + } - nr_of_uploading_clients++; + *con_cls = (void *) con_info; - con_info->connectiontype = POST; - } - else - { - con_info->connectiontype = GET; - } + return MHD_YES; + } - *con_cls = (void *) con_info; + if (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) + { + /* We just return the standard form for uploads on all GET requests */ + char buffer[1024]; + + snprintf (buffer, + sizeof (buffer), + askpage, + nr_of_uploading_clients); + return send_page (connection, + buffer, + MHD_HTTP_OK); + } - return MHD_YES; - } + if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST)) + { + struct connection_info_struct *con_info = *con_cls; - if (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) + if (0 != *upload_data_size) { - /* We just return the standard form for uploads on all GET requests */ - char buffer[1024]; + /* Upload not yet done */ + if (0 != con_info->answercode) + { + /* we already know the answer, skip rest of upload */ + *upload_data_size = 0; + return MHD_YES; + } + if (MHD_YES != + MHD_post_process (con_info->postprocessor, + upload_data, + *upload_data_size)) + { + con_info->answerstring = postprocerror; + con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; + } + *upload_data_size = 0; - snprintf (buffer, - sizeof (buffer), - askpage, - nr_of_uploading_clients); - return send_page (connection, - buffer, - MHD_HTTP_OK); + return MHD_YES; } - - if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST)) + /* Upload finished */ + if (NULL != con_info->fp) { - struct connection_info_struct *con_info = *con_cls; - - if (0 != *upload_data_size) - { - /* Upload not yet done */ - if (0 != con_info->answercode) - { - /* we already know the answer, skip rest of upload */ - *upload_data_size = 0; - return MHD_YES; - } - if (MHD_YES != - MHD_post_process (con_info->postprocessor, - upload_data, - *upload_data_size)) - { - con_info->answerstring = postprocerror; - con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; - } - *upload_data_size = 0; - - return MHD_YES; - } - /* Upload finished */ - if (NULL != con_info->fp) - { - fclose (con_info->fp); - con_info->fp = NULL; - } - if (0 == con_info->answercode) - { - /* No errors encountered, declare success */ - con_info->answerstring = completepage; - con_info->answercode = MHD_HTTP_OK; - } - return send_page (connection, - con_info->answerstring, - con_info->answercode); + fclose (con_info->fp); + con_info->fp = NULL; } + if (0 == con_info->answercode) + { + /* No errors encountered, declare success */ + con_info->answerstring = completepage; + con_info->answercode = MHD_HTTP_OK; + } + return send_page (connection, + con_info->answerstring, + con_info->answercode); + } /* Note a GET or a POST, generate error */ return send_page (connection, @@ -337,14 +338,15 @@ main () daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL, &answer_to_connection, NULL, - MHD_OPTION_NOTIFY_COMPLETED, &request_completed, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &request_completed, + NULL, MHD_OPTION_END); if (NULL == daemon) - { - fprintf (stderr, - "Failed to start daemon\n"); - return 1; - } + { + fprintf (stderr, + "Failed to start daemon\n"); + return 1; + } (void) getchar (); MHD_stop_daemon (daemon); return 0; diff --git a/doc/examples/logging.c b/doc/examples/logging.c @@ -14,28 +14,28 @@ #define PORT 8888 -static int +static enum MHD_Result print_out_key (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { - (void)cls; /* Unused. Silent compiler warning. */ - (void)kind; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) kind; /* Unused. Silent compiler warning. */ printf ("%s: %s\n", key, value); return MHD_YES; } -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { - (void)cls; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ - (void)con_cls; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void) con_cls; /* Unused. Silent compiler warning. */ printf ("New %s request for %s using version %s\n", method, url, version); MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key, diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c @@ -19,7 +19,7 @@ #define FILENAME "picture.png" #define MIMETYPE "image/png" -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, @@ -27,43 +27,43 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, { struct MHD_Response *response; int fd; - int ret; + enum MHD_Result ret; struct stat sbuf; - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ - (void)con_cls; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void) con_cls; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; if ( (-1 == (fd = open (FILENAME, O_RDONLY))) || (0 != fstat (fd, &sbuf)) ) - { - const char *errorstr = - "<html><body>An internal server error has occured!\ + { + const char *errorstr = + "<html><body>An internal server error has occured!\ </body></html>"; - /* error accessing file */ - if (fd != -1) - (void) close (fd); - response = - MHD_create_response_from_buffer (strlen (errorstr), - (void *) errorstr, - MHD_RESPMEM_PERSISTENT); - if (NULL != response) - { - ret = - MHD_queue_response (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - response); - MHD_destroy_response (response); + /* error accessing file */ + if (fd != -1) + (void) close (fd); + response = + MHD_create_response_from_buffer (strlen (errorstr), + (void *) errorstr, + MHD_RESPMEM_PERSISTENT); + if (NULL != response) + { + ret = + MHD_queue_response (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, + response); + MHD_destroy_response (response); - return ret; - } - else - return MHD_NO; + return ret; } + else + return MHD_NO; + } response = MHD_create_response_from_fd_at_offset64 (sbuf.st_size, fd, 0); MHD_add_response_header (response, "Content-Type", MIMETYPE); diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c @@ -11,7 +11,7 @@ #include <time.h> #include <microhttpd.h> -#if defined _WIN32 && !defined(__MINGW64_VERSION_MAJOR) +#if defined _WIN32 && ! defined(__MINGW64_VERSION_MAJOR) static int asprintf (char **resultp, const char *format, ...) { @@ -32,7 +32,7 @@ asprintf (char **resultp, const char *format, ...) if (result != NULL) { int len2 = _vscprintf ((char *) format, argptr); - if (len2 != len - 1 || len2 <= 0) + if ((len2 != len - 1) || (len2 <= 0)) { free (result); result = NULL; @@ -49,37 +49,45 @@ asprintf (char **resultp, const char *format, ...) va_end (argptr); return len; } + + #endif /** * Invalid method page. */ -#define METHOD_ERROR "<html><head><title>Illegal request</title></head><body>Go away.</body></html>" +#define METHOD_ERROR \ + "<html><head><title>Illegal request</title></head><body>Go away.</body></html>" /** * Invalid URL page. */ -#define NOT_FOUND_ERROR "<html><head><title>Not found</title></head><body>Go away.</body></html>" +#define NOT_FOUND_ERROR \ + "<html><head><title>Not found</title></head><body>Go away.</body></html>" /** * Front page. (/) */ -#define MAIN_PAGE "<html><head><title>Welcome</title></head><body><form action=\"/2\" method=\"post\">What is your name? <input type=\"text\" name=\"v1\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" +#define MAIN_PAGE \ + "<html><head><title>Welcome</title></head><body><form action=\"/2\" method=\"post\">What is your name? <input type=\"text\" name=\"v1\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" /** * Second page. (/2) */ -#define SECOND_PAGE "<html><head><title>Tell me more</title></head><body><a href=\"/\">previous</a> <form action=\"/S\" method=\"post\">%s, what is your job? <input type=\"text\" name=\"v2\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" +#define SECOND_PAGE \ + "<html><head><title>Tell me more</title></head><body><a href=\"/\">previous</a> <form action=\"/S\" method=\"post\">%s, what is your job? <input type=\"text\" name=\"v2\" value=\"%s\" /><input type=\"submit\" value=\"Next\" /></body></html>" /** * Second page (/S) */ -#define SUBMIT_PAGE "<html><head><title>Ready to submit?</title></head><body><form action=\"/F\" method=\"post\"><a href=\"/2\">previous </a> <input type=\"hidden\" name=\"DONE\" value=\"yes\" /><input type=\"submit\" value=\"Submit\" /></body></html>" +#define SUBMIT_PAGE \ + "<html><head><title>Ready to submit?</title></head><body><form action=\"/F\" method=\"post\"><a href=\"/2\">previous </a> <input type=\"hidden\" name=\"DONE\" value=\"yes\" /><input type=\"submit\" value=\"Submit\" /></body></html>" /** * Last page. */ -#define LAST_PAGE "<html><head><title>Thank you</title></head><body>Thank you.</body></html>" +#define LAST_PAGE \ + "<html><head><title>Thank you</title></head><body>Thank you.</body></html>" /** * Name of our cookie. @@ -159,8 +167,6 @@ struct Request static struct Session *sessions; - - /** * Return the session handle for this connection, or * create one if this is a new user. @@ -172,40 +178,40 @@ get_session (struct MHD_Connection *connection) const char *cookie; cookie = MHD_lookup_connection_value (connection, - MHD_COOKIE_KIND, - COOKIE_NAME); + MHD_COOKIE_KIND, + COOKIE_NAME); if (cookie != NULL) + { + /* find existing session */ + ret = sessions; + while (NULL != ret) { - /* find existing session */ - ret = sessions; - while (NULL != ret) - { - if (0 == strcmp (cookie, ret->sid)) - break; - ret = ret->next; - } - if (NULL != ret) - { - ret->rc++; - return ret; - } + if (0 == strcmp (cookie, ret->sid)) + break; + ret = ret->next; } + if (NULL != ret) + { + ret->rc++; + return ret; + } + } /* create fresh session */ ret = calloc (1, sizeof (struct Session)); if (NULL == ret) - { - fprintf (stderr, "calloc error: %s\n", strerror (errno)); - return NULL; - } + { + fprintf (stderr, "calloc error: %s\n", strerror (errno)); + return NULL; + } /* not a super-secure way to generate a random session ID, but should do for a simple example... */ snprintf (ret->sid, - sizeof (ret->sid), - "%X%X%X%X", - (unsigned int) rand (), - (unsigned int) rand (), - (unsigned int) rand (), - (unsigned int) rand ()); + sizeof (ret->sid), + "%X%X%X%X", + (unsigned int) rand (), + (unsigned int) rand (), + (unsigned int) rand (), + (unsigned int) rand ()); ret->rc++; ret->start = time (NULL); ret->next = sessions; @@ -221,12 +227,12 @@ get_session (struct MHD_Connection *connection) * @param mime mime type to use * @param session session information * @param connection connection to process - * @param MHD_YES on success, MHD_NO on failure + * @param #MHD_YES on success, #MHD_NO on failure */ -typedef int (*PageHandler)(const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection); +typedef enum MHD_Result (*PageHandler)(const void *cls, + const char *mime, + struct Session *session, + struct MHD_Connection *connection); /** @@ -264,22 +270,22 @@ struct Page */ static void add_session_cookie (struct Session *session, - struct MHD_Response *response) + struct MHD_Response *response) { char cstr[256]; snprintf (cstr, - sizeof (cstr), - "%s=%s", - COOKIE_NAME, - session->sid); + sizeof (cstr), + "%s=%s", + COOKIE_NAME, + session->sid); if (MHD_NO == MHD_add_response_header (response, - MHD_HTTP_HEADER_SET_COOKIE, - cstr)) - { - fprintf (stderr, - "Failed to set session cookie header!\n"); - } + MHD_HTTP_HEADER_SET_COOKIE, + cstr)) + { + fprintf (stderr, + "Failed to set session cookie header!\n"); + } } @@ -292,27 +298,27 @@ add_session_cookie (struct Session *session, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result serve_simple_form (const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection) + const char *mime, + struct Session *session, + struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; const char *form = cls; struct MHD_Response *response; /* return static form */ response = MHD_create_response_from_buffer (strlen (form), - (void *) form, - MHD_RESPMEM_PERSISTENT); + (void *) form, + MHD_RESPMEM_PERSISTENT); add_session_cookie (session, response); MHD_add_response_header (response, - MHD_HTTP_HEADER_CONTENT_ENCODING, - mime); + MHD_HTTP_HEADER_CONTENT_ENCODING, + mime); ret = MHD_queue_response (connection, - MHD_HTTP_OK, - response); + MHD_HTTP_OK, + response); MHD_destroy_response (response); return ret; } @@ -326,35 +332,35 @@ serve_simple_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result fill_v1_form (const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection) + const char *mime, + struct Session *session, + struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; const char *form = cls; char *reply; struct MHD_Response *response; if (-1 == asprintf (&reply, - form, - session->value_1)) - { - /* oops */ - return MHD_NO; - } + form, + session->value_1)) + { + /* oops */ + return MHD_NO; + } /* return static form */ response = MHD_create_response_from_buffer (strlen (reply), - (void *) reply, - MHD_RESPMEM_MUST_FREE); + (void *) reply, + MHD_RESPMEM_MUST_FREE); add_session_cookie (session, response); MHD_add_response_header (response, - MHD_HTTP_HEADER_CONTENT_ENCODING, - mime); + MHD_HTTP_HEADER_CONTENT_ENCODING, + mime); ret = MHD_queue_response (connection, - MHD_HTTP_OK, - response); + MHD_HTTP_OK, + response); MHD_destroy_response (response); return ret; } @@ -368,36 +374,36 @@ fill_v1_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result fill_v1_v2_form (const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection) + const char *mime, + struct Session *session, + struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; const char *form = cls; char *reply; struct MHD_Response *response; if (-1 == asprintf (&reply, - form, - session->value_1, - session->value_2)) - { - /* oops */ - return MHD_NO; - } + form, + session->value_1, + session->value_2)) + { + /* oops */ + return MHD_NO; + } /* return static form */ response = MHD_create_response_from_buffer (strlen (reply), - (void *) reply, - MHD_RESPMEM_MUST_FREE); + (void *) reply, + MHD_RESPMEM_MUST_FREE); add_session_cookie (session, response); MHD_add_response_header (response, - MHD_HTTP_HEADER_CONTENT_ENCODING, - mime); + MHD_HTTP_HEADER_CONTENT_ENCODING, + mime); ret = MHD_queue_response (connection, - MHD_HTTP_OK, - response); + MHD_HTTP_OK, + response); MHD_destroy_response (response); return ret; } @@ -411,27 +417,27 @@ fill_v1_v2_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result not_found_page (const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection) + const char *mime, + struct Session *session, + struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; - (void)cls; /* Unused. Silent compiler warning. */ - (void)session; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) session; /* Unused. Silent compiler warning. */ /* unsupported HTTP method */ response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR), - (void *) NOT_FOUND_ERROR, - MHD_RESPMEM_PERSISTENT); + (void *) NOT_FOUND_ERROR, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, - MHD_HTTP_NOT_FOUND, - response); + MHD_HTTP_NOT_FOUND, + response); MHD_add_response_header (response, - MHD_HTTP_HEADER_CONTENT_ENCODING, - mime); + MHD_HTTP_HEADER_CONTENT_ENCODING, + mime); MHD_destroy_response (response); return ret; } @@ -440,15 +446,13 @@ not_found_page (const void *cls, /** * List of all pages served by this HTTP server. */ -static struct Page pages[] = - { - { "/", "text/html", &fill_v1_form, MAIN_PAGE }, - { "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE }, - { "/S", "text/html", &serve_simple_form, SUBMIT_PAGE }, - { "/F", "text/html", &serve_simple_form, LAST_PAGE }, - { NULL, NULL, &not_found_page, NULL } /* 404 */ - }; - +static struct Page pages[] = { + { "/", "text/html", &fill_v1_form, MAIN_PAGE }, + { "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE }, + { "/S", "text/html", &serve_simple_form, SUBMIT_PAGE }, + { "/F", "text/html", &serve_simple_form, LAST_PAGE }, + { NULL, NULL, &not_found_page, NULL } /* 404 */ +}; /** @@ -470,53 +474,53 @@ static struct Page pages[] = * @return MHD_YES to continue iterating, * MHD_NO to abort the iteration */ -static int +static enum MHD_Result post_iterator (void *cls, - enum MHD_ValueKind kind, - const char *key, - const char *filename, - const char *content_type, - const char *transfer_encoding, - const char *data, uint64_t off, size_t size) + enum MHD_ValueKind kind, + const char *key, + const char *filename, + const char *content_type, + const char *transfer_encoding, + const char *data, uint64_t off, size_t size) { struct Request *request = cls; struct Session *session = request->session; - (void)kind; /* Unused. Silent compiler warning. */ - (void)filename; /* Unused. Silent compiler warning. */ - (void)content_type; /* Unused. Silent compiler warning. */ - (void)transfer_encoding; /* Unused. Silent compiler warning. */ + (void) kind; /* Unused. Silent compiler warning. */ + (void) filename; /* Unused. Silent compiler warning. */ + (void) content_type; /* Unused. Silent compiler warning. */ + (void) transfer_encoding; /* Unused. Silent compiler warning. */ if (0 == strcmp ("DONE", key)) - { - fprintf (stdout, - "Session `%s' submitted `%s', `%s'\n", - session->sid, - session->value_1, - session->value_2); - return MHD_YES; - } + { + fprintf (stdout, + "Session `%s' submitted `%s', `%s'\n", + session->sid, + session->value_1, + session->value_2); + return MHD_YES; + } if (0 == strcmp ("v1", key)) - { - if (size + off > sizeof(session->value_1)) - size = sizeof (session->value_1) - off; - memcpy (&session->value_1[off], - data, - size); - if (size + off < sizeof (session->value_1)) - session->value_1[size+off] = '\0'; - return MHD_YES; - } + { + if (size + off > sizeof(session->value_1)) + size = sizeof (session->value_1) - off; + memcpy (&session->value_1[off], + data, + size); + if (size + off < sizeof (session->value_1)) + session->value_1[size + off] = '\0'; + return MHD_YES; + } if (0 == strcmp ("v2", key)) - { - if (size + off > sizeof(session->value_2)) - size = sizeof (session->value_2) - off; - memcpy (&session->value_2[off], - data, - size); - if (size + off < sizeof (session->value_2)) - session->value_2[size+off] = '\0'; - return MHD_YES; - } + { + if (size + off > sizeof(session->value_2)) + size = sizeof (session->value_2) - off; + memcpy (&session->value_2[off], + data, + size); + if (size + off < sizeof (session->value_2)) + session->value_2[size + off] = '\0'; + return MHD_YES; + } fprintf (stderr, "Unsupported form value `%s'\n", key); return MHD_YES; } @@ -556,101 +560,101 @@ post_iterator (void *cls, * MHS_NO if the socket must be closed due to a serios * error while handling the request */ -static int +static enum MHD_Result create_response (void *cls, - struct MHD_Connection *connection, - const char *url, - const char *method, - const char *version, - const char *upload_data, - size_t *upload_data_size, - void **ptr) + struct MHD_Connection *connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + size_t *upload_data_size, + void **ptr) { struct MHD_Response *response; struct Request *request; struct Session *session; - int ret; + enum MHD_Result ret; unsigned int i; - (void)cls; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ request = *ptr; if (NULL == request) + { + request = calloc (1, sizeof (struct Request)); + if (NULL == request) { - request = calloc (1, sizeof (struct Request)); - if (NULL == request) - { - fprintf (stderr, "calloc error: %s\n", strerror (errno)); - return MHD_NO; - } - *ptr = request; - if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) - { - request->pp = MHD_create_post_processor (connection, 1024, - &post_iterator, request); - if (NULL == request->pp) - { - fprintf (stderr, "Failed to setup post processor for `%s'\n", - url); - return MHD_NO; /* internal error */ - } - } - return MHD_YES; + fprintf (stderr, "calloc error: %s\n", strerror (errno)); + return MHD_NO; + } + *ptr = request; + if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) + { + request->pp = MHD_create_post_processor (connection, 1024, + &post_iterator, request); + if (NULL == request->pp) + { + fprintf (stderr, "Failed to setup post processor for `%s'\n", + url); + return MHD_NO; /* internal error */ + } } + return MHD_YES; + } if (NULL == request->session) + { + request->session = get_session (connection); + if (NULL == request->session) { - request->session = get_session (connection); - if (NULL == request->session) - { - fprintf (stderr, "Failed to setup session for `%s'\n", - url); - return MHD_NO; /* internal error */ - } + fprintf (stderr, "Failed to setup session for `%s'\n", + url); + return MHD_NO; /* internal error */ } + } 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, + *upload_data_size); + if (0 != *upload_data_size) { - /* evaluate POST data */ - MHD_post_process (request->pp, - upload_data, - *upload_data_size); - if (0 != *upload_data_size) - { - *upload_data_size = 0; - return MHD_YES; - } - /* done with POST data, serve response */ - MHD_destroy_post_processor (request->pp); - request->pp = NULL; - method = MHD_HTTP_METHOD_GET; /* fake 'GET' */ - if (NULL != request->post_url) - url = request->post_url; + *upload_data_size = 0; + return MHD_YES; } + /* done with POST data, serve response */ + MHD_destroy_post_processor (request->pp); + request->pp = NULL; + method = MHD_HTTP_METHOD_GET; /* fake 'GET' */ + if (NULL != request->post_url) + url = request->post_url; + } if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) - { - /* find out which page to serve */ - i=0; - while ( (pages[i].url != NULL) && - (0 != strcmp (pages[i].url, url)) ) - i++; - ret = pages[i].handler (pages[i].handler_cls, - pages[i].mime, - session, connection); - if (ret != MHD_YES) - fprintf (stderr, "Failed to create page for `%s'\n", - url); - return ret; - } + { + /* find out which page to serve */ + i = 0; + while ( (pages[i].url != NULL) && + (0 != strcmp (pages[i].url, url)) ) + i++; + ret = pages[i].handler (pages[i].handler_cls, + pages[i].mime, + session, connection); + if (ret != MHD_YES) + fprintf (stderr, "Failed to create page for `%s'\n", + url); + return ret; + } /* unsupported HTTP method */ response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), - (void *) METHOD_ERROR, - MHD_RESPMEM_PERSISTENT); + (void *) METHOD_ERROR, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, - MHD_HTTP_NOT_ACCEPTABLE, - response); + MHD_HTTP_NOT_ACCEPTABLE, + response); MHD_destroy_response (response); return ret; } @@ -667,14 +671,14 @@ create_response (void *cls, */ static void request_completed_callback (void *cls, - struct MHD_Connection *connection, - void **con_cls, - enum MHD_RequestTerminationCode toe) + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe) { struct Request *request = *con_cls; - (void)cls; /* Unused. Silent compiler warning. */ - (void)connection; /* Unused. Silent compiler warning. */ - (void)toe; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) connection; /* Unused. Silent compiler warning. */ + (void) toe; /* Unused. Silent compiler warning. */ if (NULL == request) return; @@ -702,21 +706,21 @@ expire_sessions () prev = NULL; pos = sessions; while (NULL != pos) + { + next = pos->next; + if (now - pos->start > 60 * 60) { - next = pos->next; - if (now - pos->start > 60 * 60) - { - /* expire sessions after 1h */ - if (NULL == prev) - sessions = pos->next; - else - prev->next = next; - free (pos); - } + /* expire sessions after 1h */ + if (NULL == prev) + sessions = pos->next; else - prev = pos; - pos = next; + prev->next = next; + free (pos); } + else + prev = pos; + pos = next; + } } @@ -737,48 +741,49 @@ main (int argc, char *const *argv) MHD_UNSIGNED_LONG_LONG mhd_timeout; if (argc != 2) - { - printf ("%s PORT\n", argv[0]); - return 1; - } + { + printf ("%s PORT\n", argv[0]); + return 1; + } /* initialize PRNG */ srand ((unsigned int) time (NULL)); d = MHD_start_daemon (MHD_USE_ERROR_LOG, atoi (argv[1]), NULL, NULL, - &create_response, NULL, - MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, - MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, - MHD_OPTION_END); + &create_response, NULL, + MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, + MHD_OPTION_NOTIFY_COMPLETED, + &request_completed_callback, NULL, + MHD_OPTION_END); if (NULL == d) return 1; while (1) + { + expire_sessions (); + max = 0; + FD_ZERO (&rs); + FD_ZERO (&ws); + 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) { - expire_sessions (); - max = 0; - FD_ZERO (&rs); - FD_ZERO (&ws); - 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) - { - tv.tv_sec = mhd_timeout / 1000; - tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000; - tvp = &tv; - } - else - tvp = NULL; - if (-1 == select (max + 1, &rs, &ws, &es, tvp)) - { - if (EINTR != errno) - fprintf (stderr, - "Aborting due to error during select: %s\n", - strerror (errno)); - break; - } - MHD_run (d); + tv.tv_sec = mhd_timeout / 1000; + tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000; + tvp = &tv; } + else + tvp = NULL; + if (-1 == select (max + 1, &rs, &ws, &es, tvp)) + { + if (EINTR != errno) + fprintf (stderr, + "Aborting due to error during select: %s\n", + strerror (errno)); + break; + } + MHD_run (d); + } MHD_stop_daemon (d); return 0; } diff --git a/doc/examples/simplepost.c b/doc/examples/simplepost.c @@ -13,7 +13,7 @@ #include <string.h> #include <stdlib.h> -#if defined(_MSC_VER) && _MSC_VER+0 <= 1800 +#if defined(_MSC_VER) && _MSC_VER + 0 <= 1800 /* Substitution is OK while return value is not used */ #define snprintf _snprintf #endif @@ -33,7 +33,8 @@ struct connection_info_struct struct MHD_PostProcessor *postprocessor; }; -const char *askpage = "<html><body>\ +const char *askpage = + "<html><body>\ What's your name, Sir?<br>\ <form action=\"/namepost\" method=\"post\">\ <input name=\"name\" type=\"text\">\ @@ -47,17 +48,17 @@ const char *errorpage = "<html><body>This doesn't seem to be right.</body></html>"; -static int +static enum MHD_Result send_page (struct MHD_Connection *connection, const char *page) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; response = MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); - if (!response) + MHD_RESPMEM_PERSISTENT); + if (! response) return MHD_NO; ret = MHD_queue_response (connection, MHD_HTTP_OK, response); @@ -67,135 +68,138 @@ send_page (struct MHD_Connection *connection, const char *page) } -static int +static enum MHD_Result iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) { struct connection_info_struct *con_info = coninfo_cls; - (void)kind; /* Unused. Silent compiler warning. */ - (void)filename; /* Unused. Silent compiler warning. */ - (void)content_type; /* Unused. Silent compiler warning. */ - (void)transfer_encoding; /* Unused. Silent compiler warning. */ - (void)off; /* Unused. Silent compiler warning. */ + (void) kind; /* Unused. Silent compiler warning. */ + (void) filename; /* Unused. Silent compiler warning. */ + (void) content_type; /* Unused. Silent compiler warning. */ + (void) transfer_encoding; /* Unused. Silent compiler warning. */ + (void) off; /* Unused. Silent compiler warning. */ if (0 == strcmp (key, "name")) + { + if ((size > 0) && (size <= MAXNAMESIZE)) { - if ((size > 0) && (size <= MAXNAMESIZE)) - { - char *answerstring; - answerstring = malloc (MAXANSWERSIZE); - if (!answerstring) - return MHD_NO; - - snprintf (answerstring, MAXANSWERSIZE, greetingpage, data); - con_info->answerstring = answerstring; - } - else - con_info->answerstring = NULL; + char *answerstring; + answerstring = malloc (MAXANSWERSIZE); + if (! answerstring) + return MHD_NO; - return MHD_NO; + snprintf (answerstring, MAXANSWERSIZE, greetingpage, data); + con_info->answerstring = answerstring; } + else + con_info->answerstring = NULL; + + return MHD_NO; + } return MHD_YES; } + static void request_completed (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe) { struct connection_info_struct *con_info = *con_cls; - (void)cls; /* Unused. Silent compiler warning. */ - (void)connection; /* Unused. Silent compiler warning. */ - (void)toe; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) connection; /* Unused. Silent compiler warning. */ + (void) toe; /* Unused. Silent compiler warning. */ if (NULL == con_info) return; if (con_info->connectiontype == POST) - { - MHD_destroy_post_processor (con_info->postprocessor); - if (con_info->answerstring) - free (con_info->answerstring); - } + { + MHD_destroy_post_processor (con_info->postprocessor); + if (con_info->answerstring) + free (con_info->answerstring); + } free (con_info); *con_cls = NULL; } -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ if (NULL == *con_cls) - { - struct connection_info_struct *con_info; + { + struct connection_info_struct *con_info; - con_info = malloc (sizeof (struct connection_info_struct)); - if (NULL == con_info) - return MHD_NO; - con_info->answerstring = NULL; + con_info = malloc (sizeof (struct connection_info_struct)); + if (NULL == con_info) + return MHD_NO; + con_info->answerstring = NULL; - if (0 == strcmp (method, "POST")) - { - con_info->postprocessor = - MHD_create_post_processor (connection, POSTBUFFERSIZE, - iterate_post, (void *) con_info); + if (0 == strcmp (method, "POST")) + { + con_info->postprocessor = + MHD_create_post_processor (connection, POSTBUFFERSIZE, + iterate_post, (void *) con_info); - if (NULL == con_info->postprocessor) - { - free (con_info); - return MHD_NO; - } + if (NULL == con_info->postprocessor) + { + free (con_info); + return MHD_NO; + } - con_info->connectiontype = POST; - } - else - con_info->connectiontype = GET; + con_info->connectiontype = POST; + } + else + con_info->connectiontype = GET; - *con_cls = (void *) con_info; + *con_cls = (void *) con_info; - return MHD_YES; - } + return MHD_YES; + } if (0 == strcmp (method, "GET")) - { - return send_page (connection, askpage); - } + { + return send_page (connection, askpage); + } if (0 == strcmp (method, "POST")) + { + struct connection_info_struct *con_info = *con_cls; + + if (*upload_data_size != 0) { - struct connection_info_struct *con_info = *con_cls; - - if (*upload_data_size != 0) - { - MHD_post_process (con_info->postprocessor, upload_data, - *upload_data_size); - *upload_data_size = 0; - - return MHD_YES; - } - else if (NULL != con_info->answerstring) - return send_page (connection, con_info->answerstring); + MHD_post_process (con_info->postprocessor, upload_data, + *upload_data_size); + *upload_data_size = 0; + + return MHD_YES; } + else if (NULL != con_info->answerstring) + return send_page (connection, con_info->answerstring); + } return send_page (connection, errorpage); } + int main () { struct MHD_Daemon *daemon; - daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL, + daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, + PORT, NULL, NULL, &answer_to_connection, NULL, MHD_OPTION_NOTIFY_COMPLETED, request_completed, NULL, MHD_OPTION_END); diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c @@ -38,20 +38,20 @@ string_to_base64 (const char *message) return NULL; tmp[0] = 0; for (i = 0; i < length; i += 3) - { - l = (((unsigned long) message[i]) << 16) + { + l = (((unsigned long) message[i]) << 16) | (((i + 1) < length) ? (((unsigned long) message[i + 1]) << 8) : 0) | (((i + 2) < length) ? ((unsigned long) message[i + 2]) : 0); - strncat (tmp, &lookup[(l >> 18) & 0x3F], 1); - strncat (tmp, &lookup[(l >> 12) & 0x3F], 1); + strncat (tmp, &lookup[(l >> 18) & 0x3F], 1); + strncat (tmp, &lookup[(l >> 12) & 0x3F], 1); - if (i + 1 < length) - strncat (tmp, &lookup[(l >> 6) & 0x3F], 1); - if (i + 2 < length) - strncat (tmp, &lookup[l & 0x3F], 1); - } + if (i + 1 < length) + strncat (tmp, &lookup[(l >> 6) & 0x3F], 1); + if (i + 2 < length) + strncat (tmp, &lookup[l & 0x3F], 1); + } if (length % 3) strncat (tmp, "===", 3 - length % 3); @@ -67,16 +67,16 @@ get_file_size (const char *filename) fp = fopen (filename, "rb"); if (fp) - { - long size; + { + long size; - if ((0 != fseek (fp, 0, SEEK_END)) || (-1 == (size = ftell (fp)))) - size = 0; + if ((0 != fseek (fp, 0, SEEK_END)) || (-1 == (size = ftell (fp)))) + size = 0; - fclose (fp); + fclose (fp); - return size; - } + return size; + } else return 0; } @@ -99,58 +99,58 @@ load_file (const char *filename) buffer = malloc (size + 1); if (! buffer) - { - fclose (fp); - return NULL; - } + { + fclose (fp); + return NULL; + } buffer[size] = '\0'; - if (size != (long)fread (buffer, 1, size, fp)) - { - free (buffer); - buffer = NULL; - } + if (size != (long) fread (buffer, 1, size, fp)) + { + free (buffer); + buffer = NULL; + } fclose (fp); return buffer; } -static int +static enum MHD_Result ask_for_authentication (struct MHD_Connection *connection, const char *realm) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; char *headervalue; size_t slen; const char *strbase = "Basic realm="; response = MHD_create_response_from_buffer (0, NULL, - MHD_RESPMEM_PERSISTENT); - if (!response) + MHD_RESPMEM_PERSISTENT); + if (! response) return MHD_NO; slen = strlen (strbase) + strlen (realm) + 1; if (NULL == (headervalue = malloc (slen))) return MHD_NO; snprintf (headervalue, - slen, - "%s%s", - strbase, - realm); + slen, + "%s%s", + strbase, + realm); ret = MHD_add_response_header (response, - "WWW-Authenticate", - headervalue); + "WWW-Authenticate", + headervalue); free (headervalue); if (! ret) - { - MHD_destroy_response (response); - return MHD_NO; - } + { + MHD_destroy_response (response); + return MHD_NO; + } ret = MHD_queue_response (connection, - MHD_HTTP_UNAUTHORIZED, - response); + MHD_HTTP_UNAUTHORIZED, + response); MHD_destroy_response (response); return ret; } @@ -159,7 +159,7 @@ ask_for_authentication (struct MHD_Connection *connection, const char *realm) static int is_authenticated (struct MHD_Connection *connection, const char *username, - const char *password) + const char *password) { const char *headervalue; char *expected_b64; @@ -180,10 +180,10 @@ is_authenticated (struct MHD_Connection *connection, if (NULL == (expected = malloc (slen))) return 0; snprintf (expected, - slen, - "%s:%s", - username, - password); + slen, + "%s:%s", + username, + password); expected_b64 = string_to_base64 (expected); free (expected); if (NULL == expected_b64) @@ -196,17 +196,17 @@ is_authenticated (struct MHD_Connection *connection, } -static int +static enum MHD_Result secret_page (struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; const char *page = "<html><body>A secret.</body></html>"; response = MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); - if (!response) + MHD_RESPMEM_PERSISTENT); + if (! response) return MHD_NO; ret = MHD_queue_response (connection, MHD_HTTP_OK, response); @@ -216,27 +216,27 @@ secret_page (struct MHD_Connection *connection) } -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { - (void)cls; /* Unused. Silent compiler warning. */ - (void)url; /* Unused. Silent compiler warning. */ - (void)version; /* Unused. Silent compiler warning. */ - (void)upload_data; /* Unused. Silent compiler warning. */ - (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void) cls; /* Unused. Silent compiler warning. */ + (void) url; /* Unused. Silent compiler warning. */ + (void) version; /* Unused. Silent compiler warning. */ + (void) upload_data; /* Unused. Silent compiler warning. */ + (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; if (NULL == *con_cls) - { - *con_cls = connection; - return MHD_YES; - } + { + *con_cls = connection; + return MHD_YES; + } - if (!is_authenticated (connection, USER, PASSWORD)) + if (! is_authenticated (connection, USER, PASSWORD)) return ask_for_authentication (connection, REALM); return secret_page (connection); @@ -254,14 +254,14 @@ main () cert_pem = load_file (SERVERCERTFILE); if ((key_pem == NULL) || (cert_pem == NULL)) - { - printf ("The key/certificate files could not be read.\n"); - if (NULL != key_pem) - free (key_pem); - if (NULL != cert_pem) - free (cert_pem); - return 1; - } + { + printf ("The key/certificate files could not be read.\n"); + if (NULL != key_pem) + free (key_pem); + if (NULL != cert_pem) + free (cert_pem); + return 1; + } daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS, PORT, NULL, @@ -269,14 +269,14 @@ main () MHD_OPTION_HTTPS_MEM_KEY, key_pem, MHD_OPTION_HTTPS_MEM_CERT, cert_pem, MHD_OPTION_END); if (NULL == daemon) - { - printf ("%s\n", cert_pem); + { + printf ("%s\n", cert_pem); - free (key_pem); - free (cert_pem); + free (key_pem); + free (cert_pem); - return 1; - } + return 1; + } (void) getchar (); diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c @@ -39,7 +39,7 @@ "<html><head><title>Access denied</title></head><body>Access denied</body></html>" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -50,7 +50,7 @@ ahc_echo (void *cls, static int aptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; char *user; char *pass; int fail; diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c @@ -106,7 +106,7 @@ uri_logger_cb (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c @@ -106,7 +106,7 @@ uri_logger_cb (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c @@ -86,7 +86,7 @@ static const char simple_response_text[] = "<body>Simple response text</body></html>"; -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -99,7 +99,7 @@ ahc_echo (void *cls, static int aptr; struct ResponseContentCallbackParam *callback_param; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/demo.c b/src/examples/demo.c @@ -264,7 +264,7 @@ struct ResponseDataContext * @param dirname name of the directory to list * @return #MHD_YES on success, #MHD_NO on error */ -static int +static enum MHD_Result list_directory (struct ResponseDataContext *rdc, const char *dirname) { @@ -444,7 +444,7 @@ struct UploadContext * @param size number of bytes in 'data' * @return #MHD_NO on allocation failure, #MHD_YES on success */ -static int +static enum MHD_Result do_append (char **ret, const char *data, size_t size) @@ -493,7 +493,7 @@ do_append (char **ret, * @return #MHD_YES to continue iterating, * #MHD_NO to abort the iteration */ -static int +static enum MHD_Result process_upload_data (void *cls, enum MHD_ValueKind kind, const char *key, @@ -662,12 +662,12 @@ response_completed_callback (void *cls, * Return the current directory listing. * * @param connection connection to return the directory for - * @return MHD_YES on success, MHD_NO on error + * @return #MHD_YES on success, #MHD_NO on error */ -static int +static enum MHD_Result return_directory_response (struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; (void) pthread_mutex_lock (&mutex); if (NULL == cached_directory_response) @@ -696,7 +696,7 @@ return_directory_response (struct MHD_Connection *connection) * @param ptr our context * @return #MHD_YES on success, #MHD_NO to drop connection */ -static int +static enum MHD_Result generate_page (void *cls, struct MHD_Connection *connection, const char *url, @@ -706,7 +706,7 @@ generate_page (void *cls, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; int fd; struct stat buf; (void) cls; /* Unused. Silent compiler warning. */ diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c @@ -267,7 +267,7 @@ struct ResponseDataContext * @param dirname name of the directory to list * @return MHD_YES on success, MHD_NO on error */ -static int +static enum MHD_Result list_directory (struct ResponseDataContext *rdc, const char *dirname) { @@ -447,7 +447,7 @@ struct UploadContext * @param size number of bytes in 'data' * @return #MHD_NO on allocation failure, #MHD_YES on success */ -static int +static enum MHD_Result do_append (char **ret, const char *data, size_t size) @@ -493,10 +493,10 @@ do_append (char **ret, * specified offset * @param off offset of data in the overall value * @param size number of bytes in data available - * @return MHD_YES to continue iterating, - * MHD_NO to abort the iteration + * @return #MHD_YES to continue iterating, + * #MHD_NO to abort the iteration */ -static int +static enum MHD_Result process_upload_data (void *cls, enum MHD_ValueKind kind, const char *key, @@ -667,10 +667,10 @@ response_completed_callback (void *cls, * @param connection connection to return the directory for * @return MHD_YES on success, MHD_NO on error */ -static int +static enum MHD_Result return_directory_response (struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; (void) pthread_mutex_lock (&mutex); if (NULL == cached_directory_response) @@ -699,7 +699,7 @@ return_directory_response (struct MHD_Connection *connection) * @param ptr our context * @return #MHD_YES on success, #MHD_NO to drop connection */ -static int +static enum MHD_Result generate_page (void *cls, struct MHD_Connection *connection, const char *url, @@ -709,7 +709,7 @@ generate_page (void *cls, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; int fd; struct stat buf; (void) cls; /* Unused. Silent compiler warning. */ diff --git a/src/examples/digest_auth_example.c b/src/examples/digest_auth_example.c @@ -34,7 +34,7 @@ #define MY_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -46,7 +46,7 @@ ahc_echo (void *cls, char *username; const char *password = "testpass"; const char *realm = "test@example.com"; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) method; /* Unused. Silent compiler warning. */ diff --git a/src/examples/dual_stack_example.c b/src/examples/dual_stack_example.c @@ -28,7 +28,7 @@ #define PAGE \ "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -39,7 +39,7 @@ ahc_echo (void *cls, static int aptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; /* Unused. Silent compiler warning. */ diff --git a/src/examples/fileserver_example.c b/src/examples/fileserver_example.c @@ -41,7 +41,7 @@ #define S_ISREG(x) (S_IFREG == (x & S_IFREG)) #endif /* S_ISREG */ -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -52,7 +52,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; int fd; struct stat buf; (void) cls; /* Unused. Silent compiler warning. */ diff --git a/src/examples/fileserver_example_dirs.c b/src/examples/fileserver_example_dirs.c @@ -81,7 +81,7 @@ dir_reader (void *cls, uint64_t pos, char *buf, size_t max) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; FILE *file; int fd; DIR *dir; diff --git a/src/examples/fileserver_example_external_select.c b/src/examples/fileserver_example_external_select.c @@ -48,7 +48,7 @@ free_callback (void *cls) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -59,7 +59,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; FILE *file; int fd; struct stat buf; diff --git a/src/examples/http_chunked_compression.c b/src/examples/http_chunked_compression.c @@ -51,13 +51,13 @@ struct Holder void *buf; }; -static int +static enum MHD_Result compress_buf (z_stream *strm, const void *src, size_t src_size, size_t *offset, void **dest, size_t *dest_size, void *tmp) { unsigned int have; - int ret; + enum MHD_Result ret; int flush; void *tmp_dest; *dest = NULL; @@ -152,14 +152,14 @@ free_cb (void *cls) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *con, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_size, void **ptr) { struct Holder *holder; struct MHD_Response *res; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) method; diff --git a/src/examples/http_compression.c b/src/examples/http_compression.c @@ -31,7 +31,7 @@ "hello, hello. This is a 'hello world' message for the world, " \ "repeat, for the world.</body></html>" -static int +static enum MHD_Result can_compress (struct MHD_Connection *con) { const char *ae; @@ -60,7 +60,7 @@ can_compress (struct MHD_Connection *con) } -static int +static enum MHD_Result body_compress (void **buf, size_t *buf_size) { @@ -90,7 +90,7 @@ body_compress (void **buf, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -99,8 +99,8 @@ ahc_echo (void *cls, const char *upload_data, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; - int ret; - int comp; + enum MHD_Result ret; + enum MHD_Result comp; size_t body_len; char *body_str; (void) cls; /* Unused. Silent compiler warning. */ diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c @@ -113,7 +113,7 @@ file_free_callback (void *cls) /* HTTP access handler call back */ -static int +static enum MHD_Result http_ahc (void *cls, struct MHD_Connection *connection, const char *url, @@ -124,7 +124,7 @@ http_ahc (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; FILE *file; int fd; struct stat buf; diff --git a/src/examples/minimal_example.c b/src/examples/minimal_example.c @@ -28,7 +28,7 @@ #define PAGE \ "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -41,7 +41,7 @@ ahc_echo (void *cls, static int aptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/minimal_example_comet.c b/src/examples/minimal_example_comet.c @@ -38,7 +38,7 @@ data_generator (void *cls, uint64_t pos, char *buf, size_t max) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -48,7 +48,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/minimal_example_empty.c b/src/examples/minimal_example_empty.c @@ -26,7 +26,7 @@ #include <microhttpd.h> -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -38,7 +38,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/minimal_example_empty_tls.c b/src/examples/minimal_example_empty_tls.c @@ -26,7 +26,7 @@ #include <microhttpd.h> -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -38,7 +38,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/post_example.c b/src/examples/post_example.c @@ -205,10 +205,10 @@ get_session (struct MHD_Connection *connection) * @param connection connection to process * @param MHD_YES on success, MHD_NO on failure */ -typedef int (*PageHandler)(const void *cls, - const char *mime, - struct Session *session, - struct MHD_Connection *connection); +typedef enum MHD_Result (*PageHandler)(const void *cls, + const char *mime, + struct Session *session, + struct MHD_Connection *connection); /** @@ -274,13 +274,13 @@ add_session_cookie (struct Session *session, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result serve_simple_form (const void *cls, const char *mime, struct Session *session, struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; const char *form = cls; struct MHD_Response *response; @@ -310,13 +310,13 @@ serve_simple_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result fill_v1_form (const void *cls, const char *mime, struct Session *session, struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; size_t slen; char *reply; struct MHD_Response *response; @@ -359,13 +359,13 @@ fill_v1_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result fill_v1_v2_form (const void *cls, const char *mime, struct Session *session, struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; char *reply; struct MHD_Response *response; size_t slen; @@ -410,13 +410,13 @@ fill_v1_v2_form (const void *cls, * @param session session handle * @param connection connection to use */ -static int +static enum MHD_Result not_found_page (const void *cls, const char *mime, struct Session *session, struct MHD_Connection *connection) { - int ret; + enum MHD_Result ret; struct MHD_Response *response; (void) cls; /* Unused. Silent compiler warning. */ (void) session; /* Unused. Silent compiler warning. */ @@ -469,7 +469,7 @@ static struct Page pages[] = { * @return MHD_YES to continue iterating, * MHD_NO to abort the iteration */ -static int +static enum MHD_Result post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -554,7 +554,7 @@ post_iterator (void *cls, * MHS_NO if the socket must be closed due to a serios * error while handling the request */ -static int +static enum MHD_Result create_response (void *cls, struct MHD_Connection *connection, const char *url, @@ -567,7 +567,7 @@ create_response (void *cls, struct MHD_Response *response; struct Request *request; struct Session *session; - int ret; + enum MHD_Result ret; unsigned int i; (void) cls; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/querystring_example.c b/src/examples/querystring_example.c @@ -29,7 +29,7 @@ #define PAGE \ "<html><head><title>libmicrohttpd demo</title></head><body>Query string for &quot;%s&quot; was &quot;%s&quot;</body></html>" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -42,7 +42,7 @@ ahc_echo (void *cls, const char *val; char *me; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; /* Unused. Silent compiler warning. */ diff --git a/src/examples/refuse_post_example.c b/src/examples/refuse_post_example.c @@ -35,7 +35,7 @@ const char *askpage = #define BUSYPAGE \ "<html><head><title>Webserver busy</title></head><body>We are too busy to process POSTs right now.</body></html>" -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -46,7 +46,7 @@ ahc_echo (void *cls, static int aptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/suspend_resume_epoll.c b/src/examples/suspend_resume_epoll.c @@ -43,7 +43,7 @@ static int epfd; static struct epoll_event evt; -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -52,7 +52,7 @@ ahc_echo (void *cls, const char *upload_data, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; struct Request*req; struct itimerspec ts; diff --git a/src/examples/timeout.c b/src/examples/timeout.c @@ -29,7 +29,7 @@ #define PORT 8080 -static int +static enum MHD_Result answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, @@ -41,7 +41,7 @@ answer_to_connection (void *cls, { const char *page = "<html><body>Hello timeout!</body></html>"; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/examples/upgrade_example.c b/src/examples/upgrade_example.c @@ -240,7 +240,7 @@ uh_cb (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -252,7 +252,7 @@ ahc_echo (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/microhttpd/test_daemon.c b/src/microhttpd/test_daemon.c @@ -52,7 +52,7 @@ testStartError () } -static int +static enum MHD_Result apc_nothing (void *cls, const struct sockaddr *addr, socklen_t addrlen) @@ -63,7 +63,7 @@ apc_nothing (void *cls, } -static int +static enum MHD_Result apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) @@ -74,7 +74,7 @@ apc_all (void *cls, } -static int +static enum MHD_Result ahc_nothing (void *cls, struct MHD_Connection *connection, const char *url, diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c @@ -92,7 +92,7 @@ mismatch (const char *a, const char *b) } -static int +static enum MHD_Result value_checker (void *cls, enum MHD_ValueKind kind, const char *key, @@ -140,10 +140,10 @@ value_checker (void *cls, fprintf (stderr, "Wanted: `%s' `%s' `%s' `%s' `%s'\n", want[idx], - want[idx+1], - want[idx+2], - want[idx+3], - want[idx+4]); + want[idx + 1], + want[idx + 2], + want[idx + 3], + want[idx + 4]); fprintf (stderr, "Unexpected result: %d/%d/%d/%d/%d/%d/%d\n", (idx < 0), @@ -155,7 +155,7 @@ value_checker (void *cls, (0 != memcmp (data, &want[idx + 4][off], size))); return MHD_NO; } - if ( ( (NULL == want[idx+4]) && + if ( ( (NULL == want[idx + 4]) && (0 == off + size) ) || (off + size == strlen (want[idx + 4])) ) *want_off = idx + 5; diff --git a/src/microhttpd/test_postprocessor_amp.c b/src/microhttpd/test_postprocessor_amp.c @@ -7,7 +7,7 @@ uint64_t num_errors; -int +enum MHD_Result check_post (void *cls, enum MHD_ValueKind kind, const char*key, const char*filename, const char*content_type, const char*content_encoding, const char*data, diff --git a/src/microhttpd/test_postprocessor_large.c b/src/microhttpd/test_postprocessor_large.c @@ -33,7 +33,7 @@ #include <unistd.h> #endif -static int +static enum MHD_Result value_checker (void *cls, enum MHD_ValueKind kind, const char *key, diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c @@ -843,7 +843,7 @@ upgrade_cb (void *cls, * #MHD_NO if the socket must be closed due to a serios * error while handling the request */ -static int +static enum MHD_Result ahc_upgrade (void *cls, struct MHD_Connection *connection, const char *url, @@ -854,7 +854,7 @@ ahc_upgrade (void *cls, void **con_cls) { struct MHD_Response *resp; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) method; /* Unused. Silent compiler warning. */ diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c @@ -867,7 +867,7 @@ upgrade_cb (void *cls, * #MHD_NO if the socket must be closed due to a serios * error while handling the request */ -static int +static enum MHD_Result ahc_upgrade (void *cls, struct MHD_Connection *connection, const char *url, @@ -878,7 +878,7 @@ ahc_upgrade (void *cls, void **con_cls) { struct MHD_Response *resp; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) method; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c @@ -38,7 +38,7 @@ extern const char srv_self_signed_cert_pem[]; static int oneone; -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -48,7 +48,7 @@ ahc_echo (void *cls, void **unused) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c @@ -91,7 +91,7 @@ test_secure_get (FILE *test_fd, } -static int +static enum MHD_Result ahc_empty (void *cls, struct MHD_Connection *connection, const char *url, @@ -103,7 +103,7 @@ ahc_empty (void *cls, { static int ptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) url; diff --git a/src/testcurl/https/test_https_get_select.c b/src/testcurl/https/test_https_get_select.c @@ -39,7 +39,7 @@ extern const char srv_self_signed_cert_pem[]; static int oneone; -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -51,7 +51,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (me, method)) diff --git a/src/testcurl/https/test_https_session_info.c b/src/testcurl/https/test_https_session_info.c @@ -41,14 +41,15 @@ struct MHD_Daemon *d; * HTTP access handler call back * used to query negotiated security parameters */ -static int +static enum MHD_Result query_session_ahc (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; + int gret; (void) cls; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ @@ -59,11 +60,11 @@ query_session_ahc (void *cls, struct MHD_Connection *connection, } if (GNUTLS_TLS1_1 != - (ret = MHD_get_connection_info - (connection, - MHD_CONNECTION_INFO_PROTOCOL)->protocol)) + (gret = MHD_get_connection_info + (connection, + MHD_CONNECTION_INFO_PROTOCOL)->protocol)) { - if (GNUTLS_TLS1_2 == ret) + if (GNUTLS_TLS1_2 == gret) { /* as usual, TLS implementations sometimes don't quite do what was asked, just mildly complain... */ @@ -76,8 +77,8 @@ query_session_ahc (void *cls, struct MHD_Connection *connection, fprintf (stderr, "Error: requested protocol mismatch (wanted %d, got %d)\n", GNUTLS_TLS1_1, - ret); - return -1; + gret); + return MHD_NO; } } diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c @@ -176,7 +176,7 @@ copyBuffer (void *ptr, /** * HTTP access handler call back */ -int +enum MHD_Result http_ahc (void *cls, struct MHD_Connection *connection, const char *url, @@ -188,7 +188,7 @@ http_ahc (void *cls, { static int aptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ @@ -211,7 +211,7 @@ http_ahc (void *cls, /* HTTP access handler call back */ -int +enum MHD_Result http_dummy_ahc (void *cls, struct MHD_Connection *connection, const char *url, diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h @@ -95,12 +95,12 @@ print_test_result (int test_outcome, char *test_name); size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx); -int +enum MHD_Result http_ahc (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *upload_data, const char *version, size_t *upload_data_size, void **ptr); -int +enum MHD_Result http_dummy_ahc (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *upload_data, const char *version, size_t *upload_data_size, diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c @@ -151,7 +151,7 @@ copyBuffer (void *ptr, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -162,7 +162,7 @@ ahc_echo (void *cls, { static int ptr; const char *me = cls; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c @@ -146,7 +146,7 @@ copyBuffer (void *ptr, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -157,7 +157,7 @@ ahc_echo (void *cls, { static int ptr; const char *me = cls; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c @@ -58,7 +58,7 @@ called_twice (void *cls, uint64_t pos, char *buf, size_t max) } -static int +static enum MHD_Result callback (void *cls, struct MHD_Connection *connection, const char *url, @@ -70,7 +70,7 @@ callback (void *cls, { struct callback_closure *cbc = calloc (1, sizeof(struct callback_closure)); struct MHD_Response *r; - int ret; + enum MHD_Result ret; (void) cls; (void) url; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c @@ -134,7 +134,7 @@ copyBuffer (void *ptr, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -146,7 +146,7 @@ ahc_echo (void *cls, { static int ptr; const char *me = cls; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_delete.c b/src/testcurl/test_delete.c @@ -81,7 +81,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcasecmp ("DELETE", method)) diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c @@ -76,7 +76,7 @@ copyBuffer (void *ptr, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -90,7 +90,7 @@ ahc_echo (void *cls, char *username; const char *password = "testpass"; const char *realm = "test@example.com"; - int ret; + enum MHD_Result ret; (void) cls; (void) url; /* Unused. Silent compiler warning. */ (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_digestauth_sha256.c b/src/testcurl/test_digestauth_sha256.c @@ -77,7 +77,7 @@ copyBuffer (void *ptr, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -91,7 +91,7 @@ ahc_echo (void *cls, char *username; const char *password = "testpass"; const char *realm = "test@example.com"; - int ret; + enum MHD_Result ret; (void) cls; (void) url; /* Unused. Silent compiler warning. */ (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_digestauth_with_arguments.c b/src/testcurl/test_digestauth_with_arguments.c @@ -71,7 +71,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -84,7 +84,7 @@ ahc_echo (void *cls, char *username; const char *password = "testpass"; const char *realm = "test@example.com"; - int ret; + enum MHD_Result ret; (void) cls; (void) url; /* Unused. Silent compiler warning. */ (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c @@ -98,7 +98,7 @@ log_cb (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -110,7 +110,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; const char *v; (void) version; (void) upload_data; @@ -714,7 +714,7 @@ testStopRace (int poll_flag) } -static int +static enum MHD_Result ahc_empty (void *cls, struct MHD_Connection *connection, const char *url, @@ -726,7 +726,7 @@ ahc_empty (void *cls, { static int ptr; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) url; diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c @@ -106,7 +106,7 @@ crcf (void *ptr) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -118,7 +118,7 @@ ahc_echo (void *cls, const char *me = cls; struct MHD_Response *response; struct MHD_Response **responseptr; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c @@ -116,7 +116,7 @@ push_free_callback (void *cls) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -128,7 +128,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c @@ -75,7 +75,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -87,7 +87,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; int fd; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ @@ -490,7 +490,7 @@ testExternalGet () if (cbc.pos != strlen (TESTSTR)) { fprintf (stderr, - "Got %.*s instead of %S!\n", + "Got %.*s instead of %s!\n", (int) cbc.pos, cbc.buf, TESTSTR); diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c @@ -74,7 +74,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -86,7 +86,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (me, method)) diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c @@ -118,7 +118,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -129,7 +129,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; static size_t processed; (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_long_header.c b/src/testcurl/test_long_header.c @@ -46,7 +46,7 @@ static int oneone; -static int +static enum MHD_Result apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) { (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */ @@ -69,7 +69,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -80,7 +80,7 @@ ahc_echo (void *cls, { const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_parse_cookies.c b/src/testcurl/test_parse_cookies.c @@ -59,7 +59,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -71,7 +71,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; const char *hdr; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_patch.c b/src/testcurl/test_patch.c @@ -81,7 +81,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcasecmp ("PATCH", method)) diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c @@ -97,7 +97,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) * in that it fails to support incremental processing. * (to be fixed in the future) */ -static int +static enum MHD_Result post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -120,7 +120,7 @@ post_iterator (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -132,7 +132,7 @@ ahc_echo (void *cls, static int eok; struct MHD_Response *response; struct MHD_PostProcessor *pp; - int ret; + enum MHD_Result ret; (void) cls; (void) version; /* Unused. Silent compiler warning. */ if (0 != strcasecmp ("POST", method)) @@ -562,7 +562,7 @@ testExternalPost () } -static int +static enum MHD_Result ahc_cancel (void *cls, struct MHD_Connection *connection, const char *url, @@ -572,7 +572,7 @@ ahc_cancel (void *cls, void **unused) { struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c @@ -72,7 +72,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -83,7 +83,7 @@ ahc_echo (void *cls, { static int marker; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c @@ -93,7 +93,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) * in that it fails to support incremental processing. * (to be fixed in the future) */ -static int +static enum MHD_Result post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -119,7 +119,7 @@ post_iterator (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -131,7 +131,7 @@ ahc_echo (void *cls, static int eok; struct MHD_Response *response; struct MHD_PostProcessor *pp; - int ret; + enum MHD_Result ret; (void) cls; (void) version; /* Unused. Silent compiler warning. */ if (0 != strcmp ("POST", method)) diff --git a/src/testcurl/test_process_arguments.c b/src/testcurl/test_process_arguments.c @@ -60,7 +60,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -72,7 +72,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; const char *hdr; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c @@ -66,7 +66,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { if ((0 == strcmp (key, MHD_HTTP_HEADER_HOST)) && @@ -80,7 +80,7 @@ kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; const char *hdr; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_put.c b/src/testcurl/test_put.c @@ -81,7 +81,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcasecmp ("PUT", method)) diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c @@ -81,7 +81,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -92,7 +92,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; int have; (void) version; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c @@ -70,7 +70,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -82,7 +82,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (me, method)) diff --git a/src/testcurl/test_quiesce_stream.c b/src/testcurl/test_quiesce_stream.c @@ -132,7 +132,7 @@ free_crc_data (void *crc_data) } -static int +static enum MHD_Result http_AccessHandlerCallback (void *cls, struct MHD_Connection *connection, const char *url, @@ -142,7 +142,7 @@ http_AccessHandlerCallback (void *cls, size_t *upload_data_size, void **con_cls) { - int ret; + enum MHD_Result ret; (void) cls; (void) url; /* Unused. Silent compiler warning. */ (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; /* Unused. Silent compiler warning. */ diff --git a/src/testcurl/test_termination.c b/src/testcurl/test_termination.c @@ -47,7 +47,7 @@ #include <windows.h> #endif -static int +static enum MHD_Result connection_handler (void *cls, struct MHD_Connection *connection, const char *url, @@ -76,7 +76,7 @@ connection_handler (void *cls, struct MHD_Response *response = MHD_create_response_from_buffer (strlen ("Response"), "Response", MHD_RESPMEM_PERSISTENT); - int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + enum MHD_Result ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c @@ -121,7 +121,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -132,7 +132,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcmp ("PUT", method)) diff --git a/src/testcurl/test_urlparse.c b/src/testcurl/test_urlparse.c @@ -69,7 +69,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result test_values (void *cls, enum MHD_ValueKind kind, const char *key, @@ -89,7 +89,7 @@ test_values (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -101,7 +101,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (me, method)) diff --git a/src/testzzuf/test_get.c b/src/testzzuf/test_get.c @@ -60,7 +60,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -72,7 +72,7 @@ ahc_echo (void *cls, static int ptr; const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (me, method)) diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c @@ -89,7 +89,7 @@ crcf (void *ptr) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -101,7 +101,7 @@ ahc_echo (void *cls, const char *me = cls; struct MHD_Response *response; struct MHD_Response **responseptr; - int ret; + enum MHD_Result ret; (void) url; (void) version; /* Unused. Silent compiler warning. */ diff --git a/src/testzzuf/test_long_header.c b/src/testzzuf/test_long_header.c @@ -47,7 +47,7 @@ static int oneone; -static int +static enum MHD_Result apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) { (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */ @@ -70,7 +70,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -81,7 +81,7 @@ ahc_echo (void *cls, { const char *me = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ @@ -128,6 +128,11 @@ testLongUrlGet () c = curl_easy_init (); url = malloc (VERY_LONG); + if (NULL == url) + { + zzuf_socat_stop (); + return 1; + } memset (url, 'a', VERY_LONG); url[VERY_LONG - 1] = '\0'; memcpy (url, "http://127.0.0.1:11081/", @@ -189,6 +194,12 @@ testLongHeaderGet () fprintf (stderr, "."); c = curl_easy_init (); url = malloc (VERY_LONG); + if (NULL == url) + { + zzuf_socat_stop (); + curl_easy_cleanup (c); + return 16; + } memset (url, 'a', VERY_LONG); url[VERY_LONG - 1] = '\0'; url[VERY_LONG / 2] = ':'; diff --git a/src/testzzuf/test_post.c b/src/testzzuf/test_post.c @@ -84,7 +84,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) * in that it fails to support incremental processing. * (to be fixed in the future) */ -static int +static enum MHD_Result post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -107,7 +107,7 @@ post_iterator (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -119,7 +119,7 @@ ahc_echo (void *cls, static int eok; struct MHD_Response *response; struct MHD_PostProcessor *pp; - int ret; + enum MHD_Result ret; (void) cls; (void) version; /* Unused. Silent compiler warning. */ if (0 != strcmp ("POST", method)) diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c @@ -82,7 +82,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) * in that it fails to support incremental processing. * (to be fixed in the future) */ -static int +static enum MHD_Result post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, @@ -110,7 +110,7 @@ post_iterator (void *cls, } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -122,7 +122,7 @@ ahc_echo (void *cls, static int eok; struct MHD_Response *response; struct MHD_PostProcessor *pp; - int ret; + enum MHD_Result ret; (void) cls; (void) version; /* Unused. Silent compiler warning. */ if (0 != strcmp ("POST", method)) diff --git a/src/testzzuf/test_put.c b/src/testzzuf/test_put.c @@ -76,7 +76,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -87,7 +87,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcmp ("PUT", method)) diff --git a/src/testzzuf/test_put_chunked.c b/src/testzzuf/test_put_chunked.c @@ -76,7 +76,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -87,7 +87,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; int have; (void) version; (void) unused; /* Unused. Silent compiler warning. */ diff --git a/src/testzzuf/test_put_large.c b/src/testzzuf/test_put_large.c @@ -84,7 +84,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, @@ -95,7 +95,7 @@ ahc_echo (void *cls, { int *done = cls; struct MHD_Response *response; - int ret; + enum MHD_Result ret; (void) version; (void) unused; /* Unused. Silent compiler warning. */ if (0 != strcmp ("PUT", method)) @@ -376,6 +376,8 @@ main (int argc, char *const *argv) if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; put_buffer = malloc (PUT_SIZE); + if (0 == put_buffer) + return 77; memset (put_buffer, 1, PUT_SIZE); if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) {