gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36758 - libmicrohttpd/doc/examples


From: gnunet
Subject: [GNUnet-SVN] r36758 - libmicrohttpd/doc/examples
Date: Fri, 11 Dec 2015 23:29:46 +0100

Author: grothoff
Date: 2015-12-11 23:29:46 +0100 (Fri, 11 Dec 2015)
New Revision: 36758

Modified:
   libmicrohttpd/doc/examples/largepost.c
Log:
cleaning up largepost

Modified: libmicrohttpd/doc/examples/largepost.c
===================================================================
--- libmicrohttpd/doc/examples/largepost.c      2015-12-11 19:21:11 UTC (rev 
36757)
+++ libmicrohttpd/doc/examples/largepost.c      2015-12-11 22:29:46 UTC (rev 
36758)
@@ -17,14 +17,17 @@
 #define POSTBUFFERSIZE  512
 #define MAXCLIENTS      2
 
-#define GET             0
-#define POST            1
+enum ConnectionType
+  {
+    GET = 0,
+    POST = 1
+  };
 
 static unsigned int nr_of_uploading_clients = 0;
 
 struct connection_info_struct
 {
-  int connectiontype;
+  enum ConnectionType connectiontype;
   struct MHD_PostProcessor *postprocessor;
   FILE *fp;
   const char *answerstring;
@@ -54,7 +57,8 @@
 
 
 static int
-send_page (struct MHD_Connection *connection, const char *page,
+send_page (struct MHD_Connection *connection,
+           const char *page,
            int status_code)
 {
   int ret;
@@ -61,12 +65,17 @@
   struct MHD_Response *response;
 
   response =
-    MHD_create_response_from_buffer (strlen (page), (void *) page,
+    MHD_create_response_from_buffer (strlen (page),
+                                     (void *) page,
                                     MHD_RESPMEM_MUST_COPY);
   if (!response)
     return MHD_NO;
-  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, 
"text/html");
-  ret = MHD_queue_response (connection, status_code, response);
+  MHD_add_response_header (response,
+                           MHD_HTTP_HEADER_CONTENT_TYPE,
+                           "text/html");
+  ret = MHD_queue_response (connection,
+                            status_code,
+                            response);
   MHD_destroy_response (response);
 
   return ret;
@@ -74,9 +83,14 @@
 
 
 static 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, uint64_t off,
+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;
@@ -88,7 +102,7 @@
   if (0 != strcmp (key, "file"))
     return MHD_NO;
 
-  if (!con_info->fp)
+  if (! con_info->fp)
     {
       if (NULL != (fp = fopen (filename, "rb")))
         {
@@ -105,7 +119,7 @@
 
   if (size > 0)
     {
-      if (!fwrite (data, size, sizeof (char), con_info->fp))
+      if (! fwrite (data, sizeof (char), size, con_info->fp))
         return MHD_NO;
     }
 
@@ -117,8 +131,10 @@
 
 
 static void
-request_completed (void *cls, struct MHD_Connection *connection,
-                   void **con_cls, enum MHD_RequestTerminationCode toe)
+request_completed (void *cls,
+                   struct MHD_Connection *connection,
+                   void **con_cls,
+                   enum MHD_RequestTerminationCode toe)
 {
   struct connection_info_struct *con_info = *con_cls;
 
@@ -143,10 +159,14 @@
 
 
 static int
-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)
+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)
 {
   if (NULL == *con_cls)
     {
@@ -153,7 +173,9 @@
       struct connection_info_struct *con_info;
 
       if (nr_of_uploading_clients >= MAXCLIENTS)
-        return send_page (connection, busypage, MHD_HTTP_SERVICE_UNAVAILABLE);
+        return send_page (connection,
+                          busypage,
+                          MHD_HTTP_SERVICE_UNAVAILABLE);
 
       con_info = malloc (sizeof (struct connection_info_struct));
       if (NULL == con_info)
@@ -161,11 +183,13 @@
 
       con_info->fp = NULL;
 
-      if (0 == strcmp (method, "POST"))
+      if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST))
         {
           con_info->postprocessor =
-            MHD_create_post_processor (connection, POSTBUFFERSIZE,
-                                       iterate_post, (void *) con_info);
+            MHD_create_post_processor (connection,
+                                       POSTBUFFERSIZE,
+                                       &iterate_post,
+                                       (void *) con_info);
 
           if (NULL == con_info->postprocessor)
             {
@@ -187,21 +211,27 @@
       return MHD_YES;
     }
 
-  if (0 == strcmp (method, "GET"))
+  if (0 == strcasecmp (method, MHD_HTTP_METHOD_GET))
     {
       char buffer[1024];
 
-      snprintf (buffer, sizeof (buffer), askpage, nr_of_uploading_clients);
-      return send_page (connection, buffer, MHD_HTTP_OK);
+      snprintf (buffer,
+                sizeof (buffer),
+                askpage,
+                nr_of_uploading_clients);
+      return send_page (connection,
+                        buffer,
+                        MHD_HTTP_OK);
     }
 
-  if (0 == strcmp (method, "POST"))
+  if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST))
     {
       struct connection_info_struct *con_info = *con_cls;
 
       if (0 != *upload_data_size)
         {
-          MHD_post_process (con_info->postprocessor, upload_data,
+          MHD_post_process (con_info->postprocessor,
+                            upload_data,
                             *upload_data_size);
           *upload_data_size = 0;
 
@@ -214,14 +244,18 @@
            fclose (con_info->fp);
            con_info->fp = NULL;
          }
-         /* Now it is safe to open and inspect the file before calling 
send_page with a response */
-         return send_page (connection, con_info->answerstring,
+         /* Now it is safe to open and inspect the file before
+             calling send_page with a response */
+         return send_page (connection,
+                            con_info->answerstring,
                            con_info->answercode);
        }
 
     }
 
-  return send_page (connection, errorpage, MHD_HTTP_BAD_REQUEST);
+  return send_page (connection,
+                    errorpage,
+                    MHD_HTTP_BAD_REQUEST);
 }
 
 
@@ -230,10 +264,11 @@
 {
   struct MHD_Daemon *daemon;
 
-  daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL,
+  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);
+                             MHD_OPTION_NOTIFY_COMPLETED, &request_completed, 
NULL,
+                             MHD_OPTION_END);
   if (NULL == daemon)
     return 1;
   (void) getchar ();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]