2 This file is part of GNUnet
3 Copyright (C) 2002-2014 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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
27 #include "gnunet_common.h"
28 #include "gnunet_transport_plugin.h"
31 * Timeout values for testing
33 #define TESTING GNUNET_NO
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
49 #define PROTOCOL "https"
51 #define PROTOCOL "http"
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
64 #define HTTP_DEFAULT_PORT 80
65 #define HTTPS_DEFAULT_PORT 443
68 * Bits in the `options` field of HTTP addresses.
70 enum HttpAddressOptions
75 HTTP_OPTIONS_NONE = 0,
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).
82 HTTP_OPTIONS_VERIFY_CERTIFICATE = 1,
85 * Enable TCP Stealth-style port knocking.
87 HTTP_OPTIONS_TCP_STEALTH = 2
91 GNUNET_NETWORK_STRUCT_BEGIN
100 * see `enum HttpAddressOptions`
102 uint32_t options GNUNET_PACKED;
105 * Length of URL located after struct
107 uint32_t urlen GNUNET_PACKED;
110 GNUNET_NETWORK_STRUCT_END
113 * Representation of HTTP URL split into its components.
115 struct SplittedHTTPAddress
125 * Split an HTTP address into protocol, hostname, port
126 * and path components.
128 struct SplittedHTTPAddress *
129 http_split_address (const char *addr);
133 * Convert the transports address to a nice, human-readable
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
147 http_common_plugin_address_pretty_printer (void *cls,
152 struct GNUNET_TIME_Relative timeout,
153 GNUNET_TRANSPORT_AddressStringCallback
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.
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
170 http_common_plugin_address_to_string (const char *plugin,
176 * Function called to convert a string address to
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
188 http_common_plugin_string_to_address (void *cls,
196 * Create a HTTP address from a socketaddr
198 * @param protocol protocol
199 * @param addr `sockaddr *` address
200 * @param addrlen length of the @a addr
204 http_common_address_from_socket (const char *protocol,
205 const struct sockaddr *addr,
210 * Create a socketaddr from a HTTP address
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?)
221 http_common_socket_from_address (const void *addr,
227 http_common_plugin_address_to_url (void *cls,
233 * Get the length of an address
235 * @param addr address
239 http_common_address_get_size (const struct HttpAddress *addr);
243 * Compare addr1 to addr2
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
252 http_common_cmp_addresses (const void *addr1,
259 * Function obtain the network type for an address.
261 * @param env the environment
262 * @param address the address
263 * @return the network type
265 enum GNUNET_NetworkType
266 http_common_get_network_for_address (struct
267 GNUNET_TRANSPORT_PluginEnvironment *env,
269 GNUNET_HELLO_Address *address);
272 /* end of plugin_transport_http_common.h */