GNUnet 0.21.1
CURL integration library

Download JSON using libcurl. More...

Collaboration diagram for CURL integration library:

Data Structures

struct  GNUNET_CURL_DownloadBuffer
 Buffer data structure we use to buffer the HTTP download before giving it to the JSON parser. More...
 

Typedefs

typedef void(* GNUNET_CURL_RescheduleCallback) (void *cls)
 Function called by the context to ask for the event loop to be rescheduled, that is the application should call GNUNET_CURL_get_select_info() as the set of sockets we care about just changed. More...
 
typedef void *(* GNUNET_CURL_RawParser) (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
 Parses the raw response we got from the Web server. More...
 
typedef void(* GNUNET_CURL_ResponseCleaner) (void *response)
 Deallocate the response. More...
 
typedef void(* GNUNET_CURL_JobCompletionCallback) (void *cls, long response_code, const void *response)
 Function to call upon completion of a job. More...
 
typedef void(* GNUNET_CURL_RawJobCompletionCallback) (void *cls, long response_code, const void *body, size_t body_size)
 Function to call upon completion of a raw job. More...
 

Functions

struct GNUNET_CURL_ContextGNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls)
 Initialise this library. More...
 
void GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *max_fd, long *timeout)
 Obtain the information for a select() call to wait until GNUNET_CURL_perform() is ready again. More...
 
enum GNUNET_GenericReturnValue GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, const char *header)
 Add custom request header. More...
 
void GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
 Run the main event loop for the CURL interaction. More...
 
void GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, GNUNET_CURL_RawParser rp, GNUNET_CURL_ResponseCleaner rc)
 Run the main event loop for the HTTP interaction. More...
 
void GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx)
 Cleanup library initialisation resources. More...
 
struct GNUNET_CURL_JobGNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, CURL *eh, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls)
 Schedule a CURL request to be executed and call the given jcc upon its completion. More...
 
struct GNUNET_CURL_JobGNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx, CURL *eh, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls)
 Schedule a CURL request to be executed and call the given jcc upon its completion. More...
 
void GNUNET_CURL_set_userpass (struct GNUNET_CURL_Context *ctx, const char *userpass)
 Force use of the provided username and password for client authentication for all operations performed with ctx. More...
 
void GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx, const char *certtype, const char *certfile, const char *keyfile, const char *keypass)
 Force use of the provided TLS client certificate for client authentication for all operations performed with ctx. More...
 
struct GNUNET_CURL_JobGNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, CURL *eh, const struct curl_slist *job_headers, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls)
 Schedule a CURL request to be executed and call the given jcc upon its completion. More...
 
struct GNUNET_CURL_JobGNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx, CURL *eh, const struct curl_slist *job_headers, GNUNET_CURL_RawJobCompletionCallback jcc, void *jcc_cls)
 Schedule a CURL request to be executed and call the given jcc upon its completion. More...
 
void GNUNET_CURL_extend_headers (struct GNUNET_CURL_Job *job, const struct curl_slist *extra_headers)
 Add extra_headers to the HTTP headers for job. More...
 
void GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
 Cancel a job. More...
 
struct GNUNET_CURL_RescheduleContextGNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx)
 Initialize reschedule context. More...
 
struct GNUNET_CURL_RescheduleContextGNUNET_CURL_gnunet_rc_create_with_parser (struct GNUNET_CURL_Context *ctx, GNUNET_CURL_RawParser rp, GNUNET_CURL_ResponseCleaner rc)
 Initialize reschedule context; with custom response parser. More...
 
void GNUNET_CURL_gnunet_rc_destroy (struct GNUNET_CURL_RescheduleContext *rc)
 Destroy reschedule context. More...
 
void GNUNET_CURL_gnunet_scheduler_reschedule (void *cls)
 Implementation of the GNUNET_CURL_RescheduleCallback for GNUnet's scheduler. More...
 
void GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name)
 Enable sending the async scope ID as a header. More...
 
enum GNUNET_GenericReturnValue GNUNET_CURL_is_valid_scope_id (const char *scope_id)
 Return GNUNET_YES if given a valid scope ID and GNUNET_NO otherwise. More...
 

Detailed Description

Download JSON using libcurl.

Typedef Documentation

◆ GNUNET_CURL_RescheduleCallback

typedef void(* GNUNET_CURL_RescheduleCallback) (void *cls)

