summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-09-16 21:22:12 +0200
committerChristian Grothoff <christian@grothoff.org>2019-09-16 21:22:23 +0200
commitcd92f5e61376da2ee32c9f52eb4230857bd8a391 (patch)
treef6a170b7c8a5d02ba24b44737d805838bdfef262
parent570f2a84b187faa98b87d69c263e1f66450bc177 (diff)
downloadgnunet-cd92f5e61376da2ee32c9f52eb4230857bd8a391.tar.gz
gnunet-cd92f5e61376da2ee32c9f52eb4230857bd8a391.zip
reindentation
-rw-r--r--src/curl/curl.c502
1 files changed, 252 insertions, 250 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 8e66ba4cb..98bf67d2e 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -40,23 +40,23 @@
40 * @param code what was the curl error code 40 * @param code what was the curl error code
41 */ 41 */
42#define CURL_STRERROR(type, function, code) \ 42#define CURL_STRERROR(type, function, code) \
43 GNUNET_log(type, \ 43 GNUNET_log (type, \
44 "Curl function `%s' has failed at `%s:%d' with error: %s\n", \ 44 "Curl function `%s' has failed at `%s:%d' with error: %s\n", \
45 function, \ 45 function, \
46 __FILE__, \ 46 __FILE__, \
47 __LINE__, \ 47 __LINE__, \
48 curl_easy_strerror(code)); 48 curl_easy_strerror (code));
49 49
50/** 50/**
51 * Print JSON parsing related error information 51 * Print JSON parsing related error information
52 */ 52 */
53#define JSON_WARN(error) \ 53#define JSON_WARN(error) \
54 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ 54 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
55 "JSON parsing failed at %s:%u: %s (%s)\n", \ 55 "JSON parsing failed at %s:%u: %s (%s)\n", \
56 __FILE__, \ 56 __FILE__, \
57 __LINE__, \ 57 __LINE__, \
58 error.text, \ 58 error.text, \
59 error.source) 59 error.source)
60 60
61 61
62/** 62/**
@@ -68,7 +68,8 @@ static int curl_fail;
68/** 68/**
69 * Jobs are CURL requests running within a `struct GNUNET_CURL_Context`. 69 * Jobs are CURL requests running within a `struct GNUNET_CURL_Context`.
70 */ 70 */
71struct GNUNET_CURL_Job { 71struct GNUNET_CURL_Job
72{
72 /** 73 /**
73 * We keep jobs in a DLL. 74 * We keep jobs in a DLL.
74 */ 75 */
@@ -115,7 +116,8 @@ struct GNUNET_CURL_Job {
115/** 116/**
116 * Context 117 * Context
117 */ 118 */
118struct GNUNET_CURL_Context { 119struct GNUNET_CURL_Context
120{
119 /** 121 /**
120 * Curl multi handle 122 * Curl multi handle
121 */ 123 */
@@ -169,30 +171,30 @@ struct GNUNET_CURL_Context {
169 * @return library context 171 * @return library context
170 */ 172 */
171struct GNUNET_CURL_Context * 173struct GNUNET_CURL_Context *
172GNUNET_CURL_init(GNUNET_CURL_RescheduleCallback cb, void *cb_cls) 174GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls)
173{ 175{
174 struct GNUNET_CURL_Context *ctx; 176 struct GNUNET_CURL_Context *ctx;
175 CURLM *multi; 177 CURLM *multi;
176 CURLSH *share; 178 CURLSH *share;
177 179
178 if (curl_fail) 180 if (curl_fail)
179 { 181 {
180 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Curl was not initialised properly\n"); 182 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Curl was not initialised properly\n");
181 return NULL; 183 return NULL;
182 } 184 }
183 if (NULL == (multi = curl_multi_init())) 185 if (NULL == (multi = curl_multi_init ()))
184 { 186 {
185 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
186 "Failed to create a Curl multi handle\n"); 188 "Failed to create a Curl multi handle\n");
187 return NULL; 189 return NULL;
188 } 190 }
189 if (NULL == (share = curl_share_init())) 191 if (NULL == (share = curl_share_init ()))
190 { 192 {
191 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 "Failed to create a Curl share handle\n"); 194 "Failed to create a Curl share handle\n");
193 return NULL; 195 return NULL;
194 } 196 }
195 ctx = GNUNET_new(struct GNUNET_CURL_Context); 197 ctx = GNUNET_new (struct GNUNET_CURL_Context);
196 ctx->cb = cb; 198 ctx->cb = cb;
197 ctx->cb_cls = cb_cls; 199 ctx->cb_cls = cb_cls;
198 ctx->multi = multi; 200 ctx->multi = multi;
@@ -208,8 +210,8 @@ GNUNET_CURL_init(GNUNET_CURL_RescheduleCallback cb, void *cb_cls)
208 * @param header_name name of the header to send. 210 * @param header_name name of the header to send.
209 */ 211 */
210void 212void
211GNUNET_CURL_enable_async_scope_header(struct GNUNET_CURL_Context *ctx, 213GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
212 const char *header_name) 214 const char *header_name)
213{ 215{
214 ctx->async_scope_id_header = header_name; 216 ctx->async_scope_id_header = header_name;
215} 217}
@@ -229,26 +231,26 @@ GNUNET_CURL_enable_async_scope_header(struct GNUNET_CURL_Context *ctx,
229 * @return number of bytes processed from @a bufptr 231 * @return number of bytes processed from @a bufptr
230 */ 232 */
231static size_t 233static size_t
232download_cb(char *bufptr, size_t size, size_t nitems, void *cls) 234download_cb (char *bufptr, size_t size, size_t nitems, void *cls)
233{ 235{
234 struct GNUNET_CURL_DownloadBuffer *db = cls; 236 struct GNUNET_CURL_DownloadBuffer *db = cls;
235 size_t msize; 237 size_t msize;
236 void *buf; 238 void *buf;
237 239
238 if (0 == size * nitems) 240 if (0 == size * nitems)
239 { 241 {
240 /* Nothing (left) to do */ 242 /* Nothing (left) to do */
241 return 0; 243 return 0;
242 } 244 }
243 msize = size * nitems; 245 msize = size * nitems;
244 if ((msize + db->buf_size) >= GNUNET_MAX_MALLOC_CHECKED) 246 if ((msize + db->buf_size) >= GNUNET_MAX_MALLOC_CHECKED)
245 { 247 {
246 db->eno = ENOMEM; 248 db->eno = ENOMEM;
247 return 0; /* signals an error to curl */ 249 return 0; /* signals an error to curl */
248 } 250 }
249 db->buf = GNUNET_realloc(db->buf, db->buf_size + msize); 251 db->buf = GNUNET_realloc (db->buf, db->buf_size + msize);
250 buf = db->buf + db->buf_size; 252 buf = db->buf + db->buf_size;
251 GNUNET_memcpy(buf, bufptr, msize); 253 GNUNET_memcpy (buf, bufptr, msize);
252 db->buf_size += msize; 254 db->buf_size += msize;
253 return msize; 255 return msize;
254} 256}
@@ -274,77 +276,77 @@ download_cb(char *bufptr, size_t size, size_t nitems, void *cls)
274 * @return NULL on error (in this case, @eh is still released!) 276 * @return NULL on error (in this case, @eh is still released!)
275 */ 277 */
276struct GNUNET_CURL_Job * 278struct GNUNET_CURL_Job *
277GNUNET_CURL_job_add2(struct GNUNET_CURL_Context *ctx, 279GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
278 CURL *eh, 280 CURL *eh,
279 const struct curl_slist *job_headers, 281 const struct curl_slist *job_headers,
280 GNUNET_CURL_JobCompletionCallback jcc, 282 GNUNET_CURL_JobCompletionCallback jcc,
281 void *jcc_cls) 283 void *jcc_cls)
282{ 284{
283 struct GNUNET_CURL_Job *job; 285 struct GNUNET_CURL_Job *job;
284 struct curl_slist *all_headers = NULL; 286 struct curl_slist *all_headers = NULL;
285 287
286 for (const struct curl_slist *curr = job_headers; curr != NULL; 288 for (const struct curl_slist *curr = job_headers; curr != NULL;
287 curr = curr->next) 289 curr = curr->next)
288 { 290 {
289 GNUNET_assert(NULL != 291 GNUNET_assert (NULL !=
290 (all_headers = curl_slist_append(all_headers, curr->data))); 292 (all_headers = curl_slist_append (all_headers, curr->data)));
291 } 293 }
292 294
293 for (const struct curl_slist *curr = ctx->common_headers; curr != NULL; 295 for (const struct curl_slist *curr = ctx->common_headers; curr != NULL;
294 curr = curr->next) 296 curr = curr->next)
295 { 297 {
296 GNUNET_assert(NULL != 298 GNUNET_assert (NULL !=
297 (all_headers = curl_slist_append(all_headers, curr->data))); 299 (all_headers = curl_slist_append (all_headers, curr->data)));
298 } 300 }
299 301
300 if (NULL != ctx->async_scope_id_header) 302 if (NULL != ctx->async_scope_id_header)
301 { 303 {
302 struct GNUNET_AsyncScopeSave scope; 304 struct GNUNET_AsyncScopeSave scope;
303
304 GNUNET_async_scope_get(&scope);
305 if (GNUNET_YES == scope.have_scope)
306 {
307 char *aid_header = NULL;
308 aid_header =
309 GNUNET_STRINGS_data_to_string_alloc(&scope.scope_id,
310 sizeof(
311 struct GNUNET_AsyncScopeId));
312 GNUNET_assert(NULL != aid_header);
313 GNUNET_assert(NULL != curl_slist_append(all_headers, aid_header));
314 GNUNET_free(aid_header);
315 }
316 }
317 305
318 if (CURLE_OK != curl_easy_setopt(eh, CURLOPT_HTTPHEADER, all_headers)) 306 GNUNET_async_scope_get (&scope);
307 if (GNUNET_YES == scope.have_scope)
319 { 308 {
320 GNUNET_break(0); 309 char *aid_header = NULL;
321 curl_slist_free_all(all_headers); 310 aid_header =
322 curl_easy_cleanup(eh); 311 GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id,
323 return NULL; 312 sizeof(
313 struct GNUNET_AsyncScopeId));
314 GNUNET_assert (NULL != aid_header);
315 GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header));
316 GNUNET_free (aid_header);
324 } 317 }
318 }
319
320 if (CURLE_OK != curl_easy_setopt (eh, CURLOPT_HTTPHEADER, all_headers))
321 {
322 GNUNET_break (0);
323 curl_slist_free_all (all_headers);
324 curl_easy_cleanup (eh);
325 return NULL;
326 }
325 327
326 job = GNUNET_new(struct GNUNET_CURL_Job); 328 job = GNUNET_new (struct GNUNET_CURL_Job);
327 job->job_headers = all_headers; 329 job->job_headers = all_headers;
328 330
329 if ((CURLE_OK != curl_easy_setopt(eh, CURLOPT_PRIVATE, job)) || 331 if ((CURLE_OK != curl_easy_setopt (eh, CURLOPT_PRIVATE, job)) ||
330 (CURLE_OK != 332 (CURLE_OK !=
331 curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, &download_cb)) || 333 curl_easy_setopt (eh, CURLOPT_WRITEFUNCTION, &download_cb)) ||
332 (CURLE_OK != curl_easy_setopt(eh, CURLOPT_WRITEDATA, &job->db)) || 334 (CURLE_OK != curl_easy_setopt (eh, CURLOPT_WRITEDATA, &job->db)) ||
333 (CURLE_OK != curl_easy_setopt(eh, CURLOPT_SHARE, ctx->share)) || 335 (CURLE_OK != curl_easy_setopt (eh, CURLOPT_SHARE, ctx->share)) ||
334 (CURLM_OK != curl_multi_add_handle(ctx->multi, eh))) 336 (CURLM_OK != curl_multi_add_handle (ctx->multi, eh)))
335 { 337 {
336 GNUNET_break(0); 338 GNUNET_break (0);
337 GNUNET_free(job); 339 GNUNET_free (job);
338 curl_easy_cleanup(eh); 340 curl_easy_cleanup (eh);
339 return NULL; 341 return NULL;
340 } 342 }
341 343
342 job->easy_handle = eh; 344 job->easy_handle = eh;
343 job->ctx = ctx; 345 job->ctx = ctx;
344 job->jcc = jcc; 346 job->jcc = jcc;
345 job->jcc_cls = jcc_cls; 347 job->jcc_cls = jcc_cls;
346 GNUNET_CONTAINER_DLL_insert(ctx->jobs_head, ctx->jobs_tail, job); 348 GNUNET_CONTAINER_DLL_insert (ctx->jobs_head, ctx->jobs_tail, job);
347 ctx->cb(ctx->cb_cls); 349 ctx->cb (ctx->cb_cls);
348 return job; 350 return job;
349} 351}
350 352
@@ -366,24 +368,24 @@ GNUNET_CURL_job_add2(struct GNUNET_CURL_Context *ctx,
366 * @return NULL on error (in this case, @eh is still released!) 368 * @return NULL on error (in this case, @eh is still released!)
367 */ 369 */
368struct GNUNET_CURL_Job * 370struct GNUNET_CURL_Job *
369GNUNET_CURL_job_add(struct GNUNET_CURL_Context *ctx, 371GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
370 CURL *eh, 372 CURL *eh,
371 int add_json, 373 int add_json,
372 GNUNET_CURL_JobCompletionCallback jcc, 374 GNUNET_CURL_JobCompletionCallback jcc,
373 void *jcc_cls) 375 void *jcc_cls)
374{ 376{
375 struct GNUNET_CURL_Job *job; 377 struct GNUNET_CURL_Job *job;
376 struct curl_slist *job_headers = NULL; 378 struct curl_slist *job_headers = NULL;
377 379
378 if (GNUNET_YES == add_json) 380 if (GNUNET_YES == add_json)
379 { 381 {
380 GNUNET_assert( 382 GNUNET_assert (
381 NULL != (job_headers = 383 NULL != (job_headers =
382 curl_slist_append(NULL, "Content-Type: application/json"))); 384 curl_slist_append (NULL, "Content-Type: application/json")));
383 } 385 }
384 386
385 job = GNUNET_CURL_job_add2(ctx, eh, job_headers, jcc, jcc_cls); 387 job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls);
386 curl_slist_free_all(job_headers); 388 curl_slist_free_all (job_headers);
387 return job; 389 return job;
388} 390}
389 391
@@ -395,17 +397,17 @@ GNUNET_CURL_job_add(struct GNUNET_CURL_Context *ctx,
395 * @param job job to cancel 397 * @param job job to cancel
396 */ 398 */
397void 399void
398GNUNET_CURL_job_cancel(struct GNUNET_CURL_Job *job) 400GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
399{ 401{
400 struct GNUNET_CURL_Context *ctx = job->ctx; 402 struct GNUNET_CURL_Context *ctx = job->ctx;
401 403
402 GNUNET_CONTAINER_DLL_remove(ctx->jobs_head, ctx->jobs_tail, job); 404 GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, ctx->jobs_tail, job);
403 GNUNET_break(CURLM_OK == 405 GNUNET_break (CURLM_OK ==
404 curl_multi_remove_handle(ctx->multi, job->easy_handle)); 406 curl_multi_remove_handle (ctx->multi, job->easy_handle));
405 curl_easy_cleanup(job->easy_handle); 407 curl_easy_cleanup (job->easy_handle);
406 GNUNET_free_non_null(job->db.buf); 408 GNUNET_free_non_null (job->db.buf);
407 curl_slist_free_all(job->job_headers); 409 curl_slist_free_all (job->job_headers);
408 GNUNET_free(job); 410 GNUNET_free (job);
409} 411}
410 412
411 413
@@ -428,62 +430,62 @@ GNUNET_CURL_job_cancel(struct GNUNET_CURL_Job *job)
428 * @return NULL if downloading a JSON reply failed. 430 * @return NULL if downloading a JSON reply failed.
429 */ 431 */
430void * 432void *
431GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db, 433GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
432 CURL *eh, 434 CURL *eh,
433 long *response_code) 435 long *response_code)
434{ 436{
435 json_t *json; 437 json_t *json;
436 json_error_t error; 438 json_error_t error;
437 char *ct; 439 char *ct;
438 440
439 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Downloaded body: %.*s\n", 442 "Downloaded body: %.*s\n",
441 (int)db->buf_size, 443 (int) db->buf_size,
442 (char *)db->buf); 444 (char *) db->buf);
443 445
444 if ((CURLE_OK != curl_easy_getinfo(eh, CURLINFO_CONTENT_TYPE, &ct)) || 446 if ((CURLE_OK != curl_easy_getinfo (eh, CURLINFO_CONTENT_TYPE, &ct)) ||
445 (NULL == ct) || (0 != strcasecmp(ct, "application/json"))) 447 (NULL == ct) || (0 != strcasecmp (ct, "application/json")))
448 {
449 /* No content type or explicitly not JSON, refuse to parse
450 (but keep response code) */
451 if (CURLE_OK !=
452 curl_easy_getinfo (eh, CURLINFO_RESPONSE_CODE, response_code))
446 { 453 {
447 /* No content type or explicitly not JSON, refuse to parse 454 /* unexpected error... */
448 (but keep response code) */ 455 GNUNET_break (0);
449 if (CURLE_OK != 456 *response_code = 0;
450 curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, response_code))
451 {
452 /* unexpected error... */
453 GNUNET_break(0);
454 *response_code = 0;
455 }
456 if (0 != db->buf_size)
457 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
458 "Did NOT detect response as JSON\n");
459 return NULL;
460 } 457 }
458 if (0 != db->buf_size)
459 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
460 "Did NOT detect response as JSON\n");
461 return NULL;
462 }
461 json = NULL; 463 json = NULL;
462 if (0 == db->eno) 464 if (0 == db->eno)
465 {
466 json = json_loadb (db->buf,
467 db->buf_size,
468 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
469 &error);
470 if (NULL == json)
463 { 471 {
464 json = json_loadb(db->buf, 472 JSON_WARN (error);
465 db->buf_size, 473 *response_code = 0;
466 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
467 &error);
468 if (NULL == json)
469 {
470 JSON_WARN(error);
471 *response_code = 0;
472 }
473 } 474 }
474 GNUNET_free_non_null(db->buf); 475 }
476 GNUNET_free_non_null (db->buf);
475 db->buf = NULL; 477 db->buf = NULL;
476 db->buf_size = 0; 478 db->buf_size = 0;
477 if (NULL != json) 479 if (NULL != json)
480 {
481 if (CURLE_OK !=
482 curl_easy_getinfo (eh, CURLINFO_RESPONSE_CODE, response_code))
478 { 483 {
479 if (CURLE_OK != 484 /* unexpected error... */
480 curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, response_code)) 485 GNUNET_break (0);
481 { 486 *response_code = 0;
482 /* unexpected error... */
483 GNUNET_break(0);
484 *response_code = 0;
485 }
486 } 487 }
488 }
487 return json; 489 return json;
488} 490}
489 491
@@ -496,9 +498,9 @@ GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db,
496 * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise. 498 * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
497 */ 499 */
498int 500int
499GNUNET_CURL_append_header(struct GNUNET_CURL_Context *ctx, const char *header) 501GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, const char *header)
500{ 502{
501 ctx->common_headers = curl_slist_append(ctx->common_headers, header); 503 ctx->common_headers = curl_slist_append (ctx->common_headers, header);
502 if (NULL == ctx->common_headers) 504 if (NULL == ctx->common_headers)
503 return GNUNET_SYSERR; 505 return GNUNET_SYSERR;
504 506
@@ -515,98 +517,98 @@ GNUNET_CURL_append_header(struct GNUNET_CURL_Context *ctx, const char *header)
515 * @param rc cleans/frees the response 517 * @param rc cleans/frees the response
516 */ 518 */
517void 519void
518GNUNET_CURL_perform2(struct GNUNET_CURL_Context *ctx, 520GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
519 GNUNET_CURL_RawParser rp, 521 GNUNET_CURL_RawParser rp,
520 GNUNET_CURL_ResponseCleaner rc) 522 GNUNET_CURL_ResponseCleaner rc)
521{ 523{
522 CURLMsg *cmsg; 524 CURLMsg *cmsg;
523 int n_running; 525 int n_running;
524 int n_completed; 526 int n_completed;
525 527
526 (void)curl_multi_perform(ctx->multi, &n_running); 528 (void) curl_multi_perform (ctx->multi, &n_running);
527 while (NULL != (cmsg = curl_multi_info_read(ctx->multi, &n_completed))) 529 while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed)))
528 { 530 {
529 struct GNUNET_CURL_Job *job; 531 struct GNUNET_CURL_Job *job;
530 long response_code; 532 long response_code;
531 void *response; 533 void *response;
532 534
533 /* Only documented return value is CURLMSG_DONE */ 535 /* Only documented return value is CURLMSG_DONE */
534 GNUNET_break(CURLMSG_DONE == cmsg->msg); 536 GNUNET_break (CURLMSG_DONE == cmsg->msg);
535 GNUNET_assert(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 537 GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
536 CURLINFO_PRIVATE, 538 CURLINFO_PRIVATE,
537 (char **)&job)); 539 (char **) &job));
538 GNUNET_assert(job->ctx == ctx); 540 GNUNET_assert (job->ctx == ctx);
539 response_code = 0; 541 response_code = 0;
540 response = rp(&job->db, job->easy_handle, &response_code); 542 response = rp (&job->db, job->easy_handle, &response_code);
541#if ENABLE_BENCHMARK 543#if ENABLE_BENCHMARK
542 { 544 {
543 char *url = NULL; 545 char *url = NULL;
544 double total_as_double = 0; 546 double total_as_double = 0;
545 struct GNUNET_TIME_Relative total; 547 struct GNUNET_TIME_Relative total;
546 struct UrlRequestData *urd; 548 struct UrlRequestData *urd;
547 /* Some care required, as curl is using data types (long vs curl_off_t vs 549 /* Some care required, as curl is using data types (long vs curl_off_t vs
548 * double) inconsistently to store byte count. */ 550 * double) inconsistently to store byte count. */
549 curl_off_t size_curl = 0; 551 curl_off_t size_curl = 0;
550 long size_long = 0; 552 long size_long = 0;
551 uint64_t bytes_sent = 0; 553 uint64_t bytes_sent = 0;
552 uint64_t bytes_received = 0; 554 uint64_t bytes_received = 0;
553 555
554 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 556 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
555 CURLINFO_TOTAL_TIME, 557 CURLINFO_TOTAL_TIME,
556 &total_as_double)); 558 &total_as_double));
557 total.rel_value_us = total_as_double * 1000 * 1000; 559 total.rel_value_us = total_as_double * 1000 * 1000;
558 560
559 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 561 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
560 CURLINFO_EFFECTIVE_URL, 562 CURLINFO_EFFECTIVE_URL,
561 &url)); 563 &url));
562 564
563 /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total 565 /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total
564 number of bytes received, not clear from curl docs. */ 566 number of bytes received, not clear from curl docs. */
565 567
566 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 568 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
567 CURLINFO_HEADER_SIZE, 569 CURLINFO_HEADER_SIZE,
568 &size_long)); 570 &size_long));
569 bytes_received += size_long; 571 bytes_received += size_long;
570 572
571 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 573 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
572 CURLINFO_SIZE_DOWNLOAD_T, 574 CURLINFO_SIZE_DOWNLOAD_T,
573 &size_curl)); 575 &size_curl));
574 bytes_received += size_curl; 576 bytes_received += size_curl;
575 577
576 /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes 578 /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes
577 sent, again docs are not completely clear. */ 579 sent, again docs are not completely clear. */
578 580
579 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 581 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
580 CURLINFO_REQUEST_SIZE, 582 CURLINFO_REQUEST_SIZE,
581 &size_long)); 583 &size_long));
582 bytes_sent += size_long; 584 bytes_sent += size_long;
583 585
584 /* We obtain this value to check an invariant, but never use it otherwise. */ 586 /* We obtain this value to check an invariant, but never use it otherwise. */
585 GNUNET_break(CURLE_OK == curl_easy_getinfo(cmsg->easy_handle, 587 GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
586 CURLINFO_SIZE_UPLOAD_T, 588 CURLINFO_SIZE_UPLOAD_T,
587 &size_curl)); 589 &size_curl));
588 590
589 /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should 591 /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should
590 be an invariant. 592 be an invariant.
591 As verified with 593 As verified with
592 curl -w "foo%{size_request} -XPOST --data "ABC" $URL 594 curl -w "foo%{size_request} -XPOST --data "ABC" $URL
593 the CURLINFO_REQUEST_SIZE should be the whole size of the request 595 the CURLINFO_REQUEST_SIZE should be the whole size of the request
594 including headers and body. 596 including headers and body.
595 */ 597 */
596 GNUNET_break(size_curl <= size_long); 598 GNUNET_break (size_curl <= size_long);
597 599
598 urd = get_url_benchmark_data(url, (unsigned int)response_code); 600 urd = get_url_benchmark_data (url, (unsigned int) response_code);
599 urd->count++; 601 urd->count++;
600 urd->time = GNUNET_TIME_relative_add(urd->time, total); 602 urd->time = GNUNET_TIME_relative_add (urd->time, total);
601 urd->time_max = GNUNET_TIME_relative_max(total, urd->time_max); 603 urd->time_max = GNUNET_TIME_relative_max (total, urd->time_max);
602 urd->bytes_sent += bytes_sent; 604 urd->bytes_sent += bytes_sent;
603 urd->bytes_received += bytes_received; 605 urd->bytes_received += bytes_received;
604 }
605#endif
606 job->jcc(job->jcc_cls, response_code, response);
607 rc(response);
608 GNUNET_CURL_job_cancel(job);
609 } 606 }
607#endif
608 job->jcc (job->jcc_cls, response_code, response);
609 rc (response);
610 GNUNET_CURL_job_cancel (job);
611 }
610} 612}
611 613
612 614
@@ -616,11 +618,11 @@ GNUNET_CURL_perform2(struct GNUNET_CURL_Context *ctx,
616 * @param ctx the library context 618 * @param ctx the library context
617 */ 619 */
618void 620void
619GNUNET_CURL_perform(struct GNUNET_CURL_Context *ctx) 621GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
620{ 622{
621 GNUNET_CURL_perform2(ctx, 623 GNUNET_CURL_perform2 (ctx,
622 &GNUNET_CURL_download_get_result_, 624 &GNUNET_CURL_download_get_result_,
623 (GNUNET_CURL_ResponseCleaner) & json_decref); 625 (GNUNET_CURL_ResponseCleaner) & json_decref);
624} 626}
625 627
626 628
@@ -653,25 +655,25 @@ GNUNET_CURL_perform(struct GNUNET_CURL_Context *ctx)
653 * proceed immediately with #GNUNET_CURL_perform(). 655 * proceed immediately with #GNUNET_CURL_perform().
654 */ 656 */
655void 657void
656GNUNET_CURL_get_select_info(struct GNUNET_CURL_Context *ctx, 658GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
657 fd_set *read_fd_set, 659 fd_set *read_fd_set,
658 fd_set *write_fd_set, 660 fd_set *write_fd_set,
659 fd_set *except_fd_set, 661 fd_set *except_fd_set,
660 int *max_fd, 662 int *max_fd,
661 long *timeout) 663 long *timeout)
662{ 664{
663 long to; 665 long to;
664 int m; 666 int m;
665 667
666 m = -1; 668 m = -1;
667 GNUNET_assert(CURLM_OK == curl_multi_fdset(ctx->multi, 669 GNUNET_assert (CURLM_OK == curl_multi_fdset (ctx->multi,
668 read_fd_set, 670 read_fd_set,
669 write_fd_set, 671 write_fd_set,
670 except_fd_set, 672 except_fd_set,
671 &m)); 673 &m));
672 to = *timeout; 674 to = *timeout;
673 *max_fd = GNUNET_MAX(m, *max_fd); 675 *max_fd = GNUNET_MAX (m, *max_fd);
674 GNUNET_assert(CURLM_OK == curl_multi_timeout(ctx->multi, &to)); 676 GNUNET_assert (CURLM_OK == curl_multi_timeout (ctx->multi, &to));
675 677
676 /* Only if what we got back from curl is smaller than what we 678 /* Only if what we got back from curl is smaller than what we
677 already had (-1 == infinity!), then update timeout */ 679 already had (-1 == infinity!), then update timeout */
@@ -690,14 +692,14 @@ GNUNET_CURL_get_select_info(struct GNUNET_CURL_Context *ctx,
690 * @param ctx the library context 692 * @param ctx the library context
691 */ 693 */
692void 694void
693GNUNET_CURL_fini(struct GNUNET_CURL_Context *ctx) 695GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx)
694{ 696{
695 /* all jobs must have been cancelled at this time, assert this */ 697 /* all jobs must have been cancelled at this time, assert this */
696 GNUNET_assert(NULL == ctx->jobs_head); 698 GNUNET_assert (NULL == ctx->jobs_head);
697 curl_share_cleanup(ctx->share); 699 curl_share_cleanup (ctx->share);
698 curl_multi_cleanup(ctx->multi); 700 curl_multi_cleanup (ctx->multi);
699 curl_slist_free_all(ctx->common_headers); 701 curl_slist_free_all (ctx->common_headers);
700 GNUNET_free(ctx); 702 GNUNET_free (ctx);
701} 703}
702 704
703 705
@@ -705,15 +707,15 @@ GNUNET_CURL_fini(struct GNUNET_CURL_Context *ctx)
705 * Initial global setup logic, specifically runs the Curl setup. 707 * Initial global setup logic, specifically runs the Curl setup.
706 */ 708 */
707__attribute__ ((constructor)) void 709__attribute__ ((constructor)) void
708GNUNET_CURL_constructor__(void) 710GNUNET_CURL_constructor__ (void)
709{ 711{
710 CURLcode ret; 712 CURLcode ret;
711 713
712 if (CURLE_OK != (ret = curl_global_init(CURL_GLOBAL_DEFAULT))) 714 if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT)))
713 { 715 {
714 CURL_STRERROR(GNUNET_ERROR_TYPE_ERROR, "curl_global_init", ret); 716 CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, "curl_global_init", ret);
715 curl_fail = 1; 717 curl_fail = 1;
716 } 718 }
717} 719}
718 720
719 721
@@ -721,11 +723,11 @@ GNUNET_CURL_constructor__(void)
721 * Cleans up after us, specifically runs the Curl cleanup. 723 * Cleans up after us, specifically runs the Curl cleanup.
722 */ 724 */
723__attribute__ ((destructor)) void 725__attribute__ ((destructor)) void
724GNUNET_CURL_destructor__(void) 726GNUNET_CURL_destructor__ (void)
725{ 727{
726 if (curl_fail) 728 if (curl_fail)
727 return; 729 return;
728 curl_global_cleanup(); 730 curl_global_cleanup ();
729} 731}
730 732
731/* end of curl.c */ 733/* end of curl.c */