diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/test_http_common.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/test_http_common.c')
-rw-r--r-- | src/transport/test_http_common.c | 293 |
1 files changed, 151 insertions, 142 deletions
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c index 251b1543a..d925f1318 100644 --- a/src/transport/test_http_common.c +++ b/src/transport/test_http_common.c | |||
@@ -28,227 +28,236 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | static void | 30 | static void |
31 | clean(struct SplittedHTTPAddress *addr) | 31 | clean (struct SplittedHTTPAddress *addr) |
32 | { | 32 | { |
33 | if (NULL == addr) | 33 | if (NULL == addr) |
34 | return; | 34 | return; |
35 | GNUNET_free_non_null(addr->host); | 35 | GNUNET_free_non_null (addr->host); |
36 | GNUNET_free_non_null(addr->path); | 36 | GNUNET_free_non_null (addr->path); |
37 | GNUNET_free_non_null(addr->protocol); | 37 | GNUNET_free_non_null (addr->protocol); |
38 | GNUNET_free(addr); | 38 | GNUNET_free (addr); |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static int |
43 | check(struct SplittedHTTPAddress *addr, | 43 | check (struct SplittedHTTPAddress *addr, |
44 | const char *protocol, | 44 | const char *protocol, |
45 | const char *host, | 45 | const char *host, |
46 | int port, | 46 | int port, |
47 | const char *path) | 47 | const char *path) |
48 | { | 48 | { |
49 | if (NULL == addr) | 49 | if (NULL == addr) |
50 | return GNUNET_NO; | 50 | return GNUNET_NO; |
51 | if (((NULL == addr->protocol) && (NULL != protocol)) || | 51 | if (((NULL == addr->protocol) && (NULL != protocol)) || |
52 | ((NULL != addr->protocol) && (NULL == protocol))) | 52 | ((NULL != addr->protocol) && (NULL == protocol))) |
53 | { | 53 | { |
54 | GNUNET_break(0); | 54 | GNUNET_break (0); |
55 | return GNUNET_NO; | 55 | return GNUNET_NO; |
56 | } | 56 | } |
57 | else if ((NULL != addr->protocol) && (NULL != protocol)) | 57 | else if ((NULL != addr->protocol) && (NULL != protocol)) |
58 | { | ||
59 | if (0 != strcmp (addr->protocol, protocol)) | ||
58 | { | 60 | { |
59 | if (0 != strcmp(addr->protocol, protocol)) | 61 | GNUNET_break (0); |
60 | { | 62 | return GNUNET_NO; |
61 | GNUNET_break(0); | ||
62 | return GNUNET_NO; | ||
63 | } | ||
64 | } | 63 | } |
64 | } | ||
65 | 65 | ||
66 | if (((NULL == addr->host) && (NULL != host)) || | 66 | if (((NULL == addr->host) && (NULL != host)) || |
67 | ((NULL != addr->host) && (NULL == host))) | 67 | ((NULL != addr->host) && (NULL == host))) |
68 | { | 68 | { |
69 | GNUNET_break(0); | 69 | GNUNET_break (0); |
70 | return GNUNET_NO; | 70 | return GNUNET_NO; |
71 | } | 71 | } |
72 | else if ((NULL != addr->host) && (NULL != host)) | 72 | else if ((NULL != addr->host) && (NULL != host)) |
73 | { | ||
74 | if (0 != strcmp (addr->host, host)) | ||
73 | { | 75 | { |
74 | if (0 != strcmp(addr->host, host)) | 76 | GNUNET_break (0); |
75 | { | 77 | return GNUNET_NO; |
76 | GNUNET_break(0); | ||
77 | return GNUNET_NO; | ||
78 | } | ||
79 | } | 78 | } |
79 | } | ||
80 | 80 | ||
81 | if (((NULL == addr->path) && (NULL != path)) || | 81 | if (((NULL == addr->path) && (NULL != path)) || |
82 | ((NULL != addr->path) && (NULL == path))) | 82 | ((NULL != addr->path) && (NULL == path))) |
83 | { | 83 | { |
84 | GNUNET_break(0); | 84 | GNUNET_break (0); |
85 | return GNUNET_NO; | 85 | return GNUNET_NO; |
86 | } | 86 | } |
87 | else if ((NULL != addr->path) && (NULL != path)) | 87 | else if ((NULL != addr->path) && (NULL != path)) |
88 | { | ||
89 | if (0 != strcmp (addr->path, path)) | ||
88 | { | 90 | { |
89 | if (0 != strcmp(addr->path, path)) | 91 | GNUNET_break (0); |
90 | { | 92 | return GNUNET_NO; |
91 | GNUNET_break(0); | ||
92 | return GNUNET_NO; | ||
93 | } | ||
94 | } | 93 | } |
94 | } | ||
95 | 95 | ||
96 | if ((addr->port != port)) | 96 | if ((addr->port != port)) |
97 | { | 97 | { |
98 | GNUNET_break(0); | 98 | GNUNET_break (0); |
99 | return GNUNET_NO; | 99 | return GNUNET_NO; |
100 | } | 100 | } |
101 | return GNUNET_OK; | 101 | return GNUNET_OK; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | static int | 105 | static int |
106 | check_pass(const char *src, | 106 | check_pass (const char *src, |
107 | const char *protocol, | 107 | const char *protocol, |
108 | const char *host, | 108 | const char *host, |
109 | int port, | 109 | int port, |
110 | const char *path) | 110 | const char *path) |
111 | { | 111 | { |
112 | struct SplittedHTTPAddress *spa; | 112 | struct SplittedHTTPAddress *spa; |
113 | 113 | ||
114 | spa = http_split_address(src); | 114 | spa = http_split_address (src); |
115 | if (NULL == spa) | 115 | if (NULL == spa) |
116 | { | 116 | { |
117 | GNUNET_break(0); | 117 | GNUNET_break (0); |
118 | return GNUNET_SYSERR; | 118 | return GNUNET_SYSERR; |
119 | } | 119 | } |
120 | if (GNUNET_OK != check(spa, protocol, host, port, path)) | 120 | if (GNUNET_OK != check (spa, protocol, host, port, path)) |
121 | { | 121 | { |
122 | clean(spa); | 122 | clean (spa); |
123 | GNUNET_break(0); | 123 | GNUNET_break (0); |
124 | return GNUNET_SYSERR; | 124 | return GNUNET_SYSERR; |
125 | } | 125 | } |
126 | clean(spa); | 126 | clean (spa); |
127 | return GNUNET_OK; | 127 | return GNUNET_OK; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | static int | 131 | static int |
132 | check_fail(const char *src) | 132 | check_fail (const char *src) |
133 | { | 133 | { |
134 | struct SplittedHTTPAddress * spa; | 134 | struct SplittedHTTPAddress *spa; |
135 | 135 | ||
136 | spa = http_split_address(src); | 136 | spa = http_split_address (src); |
137 | if (NULL != spa) | 137 | if (NULL != spa) |
138 | { | 138 | { |
139 | GNUNET_break(0); | 139 | GNUNET_break (0); |
140 | clean(spa); | 140 | clean (spa); |
141 | return GNUNET_SYSERR; | 141 | return GNUNET_SYSERR; |
142 | } | 142 | } |
143 | return GNUNET_OK; | 143 | return GNUNET_OK; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | static void | 147 | static void |
148 | test_pass_hostname() | 148 | test_pass_hostname () |
149 | { | 149 | { |
150 | check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); | 150 | check_pass ("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); |
151 | check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); | 151 | check_pass ("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, |
152 | check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path"); | 152 | "/"); |
153 | check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/"); | 153 | check_pass ("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, |
154 | check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more"); | 154 | "/path"); |
155 | check_pass("http://test.local:81", "http", "test.local", 81, ""); | 155 | check_pass ("http://test.local/path/", "http", "test.local", |
156 | check_pass("http://test.local:81/", "http", "test.local", 81, "/"); | 156 | HTTP_DEFAULT_PORT, "/path/"); |
157 | check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); | 157 | check_pass ("http://test.local/path/more", "http", "test.local", |
158 | check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); | 158 | HTTP_DEFAULT_PORT, "/path/more"); |
159 | check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); | 159 | check_pass ("http://test.local:81", "http", "test.local", 81, ""); |
160 | check_pass ("http://test.local:81/", "http", "test.local", 81, "/"); | ||
161 | check_pass ("http://test.local:81/path", "http", "test.local", 81, "/path"); | ||
162 | check_pass ("http://test.local:81/path/", "http", "test.local", 81, "/path/"); | ||
163 | check_pass ("http://test.local:81/path/more", "http", "test.local", 81, | ||
164 | "/path/more"); | ||
160 | } | 165 | } |
161 | 166 | ||
162 | 167 | ||
163 | static void | 168 | static void |
164 | test_pass_ipv4() | 169 | test_pass_ipv4 () |
165 | { | 170 | { |
166 | check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); | 171 | 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, "/"); | 172 | check_pass ("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); |
168 | check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path"); | 173 | check_pass ("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, |
169 | check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/"); | 174 | "/path"); |
170 | check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, ""); | 175 | check_pass ("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, |
171 | check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); | 176 | "/path/"); |
172 | check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); | 177 | check_pass ("http://127.0.0.1:81", "http", "127.0.0.1", 81, ""); |
173 | check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); | 178 | check_pass ("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); |
174 | check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more"); | 179 | check_pass ("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); |
180 | check_pass ("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); | ||
181 | check_pass ("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, | ||
182 | "/path/more"); | ||
175 | } | 183 | } |
176 | 184 | ||
177 | 185 | ||
178 | static void | 186 | static void |
179 | test_fail_ipv6() | 187 | test_fail_ipv6 () |
180 | { | 188 | { |
181 | check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); | 189 | check_pass ("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); |
182 | check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); | 190 | check_pass ("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); |
183 | check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path"); | 191 | check_pass ("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path"); |
184 | check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/"); | 192 | check_pass ("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, |
185 | check_pass("http://[::1]:81", "http", "[::1]", 81, ""); | 193 | "/path/"); |
186 | check_pass("http://[::1]:81/", "http", "[::1]", 81, "/"); | 194 | check_pass ("http://[::1]:81", "http", "[::1]", 81, ""); |
187 | check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path"); | 195 | check_pass ("http://[::1]:81/", "http", "[::1]", 81, "/"); |
188 | check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); | 196 | check_pass ("http://[::1]:81/path", "http", "[::1]", 81, "/path"); |
189 | check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more"); | 197 | check_pass ("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); |
198 | check_pass ("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more"); | ||
190 | } | 199 | } |
191 | 200 | ||
192 | 201 | ||
193 | static void | 202 | static void |
194 | test_fail() | 203 | test_fail () |
195 | { | 204 | { |
196 | if (GNUNET_SYSERR == check_fail("")) | 205 | if (GNUNET_SYSERR == check_fail ("")) |
197 | GNUNET_break(0); | 206 | GNUNET_break (0); |
198 | if (GNUNET_SYSERR == check_fail("http")) | 207 | if (GNUNET_SYSERR == check_fail ("http")) |
199 | GNUNET_break(0); | 208 | GNUNET_break (0); |
200 | if (GNUNET_SYSERR == check_fail("://")) | 209 | if (GNUNET_SYSERR == check_fail ("://")) |
201 | GNUNET_break(0); | 210 | GNUNET_break (0); |
202 | if (GNUNET_SYSERR == check_fail("http://")) | 211 | if (GNUNET_SYSERR == check_fail ("http://")) |
203 | GNUNET_break(0); | 212 | GNUNET_break (0); |
204 | if (GNUNET_SYSERR == check_fail("//localhost")) | 213 | if (GNUNET_SYSERR == check_fail ("//localhost")) |
205 | GNUNET_break(0); | 214 | GNUNET_break (0); |
206 | if (GNUNET_SYSERR == check_fail("//:80")) | 215 | if (GNUNET_SYSERR == check_fail ("//:80")) |
207 | GNUNET_break(0); | 216 | GNUNET_break (0); |
208 | if (GNUNET_SYSERR == check_fail("//:80/")) | 217 | if (GNUNET_SYSERR == check_fail ("//:80/")) |
209 | GNUNET_break(0); | 218 | GNUNET_break (0); |
210 | if (GNUNET_SYSERR == check_fail("//:80:")) | 219 | if (GNUNET_SYSERR == check_fail ("//:80:")) |
211 | GNUNET_break(0); | 220 | GNUNET_break (0); |
212 | if (GNUNET_SYSERR == check_fail("http://localhost:a/")) | 221 | if (GNUNET_SYSERR == check_fail ("http://localhost:a/")) |
213 | GNUNET_break(0); | 222 | GNUNET_break (0); |
214 | if (GNUNET_SYSERR == check_fail("http://127.0.0.1:a/")) | 223 | if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/")) |
215 | GNUNET_break(0); | 224 | GNUNET_break (0); |
216 | } | 225 | } |
217 | 226 | ||
218 | 227 | ||
219 | int | 228 | int |
220 | main(int argc, char *argv[]) | 229 | main (int argc, char *argv[]) |
221 | { | 230 | { |
222 | int ret = 0; | 231 | int ret = 0; |
223 | struct SplittedHTTPAddress * spa; | 232 | struct SplittedHTTPAddress *spa; |
224 | 233 | ||
225 | GNUNET_log_setup("test", "DEBUG", NULL); | 234 | GNUNET_log_setup ("test", "DEBUG", NULL); |
226 | spa = http_split_address(""); | 235 | spa = http_split_address (""); |
227 | if (NULL != spa) | 236 | if (NULL != spa) |
228 | { | 237 | { |
229 | clean(spa); | 238 | clean (spa); |
230 | spa = NULL; | 239 | spa = NULL; |
231 | GNUNET_break(0); | 240 | GNUNET_break (0); |
232 | } | 241 | } |
233 | 242 | ||
234 | spa = http_split_address("http://"); | 243 | spa = http_split_address ("http://"); |
235 | if (NULL != spa) | 244 | if (NULL != spa) |
236 | { | 245 | { |
237 | clean(spa); | 246 | clean (spa); |
238 | GNUNET_break(0); | 247 | GNUNET_break (0); |
239 | } | 248 | } |
240 | 249 | ||
241 | spa = http_split_address("://"); | 250 | spa = http_split_address ("://"); |
242 | if (NULL != spa) | 251 | if (NULL != spa) |
243 | { | 252 | { |
244 | clean(spa); | 253 | clean (spa); |
245 | GNUNET_break(0); | 254 | GNUNET_break (0); |
246 | } | 255 | } |
247 | 256 | ||
248 | test_pass_hostname(); | 257 | test_pass_hostname (); |
249 | test_pass_ipv4(); | 258 | test_pass_ipv4 (); |
250 | test_fail_ipv6(); | 259 | test_fail_ipv6 (); |
251 | test_fail(); | 260 | test_fail (); |
252 | 261 | ||
253 | return ret; | 262 | return ret; |
254 | } | 263 | } |