Function called by the context to ask for the event loop to be rescheduled, that is the application should call GNUNET_CURL_get_select_info() as the set of sockets we care about just changed.

Parameters
clsclosure

Definition at line 48 of file gnunet_curl_lib.h.

◆ GNUNET_CURL_RawParser

typedef void *(* GNUNET_CURL_RawParser) (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)

Parses the raw response we got from the Web server.

Parameters
dbthe raw data
ehhandle
response_codeHTTP response code
Returns
the parsed object

Definition at line 83 of file gnunet_curl_lib.h.

◆ GNUNET_CURL_ResponseCleaner

typedef void(* GNUNET_CURL_ResponseCleaner) (void *response)

Deallocate the response.

Parameters
responseobject to clean

Definition at line 93 of file gnunet_curl_lib.h.

◆ GNUNET_CURL_JobCompletionCallback

typedef void(* GNUNET_CURL_JobCompletionCallback) (void *cls, long response_code, const void *response)

Function to call upon completion of a job.

Parameters
clsclosure
response_codeHTTP response code from server, 0 on hard error
responsein JSON, NULL if response was not in JSON format

Definition at line 200 of file gnunet_curl_lib.h.

◆ GNUNET_CURL_RawJobCompletionCallback

typedef void(* GNUNET_CURL_RawJobCompletionCallback) (void *cls, long response_code, const void *body, size_t body_size)

Function to call upon completion of a raw job.

Parameters
clsclosure
response_codeHTTP response code from server, 0 on hard error
bodyhttp body of the response
body_sizenumber of bytes in body

Definition at line 214 of file gnunet_curl_lib.h.

Function Documentation

◆ GNUNET_CURL_init()

struct GNUNET_CURL_Context * GNUNET_CURL_init ( GNUNET_CURL_RescheduleCallback  cb,
void *  cb_cls 
)

Initialise this library.

This function should be called before using any of the following functions.

Parameters
cbfunction to call when rescheduling is required
cb_clsclosure for cb
Returns
library context

Definition at line 246 of file curl.c.

248{
249 struct GNUNET_CURL_Context *ctx;
250 CURLM *multi;
251 CURLSH *share;
252
253 if (curl_fail)
254 {
256 "Curl was not initialised properly\n");
257 return NULL;
258 }
259 if (NULL == (multi = curl_multi_init ()))
260 {
262 "Failed to create a Curl multi handle\n");
263 return NULL;
264 }
265 if (NULL == (share = curl_share_init ()))
266 {
268 "Failed to create a Curl share handle\n");
269 return NULL;
270 }
272 ctx->cb = cb;
273 ctx->cb_cls = cb_cls;
274 ctx->multi = multi;
275 ctx->share = share;
276 return ctx;
277}
static int curl_fail
Failsafe flag.
Definition: curl.c:71
static CURLM * multi
Current multi-CURL handle.
static struct GNUNET_FS_Handle * ctx
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context.
Definition: curl.c:140
void * cb_cls
Closure for cb.
Definition: curl.c:181
CURLSH * share
Curl share handle.
Definition: curl.c:149
GNUNET_CURL_RescheduleCallback cb
Function we need to call whenever the event loop's socket set changed.
Definition: curl.c:176

References GNUNET_CURL_Context::cb, GNUNET_CURL_Context::cb_cls, ctx, curl_fail, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, multi, and GNUNET_CURL_Context::share.

◆ GNUNET_CURL_get_select_info()

void GNUNET_CURL_get_select_info ( struct GNUNET_CURL_Context ctx,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set,
int *  max_fd,
long *  timeout 
)

Obtain the information for a select() call to wait until GNUNET_CURL_perform() is ready again.

Basically, a client should use this API to prepare for select(), then block on select(), then call GNUNET_CURL_perform() and then start again until the work with the context is done.

This function will NOT zero out the sets and assumes that max_fd and timeout are already set to minimal applicable values. It is safe to give this API FD-sets and max_fd and timeout that are already initialized to some other descriptors that need to go into the select() call.

Parameters
ctxcontext to get the event loop information for
read_fd_setwill be set for any pending read operations
write_fd_setwill be set for any pending write operations
except_fd_setis here because curl_multi_fdset() has this argument
max_fdset to the highest FD included in any set; if the existing sets have no FDs in it, the initial value should be "-1". (Note that max_fd + 1 will need to be passed to select().)
timeoutset to the timeout in milliseconds (!); -1 means no timeout (NULL, blocking forever is OK), 0 means to proceed immediately with GNUNET_CURL_perform().

