diff options
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index b1bf7b0de..a7a39baec 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -50,8 +50,11 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
50 | GNUNET_TRANSPORT_AddressStringCallback | 50 | GNUNET_TRANSPORT_AddressStringCallback |
51 | asc, void *asc_cls) | 51 | asc, void *asc_cls) |
52 | { | 52 | { |
53 | GNUNET_break (0); | 53 | const char *saddr = (const char *) addr; |
54 | asc (asc_cls, NULL); | 54 | GNUNET_assert (NULL != saddr); |
55 | GNUNET_assert (0 < addrlen); | ||
56 | GNUNET_assert (saddr[addrlen-1] == '\0'); | ||
57 | asc (asc_cls, saddr); | ||
55 | } | 58 | } |
56 | 59 | ||
57 | 60 | ||
@@ -69,8 +72,11 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
69 | const char * | 72 | const char * |
70 | http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 73 | http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
71 | { | 74 | { |
72 | GNUNET_break (0); | 75 | const char *saddr = (const char *) addr; |
73 | return NULL; | 76 | GNUNET_assert (NULL != saddr); |
77 | GNUNET_assert (0 < addrlen); | ||
78 | GNUNET_assert (saddr[addrlen-1] == '\0'); | ||
79 | return saddr; | ||
74 | } | 80 | } |
75 | 81 | ||
76 | /** | 82 | /** |
@@ -92,8 +98,60 @@ http_common_plugin_string_to_address (void *cls, | |||
92 | void **buf, | 98 | void **buf, |
93 | size_t *added) | 99 | size_t *added) |
94 | { | 100 | { |
95 | GNUNET_break (0); | 101 | GNUNET_assert (NULL != addr); |
96 | return GNUNET_SYSERR; | 102 | GNUNET_assert (0 < addrlen); |
103 | GNUNET_assert (addr[addrlen-1] == '\0'); | ||
104 | |||
105 | (*buf) = strdup (addr); | ||
106 | (*added) = strlen (addr) + 1; | ||
107 | return GNUNET_OK; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Create a HTTP address from a socketaddr | ||
112 | * | ||
113 | * @param protocol protocol | ||
114 | * @param addr sockaddr * address | ||
115 | * @param addrlen length of the address | ||
116 | * @return the string | ||
117 | */ | ||
118 | char * | ||
119 | http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen) | ||
120 | { | ||
121 | char *res; | ||
122 | GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); | ||
123 | return res; | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Get the length of an address | ||
128 | * | ||
129 | * @param addr address | ||
130 | * @return the size | ||
131 | */ | ||
132 | size_t | ||
133 | http_common_address_get_size (const void *addr) | ||
134 | { | ||
135 | return strlen (addr) + 1; | ||
97 | } | 136 | } |
98 | 137 | ||
138 | /** | ||
139 | * Compare addr1 to addr2 | ||
140 | * | ||
141 | * @param addr1 address1 | ||
142 | * @param addrlen1 address 1 length | ||
143 | * @param addr2 address2 | ||
144 | * @param addrlen2 address 2 length | ||
145 | * @return GNUNET_YES if equal, GNUNET_NO else | ||
146 | */ | ||
147 | size_t | ||
148 | http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2) | ||
149 | { | ||
150 | if (0 == strcmp (addr1, addr2)) | ||
151 | return GNUNET_YES; | ||
152 | return GNUNET_NO; | ||
153 | } | ||
154 | |||
155 | |||
156 | |||
99 | /* end of plugin_transport_http_common.c */ | 157 | /* end of plugin_transport_http_common.c */ |