Download JSON using libcurl. More...
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_Context * | GNUNET_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_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. More... | |
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. 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_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. More... | |
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. 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_RescheduleContext * | GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx) |
Initialize reschedule context. More... | |
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. 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... | |
Download JSON using libcurl.
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.
cls | closure |
Definition at line 48 of file gnunet_curl_lib.h.
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.
db | the raw data |
eh | handle |
response_code | HTTP response code |
Definition at line 83 of file gnunet_curl_lib.h.
typedef void(* GNUNET_CURL_ResponseCleaner) (void *response) |
Deallocate the response.
response | object to clean |
Definition at line 93 of file gnunet_curl_lib.h.
typedef void(* GNUNET_CURL_JobCompletionCallback) (void *cls, long response_code, const void *response) |
Function to call upon completion of a job.
cls | closure |
response_code | HTTP response code from server, 0 on hard error |
response | in JSON, NULL if response was not in JSON format |
Definition at line 200 of file gnunet_curl_lib.h.
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.
cls | closure |
response_code | HTTP response code from server, 0 on hard error |
body | http body of the response |
body_size | number of bytes in body |
Definition at line 214 of file gnunet_curl_lib.h.
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.
cb | function to call when rescheduling is required |
cb_cls | closure for cb |
Definition at line 247 of file curl.c.
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.
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.
ctx | context to get the event loop information for |
read_fd_set | will be set for any pending read operations |
write_fd_set | will be set for any pending write operations |
except_fd_set | is here because curl_multi_fdset() has this argument |
max_fd | set 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().) |
timeout | set 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 834 of file curl.c.
References ctx, GNUNET_assert, GNUNET_MAX, m, and timeout.
Referenced by context_task().
enum GNUNET_GenericReturnValue GNUNET_CURL_append_header | ( | struct GNUNET_CURL_Context * | ctx, |
const char * | header | ||
) |
Add custom request header.
ctx | cURL context. |
header | header string; will be given to the context AS IS. |
Definition at line 740 of file curl.c.
References ctx, GNUNET_OK, and GNUNET_SYSERR.
void GNUNET_CURL_perform | ( | struct GNUNET_CURL_Context * | ctx | ) |
Run the main event loop for the CURL interaction.
ctx | the library context |
Definition at line 825 of file curl.c.
References ctx, GNUNET_CURL_download_get_result_(), and 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.
ctx | the library context |
rp | parses the raw response returned from the Web server. |
rc | cleans/frees the response |
Definition at line 753 of file curl.c.
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().
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.
ctx | the library context |
Definition at line 867 of file curl.c.
References ctx, GNUNET_assert, and GNUNET_free.
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.
ctx | context to execute the job in |
eh | curl easy handle for the request, will be executed AND cleaned up |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 584 of file curl.c.
References ctx, GNUNET_CURL_job_add2(), GNUNET_CURL_Job::jcc, and GNUNET_CURL_Job::jcc_cls.
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.
ctx | context to execute the job in |
eh | curl easy handle for the request, will be executed AND cleaned up |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 561 of file curl.c.
References ctx, GNUNET_assert, GNUNET_CURL_job_add2(), and job.
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.
ctx | context to set authentication data for |
userpass | string with "$USERNAME:$PASSWORD" |
Definition at line 215 of file curl.c.
References ctx, GNUNET_free, and GNUNET_strdup.
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()!
ctx | context to set authentication data for |
certtype | type of the certificate |
certfile | file with the certificate |
keyfile | file with the private key |
keypass | passphrase to decrypt keyfile (or NULL) |
Definition at line 225 of file curl.c.
References ctx, GNUNET_free, and GNUNET_strdup.
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.
ctx | context to execute the job in |
eh | curl easy handle for the request, will be executed AND cleaned up |
job_headers | extra headers to add for this request |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 510 of file curl.c.
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().
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.
ctx | context to execute the job in |
eh | curl easy handle for the request, will be executed AND cleaned up |
job_headers | extra headers to add for this request |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 486 of file curl.c.
References ctx, GNUNET_assert, job, setup_job(), and setup_job_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.
[in,out] | job | the job to modify |
extra_headers | headers to append |
Definition at line 468 of file curl.c.
References GNUNET_assert, and job.
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.
job | job to cancel |
Definition at line 598 of file curl.c.
References ctx, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and job.
Referenced by GNUNET_CURL_perform2().
struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create | ( | struct GNUNET_CURL_Context * | ctx | ) |
Initialize reschedule context.
ctx | context to manage |
Definition at line 87 of file curl_reschedule.c.
References clean_result(), GNUNET_CURL_RescheduleContext::cleaner, ctx, GNUNET_CURL_RescheduleContext::ctx, GNUNET_CURL_download_get_result_(), GNUNET_new, and GNUNET_CURL_RescheduleContext::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.
ctx | context to manage |
Definition at line 59 of file curl_reschedule.c.
References GNUNET_CURL_RescheduleContext::cleaner, ctx, GNUNET_CURL_RescheduleContext::ctx, GNUNET_new, GNUNET_CURL_RescheduleContext::parser, and rp.
void GNUNET_CURL_gnunet_rc_destroy | ( | struct GNUNET_CURL_RescheduleContext * | rc | ) |
Destroy reschedule context.
rc | context to destroy |
Definition at line 100 of file curl_reschedule.c.
References GNUNET_free, GNUNET_SCHEDULER_cancel(), and GNUNET_CURL_RescheduleContext::task.
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().
cls | must point to a struct GNUNET_CURL_RescheduleContext * (pointer to a pointer!) |
Definition at line 166 of file curl_reschedule.c.
References context_task(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and GNUNET_CURL_RescheduleContext::task.
void GNUNET_CURL_enable_async_scope_header | ( | struct GNUNET_CURL_Context * | ctx, |
const char * | header_name | ||
) |
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.
Definition at line 290 of file curl.c.
References GNUNET_NO, and GNUNET_YES.