aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-04-12 14:29:58 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-04-12 14:29:58 +0000
commit0f6e3bcd617ea997060756a9c4167806b137f440 (patch)
tree7c914e524deae4bdb588d1305a7a5a55171ead44 /src/transport/plugin_transport_http.c
parenta28a4579c881fca8f30a9c066dc72df07dc9552f (diff)
downloadgnunet-0f6e3bcd617ea997060756a9c4167806b137f440.tar.gz
gnunet-0f6e3bcd617ea997060756a9c4167806b137f440.zip
- fixed string to address parsing
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 2518dac5c..076bef130 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -350,45 +350,56 @@ int http_string_to_address (void *cls,
350 struct sockaddr_in6 addr_6; 350 struct sockaddr_in6 addr_6;
351 struct IPv4HttpAddress * http_4addr; 351 struct IPv4HttpAddress * http_4addr;
352 struct IPv6HttpAddress * http_6addr; 352 struct IPv6HttpAddress * http_6addr;
353 GNUNET_break (0);
354 if ((addr == NULL) || (addrlen == 0) || (buf == NULL)) 353 if ((addr == NULL) || (addrlen == 0) || (buf == NULL))
355 return GNUNET_SYSERR; 354 return GNUNET_SYSERR;
356 355
357 /* protocoll + "://" + ":" */ 356 /* protocoll + "://" + ":" */
358 if (addrlen <= strlen (protocol) + 4); 357 if (addrlen <= (strlen (protocol) + 4))
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
360 "Invalid address string `%s' to convert to address\n",
361 addr);
362 GNUNET_break (0);
359 return GNUNET_SYSERR; 363 return GNUNET_SYSERR;
364 }
360 365
361 if (NULL == (addr = strstr(addr_str, "://"))) 366 if (NULL == (addr_str = strstr(addr, "://")))
362 return GNUNET_SYSERR; 367 {
363 368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
369 "Invalid address string `%s' to convert to address\n",
370 addr);
371 GNUNET_break (0);
372 return GNUNET_SYSERR;
373 }
364 addr_str = &addr_str[3]; 374 addr_str = &addr_str[3];
365 375
366 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr, strlen(addr_str), &addr_4)) 376 if (addr_str[strlen(addr_str)-1] == '/')
377 addr_str[strlen(addr_str)-1] = '\0';
378
379 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr_str, strlen(addr_str), &addr_4))
367 { 380 {
368 http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress)); 381 http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
369 http_4addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
370 http_4addr->u4_port = addr_4.sin_port; 382 http_4addr->u4_port = addr_4.sin_port;
371 http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr; 383 http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr;
372
373 (*buf) = http_4addr; 384 (*buf) = http_4addr;
374 (*added) = sizeof (struct IPv4HttpAddress); 385 (*added) = sizeof (struct IPv4HttpAddress);
375 GNUNET_break (0);
376 return GNUNET_OK; 386 return GNUNET_OK;
377 } 387 }
378 else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr, strlen(addr_str), &addr_6)) 388 else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
379 { 389 {
380 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress)); 390 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
381 http_6addr->u6_port = addr_6.sin6_port; 391 http_6addr->u6_port = addr_6.sin6_port;
382 http_6addr->ipv6_addr = addr_6.sin6_addr; 392 http_6addr->ipv6_addr = addr_6.sin6_addr;
383
384 (*buf) = http_6addr; 393 (*buf) = http_6addr;
385 (*added) = sizeof (struct IPv6HttpAddress); 394 (*added) = sizeof (struct IPv6HttpAddress);
386 GNUNET_break (0);
387 return GNUNET_OK; 395 return GNUNET_OK;
388
389 } 396 }
390 else 397 else
391 { 398 {
399 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
400 "Invalid address string `%s' to convert to address\n",
401 addr);
402 GNUNET_break (0);
392 return GNUNET_SYSERR; 403 return GNUNET_SYSERR;
393 } 404 }
394} 405}
@@ -1443,7 +1454,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1443 api->cls = NULL; 1454 api->cls = NULL;
1444 api->address_pretty_printer = &http_plugin_address_pretty_printer; 1455 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1445 api->address_to_string = &http_plugin_address_to_string; 1456 api->address_to_string = &http_plugin_address_to_string;
1446 api->string_to_address = NULL; // FIXME! 1457 api->string_to_address = &http_string_to_address;
1447 return api; 1458 return api;
1448 } 1459 }
1449 1460