aboutsummaryrefslogtreecommitdiff
path: root/src/curl/curl.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-14 15:59:07 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-14 15:59:12 +0100
commit99779b455ce3bf9c53dd411575766bf298a3a5f3 (patch)
tree12cd49f097fdd1947580b08ec10ca961f8c250b9 /src/curl/curl.c
parent8c702327dae9e504e0f6e1678884d9327321f44a (diff)
downloadgnunet-99779b455ce3bf9c53dd411575766bf298a3a5f3.tar.gz
gnunet-99779b455ce3bf9c53dd411575766bf298a3a5f3.zip
introducing GNUNET_TIME_Timestamp
Diffstat (limited to 'src/curl/curl.c')
-rw-r--r--src/curl/curl.c196
1 files changed, 3 insertions, 193 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 684610101..e45612e94 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -201,14 +201,6 @@ struct GNUNET_CURL_Context
201}; 201};
202 202
203 203
204/**
205 * Force use of the provided username and password
206 * for client authentication for all operations performed
207 * with @a ctx.
208 *
209 * @param ctx context to set authentication data for
210 * @param userpass string with "$USERNAME:$PASSWORD"
211 */
212void 204void
213GNUNET_CURL_set_userpass (struct GNUNET_CURL_Context *ctx, 205GNUNET_CURL_set_userpass (struct GNUNET_CURL_Context *ctx,
214 const char *userpass) 206 const char *userpass)
@@ -219,21 +211,6 @@ GNUNET_CURL_set_userpass (struct GNUNET_CURL_Context *ctx,
219} 211}
220 212
221 213
222/**
223 * Force use of the provided TLS client certificate
224 * for client authentication for all operations performed
225 * with @a ctx.
226 *
227 * Note that if the provided information is incorrect,
228 * the earliest operation that could fail is
229 * #GNUNET_CURL_job_add() or #GNUNET_CURL_job_add2()!
230 *
231 * @param ctx context to set authentication data for
232 * @param certtype type of the certificate
233 * @param certfile file with the certificate
234 * @param keyfile file with the private key
235 * @param keypass passphrase to decrypt @a keyfile (or NULL)
236 */
237void 214void
238GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx, 215GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx,
239 const char *certtype, 216 const char *certtype,
@@ -256,14 +233,6 @@ GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx,
256} 233}
257 234
258 235
259/**
260 * Initialise this library. This function should be called before using any of
261 * the following functions.
262 *
263 * @param cb function to call when rescheduling is required
264 * @param cb_cls closure for @a cb
265 * @return library context
266 */
267struct GNUNET_CURL_Context * 236struct GNUNET_CURL_Context *
268GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, 237GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb,
269 void *cb_cls) 238 void *cb_cls)
@@ -299,12 +268,6 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb,
299} 268}
300 269
301 270
302/**
303 * Enable sending the async scope ID as a header.
304 *
305 * @param ctx the context to enable this for
306 * @param header_name name of the header to send.
307 */
308void 271void
309GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, 272GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
310 const char *header_name) 273 const char *header_name)
@@ -313,15 +276,6 @@ GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
313} 276}
314 277
315 278
316/**
317 * Return #GNUNET_YES if given a valid scope ID and
318 * #GNUNET_NO otherwise. See #setup_job_headers,
319 * logic related to
320 * #GNUNET_CURL_enable_async_scope_header() for the
321 * code that generates such a @a scope_id.
322 *
323 * @returns #GNUNET_YES iff given a valid scope ID
324 */
325int 279int
326GNUNET_CURL_is_valid_scope_id (const char *scope_id) 280GNUNET_CURL_is_valid_scope_id (const char *scope_id)
327{ 281{
@@ -447,7 +401,9 @@ setup_job (CURL *eh,
447 struct GNUNET_CURL_Job *job; 401 struct GNUNET_CURL_Job *job;
448 402
449 if (CURLE_OK != 403 if (CURLE_OK !=
450 curl_easy_setopt (eh, CURLOPT_HTTPHEADER, all_headers)) 404 curl_easy_setopt (eh,
405 CURLOPT_HTTPHEADER,
406 all_headers))
451 { 407 {
452 GNUNET_break (0); 408 GNUNET_break (0);
453 curl_slist_free_all (all_headers); 409 curl_slist_free_all (all_headers);
@@ -491,12 +447,6 @@ setup_job (CURL *eh,
491} 447}
492 448
493 449
494/**
495 * Add @a extra_headers to the HTTP headers for @a job.
496 *
497 * @param[in,out] job the job to modify
498 * @param extra_headers headers to append
499 */
500void 450void
501GNUNET_CURL_extend_headers (struct GNUNET_CURL_Job *job, 451GNUNET_CURL_extend_headers (struct GNUNET_CURL_Job *job,
502 const struct curl_slist *extra_headers) 452 const struct curl_slist *extra_headers)
@@ -515,21 +465,6 @@ GNUNET_CURL_extend_headers (struct GNUNET_CURL_Job *job,
515} 465}
516 466
517 467
518/**
519 * Schedule a CURL request to be executed and call the given @a jcc
520 * upon its completion. Note that the context will make use of the
521 * CURLOPT_PRIVATE facility of the CURL @a eh. Used to download
522 * resources that are NOT in JSON. The raw body will be returned.
523 *
524 * @param ctx context to execute the job in
525 * @param eh curl easy handle for the request, will
526 * be executed AND cleaned up
527 * @param job_headers extra headers to add for this request
528 * @param max_reply_size largest acceptable response body
529 * @param jcc callback to invoke upon completion
530 * @param jcc_cls closure for @a jcc
531 * @return NULL on error (in this case, @eh is still released!)
532 */
533struct GNUNET_CURL_Job * 468struct GNUNET_CURL_Job *
534GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx, 469GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx,
535 CURL *eh, 470 CURL *eh,
@@ -554,25 +489,6 @@ GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx,
554} 489}
555 490
556 491
557/**
558 * Schedule a CURL request to be executed and call the given @a jcc
559 * upon its completion. Note that the context will make use of the
560 * CURLOPT_PRIVATE facility of the CURL @a eh.
561 *
562 * This function modifies the CURL handle to add the
563 * "Content-Type: application/json" header if @a add_json is set.
564 *
565 * @param ctx context to execute the job in
566 * @param eh curl easy handle for the request, will be executed AND
567 * cleaned up. NOTE: the handle should _never_ have gotten
568 * any headers list, as that would then be overridden by
569 * @a jcc. Therefore, always pass custom headers as the
570 * @a job_headers parameter.
571 * @param job_headers extra headers to add for this request
572 * @param jcc callback to invoke upon completion
573 * @param jcc_cls closure for @a jcc
574 * @return NULL on error (in this case, @eh is still released!)
575 */
576struct GNUNET_CURL_Job * 492struct GNUNET_CURL_Job *
577GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, 493GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
578 CURL *eh, 494 CURL *eh,
@@ -624,21 +540,6 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
624} 540}
625 541
626 542
627/**
628 * Schedule a CURL request to be executed and call the given @a jcc
629 * upon its completion. Note that the context will make use of the
630 * CURLOPT_PRIVATE facility of the CURL @a eh.
631 *
632 * This function modifies the CURL handle to add the
633 * "Content-Type: application/json" header.
634 *
635 * @param ctx context to execute the job in
636 * @param eh curl easy handle for the request, will
637 * be executed AND cleaned up
638 * @param jcc callback to invoke upon completion
639 * @param jcc_cls closure for @a jcc
640 * @return NULL on error (in this case, @eh is still released!)
641 */
642struct GNUNET_CURL_Job * 543struct GNUNET_CURL_Job *
643GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx, 544GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx,
644 CURL *eh, 545 CURL *eh,
@@ -661,18 +562,6 @@ GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx,
661} 562}
662 563
663 564
664/**
665 * Schedule a CURL request to be executed and call the given @a jcc
666 * upon its completion. Note that the context will make use of the
667 * CURLOPT_PRIVATE facility of the CURL @a eh.
668 *
669 * @param ctx context to execute the job in
670 * @param eh curl easy handle for the request, will
671 * be executed AND cleaned up
672 * @param jcc callback to invoke upon completion
673 * @param jcc_cls closure for @a jcc
674 * @return NULL on error (in this case, @eh is still released!)
675 */
676struct GNUNET_CURL_Job * 565struct GNUNET_CURL_Job *
677GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, 566GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
678 CURL *eh, 567 CURL *eh,
@@ -687,12 +576,6 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
687} 576}
688 577
689 578
690/**
691 * Cancel a job. Must only be called before the job completion
692 * callback is called for the respective job.
693 *
694 * @param job job to cancel
695 */
696void 579void
697GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) 580GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
698{ 581{
@@ -746,24 +629,6 @@ is_json (const char *ct)
746} 629}
747 630
748 631
749/**
750 * Obtain information about the final result about the
751 * HTTP download. If the download was successful, parses
752 * the JSON in the @a db and returns it. Also returns
753 * the HTTP @a response_code. If the download failed,
754 * the return value is NULL. The response code is set
755 * in any case, on download errors to zero.
756 *
757 * Calling this function also cleans up @a db.
758 *
759 * @param db download buffer
760 * @param eh CURL handle (to get the response code)
761 * @param[out] response_code set to the HTTP response code
762 * (or zero if we aborted the download, for example
763 * because the response was too big, or if
764 * the JSON we received was malformed).
765 * @return NULL if downloading a JSON reply failed.
766 */
767void * 632void *
768GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, 633GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
769 CURL *eh, 634 CURL *eh,
@@ -838,13 +703,6 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
838} 703}
839 704
840 705
841/**
842 * Add custom request header.
843 *
844 * @param ctx cURL context.
845 * @param header header string; will be given to the context AS IS.
846 * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
847 */
848enum GNUNET_GenericReturnValue 706enum GNUNET_GenericReturnValue
849GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, 707GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
850 const char *header) 708 const char *header)
@@ -858,14 +716,6 @@ GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
858} 716}
859 717
860 718
861/**
862 * Run the main event loop for the HTTP interaction.
863 *
864 * @param ctx the library context
865 * @param rp parses the raw response returned from
866 * the Web server.
867 * @param rc cleans/frees the response
868 */
869void 719void
870GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, 720GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
871 GNUNET_CURL_RawParser rp, 721 GNUNET_CURL_RawParser rp,
@@ -920,11 +770,6 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
920} 770}
921 771
922 772
923/**
924 * Run the main event loop for the HTTP interaction.
925 *
926 * @param ctx the library context
927 */
928void 773void
929GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) 774GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
930{ 775{
@@ -934,34 +779,6 @@ GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
934} 779}
935 780
936 781
937/**
938 * Obtain the information for a select() call to wait until
939 * #GNUNET_CURL_perform() is ready again. Note that calling
940 * any other GNUNET_CURL-API may also imply that the library
941 * is again ready for #GNUNET_CURL_perform().
942 *
943 * Basically, a client should use this API to prepare for select(),
944 * then block on select(), then call #GNUNET_CURL_perform() and then
945 * start again until the work with the context is done.
946 *
947 * This function will NOT zero out the sets and assumes that @a max_fd
948 * and @a timeout are already set to minimal applicable values. It is
949 * safe to give this API FD-sets and @a max_fd and @a timeout that are
950 * already initialized to some other descriptors that need to go into
951 * the select() call.
952 *
953 * @param ctx context to get the event loop information for
954 * @param read_fd_set will be set for any pending read operations
955 * @param write_fd_set will be set for any pending write operations
956 * @param except_fd_set is here because curl_multi_fdset() has this argument
957 * @param max_fd set to the highest FD included in any set;
958 * if the existing sets have no FDs in it, the initial
959 * value should be "-1". (Note that `max_fd + 1` will need
960 * to be passed to select().)
961 * @param timeout set to the timeout in milliseconds (!); -1 means
962 * no timeout (NULL, blocking forever is OK), 0 means to
963 * proceed immediately with #GNUNET_CURL_perform().
964 */
965void 782void
966GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx, 783GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
967 fd_set *read_fd_set, 784 fd_set *read_fd_set,
@@ -995,13 +812,6 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
995} 812}
996 813
997 814
998/**
999 * Cleanup library initialisation resources. This function should be called
1000 * after using this library to cleanup the resources occupied during library's
1001 * initialisation.
1002 *
1003 * @param ctx the library context
1004 */
1005void 815void
1006GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx) 816GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx)
1007{ 817{