aboutsummaryrefslogtreecommitdiff
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)
downloadgnunet-f62ff9256f67cec85b84273a77c7393e4a224399.tar.gz
gnunet-f62ff9256f67cec85b84273a77c7393e4a224399.zip
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
37 int port; 37 int port;
38}; 38};
39 39
40static void
41http_clean_splitted (struct SplittedHTTPAddress *spa)
42{
43 if (NULL != spa)
44 {
45 GNUNET_free_non_null (spa->protocol);
46 GNUNET_free_non_null (spa->host);
47 GNUNET_free_non_null (spa->path);
48 GNUNET_free_non_null (spa);
49 }
50}
51
40struct SplittedHTTPAddress * 52struct SplittedHTTPAddress *
41http_split_address (const char * addr) 53http_split_address (const char * addr)
42{ 54{
@@ -289,11 +301,10 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad
289struct sockaddr * 301struct sockaddr *
290http_common_socket_from_address (const void *addr, size_t addrlen, int *res) 302http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
291{ 303{
304 struct SplittedHTTPAddress * spa;
292 struct sockaddr_storage *s; 305 struct sockaddr_storage *s;
293 char *addrs;
294 char *addrs_org;
295 char *addrs_end;
296 (*res) = GNUNET_SYSERR; 306 (*res) = GNUNET_SYSERR;
307 char * to_conv;
297 308
298 if (NULL == addr) 309 if (NULL == addr)
299 { 310 {
@@ -311,50 +322,35 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
311 return NULL; 322 return NULL;
312 } 323 }
313 324
314 addrs_org = strdup ((char *) addr); 325 spa = http_split_address (addr);
315 addrs = strstr (addrs_org , "://"); 326 if (NULL == spa)
316 if (NULL == addrs)
317 {
318 GNUNET_break (0);
319 GNUNET_free (addrs_org);
320 return NULL;
321 }
322
323 if (strlen (addrs) < 3)
324 { 327 {
325 GNUNET_break (0); 328 (*res) = GNUNET_SYSERR;
326 GNUNET_free (addrs_org); 329 return NULL;
327 return NULL;
328 } 330 }
329 331
330 addrs += 3;
331
332 addrs_end = strchr (addrs, '/');
333 if (NULL != addrs_end)
334 addrs[strlen (addrs) - strlen(addrs_end)] = '\0';
335
336 s = GNUNET_malloc (sizeof (struct sockaddr_storage)); 332 s = GNUNET_malloc (sizeof (struct sockaddr_storage));
337 if (GNUNET_SYSERR == GNUNET_STRINGS_to_address_ip (addrs, strlen(addrs), s)) 333 GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port);
334 if (GNUNET_SYSERR == GNUNET_STRINGS_to_address_ip (to_conv, strlen(to_conv), s))
338 { 335 {
339 /* could be a hostname */ 336 /* could be a hostname */
340 GNUNET_free (s); 337 GNUNET_free (s);
341 GNUNET_free (addrs_org);
342 (*res) = GNUNET_NO; 338 (*res) = GNUNET_NO;
343 return NULL; 339 s = NULL;
340 }
341 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
342 {
343
344 GNUNET_free (s);
345 (*res) = GNUNET_SYSERR;
346 s = NULL;
344 } 347 }
345 else 348 else
346 { 349 {
347 if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) 350 (*res) = GNUNET_YES;
348 {
349 GNUNET_break (0);
350 GNUNET_free (s);
351 GNUNET_free (addrs_org);
352 (*res) = GNUNET_SYSERR;
353 return NULL;
354 }
355 } 351 }
356 (*res) = GNUNET_YES; 352 http_clean_splitted (spa);
357 GNUNET_free (addrs_org); 353 GNUNET_free (to_conv);
358 return (struct sockaddr *) s; 354 return (struct sockaddr *) s;
359} 355}
360 356