-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / plugin_transport_http_common.h
1 /*
2      This file is part of GNUnet
3      (C) 2002-2013 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 #include "gnunet_transport_plugin.h"
30
31 /**
32  * Timeout values for testing
33  */
34 #define TESTING GNUNET_NO
35
36 #if TESTING
37 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
38 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
39 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
40 #define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
41 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
42
43 #else
44
45 #if BUILD_HTTPS
46 #define PROTOCOL "https"
47 #else
48 #define PROTOCOL "http"
49 #endif
50
51 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
52 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
53 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
54 #define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
55 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
56
57 #endif
58
59 #define HTTP_DEFAULT_PORT 80
60 #define HTTPS_DEFAULT_PORT 443
61
62 enum HTTP_ADDRESS_OPTIONS
63 {
64   HTTP_OPTIONS_NONE = 0,
65   HTTP_OPTIONS_VERIFY_CERTIFICATE = 1
66 };
67
68
69 GNUNET_NETWORK_STRUCT_BEGIN
70
71 /**
72  * HttpAddress
73  */
74 struct HttpAddress
75 {
76   /**
77    * Address options
78    */
79   uint32_t options;
80
81   /**
82    * Length of URL located after struct
83    */
84   uint32_t urlen;
85 };
86
87 GNUNET_NETWORK_STRUCT_END
88
89 struct SplittedHTTPAddress;
90
91 struct SplittedHTTPAddress *
92 http_split_address (const char * addr);
93
94 /**
95  * Convert the transports address to a nice, human-readable
96  * format.
97  *
98  * @param cls closure
99  * @param type name of the transport that generated the address
100  * @param addr one of the addresses of the host, NULL for the last address
101  *        the specific address format depends on the transport
102  * @param addrlen length of the address
103  * @param numeric should (IP) addresses be displayed in numeric form?
104  * @param timeout after how long should we give up?
105  * @param asc function to call on each string
106  * @param asc_cls closure for @a asc
107  */
108 void
109 http_common_plugin_address_pretty_printer (void *cls, const char *type,
110                                            const void *addr, size_t addrlen,
111                                            int numeric,
112                                            struct GNUNET_TIME_Relative timeout,
113                                            GNUNET_TRANSPORT_AddressStringCallback
114                                            asc, void *asc_cls);
115
116
117 /**
118  * Function called for a quick conversion of the binary address to
119  * a numeric address.  Note that the caller must not free the
120  * address and that the next call to this function is allowed
121  * to override the address again.
122  *
123  * @param cls closure
124  * @param plugin the plugin
125  * @param addr binary address
126  * @param addrlen length of the address
127  * @return string representing the same address
128  */
129 const char *
130 http_common_plugin_address_to_string (void *cls,
131                                       const char *plugin,
132                                       const void *addr,
133                                       size_t addrlen);
134
135
136 /**
137  * Function called to convert a string address to
138  * a binary address.
139  *
140  * @param cls closure (`struct Plugin*`)
141  * @param addr string address
142  * @param addrlen length of the address
143  * @param buf location to store the buffer
144  *        If the function returns #GNUNET_SYSERR, its contents are undefined.
145  * @param added length of created address
146  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
147  */
148 int
149 http_common_plugin_string_to_address (void *cls,
150                                       const char *addr,
151                                       uint16_t addrlen,
152                                       void **buf,
153                                       size_t *added);
154
155
156 /**
157  * Create a HTTP address from a socketaddr
158  *
159  * @param protocol protocol
160  * @param addr `sockaddr *` address
161  * @param addrlen length of the @a addr
162  * @return the string
163  */
164 struct HttpAddress *
165 http_common_address_from_socket (const char *protocol,
166                                  const struct sockaddr *addr,
167                                  socklen_t addrlen);
168
169
170 /**
171  * Create a socketaddr from a HTTP address
172  *
173  * @param addr a `sockaddr *` address
174  * @param addrlen length of the @a addr
175  * @param res the result:
176  *   #GNUNET_SYSERR, invalid input,
177  *   #GNUNET_YES: could convert to ip,
178  *   #GNUNET_NO: valid input but could not convert to ip (hostname?)
179  * @return the string
180  */
181 struct sockaddr *
182 http_common_socket_from_address (const void *addr,
183                                  size_t addrlen,
184                                  int *res);
185
186
187 const char *
188 http_common_plugin_address_to_url (void *cls,
189                                    const void *addr,
190                                    size_t addrlen);
191
192
193 /**
194  * Get the length of an address
195  *
196  * @param addr address
197  * @return the size
198  */
199 size_t
200 http_common_address_get_size (const struct HttpAddress * addr);
201
202
203 /**
204  * Compare addr1 to addr2
205  *
206  * @param addr1 address1
207  * @param addrlen1 address 1 length
208  * @param addr2 address2
209  * @param addrlen2 address 2 length
210  * @return #GNUNET_YES if equal, #GNUNET_NO else
211  */
212 size_t
213 http_common_cmp_addresses (const void *addr1,
214                            size_t addrlen1,
215                            const void *addr2,
216                            size_t addrlen2);
217
218 /* end of plugin_transport_http_common.h */