2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_http_common.c
23 * @brief functionality shared by http client and server transport service plugin
24 * @author Matthias Wachs
28 #include "gnunet_common.h"
29 #include "gnunet_transport_plugin.h"
32 * Convert the transports address to a nice, human-readable
36 * @param type name of the transport that generated the address
37 * @param addr one of the addresses of the host, NULL for the last address
38 * the specific address format depends on the transport
39 * @param addrlen length of the address
40 * @param numeric should (IP) addresses be displayed in numeric form?
41 * @param timeout after how long should we give up?
42 * @param asc function to call on each string
43 * @param asc_cls closure for asc
46 http_common_plugin_address_pretty_printer (void *cls, const char *type,
47 const void *addr, size_t addrlen,
49 struct GNUNET_TIME_Relative timeout,
50 GNUNET_TRANSPORT_AddressStringCallback
53 const char *saddr = (const char *) addr;
65 if (saddr[addrlen-1] != '\0')
76 * Function called for a quick conversion of the binary address to
77 * a numeric address. Note that the caller must not free the
78 * address and that the next call to this function is allowed
79 * to override the address again.
82 * @param addr binary address
83 * @param addrlen length of the address
84 * @return string representing the same address
87 http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
89 const char *saddr = (const char *) addr;
94 if (saddr[addrlen-1] != '\0')
100 * Function called to convert a string address to
103 * @param cls closure ('struct Plugin*')
104 * @param addr string address
105 * @param addrlen length of the address
106 * @param buf location to store the buffer
107 * If the function returns GNUNET_SYSERR, its contents are undefined.
108 * @param added length of created address
109 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
112 http_common_plugin_string_to_address (void *cls,
119 return GNUNET_SYSERR;
121 return GNUNET_SYSERR;
122 if (addr[addrlen-1] != '\0')
123 return GNUNET_SYSERR;
125 (*buf) = strdup (addr);
126 (*added) = strlen (addr) + 1;
131 * Create a HTTP address from a socketaddr
133 * @param protocol protocol
134 * @param addr sockaddr * address
135 * @param addrlen length of the address
139 http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen)
142 GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen));
147 * Get the length of an address
149 * @param addr address
153 http_common_address_get_size (const void *addr)
155 return strlen (addr) + 1;
159 * Compare addr1 to addr2
161 * @param addr1 address1
162 * @param addrlen1 address 1 length
163 * @param addr2 address2
164 * @param addrlen2 address 2 length
165 * @return GNUNET_YES if equal, GNUNET_NO if not, GNUNET_SYSERR on error
168 http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2)
170 const char *a1 = (const char *) addr1;
171 const char *a2 = (const char *) addr2;
174 return GNUNET_SYSERR;
176 return GNUNET_SYSERR;
177 if (a1[addrlen1-1] != '\0')
178 return GNUNET_SYSERR;
181 return GNUNET_SYSERR;
183 return GNUNET_SYSERR;
184 if (a2[addrlen2-1] != '\0')
185 return GNUNET_SYSERR;
187 if (addrlen1 != addrlen2)
190 if (0 == strcmp (addr1, addr2))
197 /* end of plugin_transport_http_common.c */