diff options
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 396 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.h | 86 |
2 files changed, 260 insertions, 222 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index c020118ac..131624f16 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2002-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -28,12 +28,13 @@ | |||
28 | #include "gnunet_transport_plugin.h" | 28 | #include "gnunet_transport_plugin.h" |
29 | #include "plugin_transport_http_common.h" | 29 | #include "plugin_transport_http_common.h" |
30 | 30 | ||
31 | |||
31 | struct SplittedHTTPAddress | 32 | struct SplittedHTTPAddress |
32 | { | 33 | { |
33 | char *protocol; | 34 | char *protocol; |
34 | char *host; | 35 | char *host; |
35 | char *path; | 36 | char *path; |
36 | int port; | 37 | int port; |
37 | }; | 38 | }; |
38 | 39 | ||
39 | 40 | ||
@@ -49,137 +50,138 @@ http_clean_splitted (struct SplittedHTTPAddress *spa) | |||
49 | } | 50 | } |
50 | } | 51 | } |
51 | 52 | ||
53 | |||
52 | struct SplittedHTTPAddress * | 54 | struct SplittedHTTPAddress * |
53 | http_split_address (const char * addr) | 55 | http_split_address (const char * addr) |
54 | { | 56 | { |
55 | struct SplittedHTTPAddress *sp; | 57 | struct SplittedHTTPAddress *sp; |
56 | char *src = GNUNET_strdup (addr); | 58 | char *src = GNUNET_strdup (addr); |
57 | char *protocol_start = NULL; | 59 | char *protocol_start = NULL; |
58 | char *host_start = NULL; | 60 | char *host_start = NULL; |
59 | char *v6_end = NULL; | 61 | char *v6_end = NULL; |
60 | char *port_start = NULL; | 62 | char *port_start = NULL; |
61 | char *path_start = NULL; | 63 | char *path_start = NULL; |
62 | protocol_start = src; | 64 | protocol_start = src; |
63 | sp = GNUNET_new (struct SplittedHTTPAddress); | 65 | |
64 | 66 | sp = GNUNET_new (struct SplittedHTTPAddress); | |
65 | /* Address string consists of protocol://host[:port]path*/ | 67 | /* Address string consists of protocol://host[:port]path*/ |
66 | 68 | ||
67 | host_start = strstr (src, "://"); | 69 | host_start = strstr (src, "://"); |
68 | if (NULL == host_start) | 70 | if (NULL == host_start) |
69 | { | 71 | { |
70 | GNUNET_free (src); | 72 | GNUNET_free (src); |
71 | GNUNET_free (sp); | 73 | GNUNET_free (sp); |
72 | return NULL; | 74 | return NULL; |
73 | } | 75 | } |
74 | 76 | host_start[0] = '\0'; | |
75 | host_start[0] = '\0'; | 77 | sp->protocol = GNUNET_strdup (protocol_start); |
76 | sp->protocol = GNUNET_strdup (protocol_start); | 78 | |
77 | 79 | host_start += strlen ("://"); | |
78 | host_start += strlen ("://"); | 80 | if (strlen (host_start) == 0) |
79 | if (strlen (host_start) == 0) | 81 | { |
80 | { | 82 | GNUNET_free (src); |
81 | GNUNET_free (src); | 83 | GNUNET_free (sp->protocol); |
82 | GNUNET_free (sp->protocol); | 84 | GNUNET_free (sp); |
83 | GNUNET_free (sp); | 85 | return NULL; |
84 | return NULL; | 86 | } |
85 | } | 87 | |
86 | 88 | /* Find path start */ | |
87 | /* Find path start */ | 89 | path_start = strchr (host_start, '/'); |
88 | path_start = strchr (host_start, '/'); | 90 | if (NULL != path_start) |
89 | if (NULL != path_start) | 91 | { |
90 | { | 92 | sp->path = GNUNET_strdup (path_start); |
91 | sp->path = GNUNET_strdup (path_start); | 93 | path_start[0] = '\0'; |
92 | path_start[0] = '\0'; | 94 | } |
93 | } | 95 | else |
94 | else | 96 | sp->path = GNUNET_strdup (""); |
95 | sp->path = GNUNET_strdup (""); | 97 | |
96 | 98 | if (strlen(host_start) < 1) | |
97 | if (strlen(host_start) < 1) | 99 | { |
98 | { | 100 | GNUNET_free (src); |
99 | GNUNET_free (src); | 101 | GNUNET_free (sp->protocol); |
100 | GNUNET_free (sp->protocol); | 102 | GNUNET_free (sp->path); |
101 | GNUNET_free (sp->path); | 103 | GNUNET_free (sp); |
102 | GNUNET_free (sp); | 104 | return NULL; |
103 | return NULL; | 105 | } |
104 | } | 106 | |
105 | 107 | if (NULL != (port_start = strrchr (host_start, ':'))) | |
106 | if (NULL != (port_start = strrchr (host_start, ':'))) | 108 | { |
107 | { | 109 | /* *We COULD have a port, but also an IPv6 address! */ |
108 | /* *We COULD have a port, but also an IPv6 address! */ | 110 | if (NULL != (v6_end = strchr(host_start, ']'))) |
109 | if (NULL != (v6_end = strchr(host_start, ']'))) | 111 | { |
110 | { | 112 | if (v6_end < port_start) |
111 | if (v6_end < port_start) | 113 | { |
112 | { | 114 | /* IPv6 address + port */ |
113 | /* IPv6 address + port */ | 115 | port_start[0] = '\0'; |
114 | port_start[0] = '\0'; | 116 | port_start ++; |
115 | port_start ++; | 117 | sp->port = atoi (port_start); |
116 | sp->port = atoi (port_start); | 118 | if ((0 == sp->port) || (65535 < sp->port)) |
117 | if ((0 == sp->port) || (65535 < sp->port)) | 119 | { |
118 | { | 120 | GNUNET_free (src); |
119 | GNUNET_free (src); | 121 | GNUNET_free (sp->protocol); |
120 | GNUNET_free (sp->protocol); | 122 | GNUNET_free (sp->path); |
121 | GNUNET_free (sp->path); | 123 | GNUNET_free (sp); |
122 | GNUNET_free (sp); | 124 | return NULL; |
123 | return NULL; | 125 | } |
124 | } | 126 | } |
125 | } | 127 | else |
126 | else | 128 | { |
127 | { | 129 | /* IPv6 address + no port */ |
128 | /* IPv6 address + no port */ | 130 | if (0 == strcmp(sp->protocol, "https")) |
129 | if (0 == strcmp(sp->protocol, "https")) | 131 | sp->port = HTTPS_DEFAULT_PORT; |
130 | sp->port = HTTPS_DEFAULT_PORT; | 132 | else if (0 == strcmp(sp->protocol, "http")) |
131 | else if (0 == strcmp(sp->protocol, "http")) | 133 | sp->port = HTTP_DEFAULT_PORT; |
132 | sp->port = HTTP_DEFAULT_PORT; | 134 | } |
133 | } | 135 | } |
134 | } | 136 | else |
135 | else | 137 | { |
136 | { | 138 | /* No IPv6 address */ |
137 | /* No IPv6 address */ | 139 | port_start[0] = '\0'; |
138 | port_start[0] = '\0'; | 140 | port_start ++; |
139 | port_start ++; | 141 | sp->port = atoi (port_start); |
140 | sp->port = atoi (port_start); | 142 | if ((0 == sp->port) || (65535 < sp->port)) |
141 | if ((0 == sp->port) || (65535 < sp->port)) | 143 | { |
142 | { | 144 | GNUNET_free (src); |
143 | GNUNET_free (src); | 145 | GNUNET_free (sp->protocol); |
144 | GNUNET_free (sp->protocol); | 146 | GNUNET_free (sp->path); |
145 | GNUNET_free (sp->path); | 147 | GNUNET_free (sp); |
146 | GNUNET_free (sp); | 148 | return NULL; |
147 | return NULL; | 149 | } |
148 | } | 150 | } |
149 | } | 151 | } |
150 | } | 152 | else |
151 | else | 153 | { |
152 | { | 154 | /* No ':' as port separator, default port for protocol */ |
153 | /* No ':' as port separator, default port for protocol */ | 155 | if (0 == strcmp(sp->protocol, "https")) |
154 | if (0 == strcmp(sp->protocol, "https")) | 156 | sp->port = HTTPS_DEFAULT_PORT; |
155 | sp->port = HTTPS_DEFAULT_PORT; | 157 | else if (0 == strcmp(sp->protocol, "http")) |
156 | else if (0 == strcmp(sp->protocol, "http")) | 158 | sp->port = HTTP_DEFAULT_PORT; |
157 | sp->port = HTTP_DEFAULT_PORT; | 159 | else |
158 | else | 160 | { |
159 | { | 161 | GNUNET_break (0); |
160 | GNUNET_break (0); | 162 | GNUNET_free (src); |
161 | GNUNET_free (src); | 163 | GNUNET_free (sp->protocol); |
162 | GNUNET_free (sp->protocol); | 164 | GNUNET_free (sp->path); |
163 | GNUNET_free (sp->path); | 165 | GNUNET_free (sp); |
164 | GNUNET_free (sp); | 166 | return NULL; |
165 | return NULL; | 167 | } |
166 | } | 168 | } |
167 | } | 169 | if (strlen (host_start) > 0) |
168 | if (strlen (host_start) > 0) | 170 | sp->host = GNUNET_strdup (host_start); |
169 | sp->host = GNUNET_strdup (host_start); | 171 | else |
170 | else | 172 | { |
171 | { | 173 | GNUNET_break (0); |
172 | GNUNET_break (0); | 174 | GNUNET_free (src); |
173 | GNUNET_free (src); | 175 | GNUNET_free (sp->protocol); |
174 | GNUNET_free (sp->protocol); | 176 | GNUNET_free (sp->path); |
175 | GNUNET_free (sp->path); | 177 | GNUNET_free (sp); |
176 | GNUNET_free (sp); | 178 | return NULL; |
177 | return NULL; | 179 | } |
178 | } | 180 | GNUNET_free (src); |
179 | GNUNET_free (src); | 181 | return sp; |
180 | return sp; | ||
181 | } | 182 | } |
182 | 183 | ||
184 | |||
183 | /** | 185 | /** |
184 | * Convert the transports address to a nice, human-readable | 186 | * Convert the transports address to a nice, human-readable |
185 | * format. | 187 | * format. |
@@ -188,53 +190,60 @@ http_split_address (const char * addr) | |||
188 | * @param type name of the transport that generated the address | 190 | * @param type name of the transport that generated the address |
189 | * @param addr one of the addresses of the host, NULL for the last address | 191 | * @param addr one of the addresses of the host, NULL for the last address |
190 | * the specific address format depends on the transport | 192 | * the specific address format depends on the transport |
191 | * @param addrlen length of the address | 193 | * @param addrlen length of the @a addr |
192 | * @param numeric should (IP) addresses be displayed in numeric form? | 194 | * @param numeric should (IP) addresses be displayed in numeric form? |
193 | * @param timeout after how long should we give up? | 195 | * @param timeout after how long should we give up? |
194 | * @param asc function to call on each string | 196 | * @param asc function to call on each string |
195 | * @param asc_cls closure for asc | 197 | * @param asc_cls closure for @a asc |
196 | */ | 198 | */ |
197 | void | 199 | void |
198 | http_common_plugin_address_pretty_printer (void *cls, const char *type, | 200 | http_common_plugin_address_pretty_printer (void *cls, |
199 | const void *addr, size_t addrlen, | 201 | const char *type, |
200 | int numeric, | 202 | const void *addr, |
201 | struct GNUNET_TIME_Relative timeout, | 203 | size_t addrlen, |
202 | GNUNET_TRANSPORT_AddressStringCallback | 204 | int numeric, |
203 | asc, void *asc_cls) | 205 | struct GNUNET_TIME_Relative timeout, |
206 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
207 | void *asc_cls) | ||
204 | { | 208 | { |
205 | const struct HttpAddress *address = addr; | 209 | const struct HttpAddress *address = addr; |
206 | 210 | ||
207 | if (NULL == http_common_plugin_address_to_string (NULL, (char *) type, address, addrlen)) | 211 | if (NULL == |
212 | http_common_plugin_address_to_string (NULL, type, | ||
213 | address, addrlen)) | ||
208 | { | 214 | { |
209 | asc (asc_cls, NULL); | 215 | asc (asc_cls, NULL); |
210 | return; | 216 | return; |
211 | } | 217 | } |
212 | asc (asc_cls, http_common_plugin_address_to_string (NULL, (char *) type, address, addrlen)); | 218 | asc (asc_cls, http_common_plugin_address_to_string (NULL, |
219 | type, | ||
220 | address, addrlen)); | ||
213 | asc (asc_cls, NULL); | 221 | asc (asc_cls, NULL); |
214 | } | 222 | } |
215 | 223 | ||
224 | |||
216 | const char * | 225 | const char * |
217 | http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | 226 | http_common_plugin_address_to_url (void *cls, |
227 | const void *addr, | ||
228 | size_t addrlen) | ||
218 | { | 229 | { |
219 | static char rbuf[1024]; | 230 | static char rbuf[1024]; |
220 | const struct HttpAddress *address = addr; | 231 | const struct HttpAddress *address = addr; |
221 | const char * addr_str; | 232 | const char * addr_str; |
222 | 233 | ||
223 | |||
224 | |||
225 | if (NULL == addr) | 234 | if (NULL == addr) |
226 | { | 235 | { |
227 | GNUNET_break (0); | 236 | GNUNET_break (0); |
228 | return NULL; | 237 | return NULL; |
229 | } | 238 | } |
230 | if (0 >= addrlen) | 239 | if (0 >= addrlen) |
231 | { | 240 | { |
232 | GNUNET_break (0); | 241 | GNUNET_break (0); |
233 | return NULL; | 242 | return NULL; |
234 | } | 243 | } |
235 | if (addrlen != http_common_address_get_size (address)) | 244 | if (addrlen != http_common_address_get_size (address)) |
236 | { | 245 | { |
237 | GNUNET_break (0); | 246 | GNUNET_break (0); |
238 | return NULL; | 247 | return NULL; |
239 | } | 248 | } |
240 | addr_str = (char *) &address[1]; | 249 | addr_str = (char *) &address[1]; |
@@ -246,6 +255,7 @@ http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | |||
246 | return rbuf; | 255 | return rbuf; |
247 | } | 256 | } |
248 | 257 | ||
258 | |||
249 | /** | 259 | /** |
250 | * Function called for a quick conversion of the binary address to | 260 | * Function called for a quick conversion of the binary address to |
251 | * a numeric address. Note that the caller must not free the | 261 | * a numeric address. Note that the caller must not free the |
@@ -259,10 +269,13 @@ http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen) | |||
259 | * @return string representing the same address | 269 | * @return string representing the same address |
260 | */ | 270 | */ |
261 | const char * | 271 | const char * |
262 | http_common_plugin_address_to_string (void *cls, char *plugin, const void *addr, size_t addrlen) | 272 | http_common_plugin_address_to_string (void *cls, |
273 | const char *plugin, | ||
274 | const void *addr, | ||
275 | size_t addrlen) | ||
263 | { | 276 | { |
264 | static char rbuf[1024]; | 277 | static char rbuf[1024]; |
265 | const struct HttpAddress *address = addr; | 278 | const struct HttpAddress *address = addr; |
266 | const char * addr_str; | 279 | const char * addr_str; |
267 | char *res; | 280 | char *res; |
268 | 281 | ||
@@ -281,35 +294,36 @@ http_common_plugin_address_to_string (void *cls, char *plugin, const void *addr, | |||
281 | GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl(address->options), &address[1]); | 294 | GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl(address->options), &address[1]); |
282 | if (strlen(res) + 1 < 500) | 295 | if (strlen(res) + 1 < 500) |
283 | { | 296 | { |
284 | memcpy (rbuf, res, strlen(res) + 1); | 297 | memcpy (rbuf, res, strlen(res) + 1); |
285 | GNUNET_free (res); | 298 | GNUNET_free (res); |
286 | return rbuf; | 299 | return rbuf; |
287 | } | 300 | } |
288 | GNUNET_break (0); | 301 | GNUNET_break (0); |
289 | GNUNET_free (res); | 302 | GNUNET_free (res); |
290 | return NULL; | 303 | return NULL; |
291 | } | 304 | } |
292 | 305 | ||
306 | |||
293 | /** | 307 | /** |
294 | * Function called to convert a string address to | 308 | * Function called to convert a string address to |
295 | * a binary address. | 309 | * a binary address. |
296 | * | 310 | * |
297 | * @param cls closure ('struct Plugin*') | 311 | * @param cls closure ('struct Plugin*') |
298 | * @param addr string address | 312 | * @param addr string address |
299 | * @param addrlen length of the address | 313 | * @param addrlen length of the @a addr |
300 | * @param buf location to store the buffer | 314 | * @param buf location to store the buffer |
301 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 315 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
302 | * @param added length of created address | 316 | * @param added length of created address |
303 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 317 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
304 | */ | 318 | */ |
305 | int | 319 | int |
306 | http_common_plugin_string_to_address (void *cls, | 320 | http_common_plugin_string_to_address (void *cls, |
307 | const char *addr, | 321 | const char *addr, |
308 | uint16_t addrlen, | 322 | uint16_t addrlen, |
309 | void **buf, | 323 | void **buf, |
310 | size_t *added) | 324 | size_t *added) |
311 | { | 325 | { |
312 | struct HttpAddress *a; | 326 | struct HttpAddress *a; |
313 | char *address; | 327 | char *address; |
314 | char *plugin; | 328 | char *plugin; |
315 | char *optionstr; | 329 | char *optionstr; |
@@ -368,6 +382,7 @@ http_common_plugin_string_to_address (void *cls, | |||
368 | return GNUNET_OK; | 382 | return GNUNET_OK; |
369 | } | 383 | } |
370 | 384 | ||
385 | |||
371 | /** | 386 | /** |
372 | * Create a HTTP address from a socketaddr | 387 | * Create a HTTP address from a socketaddr |
373 | * | 388 | * |
@@ -377,45 +392,51 @@ http_common_plugin_string_to_address (void *cls, | |||
377 | * @return the HttpAddress | 392 | * @return the HttpAddress |
378 | */ | 393 | */ |
379 | struct HttpAddress * | 394 | struct HttpAddress * |
380 | http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen) | 395 | http_common_address_from_socket (const char *protocol, |
396 | const struct sockaddr *addr, | ||
397 | socklen_t addrlen) | ||
381 | { | 398 | { |
382 | struct HttpAddress *address = NULL; | 399 | struct HttpAddress *address = NULL; |
383 | char *res; | 400 | char *res; |
384 | size_t len; | 401 | size_t len; |
385 | 402 | ||
386 | GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); | 403 | GNUNET_asprintf(&res, |
404 | "%s://%s", | ||
405 | protocol, | ||
406 | GNUNET_a2s (addr, addrlen)); | ||
387 | len = strlen (res)+1; | 407 | len = strlen (res)+1; |
388 | |||
389 | address = GNUNET_malloc (sizeof (struct HttpAddress) + len); | 408 | address = GNUNET_malloc (sizeof (struct HttpAddress) + len); |
390 | address->options = htonl (HTTP_OPTIONS_NONE); | 409 | address->options = htonl (HTTP_OPTIONS_NONE); |
391 | address->urlen = htonl (len); | 410 | address->urlen = htonl (len); |
392 | memcpy (&address[1], res, len); | 411 | memcpy (&address[1], res, len); |
393 | GNUNET_free (res); | 412 | GNUNET_free (res); |
394 | |||
395 | return address; | 413 | return address; |
396 | } | 414 | } |
397 | 415 | ||
416 | |||
398 | /** | 417 | /** |
399 | * Create a socketaddr from a HTTP address | 418 | * Create a socketaddr from a HTTP address |
400 | * | 419 | * |
401 | * @param addr sockaddr * address | 420 | * @param addr a `sockaddr *` address |
402 | * @param addrlen length of the address | 421 | * @param addrlen length of the @a addr |
403 | * @param res the result: | 422 | * @param res the result: |
404 | * GNUNET_SYSERR, invalid input, | 423 | * #GNUNET_SYSERR, invalid input, |
405 | * GNUNET_YES: could convert to ip, | 424 | * #GNUNET_YES: could convert to ip, |
406 | * GNUNET_NO: valid input but could not convert to ip (hostname?) | 425 | * #GNUNET_NO: valid input but could not convert to ip (hostname?) |
407 | * @return the string | 426 | * @return the string |
408 | */ | 427 | */ |
409 | struct sockaddr * | 428 | struct sockaddr * |
410 | http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | 429 | http_common_socket_from_address (const void *addr, |
430 | size_t addrlen, | ||
431 | int *res) | ||
411 | { | 432 | { |
412 | const struct HttpAddress *ha; | 433 | const struct HttpAddress *ha; |
413 | struct SplittedHTTPAddress * spa; | 434 | struct SplittedHTTPAddress * spa; |
414 | struct sockaddr_storage *s; | 435 | struct sockaddr_storage *s; |
415 | (*res) = GNUNET_SYSERR; | ||
416 | char * to_conv; | 436 | char * to_conv; |
417 | size_t urlen; | 437 | size_t urlen; |
418 | 438 | ||
439 | (*res) = GNUNET_SYSERR; | ||
419 | ha = (const struct HttpAddress *) addr; | 440 | ha = (const struct HttpAddress *) addr; |
420 | if (NULL == addr) | 441 | if (NULL == addr) |
421 | { | 442 | { |
@@ -480,6 +501,7 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | |||
480 | return (struct sockaddr *) s; | 501 | return (struct sockaddr *) s; |
481 | } | 502 | } |
482 | 503 | ||
504 | |||
483 | /** | 505 | /** |
484 | * Get the length of an address | 506 | * Get the length of an address |
485 | * | 507 | * |
@@ -492,6 +514,7 @@ http_common_address_get_size (const struct HttpAddress * addr) | |||
492 | return sizeof (struct HttpAddress) + ntohl(addr->urlen); | 514 | return sizeof (struct HttpAddress) + ntohl(addr->urlen); |
493 | } | 515 | } |
494 | 516 | ||
517 | |||
495 | /** | 518 | /** |
496 | * Compare addr1 to addr2 | 519 | * Compare addr1 to addr2 |
497 | * | 520 | * |
@@ -499,15 +522,18 @@ http_common_address_get_size (const struct HttpAddress * addr) | |||
499 | * @param addrlen1 address 1 length | 522 | * @param addrlen1 address 1 length |
500 | * @param addr2 address2 | 523 | * @param addr2 address2 |
501 | * @param addrlen2 address 2 length | 524 | * @param addrlen2 address 2 length |
502 | * @return GNUNET_YES if equal, GNUNET_NO if not, GNUNET_SYSERR on error | 525 | * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error |
503 | */ | 526 | */ |
504 | size_t | 527 | size_t |
505 | http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2) | 528 | http_common_cmp_addresses (const void *addr1, |
529 | size_t addrlen1, | ||
530 | const void *addr2, | ||
531 | size_t addrlen2) | ||
506 | { | 532 | { |
507 | const struct HttpAddress *ha1; | 533 | const char *a1 = addr1; |
508 | const struct HttpAddress *ha2; | 534 | const char *a2 = addr2; |
509 | const char *a1 = (const char *) addr1; | 535 | const struct HttpAddress *ha1; |
510 | const char *a2 = (const char *) addr2; | 536 | const struct HttpAddress *ha2; |
511 | ha1 = (const struct HttpAddress *) a1; | 537 | ha1 = (const struct HttpAddress *) a1; |
512 | ha2 = (const struct HttpAddress *) a2; | 538 | ha2 = (const struct HttpAddress *) a2; |
513 | 539 | ||
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 33a5b38f5..473516502 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2002-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -61,8 +61,8 @@ | |||
61 | 61 | ||
62 | enum HTTP_OPTIONS | 62 | enum HTTP_OPTIONS |
63 | { | 63 | { |
64 | HTTP_OPTIONS_NONE = 0, | 64 | HTTP_OPTIONS_NONE = 0, |
65 | HTTP_OPTIONS_VERIFY_CERTIFICATE = 1 | 65 | HTTP_OPTIONS_VERIFY_CERTIFICATE = 1 |
66 | }; | 66 | }; |
67 | 67 | ||
68 | 68 | ||
@@ -73,16 +73,15 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
73 | */ | 73 | */ |
74 | struct HttpAddress | 74 | struct HttpAddress |
75 | { | 75 | { |
76 | /** | 76 | /** |
77 | * Address options | 77 | * Address options |
78 | */ | 78 | */ |
79 | uint32_t options; | 79 | uint32_t options; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Length of URL located after struct | 82 | * Length of URL located after struct |
83 | * | 83 | */ |
84 | */ | 84 | uint32_t urlen; |
85 | uint32_t urlen; | ||
86 | }; | 85 | }; |
87 | 86 | ||
88 | GNUNET_NETWORK_STRUCT_END | 87 | GNUNET_NETWORK_STRUCT_END |
@@ -104,15 +103,16 @@ http_split_address (const char * addr); | |||
104 | * @param numeric should (IP) addresses be displayed in numeric form? | 103 | * @param numeric should (IP) addresses be displayed in numeric form? |
105 | * @param timeout after how long should we give up? | 104 | * @param timeout after how long should we give up? |
106 | * @param asc function to call on each string | 105 | * @param asc function to call on each string |
107 | * @param asc_cls closure for asc | 106 | * @param asc_cls closure for @a asc |
108 | */ | 107 | */ |
109 | void | 108 | void |
110 | http_common_plugin_address_pretty_printer (void *cls, const char *type, | 109 | http_common_plugin_address_pretty_printer (void *cls, const char *type, |
111 | const void *addr, size_t addrlen, | 110 | const void *addr, size_t addrlen, |
112 | int numeric, | 111 | int numeric, |
113 | struct GNUNET_TIME_Relative timeout, | 112 | struct GNUNET_TIME_Relative timeout, |
114 | GNUNET_TRANSPORT_AddressStringCallback | 113 | GNUNET_TRANSPORT_AddressStringCallback |
115 | asc, void *asc_cls); | 114 | asc, void *asc_cls); |
115 | |||
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Function called for a quick conversion of the binary address to | 118 | * Function called for a quick conversion of the binary address to |
@@ -128,21 +128,22 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
128 | */ | 128 | */ |
129 | const char * | 129 | const char * |
130 | http_common_plugin_address_to_string (void *cls, | 130 | http_common_plugin_address_to_string (void *cls, |
131 | char *plugin, | 131 | const char *plugin, |
132 | const void *addr, | 132 | const void *addr, |
133 | size_t addrlen); | 133 | size_t addrlen); |
134 | 134 | ||
135 | |||
135 | /** | 136 | /** |
136 | * Function called to convert a string address to | 137 | * Function called to convert a string address to |
137 | * a binary address. | 138 | * a binary address. |
138 | * | 139 | * |
139 | * @param cls closure ('struct Plugin*') | 140 | * @param cls closure (`struct Plugin*`) |
140 | * @param addr string address | 141 | * @param addr string address |
141 | * @param addrlen length of the address | 142 | * @param addrlen length of the address |
142 | * @param buf location to store the buffer | 143 | * @param buf location to store the buffer |
143 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 144 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
144 | * @param added length of created address | 145 | * @param added length of created address |
145 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 146 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
146 | */ | 147 | */ |
147 | int | 148 | int |
148 | http_common_plugin_string_to_address (void *cls, | 149 | http_common_plugin_string_to_address (void *cls, |
@@ -156,31 +157,38 @@ http_common_plugin_string_to_address (void *cls, | |||
156 | * Create a HTTP address from a socketaddr | 157 | * Create a HTTP address from a socketaddr |
157 | * | 158 | * |
158 | * @param protocol protocol | 159 | * @param protocol protocol |
159 | * @param addr sockaddr * address | 160 | * @param addr `sockaddr *` address |
160 | * @param addrlen length of the address | 161 | * @param addrlen length of the @a addr |
161 | * @return the string | 162 | * @return the string |
162 | */ | 163 | */ |
163 | struct HttpAddress * | 164 | struct HttpAddress * |
164 | http_common_address_from_socket (const char *protocol, | 165 | http_common_address_from_socket (const char *protocol, |
165 | const struct sockaddr *addr, | 166 | const struct sockaddr *addr, |
166 | socklen_t addrlen); | 167 | socklen_t addrlen); |
168 | |||
167 | 169 | ||
168 | /** | 170 | /** |
169 | * Create a socketaddr from a HTTP address | 171 | * Create a socketaddr from a HTTP address |
170 | * | 172 | * |
171 | * @param addr sockaddr * address | 173 | * @param addr a `sockaddr *` address |
172 | * @param addrlen length of the address | 174 | * @param addrlen length of the @a addr |
173 | * @param res the result: | 175 | * @param res the result: |
174 | * GNUNET_SYSERR, invalid input, | 176 | * #GNUNET_SYSERR, invalid input, |
175 | * GNUNET_YES: could convert to ip, | 177 | * #GNUNET_YES: could convert to ip, |
176 | * GNUNET_NO: valid input but could not convert to ip (hostname?) | 178 | * #GNUNET_NO: valid input but could not convert to ip (hostname?) |
177 | * @return the string | 179 | * @return the string |
178 | */ | 180 | */ |
179 | struct sockaddr * | 181 | struct sockaddr * |
180 | http_common_socket_from_address (const void *addr, size_t addrlen, int *res); | 182 | http_common_socket_from_address (const void *addr, |
183 | size_t addrlen, | ||
184 | int *res); | ||
185 | |||
181 | 186 | ||
182 | const char * | 187 | const char * |
183 | http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen); | 188 | http_common_plugin_address_to_url (void *cls, |
189 | const void *addr, | ||
190 | size_t addrlen); | ||
191 | |||
184 | 192 | ||
185 | /** | 193 | /** |
186 | * Get the length of an address | 194 | * Get the length of an address |
@@ -199,8 +207,12 @@ http_common_address_get_size (const struct HttpAddress * addr); | |||
199 | * @param addrlen1 address 1 length | 207 | * @param addrlen1 address 1 length |
200 | * @param addr2 address2 | 208 | * @param addr2 address2 |
201 | * @param addrlen2 address 2 length | 209 | * @param addrlen2 address 2 length |
202 | * @return GNUNET_YES if equal, GNUNET_NO else | 210 | * @return #GNUNET_YES if equal, #GNUNET_NO else |
203 | */ | 211 | */ |
204 | size_t | 212 | size_t |
205 | http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2); | 213 | http_common_cmp_addresses (const void *addr1, |
206 | /* end of plugin_transport_http_common.c */ | 214 | size_t addrlen1, |
215 | const void *addr2, | ||
216 | size_t addrlen2); | ||
217 | |||
218 | /* end of plugin_transport_http_common.h */ | ||