Definition at line 828 of file curl.c.

834{
835 long to;
836 int m;
837
838 m = -1;
839 GNUNET_assert (CURLM_OK ==
840 curl_multi_fdset (ctx->multi,
841 read_fd_set,
842 write_fd_set,
843 except_fd_set,
844 &m));
845 to = *timeout;
846 *max_fd = GNUNET_MAX (m, *max_fd);
847 GNUNET_assert (CURLM_OK ==
848 curl_multi_timeout (ctx->multi,
849 &to));
850
851 /* Only if what we got back from curl is smaller than what we
852 already had (-1 == infinity!), then update timeout */
853 if ((to < *timeout) && (-1 != to))
854 *timeout = to;
855 if ((-1 == (*timeout)) && (NULL != ctx->jobs_head))
856 *timeout = to;
857}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
#define GNUNET_MAX(a, b)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References ctx, GNUNET_assert, GNUNET_MAX, m, and timeout.

Referenced by context_task().

Here is the caller graph for this function:

◆ GNUNET_CURL_append_header()

enum GNUNET_GenericReturnValue GNUNET_CURL_append_header ( struct GNUNET_CURL_Context ctx,
const char *  header 
)

Add custom request header.

Parameters
ctxcURL context.
headerheader string; will be given to the context AS IS.
Returns
GNUNET_OK if no errors occurred, GNUNET_SYSERR otherwise.

Definition at line 734 of file curl.c.

736{
737 ctx->common_headers = curl_slist_append (ctx->common_headers,
738 header);
739 if (NULL == ctx->common_headers)
740 return GNUNET_SYSERR;
741
742 return GNUNET_OK;
743}
@ GNUNET_OK
@ GNUNET_SYSERR

References ctx, GNUNET_OK, and GNUNET_SYSERR.

◆ GNUNET_CURL_perform()

void GNUNET_CURL_perform ( struct GNUNET_CURL_Context ctx)

Run the main event loop for the CURL interaction.

Parameters
ctxthe library context

Definition at line 819 of file curl.c.

820{
823 (GNUNET_CURL_ResponseCleaner) & json_decref);
824}
void * GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
Definition: curl.c:649
void(* GNUNET_CURL_ResponseCleaner)(void *response)
Deallocate the response.
void GNUNET_CURL_perform2(struct GNUNET_CURL_Context *ctx, GNUNET_CURL_RawParser rp, GNUNET_CURL_ResponseCleaner rc)
Run the main event loop for the HTTP interaction.
Definition: curl.c:747

References ctx, GNUNET_CURL_download_get_result_(), and GNUNET_CURL_perform2().

Here is the call graph for this function:

◆ GNUNET_CURL_perform2()

void GNUNET_CURL_perform2 ( struct GNUNET_CURL_Context ctx,
GNUNET_CURL_RawParser  rp,
GNUNET_CURL_ResponseCleaner  rc 
)

Run the main event loop for the HTTP interaction.

Parameters
ctxthe library context
rpparses the raw response returned from the Web server.
rccleans/frees the response

Definition at line 747 of file curl.c.

750{
751 CURLMsg *cmsg;
752 int n_running;
753 int n_completed;
754
755 (void) curl_multi_perform (ctx->multi,
756 &n_running);
757 while (NULL != (cmsg = curl_multi_info_read (ctx->multi,
758 &n_completed)))
759 {
760 struct GNUNET_CURL_Job *job;
762 long response_code;
763 void *response;
764
765 /* Only documented return value is CURLMSG_DONE */
766 GNUNET_break (CURLMSG_DONE == cmsg->msg);
767 GNUNET_assert (CURLE_OK ==
768 curl_easy_getinfo (cmsg->easy_handle,
769 CURLINFO_PRIVATE,
770 (char **) &job));
771 GNUNET_assert (job->ctx == ctx);
772 response_code = 0;
774 if (NULL != job->jcc_raw)
775 {
776 /* RAW mode, no parsing */
777 GNUNET_break (CURLE_OK ==
778 curl_easy_getinfo (job->easy_handle,
779 CURLINFO_RESPONSE_CODE,
780 &response_code));
781 job->jcc_raw (job->jcc_raw_cls,
782 response_code,
783 job->db.buf,
784 job->db.buf_size);
785 }
786 else
787 {
788 /* to be parsed via 'rp' */
789 response = rp (&job->db,
790 job->easy_handle,
791 &response_code);
792 job->jcc (job->jcc_cls,
793 response_code,
794 response);
795 rc (response);
796 }
797 {
798 char *url = NULL;
799
800 if (CURLE_UNKNOWN_OPTION ==
801 curl_easy_getinfo (job->easy_handle,
802 CURLINFO_EFFECTIVE_URL,
803 &url))
804 url = "<unknown>";
806 "HTTP request for `%s' finished with %u after %s\n",
807 url,
808 (unsigned int) response_code,
810 true));
811 /* Note: we MUST NOT free 'url' here */
812 }
814 }
815}
static struct GNUNET_SCHEDULER_Task * job
Task for main job.
Definition: gnunet-cadet.c:137
static struct MHD_Response * response
Our canonical response.
static char * rp
Relying party.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:90
void GNUNET_CURL_job_cancel(struct GNUNET_CURL_Job *job)
Cancel a job.
Definition: curl.c:596
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_INFO
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
Definition: time.c:264
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:436
Jobs are CURL requests running within a struct GNUNET_CURL_Context.
Definition: curl.c:77
Time for relative time used by GNUnet, in microseconds.

