diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-02 19:38:20 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-02 19:38:20 +0000 |
commit | 78ef40f28e08ef786292429a4257fb82cf244635 (patch) | |
tree | 714b2a35361aa38b02fd98d37b39edda573301ed /src/peerinfo-tool | |
parent | 78bda4c51a6c27a7656273831e7c1bdbdfe0aad7 (diff) | |
download | gnunet-78ef40f28e08ef786292429a4257fb82cf244635.tar.gz gnunet-78ef40f28e08ef786292429a4257fb82cf244635.zip |
Diffstat (limited to 'src/peerinfo-tool')
-rw-r--r-- | src/peerinfo-tool/gnunet-peerinfo.c | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 2c26c4599..8bb7392d9 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -228,6 +228,42 @@ state_machine (void *cls, | |||
228 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 228 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
229 | 229 | ||
230 | 230 | ||
231 | |||
232 | /** | ||
233 | * Replace all characters in the input 'in' according | ||
234 | * to the mapping. The mapping says to map each character | ||
235 | * in 'oldchars' to the corresponding character (by offset) | ||
236 | * in 'newchars'. | ||
237 | * | ||
238 | * @param in input string to remap | ||
239 | * @param oldchars characters to replace | ||
240 | * @param newchars replacement characters, must have same length as 'oldchars' | ||
241 | * @return copy of string with replacement applied. | ||
242 | */ | ||
243 | static char * | ||
244 | map_characters (const char *in, | ||
245 | const char *oldchars, | ||
246 | const char *newchars) | ||
247 | { | ||
248 | char *ret; | ||
249 | const char *off; | ||
250 | size_t i; | ||
251 | |||
252 | GNUNET_assert (strlen (oldchars) == strlen (newchars)); | ||
253 | ret = GNUNET_strdup (in); | ||
254 | i = 0; | ||
255 | while (ret[i] != '\0') | ||
256 | { | ||
257 | off = strchr (oldchars, ret[i]); | ||
258 | if (NULL != off) | ||
259 | ret[i] = newchars[off - oldchars]; | ||
260 | i++; | ||
261 | } | ||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | |||
266 | |||
231 | /* ********************* 'get_info' ******************* */ | 267 | /* ********************* 'get_info' ******************* */ |
232 | 268 | ||
233 | /** | 269 | /** |
@@ -412,6 +448,7 @@ compose_uri (void *cls, const struct GNUNET_HELLO_Address *address, | |||
412 | struct GetUriContext *guc = cls; | 448 | struct GetUriContext *guc = cls; |
413 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 449 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
414 | const char *addr; | 450 | const char *addr; |
451 | char *uri_addr; | ||
415 | char *ret; | 452 | char *ret; |
416 | char tbuf[16]; | 453 | char tbuf[16]; |
417 | struct tm *t; | 454 | struct tm *t; |
@@ -433,6 +470,9 @@ compose_uri (void *cls, const struct GNUNET_HELLO_Address *address, | |||
433 | addr = papi->address_to_string (papi->cls, address->address, address->address_length); | 470 | addr = papi->address_to_string (papi->cls, address->address, address->address_length); |
434 | if ( (addr == NULL) || (strlen(addr) == 0) ) | 471 | if ( (addr == NULL) || (strlen(addr) == 0) ) |
435 | return GNUNET_OK; | 472 | return GNUNET_OK; |
473 | /* For URIs we use '(' and ')' instead of '[' and ']' as brackets are reserved | ||
474 | characters in URIs */ | ||
475 | uri_addr = map_characters (addr, "[]", "()"); | ||
436 | seconds = expiration.abs_value / 1000; | 476 | seconds = expiration.abs_value / 1000; |
437 | t = gmtime (&seconds); | 477 | t = gmtime (&seconds); |
438 | GNUNET_assert (0 != strftime (tbuf, sizeof (tbuf), | 478 | GNUNET_assert (0 != strftime (tbuf, sizeof (tbuf), |
@@ -443,7 +483,8 @@ compose_uri (void *cls, const struct GNUNET_HELLO_Address *address, | |||
443 | guc->uri, | 483 | guc->uri, |
444 | tbuf, | 484 | tbuf, |
445 | address->transport_name, | 485 | address->transport_name, |
446 | addr); | 486 | uri_addr); |
487 | GNUNET_free (uri_addr); | ||
447 | GNUNET_free (guc->uri); | 488 | GNUNET_free (guc->uri); |
448 | guc->uri = ret; | 489 | guc->uri = ret; |
449 | return GNUNET_OK; | 490 | return GNUNET_OK; |
@@ -501,7 +542,8 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
501 | struct GNUNET_PEERINFO_HelloAddressParsingContext *ctx = cls; | 542 | struct GNUNET_PEERINFO_HelloAddressParsingContext *ctx = cls; |
502 | const char *tname; | 543 | const char *tname; |
503 | const char *address; | 544 | const char *address; |
504 | char * address_terminated; | 545 | char *uri_address; |
546 | char *plugin_address; | ||
505 | const char *end; | 547 | const char *end; |
506 | char *plugin_name; | 548 | char *plugin_name; |
507 | struct tm expiration_time; | 549 | struct tm expiration_time; |
@@ -512,6 +554,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
512 | size_t addr_len; | 554 | size_t addr_len; |
513 | struct GNUNET_HELLO_Address haddr; | 555 | struct GNUNET_HELLO_Address haddr; |
514 | size_t ret; | 556 | size_t ret; |
557 | |||
515 | if (NULL == ctx->pos) | 558 | if (NULL == ctx->pos) |
516 | return 0; | 559 | return 0; |
517 | if ('!' != ctx->pos[0]) | 560 | if ('!' != ctx->pos[0]) |
@@ -564,23 +607,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
564 | } | 607 | } |
565 | address++; | 608 | address++; |
566 | end = strchr (address, (int) '!'); | 609 | end = strchr (address, (int) '!'); |
567 | if (NULL == end) | 610 | ctx->pos = end; |
568 | { | ||
569 | /* Last address */ | ||
570 | end = address + strlen (address); | ||
571 | address_terminated = strdup (address); | ||
572 | ctx->pos = NULL; | ||
573 | } | ||
574 | else | ||
575 | { | ||
576 | /* More addresses follow */ | ||
577 | size_t len = (end - address); | ||
578 | address_terminated = GNUNET_malloc (len + 1); | ||
579 | memcpy (address_terminated, address, len); | ||
580 | address_terminated[len] = '\0'; | ||
581 | ctx->pos = end; | ||
582 | |||
583 | } | ||
584 | plugin_name = GNUNET_strndup (tname, address - (tname+1)); | 611 | plugin_name = GNUNET_strndup (tname, address - (tname+1)); |
585 | papi = GPI_plugins_find (plugin_name); | 612 | papi = GPI_plugins_find (plugin_name); |
586 | if (NULL == papi) | 613 | if (NULL == papi) |
@@ -593,9 +620,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
593 | _("Plugin `%s' not found\n"), | 620 | _("Plugin `%s' not found\n"), |
594 | plugin_name); | 621 | plugin_name); |
595 | GNUNET_free (plugin_name); | 622 | GNUNET_free (plugin_name); |
596 | |||
597 | GNUNET_break (0); | 623 | GNUNET_break (0); |
598 | GNUNET_free (address_terminated); | ||
599 | return 0; | 624 | return 0; |
600 | } | 625 | } |
601 | if (NULL == papi->string_to_address) | 626 | if (NULL == papi->string_to_address) |
@@ -604,25 +629,29 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
604 | _("Plugin `%s' does not support URIs yet\n"), | 629 | _("Plugin `%s' does not support URIs yet\n"), |
605 | plugin_name); | 630 | plugin_name); |
606 | GNUNET_free (plugin_name); | 631 | GNUNET_free (plugin_name); |
607 | GNUNET_free (address_terminated); | ||
608 | GNUNET_break (0); | 632 | GNUNET_break (0); |
609 | return 0; | 633 | return 0; |
610 | } | 634 | } |
611 | 635 | uri_address = GNUNET_strndup (address, end - address); | |
636 | /* For URIs we use '(' and ')' instead of '[' and ']' as brackets are reserved | ||
637 | characters in URIs; need to convert back to '[]' for the plugin */ | ||
638 | plugin_address = map_characters (uri_address, "()", "[]"); | ||
639 | GNUNET_free (uri_address); | ||
612 | if (GNUNET_OK != | 640 | if (GNUNET_OK != |
613 | papi->string_to_address (papi->cls, | 641 | papi->string_to_address (papi->cls, |
614 | address_terminated, | 642 | plugin_address, |
615 | strlen (address_terminated) + 1, | 643 | strlen (plugin_address), |
616 | &addr, | 644 | &addr, |
617 | &addr_len)) | 645 | &addr_len)) |
618 | { | 646 | { |
619 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 647 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
620 | _("Failed to parse `%s'\n"), | 648 | _("Failed to parse `%s'\n"), |
621 | address_terminated); | 649 | plugin_address); |
622 | GNUNET_free (plugin_name); | 650 | GNUNET_free (plugin_name); |
623 | GNUNET_free (address_terminated); | 651 | GNUNET_free (plugin_address); |
624 | return 0; | 652 | return 0; |
625 | } | 653 | } |
654 | GNUNET_free (plugin_address); | ||
626 | /* address.peer is unset - not used by add_address() */ | 655 | /* address.peer is unset - not used by add_address() */ |
627 | haddr.address_length = addr_len; | 656 | haddr.address_length = addr_len; |
628 | haddr.address = addr; | 657 | haddr.address = addr; |
@@ -630,7 +659,6 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
630 | ret = GNUNET_HELLO_add_address (&haddr, expire, buffer, max); | 659 | ret = GNUNET_HELLO_add_address (&haddr, expire, buffer, max); |
631 | GNUNET_free (addr); | 660 | GNUNET_free (addr); |
632 | GNUNET_free (plugin_name); | 661 | GNUNET_free (plugin_name); |
633 | GNUNET_free (address_terminated); | ||
634 | return ret; | 662 | return ret; |
635 | } | 663 | } |
636 | 664 | ||