aboutsummaryrefslogtreecommitdiff
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.c903
1 files changed, 0 insertions, 903 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
deleted file mode 100644
index 40353daeb..000000000
--- a/src/transport/plugin_transport_http_common.c
+++ /dev/null
@@ -1,903 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2002-2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/plugin_transport_http_common.c
23 * @brief functionality shared between http(s)client plugins
24 * @author Matthias Wachs
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_transport_plugin.h"
29#include "plugin_transport_http_common.h"
30#include "gnunet_resolver_service.h"
31
32static void
33http_clean_splitted (struct SplittedHTTPAddress *spa)
34{
35 if (NULL != spa)
36 {
37 GNUNET_free (spa->protocol);
38 GNUNET_free (spa->host);
39 GNUNET_free (spa->path);
40 GNUNET_free (spa);
41 }
42}
43
44
45struct SplittedHTTPAddress *
46http_split_address (const char *addr)
47{
48 struct SplittedHTTPAddress *sp;
49 char *src = GNUNET_strdup (addr);
50 char *protocol_start = NULL;
51 char *host_start = NULL;
52 char *v6_end = NULL;
53 char *port_start = NULL;
54 char *path_start = NULL;
55
56 protocol_start = src;
57
58 sp = GNUNET_new (struct SplittedHTTPAddress);
59 /* Address string consists of protocol://host[:port]path*/
60
61 host_start = strstr (src, "://");
62 if (NULL == host_start)
63 {
64 GNUNET_free (src);
65 GNUNET_free (sp);
66 return NULL;
67 }
68 host_start[0] = '\0';
69 sp->protocol = GNUNET_strdup (protocol_start);
70
71 host_start += strlen ("://");
72 if (strlen (host_start) == 0)
73 {
74 GNUNET_free (src);
75 GNUNET_free (sp->protocol);
76 GNUNET_free (sp);
77 return NULL;
78 }
79
80 /* Find path start */
81 path_start = strchr (host_start, '/');
82 if (NULL != path_start)
83 {
84 sp->path = GNUNET_strdup (path_start);
85 path_start[0] = '\0';
86 }
87 else
88 sp->path = GNUNET_strdup ("");
89
90 if (strlen (host_start) < 1)
91 {
92 GNUNET_free (src);
93 GNUNET_free (sp->protocol);
94 GNUNET_free (sp->path);
95 GNUNET_free (sp);
96 return NULL;
97 }
98
99 if (NULL != (port_start = strrchr (host_start, ':')))
100 {
101 /* *We COULD have a port, but also an IPv6 address! */
102 if (NULL != (v6_end = strchr (host_start, ']')))
103 {
104 if (v6_end < port_start)
105 {
106 /* IPv6 address + port */
107 port_start[0] = '\0';
108 port_start++;
109 sp->port = atoi (port_start);
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 {
153 GNUNET_break (0);
154 GNUNET_free (src);
155 GNUNET_free (sp->protocol);
156 GNUNET_free (sp->path);
157 GNUNET_free (sp);
158 return NULL;
159 }
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;
174}
175
176
177/**
178 * Closure for #append_port().
179 */
180struct PrettyPrinterContext
181{
182 /**
183 * DLL
184 */
185 struct PrettyPrinterContext *next;
186
187 /**
188 * DLL
189 */
190 struct PrettyPrinterContext *prev;
191
192 /**
193 * Resolver handle
194 */
195 struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
196
197 /**
198 * Function to call with the result.
199 */
200 GNUNET_TRANSPORT_AddressStringCallback asc;
201
202 /**
203 * Clsoure for @e asc.
204 */
205 void *asc_cls;
206
207 /**
208 * Timeout task
209 */
210 struct GNUNET_SCHEDULER_Task *timeout_task;
211
212 /**
213 * Split Address
214 */
215 struct SplittedHTTPAddress *saddr;
216
217 /**
218 * Plugin String
219 */
220 char *plugin;
221
222 /**
223 * Was conversion successful
224 */
225 int success;
226
227 /**
228 * Address options
229 */
230 uint32_t options;
231};
232
233/**
234 * Head of PPC list
235 */
236static struct PrettyPrinterContext *dll_ppc_head;
237
238/**
239 * Tail of PPC list
240 */
241static struct PrettyPrinterContext *dll_ppc_tail;
242
243/**
244 * Function called for a quick conversion of the binary address to
245 * a numeric address. Note that the caller must not free the
246 * address and that the next call to this function is allowed
247 * to override the address again.
248 *
249 * @param plugin the name of the plugin
250 * @param saddr the split http address
251 * @param options address options
252 * @param dnsresult dns name to include in address
253 * @return string representing the same address or NULL on error
254 */
255static const char *
256http_common_plugin_dnsresult_to_address (const char *plugin,
257 const struct
258 SplittedHTTPAddress *saddr,
259 uint32_t options,
260 const char *dnsresult)
261{
262 static char rbuf[1024];
263 char *res;
264
265 GNUNET_asprintf (&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol,
266 dnsresult, saddr->port, saddr->path);
267 if (strlen (res) + 1 < 500)
268 {
269 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
270 GNUNET_free (res);
271 return rbuf;
272 }
273 GNUNET_break (0);
274 GNUNET_free (res);
275 return NULL;
276}
277
278
279static void
280http_common_dns_reverse_lookup_cb (void *cls, const char *hostname)
281{
282 struct PrettyPrinterContext *ppc = cls;
283
284 if (NULL != hostname)
285 {
286 ppc->asc (ppc->asc_cls,
287 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
288 ppc->options,
289 hostname), GNUNET_OK);
290 ppc->success = GNUNET_YES;
291 }
292 else
293 {
294 ppc->asc (ppc->asc_cls, NULL,
295 (GNUNET_NO == ppc->success) ? GNUNET_SYSERR : GNUNET_OK);
296
297 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
298 http_clean_splitted (ppc->saddr);
299 GNUNET_free (ppc->plugin);
300 GNUNET_free (ppc);
301 }
302}
303
304
305static int
306http_common_dns_reverse_lookup (const struct sockaddr *sockaddr,
307 socklen_t sockaddr_len,
308 const char *type,
309 struct SplittedHTTPAddress *saddr,
310 uint32_t options,
311 struct GNUNET_TIME_Relative timeout,
312 GNUNET_TRANSPORT_AddressStringCallback asc,
313 void *asc_cls)
314{
315 struct PrettyPrinterContext *ppc;
316
317 ppc = GNUNET_new (struct PrettyPrinterContext);
318 ppc->saddr = saddr;
319 ppc->asc = asc;
320 ppc->asc_cls = asc_cls;
321 ppc->plugin = GNUNET_strdup (type);
322 ppc->options = options;
323 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr,
324 sockaddr_len,
325 GNUNET_YES,
326 timeout,
327 &
328 http_common_dns_reverse_lookup_cb,
329 ppc);
330 if (NULL == ppc->resolver_handle)
331 {
332 GNUNET_free (ppc->plugin);
333 GNUNET_free (ppc);
334 return GNUNET_SYSERR;
335 }
336 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
337 dll_ppc_tail,
338 ppc);
339 return GNUNET_OK;
340}
341
342
343static void
344http_common_dns_ip_lookup_cb (void *cls,
345 const struct sockaddr *addr,
346 socklen_t addrlen)
347{
348 struct PrettyPrinterContext *ppc = cls;
349
350 if (NULL != addr)
351 {
352 ppc->asc (ppc->asc_cls,
353 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr,
354 ppc->options,
355 GNUNET_a2s (addr,
356 addrlen)),
357 GNUNET_OK);
358 ppc->success = GNUNET_YES;
359 ppc->asc (ppc->asc_cls, GNUNET_a2s (addr, addrlen), GNUNET_OK);
360 }
361 else
362 {
363 ppc->asc (ppc->asc_cls, NULL,
364 (GNUNET_NO == ppc->success) ? GNUNET_SYSERR : GNUNET_OK);
365
366 GNUNET_CONTAINER_DLL_remove (dll_ppc_head, dll_ppc_tail, ppc);
367 GNUNET_free (ppc->plugin);
368 http_clean_splitted (ppc->saddr);
369 GNUNET_free (ppc);
370 }
371}
372
373
374static int
375http_common_dns_ip_lookup (const char *name,
376 const char *type,
377 struct SplittedHTTPAddress *saddr,
378 uint32_t options,
379 struct GNUNET_TIME_Relative timeout,
380 GNUNET_TRANSPORT_AddressStringCallback asc,
381 void *asc_cls)
382{
383 struct PrettyPrinterContext *ppc;
384
385 ppc = GNUNET_new (struct PrettyPrinterContext);
386 ppc->success = GNUNET_NO;
387 ppc->saddr = saddr;
388 ppc->asc = asc;
389 ppc->asc_cls = asc_cls;
390 ppc->plugin = GNUNET_strdup (type);
391 ppc->options = options;
392 ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name,
393 AF_UNSPEC,
394 timeout,
395 &http_common_dns_ip_lookup_cb,
396 ppc);
397 if (NULL == ppc->resolver_handle)
398 {
399 GNUNET_free (ppc->plugin);
400 GNUNET_free (ppc);
401 return GNUNET_SYSERR;
402 }
403 GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
404 dll_ppc_tail,
405 ppc);
406 return GNUNET_OK;
407}
408
409
410void
411http_common_plugin_address_pretty_printer (void *cls, const char *type,
412 const void *addr,
413 size_t addrlen,
414 int numeric,
415 struct GNUNET_TIME_Relative timeout,
416 GNUNET_TRANSPORT_AddressStringCallback
417 asc,
418 void *asc_cls)
419{
420 const struct HttpAddress *address = addr;
421 struct SplittedHTTPAddress *saddr;
422 struct sockaddr *sock_addr;
423 const char *ret;
424 char *addr_str;
425 int res;
426 int have_ip;
427
428 saddr = NULL;
429 sock_addr = NULL;
430 if ((addrlen < sizeof(struct HttpAddress)) ||
431 (addrlen != http_common_address_get_size (address)))
432 {
433 GNUNET_break (0);
434 goto handle_error;
435 }
436
437 addr_str = (char *) &address[1];
438 if (addr_str[ntohl (address->urlen) - 1] != '\0')
439 {
440 GNUNET_break (0);
441 goto handle_error;
442 }
443
444 saddr = http_split_address (addr_str);
445 if (NULL == saddr)
446 {
447 GNUNET_break (0);
448 goto handle_error;
449 }
450
451 sock_addr = http_common_socket_from_address (addr, addrlen, &res);
452 if (GNUNET_SYSERR == res)
453 {
454 /* Malformed address */
455 GNUNET_break (0);
456 goto handle_error;
457 }
458 else if (GNUNET_NO == res)
459 {
460 /* Could not convert to IP */
461 have_ip = GNUNET_NO;
462 }
463 else if (GNUNET_YES == res)
464 {
465 /* Converted to IP */
466 have_ip = GNUNET_YES;
467 }
468 else
469 {
470 /* Must not happen */
471 GNUNET_break (0);
472 goto handle_error;
473 }
474
475 if ((GNUNET_YES == numeric) &&
476 (GNUNET_YES == have_ip))
477 {
478 /* No lookup required */
479 ret = http_common_plugin_address_to_string (type, address, addrlen);
480 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
481 asc (asc_cls, NULL, GNUNET_OK);
482 http_clean_splitted (saddr);
483 GNUNET_free (sock_addr);
484 return;
485 }
486 if ((GNUNET_YES == numeric) &&
487 (GNUNET_NO == have_ip))
488 {
489 /* Forward lookup */
490 if (GNUNET_SYSERR ==
491 http_common_dns_ip_lookup (saddr->host, type, saddr,
492 address->options, timeout,
493 asc, asc_cls))
494 {
495 GNUNET_break (0);
496 goto handle_error;
497 }
498 /* Wait for resolver callback */
499 GNUNET_free (sock_addr);
500 return;
501 }
502 if ((GNUNET_NO == numeric) &&
503 (GNUNET_YES == have_ip))
504 {
505 /* Reverse lookup */
506 if (GNUNET_SYSERR ==
507 http_common_dns_reverse_lookup (sock_addr,
508 (AF_INET == sock_addr->sa_family)
509 ? sizeof(struct sockaddr_in)
510 : sizeof(struct sockaddr_in6),
511 type,
512 saddr,
513 address->options, timeout,
514 asc, asc_cls))
515 {
516 GNUNET_break (0);
517 goto handle_error;
518 }
519 /* Wait for resolver callback */
520 GNUNET_free (sock_addr);
521 return;
522 }
523 if ((GNUNET_NO == numeric) &&
524 (GNUNET_NO == have_ip))
525 {
526 /* No lookup required */
527 ret = http_common_plugin_address_to_string (type, address, addrlen);
528 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
529 asc (asc_cls, NULL, GNUNET_OK);
530 GNUNET_free (sock_addr);
531 http_clean_splitted (saddr);
532 return;
533 }
534 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */
535 GNUNET_break (0);
536 goto handle_error;
537
538handle_error:
539 /* Report error */
540 asc (asc_cls, NULL, GNUNET_SYSERR);
541 asc (asc_cls, NULL, GNUNET_OK);
542 GNUNET_free (sock_addr);
543 if (NULL != saddr)
544 http_clean_splitted (saddr);
545}
546
547
548/**
549 * FIXME.
550 */
551const char *
552http_common_plugin_address_to_url (void *cls,
553 const void *addr,
554 size_t addrlen)
555{
556 static char rbuf[1024];
557 const struct HttpAddress *address = addr;
558 const char *addr_str;
559
560 if (NULL == addr)
561 {
562 GNUNET_break (0);
563 return NULL;
564 }
565 if (0 == addrlen)
566 {
567 GNUNET_break (0);
568 return NULL;
569 }
570 if (addrlen != http_common_address_get_size (address))
571 {
572 GNUNET_break (0);
573 return NULL;
574 }
575 addr_str = (char *) &address[1];
576 if (addr_str[ntohl (address->urlen) - 1] != '\0')
577 return NULL;
578
579 GNUNET_memcpy (rbuf,
580 &address[1],
581 ntohl (address->urlen));
582 return rbuf;
583}
584
585
586const char *
587http_common_plugin_address_to_string (const char *plugin,
588 const void *addr,
589 size_t addrlen)
590{
591 static char rbuf[1024];
592 const struct HttpAddress *address = addr;
593 const char *addr_str;
594 char *res;
595
596 GNUNET_assert (NULL != plugin);
597 if (NULL == addr)
598 return NULL;
599 if (0 == addrlen)
600 return NULL;
601 if (addrlen != http_common_address_get_size (address))
602 return NULL;
603 addr_str = (char *) &address[1];
604 if (addr_str[ntohl (address->urlen) - 1] != '\0')
605 return NULL;
606 GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options),
607 (char*)&address[1]);
608 if (strlen (res) + 1 < 500)
609 {
610 GNUNET_memcpy (rbuf, res, strlen (res) + 1);
611 GNUNET_free (res);
612 return rbuf;
613 }
614 GNUNET_break (0);
615 GNUNET_free (res);
616 return NULL;
617}
618
619
620int
621http_common_plugin_string_to_address (void *cls,
622 const char *addr,
623 uint16_t addrlen,
624 void **buf,
625 size_t *added)
626{
627 struct HttpAddress *a;
628 char *address;
629 char *plugin;
630 char *optionstr;
631 size_t urlen;
632 uint32_t options;
633
634 /* Format protocol.options.address:port */
635 address = NULL;
636 plugin = NULL;
637 optionstr = NULL;
638 if ((NULL == addr) || (addrlen == 0))
639 {
640 GNUNET_break (0);
641 return GNUNET_SYSERR;
642 }
643 if ('\0' != addr[addrlen - 1])
644 {
645 GNUNET_break (0);
646 return GNUNET_SYSERR;
647 }
648 if (strlen (addr) != addrlen - 1)
649 {
650 GNUNET_break (0);
651 return GNUNET_SYSERR;
652 }
653 plugin = GNUNET_strdup (addr);
654 optionstr = strchr (plugin, '.');
655 if (NULL == optionstr)
656 {
657 GNUNET_break (0);
658 GNUNET_free (plugin);
659 return GNUNET_SYSERR;
660 }
661 optionstr[0] = '\0';
662 optionstr++;
663 options = atol (optionstr); /* 0 on conversion error, that's ok */
664 address = strchr (optionstr, '.');
665 if (NULL == address)
666 {
667 GNUNET_break (0);
668 GNUNET_free (plugin);
669 return GNUNET_SYSERR;
670 }
671 address[0] = '\0';
672 address++;
673 urlen = strlen (address) + 1;
674
675 a = GNUNET_malloc (sizeof(struct HttpAddress) + urlen);
676 a->options = htonl (options);
677 a->urlen = htonl (urlen);
678 GNUNET_memcpy (&a[1], address, urlen);
679
680 (*buf) = a;
681 (*added) = sizeof(struct HttpAddress) + urlen;
682 GNUNET_free (plugin);
683 return GNUNET_OK;
684}
685
686
687struct HttpAddress *
688http_common_address_from_socket (const char *protocol,
689 const struct sockaddr *addr,
690 socklen_t addrlen)
691{
692 struct HttpAddress *address = NULL;
693 char *res;
694 size_t len;
695
696 GNUNET_asprintf (&res,
697 "%s://%s",
698 protocol,
699 GNUNET_a2s (addr,
700 addrlen));
701 len = strlen (res) + 1;
702 address = GNUNET_malloc (sizeof(struct HttpAddress) + len);
703 address->options = htonl (HTTP_OPTIONS_NONE);
704 address->urlen = htonl (len);
705 GNUNET_memcpy (&address[1], res, len);
706 GNUNET_free (res);
707 return address;
708}
709
710
711/**
712 * Create a socketaddr from a HTTP address
713 *
714 * @param addr a `sockaddr *` address
715 * @param addrlen length of the @a addr
716 * @param res the result:
717 * #GNUNET_SYSERR, invalid input,
718 * #GNUNET_YES: could convert to ip,
719 * #GNUNET_NO: valid input but could not convert to ip (hostname?)
720 * @return the string
721 */
722struct sockaddr *
723http_common_socket_from_address (const void *addr,
724 size_t addrlen,
725 int *res)
726{
727 const struct HttpAddress *ha;
728 struct SplittedHTTPAddress *spa;
729 struct sockaddr_storage *s;
730 char *to_conv;
731 size_t urlen;
732
733 (*res) = GNUNET_SYSERR;
734 ha = (const struct HttpAddress *) addr;
735 if (NULL == addr)
736 {
737 GNUNET_break (0);
738 return NULL;
739 }
740 if (0 == addrlen)
741 {
742 GNUNET_break (0);
743 return NULL;
744 }
745 if (addrlen < sizeof(struct HttpAddress))
746 {
747 GNUNET_break (0);
748 return NULL;
749 }
750 urlen = ntohl (ha->urlen);
751 if (sizeof(struct HttpAddress) + urlen != addrlen)
752 {
753 /* This is a legacy addresses */
754 return NULL;
755 }
756 if (addrlen < sizeof(struct HttpAddress) + urlen)
757 {
758 /* This is a legacy addresses */
759 return NULL;
760 }
761 if (((char *) addr)[addrlen - 1] != '\0')
762 {
763 GNUNET_break (0);
764 return NULL;
765 }
766 spa = http_split_address ((const char *) &ha[1]);
767 if (NULL == spa)
768 {
769 (*res) = GNUNET_SYSERR;
770 return NULL;
771 }
772
773 s = GNUNET_new (struct sockaddr_storage);
774 GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port);
775 if (GNUNET_SYSERR
776 == GNUNET_STRINGS_to_address_ip (to_conv, strlen (to_conv), s))
777 {
778 /* could be a hostname */
779 GNUNET_free (s);
780 (*res) = GNUNET_NO;
781 s = NULL;
782 }
783 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
784 {
785 GNUNET_free (s);
786 (*res) = GNUNET_SYSERR;
787 s = NULL;
788 }
789 else
790 {
791 (*res) = GNUNET_YES;
792 }
793 http_clean_splitted (spa);
794 GNUNET_free (to_conv);
795 return (struct sockaddr *) s;
796}
797
798
799/**
800 * Get the length of an address
801 *
802 * @param addr address
803 * @return the size
804 */
805size_t
806http_common_address_get_size (const struct HttpAddress *addr)
807{
808 return sizeof(struct HttpAddress) + ntohl (addr->urlen);
809}
810
811
812/**
813 * Compare addr1 to addr2
814 *
815 * @param addr1 address1
816 * @param addrlen1 address 1 length
817 * @param addr2 address2
818 * @param addrlen2 address 2 length
819 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error
820 */
821size_t
822http_common_cmp_addresses (const void *addr1,
823 size_t addrlen1,
824 const void *addr2,
825 size_t addrlen2)
826{
827 const char *a1 = addr1;
828 const char *a2 = addr2;
829 const struct HttpAddress *ha1;
830 const struct HttpAddress *ha2;
831
832 ha1 = (const struct HttpAddress *) a1;
833 ha2 = (const struct HttpAddress *) a2;
834
835 if (NULL == a1)
836 return GNUNET_SYSERR;
837 if (0 == addrlen1)
838 return GNUNET_SYSERR;
839 if (a1[addrlen1 - 1] != '\0')
840 return GNUNET_SYSERR;
841
842 if (NULL == a2)
843 return GNUNET_SYSERR;
844 if (0 == addrlen2)
845 return GNUNET_SYSERR;
846 if (a2[addrlen2 - 1] != '\0')
847 return GNUNET_SYSERR;
848
849 if (addrlen1 != addrlen2)
850 return GNUNET_NO;
851 if (ha1->urlen != ha2->urlen)
852 return GNUNET_NO;
853
854 if (0 == strcmp ((const char *) &ha1[1], (const char *) &ha2[1]))
855 return GNUNET_YES;
856 return GNUNET_NO;
857}
858
859
860/**
861 * Function obtain the network type for an address.
862 *
863 * @param env the environment
864 * @param address the address
865 * @return the network type
866 */
867enum GNUNET_NetworkType
868http_common_get_network_for_address (struct
869 GNUNET_TRANSPORT_PluginEnvironment *env,
870 const struct GNUNET_HELLO_Address *address)
871{
872 struct sockaddr *sa;
873 enum GNUNET_NetworkType net_type;
874 size_t salen = 0;
875 int res;
876
877 net_type = GNUNET_NT_UNSPECIFIED;
878 sa = http_common_socket_from_address (address->address,
879 address->address_length,
880 &res);
881 if (GNUNET_SYSERR == res)
882 return net_type;
883 if (GNUNET_YES == res)
884 {
885 GNUNET_assert (NULL != sa);
886 if (AF_INET == sa->sa_family)
887 {
888 salen = sizeof(struct sockaddr_in);
889 }
890 else if (AF_INET6 == sa->sa_family)
891 {
892 salen = sizeof(struct sockaddr_in6);
893 }
894 net_type = env->get_address_type (env->cls,
895 sa,
896 salen);
897 GNUNET_free (sa);
898 }
899 return net_type;
900}
901
902
903/* end of plugin_transport_http_common.c */