-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / plugin_transport_http.c
index ec89393cf6b0ae6bca532ebdf1d04ec6915c403b..076bef13019dccf7899aa2f7360e825bf9e790cd 100644 (file)
@@ -350,45 +350,56 @@ int http_string_to_address (void *cls,
   struct sockaddr_in6 addr_6;
   struct IPv4HttpAddress * http_4addr;
   struct IPv6HttpAddress * http_6addr;
-  GNUNET_break (0);
   if ((addr == NULL) || (addrlen == 0) || (buf == NULL))
     return GNUNET_SYSERR;
 
   /* protocoll + "://" + ":" */
-  if (addrlen <= strlen (protocol) + 4);
+  if (addrlen <= (strlen (protocol) + 4))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     "Invalid address string `%s' to convert to address\n",
+                     addr);
+    GNUNET_break (0);
     return GNUNET_SYSERR;
+  }
 
-  if (NULL == (addr = strstr(addr_str, "://")))
-      return GNUNET_SYSERR;
-
+  if (NULL == (addr_str = strstr(addr, "://")))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Invalid address string `%s' to convert to address\n",
+               addr);
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
   addr_str = &addr_str[3];
 
-  if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr, strlen(addr_str), &addr_4))
+  if (addr_str[strlen(addr_str)-1] == '/')
+    addr_str[strlen(addr_str)-1] = '\0';
+
+  if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr_str, strlen(addr_str), &addr_4))
   {
     http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
-    http_4addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
     http_4addr->u4_port = addr_4.sin_port;
     http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr;
-
     (*buf) = http_4addr;
     (*added) = sizeof (struct IPv4HttpAddress);
-    GNUNET_break (0);
     return GNUNET_OK;
   }
-  else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr, strlen(addr_str), &addr_6))
+  else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
   {
     http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
     http_6addr->u6_port = addr_6.sin6_port;
     http_6addr->ipv6_addr = addr_6.sin6_addr;
-
     (*buf) = http_6addr;
     (*added) = sizeof (struct IPv6HttpAddress);
-    GNUNET_break (0);
     return GNUNET_OK;
-
   }
   else
   {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+                     "Invalid address string `%s' to convert to address\n",
+                     addr);
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
 }
@@ -873,8 +884,7 @@ find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addr
   default:
     return NULL;
   }
-
-
+  return NULL;
 }
 
 static void
@@ -900,17 +910,15 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
 
       GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
                                    plugin->ipv4_addr_tail, w_t4);
-    }
-#if DEBUG_HTTP
+
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to add IPv4 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t4->addr,
                                                     sizeof (struct
                                                             IPv4HttpAddress)));
-#endif
     plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
                                  sizeof (struct IPv4HttpAddress));
-
+    }
     break;
   case AF_INET6:
     w_t6 = find_address (plugin, addr, addrlen);
@@ -923,16 +931,15 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
 
       GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
                                    plugin->ipv6_addr_tail, w_t6);
-    }
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to add IPv6 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                     sizeof (struct
                                                             IPv6HttpAddress)));
-#endif
-    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
+      plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                  sizeof (struct IPv6HttpAddress));
+    }
     break;
   default:
     return;
@@ -954,15 +961,15 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
   {
   case AF_INET:
     w_t4 = find_address (plugin, addr, addrlen);
+    if (w_t4 == NULL)
       return;
 
-#if DEBUG_HTTP
+
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to remove IPv4 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t4->addr,
                                                     sizeof (struct
                                                             IPv4HttpAddress)));
-#endif
     plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
                                  sizeof (struct IPv4HttpAddress));
 
@@ -974,13 +981,13 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
     w_t6 = find_address (plugin, addr, addrlen);
     if (w_t6 == NULL)
       return;
-#if DEBUG_HTTP
+
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to remove IPv6 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                     sizeof (struct
                                                             IPv6HttpAddress)));
-#endif
+
     plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                  sizeof (struct IPv6HttpAddress));
 
@@ -1008,15 +1015,13 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
                        socklen_t addrlen)
 {
   GNUNET_assert (cls != NULL);
-#if DEBUG_HTTP
   struct Plugin *plugin = cls;
-#endif
-#if DEBUG_HTTP
+
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "NPMC called %s to address `%s'\n",
                    (add_remove == GNUNET_NO) ? "remove" : "add",
                    GNUNET_a2s (addr, addrlen));
-#endif
+
   switch (add_remove)
   {
   case GNUNET_YES:
@@ -1449,7 +1454,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
     api->cls = NULL;
     api->address_pretty_printer = &http_plugin_address_pretty_printer;
     api->address_to_string = &http_plugin_address_to_string;
-    api->string_to_address = NULL; // FIXME!
+    api->string_to_address = &http_string_to_address;
     return api;
   }