diff options
Diffstat (limited to 'src/transport/test_http_common.c')
-rw-r--r-- | src/transport/test_http_common.c | 250 |
1 files changed, 121 insertions, 129 deletions
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 | ||
29 | struct SplittedHTTPAddress | ||
30 | { | ||
31 | char *protocol; | ||
32 | char *host; | ||
33 | char *path; | ||
34 | int port; | ||
35 | }; | ||
36 | 29 | ||
37 | void | 30 | static void |
38 | clean (struct SplittedHTTPAddress *addr) | 31 | clean (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 | ||
50 | int | 42 | static int |
51 | check (struct SplittedHTTPAddress *addr, | 43 | check (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 | ||
115 | int | 104 | |
116 | check_pass (char *src, | 105 | static int |
117 | char * protocol, | 106 | check_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 | ||
142 | int | 130 | |
143 | check_fail (char *src) | 131 | static int |
132 | check_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 | ||
157 | void | 147 | static void |
158 | test_pass_hostname () | 148 | test_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 | ||
174 | void | 164 | static void |
175 | test_pass_ipv4 () | 165 | test_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 | ||
188 | void | 178 | |
179 | static void | ||
189 | test_fail_ipv6 () | 180 | test_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 | ||
203 | void | 194 | static void |
204 | test_fail () | 195 | test_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 | |||
228 | int | 220 | int |
229 | main (int argc, char *argv[]) | 221 | main (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 (); |