gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35388 - gnunet/src/rest


From: gnunet
Subject: [GNUnet-SVN] r35388 - gnunet/src/rest
Date: Fri, 13 Mar 2015 22:50:55 +0100

Author: grothoff
Date: 2015-03-13 22:50:54 +0100 (Fri, 13 Mar 2015)
New Revision: 35388

Modified:
   gnunet/src/rest/gnunet-rest-server.c
Log:
-minor fixes

Modified: gnunet/src/rest/gnunet-rest-server.c
===================================================================
--- gnunet/src/rest/gnunet-rest-server.c        2015-03-13 17:37:07 UTC (rev 
35387)
+++ gnunet/src/rest/gnunet-rest-server.c        2015-03-13 21:50:54 UTC (rev 
35388)
@@ -61,12 +61,12 @@
 /**
  * The task ID
  */
-struct GNUNET_SCHEDULER_Task * httpd_task;
+static struct GNUNET_SCHEDULER_Task * httpd_task;
 
 /**
  * is this an ssl daemon? //TODO
  */
-int is_ssl;
+static int is_ssl;
 
 /**
  * The port the service is running on (default 7776)
@@ -111,7 +111,7 @@
 /**
  * Map of loaded plugins.
  */
-struct GNUNET_CONTAINER_MultiHashMap *plugin_map;
+static struct GNUNET_CONTAINER_MultiHashMap *plugin_map;
 
 /**
  * MHD Connection handle 
@@ -164,20 +164,27 @@
  * @param cls closure (MHD connection handle)
  * @param data the data to return to the caller
  * @param len length of the data
- * @param status GNUNET_OK if successful
+ * @param status #GNUNET_OK if successful
  */
-void
+static void
 plugin_callback (void *cls,
                  struct MHD_Response *resp,
                  int status)
 {
   struct MhdConnectionHandle *handle = cls;
+  struct MHD_Response *resp = MHD_create_response_from_buffer (len,
+                                                               (void*)data,
+                                                               
MHD_RESPMEM_MUST_COPY);
+  (void) MHD_add_response_header (resp,
+                                 MHD_HTTP_HEADER_CONTENT_TYPE,
+                                 "application/json");
   handle->status = status;
   handle->response = resp;
   run_mhd_now(); 
 }
 
-int
+
+static int
 cleanup_url_map (void *cls,
                  const struct GNUNET_HashCode *key,
                  void *value)
@@ -186,7 +193,8 @@
   return GNUNET_YES;
 }
 
-void
+
+static void
 cleanup_handle (struct MhdConnectionHandle *handle)
 {
   if (NULL != handle->response)
@@ -203,10 +211,10 @@
     GNUNET_free (handle->data_handle);
   }
   GNUNET_free (handle);
-
 }
 
-int
+
+static int
 url_iterator (void *cls,
               enum MHD_ValueKind kind,
               const char *key,
@@ -293,17 +301,14 @@
       con_handle->plugin = GNUNET_CONTAINER_multihashmap_get (plugin_map,
                                                               &key);
     }
-    else
-      con_handle->plugin = NULL;
-
     if (NULL == con_handle->plugin)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Queueing response with MHD\n");
       GNUNET_free (con_handle);
-      MHD_queue_response (con,
-                          MHD_HTTP_INTERNAL_SERVER_ERROR,
-                          failure_response);
+      return MHD_queue_response (con,
+                                MHD_HTTP_NOT_FOUND,
+                                failure_response);
     }
     return MHD_YES;
   }
@@ -326,14 +331,15 @@
                                          &plugin_callback,
                                          con_handle);
     *upload_data_size = 0;
-
   }
   if (NULL != con_handle->response)
   {
-
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Queueing response from plugin with MHD\n");
-    MHD_add_response_header 
(con_handle->response,"Access-Control-Allow-Origin","*");
+    /* FIXME: this is a bit dangerous... */
+    MHD_add_response_header (con_handle->response,
+                            "Access-Control-Allow-Origin",
+                            "*");
     int ret = MHD_queue_response (con,
                                  con_handle->status,
                                  con_handle->response);
@@ -343,6 +349,7 @@
   return MHD_YES;
 }
 
+
 /* ******************** MHD HTTP setup and event loop ******************** */
 
 /**
@@ -360,14 +367,22 @@
                   void **con_cls,
                   enum MHD_RequestTerminationCode toe)
 {
+  struct MhdConnectionHandle *con_handle;
 
+  con_handle = *con_cls;
+  if (NULL != con_handle)
+  {
+    MHD_destroy_response (con_handle->response);
+    GNUNET_free (con_handle);
+    *con_cls = NULL;
+  }
   if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "MHD encountered error handling request: %d\n",
                 toe);
-  *con_cls = NULL;
 }
 
+
 /**
  * Kill the MHD daemon.
  */
@@ -386,6 +401,7 @@
   }
 }
 
+
 /**
  * Task run whenever HTTP server is idle for too long. Kill it.
  *
@@ -399,6 +415,8 @@
   httpd_task = NULL;
   kill_httpd ();
 }
+
+
 /**
  * Schedule MHD.  This function should be called initially when an
  * MHD is first getting its client socket, and will then automatically
@@ -483,6 +501,7 @@
   schedule_httpd ();
 }
 
+
 /**
  * Accept new incoming connections
  *
@@ -534,6 +553,7 @@
   schedule_httpd ();
 }
 
+
 /**
  * Task run on shutdown
  *
@@ -549,6 +569,7 @@
   kill_httpd ();
 }
 
+
 /**
  * Create an IPv4 listen socket bound to our port.
  *
@@ -584,6 +605,7 @@
   return ls;
 }
 
+
 /**
  * Create an IPv6 listen socket bound to our port.
  *
@@ -619,6 +641,7 @@
   return ls;
 }
 
+
 /**
  * Callback for plugin load
  *
@@ -626,7 +649,7 @@
  * @param libname the name of the library loaded
  * @param lib_ret the object returned by the plugin initializer
  */
-void
+static void
 load_plugin (void *cls,
              const char *libname,
              void *lib_ret)
@@ -658,6 +681,7 @@
               libname);
 }
 
+
 /**
  * Main function that will be run
  *
@@ -667,7 +691,9 @@
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls, 
+     char *const *args, 
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
@@ -676,7 +702,9 @@
   /* Open listen socket proxy */
   lsock6 = bind_v6 ();
   if (NULL == lsock6)
+  {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  }
   else
   {
     if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock6, 5))
@@ -693,7 +721,9 @@
   }
   lsock4 = bind_v4 ();
   if (NULL == lsock4)
+  {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  }
   else
   {
     if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock4, 5))
@@ -738,6 +768,7 @@
                                 &do_shutdown, NULL);
 }
 
+
 /**
  *
  * The main function for gnunet-rest-service




reply via email to

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