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