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 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.
16 * @file transport/plugin_transport_http_common.c
17 * @brief functionality shared by http client and server transport service plugin
18 * @author Matthias Wachs
19 * @author Christian Grothoff
22 #include "gnunet_common.h"
23 #include "gnunet_transport_plugin.h"
26 * Timeout values for testing
28 #define TESTING GNUNET_NO
31 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
32 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
33 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
34 #define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
35 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
40 #define PROTOCOL "https"
42 #define PROTOCOL "http"
45 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
46 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
47 #define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
48 #define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
49 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
53 #define HTTP_DEFAULT_PORT 80
54 #define HTTPS_DEFAULT_PORT 443
57 * Bits in the `options` field of HTTP addresses.
59 enum HttpAddressOptions
64 HTTP_OPTIONS_NONE = 0,
67 * Verify X509 server certificate, it should be valid.
68 * (if this bit is not set, it is probably just self-
69 * signed and not expected to be verified).
71 HTTP_OPTIONS_VERIFY_CERTIFICATE = 1,
74 * Enable TCP Stealth-style port knocking.
76 HTTP_OPTIONS_TCP_STEALTH = 2
80 GNUNET_NETWORK_STRUCT_BEGIN
89 * see `enum HttpAddressOptions`
91 uint32_t options GNUNET_PACKED;
94 * Length of URL located after struct
96 uint32_t urlen GNUNET_PACKED;
99 GNUNET_NETWORK_STRUCT_END
102 * Representation of HTTP URL split into its components.
104 struct SplittedHTTPAddress
114 * Split an HTTP address into protocol, hostname, port
115 * and path components.
117 struct SplittedHTTPAddress *
118 http_split_address (const char *addr);
122 * Convert the transports address to a nice, human-readable
126 * @param type name of the transport that generated the address
127 * @param addr one of the addresses of the host, NULL for the last address
128 * the specific address format depends on the transport
129 * @param addrlen length of the address
130 * @param numeric should (IP) addresses be displayed in numeric form?
131 * @param timeout after how long should we give up?
132 * @param asc function to call on each string
133 * @param asc_cls closure for @a asc
136 http_common_plugin_address_pretty_printer (void *cls,
141 struct GNUNET_TIME_Relative timeout,
142 GNUNET_TRANSPORT_AddressStringCallback asc,
147 * Function called for a quick conversion of the binary address to
148 * a numeric address. Note that the caller must not free the
149 * address and that the next call to this function is allowed
150 * to override the address again.
152 * @param plugin name of the plugin
153 * @param addr binary address
154 * @param addrlen length of @a addr
155 * @return string representing the same address
158 http_common_plugin_address_to_string (const char *plugin,
164 * Function called to convert a string address to
167 * @param cls closure (`struct Plugin*`)
168 * @param addr string address
169 * @param addrlen length of the address
170 * @param buf location to store the buffer
171 * If the function returns #GNUNET_SYSERR, its contents are undefined.
172 * @param added length of created address
173 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
176 http_common_plugin_string_to_address (void *cls,
184 * Create a HTTP address from a socketaddr
186 * @param protocol protocol
187 * @param addr `sockaddr *` address
188 * @param addrlen length of the @a addr
192 http_common_address_from_socket (const char *protocol,
193 const struct sockaddr *addr,
198 * Create a socketaddr from a HTTP address
200 * @param addr a `sockaddr *` address
201 * @param addrlen length of the @a addr
202 * @param res the result:
203 * #GNUNET_SYSERR, invalid input,
204 * #GNUNET_YES: could convert to ip,
205 * #GNUNET_NO: valid input but could not convert to ip (hostname?)
209 http_common_socket_from_address (const void *addr,
215 http_common_plugin_address_to_url (void *cls,
221 * Get the length of an address
223 * @param addr address
227 http_common_address_get_size (const struct HttpAddress * addr);
231 * Compare addr1 to addr2
233 * @param addr1 address1
234 * @param addrlen1 length of @a address1
235 * @param addr2 address2
236 * @param addrlen2 length of @a address2
237 * @return #GNUNET_YES if equal, #GNUNET_NO else
240 http_common_cmp_addresses (const void *addr1,
247 * Function obtain the network type for an address.
249 * @param env the environment
250 * @param address the address
251 * @return the network type
253 enum GNUNET_ATS_Network_Type
254 http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env,
255 const struct GNUNET_HELLO_Address *address);
258 /* end of plugin_transport_http_common.h */