References ctx, duration, GNUNET_assert, GNUNET_break, GNUNET_CURL_job_cancel(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative2s(), job, response, and rp.

Referenced by context_task(), and GNUNET_CURL_perform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CURL_fini()

void GNUNET_CURL_fini ( struct GNUNET_CURL_Context ctx)

Cleanup library initialisation resources.

This function should be called after using this library to cleanup the resources occupied during library's initialisation.

Parameters
ctxthe library context

Definition at line 861 of file curl.c.

862{
863 /* all jobs must have been cancelled at this time, assert this */
864 GNUNET_assert (NULL == ctx->jobs_head);
865 curl_share_cleanup (ctx->share);
866 curl_multi_cleanup (ctx->multi);
867 curl_slist_free_all (ctx->common_headers);
868 GNUNET_free (ctx->userpass);
869 GNUNET_free (ctx->certtype);
870 GNUNET_free (ctx->certfile);
871 GNUNET_free (ctx->keyfile);
872 GNUNET_free (ctx->keypass);
874}
#define GNUNET_free(ptr)
Wrapper around free.

References ctx, GNUNET_assert, and GNUNET_free.

◆ GNUNET_CURL_job_add()

struct GNUNET_CURL_Job * GNUNET_CURL_job_add ( struct GNUNET_CURL_Context ctx,
CURL *  eh,
GNUNET_CURL_JobCompletionCallback  jcc,
void *  jcc_cls 
)

Schedule a CURL request to be executed and call the given jcc upon its completion.

Note that the context will make use of the CURLOPT_PRIVATE facility of the CURL eh.

Parameters
ctxcontext to execute the job in
ehcurl easy handle for the request, will be executed AND cleaned up
jcccallback to invoke upon completion
jcc_clsclosure for jcc
Returns
NULL on error (in this case, eh is still released!)

Definition at line 582 of file curl.c.

586{
588 eh,
589 NULL,
590 jcc,
591 jcc_cls);
592}
struct GNUNET_CURL_Job * GNUNET_CURL_job_add2(struct GNUNET_CURL_Context *ctx, CURL *eh, const struct curl_slist *job_headers, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls)
Schedule a CURL request to be executed and call the given jcc upon its completion.
Definition: curl.c:509

References ctx, GNUNET_CURL_job_add2(), GNUNET_CURL_Job::jcc, and GNUNET_CURL_Job::jcc_cls.

Here is the call graph for this function:

◆ GNUNET_CURL_job_add_with_ct_json()

struct GNUNET_CURL_Job * GNUNET_CURL_job_add_with_ct_json ( struct GNUNET_CURL_Context ctx,
CURL *  eh,
GNUNET_CURL_JobCompletionCallback  jcc,
void *  jcc_cls 
)

Schedule a CURL request to be executed and call the given jcc upon its completion.

Note that the context will make use of the CURLOPT_PRIVATE facility of the CURL eh.

This function modifies the CURL handle to add the "Content-Type: application/json" header.

Parameters
ctxcontext to execute the job in
ehcurl easy handle for the request, will be executed AND cleaned up
jcccallback to invoke upon completion
jcc_clsclosure for jcc
Returns
NULL on error (in this case, eh is still released!)

Definition at line 560 of file curl.c.

