075573d7aef4630a7beea16a5d63f1803d8d9f4c
[oweals/gnunet.git] / src / transport / plugin_transport_http_common.h
1 /*
2      This file is part of GNUnet
3      (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
4
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.
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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file transport/plugin_transport_http_common.c
23  * @brief functionality shared by http client and server transport service plugin
24  * @author Matthias Wachs
25  */
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29
30 #if 0
31 GNUNET_NETWORK_STRUCT_BEGIN
32 /**
33  * HTTP addresses including a full URI
34  */
35 struct HttpAddress
36 {
37   /**
38    * Address following
39    */
40   char *address GNUNET_PACKED;
41 };
42 GNUNET_NETWORK_STRUCT_END
43 #endif
44
45 /**
46  * Convert the transports address to a nice, human-readable
47  * format.
48  *
49  * @param cls closure
50  * @param type name of the transport that generated the address
51  * @param addr one of the addresses of the host, NULL for the last address
52  *        the specific address format depends on the transport
53  * @param addrlen length of the address
54  * @param numeric should (IP) addresses be displayed in numeric form?
55  * @param timeout after how long should we give up?
56  * @param asc function to call on each string
57  * @param asc_cls closure for asc
58  */
59 void
60 http_common_plugin_address_pretty_printer (void *cls, const char *type,
61                                         const void *addr, size_t addrlen,
62                                         int numeric,
63                                         struct GNUNET_TIME_Relative timeout,
64                                         GNUNET_TRANSPORT_AddressStringCallback
65                                         asc, void *asc_cls);
66
67 /**
68  * Function called for a quick conversion of the binary address to
69  * a numeric address.  Note that the caller must not free the
70  * address and that the next call to this function is allowed
71  * to override the address again.
72  *
73  * @param cls closure
74  * @param addr binary address
75  * @param addrlen length of the address
76  * @return string representing the same address
77  */
78 const char *
79 http_common_plugin_address_to_string (void *cls,
80                                       const void *addr,
81                                       size_t addrlen);
82
83 /**
84  * Function called to convert a string address to
85  * a binary address.
86  *
87  * @param cls closure ('struct Plugin*')
88  * @param addr string address
89  * @param addrlen length of the address
90  * @param buf location to store the buffer
91  *        If the function returns GNUNET_SYSERR, its contents are undefined.
92  * @param added length of created address
93  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
94  */
95 int
96 http_common_plugin_string_to_address (void *cls,
97                                       const char *addr,
98                                       uint16_t addrlen,
99                                       void **buf,
100                                       size_t *added);
101
102
103 /**
104  * Create a HTTP address from a socketaddr
105  *
106  * @param protocol protocol
107  * @param addr sockaddr * address
108  * @param addrlen length of the address
109  * @return the string
110  */
111 char *
112 http_common_address_from_socket (const char *protocol,
113                                  const struct sockaddr *addr,
114                                  socklen_t addrlen);
115
116 /**
117  * Get the length of an address
118  *
119  * @param addr address
120  * @return the size
121  */
122 size_t
123 http_common_address_get_size (void *addr);
124
125
126 /**
127  * Compare addr1 to addr2
128  *
129  * @param addr1 address1
130  * @param addrlen1 address 1 length
131  * @param addr2 address2
132  * @param addrlen2 address 2 length
133  * @return GNUNET_YES if equal, GNUNET_NO else
134  */
135 size_t
136 http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2);
137 /* end of plugin_transport_http_common.c */