summaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_common.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-28 14:51:35 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-28 14:51:35 +0000
commit0d3fc76af81e705237ab7ccebe6d5c3c71d1757f (patch)
tree0bfe097d5cf246871cdcd0c1458e3c18b0c7c7b2 /src/transport/plugin_transport_http_common.c
parent5800c4bf0fec9d1c48be72570b8af5ed3ec29e2f (diff)
changes
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r--src/transport/plugin_transport_http_common.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index f13884507..e71b16e93 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -144,6 +144,90 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad
}
/**
+ * Create a socketaddr from a HTTP address
+ *
+ * @param protocol protocol
+ * @param addr sockaddr * address
+ * @param addrlen length of the address
+ * @param res the result:
+ * GNUNET_SYSERR, invalid input,
+ * GNUNET_YES: could convert to ip,
+ * GNUNET_NO: valid input but could not convert to ip (hostname?)
+ * @return the string
+ */
+struct sockaddr *
+http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
+{
+ struct sockaddr_storage *s;
+ char *addrs;
+ char *addrs_org;
+ char *addrs_end;
+ (*res) = GNUNET_SYSERR;
+
+ if (NULL == addr)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (0 >= addrlen)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (((char *) addr)[addrlen-1] != '\0')
+ {
+ GNUNET_break (0);
+ 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)
+ {
+ GNUNET_break (0);
+ GNUNET_free (addrs_org);
+ 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))
+ {
+ /* could be a hostname */
+ GNUNET_free (s);
+ GNUNET_free (addrs_org);
+ (*res) = GNUNET_NO;
+ return 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;
+ GNUNET_free (addrs_org);
+ return (struct sockaddr *) s;
+}
+
+/**
* Get the length of an address
*
* @param addr address