564{
565 struct GNUNET_CURL_Job *job;
566 struct curl_slist *job_headers = NULL;
567
568 GNUNET_assert (NULL != (job_headers =
569 curl_slist_append (NULL,
570 "Content-Type: application/json")));
572 eh,
573 job_headers,
574 jcc,
575 jcc_cls);
576 curl_slist_free_all (job_headers);
577 return job;
578}

References ctx, GNUNET_assert, GNUNET_CURL_job_add2(), and job.

Here is the call graph for this function:

◆ GNUNET_CURL_set_userpass()

void GNUNET_CURL_set_userpass ( struct GNUNET_CURL_Context ctx,
const char *  userpass 
)

Force use of the provided username and password for client authentication for all operations performed with ctx.

Parameters
ctxcontext to set authentication data for
userpassstring with "$USERNAME:$PASSWORD"

Definition at line 214 of file curl.c.

216{
217 GNUNET_free (ctx->userpass);
218 if (NULL != userpass)
219 ctx->userpass = GNUNET_strdup (userpass);
220}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References ctx, GNUNET_free, and GNUNET_strdup.

◆ GNUNET_CURL_set_tlscert()

void GNUNET_CURL_set_tlscert ( struct GNUNET_CURL_Context ctx,
const char *  certtype,
const char *  certfile,
const char *  keyfile,
const char *  keypass 
)

Force use of the provided TLS client certificate for client authentication for all operations performed with ctx.

Note that if the provided information is incorrect, the earliest operation that could fail is GNUNET_CURL_job_add() or GNUNET_CURL_job_add2()!

Parameters
ctxcontext to set authentication data for
certtypetype of the certificate
certfilefile with the certificate
keyfilefile with the private key
keypasspassphrase to decrypt keyfile (or NULL)

Definition at line 224 of file curl.c.

229{
230 GNUNET_free (ctx->certtype);
231 GNUNET_free (ctx->certfile);
232 GNUNET_free (ctx->keyfile);
233 GNUNET_free (ctx->keypass);
234 if (NULL != certtype)
235 ctx->certtype = GNUNET_strdup (certtype);
236 if (NULL != certfile)
237 ctx->certfile = GNUNET_strdup (certfile);
238 if (NULL != keyfile)
239 ctx->certtype = GNUNET_strdup (keyfile);
240 if (NULL != keypass)
241 ctx->certtype = GNUNET_strdup (keypass);
242}

References ctx, GNUNET_free, and GNUNET_strdup.

◆ GNUNET_CURL_job_add2()

struct GNUNET_CURL_Job * GNUNET_CURL_job_add2 ( struct GNUNET_CURL_Context ctx,
CURL *  eh,
const struct curl_slist *  job_headers,
GNUNET_CURL_JobCompletionCallback  jcc,
void *  jcc_cls 
)

Schedule a CURL request to be executed and call the given jcc upon its completion.

Note that the context will make use of the CURLOPT_PRIVATE facility of the CURL eh.

This function modifies the CURL handle to add the "Content-Type: application/json" header if add_json is set.

Parameters
ctxcontext to execute the job in
ehcurl easy handle for the request, will be executed AND cleaned up
job_headersextra headers to add for this request
jcccallback to invoke upon completion
jcc_clsclosure for jcc
Returns
NULL on error (in this case, eh is still released!)

Definition at line 509 of file curl.c.

514{
515 struct GNUNET_CURL_Job *job;
516 struct curl_slist *all_headers;
517
518 GNUNET_assert (NULL != jcc);
519 if ( (NULL != ctx->userpass) &&
520 (0 != curl_easy_setopt (eh,
521 CURLOPT_USERPWD,
522 ctx->userpass)) )
523 return NULL;
524 if ( (NULL != ctx->certfile) &&
525 (0 != curl_easy_setopt (eh,
526 CURLOPT_SSLCERT,
527 ctx->certfile)) )
528 return NULL;
529 if ( (NULL != ctx->certtype) &&
530 (0 != curl_easy_setopt (eh,
531 CURLOPT_SSLCERTTYPE,
532 ctx->certtype)) )
533 return NULL;
534 if ( (NULL != ctx->keyfile) &&
535 (0 != curl_easy_setopt (eh,
536 CURLOPT_SSLKEY,
537 ctx->keyfile)) )
538 return NULL;
539 if ( (NULL != ctx->keypass) &&
540 (0 != curl_easy_setopt (eh,
541 CURLOPT_KEYPASSWD,
542 ctx->keypass)) )
543 return NULL;
544
545 all_headers = setup_job_headers (ctx,
546 job_headers);
547 if (NULL == (job = setup_job (eh,
548 ctx,
549 all_headers)))
550 return NULL;
551
552 job->jcc = jcc;
553 job->jcc_cls = jcc_cls;
554 ctx->cb (ctx->cb_cls);
555 return job;
556}
static struct GNUNET_CURL_Job * setup_job(CURL *eh, struct GNUNET_CURL_Context *ctx, struct curl_slist *all_headers)
Create a job.
Definition: curl.c:406
static struct curl_slist * setup_job_headers(struct GNUNET_CURL_Context *ctx, const struct curl_slist *job_headers)
Create the HTTP headers for the request.
Definition: curl.c:351

