-doxygen
[oweals/gnunet.git] / src / transport / plugin_transport_http_common.c
index 5830ab63c75a5189d4228e4192152dbbd75593e9..de4cb9a26e97c29022fedf001da1739746e29fe0 100644 (file)
@@ -23,9 +23,8 @@
  * @brief functionality shared by http client and server transport service plugin
  * @author Matthias Wachs
  */
-
 #include "platform.h"
-#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_transport_plugin.h"
 #include "plugin_transport_http_common.h"
 
@@ -37,16 +36,17 @@ struct SplittedHTTPAddress
        int port;
 };
 
+
 static void
 http_clean_splitted (struct SplittedHTTPAddress *spa)
 {
-       if (NULL != spa)
-       {
-                       GNUNET_free_non_null (spa->protocol);
-                       GNUNET_free_non_null (spa->host);
-                       GNUNET_free_non_null (spa->path);
-                       GNUNET_free_non_null (spa);
-       }
+  if (NULL != spa)
+  {
+    GNUNET_free_non_null (spa->protocol);
+    GNUNET_free_non_null (spa->host);
+    GNUNET_free_non_null (spa->path);
+    GNUNET_free_non_null (spa);
+  }
 }
 
 struct SplittedHTTPAddress *
@@ -253,6 +253,7 @@ http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen)
  * to override the address again.
  *
  * @param cls closure
+ * @param plugin the plugin
  * @param addr binary address
  * @param addrlen length of the address
  * @return string representing the same address
@@ -265,19 +266,19 @@ http_common_plugin_address_to_string (void *cls, char *plugin, const void *addr,
   const char * addr_str;
   char *res;
 
+  GNUNET_assert (NULL != plugin);
 
   if (NULL == addr)
       return NULL;
-  if (0 >= addrlen)
-    return NULL;
+  if (0 == addrlen)
+    return TRANSPORT_SESSION_INBOUND_STRING;
   if (addrlen != http_common_address_get_size (address))
        return NULL;
   addr_str = (char *) &address[1];
 
   if (addr_str[ntohl(address->urlen) -1] != '\0')
     return NULL;
-
-  GNUNET_asprintf (&res, "%s.%u.%s", plugin, address->options, &address[1]);
+  GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl(address->options), &address[1]);
   if (strlen(res) + 1 < 500)
   {
        memcpy (rbuf, res, strlen(res) + 1);
@@ -319,7 +320,6 @@ http_common_plugin_string_to_address (void *cls,
   address = NULL;
   plugin = NULL;
   optionstr = NULL;
-  options = 0;
   if ((NULL == addr) || (addrlen == 0))
   {
     GNUNET_break (0);
@@ -345,7 +345,7 @@ http_common_plugin_string_to_address (void *cls,
   }
   optionstr[0] = '\0';
   optionstr ++;
-  options = atol (optionstr);
+  options = atol (optionstr); /* 0 on conversion error, that's ok */
   address = strchr (optionstr, '.');
   if (NULL == address)
   {
@@ -414,33 +414,40 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
   struct sockaddr_storage *s;
   (*res) = GNUNET_SYSERR;
   char * to_conv;
+  size_t urlen;
 
   ha = (const struct HttpAddress *) addr;
   if (NULL == addr)
-       {
-               GNUNET_break (0);
-               return NULL;
-       }
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
   if (0 >= addrlen)
-       {
-               GNUNET_break (0);
-               return NULL;
-       }
-  if (addrlen < sizeof (struct HttpAddress))
-       {
-               GNUNET_break (0);
-               return NULL;
-       }
-  if (addrlen < sizeof (struct HttpAddress) + ntohl (ha->urlen))
-       {
-               /* This is a legacy addresses */
-               return NULL;
-       }
-  if (((char *) addr)[addrlen-1] != '\0')
-       {
-               GNUNET_break (0);
-               return NULL;
-       }
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+  if (addrlen < sizeof(struct HttpAddress))
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+  urlen = ntohl (ha->urlen);
+  if (sizeof(struct HttpAddress) + urlen != addrlen)
+  {
+    /* This is a legacy addresses */
+    return NULL ;
+  }
+  if (addrlen < sizeof(struct HttpAddress) + urlen)
+  {
+    /* This is a legacy addresses */
+    return NULL ;
+  }
+  if (((char *) addr)[addrlen - 1] != '\0')
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
   spa = http_split_address ((const char *) &ha[1]);
   if (NULL == spa)
   {