diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-03 15:45:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-03 15:45:26 +0000 |
commit | c14a26c3132b1913bb22a2f83a88cf30b8d66de3 (patch) | |
tree | 62b48ac6199930e4374cf62c07f64328eedb5478 /src | |
parent | 0de7931d8c76cccdfc98290c89fd91a502e5f012 (diff) | |
download | gnunet-c14a26c3132b1913bb22a2f83a88cf30b8d66de3.tar.gz gnunet-c14a26c3132b1913bb22a2f83a88cf30b8d66de3.zip |
-simplify logic, eleminate dead code
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 99 |
1 files changed, 61 insertions, 38 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 3c14bb5d9..947b64bef 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -41,6 +41,7 @@ http_clean_splitted (struct SplittedHTTPAddress *spa) | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | |||
44 | struct SplittedHTTPAddress * | 45 | struct SplittedHTTPAddress * |
45 | http_split_address (const char * addr) | 46 | http_split_address (const char * addr) |
46 | { | 47 | { |
@@ -362,36 +363,42 @@ http_common_dns_ip_lookup_cb (void *cls, | |||
362 | } | 363 | } |
363 | } | 364 | } |
364 | 365 | ||
366 | |||
365 | static int | 367 | static int |
366 | http_common_dns_ip_lookup (const char *name, const char *type, | 368 | http_common_dns_ip_lookup (const char *name, |
367 | struct SplittedHTTPAddress *saddr, | 369 | const char *type, |
368 | uint32_t options, | 370 | struct SplittedHTTPAddress *saddr, |
369 | struct GNUNET_TIME_Relative timeout, | 371 | uint32_t options, |
370 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | 372 | struct GNUNET_TIME_Relative timeout, |
373 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | ||
371 | { | 374 | { |
372 | struct PrettyPrinterContext *ppc; | 375 | struct PrettyPrinterContext *ppc; |
373 | ppc = GNUNET_new (struct PrettyPrinterContext); | ||
374 | 376 | ||
377 | ppc = GNUNET_new (struct PrettyPrinterContext); | ||
375 | ppc->sucess = GNUNET_NO; | 378 | ppc->sucess = GNUNET_NO; |
376 | ppc->saddr = saddr; | 379 | ppc->saddr = saddr; |
377 | ppc->asc = asc; | 380 | ppc->asc = asc; |
378 | ppc->asc_cls = asc_cls; | 381 | ppc->asc_cls = asc_cls; |
379 | ppc->plugin = GNUNET_strdup (type); | 382 | ppc->plugin = GNUNET_strdup (type); |
380 | ppc->options = options; | 383 | ppc->options = options; |
381 | 384 | ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name, | |
382 | ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name, AF_UNSPEC, timeout, | 385 | AF_UNSPEC, |
383 | &http_common_dns_ip_lookup_cb, ppc); | 386 | timeout, |
387 | &http_common_dns_ip_lookup_cb, | ||
388 | ppc); | ||
384 | if (NULL == ppc->resolver_handle) | 389 | if (NULL == ppc->resolver_handle) |
385 | { | 390 | { |
386 | GNUNET_free(ppc->plugin); | 391 | GNUNET_free(ppc->plugin); |
387 | GNUNET_free(ppc); | 392 | GNUNET_free(ppc); |
388 | return GNUNET_SYSERR; | 393 | return GNUNET_SYSERR; |
389 | } | 394 | } |
390 | 395 | GNUNET_CONTAINER_DLL_insert (dll_ppc_head, | |
391 | GNUNET_CONTAINER_DLL_insert(dll_ppc_head, dll_ppc_tail, ppc); | 396 | dll_ppc_tail, |
397 | ppc); | ||
392 | return GNUNET_OK; | 398 | return GNUNET_OK; |
393 | } | 399 | } |
394 | 400 | ||
401 | |||
395 | /** | 402 | /** |
396 | * Convert the transports address to a nice, human-readable | 403 | * Convert the transports address to a nice, human-readable |
397 | * format. | 404 | * format. |
@@ -470,7 +477,8 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
470 | goto handle_error; | 477 | goto handle_error; |
471 | } | 478 | } |
472 | 479 | ||
473 | if ((GNUNET_YES == numeric) && (GNUNET_YES == have_ip)) | 480 | if ( (GNUNET_YES == numeric) && |
481 | (GNUNET_YES == have_ip) ) | ||
474 | { | 482 | { |
475 | /* No lookup required */ | 483 | /* No lookup required */ |
476 | ret = http_common_plugin_address_to_string (type, address, addrlen); | 484 | ret = http_common_plugin_address_to_string (type, address, addrlen); |
@@ -480,7 +488,8 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
480 | GNUNET_free_non_null (sock_addr); | 488 | GNUNET_free_non_null (sock_addr); |
481 | return; | 489 | return; |
482 | } | 490 | } |
483 | else if ((GNUNET_YES == numeric) && (GNUNET_NO == have_ip)) | 491 | if ( (GNUNET_YES == numeric) && |
492 | (GNUNET_NO == have_ip) ) | ||
484 | { | 493 | { |
485 | /* Forward lookup */ | 494 | /* Forward lookup */ |
486 | if (GNUNET_SYSERR == | 495 | if (GNUNET_SYSERR == |
@@ -495,7 +504,8 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
495 | GNUNET_free_non_null (sock_addr); | 504 | GNUNET_free_non_null (sock_addr); |
496 | return; | 505 | return; |
497 | } | 506 | } |
498 | else if ((GNUNET_NO == numeric) && (GNUNET_YES == have_ip)) | 507 | if ( (GNUNET_NO == numeric) && |
508 | (GNUNET_YES == have_ip) ) | ||
499 | { | 509 | { |
500 | /* Reverse lookup */ | 510 | /* Reverse lookup */ |
501 | if (GNUNET_SYSERR == | 511 | if (GNUNET_SYSERR == |
@@ -515,7 +525,8 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
515 | GNUNET_free_non_null (sock_addr); | 525 | GNUNET_free_non_null (sock_addr); |
516 | return; | 526 | return; |
517 | } | 527 | } |
518 | else if ((GNUNET_NO == numeric) && (GNUNET_NO == have_ip)) | 528 | if ( (GNUNET_NO == numeric) && |
529 | (GNUNET_NO == have_ip) ) | ||
519 | { | 530 | { |
520 | /* No lookup required */ | 531 | /* No lookup required */ |
521 | ret = http_common_plugin_address_to_string (type, address, addrlen); | 532 | ret = http_common_plugin_address_to_string (type, address, addrlen); |
@@ -525,30 +536,27 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
525 | http_clean_splitted (saddr); | 536 | http_clean_splitted (saddr); |
526 | return; | 537 | return; |
527 | } | 538 | } |
528 | else | 539 | /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */ |
529 | { | 540 | GNUNET_break (0); |
530 | /* Error */ | 541 | goto handle_error; |
531 | goto handle_error; | ||
532 | } | ||
533 | GNUNET_free_non_null (sock_addr); | ||
534 | return; | ||
535 | 542 | ||
536 | handle_error: | 543 | handle_error: |
537 | /* Error */ | 544 | /* Report error */ |
538 | asc (asc_cls, NULL, GNUNET_SYSERR); | 545 | asc (asc_cls, NULL, GNUNET_SYSERR); |
539 | asc (asc_cls, NULL, GNUNET_OK); | 546 | asc (asc_cls, NULL, GNUNET_OK); |
540 | GNUNET_free_non_null (sock_addr); | 547 | GNUNET_free_non_null (sock_addr); |
541 | if (NULL != saddr) | 548 | if (NULL != saddr) |
542 | http_clean_splitted (saddr); | 549 | http_clean_splitted (saddr); |
543 | return; | ||
544 | |||
545 | } | 550 | } |
546 | 551 | ||
552 | |||
547 | /** | 553 | /** |
548 | * FIXME. | 554 | * FIXME. |
549 | */ | 555 | */ |
550 | const char * | 556 | const char * |
551 | http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | 557 | http_common_plugin_address_to_url (void *cls, |
558 | const void *addr, | ||
559 | size_t addrlen) | ||
552 | { | 560 | { |
553 | static char rbuf[1024]; | 561 | static char rbuf[1024]; |
554 | const struct HttpAddress *address = addr; | 562 | const struct HttpAddress *address = addr; |
@@ -557,27 +565,29 @@ http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | |||
557 | if (NULL == addr) | 565 | if (NULL == addr) |
558 | { | 566 | { |
559 | GNUNET_break(0); | 567 | GNUNET_break(0); |
560 | return NULL ; | 568 | return NULL; |
561 | } | 569 | } |
562 | if (0 >= addrlen) | 570 | if (0 >= addrlen) |
563 | { | 571 | { |
564 | GNUNET_break(0); | 572 | GNUNET_break(0); |
565 | return NULL ; | 573 | return NULL; |
566 | } | 574 | } |
567 | if (addrlen != http_common_address_get_size (address)) | 575 | if (addrlen != http_common_address_get_size (address)) |
568 | { | 576 | { |
569 | GNUNET_break(0); | 577 | GNUNET_break(0); |
570 | return NULL ; | 578 | return NULL; |
571 | } | 579 | } |
572 | addr_str = (char *) &address[1]; | 580 | addr_str = (char *) &address[1]; |
573 | |||
574 | if (addr_str[ntohl (address->urlen) - 1] != '\0') | 581 | if (addr_str[ntohl (address->urlen) - 1] != '\0') |
575 | return NULL ; | 582 | return NULL; |
576 | 583 | ||
577 | memcpy (rbuf, &address[1], ntohl (address->urlen)); | 584 | memcpy (rbuf, |
585 | &address[1], | ||
586 | ntohl (address->urlen)); | ||
578 | return rbuf; | 587 | return rbuf; |
579 | } | 588 | } |
580 | 589 | ||
590 | |||
581 | /** | 591 | /** |
582 | * Function called for a quick conversion of the binary address to | 592 | * Function called for a quick conversion of the binary address to |
583 | * a numeric address. Note that the caller must not free the | 593 | * a numeric address. Note that the caller must not free the |
@@ -590,8 +600,9 @@ http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | |||
590 | * @return string representing the same address | 600 | * @return string representing the same address |
591 | */ | 601 | */ |
592 | const char * | 602 | const char * |
593 | http_common_plugin_address_to_string (const char *plugin, const void *addr, | 603 | http_common_plugin_address_to_string (const char *plugin, |
594 | size_t addrlen) | 604 | const void *addr, |
605 | size_t addrlen) | ||
595 | { | 606 | { |
596 | static char rbuf[1024]; | 607 | static char rbuf[1024]; |
597 | const struct HttpAddress *address = addr; | 608 | const struct HttpAddress *address = addr; |
@@ -634,8 +645,11 @@ http_common_plugin_address_to_string (const char *plugin, const void *addr, | |||
634 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 645 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
635 | */ | 646 | */ |
636 | int | 647 | int |
637 | http_common_plugin_string_to_address (void *cls, const char *addr, | 648 | http_common_plugin_string_to_address (void *cls, |
638 | uint16_t addrlen, void **buf, size_t *added) | 649 | const char *addr, |
650 | uint16_t addrlen, | ||
651 | void **buf, | ||
652 | size_t *added) | ||
639 | { | 653 | { |
640 | struct HttpAddress *a; | 654 | struct HttpAddress *a; |
641 | char *address; | 655 | char *address; |
@@ -696,6 +710,7 @@ http_common_plugin_string_to_address (void *cls, const char *addr, | |||
696 | return GNUNET_OK; | 710 | return GNUNET_OK; |
697 | } | 711 | } |
698 | 712 | ||
713 | |||
699 | /** | 714 | /** |
700 | * Create a HTTP address from a socketaddr | 715 | * Create a HTTP address from a socketaddr |
701 | * | 716 | * |
@@ -706,13 +721,18 @@ http_common_plugin_string_to_address (void *cls, const char *addr, | |||
706 | */ | 721 | */ |
707 | struct HttpAddress * | 722 | struct HttpAddress * |
708 | http_common_address_from_socket (const char *protocol, | 723 | http_common_address_from_socket (const char *protocol, |
709 | const struct sockaddr *addr, socklen_t addrlen) | 724 | const struct sockaddr *addr, |
725 | socklen_t addrlen) | ||
710 | { | 726 | { |
711 | struct HttpAddress *address = NULL; | 727 | struct HttpAddress *address = NULL; |
712 | char *res; | 728 | char *res; |
713 | size_t len; | 729 | size_t len; |
714 | 730 | ||
715 | GNUNET_asprintf (&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); | 731 | GNUNET_asprintf (&res, |
732 | "%s://%s", | ||
733 | protocol, | ||
734 | GNUNET_a2s (addr, | ||
735 | addrlen)); | ||
716 | len = strlen (res) + 1; | 736 | len = strlen (res) + 1; |
717 | address = GNUNET_malloc (sizeof (struct HttpAddress) + len); | 737 | address = GNUNET_malloc (sizeof (struct HttpAddress) + len); |
718 | address->options = htonl (HTTP_OPTIONS_NONE); | 738 | address->options = htonl (HTTP_OPTIONS_NONE); |
@@ -722,6 +742,7 @@ http_common_address_from_socket (const char *protocol, | |||
722 | return address; | 742 | return address; |
723 | } | 743 | } |
724 | 744 | ||
745 | |||
725 | /** | 746 | /** |
726 | * Create a socketaddr from a HTTP address | 747 | * Create a socketaddr from a HTTP address |
727 | * | 748 | * |
@@ -809,6 +830,7 @@ http_common_socket_from_address (const void *addr, | |||
809 | return (struct sockaddr *) s; | 830 | return (struct sockaddr *) s; |
810 | } | 831 | } |
811 | 832 | ||
833 | |||
812 | /** | 834 | /** |
813 | * Get the length of an address | 835 | * Get the length of an address |
814 | * | 836 | * |
@@ -821,6 +843,7 @@ http_common_address_get_size (const struct HttpAddress * addr) | |||
821 | return sizeof(struct HttpAddress) + ntohl (addr->urlen); | 843 | return sizeof(struct HttpAddress) + ntohl (addr->urlen); |
822 | } | 844 | } |
823 | 845 | ||
846 | |||
824 | /** | 847 | /** |
825 | * Compare addr1 to addr2 | 848 | * Compare addr1 to addr2 |
826 | * | 849 | * |