changes
[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
30 #define TESTING GNUNET_NO
31
32 #if TESTING
33 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_ERROR
34 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
35 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
36 #else
37 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
38 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
39 #define TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
40 #endif
41
42 /**
43  * Convert the transports address to a nice, human-readable
44  * format.
45  *
46  * @param cls closure
47  * @param type name of the transport that generated the address
48  * @param addr one of the addresses of the host, NULL for the last address
49  *        the specific address format depends on the transport
50  * @param addrlen length of the address
51  * @param numeric should (IP) addresses be displayed in numeric form?
52  * @param timeout after how long should we give up?
53  * @param asc function to call on each string
54  * @param asc_cls closure for asc
55  */
56 void
57 http_common_plugin_address_pretty_printer (void *cls, const char *type,
58                                         const void *addr, size_t addrlen,
59                                         int numeric,
60                                         struct GNUNET_TIME_Relative timeout,
61                                         GNUNET_TRANSPORT_AddressStringCallback
62                                         asc, void *asc_cls);
63
64 /**
65  * Function called for a quick conversion of the binary address to
66  * a numeric address.  Note that the caller must not free the
67  * address and that the next call to this function is allowed
68  * to override the address again.
69  *
70  * @param cls closure
71  * @param addr binary address
72  * @param addrlen length of the address
73  * @return string representing the same address
74  */
75 const char *
76 http_common_plugin_address_to_string (void *cls,
77                                       const void *addr,
78                                       size_t addrlen);
79
80 /**
81  * Function called to convert a string address to
82  * a binary address.
83  *
84  * @param cls closure ('struct Plugin*')
85  * @param addr string address
86  * @param addrlen length of the address
87  * @param buf location to store the buffer
88  *        If the function returns GNUNET_SYSERR, its contents are undefined.
89  * @param added length of created address
90  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
91  */
92 int
93 http_common_plugin_string_to_address (void *cls,
94                                       const char *addr,
95                                       uint16_t addrlen,
96                                       void **buf,
97                                       size_t *added);
98
99
100 /**
101  * Create a HTTP address from a socketaddr
102  *
103  * @param protocol protocol
104  * @param addr sockaddr * address
105  * @param addrlen length of the address
106  * @return the string
107  */
108 char *
109 http_common_address_from_socket (const char *protocol,
110                                  const struct sockaddr *addr,
111                                  socklen_t addrlen);
112
113 /**
114  * Get the length of an address
115  *
116  * @param addr address
117  * @return the size
118  */
119 size_t
120 http_common_address_get_size (void *addr);
121
122
123 /**
124  * Compare addr1 to addr2
125  *
126  * @param addr1 address1
127  * @param addrlen1 address 1 length
128  * @param addr2 address2
129  * @param addrlen2 address 2 length
130  * @return GNUNET_YES if equal, GNUNET_NO else
131  */
132 size_t
133 http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2);
134 /* end of plugin_transport_http_common.c */