aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-07-15 11:15:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-07-15 11:15:28 +0000
commitc6becd402caf853f1cebe637bfb4664be4cba9bd (patch)
tree6aa5106b5f834b719897d6a5ad2550d93bba9dc8 /src/transport/plugin_transport_http.c
parente0ba76a9eccc829ffad2eb770be5e66422ac785f (diff)
downloadgnunet-c6becd402caf853f1cebe637bfb4664be4cba9bd.tar.gz
gnunet-c6becd402caf853f1cebe637bfb4664be4cba9bd.zip
new pretty printer
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c118
1 files changed, 87 insertions, 31 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 4aca7da61..2c87e0788 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -103,7 +103,7 @@ struct IPv4HttpAddress
103 /** 103 /**
104 * Port number, in network byte order. 104 * Port number, in network byte order.
105 */ 105 */
106 uint16_t u_port GNUNET_PACKED; 106 uint16_t port GNUNET_PACKED;
107}; 107};
108 108
109/** 109/**
@@ -137,7 +137,7 @@ struct IPv6HttpAddress
137 /** 137 /**
138 * Port number, in network byte order. 138 * Port number, in network byte order.
139 */ 139 */
140 uint16_t u6_port GNUNET_PACKED; 140 uint16_t port GNUNET_PACKED;
141 141
142}; 142};
143 143
@@ -514,6 +514,27 @@ struct Plugin
514#endif 514#endif
515}; 515};
516 516
517/**
518 * Context for address to string conversion.
519 */
520struct PrettyPrinterContext
521{
522 /**
523 * Function to call with the result.
524 */
525 GNUNET_TRANSPORT_AddressStringCallback asc;
526
527 /**
528 * Clsoure for 'asc'.
529 */
530 void *asc_cls;
531
532 /**
533 * Port to add after the IP address.
534 */
535 uint16_t port;
536};
537
517 538
518/** 539/**
519 * Function called for a quick conversion of the binary address to 540 * Function called for a quick conversion of the binary address to
@@ -849,7 +870,7 @@ process_interfaces (void *cls,
849 870
850 871
851 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 872 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
852 t4->u_port = htons (plugin->port_inbound); 873 t4->port = htons (plugin->port_inbound);
853 if (plugin->bind4_address != NULL) { 874 if (plugin->bind4_address != NULL) {
854 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) 875 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr)))
855 { 876 {
@@ -890,7 +911,7 @@ process_interfaces (void *cls,
890 memcpy (&t6->ipv6_addr, 911 memcpy (&t6->ipv6_addr,
891 &((struct sockaddr_in6 *) addr)->sin6_addr, 912 &((struct sockaddr_in6 *) addr)->sin6_addr,
892 sizeof (struct in6_addr)); 913 sizeof (struct in6_addr));
893 t6->u6_port = htons (plugin->port_inbound); 914 t6->port = htons (plugin->port_inbound);
894 plugin->env->notify_address(plugin->env->cls, 915 plugin->env->notify_address(plugin->env->cls,
895 GNUNET_YES, 916 GNUNET_YES,
896 t6, sizeof (struct IPv6HttpAddress)); 917 t6, sizeof (struct IPv6HttpAddress));
@@ -905,7 +926,7 @@ process_interfaces (void *cls,
905 memcpy (&t6->ipv6_addr, 926 memcpy (&t6->ipv6_addr,
906 &((struct sockaddr_in6 *) addr)->sin6_addr, 927 &((struct sockaddr_in6 *) addr)->sin6_addr,
907 sizeof (struct in6_addr)); 928 sizeof (struct in6_addr));
908 t6->u6_port = htons (plugin->port_inbound); 929 t6->port = htons (plugin->port_inbound);
909 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6); 930 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
910 931
911 plugin->env->notify_address(plugin->env->cls, 932 plugin->env->notify_address(plugin->env->cls,
@@ -1245,7 +1266,7 @@ mhd_access_cb (void *cls,
1245 addrin = (const struct sockaddr_in*) client_addr; 1266 addrin = (const struct sockaddr_in*) client_addr;
1246 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN); 1267 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
1247 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr)); 1268 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr));
1248 ipv4addr.u_port = addrin->sin_port; 1269 ipv4addr.port = addrin->sin_port;
1249 addr = &ipv4addr; 1270 addr = &ipv4addr;
1250 addr_len = sizeof(struct IPv4HttpAddress); 1271 addr_len = sizeof(struct IPv4HttpAddress);
1251 } 1272 }
@@ -1255,7 +1276,7 @@ mhd_access_cb (void *cls,
1255 addrin6 = (const struct sockaddr_in6 *) client_addr; 1276 addrin6 = (const struct sockaddr_in6 *) client_addr;
1256 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); 1277 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
1257 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr)); 1278 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr));
1258 ipv6addr.u6_port = addrin6->sin6_port; 1279 ipv6addr.port = addrin6->sin6_port;
1259 addr = &ipv6addr; 1280 addr = &ipv6addr;
1260 addr_len = sizeof(struct IPv6HttpAddress); 1281 addr_len = sizeof(struct IPv6HttpAddress);
1261 } 1282 }
@@ -2702,6 +2723,32 @@ http_plugin_disconnect (void *cls,
2702 2723
2703 2724
2704/** 2725/**
2726 * Append our port and forward the result.
2727 *
2728 * @param cls the 'struct PrettyPrinterContext*'
2729 * @param hostname hostname part of the address
2730 */
2731static void
2732append_port (void *cls, const char *hostname)
2733{
2734 struct PrettyPrinterContext *ppc = cls;
2735 char *ret;
2736
2737 if (hostname == NULL)
2738 {
2739 ppc->asc (ppc->asc_cls, NULL);
2740 GNUNET_free (ppc);
2741 return;
2742 }
2743 GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port);
2744
2745 ppc->asc (ppc->asc_cls, ret);
2746 GNUNET_free (ret);
2747}
2748
2749
2750
2751/**
2705 * Convert the transports address to a nice, human-readable 2752 * Convert the transports address to a nice, human-readable
2706 * format. 2753 * format.
2707 * 2754 *
@@ -2725,31 +2772,38 @@ http_plugin_address_pretty_printer (void *cls,
2725 GNUNET_TRANSPORT_AddressStringCallback 2772 GNUNET_TRANSPORT_AddressStringCallback
2726 asc, void *asc_cls) 2773 asc, void *asc_cls)
2727{ 2774{
2775 struct PrettyPrinterContext *ppc;
2776 const void *sb;
2777 size_t sbs;
2778 struct sockaddr_in a4;
2779 struct sockaddr_in6 a6;
2728 const struct IPv4HttpAddress *t4; 2780 const struct IPv4HttpAddress *t4;
2729 const struct IPv6HttpAddress *t6; 2781 const struct IPv6HttpAddress *t6;
2730 struct sockaddr_in a4; 2782 uint16_t port;
2731 struct sockaddr_in6 a6;
2732 char * address;
2733 char * ret;
2734 unsigned int port;
2735 unsigned int res;
2736 2783
2737 GNUNET_assert(cls !=NULL);
2738 if (addrlen == sizeof (struct IPv6HttpAddress)) 2784 if (addrlen == sizeof (struct IPv6HttpAddress))
2739 { 2785 {
2740 address = GNUNET_malloc (INET6_ADDRSTRLEN);
2741 t6 = addr; 2786 t6 = addr;
2742 a6.sin6_addr = t6->ipv6_addr; 2787 memset (&a6, 0, sizeof (a6));
2743 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN); 2788 a6.sin6_family = AF_INET6;
2744 port = ntohs(t6->u6_port); 2789 a6.sin6_port = t6->port;
2790 memcpy (&a6.sin6_addr,
2791 &t6->ipv6_addr,
2792 sizeof (struct in6_addr));
2793 port = ntohs (t6->port);
2794 sb = &a6;
2795 sbs = sizeof (a6);
2745 } 2796 }
2746 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2797 else if (addrlen == sizeof (struct IPv4HttpAddress))
2747 { 2798 {
2748 address = GNUNET_malloc (INET_ADDRSTRLEN);
2749 t4 = addr; 2799 t4 = addr;
2750 a4.sin_addr.s_addr = t4->ipv4_addr; 2800 memset (&a4, 0, sizeof (a4));
2751 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN); 2801 a4.sin_family = AF_INET;
2752 port = ntohs(t4->u_port); 2802 a4.sin_port = t4->port;
2803 a4.sin_addr.s_addr = t4->ipv4_addr;
2804 port = ntohs (t4->ipv4_addr);
2805 sb = &a4;
2806 sbs = sizeof (a4);
2753 } 2807 }
2754 else 2808 else
2755 { 2809 {
@@ -2758,11 +2812,13 @@ http_plugin_address_pretty_printer (void *cls,
2758 asc (asc_cls, NULL); 2812 asc (asc_cls, NULL);
2759 return; 2813 return;
2760 } 2814 }
2761 res = GNUNET_asprintf(&ret,"%s://%s:%u/", PROTOCOL_PREFIX, address, port); 2815 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
2762 GNUNET_free (address); 2816 ppc->asc = asc;
2763 GNUNET_assert(res != 0); 2817 ppc->asc_cls = asc_cls;
2764 asc (asc_cls, ret); 2818 ppc->port = port;
2765 GNUNET_free_non_null (ret); 2819 GNUNET_RESOLVER_hostname_get (sb,
2820 sbs,
2821 !numeric, timeout, &append_port, ppc);
2766} 2822}
2767 2823
2768 2824
@@ -2870,7 +2926,7 @@ http_plugin_address_to_string (void *cls,
2870 t6 = addr; 2926 t6 = addr;
2871 a6.sin6_addr = t6->ipv6_addr; 2927 a6.sin6_addr = t6->ipv6_addr;
2872 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN); 2928 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
2873 port = ntohs(t6->u6_port); 2929 port = ntohs(t6->port);
2874 } 2930 }
2875 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2931 else if (addrlen == sizeof (struct IPv4HttpAddress))
2876 { 2932 {
@@ -2878,7 +2934,7 @@ http_plugin_address_to_string (void *cls,
2878 t4 = addr; 2934 t4 = addr;
2879 a4.sin_addr.s_addr = t4->ipv4_addr; 2935 a4.sin_addr.s_addr = t4->ipv4_addr;
2880 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN); 2936 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
2881 port = ntohs(t4->u_port); 2937 port = ntohs(t4->port);
2882 } 2938 }
2883 else 2939 else
2884 { 2940 {
@@ -2948,7 +3004,7 @@ tcp_nat_cb_add_addr (void *cls,
2948 memcpy (&t4->ipv4_addr, 3004 memcpy (&t4->ipv4_addr,
2949 &((struct sockaddr_in *) addr)->sin_addr, 3005 &((struct sockaddr_in *) addr)->sin_addr,
2950 sizeof (struct in_addr)); 3006 sizeof (struct in_addr));
2951 t4->u_port = htons (plugin->port_inbound); 3007 t4->port = htons (plugin->port_inbound);
2952 3008
2953 w_t4->addr = t4; 3009 w_t4->addr = t4;
2954 3010
@@ -2979,7 +3035,7 @@ tcp_nat_cb_add_addr (void *cls,
2979 memcpy (&t6->ipv6_addr, 3035 memcpy (&t6->ipv6_addr,
2980 &((struct sockaddr_in6 *) addr)->sin6_addr, 3036 &((struct sockaddr_in6 *) addr)->sin6_addr,
2981 sizeof (struct in6_addr)); 3037 sizeof (struct in6_addr));
2982 t6->u6_port = htons (plugin->port_inbound); 3038 t6->port = htons (plugin->port_inbound);
2983 3039
2984 w_t6->addr = t6; 3040 w_t6->addr = t6;
2985 3041