libmicrohttpd

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

commit 57f2c46ede626e2e4334f3063195b425e74548f2
parent 20be47629397dc69192a270ca171e24afb4f7365
Author: Sebastian Gerhardt <sebgerhardt@gmx.net>
Date:   Thu, 14 Aug 2008 20:07:48 +0000

improved adherence to GNU coding standards 
- basic authentication example
- simple post processing example  


Diffstat:
Mdoc/basicauthentication.inc | 59+++++++++++++++++++++++++++++------------------------------
Mdoc/examples/basicauthentication.c | 107+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mdoc/examples/simplepost.c | 176++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mdoc/processingpost.inc | 148+++++++++++++++++++++++++++++++++++++++++--------------------------------------
4 files changed, 248 insertions(+), 242 deletions(-)

diff --git a/doc/basicauthentication.inc b/doc/basicauthentication.inc @@ -42,12 +42,13 @@ so we can set the parameter to any adress that is assured to be not null. The po Not even the headers will be looked at on the first iteration. @verbatim -int AnswerToConnection(void *cls, struct MHD_Connection *connection, - const char *url, const char *method, const char *version, - const char *upload_data, unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, + const char *url, const char *method, const char *version, + const char *upload_data, unsigned int *upload_data_size, + void **con_cls) { if (0 != strcmp(method, "GET")) return MHD_NO; - if(*con_cls==NULL) {*con_cls=connection; return MHD_YES;} + if (NULL == *con_cls) {*con_cls = connection; return MHD_YES;} ... /* else respond accordingly */ @@ -69,24 +70,24 @@ so every "GET" request will be challenged. We let an extra function function do this. @verbatim -int AskForAuthentication(struct MHD_Connection *connection, const char *realm) +int ask_for_authentication (struct MHD_Connection *connection, const char *realm) { int ret; struct MHD_Response *response; char *headervalue; const char *strbase = "Basic realm="; - response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO); + response = MHD_create_response_from_data (0, NULL, MHD_NO, MHD_NO); if (!response) return MHD_NO; - headervalue = malloc( strlen(strbase) + strlen(realm) + 1); + headervalue = malloc (strlen (strbase) + strlen (realm) + 1); if (!headervalue) return MHD_NO; - strcpy(headervalue, strbase); - strcat(headervalue, realm); + strcpy (headervalue, strbase); + strcat (headervalue, realm); - ret = MHD_add_response_header(response, "WWW-Authenticate", headervalue); - free(headervalue); + ret = MHD_add_response_header (response, "WWW-Authenticate", headervalue); + free (headervalue); if (!ret) {MHD_destroy_response (response); return MHD_NO;} ret = MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response); @@ -115,16 +116,15 @@ and the resulting line is the value of a request header of the type "Authorizati This header line thus is of interest to the function checking a connection for a given username/password: @verbatim -int IsAuthenticated(struct MHD_Connection *connection, - const char *username, const char *password) +int is_authenticated (struct MHD_Connection *connection, + const char *username, const char *password) { const char *headervalue; ... - headervalue = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, "Authorization"); - - if(headervalue == NULL) return 0; + headervalue = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, + "Authorization"); + if (NULL == headervalue) return 0; @end verbatim @noindent @@ -132,7 +132,7 @@ where, firstly, the authentication method will be checked. @verbatim const char *strbase = "Basic "; ... -if (strncmp(headervalue, strbase, strlen(strbase))!=0) return 0; +if (0 != strncmp (headervalue, strbase, strlen (strbase))) return 0; @end verbatim @noindent @@ -146,18 +146,17 @@ it has been checked already at this point. int authenticated; ... - strcpy(expected, username); - strcat(expected, ":"); - strcat(expected, password); + strcpy (expected, username); + strcat (expected, ":"); + strcat (expected, password); - expected_b64 = StringToBase64(expected); - if(expected_b64 == NULL) return 0; + expected_b64 = string_to_base64 (expected); + if (NULL == expected_b64) return 0; - strcpy(expected, strbase); - - authenticated = (strcmp(headervalue+strlen(strbase), expected_b64) == 0); + strcpy (expected, strbase); + authenticated = (strcmp (headervalue + strlen (strbase), expected_b64) == 0); - free(expected_b64); + free (expected_b64); return authenticated; } @@ -167,10 +166,10 @@ it has been checked already at this point. These two functions---together with a response function in case of positive authentication doing little new---allow the rest of the callback function to be rather short. @verbatim - if (!IsAuthenticated(connection, USER, PASSWORD)) - return AskForAuthentication(connection, REALM); + if (!is_authenticated (connection, USER, PASSWORD)) + return ask_for_authentication (connection, REALM); - return SecretPage(connection); + return secret_page (connection); } @end verbatim @noindent diff --git a/doc/examples/basicauthentication.c b/doc/examples/basicauthentication.c @@ -11,27 +11,27 @@ #define PASSWORD "and his password" -char* StringToBase64(const char *message); +char* string_to_base64 (const char *message); -int AskForAuthentication(struct MHD_Connection *connection, const char *realm) +int ask_for_authentication (struct MHD_Connection *connection, const char *realm) { int ret; struct MHD_Response *response; char *headervalue; const char *strbase = "Basic realm="; - response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO); + response = MHD_create_response_from_data (0, NULL, MHD_NO, MHD_NO); if (!response) return MHD_NO; - headervalue = malloc( strlen(strbase) + strlen(realm) + 1); + headervalue = malloc (strlen (strbase) + strlen (realm) + 1); if (!headervalue) return MHD_NO; - strcpy(headervalue, strbase); - strcat(headervalue, realm); + strcpy (headervalue, strbase); + strcat (headervalue, realm); - ret = MHD_add_response_header(response, "WWW-Authenticate", headervalue); - free(headervalue); + ret = MHD_add_response_header (response, "WWW-Authenticate", headervalue); + free (headervalue); if (!ret) {MHD_destroy_response (response); return MHD_NO;} ret = MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response); @@ -41,8 +41,8 @@ int AskForAuthentication(struct MHD_Connection *connection, const char *realm) return ret; } -int IsAuthenticated(struct MHD_Connection *connection, const char *username, - const char *password) +int is_authenticated (struct MHD_Connection *connection, + const char *username, const char *password) { const char *headervalue; char *expected_b64, *expected; @@ -50,57 +50,56 @@ int IsAuthenticated(struct MHD_Connection *connection, const char *username, int authenticated; headervalue = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Authorization"); - if(headervalue == NULL) return 0; - if (strncmp(headervalue, strbase, strlen(strbase))!=0) return 0; + if (NULL == headervalue) return 0; + if (0 != strncmp (headervalue, strbase, strlen (strbase))) return 0; - expected = malloc(strlen(username) + 1 + strlen(password) + 1); - if(expected == NULL) return 0; + expected = malloc (strlen (username) + 1 + strlen (password) + 1); + if (NULL == expected) return 0; - strcpy(expected, username); - strcat(expected, ":"); - strcat(expected, password); + strcpy (expected, username); + strcat (expected, ":"); + strcat (expected, password); - expected_b64 = StringToBase64(expected); - if(expected_b64 == NULL) return 0; + expected_b64 = string_to_base64 (expected); + if (NULL == expected_b64) return 0; - strcpy(expected, strbase); + strcpy (expected, strbase); + authenticated = (strcmp (headervalue + strlen (strbase), expected_b64) == 0); - authenticated = (strcmp(headervalue+strlen(strbase), expected_b64) == 0); - - free(expected_b64); + free (expected_b64); return authenticated; } -int SecretPage(struct MHD_Connection *connection) +int secret_page (struct MHD_Connection *connection) { int ret; struct MHD_Response *response; const char *page = "<html><body>A secret.</body></html>"; - response = MHD_create_response_from_data(strlen(page), (void*)page, MHD_NO, MHD_NO); + response = MHD_create_response_from_data (strlen (page), (void*) page, MHD_NO, MHD_NO); if (!response) return MHD_NO; ret = MHD_queue_response (connection, MHD_HTTP_OK, response); - MHD_destroy_response (response); return ret; } -int AnswerToConnection(void *cls, struct MHD_Connection *connection, - const char *url, const char *method, const char *version, - const char *upload_data, unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, + const char *url, const char *method, const char *version, + const char *upload_data, unsigned int *upload_data_size, + void **con_cls) { if (0 != strcmp(method, "GET")) return MHD_NO; - if(*con_cls==NULL) {*con_cls=connection; return MHD_YES;} + if (NULL == *con_cls) {*con_cls = connection; return MHD_YES;} - if (!IsAuthenticated(connection, USER, PASSWORD)) - return AskForAuthentication(connection, REALM); + if (!is_authenticated (connection, USER, PASSWORD)) + return ask_for_authentication (connection, REALM); - return SecretPage(connection); + return secret_page (connection); } @@ -109,44 +108,44 @@ int main () struct MHD_Daemon *daemon; daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, - &AnswerToConnection, NULL, MHD_OPTION_END); + &answer_to_connection, NULL, MHD_OPTION_END); + if (NULL == daemon) return 1; - if (daemon == NULL) return 1; + getchar (); - getchar(); - - MHD_stop_daemon(daemon); + MHD_stop_daemon (daemon); return 0; } -char* StringToBase64(const char *message) +char* string_to_base64 (const char *message) { const char *lookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; unsigned long l; int i; char *tmp; - size_t length = strlen(message); + size_t length = strlen (message); - tmp = malloc(length*2); - if (tmp==NULL) return tmp; - tmp[0]=0; + tmp = malloc (length * 2); + if (NULL == tmp) return tmp; + + tmp[0] = 0; - for(i=0; i<length; i+=3) - { - 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 ); + for (i = 0; i < length; i += 3) + { + 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) ; + if (length % 3) strncat (tmp, "===", 3-length%3); return tmp; } diff --git a/doc/examples/simplepost.c b/doc/examples/simplepost.c @@ -11,132 +11,136 @@ #define GET 0 #define POST 1 -struct ConnectionInfoStruct +struct connection_info_struct { int connectiontype; char *answerstring; struct MHD_PostProcessor *postprocessor; }; -const char* askpage="<html><body>\ - What's your name, Sir?<br>\ - <form action=\"/namepost\" method=\"post\">\ - <input name=\"name\" type=\"text\"\ - <input type=\"submit\" value=\" Send \"></form>\ - </body></html>"; +const char* askpage = "<html><body>\ + What's your name, Sir?<br>\ + <form action=\"/namepost\" method=\"post\">\ + <input name=\"name\" type=\"text\"\ + <input type=\"submit\" value=\" Send \"></form>\ + </body></html>"; -const char* greatingpage="<html><body><h1>Welcome, %s!</center></h1></body></html>"; +const char* greatingpage = "<html><body><h1>Welcome, %s!</center></h1></body></html>"; -const char* errorpage="<html><body>This doesn't seem to be right.</body></html>"; +const char* errorpage = "<html><body>This doesn't seem to be right.</body></html>"; -int SendPage(struct MHD_Connection *connection, const char* page) +int send_page (struct MHD_Connection *connection, const char* page) { int ret; struct MHD_Response *response; - response = MHD_create_response_from_data(strlen(page), (void*)page, MHD_NO, MHD_NO); + response = MHD_create_response_from_data (strlen (page), (void*) page, MHD_NO, MHD_NO); if (!response) return MHD_NO; - ret = MHD_queue_response(connection, MHD_HTTP_OK, response); - - MHD_destroy_response(response); + ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); return ret; } -int IteratePost(void *coninfo_cls, enum MHD_ValueKind kind, const char *key, - const char *filename, const char *content_type, - const char *transfer_encoding, const char *data, size_t off, size_t size) +int 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, size_t off, size_t size) { - struct ConnectionInfoStruct *con_info = (struct ConnectionInfoStruct*)(coninfo_cls); + struct connection_info_struct *con_info = (struct connection_info_struct*) coninfo_cls; - if (0 == strcmp(key, "name")) - { - if ((size>0) && (size<=MAXNAMESIZE)) + if (0 == strcmp (key, "name")) { - char *answerstring; - answerstring = malloc(MAXANSWERSIZE); - if (!answerstring) return MHD_NO; + if ((size > 0) && (size <= MAXNAMESIZE)) + { + char *answerstring; + answerstring = malloc (MAXANSWERSIZE); + if (!answerstring) return MHD_NO; - snprintf(answerstring, MAXANSWERSIZE, greatingpage, data); - con_info->answerstring = answerstring; - } else con_info->answerstring=NULL; + snprintf (answerstring, MAXANSWERSIZE, greatingpage, data); + con_info->answerstring = answerstring; + } + else con_info->answerstring = NULL; - return MHD_NO; - } + return MHD_NO; + } return MHD_YES; } -void RequestCompleted(void *cls, struct MHD_Connection *connection, void **con_cls, - enum MHD_RequestTerminationCode toe) +void request_completed (void *cls, struct MHD_Connection *connection, void **con_cls, + enum MHD_RequestTerminationCode toe) { - struct ConnectionInfoStruct *con_info = (struct ConnectionInfoStruct*)(*con_cls); + struct connection_info_struct *con_info = (struct connection_info_struct*) *con_cls; 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); + free (con_info); } -int AnswerToConnection(void *cls, struct MHD_Connection *connection, const char *url, - const char *method, const char *version, const char *upload_data, - unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, + const char *method, const char *version, const char *upload_data, + unsigned int *upload_data_size, void **con_cls) { - if(*con_cls==NULL) - { - struct ConnectionInfoStruct *con_info; - - con_info = malloc(sizeof(struct ConnectionInfoStruct)); - if (NULL == con_info) return MHD_NO; - - if (0 == strcmp(method, "POST")) - { - con_info->postprocessor = MHD_create_post_processor(connection, POSTBUFFERSIZE, - IteratePost, (void*)con_info); - - if (NULL == con_info->postprocessor) - { - free(con_info); - return MHD_NO; - } - - con_info->connectiontype = POST; - } else con_info->connectiontype = GET; - - *con_cls = (void*)con_info; - return MHD_YES; - } - - if (0 == strcmp(method, "GET")) - { - return SendPage(connection, askpage); - } - - if (0 == strcmp(method, "POST")) - { - struct ConnectionInfoStruct *con_info = *con_cls; - - if (*upload_data_size != 0) + if(NULL == *con_cls) { - MHD_post_process(con_info->postprocessor, upload_data, *upload_data_size); - *upload_data_size = 0; + struct connection_info_struct *con_info; + + con_info = malloc (sizeof (struct connection_info_struct)); + if (NULL == con_info) return MHD_NO; + + 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; + } + + con_info->connectiontype = POST; + } + else con_info->connectiontype = GET; + + *con_cls = (void*) con_info; + return MHD_YES; - } else return SendPage(connection, con_info->answerstring); - } + } - return SendPage(connection, errorpage); + if (0 == strcmp (method, "GET")) + { + return send_page (connection, askpage); + } + + if (0 == strcmp (method, "POST")) + { + 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 return send_page (connection, con_info->answerstring); + } + + return send_page(connection, errorpage); } int main () @@ -144,14 +148,14 @@ int main () struct MHD_Daemon *daemon; - daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, - &AnswerToConnection, NULL, MHD_OPTION_NOTIFY_COMPLETED, - RequestCompleted, NULL, MHD_OPTION_END); - + daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, + &answer_to_connection, NULL, MHD_OPTION_NOTIFY_COMPLETED, + request_completed, NULL, MHD_OPTION_END); if (NULL == daemon) return 1; - getchar(); + getchar (); + + MHD_stop_daemon (daemon); - MHD_stop_daemon(daemon); return 0; } diff --git a/doc/processingpost.inc b/doc/processingpost.inc @@ -14,12 +14,12 @@ When the first @emph{GET} request arrives, the server shall respond with a HTML edit field for the name. @verbatim -const char* askpage="<html><body>\ - What's your name, Sir?<br>\ - <form action=\"/namepost\" method=\"post\">\ - <input name=\"name\" type=\"text\"\ - <input type=\"submit\" value=\" Send \"></form>\ - </body></html>"; +const char* askpage = "<html><body>\ + What's your name, Sir?<br>\ + <form action=\"/namepost\" method=\"post\">\ + <input name=\"name\" type=\"text\"\ + <input type=\"submit\" value=\" Send \"></form>\ + </body></html>"; @end verbatim @noindent @@ -56,7 +56,7 @@ But in order to pass this string to other functions and still be able to differe connections, we must first define a structure to share the information, holding the most import entries. @verbatim -struct ConnectionInfoStruct +struct connection_info_struct { int connectiontype; char *answerstring; @@ -73,27 +73,28 @@ chunks, we had to expand the namestring dynamically as additional parts of it wi came in. But in this example, the name is assumed to fit entirely inside one single packet. @verbatim -int IteratePost(void *coninfo_cls, enum MHD_ValueKind kind, const char *key, - const char *filename, const char *content_type, - const char *transfer_encoding, const char *data, size_t off, size_t size) +int 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, size_t off, size_t size) { - struct ConnectionInfoStruct *con_info = (struct ConnectionInfoStruct*)(coninfo_cls); + struct connection_info_struct *con_info = (struct connection_info_struct*) coninfo_cls; - if (0 == strcmp(key, "name")) - { - if ((size>0) && (size<=MAXNAMESIZE)) + if (0 == strcmp (key, "name")) { - char *answerstring; - answerstring = malloc(MAXANSWERSIZE); - if (!answerstring) return MHD_NO; + if ((size > 0) && (size <= MAXNAMESIZE)) + { + char *answerstring; + answerstring = malloc (MAXANSWERSIZE); + if (!answerstring) return MHD_NO; - snprintf(answerstring, MAXANSWERSIZE, greatingpage, data); - con_info->answerstring = answerstring; - } else con_info->answerstring=NULL; + snprintf (answerstring, MAXANSWERSIZE, greatingpage, data); + con_info->answerstring = answerstring; + } + else con_info->answerstring = NULL; - return MHD_NO; - } + return MHD_NO; + } return MHD_YES; } @@ -107,21 +108,21 @@ string. This cleanup function must take into account that it will also be called requests other than @emph{POST} requests. @verbatim -void RequestCompleted(void *cls, struct MHD_Connection *connection, void **con_cls, - enum MHD_RequestTerminationCode toe) +void request_completed (void *cls, struct MHD_Connection *connection, void **con_cls, + enum MHD_RequestTerminationCode toe) { - struct ConnectionInfoStruct *con_info = (struct ConnectionInfoStruct*)(*con_cls); + struct connection_info_struct *con_info = (struct connection_info_struct*) *con_cls; 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); + free (con_info); } @end verbatim @noindent @@ -131,9 +132,9 @@ in the main function. @verbatim ... -daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, - &AnswerToConnection, NULL, MHD_OPTION_NOTIFY_COMPLETED, - RequestCompleted, NULL, MHD_OPTION_END); +daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, + &answer_to_connection, NULL, MHD_OPTION_NOTIFY_COMPLETED, + request_completed, NULL, MHD_OPTION_END); ... @end verbatim @noindent @@ -146,54 +147,55 @@ On the first iteration for a new request, we start by allocating a new instance iterations and other functions. @verbatim -int AnswerToConnection(void *cls, struct MHD_Connection *connection, const char *url, - const char *method, const char *version, const char *upload_data, - unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, + const char *method, const char *version, const char *upload_data, + unsigned int *upload_data_size, void **con_cls) { - if(*con_cls==NULL) - { - struct ConnectionInfoStruct *con_info; + if(NULL == *con_cls) + { + struct connection_info_struct *con_info; - con_info = malloc(sizeof(struct ConnectionInfoStruct)); - if (NULL == con_info) return MHD_NO; + con_info = malloc (sizeof (struct connection_info_struct)); + if (NULL == con_info) return MHD_NO; @end verbatim @noindent If the new request is a @emph{POST}, the postprocessor must be created now. In addition, the type of the request is stored for convenience. @verbatim - if (0 == strcmp(method, "POST")) - { - con_info->postprocessor = MHD_create_post_processor(connection, POSTBUFFERSIZE, - IteratePost, (void*)con_info); - - if (NULL == con_info->postprocessor) - { - free(con_info); - return MHD_NO; - } - - con_info->connectiontype = POST; - } else con_info->connectiontype = GET; + 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; + } + + con_info->connectiontype = POST; + } + else con_info->connectiontype = GET; @end verbatim @noindent The address of our structure will both serve as the indicator for successive iterations and to remember the particular details about the connection. @verbatim - *con_cls = (void*)con_info; - return MHD_YES; - } + *con_cls = (void*) con_info; + return MHD_YES; + } @end verbatim @noindent The rest of the function will not be executed on the first iteration. A @emph{GET} request is easily satisfied by sending the question form. @verbatim - if (0 == strcmp(method, "GET")) - { - return SendPage(connection, askpage); - } + if (0 == strcmp (method, "GET")) + { + return send_page (connection, askpage); + } @end verbatim @noindent @@ -201,23 +203,25 @@ In case of @emph{POST}, we invoke the post processor for as long as data keeps i @code{*upload_data_size} to zero in order to indicate that we have processed---or at least have considered---all of it. @verbatim - if (0 == strcmp(method, "POST")) - { - struct ConnectionInfoStruct *con_info = *con_cls; - - if (*upload_data_size != 0) + if (0 == strcmp (method, "POST")) { - MHD_post_process(con_info->postprocessor, upload_data, *upload_data_size); - *upload_data_size = 0; - return MHD_YES; - } else return SendPage(connection, con_info->answerstring); - } + 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 return send_page (connection, con_info->answerstring); + } @end verbatim @noindent If they are neither @emph{GET} nor @emph{POST} requests, the error page is returned finally. @verbatim - return SendPage(connection, errorpage); + return send_page(connection, errorpage); } @end verbatim @noindent