aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-23 19:24:14 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-23 19:24:14 +0000
commitf874eb3423cde2257d57c0f5d651297b303b3cff (patch)
treedbc7e59d4edcff24cd64b75cfdb78e1198347ac2 /src/transport
parentcb2ba3aea878701a9bf816892de389eb45ca9aa4 (diff)
downloadgnunet-f874eb3423cde2257d57c0f5d651297b303b3cff.tar.gz
gnunet-f874eb3423cde2257d57c0f5d651297b303b3cff.zip
-minor code cleanup, indentation, doxygen
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_http_common.c13
-rw-r--r--src/transport/plugin_transport_http_common.h24
-rw-r--r--src/transport/test_http_common.c250
3 files changed, 141 insertions, 146 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 4cc6a84b2..a2e4fd129 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -29,15 +29,6 @@
29#include "plugin_transport_http_common.h" 29#include "plugin_transport_http_common.h"
30 30
31 31
32struct SplittedHTTPAddress
33{
34 char *protocol;
35 char *host;
36 char *path;
37 int port;
38};
39
40
41static void 32static void
42http_clean_splitted (struct SplittedHTTPAddress *spa) 33http_clean_splitted (struct SplittedHTTPAddress *spa)
43{ 34{
@@ -474,8 +465,8 @@ http_common_socket_from_address (const void *addr,
474 spa = http_split_address ((const char *) &ha[1]); 465 spa = http_split_address ((const char *) &ha[1]);
475 if (NULL == spa) 466 if (NULL == spa)
476 { 467 {
477 (*res) = GNUNET_SYSERR; 468 (*res) = GNUNET_SYSERR;
478 return NULL; 469 return NULL;
479 } 470 }
480 471
481 s = GNUNET_new (struct sockaddr_storage); 472 s = GNUNET_new (struct sockaddr_storage);
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h
index 04d3adc29..1fb1bd1ed 100644
--- a/src/transport/plugin_transport_http_common.h
+++ b/src/transport/plugin_transport_http_common.h
@@ -17,13 +17,11 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * @file transport/plugin_transport_http_common.c 21 * @file transport/plugin_transport_http_common.c
23 * @brief functionality shared by http client and server transport service plugin 22 * @brief functionality shared by http client and server transport service plugin
24 * @author Matthias Wachs 23 * @author Matthias Wachs
25 */ 24 */
26
27#include "platform.h" 25#include "platform.h"
28#include "gnunet_common.h" 26#include "gnunet_common.h"
29#include "gnunet_transport_plugin.h" 27#include "gnunet_transport_plugin.h"
@@ -86,8 +84,22 @@ struct HttpAddress
86 84
87GNUNET_NETWORK_STRUCT_END 85GNUNET_NETWORK_STRUCT_END
88 86
89struct SplittedHTTPAddress; 87/**
88 * Representation of HTTP URL split into its components.
89 */
90struct SplittedHTTPAddress
91{
92 char *protocol;
93 char *host;
94 char *path;
95 int port;
96};
97
90 98
99/**
100 * Split an HTTP address into protocol, hostname, port
101 * and path components.
102 */
91struct SplittedHTTPAddress * 103struct SplittedHTTPAddress *
92http_split_address (const char *addr); 104http_split_address (const char *addr);
93 105
@@ -125,7 +137,7 @@ http_common_plugin_address_pretty_printer (void *cls,
125 * 137 *
126 * @param plugin name of the plugin 138 * @param plugin name of the plugin
127 * @param addr binary address 139 * @param addr binary address
128 * @param addrlen length of the address 140 * @param addrlen length of @a addr
129 * @return string representing the same address 141 * @return string representing the same address
130 */ 142 */
131const char * 143const char *
@@ -205,9 +217,9 @@ http_common_address_get_size (const struct HttpAddress * addr);
205 * Compare addr1 to addr2 217 * Compare addr1 to addr2
206 * 218 *
207 * @param addr1 address1 219 * @param addr1 address1
208 * @param addrlen1 address 1 length 220 * @param addrlen1 length of @a address1
209 * @param addr2 address2 221 * @param addr2 address2
210 * @param addrlen2 address 2 length 222 * @param addrlen2 length of @a address2
211 * @return #GNUNET_YES if equal, #GNUNET_NO else 223 * @return #GNUNET_YES if equal, #GNUNET_NO else
212 */ 224 */
213size_t 225size_t
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c
index c97ae1745..9c619ea60 100644
--- a/src/transport/test_http_common.c
+++ b/src/transport/test_http_common.c
@@ -26,135 +26,125 @@
26#include "transport-testing.h" 26#include "transport-testing.h"
27#include "plugin_transport_http_common.h" 27#include "plugin_transport_http_common.h"
28 28
29struct SplittedHTTPAddress
30{
31 char *protocol;
32 char *host;
33 char *path;
34 int port;
35};
36 29
37void 30static void
38clean (struct SplittedHTTPAddress *addr) 31clean (struct SplittedHTTPAddress *addr)
39{ 32{
40 if (NULL != addr) 33 if (NULL == addr)
41 { 34 return;
42 GNUNET_free_non_null (addr->host); 35 GNUNET_free_non_null (addr->host);
43 GNUNET_free_non_null (addr->path); 36 GNUNET_free_non_null (addr->path);
44 GNUNET_free_non_null (addr->protocol); 37 GNUNET_free_non_null (addr->protocol);
45 GNUNET_free_non_null (addr); 38 GNUNET_free (addr);
46 }
47} 39}
48 40
49 41
50int 42static int
51check (struct SplittedHTTPAddress *addr, 43check (struct SplittedHTTPAddress *addr,
52 char * protocol, 44 char * protocol,
53 char * host, 45 char * host,
54 int port, 46 int port,
55 char * path) 47 char * path)
56{ 48{
49 if (NULL == addr)
50 return GNUNET_NO;
51 if (((NULL == addr->protocol) && (NULL != protocol)) ||
52 ((NULL != addr->protocol) && (NULL == protocol)))
53 {
54 GNUNET_break (0);
55 return GNUNET_NO;
56 }
57 else if ((NULL != addr->protocol) && (NULL != protocol))
58 {
59 if (0 != strcmp(addr->protocol, protocol))
60 {
61 GNUNET_break (0);
62 return GNUNET_NO;
63 }
64 }
65
66 if (((NULL == addr->host) && (NULL != host)) ||
67 ((NULL != addr->host) && (NULL == host)))
68 {
69 GNUNET_break (0);
70 return GNUNET_NO;
71 }
72 else if ((NULL != addr->host) && (NULL != host))
73 {
74 if (0 != strcmp(addr->host, host))
75 {
76 GNUNET_break (0);
77 return GNUNET_NO;
78 }
79 }
80
81 if (((NULL == addr->path) && (NULL != path)) ||
82 ((NULL != addr->path) && (NULL == path)))
83 {
84 GNUNET_break (0);
85 return GNUNET_NO;
86 }
87 else if ((NULL != addr->path) && (NULL != path))
88 {
89 if (0 != strcmp(addr->path, path))
90 {
91 GNUNET_break (0);
92 return GNUNET_NO;
93 }
94 }
57 95
58 if (NULL == addr) 96 if ((addr->port != port))
59 return GNUNET_NO; 97 {
60 if (((NULL == addr->protocol) && (NULL != protocol)) || 98 GNUNET_break (0);
61 ((NULL != addr->protocol) && (NULL == protocol))) 99 return GNUNET_NO;
62 { 100 }
63 GNUNET_break (0); 101 return GNUNET_OK;
64 return GNUNET_NO;
65 }
66 else if ((NULL != addr->protocol) && (NULL != protocol))
67 {
68 if (0 != strcmp(addr->protocol, protocol))
69 {
70 GNUNET_break (0);
71 return GNUNET_NO;
72 }
73 }
74
75 if (((NULL == addr->host) && (NULL != host)) ||
76 ((NULL != addr->host) && (NULL == host)))
77 {
78 GNUNET_break (0);
79 return GNUNET_NO;
80 }
81 else if ((NULL != addr->host) && (NULL != host))
82 {
83 if (0 != strcmp(addr->host, host))
84 {
85 GNUNET_break (0);
86 return GNUNET_NO;
87 }
88 }
89
90
91 if (((NULL == addr->path) && (NULL != path)) ||
92 ((NULL != addr->path) && (NULL == path)))
93 {
94 GNUNET_break (0);
95 return GNUNET_NO;
96 }
97 else if ((NULL != addr->path) && (NULL != path))
98 {
99 if (0 != strcmp(addr->path, path))
100 {
101 GNUNET_break (0);
102 return GNUNET_NO;
103 }
104 }
105
106 if ((addr->port != port))
107 {
108 GNUNET_break (0);
109 return GNUNET_NO;
110 }
111
112 return GNUNET_OK;
113} 102}
114 103
115int 104
116check_pass (char *src, 105static int
117 char * protocol, 106check_pass (const char *src,
118 char * host, 107 const char *protocol,
119 int port, 108 const char *host,
120 char * path) 109 int port,
110 const char *path)
121{ 111{
122 struct SplittedHTTPAddress * spa; 112 struct SplittedHTTPAddress *spa;
113
123 spa = http_split_address (src); 114 spa = http_split_address (src);
124 if (NULL == spa) 115 if (NULL == spa)
125 { 116 {
126 GNUNET_break (0); 117 GNUNET_break (0);
127 return GNUNET_SYSERR; 118 return GNUNET_SYSERR;
128 } 119 }
129 else 120 if (GNUNET_OK != check(spa, protocol, host, port, path))
130 { 121 {
131 if (GNUNET_OK != check(spa, protocol, host, port, path)) 122 clean (spa);
132 { 123 GNUNET_break (0);
133 clean (spa); 124 return GNUNET_SYSERR;
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 clean (spa);
138 } 125 }
126 clean (spa);
139 return GNUNET_OK; 127 return GNUNET_OK;
140} 128}
141 129
142int 130
143check_fail (char *src) 131static int
132check_fail (const char *src)
144{ 133{
145 struct SplittedHTTPAddress * spa; 134 struct SplittedHTTPAddress * spa;
135
146 spa = http_split_address (src); 136 spa = http_split_address (src);
147 if (NULL != spa) 137 if (NULL != spa)
148 { 138 {
149 GNUNET_break (0); 139 GNUNET_break (0);
150 clean (spa); 140 clean (spa);
151 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
152 } 142 }
153 return GNUNET_OK; 143 return GNUNET_OK;
154} 144}
155 145
156 146
157void 147static void
158test_pass_hostname () 148test_pass_hostname ()
159{ 149{
160 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); 150 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
@@ -171,7 +161,7 @@ test_pass_hostname ()
171} 161}
172 162
173 163
174void 164static void
175test_pass_ipv4 () 165test_pass_ipv4 ()
176{ 166{
177 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); 167 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
@@ -185,7 +175,8 @@ test_pass_ipv4 ()
185 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more"); 175 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
186} 176}
187 177
188void 178
179static void
189test_fail_ipv6 () 180test_fail_ipv6 ()
190{ 181{
191 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); 182 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
@@ -200,57 +191,58 @@ test_fail_ipv6 ()
200} 191}
201 192
202 193
203void 194static void
204test_fail () 195test_fail ()
205{ 196{
206 if (GNUNET_SYSERR == check_fail ("")) 197 if (GNUNET_SYSERR == check_fail (""))
207 GNUNET_break (0); 198 GNUNET_break (0);
208 if (GNUNET_SYSERR == check_fail ("http")) 199 if (GNUNET_SYSERR == check_fail ("http"))
209 GNUNET_break (0); 200 GNUNET_break (0);
210 if (GNUNET_SYSERR == check_fail ("://")) 201 if (GNUNET_SYSERR == check_fail ("://"))
211 GNUNET_break (0); 202 GNUNET_break (0);
212 if (GNUNET_SYSERR == check_fail ("http://")) 203 if (GNUNET_SYSERR == check_fail ("http://"))
213 GNUNET_break (0); 204 GNUNET_break (0);
214 if (GNUNET_SYSERR == check_fail ("//localhost")) 205 if (GNUNET_SYSERR == check_fail ("//localhost"))
215 GNUNET_break (0); 206 GNUNET_break (0);
216 if (GNUNET_SYSERR == check_fail ("//:80")) 207 if (GNUNET_SYSERR == check_fail ("//:80"))
217 GNUNET_break (0); 208 GNUNET_break (0);
218 if (GNUNET_SYSERR == check_fail ("//:80/")) 209 if (GNUNET_SYSERR == check_fail ("//:80/"))
219 GNUNET_break (0); 210 GNUNET_break (0);
220 if (GNUNET_SYSERR == check_fail ("//:80:")) 211 if (GNUNET_SYSERR == check_fail ("//:80:"))
221 GNUNET_break (0); 212 GNUNET_break (0);
222 if (GNUNET_SYSERR == check_fail ("http://localhost:a/")) 213 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
223 GNUNET_break (0); 214 GNUNET_break (0);
224 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/")) 215 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
225 GNUNET_break (0); 216 GNUNET_break (0);
226} 217}
227 218
219
228int 220int
229main (int argc, char *argv[]) 221main (int argc, char *argv[])
230{ 222{
231 int ret = 0; 223 int ret = 0;
232 struct SplittedHTTPAddress * spa; 224 struct SplittedHTTPAddress * spa;
233 GNUNET_log_setup ("test", "DEBUG", NULL);
234 225
226 GNUNET_log_setup ("test", "DEBUG", NULL);
235 spa = http_split_address (""); 227 spa = http_split_address ("");
236 if (NULL != spa) 228 if (NULL != spa)
237 { 229 {
238 clean (spa); 230 clean (spa);
239 GNUNET_break (0); 231 GNUNET_break (0);
240 } 232 }
241 233
242 http_split_address ("http://"); 234 http_split_address ("http://");
243 if (NULL != spa) 235 if (NULL != spa)
244 { 236 {
245 clean (spa); 237 clean (spa);
246 GNUNET_break (0); 238 GNUNET_break (0);
247 } 239 }
248 240
249 http_split_address ("://"); 241 http_split_address ("://");
250 if (NULL != spa) 242 if (NULL != spa)
251 { 243 {
252 clean (spa); 244 clean (spa);
253 GNUNET_break (0); 245 GNUNET_break (0);
254 } 246 }
255 247
256 test_pass_hostname (); 248 test_pass_hostname ();