summaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_common.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-01-18 13:49:00 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-01-18 13:49:00 +0000
commitf62ff9256f67cec85b84273a77c7393e4a224399 (patch)
treeb86e70517d9c9bb0c397594796588538748b08c4 /src/transport/plugin_transport_http_common.c
parentaafe8b7d1b55adb2f4711a59d80676f1a1c85d65 (diff)
changes
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r--src/transport/plugin_transport_http_common.c68
1 files changed, 32 insertions, 36 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 13ac3d043..bf983302e 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -37,6 +37,18 @@ 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);
+ }
+}
+
struct SplittedHTTPAddress *
http_split_address (const char * addr)
{
@@ -289,11 +301,10 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad
struct sockaddr *
http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
{
+ struct SplittedHTTPAddress * spa;
struct sockaddr_storage *s;
- char *addrs;
- char *addrs_org;
- char *addrs_end;
(*res) = GNUNET_SYSERR;
+ char * to_conv;
if (NULL == addr)
{
@@ -311,50 +322,35 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
return NULL;
}
- addrs_org = strdup ((char *) addr);
- addrs = strstr (addrs_org , "://");
- if (NULL == addrs)
- {
- GNUNET_break (0);
- GNUNET_free (addrs_org);
- return NULL;
- }
-
- if (strlen (addrs) < 3)
+ spa = http_split_address (addr);
+ if (NULL == spa)
{
- GNUNET_break (0);
- GNUNET_free (addrs_org);
- return NULL;
+ (*res) = GNUNET_SYSERR;
+ return NULL;
}
- addrs += 3;
-
- addrs_end = strchr (addrs, '/');
- if (NULL != addrs_end)
- addrs[strlen (addrs) - strlen(addrs_end)] = '\0';
-
s = GNUNET_malloc (sizeof (struct sockaddr_storage));
- if (GNUNET_SYSERR == GNUNET_STRINGS_to_address_ip (addrs, strlen(addrs), s))
+ GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port);
+ if (GNUNET_SYSERR == GNUNET_STRINGS_to_address_ip (to_conv, strlen(to_conv), s))
{
/* could be a hostname */
- GNUNET_free (s);
- GNUNET_free (addrs_org);
+ GNUNET_free (s);
(*res) = GNUNET_NO;
- return NULL;
+ s = NULL;
+ }
+ else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
+ {
+
+ GNUNET_free (s);
+ (*res) = GNUNET_SYSERR;
+ s = NULL;
}
else
{
- if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
- {
- GNUNET_break (0);
- GNUNET_free (s);
- GNUNET_free (addrs_org);
- (*res) = GNUNET_SYSERR;
- return NULL;
- }
+ (*res) = GNUNET_YES;
}
- (*res) = GNUNET_YES;
- GNUNET_free (addrs_org);
+ http_clean_splitted (spa);
+ GNUNET_free (to_conv);
return (struct sockaddr *) s;
}