diff options
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 3 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 68 |
2 files changed, 34 insertions, 37 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index d19d0c999..e7bf70462 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -1450,11 +1450,12 @@ http_client_plugin_get_session (void *cls, | |||
1450 | { | 1450 | { |
1451 | salen = sizeof (struct sockaddr_in); | 1451 | salen = sizeof (struct sockaddr_in); |
1452 | } | 1452 | } |
1453 | else if (AF_INET == sa->sa_family) | 1453 | else if (AF_INET6 == sa->sa_family) |
1454 | { | 1454 | { |
1455 | salen = sizeof (struct sockaddr_in6); | 1455 | salen = sizeof (struct sockaddr_in6); |
1456 | } | 1456 | } |
1457 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); | 1457 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); |
1458 | //fprintf (stderr, "Address %s is in %s\n", GNUNET_a2s (sa,salen), GNUNET_ATS_print_network_type(ntohl(ats.value))); | ||
1458 | GNUNET_free (sa); | 1459 | GNUNET_free (sa); |
1459 | } | 1460 | } |
1460 | else if (GNUNET_NO == res) | 1461 | else if (GNUNET_NO == res) |
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 | ||
40 | static void | ||
41 | http_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 | |||
40 | struct SplittedHTTPAddress * | 52 | struct SplittedHTTPAddress * |
41 | http_split_address (const char * addr) | 53 | http_split_address (const char * addr) |
42 | { | 54 | { |
@@ -289,11 +301,10 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad | |||
289 | struct sockaddr * | 301 | struct sockaddr * |
290 | http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | 302 | http_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 | ||