use NULL value in load_path_suffix to NOT load any files
[oweals/gnunet.git] / src / transport / plugin_transport_http_common.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2002-2014 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  * @file transport/plugin_transport_http_common.c
22  * @brief functionality shared by http client and server transport service plugin
23  * @author Matthias Wachs
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_common.h"
28 #include "gnunet_transport_plugin.h"
29
30 /**
31  * Timeout values for testing
32  */
33 #define TESTING GNUNET_NO
34
35 #if TESTING
36 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
37     GNUNET_TIME_UNIT_SECONDS, 3)
38 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
39     GNUNET_TIME_UNIT_SECONDS, 3)
40 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \
41     GNUNET_TIME_UNIT_SECONDS, 7)
42 #define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply ( \
43     GNUNET_TIME_UNIT_SECONDS, 7)
44 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
45
46 #else
47
48 #if BUILD_HTTPS
49 #define PROTOCOL "https"
50 #else
51 #define PROTOCOL "http"
52 #endif
53
54 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
55     GNUNET_TIME_UNIT_SECONDS, 15)
56 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
57     GNUNET_TIME_UNIT_SECONDS, 15)
58 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
59 #define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
60 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
61
62 #endif
63
64 #define HTTP_DEFAULT_PORT 80
65 #define HTTPS_DEFAULT_PORT 443
66
67 /**
68  * Bits in the `options` field of HTTP addresses.
69  */
70 enum HttpAddressOptions
71 {
72   /**
73    * No bits set.
74    */
75   HTTP_OPTIONS_NONE = 0,
76
77   /**
78    * Verify X509 server certificate, it should be valid.
79    * (if this bit is not set, it is probably just self-
80    * signed and not expected to be verified).
81    */
82   HTTP_OPTIONS_VERIFY_CERTIFICATE = 1,
83
84   /**
85    * Enable TCP Stealth-style port knocking.
86    */
87   HTTP_OPTIONS_TCP_STEALTH = 2
88 };
89
90
91 GNUNET_NETWORK_STRUCT_BEGIN
92
93 /**
94  * HttpAddress
95  */
96 struct HttpAddress
97 {
98   /**
99    * Address options
100    * see `enum HttpAddressOptions`
101    */
102   uint32_t options GNUNET_PACKED;
103
104   /**
105    * Length of URL located after struct
106    */
107   uint32_t urlen GNUNET_PACKED;
108 };
109
110 GNUNET_NETWORK_STRUCT_END
111
112 /**
113  * Representation of HTTP URL split into its components.
114  */
115 struct SplittedHTTPAddress
116 {
117   char *protocol;
118   char *host;
119   char *path;
120   int port;
121 };
122
123
124 /**
125  * Split an HTTP address into protocol, hostname, port
126  * and path components.
127  */
128 struct SplittedHTTPAddress *
129 http_split_address (const char *addr);
130
131
132 /**
133  * Convert the transports address to a nice, human-readable
134  * format.
135  *
136  * @param cls closure
137  * @param type name of the transport that generated the address
138  * @param addr one of the addresses of the host, NULL for the last address
139  *        the specific address format depends on the transport
140  * @param addrlen length of the address
141  * @param numeric should (IP) addresses be displayed in numeric form?
142  * @param timeout after how long should we give up?
143  * @param asc function to call on each string
144  * @param asc_cls closure for @a asc
145  */
146 void
147 http_common_plugin_address_pretty_printer (void *cls,
148                                            const char *type,
149                                            const void *addr,
150                                            size_t addrlen,
151                                            int numeric,
152                                            struct GNUNET_TIME_Relative timeout,
153                                            GNUNET_TRANSPORT_AddressStringCallback
154                                            asc,
155                                            void *asc_cls);
156
157
158 /**
159  * Function called for a quick conversion of the binary address to
160  * a numeric address.  Note that the caller must not free the
161  * address and that the next call to this function is allowed
162  * to override the address again.
163  *
164  * @param plugin name of the plugin
165  * @param addr binary address
166  * @param addrlen length of @a addr
167  * @return string representing the same address
168  */
169 const char *
170 http_common_plugin_address_to_string (const char *plugin,
171                                       const void *addr,
172                                       size_t addrlen);
173
174
175 /**
176  * Function called to convert a string address to
177  * a binary address.
178  *
179  * @param cls closure (`struct Plugin*`)
180  * @param addr string address
181  * @param addrlen length of the address
182  * @param buf location to store the buffer
183  *        If the function returns #GNUNET_SYSERR, its contents are undefined.
184  * @param added length of created address
185  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
186  */
187 int
188 http_common_plugin_string_to_address (void *cls,
189                                       const char *addr,
190                                       uint16_t addrlen,
191                                       void **buf,
192                                       size_t *added);
193
194
195 /**
196  * Create a HTTP address from a socketaddr
197  *
198  * @param protocol protocol
199  * @param addr `sockaddr *` address
200  * @param addrlen length of the @a addr
201  * @return the string
202  */
203 struct HttpAddress *
204 http_common_address_from_socket (const char *protocol,
205                                  const struct sockaddr *addr,
206                                  socklen_t addrlen);
207
208
209 /**
210  * Create a socketaddr from a HTTP address
211  *
212  * @param addr a `sockaddr *` address
213  * @param addrlen length of the @a addr
214  * @param res the result:
215  *   #GNUNET_SYSERR, invalid input,
216  *   #GNUNET_YES: could convert to ip,
217  *   #GNUNET_NO: valid input but could not convert to ip (hostname?)
218  * @return the string
219  */
220 struct sockaddr *
221 http_common_socket_from_address (const void *addr,
222                                  size_t addrlen,
223                                  int *res);
224
225
226 const char *
227 http_common_plugin_address_to_url (void *cls,
228                                    const void *addr,
229                                    size_t addrlen);
230
231
232 /**
233  * Get the length of an address
234  *
235  * @param addr address
236  * @return the size
237  */
238 size_t
239 http_common_address_get_size (const struct HttpAddress *addr);
240
241
242 /**
243  * Compare addr1 to addr2
244  *
245  * @param addr1 address1
246  * @param addrlen1 length of @a address1
247  * @param addr2 address2
248  * @param addrlen2 length of @a address2
249  * @return #GNUNET_YES if equal, #GNUNET_NO else
250  */
251 size_t
252 http_common_cmp_addresses (const void *addr1,
253                            size_t addrlen1,
254                            const void *addr2,
255                            size_t addrlen2);
256
257
258 /**
259  * Function obtain the network type for an address.
260  *
261  * @param env the environment
262  * @param address the address
263  * @return the network type
264  */
265 enum GNUNET_NetworkType
266 http_common_get_network_for_address (struct
267                                      GNUNET_TRANSPORT_PluginEnvironment *env,
268                                      const struct
269                                      GNUNET_HELLO_Address *address);
270
271
272 /* end of plugin_transport_http_common.h */