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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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 (GNUNET_TIME_UNIT_SECONDS, 3)
37 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
38 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
39 #define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
40 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
45 #define PROTOCOL "https"
47 #define PROTOCOL "http"
50 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
51 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
52 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
53 #define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
54 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
58 #define HTTP_DEFAULT_PORT 80
59 #define HTTPS_DEFAULT_PORT 443
62 * Bits in the `options` field of HTTP addresses.
64 enum HttpAddressOptions
69 HTTP_OPTIONS_NONE = 0,
72 * Verify X509 server certificate, it should be valid.
73 * (if this bit is not set, it is probably just self-
74 * signed and not expected to be verified).
76 HTTP_OPTIONS_VERIFY_CERTIFICATE = 1,
79 * Enable TCP Stealth-style port knocking.
81 HTTP_OPTIONS_TCP_STEALTH = 2
85 GNUNET_NETWORK_STRUCT_BEGIN
94 * see `enum HttpAddressOptions`
96 uint32_t options GNUNET_PACKED;
99 * Length of URL located after struct
101 uint32_t urlen GNUNET_PACKED;
104 GNUNET_NETWORK_STRUCT_END
107 * Representation of HTTP URL split into its components.
109 struct SplittedHTTPAddress
119 * Split an HTTP address into protocol, hostname, port
120 * and path components.
122 struct SplittedHTTPAddress *
123 http_split_address (const char *addr);
127 * Convert the transports address to a nice, human-readable
131 * @param type name of the transport that generated the address
132 * @param addr one of the addresses of the host, NULL for the last address
133 * the specific address format depends on the transport
134 * @param addrlen length of the address
135 * @param numeric should (IP) addresses be displayed in numeric form?
136 * @param timeout after how long should we give up?
137 * @param asc function to call on each string
138 * @param asc_cls closure for @a asc
141 http_common_plugin_address_pretty_printer (void *cls,
146 struct GNUNET_TIME_Relative timeout,
147 GNUNET_TRANSPORT_AddressStringCallback asc,
152 * Function called for a quick conversion of the binary address to
153 * a numeric address. Note that the caller must not free the
154 * address and that the next call to this function is allowed
155 * to override the address again.
157 * @param plugin name of the plugin
158 * @param addr binary address
159 * @param addrlen length of @a addr
160 * @return string representing the same address
163 http_common_plugin_address_to_string (const char *plugin,
169 * Function called to convert a string address to
172 * @param cls closure (`struct Plugin*`)
173 * @param addr string address
174 * @param addrlen length of the address
175 * @param buf location to store the buffer
176 * If the function returns #GNUNET_SYSERR, its contents are undefined.
177 * @param added length of created address
178 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
181 http_common_plugin_string_to_address (void *cls,
189 * Create a HTTP address from a socketaddr
191 * @param protocol protocol
192 * @param addr `sockaddr *` address
193 * @param addrlen length of the @a addr
197 http_common_address_from_socket (const char *protocol,
198 const struct sockaddr *addr,
203 * Create a socketaddr from a HTTP address
205 * @param addr a `sockaddr *` address
206 * @param addrlen length of the @a addr
207 * @param res the result:
208 * #GNUNET_SYSERR, invalid input,
209 * #GNUNET_YES: could convert to ip,
210 * #GNUNET_NO: valid input but could not convert to ip (hostname?)
214 http_common_socket_from_address (const void *addr,
220 http_common_plugin_address_to_url (void *cls,
226 * Get the length of an address
228 * @param addr address
232 http_common_address_get_size (const struct HttpAddress * addr);
236 * Compare addr1 to addr2
238 * @param addr1 address1
239 * @param addrlen1 length of @a address1
240 * @param addr2 address2
241 * @param addrlen2 length of @a address2
242 * @return #GNUNET_YES if equal, #GNUNET_NO else
245 http_common_cmp_addresses (const void *addr1,
252 * Function obtain the network type for an address.
254 * @param env the environment
255 * @param address the address
256 * @return the network type
258 enum GNUNET_ATS_Network_Type
259 http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env,
260 const struct GNUNET_HELLO_Address *address);
263 /* end of plugin_transport_http_common.h */