diff options
author | xrs <xrs@mail36.net> | 2019-06-22 22:58:04 +0200 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2019-06-22 22:58:04 +0200 |
commit | ea20a69462912d46cf4f9dc47e6c7945c9da5f97 (patch) | |
tree | bc75b6e04ba593d06b4f615a2ce628a6fce29daf /src/curl | |
parent | d6c25f60406596d84900aa6ac012bf8ce111d57c (diff) | |
parent | 4b3469ce52759581bf8833a3093cfe7ddad8aa9d (diff) | |
download | gnunet-ea20a69462912d46cf4f9dc47e6c7945c9da5f97.tar.gz gnunet-ea20a69462912d46cf4f9dc47e6c7945c9da5f97.zip |
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src/curl')
-rw-r--r-- | src/curl/curl.c | 57 | ||||
-rw-r--r-- | src/curl/curl_reschedule.c | 29 |
2 files changed, 40 insertions, 46 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c index 749094800..38a1f5fcd 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -111,7 +111,6 @@ struct GNUNET_CURL_Job | |||
111 | * after the job has finished. | 111 | * after the job has finished. |
112 | */ | 112 | */ |
113 | struct curl_slist *job_headers; | 113 | struct curl_slist *job_headers; |
114 | |||
115 | }; | 114 | }; |
116 | 115 | ||
117 | 116 | ||
@@ -161,7 +160,6 @@ struct GNUNET_CURL_Context | |||
161 | * Closure for @e cb. | 160 | * Closure for @e cb. |
162 | */ | 161 | */ |
163 | void *cb_cls; | 162 | void *cb_cls; |
164 | |||
165 | }; | 163 | }; |
166 | 164 | ||
167 | 165 | ||
@@ -213,7 +211,8 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) | |||
213 | * @param header_name name of the header to send. | 211 | * @param header_name name of the header to send. |
214 | */ | 212 | */ |
215 | void | 213 | void |
216 | GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name) | 214 | GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, |
215 | const char *header_name) | ||
217 | { | 216 | { |
218 | ctx->async_scope_id_header = header_name; | 217 | ctx->async_scope_id_header = header_name; |
219 | } | 218 | } |
@@ -279,30 +278,26 @@ download_cb (char *bufptr, size_t size, size_t nitems, void *cls) | |||
279 | */ | 278 | */ |
280 | struct GNUNET_CURL_Job * | 279 | struct GNUNET_CURL_Job * |
281 | GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, | 280 | GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, |
282 | CURL *eh, | 281 | CURL *eh, |
283 | const struct curl_slist *job_headers, | 282 | const struct curl_slist *job_headers, |
284 | GNUNET_CURL_JobCompletionCallback jcc, | 283 | GNUNET_CURL_JobCompletionCallback jcc, |
285 | void *jcc_cls) | 284 | void *jcc_cls) |
286 | { | 285 | { |
287 | struct GNUNET_CURL_Job *job; | 286 | struct GNUNET_CURL_Job *job; |
288 | struct curl_slist *all_headers = NULL; | 287 | struct curl_slist *all_headers = NULL; |
289 | 288 | ||
290 | for (const struct curl_slist *curr = job_headers; | 289 | for (const struct curl_slist *curr = job_headers; curr != NULL; |
291 | curr != NULL; | ||
292 | curr = curr->next) | 290 | curr = curr->next) |
293 | { | 291 | { |
294 | GNUNET_assert ( | 292 | GNUNET_assert (NULL != |
295 | NULL != (all_headers = | 293 | (all_headers = curl_slist_append (all_headers, curr->data))); |
296 | curl_slist_append (all_headers, curr->data))); | ||
297 | } | 294 | } |
298 | 295 | ||
299 | for (const struct curl_slist *curr = ctx->common_headers; | 296 | for (const struct curl_slist *curr = ctx->common_headers; curr != NULL; |
300 | curr != NULL; | ||
301 | curr = curr->next) | 297 | curr = curr->next) |
302 | { | 298 | { |
303 | GNUNET_assert ( | 299 | GNUNET_assert (NULL != |
304 | NULL != (all_headers = | 300 | (all_headers = curl_slist_append (all_headers, curr->data))); |
305 | curl_slist_append (all_headers, curr->data))); | ||
306 | } | 301 | } |
307 | 302 | ||
308 | if (NULL != ctx->async_scope_id_header) | 303 | if (NULL != ctx->async_scope_id_header) |
@@ -313,8 +308,10 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, | |||
313 | if (GNUNET_YES == scope.have_scope) | 308 | if (GNUNET_YES == scope.have_scope) |
314 | { | 309 | { |
315 | char *aid_header = NULL; | 310 | char *aid_header = NULL; |
316 | aid_header = GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, | 311 | aid_header = |
317 | sizeof (struct GNUNET_AsyncScopeId)); | 312 | GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, |
313 | sizeof ( | ||
314 | struct GNUNET_AsyncScopeId)); | ||
318 | GNUNET_assert (NULL != aid_header); | 315 | GNUNET_assert (NULL != aid_header); |
319 | GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); | 316 | GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); |
320 | GNUNET_free (aid_header); | 317 | GNUNET_free (aid_header); |
@@ -378,7 +375,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, | |||
378 | GNUNET_CURL_JobCompletionCallback jcc, | 375 | GNUNET_CURL_JobCompletionCallback jcc, |
379 | void *jcc_cls) | 376 | void *jcc_cls) |
380 | { | 377 | { |
378 | struct GNUNET_CURL_Job *job; | ||
381 | struct curl_slist *job_headers = NULL; | 379 | struct curl_slist *job_headers = NULL; |
380 | |||
382 | if (GNUNET_YES == add_json) | 381 | if (GNUNET_YES == add_json) |
383 | { | 382 | { |
384 | GNUNET_assert ( | 383 | GNUNET_assert ( |
@@ -386,7 +385,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, | |||
386 | curl_slist_append (NULL, "Content-Type: application/json"))); | 385 | curl_slist_append (NULL, "Content-Type: application/json"))); |
387 | } | 386 | } |
388 | 387 | ||
389 | return GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); | 388 | job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); |
389 | curl_slist_free_all (job_headers); | ||
390 | return job; | ||
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||
@@ -430,9 +431,9 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) | |||
430 | * @return NULL if downloading a JSON reply failed. | 431 | * @return NULL if downloading a JSON reply failed. |
431 | */ | 432 | */ |
432 | void * | 433 | void * |
433 | download_get_result (struct GNUNET_CURL_DownloadBuffer *db, | 434 | GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, |
434 | CURL *eh, | 435 | CURL *eh, |
435 | long *response_code) | 436 | long *response_code) |
436 | { | 437 | { |
437 | json_t *json; | 438 | json_t *json; |
438 | json_error_t error; | 439 | json_error_t error; |
@@ -522,15 +523,16 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, | |||
522 | GNUNET_CURL_ResponseCleaner rc) | 523 | GNUNET_CURL_ResponseCleaner rc) |
523 | { | 524 | { |
524 | CURLMsg *cmsg; | 525 | CURLMsg *cmsg; |
525 | struct GNUNET_CURL_Job *job; | ||
526 | int n_running; | 526 | int n_running; |
527 | int n_completed; | 527 | int n_completed; |
528 | long response_code; | ||
529 | void *response; | ||
530 | 528 | ||
531 | (void) curl_multi_perform (ctx->multi, &n_running); | 529 | (void) curl_multi_perform (ctx->multi, &n_running); |
532 | while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) | 530 | while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) |
533 | { | 531 | { |
532 | struct GNUNET_CURL_Job *job; | ||
533 | long response_code; | ||
534 | void *response; | ||
535 | |||
534 | /* Only documented return value is CURLMSG_DONE */ | 536 | /* Only documented return value is CURLMSG_DONE */ |
535 | GNUNET_break (CURLMSG_DONE == cmsg->msg); | 537 | GNUNET_break (CURLMSG_DONE == cmsg->msg); |
536 | GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 538 | GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, |
@@ -619,9 +621,8 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, | |||
619 | void | 621 | void |
620 | GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) | 622 | GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) |
621 | { | 623 | { |
622 | |||
623 | GNUNET_CURL_perform2 (ctx, | 624 | GNUNET_CURL_perform2 (ctx, |
624 | download_get_result, | 625 | &GNUNET_CURL_download_get_result_, |
625 | (GNUNET_CURL_ResponseCleaner) &json_decref); | 626 | (GNUNET_CURL_ResponseCleaner) &json_decref); |
626 | } | 627 | } |
627 | 628 | ||
diff --git a/src/curl/curl_reschedule.c b/src/curl/curl_reschedule.c index 1b0f2e440..354ba13df 100644 --- a/src/curl/curl_reschedule.c +++ b/src/curl/curl_reschedule.c | |||
@@ -28,9 +28,9 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | 29 | ||
30 | extern void * | 30 | extern void * |
31 | download_get_result (struct GNUNET_CURL_DownloadBuffer *db, | 31 | GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, |
32 | CURL *eh, | 32 | CURL *eh, |
33 | long *response_code); | 33 | long *response_code); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). | 36 | * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). |
@@ -105,7 +105,7 @@ GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx) | |||
105 | 105 | ||
106 | rc = GNUNET_new (struct GNUNET_CURL_RescheduleContext); | 106 | rc = GNUNET_new (struct GNUNET_CURL_RescheduleContext); |
107 | rc->ctx = ctx; | 107 | rc->ctx = ctx; |
108 | rc->parser = &download_get_result; | 108 | rc->parser = &GNUNET_CURL_download_get_result_; |
109 | rc->cleaner = &clean_result; | 109 | rc->cleaner = &clean_result; |
110 | return rc; | 110 | return rc; |
111 | } | 111 | } |
@@ -145,9 +145,7 @@ context_task (void *cls) | |||
145 | 145 | ||
146 | rc->task = NULL; | 146 | rc->task = NULL; |
147 | 147 | ||
148 | GNUNET_CURL_perform2 (rc->ctx, | 148 | GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner); |
149 | rc->parser, | ||
150 | rc->cleaner); | ||
151 | max_fd = -1; | 149 | max_fd = -1; |
152 | timeout = -1; | 150 | timeout = -1; |
153 | FD_ZERO (&read_fd_set); | 151 | FD_ZERO (&read_fd_set); |
@@ -160,18 +158,14 @@ context_task (void *cls) | |||
160 | &max_fd, | 158 | &max_fd, |
161 | &timeout); | 159 | &timeout); |
162 | if (timeout >= 0) | 160 | if (timeout >= 0) |
163 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 161 | delay = |
164 | timeout); | 162 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout); |
165 | else | 163 | else |
166 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 164 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
167 | rs = GNUNET_NETWORK_fdset_create (); | 165 | rs = GNUNET_NETWORK_fdset_create (); |
168 | GNUNET_NETWORK_fdset_copy_native (rs, | 166 | GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, max_fd + 1); |
169 | &read_fd_set, | ||
170 | max_fd + 1); | ||
171 | ws = GNUNET_NETWORK_fdset_create (); | 167 | ws = GNUNET_NETWORK_fdset_create (); |
172 | GNUNET_NETWORK_fdset_copy_native (ws, | 168 | GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, max_fd + 1); |
173 | &write_fd_set, | ||
174 | max_fd + 1); | ||
175 | if (NULL == rc->task) | 169 | if (NULL == rc->task) |
176 | rc->task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 170 | rc->task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
177 | delay, | 171 | delay, |
@@ -196,12 +190,11 @@ context_task (void *cls) | |||
196 | void | 190 | void |
197 | GNUNET_CURL_gnunet_scheduler_reschedule (void *cls) | 191 | GNUNET_CURL_gnunet_scheduler_reschedule (void *cls) |
198 | { | 192 | { |
199 | struct GNUNET_CURL_RescheduleContext *rc = *(void**) cls; | 193 | struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls; |
200 | 194 | ||
201 | if (NULL != rc->task) | 195 | if (NULL != rc->task) |
202 | GNUNET_SCHEDULER_cancel (rc->task); | 196 | GNUNET_SCHEDULER_cancel (rc->task); |
203 | rc->task = GNUNET_SCHEDULER_add_now (&context_task, | 197 | rc->task = GNUNET_SCHEDULER_add_now (&context_task, rc); |
204 | rc); | ||
205 | } | 198 | } |
206 | 199 | ||
207 | /* end of curl_reschedule.c */ | 200 | /* end of curl_reschedule.c */ |