removed malloc from curl_logger
[oweals/gnunet.git] / src / transport / plugin_transport_http.c
index c2f8a6091b1c32c65064007762981c72c701b2cb..6af53332acce02f0fa00ba67a232555718bd102c 100644 (file)
@@ -57,7 +57,7 @@
 #define DEBUG_MHD GNUNET_NO
 #define DEBUG_CONNECTIONS GNUNET_NO
 #define DEBUG_SESSION_SELECTION GNUNET_NO
-
+#define DEBUG_SCHEDULING GNUNET_NO
 #define CURL_TCP_NODELAY GNUNET_YES
 
 #define INBOUND GNUNET_NO
@@ -720,19 +720,14 @@ void mhd_logger (void * arg, const char * fmt, va_list ap)
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"MHD: %s \n", text);
 }
 
-/**
- * Callback called by MHD when a connection is terminated
- * @param cls closure
- * @param connection the terminated connection
- * @httpSessionCache the mhd session reference
- */
+
 static void mhd_termination_cb (void *cls, struct MHD_Connection * connection, void **httpSessionCache)
 {
   struct Session * ps = *httpSessionCache;
   if (ps == NULL)
     return;
   struct HTTP_PeerContext * pc = ps->peercontext;
-
+        
   if (connection==ps->recv_endpoint)
   {
 #if DEBUG_CONNECTIONS
@@ -1152,7 +1147,7 @@ http_server_daemon_prepare (struct Plugin *plugin , struct MHD_Daemon *daemon_ha
   if (haveto == MHD_YES)
     tv.value = (uint64_t) timeout;
   else
-    tv = GNUNET_TIME_UNIT_FOREVER_REL;
+    tv = GNUNET_TIME_UNIT_SECONDS;
   GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max);
   GNUNET_NETWORK_fdset_copy_native (wws, &ws, max);
   GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
@@ -1207,6 +1202,19 @@ static void http_server_daemon_v4_run (void *cls,
 {
   struct Plugin *plugin = cls;
 
+#if DEBUG_SCHEDULING
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_READ_READY\n");      
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");  
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");        
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");                 
+#endif              
+      
   GNUNET_assert(cls !=NULL);
   plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
 
@@ -1228,6 +1236,19 @@ static void http_server_daemon_v6_run (void *cls,
                              const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct Plugin *plugin = cls;
+  
+#if DEBUG_SCHEDULING  
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_READ_READY\n");
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))  
+     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");    
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))  
+     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n"); 
+#endif                                            
 
   GNUNET_assert(cls !=NULL);
   plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
@@ -1409,7 +1430,7 @@ static size_t curl_send_cb(void *stream, size_t size, size_t nmemb, void *ptr)
   if ( msg->pos == msg->size)
   {
 #if DEBUG_CONNECTIONS
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: Message with %u bytes sent, removing message from queue \n",ps, msg->pos);
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Connection %X: Message with %u bytes sent, removing message from queue \n",ps, msg->pos);
 #endif
     /* Calling transmit continuation  */
     if (NULL != ps->pending_msgs_tail->transmit_cont)
@@ -1701,9 +1722,10 @@ static int curl_schedule(struct Plugin *plugin)
  */
 int curl_logger (CURL * curl, curl_infotype type , char * data, size_t size , void * cls)
 {
-       char * text = GNUNET_malloc(size+2);
+
        if (type == CURLINFO_TEXT)
        {
+               char text[size+2];
                memcpy(text,data,size);
                if (text[size-1] == '\n')
                        text[size] = '\0';
@@ -1713,7 +1735,6 @@ int curl_logger (CURL * curl, curl_infotype type , char * data, size_t size , vo
                        text[size+1] = '\0';
                }
                GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"CURL: Connection %X - %s", cls, text);
-               GNUNET_free(text);
        }
        return 0;
 }
@@ -2623,15 +2644,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
          plugin->bind4_address->sin_family = AF_INET;
          plugin->bind4_address->sin_port = htons (port);
 
-         if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0)
+         if (plugin->bind_hostname!=NULL)
          {
-                 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
-                                                  component_name,
-                                                  _("Misconfigured address to bind to in configuration!\n"));
-                 GNUNET_free(plugin->bind4_address);
-                 GNUNET_free(plugin->bind_hostname);
-                 plugin->bind_hostname = NULL;
-                 plugin->bind4_address = NULL;
+                 if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0)
+                 {
+                         GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+                                                          component_name,
+                                                          _("Misconfigured address to bind to in configuration!\n"));
+                         GNUNET_free(plugin->bind4_address);
+                         GNUNET_free(plugin->bind_hostname);
+                         plugin->bind_hostname = NULL;
+                         plugin->bind4_address = NULL;
+                 }
          }
   }
 
@@ -2647,16 +2671,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
                  plugin->bind6_address = GNUNET_malloc(sizeof(struct sockaddr_in6));
                  plugin->bind6_address->sin6_family = AF_INET6;
                  plugin->bind6_address->sin6_port = htons (port);
-
-                 if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0)
+                 if (plugin->bind_hostname!=NULL)
                  {
-                         GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
-                                                          component_name,
-                                                          _("Misconfigured address to bind to in configuration!\n"));
-                         GNUNET_free(plugin->bind6_address);
-                         GNUNET_free(plugin->bind_hostname);
-                         plugin->bind_hostname = NULL;
-                         plugin->bind6_address = NULL;
+                         if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0)
+                         {
+                                 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+                                                                  component_name,
+                                                                  _("Misconfigured address to bind to in configuration!\n"));
+                                 GNUNET_free(plugin->bind6_address);
+                                 GNUNET_free(plugin->bind_hostname);
+                                 plugin->bind_hostname = NULL;
+                                 plugin->bind6_address = NULL;
+                         }
                  }
          }
   }