summaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r--src/transport/plugin_transport_http_common.c968
1 files changed, 489 insertions, 479 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 902fc5c36..6d3ee3429 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -30,23 +30,23 @@
30#include "gnunet_resolver_service.h" 30#include "gnunet_resolver_service.h"
31 31
32static void 32static void
33http_clean_splitted(struct SplittedHTTPAddress *spa) 33http_clean_splitted (struct SplittedHTTPAddress *spa)
34{ 34{
35 if (NULL != spa) 35 if (NULL != spa)
36 { 36 {
37 GNUNET_free_non_null(spa->protocol); 37 GNUNET_free_non_null (spa->protocol);
38 GNUNET_free_non_null(spa->host); 38 GNUNET_free_non_null (spa->host);
39 GNUNET_free_non_null(spa->path); 39 GNUNET_free_non_null (spa->path);
40 GNUNET_free_non_null(spa); 40 GNUNET_free_non_null (spa);
41 } 41 }
42} 42}
43 43
44 44
45struct SplittedHTTPAddress * 45struct SplittedHTTPAddress *
46http_split_address(const char * addr) 46http_split_address (const char *addr)
47{ 47{
48 struct SplittedHTTPAddress *sp; 48 struct SplittedHTTPAddress *sp;
49 char *src = GNUNET_strdup(addr); 49 char *src = GNUNET_strdup (addr);
50 char *protocol_start = NULL; 50 char *protocol_start = NULL;
51 char *host_start = NULL; 51 char *host_start = NULL;
52 char *v6_end = NULL; 52 char *v6_end = NULL;
@@ -55,128 +55,129 @@ http_split_address(const char * addr)
55 55
56 protocol_start = src; 56 protocol_start = src;
57 57
58 sp = GNUNET_new(struct SplittedHTTPAddress); 58 sp = GNUNET_new (struct SplittedHTTPAddress);
59 /* Address string consists of protocol://host[:port]path*/ 59 /* Address string consists of protocol://host[:port]path*/
60 60
61 host_start = strstr(src, "://"); 61 host_start = strstr (src, "://");
62 if (NULL == host_start) 62 if (NULL == host_start)
63 { 63 {
64 GNUNET_free(src); 64 GNUNET_free (src);
65 GNUNET_free(sp); 65 GNUNET_free (sp);
66 return NULL; 66 return NULL;
67 } 67 }
68 host_start[0] = '\0'; 68 host_start[0] = '\0';
69 sp->protocol = GNUNET_strdup(protocol_start); 69 sp->protocol = GNUNET_strdup (protocol_start);
70 70
71 host_start += strlen("://"); 71 host_start += strlen ("://");
72 if (strlen(host_start) == 0) 72 if (strlen (host_start) == 0)
73 { 73 {
74 GNUNET_free(src); 74 GNUNET_free (src);
75 GNUNET_free(sp->protocol); 75 GNUNET_free (sp->protocol);
76 GNUNET_free(sp); 76 GNUNET_free (sp);
77 return NULL; 77 return NULL;
78 } 78 }
79 79
80 /* Find path start */ 80 /* Find path start */
81 path_start = strchr(host_start, '/'); 81 path_start = strchr (host_start, '/');
82 if (NULL != path_start) 82 if (NULL != path_start)
83 { 83 {
84 sp->path = GNUNET_strdup(path_start); 84 sp->path = GNUNET_strdup (path_start);
85 path_start[0] = '\0'; 85 path_start[0] = '\0';
86 } 86 }
87 else 87 else
88 sp->path = GNUNET_strdup(""); 88 sp->path = GNUNET_strdup ("");
89 89
90 if (strlen(host_start) < 1) 90 if (strlen (host_start) < 1)
91 { 91 {
92 GNUNET_free(src); 92 GNUNET_free (src);
93 GNUNET_free(sp->protocol); 93 GNUNET_free (sp->protocol);
94 GNUNET_free(sp->path); 94 GNUNET_free (sp->path);
95 GNUNET_free(sp); 95 GNUNET_free (sp);
96 return NULL; 96 return NULL;
97 } 97 }
98 98
99 if (NULL != (port_start = strrchr(host_start, ':'))) 99 if (NULL != (port_start = strrchr (host_start, ':')))
100 { 100 {
101 /* *We COULD have a port, but also an IPv6 address! */ 101 /* *We COULD have a port, but also an IPv6 address! */
102 if (NULL != (v6_end = strchr(host_start, ']'))) 102 if (NULL != (v6_end = strchr (host_start, ']')))
103 { 103 {
104 if (v6_end < port_start) 104 if (v6_end < port_start)
105 { 105 {
106 /* IPv6 address + port */ 106 /* IPv6 address + port */
107 port_start[0] = '\0'; 107 port_start[0] = '\0';
108 port_start++; 108 port_start++;
109 sp->port = atoi(port_start); 109 sp->port = atoi (port_start);
110 if ((0 == sp->port) || (65535 < sp->port)) 110 if ((0 == sp->port) || (65535 < sp->port))
111 {
112 GNUNET_free(src);
113 GNUNET_free(sp->protocol);
114 GNUNET_free(sp->path);
115 GNUNET_free(sp);
116 return NULL;
117 }
118 }
119 else
120 {
121 /* IPv6 address + no port */
122 if (0 == strcmp(sp->protocol, "https"))
123 sp->port = HTTPS_DEFAULT_PORT;
124 else if (0 == strcmp(sp->protocol, "http"))
125 sp->port = HTTP_DEFAULT_PORT;
126 }
127 }
128 else
129 {
130 /* No IPv6 address */
131 port_start[0] = '\0';
132 port_start++;
133 sp->port = atoi(port_start);
134 if ((0 == sp->port) || (65535 < sp->port))
135 {
136 GNUNET_free(src);
137 GNUNET_free(sp->protocol);
138 GNUNET_free(sp->path);
139 GNUNET_free(sp);
140 return NULL;
141 }
142 }
143 }
144 else
145 {
146 /* No ':' as port separator, default port for protocol */
147 if (0 == strcmp(sp->protocol, "https"))
148 sp->port = HTTPS_DEFAULT_PORT;
149 else if (0 == strcmp(sp->protocol, "http"))
150 sp->port = HTTP_DEFAULT_PORT;
151 else
152 { 111 {
153 GNUNET_break(0); 112 GNUNET_free (src);
154 GNUNET_free(src); 113 GNUNET_free (sp->protocol);
155 GNUNET_free(sp->protocol); 114 GNUNET_free (sp->path);
156 GNUNET_free(sp->path); 115 GNUNET_free (sp);
157 GNUNET_free(sp);
158 return NULL; 116 return NULL;
159 } 117 }
160 } 118 }
161 if (strlen(host_start) > 0) 119 else
162 sp->host = GNUNET_strdup(host_start); 120 {
121 /* IPv6 address + no port */
122 if (0 == strcmp (sp->protocol, "https"))
123 sp->port = HTTPS_DEFAULT_PORT;
124 else if (0 == strcmp (sp->protocol, "http"))
125 sp->port = HTTP_DEFAULT_PORT;
126 }
127 }
128 else
129 {
130 /* No IPv6 address */
131 port_start[0] = '\0';
132 port_start++;
133 sp->port = atoi (port_start);
134 if ((0 == sp->port) || (65535 < sp->port))
135 {
136 GNUNET_free (src);
137 GNUNET_free (sp->protocol);
138 GNUNET_free (sp->path);
139 GNUNET_free (sp);
140 return NULL;
141 }
142 }
143 }
163 else 144 else
164 { 145 {
165 GNUNET_break(0); 146 /* No ':' as port separator, default port for protocol */
166 GNUNET_free(src); 147 if (0 == strcmp (sp->protocol, "https"))
167 GNUNET_free(sp->protocol); 148 sp->port = HTTPS_DEFAULT_PORT;
168 GNUNET_free(sp->path); 149 else if (0 == strcmp (sp->protocol, "http"))
169 GNUNET_free(sp); 150 sp->port = HTTP_DEFAULT_PORT;
151 else
152 {
153 GNUNET_break (0);
154 GNUNET_free (src);
155 GNUNET_free (sp->protocol);
156 GNUNET_free (sp->path);
157 GNUNET_free (sp);
170 return NULL; 158 return NULL;
171 } 159 }
172 GNUNET_free(src); 160 }
161 if (strlen (host_start) > 0)
162 sp->host = GNUNET_strdup (host_start);
163 else
164 {
165 GNUNET_break (0);
166 GNUNET_free (src);
167 GNUNET_free (sp->protocol);
168 GNUNET_free (sp->path);
169 GNUNET_free (sp);
170 return NULL;
171 }
172 GNUNET_free (src);
173 return sp; 173 return sp;
174} 174}
175 175
176/** 176/**
177 * Closure for #append_port(). 177 * Closure for #append_port().
178 */ 178 */
179struct PrettyPrinterContext { 179struct PrettyPrinterContext
180{
180 /** 181 /**
181 * DLL 182 * DLL
182 */ 183 */
@@ -205,7 +206,7 @@ struct PrettyPrinterContext {
205 /** 206 /**
206 * Timeout task 207 * Timeout task
207 */ 208 */
208 struct GNUNET_SCHEDULER_Task * timeout_task; 209 struct GNUNET_SCHEDULER_Task *timeout_task;
209 210
210 /** 211 /**
211 * Splitted Address 212 * Splitted Address
@@ -251,149 +252,156 @@ static struct PrettyPrinterContext *dll_ppc_tail;
251 * @return string representing the same address or NULL on error 252 * @return string representing the same address or NULL on error
252 */ 253 */
253static const char * 254static const char *
254http_common_plugin_dnsresult_to_address(const char *plugin, 255http_common_plugin_dnsresult_to_address (const char *plugin,
255 const struct SplittedHTTPAddress *saddr, 256 const struct
256 uint32_t options, 257 SplittedHTTPAddress *saddr,
257 const char *dnsresult) 258 uint32_t options,
259 const char *dnsresult)
258{ 260{
259 static char rbuf[1024]; 261 static char rbuf[1024];
260 char *res; 262 char *res;
261 263
262 GNUNET_asprintf(&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol, 264 GNUNET_asprintf (&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol,
263 dnsresult, saddr->port, saddr->path); 265 dnsresult, saddr->port, saddr->path);
264 if (strlen(res) + 1 < 500) 266 if (strlen (res) + 1 < 500)
265 { 267 {
266 GNUNET_memcpy(rbuf, res, strlen(res) + 1); 268 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
267 GNUNET_free(res); 269 GNUNET_free (res);
268 return rbuf; 270 return rbuf;
269 } 271 }
270 GNUNET_break(0); 272 GNUNET_break (0);
271 GNUNET_free(res); 273 GNUNET_free (res);
272 return NULL; 274 return NULL;
273} 275}
274 276
275 277
276static void 278static void
277http_common_dns_reverse_lookup_cb(void *cls, const char *hostname) 279http_common_dns_reverse_lookup_cb (void *cls, const char *hostname)
278{ 280{
279 struct PrettyPrinterContext *ppc = cls; 281 struct PrettyPrinterContext *ppc = cls;
280 282
281 if (NULL != hostname) 283 if (NULL != hostname)
282 { 284 {
283 ppc->asc(ppc->asc_cls, 285 ppc->asc (ppc->asc_cls,
284 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, 286 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
287 ppc->options,
285 hostname), GNUNET_OK); 288 hostname), GNUNET_OK);
286 ppc->sucess = GNUNET_YES; 289 ppc->sucess = GNUNET_YES;
287 } 290 }
288 else 291 else
289 { 292 {
290 ppc->asc(ppc->asc_cls, NULL, 293 ppc->asc (ppc->asc_cls, NULL,
291 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 294 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
292 295
293 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 296 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
294 http_clean_splitted(ppc->saddr); 297 http_clean_splitted (ppc->saddr);
295 GNUNET_free(ppc->plugin); 298 GNUNET_free (ppc->plugin);
296 GNUNET_free(ppc); 299 GNUNET_free (ppc);
297 } 300 }
298} 301}
299 302
300 303
301static int 304static int
302http_common_dns_reverse_lookup(const struct sockaddr *sockaddr, 305http_common_dns_reverse_lookup (const struct sockaddr *sockaddr,
303 socklen_t sockaddr_len, 306 socklen_t sockaddr_len,
304 const char *type, 307 const char *type,
305 struct SplittedHTTPAddress *saddr, 308 struct SplittedHTTPAddress *saddr,
306 uint32_t options, 309 uint32_t options,
307 struct GNUNET_TIME_Relative timeout, 310 struct GNUNET_TIME_Relative timeout,
308 GNUNET_TRANSPORT_AddressStringCallback asc, 311 GNUNET_TRANSPORT_AddressStringCallback asc,
309 void *asc_cls) 312 void *asc_cls)
310{ 313{
311 struct PrettyPrinterContext *ppc; 314 struct PrettyPrinterContext *ppc;
312 315
313 ppc = GNUNET_new(struct PrettyPrinterContext); 316 ppc = GNUNET_new (struct PrettyPrinterContext);
314 ppc->saddr = saddr; 317 ppc->saddr = saddr;
315 ppc->asc = asc; 318 ppc->asc = asc;
316 ppc->asc_cls = asc_cls; 319 ppc->asc_cls = asc_cls;
317 ppc->plugin = GNUNET_strdup(type); 320 ppc->plugin = GNUNET_strdup (type);
318 ppc->options = options; 321 ppc->options = options;
319 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sockaddr, 322 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr,
320 sockaddr_len, 323 sockaddr_len,
321 GNUNET_YES, 324 GNUNET_YES,
322 timeout, 325 timeout,
323 &http_common_dns_reverse_lookup_cb, 326 &
324 ppc); 327 http_common_dns_reverse_lookup_cb,
328 ppc);
325 if (NULL == ppc->resolver_handle) 329 if (NULL == ppc->resolver_handle)
326 { 330 {
327 GNUNET_free(ppc->plugin); 331 GNUNET_free (ppc->plugin);
328 GNUNET_free(ppc); 332 GNUNET_free (ppc);
329 return GNUNET_SYSERR; 333 return GNUNET_SYSERR;
330 } 334 }
331 GNUNET_CONTAINER_DLL_insert(dll_ppc_head, 335 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
332 dll_ppc_tail, 336 dll_ppc_tail,
333 ppc); 337 ppc);
334 return GNUNET_OK; 338 return GNUNET_OK;
335} 339}
336 340
337 341
338static void 342static void
339http_common_dns_ip_lookup_cb(void *cls, 343http_common_dns_ip_lookup_cb (void *cls,
340 const struct sockaddr *addr, 344 const struct sockaddr *addr,
341 socklen_t addrlen) 345 socklen_t addrlen)
342{ 346{
343 struct PrettyPrinterContext *ppc = cls; 347 struct PrettyPrinterContext *ppc = cls;
344 348
345 if (NULL != addr) 349 if (NULL != addr)
346 { 350 {
347 ppc->asc(ppc->asc_cls, 351 ppc->asc (ppc->asc_cls,
348 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options, 352 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
349 GNUNET_a2s(addr, addrlen)), GNUNET_OK); 353 ppc->options,
350 ppc->sucess = GNUNET_YES; 354 GNUNET_a2s (addr,
351 ppc->asc(ppc->asc_cls, GNUNET_a2s(addr, addrlen), GNUNET_OK); 355 addrlen)),
352 } 356 GNUNET_OK);
357 ppc->sucess = GNUNET_YES;
358 ppc->asc (ppc->asc_cls, GNUNET_a2s (addr, addrlen), GNUNET_OK);
359 }
353 else 360 else
354 { 361 {
355 ppc->asc(ppc->asc_cls, NULL, 362 ppc->asc (ppc->asc_cls, NULL,
356 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 363 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
357 364
358 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 365 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
359 GNUNET_free(ppc->plugin); 366 GNUNET_free (ppc->plugin);
360 http_clean_splitted(ppc->saddr); 367 http_clean_splitted (ppc->saddr);
361 GNUNET_free(ppc); 368 GNUNET_free (ppc);
362 } 369 }
363} 370}
364 371
365 372
366static int 373static int
367http_common_dns_ip_lookup(const char *name, 374http_common_dns_ip_lookup (const char *name,
368 const char *type, 375 const char *type,
369 struct SplittedHTTPAddress *saddr, 376 struct SplittedHTTPAddress *saddr,
370 uint32_t options, 377 uint32_t options,
371 struct GNUNET_TIME_Relative timeout, 378 struct GNUNET_TIME_Relative timeout,
372 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 379 GNUNET_TRANSPORT_AddressStringCallback asc,
380 void *asc_cls)
373{ 381{
374 struct PrettyPrinterContext *ppc; 382 struct PrettyPrinterContext *ppc;
375 383
376 ppc = GNUNET_new(struct PrettyPrinterContext); 384 ppc = GNUNET_new (struct PrettyPrinterContext);
377 ppc->sucess = GNUNET_NO; 385 ppc->sucess = GNUNET_NO;
378 ppc->saddr = saddr; 386 ppc->saddr = saddr;
379 ppc->asc = asc; 387 ppc->asc = asc;
380 ppc->asc_cls = asc_cls; 388 ppc->asc_cls = asc_cls;
381 ppc->plugin = GNUNET_strdup(type); 389 ppc->plugin = GNUNET_strdup (type);
382 ppc->options = options; 390 ppc->options = options;
383 ppc->resolver_handle = GNUNET_RESOLVER_ip_get(name, 391 ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name,
384 AF_UNSPEC, 392 AF_UNSPEC,
385 timeout, 393 timeout,
386 &http_common_dns_ip_lookup_cb, 394 &http_common_dns_ip_lookup_cb,
387 ppc); 395 ppc);
388 if (NULL == ppc->resolver_handle) 396 if (NULL == ppc->resolver_handle)
389 { 397 {
390 GNUNET_free(ppc->plugin); 398 GNUNET_free (ppc->plugin);
391 GNUNET_free(ppc); 399 GNUNET_free (ppc);
392 return GNUNET_SYSERR; 400 return GNUNET_SYSERR;
393 } 401 }
394 GNUNET_CONTAINER_DLL_insert(dll_ppc_head, 402 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
395 dll_ppc_tail, 403 dll_ppc_tail,
396 ppc); 404 ppc);
397 return GNUNET_OK; 405 return GNUNET_OK;
398} 406}
399 407
@@ -413,13 +421,14 @@ http_common_dns_ip_lookup(const char *name,
413 * @param asc_cls closure for @a asc 421 * @param asc_cls closure for @a asc
414 */ 422 */
415void 423void
416http_common_plugin_address_pretty_printer(void *cls, const char *type, 424http_common_plugin_address_pretty_printer (void *cls, const char *type,
417 const void *addr, 425 const void *addr,
418 size_t addrlen, 426 size_t addrlen,
419 int numeric, 427 int numeric,
420 struct GNUNET_TIME_Relative timeout, 428 struct GNUNET_TIME_Relative timeout,
421 GNUNET_TRANSPORT_AddressStringCallback asc, 429 GNUNET_TRANSPORT_AddressStringCallback
422 void *asc_cls) 430 asc,
431 void *asc_cls)
423{ 432{
424 const struct HttpAddress *address = addr; 433 const struct HttpAddress *address = addr;
425 struct SplittedHTTPAddress *saddr; 434 struct SplittedHTTPAddress *saddr;
@@ -432,120 +441,120 @@ http_common_plugin_address_pretty_printer(void *cls, const char *type,
432 saddr = NULL; 441 saddr = NULL;
433 sock_addr = NULL; 442 sock_addr = NULL;
434 if ((addrlen < sizeof(struct HttpAddress)) || 443 if ((addrlen < sizeof(struct HttpAddress)) ||
435 (addrlen != http_common_address_get_size(address))) 444 (addrlen != http_common_address_get_size (address)))
436 { 445 {
437 GNUNET_break(0); 446 GNUNET_break (0);
438 goto handle_error; 447 goto handle_error;
439 } 448 }
440 449
441 addr_str = (char *)&address[1]; 450 addr_str = (char *) &address[1];
442 if (addr_str[ntohl(address->urlen) - 1] != '\0') 451 if (addr_str[ntohl (address->urlen) - 1] != '\0')
443 { 452 {
444 GNUNET_break(0); 453 GNUNET_break (0);
445 goto handle_error; 454 goto handle_error;
446 } 455 }
447 456
448 saddr = http_split_address(addr_str); 457 saddr = http_split_address (addr_str);
449 if (NULL == saddr) 458 if (NULL == saddr)
450 { 459 {
451 GNUNET_break(0); 460 GNUNET_break (0);
452 goto handle_error; 461 goto handle_error;
453 } 462 }
454 463
455 sock_addr = http_common_socket_from_address(addr, addrlen, &res); 464 sock_addr = http_common_socket_from_address (addr, addrlen, &res);
456 if (GNUNET_SYSERR == res) 465 if (GNUNET_SYSERR == res)
457 { 466 {
458 /* Malformed address */ 467 /* Malformed address */
459 GNUNET_break(0); 468 GNUNET_break (0);
460 goto handle_error; 469 goto handle_error;
461 } 470 }
462 else if (GNUNET_NO == res) 471 else if (GNUNET_NO == res)
463 { 472 {
464 /* Could not convert to IP */ 473 /* Could not convert to IP */
465 have_ip = GNUNET_NO; 474 have_ip = GNUNET_NO;
466 } 475 }
467 else if (GNUNET_YES == res) 476 else if (GNUNET_YES == res)
468 { 477 {
469 /* Converted to IP */ 478 /* Converted to IP */
470 have_ip = GNUNET_YES; 479 have_ip = GNUNET_YES;
471 } 480 }
472 else 481 else
473 { 482 {
474 /* Must not happen */ 483 /* Must not happen */
475 GNUNET_break(0); 484 GNUNET_break (0);
476 goto handle_error; 485 goto handle_error;
477 } 486 }
478 487
479 if ((GNUNET_YES == numeric) && 488 if ((GNUNET_YES == numeric) &&
480 (GNUNET_YES == have_ip)) 489 (GNUNET_YES == have_ip))
481 { 490 {
482 /* No lookup required */ 491 /* No lookup required */
483 ret = http_common_plugin_address_to_string(type, address, addrlen); 492 ret = http_common_plugin_address_to_string (type, address, addrlen);
484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 493 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
485 asc(asc_cls, NULL, GNUNET_OK); 494 asc (asc_cls, NULL, GNUNET_OK);
486 http_clean_splitted(saddr); 495 http_clean_splitted (saddr);
487 GNUNET_free_non_null(sock_addr); 496 GNUNET_free_non_null (sock_addr);
488 return; 497 return;
489 } 498 }
490 if ((GNUNET_YES == numeric) && 499 if ((GNUNET_YES == numeric) &&
491 (GNUNET_NO == have_ip)) 500 (GNUNET_NO == have_ip))
492 { 501 {
493 /* Forward lookup */ 502 /* Forward lookup */
494 if (GNUNET_SYSERR == 503 if (GNUNET_SYSERR ==
495 http_common_dns_ip_lookup(saddr->host, type, saddr, 504 http_common_dns_ip_lookup (saddr->host, type, saddr,
496 address->options, timeout, 505 address->options, timeout,
497 asc, asc_cls)) 506 asc, asc_cls))
498 { 507 {
499 GNUNET_break(0); 508 GNUNET_break (0);
500 goto handle_error; 509 goto handle_error;
501 }
502 /* Wait for resolver callback */
503 GNUNET_free_non_null(sock_addr);
504 return;
505 } 510 }
511 /* Wait for resolver callback */
512 GNUNET_free_non_null (sock_addr);
513 return;
514 }
506 if ((GNUNET_NO == numeric) && 515 if ((GNUNET_NO == numeric) &&
507 (GNUNET_YES == have_ip)) 516 (GNUNET_YES == have_ip))
508 { 517 {
509 /* Reverse lookup */ 518 /* Reverse lookup */
510 if (GNUNET_SYSERR == 519 if (GNUNET_SYSERR ==
511 http_common_dns_reverse_lookup(sock_addr, 520 http_common_dns_reverse_lookup (sock_addr,
512 (AF_INET == sock_addr->sa_family) 521 (AF_INET == sock_addr->sa_family)
513 ? sizeof(struct sockaddr_in) 522 ? sizeof(struct sockaddr_in)
514 : sizeof(struct sockaddr_in6), 523 : sizeof(struct sockaddr_in6),
515 type, 524 type,
516 saddr, 525 saddr,
517 address->options, timeout, 526 address->options, timeout,
518 asc, asc_cls)) 527 asc, asc_cls))
519 { 528 {
520 GNUNET_break(0); 529 GNUNET_break (0);
521 goto handle_error; 530 goto handle_error;
522 }
523 /* Wait for resolver callback */
524 GNUNET_free_non_null(sock_addr);
525 return;
526 } 531 }
532 /* Wait for resolver callback */
533 GNUNET_free_non_null (sock_addr);
534 return;
535 }
527 if ((GNUNET_NO == numeric) && 536 if ((GNUNET_NO == numeric) &&
528 (GNUNET_NO == have_ip)) 537 (GNUNET_NO == have_ip))
529 { 538 {
530 /* No lookup required */ 539 /* No lookup required */
531 ret = http_common_plugin_address_to_string(type, address, addrlen); 540 ret = http_common_plugin_address_to_string (type, address, addrlen);
532 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 541 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
533 asc(asc_cls, NULL, GNUNET_OK); 542 asc (asc_cls, NULL, GNUNET_OK);
534 GNUNET_free_non_null(sock_addr); 543 GNUNET_free_non_null (sock_addr);
535 http_clean_splitted(saddr); 544 http_clean_splitted (saddr);
536 return; 545 return;
537 } 546 }
538 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */ 547 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */
539 GNUNET_break(0); 548 GNUNET_break (0);
540 goto handle_error; 549 goto handle_error;
541 550
542handle_error: 551handle_error:
543 /* Report error */ 552 /* Report error */
544 asc(asc_cls, NULL, GNUNET_SYSERR); 553 asc (asc_cls, NULL, GNUNET_SYSERR);
545 asc(asc_cls, NULL, GNUNET_OK); 554 asc (asc_cls, NULL, GNUNET_OK);
546 GNUNET_free_non_null(sock_addr); 555 GNUNET_free_non_null (sock_addr);
547 if (NULL != saddr) 556 if (NULL != saddr)
548 http_clean_splitted(saddr); 557 http_clean_splitted (saddr);
549} 558}
550 559
551 560
@@ -553,36 +562,36 @@ handle_error:
553 * FIXME. 562 * FIXME.
554 */ 563 */
555const char * 564const char *
556http_common_plugin_address_to_url(void *cls, 565http_common_plugin_address_to_url (void *cls,
557 const void *addr, 566 const void *addr,
558 size_t addrlen) 567 size_t addrlen)
559{ 568{
560 static char rbuf[1024]; 569 static char rbuf[1024];
561 const struct HttpAddress *address = addr; 570 const struct HttpAddress *address = addr;
562 const char * addr_str; 571 const char *addr_str;
563 572
564 if (NULL == addr) 573 if (NULL == addr)
565 { 574 {
566 GNUNET_break(0); 575 GNUNET_break (0);
567 return NULL; 576 return NULL;
568 } 577 }
569 if (0 == addrlen) 578 if (0 == addrlen)
570 { 579 {
571 GNUNET_break(0); 580 GNUNET_break (0);
572 return NULL; 581 return NULL;
573 } 582 }
574 if (addrlen != http_common_address_get_size(address)) 583 if (addrlen != http_common_address_get_size (address))
575 { 584 {
576 GNUNET_break(0); 585 GNUNET_break (0);
577 return NULL; 586 return NULL;
578 } 587 }
579 addr_str = (char *)&address[1]; 588 addr_str = (char *) &address[1];
580 if (addr_str[ntohl(address->urlen) - 1] != '\0') 589 if (addr_str[ntohl (address->urlen) - 1] != '\0')
581 return NULL; 590 return NULL;
582 591
583 GNUNET_memcpy(rbuf, 592 GNUNET_memcpy (rbuf,
584 &address[1], 593 &address[1],
585 ntohl(address->urlen)); 594 ntohl (address->urlen));
586 return rbuf; 595 return rbuf;
587} 596}
588 597
@@ -599,35 +608,35 @@ http_common_plugin_address_to_url(void *cls,
599 * @return string representing the same address 608 * @return string representing the same address
600 */ 609 */
601const char * 610const char *
602http_common_plugin_address_to_string(const char *plugin, 611http_common_plugin_address_to_string (const char *plugin,
603 const void *addr, 612 const void *addr,
604 size_t addrlen) 613 size_t addrlen)
605{ 614{
606 static char rbuf[1024]; 615 static char rbuf[1024];
607 const struct HttpAddress *address = addr; 616 const struct HttpAddress *address = addr;
608 const char * addr_str; 617 const char *addr_str;
609 char *res; 618 char *res;
610 619
611 GNUNET_assert(NULL != plugin); 620 GNUNET_assert (NULL != plugin);
612 if (NULL == addr) 621 if (NULL == addr)
613 return NULL; 622 return NULL;
614 if (0 == addrlen) 623 if (0 == addrlen)
615 return NULL; 624 return NULL;
616 if (addrlen != http_common_address_get_size(address)) 625 if (addrlen != http_common_address_get_size (address))
617 return NULL; 626 return NULL;
618 addr_str = (char *)&address[1]; 627 addr_str = (char *) &address[1];
619 if (addr_str[ntohl(address->urlen) - 1] != '\0') 628 if (addr_str[ntohl (address->urlen) - 1] != '\0')
620 return NULL; 629 return NULL;
621 GNUNET_asprintf(&res, "%s.%u.%s", plugin, ntohl(address->options), 630 GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options),
622 &address[1]); 631 &address[1]);
623 if (strlen(res) + 1 < 500) 632 if (strlen (res) + 1 < 500)
624 { 633 {
625 GNUNET_memcpy(rbuf, res, strlen(res) + 1); 634 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
626 GNUNET_free(res); 635 GNUNET_free (res);
627 return rbuf; 636 return rbuf;
628 } 637 }
629 GNUNET_break(0); 638 GNUNET_break (0);
630 GNUNET_free(res); 639 GNUNET_free (res);
631 return NULL; 640 return NULL;
632} 641}
633 642
@@ -644,11 +653,11 @@ http_common_plugin_address_to_string(const char *plugin,
644 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 653 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
645 */ 654 */
646int 655int
647http_common_plugin_string_to_address(void *cls, 656http_common_plugin_string_to_address (void *cls,
648 const char *addr, 657 const char *addr,
649 uint16_t addrlen, 658 uint16_t addrlen,
650 void **buf, 659 void **buf,
651 size_t *added) 660 size_t *added)
652{ 661{
653 struct HttpAddress *a; 662 struct HttpAddress *a;
654 char *address; 663 char *address;
@@ -662,50 +671,50 @@ http_common_plugin_string_to_address(void *cls,
662 plugin = NULL; 671 plugin = NULL;
663 optionstr = NULL; 672 optionstr = NULL;
664 if ((NULL == addr) || (addrlen == 0)) 673 if ((NULL == addr) || (addrlen == 0))
665 { 674 {
666 GNUNET_break(0); 675 GNUNET_break (0);
667 return GNUNET_SYSERR; 676 return GNUNET_SYSERR;
668 } 677 }
669 if ('\0' != addr[addrlen - 1]) 678 if ('\0' != addr[addrlen - 1])
670 { 679 {
671 GNUNET_break(0); 680 GNUNET_break (0);
672 return GNUNET_SYSERR; 681 return GNUNET_SYSERR;
673 } 682 }
674 if (strlen(addr) != addrlen - 1) 683 if (strlen (addr) != addrlen - 1)
675 { 684 {
676 GNUNET_break(0); 685 GNUNET_break (0);
677 return GNUNET_SYSERR; 686 return GNUNET_SYSERR;
678 } 687 }
679 plugin = GNUNET_strdup(addr); 688 plugin = GNUNET_strdup (addr);
680 optionstr = strchr(plugin, '.'); 689 optionstr = strchr (plugin, '.');
681 if (NULL == optionstr) 690 if (NULL == optionstr)
682 { 691 {
683 GNUNET_break(0); 692 GNUNET_break (0);
684 GNUNET_free(plugin); 693 GNUNET_free (plugin);
685 return GNUNET_SYSERR; 694 return GNUNET_SYSERR;
686 } 695 }
687 optionstr[0] = '\0'; 696 optionstr[0] = '\0';
688 optionstr++; 697 optionstr++;
689 options = atol(optionstr); /* 0 on conversion error, that's ok */ 698 options = atol (optionstr); /* 0 on conversion error, that's ok */
690 address = strchr(optionstr, '.'); 699 address = strchr (optionstr, '.');
691 if (NULL == address) 700 if (NULL == address)
692 { 701 {
693 GNUNET_break(0); 702 GNUNET_break (0);
694 GNUNET_free(plugin); 703 GNUNET_free (plugin);
695 return GNUNET_SYSERR; 704 return GNUNET_SYSERR;
696 } 705 }
697 address[0] = '\0'; 706 address[0] = '\0';
698 address++; 707 address++;
699 urlen = strlen(address) + 1; 708 urlen = strlen (address) + 1;
700 709
701 a = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); 710 a = GNUNET_malloc (sizeof(struct HttpAddress) + urlen);
702 a->options = htonl(options); 711 a->options = htonl (options);
703 a->urlen = htonl(urlen); 712 a->urlen = htonl (urlen);
704 GNUNET_memcpy(&a[1], address, urlen); 713 GNUNET_memcpy (&a[1], address, urlen);
705 714
706 (*buf) = a; 715 (*buf) = a;
707 (*added) = sizeof(struct HttpAddress) + urlen; 716 (*added) = sizeof(struct HttpAddress) + urlen;
708 GNUNET_free(plugin); 717 GNUNET_free (plugin);
709 return GNUNET_OK; 718 return GNUNET_OK;
710} 719}
711 720
@@ -719,25 +728,25 @@ http_common_plugin_string_to_address(void *cls,
719 * @return the HttpAddress 728 * @return the HttpAddress
720 */ 729 */
721struct HttpAddress * 730struct HttpAddress *
722http_common_address_from_socket(const char *protocol, 731http_common_address_from_socket (const char *protocol,
723 const struct sockaddr *addr, 732 const struct sockaddr *addr,
724 socklen_t addrlen) 733 socklen_t addrlen)
725{ 734{
726 struct HttpAddress *address = NULL; 735 struct HttpAddress *address = NULL;
727 char *res; 736 char *res;
728 size_t len; 737 size_t len;
729 738
730 GNUNET_asprintf(&res, 739 GNUNET_asprintf (&res,
731 "%s://%s", 740 "%s://%s",
732 protocol, 741 protocol,
733 GNUNET_a2s(addr, 742 GNUNET_a2s (addr,
734 addrlen)); 743 addrlen));
735 len = strlen(res) + 1; 744 len = strlen (res) + 1;
736 address = GNUNET_malloc(sizeof(struct HttpAddress) + len); 745 address = GNUNET_malloc (sizeof(struct HttpAddress) + len);
737 address->options = htonl(HTTP_OPTIONS_NONE); 746 address->options = htonl (HTTP_OPTIONS_NONE);
738 address->urlen = htonl(len); 747 address->urlen = htonl (len);
739 GNUNET_memcpy(&address[1], res, len); 748 GNUNET_memcpy (&address[1], res, len);
740 GNUNET_free(res); 749 GNUNET_free (res);
741 return address; 750 return address;
742} 751}
743 752
@@ -754,79 +763,79 @@ http_common_address_from_socket(const char *protocol,
754 * @return the string 763 * @return the string
755 */ 764 */
756struct sockaddr * 765struct sockaddr *
757http_common_socket_from_address(const void *addr, 766http_common_socket_from_address (const void *addr,
758 size_t addrlen, 767 size_t addrlen,
759 int *res) 768 int *res)
760{ 769{
761 const struct HttpAddress *ha; 770 const struct HttpAddress *ha;
762 struct SplittedHTTPAddress * spa; 771 struct SplittedHTTPAddress *spa;
763 struct sockaddr_storage *s; 772 struct sockaddr_storage *s;
764 char * to_conv; 773 char *to_conv;
765 size_t urlen; 774 size_t urlen;
766 775
767 (*res) = GNUNET_SYSERR; 776 (*res) = GNUNET_SYSERR;
768 ha = (const struct HttpAddress *)addr; 777 ha = (const struct HttpAddress *) addr;
769 if (NULL == addr) 778 if (NULL == addr)
770 { 779 {
771 GNUNET_break(0); 780 GNUNET_break (0);
772 return NULL; 781 return NULL;
773 } 782 }
774 if (0 == addrlen) 783 if (0 == addrlen)
775 { 784 {
776 GNUNET_break(0); 785 GNUNET_break (0);
777 return NULL; 786 return NULL;
778 } 787 }
779 if (addrlen < sizeof(struct HttpAddress)) 788 if (addrlen < sizeof(struct HttpAddress))
780 { 789 {
781 GNUNET_break(0); 790 GNUNET_break (0);
782 return NULL; 791 return NULL;
783 } 792 }
784 urlen = ntohl(ha->urlen); 793 urlen = ntohl (ha->urlen);
785 if (sizeof(struct HttpAddress) + urlen != addrlen) 794 if (sizeof(struct HttpAddress) + urlen != addrlen)
786 { 795 {
787 /* This is a legacy addresses */ 796 /* This is a legacy addresses */
788 return NULL; 797 return NULL;
789 } 798 }
790 if (addrlen < sizeof(struct HttpAddress) + urlen) 799 if (addrlen < sizeof(struct HttpAddress) + urlen)
791 { 800 {
792 /* This is a legacy addresses */ 801 /* This is a legacy addresses */
793 return NULL; 802 return NULL;
794 } 803 }
795 if (((char *)addr)[addrlen - 1] != '\0') 804 if (((char *) addr)[addrlen - 1] != '\0')
796 { 805 {
797 GNUNET_break(0); 806 GNUNET_break (0);
798 return NULL; 807 return NULL;
799 } 808 }
800 spa = http_split_address((const char *)&ha[1]); 809 spa = http_split_address ((const char *) &ha[1]);
801 if (NULL == spa) 810 if (NULL == spa)
802 { 811 {
803 (*res) = GNUNET_SYSERR; 812 (*res) = GNUNET_SYSERR;
804 return NULL; 813 return NULL;
805 } 814 }
806 815
807 s = GNUNET_new(struct sockaddr_storage); 816 s = GNUNET_new (struct sockaddr_storage);
808 GNUNET_asprintf(&to_conv, "%s:%u", spa->host, spa->port); 817 GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port);
809 if (GNUNET_SYSERR 818 if (GNUNET_SYSERR
810 == GNUNET_STRINGS_to_address_ip(to_conv, strlen(to_conv), s)) 819 == GNUNET_STRINGS_to_address_ip (to_conv, strlen (to_conv), s))
811 { 820 {
812 /* could be a hostname */ 821 /* could be a hostname */
813 GNUNET_free(s); 822 GNUNET_free (s);
814 (*res) = GNUNET_NO; 823 (*res) = GNUNET_NO;
815 s = NULL; 824 s = NULL;
816 } 825 }
817 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) 826 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
818 { 827 {
819 GNUNET_free(s); 828 GNUNET_free (s);
820 (*res) = GNUNET_SYSERR; 829 (*res) = GNUNET_SYSERR;
821 s = NULL; 830 s = NULL;
822 } 831 }
823 else 832 else
824 { 833 {
825 (*res) = GNUNET_YES; 834 (*res) = GNUNET_YES;
826 } 835 }
827 http_clean_splitted(spa); 836 http_clean_splitted (spa);
828 GNUNET_free(to_conv); 837 GNUNET_free (to_conv);
829 return (struct sockaddr *)s; 838 return (struct sockaddr *) s;
830} 839}
831 840
832 841
@@ -837,9 +846,9 @@ http_common_socket_from_address(const void *addr,
837 * @return the size 846 * @return the size
838 */ 847 */
839size_t 848size_t
840http_common_address_get_size(const struct HttpAddress * addr) 849http_common_address_get_size (const struct HttpAddress *addr)
841{ 850{
842 return sizeof(struct HttpAddress) + ntohl(addr->urlen); 851 return sizeof(struct HttpAddress) + ntohl (addr->urlen);
843} 852}
844 853
845 854
@@ -853,18 +862,18 @@ http_common_address_get_size(const struct HttpAddress * addr)
853 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error 862 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error
854 */ 863 */
855size_t 864size_t
856http_common_cmp_addresses(const void *addr1, 865http_common_cmp_addresses (const void *addr1,
857 size_t addrlen1, 866 size_t addrlen1,
858 const void *addr2, 867 const void *addr2,
859 size_t addrlen2) 868 size_t addrlen2)
860{ 869{
861 const char *a1 = addr1; 870 const char *a1 = addr1;
862 const char *a2 = addr2; 871 const char *a2 = addr2;
863 const struct HttpAddress *ha1; 872 const struct HttpAddress *ha1;
864 const struct HttpAddress *ha2; 873 const struct HttpAddress *ha2;
865 874
866 ha1 = (const struct HttpAddress *)a1; 875 ha1 = (const struct HttpAddress *) a1;
867 ha2 = (const struct HttpAddress *)a2; 876 ha2 = (const struct HttpAddress *) a2;
868 877
869 if (NULL == a1) 878 if (NULL == a1)
870 return GNUNET_SYSERR; 879 return GNUNET_SYSERR;
@@ -885,7 +894,7 @@ http_common_cmp_addresses(const void *addr1,
885 if (ha1->urlen != ha2->urlen) 894 if (ha1->urlen != ha2->urlen)
886 return GNUNET_NO; 895 return GNUNET_NO;
887 896
888 if (0 == strcmp((const char *)&ha1[1], (const char *)&ha2[1])) 897 if (0 == strcmp ((const char *) &ha1[1], (const char *) &ha2[1]))
889 return GNUNET_YES; 898 return GNUNET_YES;
890 return GNUNET_NO; 899 return GNUNET_NO;
891} 900}
@@ -899,8 +908,9 @@ http_common_cmp_addresses(const void *addr1,
899 * @return the network type 908 * @return the network type
900 */ 909 */
901enum GNUNET_NetworkType 910enum GNUNET_NetworkType
902http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, 911http_common_get_network_for_address (struct
903 const struct GNUNET_HELLO_Address *address) 912 GNUNET_TRANSPORT_PluginEnvironment *env,
913 const struct GNUNET_HELLO_Address *address)
904{ 914{
905 struct sockaddr *sa; 915 struct sockaddr *sa;
906 enum GNUNET_NetworkType net_type; 916 enum GNUNET_NetworkType net_type;
@@ -908,27 +918,27 @@ http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *e
908 int res; 918 int res;
909 919
910 net_type = GNUNET_NT_UNSPECIFIED; 920 net_type = GNUNET_NT_UNSPECIFIED;
911 sa = http_common_socket_from_address(address->address, 921 sa = http_common_socket_from_address (address->address,
912 address->address_length, 922 address->address_length,
913 &res); 923 &res);
914 if (GNUNET_SYSERR == res) 924 if (GNUNET_SYSERR == res)
915 return net_type; 925 return net_type;
916 if (GNUNET_YES == res) 926 if (GNUNET_YES == res)
927 {
928 GNUNET_assert (NULL != sa);
929 if (AF_INET == sa->sa_family)
917 { 930 {
918 GNUNET_assert(NULL != sa); 931 salen = sizeof(struct sockaddr_in);
919 if (AF_INET == sa->sa_family) 932 }
920 { 933 else if (AF_INET6 == sa->sa_family)
921 salen = sizeof(struct sockaddr_in); 934 {
922 } 935 salen = sizeof(struct sockaddr_in6);
923 else if (AF_INET6 == sa->sa_family)
924 {
925 salen = sizeof(struct sockaddr_in6);
926 }
927 net_type = env->get_address_type(env->cls,
928 sa,
929 salen);
930 GNUNET_free(sa);
931 } 936 }
937 net_type = env->get_address_type (env->cls,
938 sa,
939 salen);
940 GNUNET_free (sa);
941 }
932 return net_type; 942 return net_type;
933} 943}
934 944