[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7559 - in libmicrohttpd/doc: . examples
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7559 - in libmicrohttpd/doc: . examples |
Date: |
Thu, 14 Aug 2008 14:07:49 -0600 (MDT) |
Author: sebdocwriter
Date: 2008-08-14 14:07:48 -0600 (Thu, 14 Aug 2008)
New Revision: 7559
Modified:
libmicrohttpd/doc/basicauthentication.inc
libmicrohttpd/doc/examples/basicauthentication.c
libmicrohttpd/doc/examples/simplepost.c
libmicrohttpd/doc/processingpost.inc
Log:
improved adherence to GNU coding standards
- basic authentication example
- simple post processing example
Modified: libmicrohttpd/doc/basicauthentication.inc
===================================================================
--- libmicrohttpd/doc/basicauthentication.inc 2008-08-14 19:59:06 UTC (rev
7558)
+++ libmicrohttpd/doc/basicauthentication.inc 2008-08-14 20:07:48 UTC (rev
7559)
@@ -42,12 +42,13 @@
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 @@
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 @@
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 @@
@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,19 +146,18 @@
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);
+ 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;
}
@end verbatim
@@ -167,10 +166,10 @@
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
Modified: libmicrohttpd/doc/examples/basicauthentication.c
===================================================================
--- libmicrohttpd/doc/examples/basicauthentication.c 2008-08-14 19:59:06 UTC
(rev 7558)
+++ libmicrohttpd/doc/examples/basicauthentication.c 2008-08-14 20:07:48 UTC
(rev 7559)
@@ -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 @@
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 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 @@
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;
- 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 );
+ 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 );
- 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;
}
Modified: libmicrohttpd/doc/examples/simplepost.c
===================================================================
--- libmicrohttpd/doc/examples/simplepost.c 2008-08-14 19:59:06 UTC (rev
7558)
+++ libmicrohttpd/doc/examples/simplepost.c 2008-08-14 20:07:48 UTC (rev
7559)
@@ -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;
+ 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;
- if (0 == strcmp(method, "POST"))
- {
- con_info->postprocessor = MHD_create_post_processor(connection,
POSTBUFFERSIZE,
- IteratePost,
(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;
- return MHD_YES;
- }
+ *con_cls = (void*) con_info;
+
+ return MHD_YES;
+ }
- if (0 == strcmp(method, "GET"))
- {
- return SendPage(connection, askpage);
- }
+ if (0 == strcmp (method, "GET"))
+ {
+ return send_page (connection, askpage);
+ }
- 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;
- return SendPage(connection, errorpage);
+ 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 @@
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;
}
Modified: libmicrohttpd/doc/processingpost.inc
===================================================================
--- libmicrohttpd/doc/processingpost.inc 2008-08-14 19:59:06 UTC (rev
7558)
+++ libmicrohttpd/doc/processingpost.inc 2008-08-14 20:07:48 UTC (rev
7559)
@@ -14,12 +14,12 @@
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 @@
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 @@
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 @@
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 @@
@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 @@
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 (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;
@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 @@
@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 (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 SendPage(connection, con_info->answerstring);
- }
+ 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7559 - in libmicrohttpd/doc: . examples,
gnunet <=