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