error msg
[oweals/gnunet.git] / src / transport / plugin_transport_http_common.h
1 /*
2      This file is part of GNUnet
3      (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 /**
22  * @file transport/plugin_transport_http_common.c
23  * @brief functionality shared by http client and server transport service plugin
24  * @author Matthias Wachs
25  */
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29 #include "gnunet_transport_plugin.h"
30 /**
31  * Timeout values for testing
32  */
33 #define TESTING GNUNET_NO
34
35 #if TESTING
36
37 #define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
38 #define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
39 #define CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
40 #define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7)
41 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
42
43 #else
44
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 CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
48 #define SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
49 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
50
51 #endif
52
53 #define HTTP_DEFAULT_PORT 80
54 #define HTTPS_DEFAULT_PORT 443
55
56
57 struct SplittedHTTPAddress;
58
59 struct SplittedHTTPAddress *
60 http_split_address (const char * addr);
61
62 /**
63  * Convert the transports address to a nice, human-readable
64  * format.
65  *
66  * @param cls closure
67  * @param type name of the transport that generated the address
68  * @param addr one of the addresses of the host, NULL for the last address
69  *        the specific address format depends on the transport
70  * @param addrlen length of the address
71  * @param numeric should (IP) addresses be displayed in numeric form?
72  * @param timeout after how long should we give up?
73  * @param asc function to call on each string
74  * @param asc_cls closure for asc
75  */
76 void
77 http_common_plugin_address_pretty_printer (void *cls, const char *type,
78                                         const void *addr, size_t addrlen,
79                                         int numeric,
80                                         struct GNUNET_TIME_Relative timeout,
81                                         GNUNET_TRANSPORT_AddressStringCallback
82                                         asc, void *asc_cls);
83
84 /**
85  * Function called for a quick conversion of the binary address to
86  * a numeric address.  Note that the caller must not free the
87  * address and that the next call to this function is allowed
88  * to override the address again.
89  *
90  * @param cls closure
91  * @param addr binary address
92  * @param addrlen length of the address
93  * @return string representing the same address
94  */
95 const char *
96 http_common_plugin_address_to_string (void *cls,
97                                       const void *addr,
98                                       size_t addrlen);
99
100 /**
101  * Function called to convert a string address to
102  * a binary address.
103  *
104  * @param cls closure ('struct Plugin*')
105  * @param addr string address
106  * @param addrlen length of the address
107  * @param buf location to store the buffer
108  *        If the function returns GNUNET_SYSERR, its contents are undefined.
109  * @param added length of created address
110  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
111  */
112 int
113 http_common_plugin_string_to_address (void *cls,
114                                       const char *addr,
115                                       uint16_t addrlen,
116                                       void **buf,
117                                       size_t *added);
118
119
120 /**
121  * Create a HTTP address from a socketaddr
122  *
123  * @param protocol protocol
124  * @param addr sockaddr * address
125  * @param addrlen length of the address
126  * @return the string
127  */
128 char *
129 http_common_address_from_socket (const char *protocol,
130                                  const struct sockaddr *addr,
131                                  socklen_t addrlen);
132
133 /**
134  * Create a socketaddr from a HTTP address
135  *
136  * @param addr sockaddr * address
137  * @param addrlen length of the address
138  * @param res the result:
139  * GNUNET_SYSERR, invalid input,
140  * GNUNET_YES: could convert to ip,
141  * GNUNET_NO: valid input but could not convert to ip (hostname?)
142  * @return the string
143  */
144 struct sockaddr *
145 http_common_socket_from_address (const void *addr, size_t addrlen, int *res);
146
147 /**
148  * Get the length of an address
149  *
150  * @param addr address
151  * @return the size
152  */
153 size_t
154 http_common_address_get_size (const void *addr);
155
156
157 /**
158  * Compare addr1 to addr2
159  *
160  * @param addr1 address1
161  * @param addrlen1 address 1 length
162  * @param addr2 address2
163  * @param addrlen2 address 2 length
164  * @return GNUNET_YES if equal, GNUNET_NO else
165  */
166 size_t
167 http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2);
168 /* end of plugin_transport_http_common.c */