References ctx, GNUNET_assert, job, setup_job(), and setup_job_headers().

Referenced by GNUNET_CURL_job_add(), and GNUNET_CURL_job_add_with_ct_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CURL_job_add_raw()

struct GNUNET_CURL_Job * GNUNET_CURL_job_add_raw ( struct GNUNET_CURL_Context ctx,
CURL *  eh,
const struct curl_slist *  job_headers,
GNUNET_CURL_RawJobCompletionCallback  jcc,
void *  jcc_cls 
)

Schedule a CURL request to be executed and call the given jcc upon its completion.

Note that the context will make use of the CURLOPT_PRIVATE facility of the CURL eh. Used to download resources that are NOT in JSON. The raw body will be returned.

Parameters
ctxcontext to execute the job in
ehcurl easy handle for the request, will be executed AND cleaned up
job_headersextra headers to add for this request
jcccallback to invoke upon completion
jcc_clsclosure for jcc
Returns
NULL on error (in this case, eh is still released!)

Definition at line 485 of file curl.c.

490{
491 struct GNUNET_CURL_Job *job;
492 struct curl_slist *all_headers;
493
494 GNUNET_assert (NULL != jcc);
495 all_headers = setup_job_headers (ctx,
496 job_headers);
497 if (NULL == (job = setup_job (eh,
498 ctx,
499 all_headers)))
500 return NULL;
501 job->jcc_raw = jcc;
502 job->jcc_raw_cls = jcc_cls;
503 ctx->cb (ctx->cb_cls);
504 return job;
505}

References ctx, GNUNET_assert, job, setup_job(), and setup_job_headers().

Here is the call graph for this function:

◆ GNUNET_CURL_extend_headers()

void GNUNET_CURL_extend_headers ( struct GNUNET_CURL_Job job,
const struct curl_slist *  extra_headers 
)

Add extra_headers to the HTTP headers for job.

Parameters
[in,out]jobthe job to modify
extra_headersheaders to append

Definition at line 467 of file curl.c.

469{
470 struct curl_slist *all_headers = job->job_headers;
471
472 for (const struct curl_slist *curr = extra_headers;
473 NULL != curr;
474 curr = curr->next)
475 {
476 GNUNET_assert (NULL !=
477 (all_headers = curl_slist_append (all_headers,
478 curr->data)));
479 }
480 job->job_headers = all_headers;
481}

References GNUNET_assert, and job.

◆ GNUNET_CURL_job_cancel()

void GNUNET_CURL_job_cancel ( struct GNUNET_CURL_Job job)

Cancel a job.

Must only be called before the job completion callback is called for the respective job.

Parameters
jobjob to cancel

Definition at line 596 of file curl.c.

597{
598 struct GNUNET_CURL_Context *ctx = job->ctx;
599
601 ctx->jobs_tail,
602 job);
603 GNUNET_break (CURLM_OK ==
604 curl_multi_remove_handle (ctx->multi,
605 job->easy_handle));
606 curl_easy_cleanup (job->easy_handle);
607 GNUNET_free (job->db.buf);
608 curl_slist_free_all (job->job_headers);
609 ctx->cb (ctx->cb_cls);
611}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References ctx, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and job.

Referenced by GNUNET_CURL_perform2().

Here is the caller graph for this function:

◆ GNUNET_CURL_gnunet_rc_create()

struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create ( struct GNUNET_CURL_Context ctx)

Initialize reschedule context.

Parameters
ctxcontext to manage
Returns
closure for GNUNET_CURL_gnunet_scheduler_reschedule().

