diff options
Diffstat (limited to 'src/gns/test_gns_proxy.c')
-rw-r--r-- | src/gns/test_gns_proxy.c | 548 |
1 files changed, 274 insertions, 274 deletions
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c index 053f5f898..2df422731 100644 --- a/src/gns/test_gns_proxy.c +++ b/src/gns/test_gns_proxy.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file test_gns_proxy.c | 22 | * @file test_gns_proxy.c |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #define TEST_DOMAIN "www.test" | 38 | #define TEST_DOMAIN "www.test" |
39 | 39 | ||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Return value for 'main'. | 43 | * Return value for 'main'. |
@@ -69,8 +69,7 @@ static gnutls_x509_crt_t proxy_cert; | |||
69 | 69 | ||
70 | static gnutls_x509_privkey_t proxy_key; | 70 | static gnutls_x509_privkey_t proxy_key; |
71 | 71 | ||
72 | struct CBC | 72 | struct CBC { |
73 | { | ||
74 | char buf[1024]; | 73 | char buf[1024]; |
75 | size_t pos; | 74 | size_t pos; |
76 | }; | 75 | }; |
@@ -85,30 +84,30 @@ static struct CBC cbc; | |||
85 | * @return NULL on error | 84 | * @return NULL on error |
86 | */ | 85 | */ |
87 | static void* | 86 | static void* |
88 | load_file (const char* filename, | 87 | load_file(const char* filename, |
89 | unsigned int* size) | 88 | unsigned int* size) |
90 | { | 89 | { |
91 | void *buffer; | 90 | void *buffer; |
92 | uint64_t fsize; | 91 | uint64_t fsize; |
93 | 92 | ||
94 | if (GNUNET_OK != | 93 | if (GNUNET_OK != |
95 | GNUNET_DISK_file_size (filename, | 94 | GNUNET_DISK_file_size(filename, |
96 | &fsize, | 95 | &fsize, |
97 | GNUNET_YES, | 96 | GNUNET_YES, |
98 | GNUNET_YES)) | 97 | GNUNET_YES)) |
99 | return NULL; | 98 | return NULL; |
100 | if (fsize > MAX_PEM_SIZE) | 99 | if (fsize > MAX_PEM_SIZE) |
101 | return NULL; | 100 | return NULL; |
102 | *size = (unsigned int) fsize; | 101 | *size = (unsigned int)fsize; |
103 | buffer = GNUNET_malloc (*size); | 102 | buffer = GNUNET_malloc(*size); |
104 | if (fsize != | 103 | if (fsize != |
105 | GNUNET_DISK_fn_read (filename, | 104 | GNUNET_DISK_fn_read(filename, |
106 | buffer, | 105 | buffer, |
107 | (size_t) fsize)) | 106 | (size_t)fsize)) |
108 | { | 107 | { |
109 | GNUNET_free (buffer); | 108 | GNUNET_free(buffer); |
110 | return NULL; | 109 | return NULL; |
111 | } | 110 | } |
112 | return buffer; | 111 | return buffer; |
113 | } | 112 | } |
114 | 113 | ||
@@ -120,25 +119,25 @@ load_file (const char* filename, | |||
120 | * @return #GNUNET_OK on success | 119 | * @return #GNUNET_OK on success |
121 | */ | 120 | */ |
122 | static int | 121 | static int |
123 | load_key_from_file (gnutls_x509_privkey_t key, | 122 | load_key_from_file(gnutls_x509_privkey_t key, |
124 | const char* keyfile) | 123 | const char* keyfile) |
125 | { | 124 | { |
126 | gnutls_datum_t key_data; | 125 | gnutls_datum_t key_data; |
127 | int ret; | 126 | int ret; |
128 | 127 | ||
129 | key_data.data = load_file (keyfile, | 128 | key_data.data = load_file(keyfile, |
130 | &key_data.size); | 129 | &key_data.size); |
131 | if (NULL == key_data.data) | 130 | if (NULL == key_data.data) |
132 | return GNUNET_SYSERR; | 131 | return GNUNET_SYSERR; |
133 | ret = gnutls_x509_privkey_import (key, &key_data, | 132 | ret = gnutls_x509_privkey_import(key, &key_data, |
134 | GNUTLS_X509_FMT_PEM); | 133 | GNUTLS_X509_FMT_PEM); |
135 | if (GNUTLS_E_SUCCESS != ret) | 134 | if (GNUTLS_E_SUCCESS != ret) |
136 | { | 135 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 136 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
138 | _("Unable to import private key from file `%s'\n"), | 137 | _("Unable to import private key from file `%s'\n"), |
139 | keyfile); | 138 | keyfile); |
140 | } | 139 | } |
141 | GNUNET_free_non_null (key_data.data); | 140 | GNUNET_free_non_null(key_data.data); |
142 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 141 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
143 | } | 142 | } |
144 | 143 | ||
@@ -150,107 +149,108 @@ load_key_from_file (gnutls_x509_privkey_t key, | |||
150 | * @return #GNUNET_OK on success | 149 | * @return #GNUNET_OK on success |
151 | */ | 150 | */ |
152 | static int | 151 | static int |
153 | load_cert_from_file (gnutls_x509_crt_t crt, | 152 | load_cert_from_file(gnutls_x509_crt_t crt, |
154 | const char* certfile) | 153 | const char* certfile) |
155 | { | 154 | { |
156 | gnutls_datum_t cert_data; | 155 | gnutls_datum_t cert_data; |
157 | int ret; | 156 | int ret; |
158 | 157 | ||
159 | cert_data.data = load_file (certfile, | 158 | cert_data.data = load_file(certfile, |
160 | &cert_data.size); | 159 | &cert_data.size); |
161 | if (NULL == cert_data.data) | 160 | if (NULL == cert_data.data) |
162 | return GNUNET_SYSERR; | 161 | return GNUNET_SYSERR; |
163 | ret = gnutls_x509_crt_import (crt, | 162 | ret = gnutls_x509_crt_import(crt, |
164 | &cert_data, | 163 | &cert_data, |
165 | GNUTLS_X509_FMT_PEM); | 164 | GNUTLS_X509_FMT_PEM); |
166 | if (GNUTLS_E_SUCCESS != ret) | 165 | if (GNUTLS_E_SUCCESS != ret) |
167 | { | 166 | { |
168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 167 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
169 | _("Unable to import certificate from `%s'\n"), | 168 | _("Unable to import certificate from `%s'\n"), |
170 | certfile); | 169 | certfile); |
171 | } | 170 | } |
172 | GNUNET_free_non_null (cert_data.data); | 171 | GNUNET_free_non_null(cert_data.data); |
173 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 172 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
174 | } | 173 | } |
175 | 174 | ||
176 | static size_t | 175 | static size_t |
177 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 176 | copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx) |
178 | { | 177 | { |
179 | struct CBC *cbc = ctx; | 178 | struct CBC *cbc = ctx; |
180 | 179 | ||
181 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) | 180 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) |
182 | return 0; /* overflow */ | 181 | return 0; /* overflow */ |
183 | GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | 182 | GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb); |
184 | cbc->pos += size * nmemb; | 183 | cbc->pos += size * nmemb; |
185 | return size * nmemb; | 184 | return size * nmemb; |
186 | } | 185 | } |
187 | 186 | ||
188 | 187 | ||
189 | static int | 188 | static int |
190 | mhd_ahc (void *cls, | 189 | mhd_ahc(void *cls, |
191 | struct MHD_Connection *connection, | 190 | struct MHD_Connection *connection, |
192 | const char *url, | 191 | const char *url, |
193 | const char *method, | 192 | const char *method, |
194 | const char *version, | 193 | const char *version, |
195 | const char *upload_data, size_t *upload_data_size, | 194 | const char *upload_data, size_t *upload_data_size, |
196 | void **unused) | 195 | void **unused) |
197 | { | 196 | { |
198 | static int ptr; | 197 | static int ptr; |
199 | struct MHD_Response *response; | 198 | struct MHD_Response *response; |
200 | int ret; | 199 | int ret; |
201 | 200 | ||
202 | if (0 != strcmp ("GET", method)) | 201 | if (0 != strcmp("GET", method)) |
203 | return MHD_NO; /* unexpected method */ | 202 | return MHD_NO; /* unexpected method */ |
204 | if (&ptr != *unused) | 203 | if (&ptr != *unused) |
205 | { | 204 | { |
206 | *unused = &ptr; | 205 | *unused = &ptr; |
207 | return MHD_YES; | 206 | return MHD_YES; |
208 | } | 207 | } |
209 | *unused = NULL; | 208 | *unused = NULL; |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); |
211 | response = MHD_create_response_from_buffer (strlen (url), | 210 | response = MHD_create_response_from_buffer(strlen(url), |
212 | (void *) url, | 211 | (void *)url, |
213 | MHD_RESPMEM_MUST_COPY); | 212 | MHD_RESPMEM_MUST_COPY); |
214 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 213 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); |
215 | MHD_destroy_response (response); | 214 | MHD_destroy_response(response); |
216 | if (ret == MHD_NO) { | 215 | if (ret == MHD_NO) |
217 | global_ret = 1; | 216 | { |
218 | abort (); | 217 | global_ret = 1; |
219 | } | 218 | abort(); |
219 | } | ||
220 | global_ret = 0; | 220 | global_ret = 0; |
221 | return ret; | 221 | return ret; |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | static void | 225 | static void |
226 | do_shutdown () | 226 | do_shutdown() |
227 | { | 227 | { |
228 | if (mhd_task_id != NULL) | 228 | if (mhd_task_id != NULL) |
229 | { | 229 | { |
230 | GNUNET_SCHEDULER_cancel (mhd_task_id); | 230 | GNUNET_SCHEDULER_cancel(mhd_task_id); |
231 | mhd_task_id = NULL; | 231 | mhd_task_id = NULL; |
232 | } | 232 | } |
233 | if (curl_task_id != NULL) | 233 | if (curl_task_id != NULL) |
234 | { | 234 | { |
235 | GNUNET_SCHEDULER_cancel (curl_task_id); | 235 | GNUNET_SCHEDULER_cancel(curl_task_id); |
236 | curl_task_id = NULL; | 236 | curl_task_id = NULL; |
237 | } | 237 | } |
238 | if (NULL != mhd) | 238 | if (NULL != mhd) |
239 | { | 239 | { |
240 | MHD_stop_daemon (mhd); | 240 | MHD_stop_daemon(mhd); |
241 | mhd = NULL; | 241 | mhd = NULL; |
242 | } | 242 | } |
243 | GNUNET_free_non_null (url); | 243 | GNUNET_free_non_null(url); |
244 | 244 | ||
245 | if (NULL != proxy_proc) | 245 | if (NULL != proxy_proc) |
246 | { | 246 | { |
247 | (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL); | 247 | (void)GNUNET_OS_process_kill(proxy_proc, SIGKILL); |
248 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proxy_proc)); | 248 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proxy_proc)); |
249 | GNUNET_OS_process_destroy (proxy_proc); | 249 | GNUNET_OS_process_destroy(proxy_proc); |
250 | proxy_proc = NULL; | 250 | proxy_proc = NULL; |
251 | } | 251 | } |
252 | url = NULL; | 252 | url = NULL; |
253 | GNUNET_SCHEDULER_shutdown (); | 253 | GNUNET_SCHEDULER_shutdown(); |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
@@ -258,19 +258,19 @@ do_shutdown () | |||
258 | * Function to run the HTTP client. | 258 | * Function to run the HTTP client. |
259 | */ | 259 | */ |
260 | static void | 260 | static void |
261 | curl_main (void); | 261 | curl_main(void); |
262 | 262 | ||
263 | 263 | ||
264 | static void | 264 | static void |
265 | curl_task (void *cls) | 265 | curl_task(void *cls) |
266 | { | 266 | { |
267 | curl_task_id = NULL; | 267 | curl_task_id = NULL; |
268 | curl_main (); | 268 | curl_main(); |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | static void | 272 | static void |
273 | curl_main () | 273 | curl_main() |
274 | { | 274 | { |
275 | fd_set rs; | 275 | fd_set rs; |
276 | fd_set ws; | 276 | fd_set ws; |
@@ -284,93 +284,93 @@ curl_main () | |||
284 | struct CURLMsg *msg; | 284 | struct CURLMsg *msg; |
285 | 285 | ||
286 | max = 0; | 286 | max = 0; |
287 | FD_ZERO (&rs); | 287 | FD_ZERO(&rs); |
288 | FD_ZERO (&ws); | 288 | FD_ZERO(&ws); |
289 | FD_ZERO (&es); | 289 | FD_ZERO(&es); |
290 | curl_multi_perform (multi, &running); | 290 | curl_multi_perform(multi, &running); |
291 | if (running == 0) | 291 | if (running == 0) |
292 | { | ||
293 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | ||
294 | if (msg->msg == CURLMSG_DONE) | ||
295 | { | 292 | { |
296 | if (msg->data.result != CURLE_OK) | 293 | GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running))); |
297 | { | 294 | if (msg->msg == CURLMSG_DONE) |
298 | fprintf (stderr, | 295 | { |
299 | "%s failed at %s:%d: `%s'\n", | 296 | if (msg->data.result != CURLE_OK) |
300 | "curl_multi_perform", | 297 | { |
301 | __FILE__, | 298 | fprintf(stderr, |
302 | __LINE__, curl_easy_strerror (msg->data.result)); | 299 | "%s failed at %s:%d: `%s'\n", |
303 | global_ret = 1; | 300 | "curl_multi_perform", |
304 | } | 301 | __FILE__, |
302 | __LINE__, curl_easy_strerror(msg->data.result)); | ||
303 | global_ret = 1; | ||
304 | } | ||
305 | } | ||
306 | curl_multi_remove_handle(multi, curl); | ||
307 | curl_multi_cleanup(multi); | ||
308 | curl_easy_cleanup(curl); | ||
309 | curl = NULL; | ||
310 | multi = NULL; | ||
311 | if (cbc.pos != strlen("/hello_world")) | ||
312 | { | ||
313 | GNUNET_break(0); | ||
314 | global_ret = 2; | ||
315 | } | ||
316 | if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) | ||
317 | { | ||
318 | GNUNET_break(0); | ||
319 | global_ret = 3; | ||
320 | } | ||
321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | ||
322 | do_shutdown(); | ||
323 | return; | ||
305 | } | 324 | } |
306 | curl_multi_remove_handle (multi, curl); | 325 | GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max)); |
307 | curl_multi_cleanup (multi); | 326 | if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || |
308 | curl_easy_cleanup (curl); | 327 | (-1 == timeout)) |
309 | curl = NULL; | ||
310 | multi = NULL; | ||
311 | if (cbc.pos != strlen ("/hello_world")) | ||
312 | { | ||
313 | GNUNET_break (0); | ||
314 | global_ret = 2; | ||
315 | } | ||
316 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
317 | { | ||
318 | GNUNET_break (0); | ||
319 | global_ret = 3; | ||
320 | } | ||
321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | ||
322 | do_shutdown (); | ||
323 | return; | ||
324 | } | ||
325 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | ||
326 | if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | ||
327 | (-1 == timeout) ) | ||
328 | delay = GNUNET_TIME_UNIT_SECONDS; | 328 | delay = GNUNET_TIME_UNIT_SECONDS; |
329 | else | 329 | else |
330 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); | 330 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int)timeout); |
331 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 331 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
332 | &rs, | 332 | &rs, |
333 | max + 1); | 333 | max + 1); |
334 | GNUNET_NETWORK_fdset_copy_native (&nws, | 334 | GNUNET_NETWORK_fdset_copy_native(&nws, |
335 | &ws, | 335 | &ws, |
336 | max + 1); | 336 | max + 1); |
337 | curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 337 | curl_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
338 | delay, | 338 | delay, |
339 | &nrs, | 339 | &nrs, |
340 | &nws, | 340 | &nws, |
341 | &curl_task, | 341 | &curl_task, |
342 | NULL); | 342 | NULL); |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | static void | 346 | static void |
347 | start_curl (void *cls) | 347 | start_curl(void *cls) |
348 | { | 348 | { |
349 | curl_task_id = NULL; | 349 | curl_task_id = NULL; |
350 | GNUNET_asprintf (&url, | 350 | GNUNET_asprintf(&url, |
351 | "https://%s:%d/hello_world", | 351 | "https://%s:%d/hello_world", |
352 | TEST_DOMAIN, port); | 352 | TEST_DOMAIN, port); |
353 | curl = curl_easy_init (); | 353 | curl = curl_easy_init(); |
354 | curl_easy_setopt (curl, CURLOPT_URL, url); | 354 | curl_easy_setopt(curl, CURLOPT_URL, url); |
355 | //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world"); | 355 | //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world"); |
356 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | 356 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ©_buffer); |
357 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 357 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc); |
358 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 358 | curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); |
359 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 359 | curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L); |
360 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | 360 | curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L); |
361 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 361 | curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
362 | curl_easy_setopt (curl, CURLOPT_CAINFO, cafile_opt); | 362 | curl_easy_setopt(curl, CURLOPT_CAINFO, cafile_opt); |
363 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L); | 363 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L); |
364 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L); | 364 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L); |
365 | curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); | 365 | curl_easy_setopt(curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); |
366 | 366 | ||
367 | multi = curl_multi_init (); | 367 | multi = curl_multi_init(); |
368 | GNUNET_assert (multi != NULL); | 368 | GNUNET_assert(multi != NULL); |
369 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 369 | GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl)); |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 370 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
371 | "Beginning HTTP download from `%s'\n", | 371 | "Beginning HTTP download from `%s'\n", |
372 | url); | 372 | url); |
373 | curl_main (); | 373 | curl_main(); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
@@ -387,12 +387,12 @@ start_curl (void *cls) | |||
387 | * specified target peer; NULL on error | 387 | * specified target peer; NULL on error |
388 | */ | 388 | */ |
389 | static void | 389 | static void |
390 | commence_testing (void *cls) | 390 | commence_testing(void *cls) |
391 | { | 391 | { |
392 | curl_task_id = | 392 | curl_task_id = |
393 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 393 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
394 | &start_curl, | 394 | &start_curl, |
395 | NULL); | 395 | NULL); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
@@ -400,20 +400,20 @@ commence_testing (void *cls) | |||
400 | * Function to keep the HTTP server running. | 400 | * Function to keep the HTTP server running. |
401 | */ | 401 | */ |
402 | static void | 402 | static void |
403 | mhd_main (void); | 403 | mhd_main(void); |
404 | 404 | ||
405 | 405 | ||
406 | static void | 406 | static void |
407 | mhd_task (void *cls) | 407 | mhd_task(void *cls) |
408 | { | 408 | { |
409 | mhd_task_id = NULL; | 409 | mhd_task_id = NULL; |
410 | MHD_run (mhd); | 410 | MHD_run(mhd); |
411 | mhd_main (); | 411 | mhd_main(); |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | static void | 415 | static void |
416 | mhd_main () | 416 | mhd_main() |
417 | { | 417 | { |
418 | struct GNUNET_NETWORK_FDSet nrs; | 418 | struct GNUNET_NETWORK_FDSet nrs; |
419 | struct GNUNET_NETWORK_FDSet nws; | 419 | struct GNUNET_NETWORK_FDSet nws; |
@@ -424,30 +424,30 @@ mhd_main () | |||
424 | unsigned MHD_LONG_LONG timeout; | 424 | unsigned MHD_LONG_LONG timeout; |
425 | struct GNUNET_TIME_Relative delay; | 425 | struct GNUNET_TIME_Relative delay; |
426 | 426 | ||
427 | GNUNET_assert (NULL == mhd_task_id); | 427 | GNUNET_assert(NULL == mhd_task_id); |
428 | FD_ZERO (&rs); | 428 | FD_ZERO(&rs); |
429 | FD_ZERO (&ws); | 429 | FD_ZERO(&ws); |
430 | FD_ZERO (&es); | 430 | FD_ZERO(&es); |
431 | max_fd = -1; | 431 | max_fd = -1; |
432 | GNUNET_assert (MHD_YES == | 432 | GNUNET_assert(MHD_YES == |
433 | MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | 433 | MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd)); |
434 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | 434 | if (MHD_YES == MHD_get_timeout(mhd, &timeout)) |
435 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 435 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
436 | (unsigned int) timeout); | 436 | (unsigned int)timeout); |
437 | else | 437 | else |
438 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 438 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
439 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 439 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
440 | &rs, | 440 | &rs, |
441 | max_fd + 1); | 441 | max_fd + 1); |
442 | GNUNET_NETWORK_fdset_copy_native (&nws, | 442 | GNUNET_NETWORK_fdset_copy_native(&nws, |
443 | &ws, | 443 | &ws, |
444 | max_fd + 1); | 444 | max_fd + 1); |
445 | mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 445 | mhd_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
446 | delay, | 446 | delay, |
447 | &nrs, | 447 | &nrs, |
448 | &nws, | 448 | &nws, |
449 | &mhd_task, | 449 | &mhd_task, |
450 | NULL); | 450 | NULL); |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
@@ -460,105 +460,105 @@ mhd_main () | |||
460 | * @param c configuration | 460 | * @param c configuration |
461 | */ | 461 | */ |
462 | static void | 462 | static void |
463 | run (void *cls, | 463 | run(void *cls, |
464 | char *const *args, | 464 | char *const *args, |
465 | const char *cfgfile, | 465 | const char *cfgfile, |
466 | const struct GNUNET_CONFIGURATION_Handle *c) | 466 | const struct GNUNET_CONFIGURATION_Handle *c) |
467 | { | 467 | { |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
469 | "Using `%s' as CA\n", | 469 | "Using `%s' as CA\n", |
470 | cafile_srv); | 470 | cafile_srv); |
471 | char cert[MAX_PEM_SIZE]; | 471 | char cert[MAX_PEM_SIZE]; |
472 | char key[MAX_PEM_SIZE]; | 472 | char key[MAX_PEM_SIZE]; |
473 | size_t key_buf_size; | 473 | size_t key_buf_size; |
474 | size_t cert_buf_size; | 474 | size_t cert_buf_size; |
475 | 475 | ||
476 | gnutls_global_init (); | 476 | gnutls_global_init(); |
477 | gnutls_x509_crt_init (&proxy_cert); | 477 | gnutls_x509_crt_init(&proxy_cert); |
478 | gnutls_x509_privkey_init (&proxy_key); | 478 | gnutls_x509_privkey_init(&proxy_key); |
479 | 479 | ||
480 | if ( (GNUNET_OK != | 480 | if ((GNUNET_OK != |
481 | load_cert_from_file (proxy_cert, | 481 | load_cert_from_file(proxy_cert, |
482 | cafile_srv)) || | 482 | cafile_srv)) || |
483 | (GNUNET_OK != | 483 | (GNUNET_OK != |
484 | load_key_from_file (proxy_key, | 484 | load_key_from_file(proxy_key, |
485 | cafile_srv)) ) | 485 | cafile_srv))) |
486 | { | 486 | { |
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 487 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
488 | _("Failed to load X.509 key and certificate from `%s'\n"), | 488 | _("Failed to load X.509 key and certificate from `%s'\n"), |
489 | cafile_srv); | 489 | cafile_srv); |
490 | gnutls_x509_crt_deinit (proxy_cert); | 490 | gnutls_x509_crt_deinit(proxy_cert); |
491 | gnutls_x509_privkey_deinit (proxy_key); | 491 | gnutls_x509_privkey_deinit(proxy_key); |
492 | gnutls_global_deinit (); | 492 | gnutls_global_deinit(); |
493 | return; | 493 | return; |
494 | } | 494 | } |
495 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 495 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
496 | NULL); | 496 | NULL); |
497 | key_buf_size = sizeof (key); | 497 | key_buf_size = sizeof(key); |
498 | cert_buf_size = sizeof (cert); | 498 | cert_buf_size = sizeof(cert); |
499 | gnutls_x509_crt_export (proxy_cert, | 499 | gnutls_x509_crt_export(proxy_cert, |
500 | GNUTLS_X509_FMT_PEM, | 500 | GNUTLS_X509_FMT_PEM, |
501 | cert, | 501 | cert, |
502 | &cert_buf_size); | 502 | &cert_buf_size); |
503 | gnutls_x509_privkey_export (proxy_key, | 503 | gnutls_x509_privkey_export(proxy_key, |
504 | GNUTLS_X509_FMT_PEM, | 504 | GNUTLS_X509_FMT_PEM, |
505 | key, | 505 | key, |
506 | &key_buf_size); | 506 | &key_buf_size); |
507 | mhd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port, | 507 | mhd = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port, |
508 | NULL, NULL, | 508 | NULL, NULL, |
509 | &mhd_ahc, NULL, | 509 | &mhd_ahc, NULL, |
510 | MHD_OPTION_HTTPS_MEM_KEY, key, | 510 | MHD_OPTION_HTTPS_MEM_KEY, key, |
511 | MHD_OPTION_HTTPS_MEM_CERT, cert, | 511 | MHD_OPTION_HTTPS_MEM_CERT, cert, |
512 | MHD_OPTION_END); | 512 | MHD_OPTION_END); |
513 | GNUNET_assert (NULL != mhd); | 513 | GNUNET_assert(NULL != mhd); |
514 | mhd_main (); | 514 | mhd_main(); |
515 | 515 | ||
516 | GNUNET_SCHEDULER_add_now (&commence_testing, | 516 | GNUNET_SCHEDULER_add_now(&commence_testing, |
517 | NULL); | 517 | NULL); |
518 | } | 518 | } |
519 | 519 | ||
520 | int | 520 | int |
521 | main (int argc, char *const *argv) | 521 | main(int argc, char *const *argv) |
522 | { | 522 | { |
523 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 523 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
524 | GNUNET_GETOPT_option_uint16 ('p', | 524 | GNUNET_GETOPT_option_uint16('p', |
525 | "port", | 525 | "port", |
526 | NULL, | 526 | NULL, |
527 | gettext_noop ("listen on specified port (default: 7777)"), | 527 | gettext_noop("listen on specified port (default: 7777)"), |
528 | &port), | 528 | &port), |
529 | GNUNET_GETOPT_option_string ('A', | 529 | GNUNET_GETOPT_option_string('A', |
530 | "curlcert", | 530 | "curlcert", |
531 | NULL, | 531 | NULL, |
532 | gettext_noop ("pem file to use as CA"), | 532 | gettext_noop("pem file to use as CA"), |
533 | &cafile_opt), | 533 | &cafile_opt), |
534 | GNUNET_GETOPT_option_string ('S', | 534 | GNUNET_GETOPT_option_string('S', |
535 | "servercert", | 535 | "servercert", |
536 | NULL, | 536 | NULL, |
537 | gettext_noop ("pem file to use for the server"), | 537 | gettext_noop("pem file to use for the server"), |
538 | &cafile_srv), | 538 | &cafile_srv), |
539 | 539 | ||
540 | GNUNET_GETOPT_OPTION_END | 540 | GNUNET_GETOPT_OPTION_END |
541 | }; | 541 | }; |
542 | 542 | ||
543 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 543 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
544 | { | 544 | { |
545 | fprintf (stderr, "failed to initialize curl\n"); | 545 | fprintf(stderr, "failed to initialize curl\n"); |
546 | return 2; | 546 | return 2; |
547 | } | 547 | } |
548 | if (GNUNET_OK != | 548 | if (GNUNET_OK != |
549 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 549 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
550 | &argc, &argv)) | 550 | &argc, &argv)) |
551 | return 2; | 551 | return 2; |
552 | GNUNET_log_setup ("gnunet-gns-proxy-test", | 552 | GNUNET_log_setup("gnunet-gns-proxy-test", |
553 | "WARNING", | 553 | "WARNING", |
554 | NULL); | 554 | NULL); |
555 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, | 555 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, argv, |
556 | "gnunet-gns-proxy-test", | 556 | "gnunet-gns-proxy-test", |
557 | _("GNUnet GNS proxy test"), | 557 | _("GNUnet GNS proxy test"), |
558 | options, | 558 | options, |
559 | &run, NULL)) | 559 | &run, NULL)) |
560 | return 1; | 560 | return 1; |
561 | GNUNET_free_non_null ((char *) argv); | 561 | GNUNET_free_non_null((char *)argv); |
562 | return global_ret; | 562 | return global_ret; |
563 | } | 563 | } |
564 | 564 | ||