Definition at line 91 of file curl_reschedule.c.

92{
94
96 rc->ctx = ctx;
98 rc->cleaner = &clean_result;
99 return rc;
100}
void * GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
Definition: curl.c:649
static void clean_result(void *response)
Just a wrapper to avoid casting of function pointers.
Closure for GNUNET_CURL_gnunet_scheduler_reschedule().
GNUNET_CURL_RawParser parser
Parser of the raw response.
struct GNUNET_CURL_Context * ctx
Context we manage.
GNUNET_CURL_ResponseCleaner cleaner
Deallocate the response object.

References clean_result(), GNUNET_CURL_RescheduleContext::cleaner, ctx, GNUNET_CURL_RescheduleContext::ctx, GNUNET_CURL_download_get_result_(), GNUNET_new, and GNUNET_CURL_RescheduleContext::parser.

Here is the call graph for this function:

◆ GNUNET_CURL_gnunet_rc_create_with_parser()

struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create_with_parser ( struct GNUNET_CURL_Context ctx,
GNUNET_CURL_RawParser  rp,
GNUNET_CURL_ResponseCleaner  rc 
)

Initialize reschedule context; with custom response parser.

Parameters
ctxcontext to manage
Returns
closure for GNUNET_CURL_gnunet_scheduler_reschedule().

Definition at line 63 of file curl_reschedule.c.

66{
68
70 rctx->ctx = ctx;
71 rctx->parser = rp;
72 rctx->cleaner = rc;
73
74 return rctx;
75}

References GNUNET_CURL_RescheduleContext::cleaner, ctx, GNUNET_CURL_RescheduleContext::ctx, GNUNET_new, GNUNET_CURL_RescheduleContext::parser, and rp.

◆ GNUNET_CURL_gnunet_rc_destroy()

void GNUNET_CURL_gnunet_rc_destroy ( struct GNUNET_CURL_RescheduleContext rc)

Destroy reschedule context.

Parameters
rccontext to destroy

Definition at line 104 of file curl_reschedule.c.

105{
106 if (NULL != rc->task)
108 GNUNET_free (rc);
109}
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * task
Just the task.

References GNUNET_free, GNUNET_SCHEDULER_cancel(), and GNUNET_CURL_RescheduleContext::task.

Here is the call graph for this function:

◆ GNUNET_CURL_gnunet_scheduler_reschedule()

void GNUNET_CURL_gnunet_scheduler_reschedule ( void *  cls)

Implementation of the GNUNET_CURL_RescheduleCallback for GNUnet's scheduler.

Will run the CURL context using GNUnet's scheduler. Note that you MUST immediately destroy the reschedule context after calling GNUNET_CURL_fini().

Parameters
clsmust point to a struct GNUNET_CURL_RescheduleContext * (pointer to a pointer!)

Definition at line 170 of file curl_reschedule.c.

171{
172 struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls;
173
174 if (NULL != rc->task)
177 rc);
178}
static void context_task(void *cls)
Task that runs the context's event loop with the GNUnet scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305

References context_task(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and GNUNET_CURL_RescheduleContext::task.

Here is the call graph for this function:

◆ GNUNET_CURL_enable_async_scope_header()

void GNUNET_CURL_enable_async_scope_header ( struct GNUNET_CURL_Context ctx,
const char *  header_name 
)

Enable sending the async scope ID as a header.

Parameters
ctxthe context to enable this for
header_namename of the header to send.

Definition at line 281 of file curl.c.

283{
284 ctx->async_scope_id_header = header_name;
285}

References ctx.

◆ GNUNET_CURL_is_valid_scope_id()

enum GNUNET_GenericReturnValue GNUNET_CURL_is_valid_scope_id ( const char *  scope_id)

Return GNUNET_YES if given a valid scope ID and GNUNET_NO otherwise.

See GNUNET_CURL_enable_async_scope_header() for the code that generates such a scope_id in an HTTP header.

Returns
GNUNET_YES iff given a valid scope ID

Definition at line 289 of file curl.c.

290{
291 if (strlen (scope_id) >= 64)
292 return GNUNET_NO;
293 for (size_t i = 0; i < strlen (scope_id); i++)
294 if (! (isalnum (scope_id[i]) || (scope_id[i] == '-')))
295 return GNUNET_NO;
296 return GNUNET_YES;
297}
@ GNUNET_YES
@ GNUNET_NO

References GNUNET_NO, and GNUNET_YES.