![]() |
GNUnet
0.11.x
|
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... | |
int | 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... | |
int | 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 51 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 86 of file gnunet_curl_lib.h.
typedef void(* GNUNET_CURL_ResponseCleaner) (void *response) |
Deallocate the response.
response | object to clean |
Definition at line 96 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 203 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 217 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 268 of file curl.c.
References GNUNET_CURL_Context::cb, GNUNET_CURL_Context::cb_cls, GNUNET_CURL_Job::ctx, curl_fail, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_CURL_Context::multi, 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(). |
Note that calling any other GNUNET_CURL-API may also imply that the library is again ready for GNUNET_CURL_perform().
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 1017 of file curl.c.
References GNUNET_assert, GNUNET_MAX, GNUNET_CURL_Context::jobs_head, m, GNUNET_CURL_Context::multi, and timeout.
Referenced by context_task().
int 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 830 of file curl.c.
References UrlRequestData::bytes_received, UrlRequestData::bytes_sent, GNUNET_CURL_Context::common_headers, UrlRequestData::count, get_url_benchmark_data(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_relative_add(), GNUNET_TIME_relative_max(), GNUNET_TIME_Relative::rel_value_us, UrlRequestData::time, and UrlRequestData::time_max.
void GNUNET_CURL_perform | ( | struct GNUNET_CURL_Context * | ctx | ) |
Run the main event loop for the CURL interaction.
ctx | the library context |
Run the main event loop for the CURL interaction.
ctx | the library context |
Definition at line 980 of file curl.c.
References 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 920 of file curl.c.
References GNUNET_assert, GNUNET_break, GNUNET_CURL_job_cancel(), job, GNUNET_CURL_Context::multi, 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 1054 of file curl.c.
References GNUNET_CURL_Context::certfile, GNUNET_CURL_Context::certtype, GNUNET_CURL_Context::common_headers, GNUNET_assert, GNUNET_free, GNUNET_CURL_Context::jobs_head, GNUNET_CURL_Context::keyfile, GNUNET_CURL_Context::keypass, GNUNET_CURL_Context::multi, GNUNET_CURL_Context::share, and GNUNET_CURL_Context::userpass.
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 662 of file curl.c.
References GNUNET_CURL_job_add2().
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 628 of file curl.c.
References GNUNET_assert, GNUNET_CURL_job_add2(), job, and GNUNET_CURL_Job::job_headers.
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 213 of file curl.c.
References GNUNET_free, GNUNET_strdup, and GNUNET_CURL_Context::userpass.
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 238 of file curl.c.
References GNUNET_CURL_Context::certfile, GNUNET_CURL_Context::certtype, GNUNET_free, GNUNET_strdup, GNUNET_CURL_Context::keyfile, and GNUNET_CURL_Context::keypass.
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.
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 |
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.
ctx | context to execute the job in |
eh | curl easy handle for the request, will be executed AND cleaned up. NOTE: the handle should never have gotten any headers list, as that would then be overridden by jcc. Therefore, always pass custom headers as the job_headers parameter. |
job_headers | extra headers to add for this request |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 562 of file curl.c.
References GNUNET_CURL_Context::cb, GNUNET_CURL_Context::cb_cls, GNUNET_CURL_Context::certfile, GNUNET_CURL_Context::certtype, GNUNET_assert, GNUNET_CURL_Job::jcc, GNUNET_CURL_Job::jcc_cls, job, GNUNET_CURL_Context::keyfile, GNUNET_CURL_Context::keypass, setup_job(), setup_job_headers(), and GNUNET_CURL_Context::userpass.
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 |
max_reply_size | largest acceptable response body |
jcc | callback to invoke upon completion |
jcc_cls | closure for jcc |
Definition at line 519 of file curl.c.
References GNUNET_CURL_Context::cb, GNUNET_CURL_Context::cb_cls, GNUNET_assert, GNUNET_CURL_Job::jcc, GNUNET_CURL_Job::jcc_cls, GNUNET_CURL_Job::jcc_raw, GNUNET_CURL_Job::jcc_raw_cls, 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 486 of file curl.c.
References GNUNET_assert, and GNUNET_CURL_Job::job_headers.
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 682 of file curl.c.
References GNUNET_CURL_DownloadBuffer::buf, GNUNET_CURL_Context::cb, GNUNET_CURL_Context::cb_cls, GNUNET_CURL_Job::ctx, GNUNET_CURL_Job::db, GNUNET_CURL_Job::easy_handle, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_CURL_Job::job_headers, GNUNET_CURL_Context::jobs_head, GNUNET_CURL_Context::jobs_tail, and GNUNET_CURL_Context::multi.
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 103 of file curl_reschedule.c.
References clean_result(), GNUNET_CURL_RescheduleContext::cleaner, 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 69 of file curl_reschedule.c.
References GNUNET_CURL_RescheduleContext::cleaner, 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 121 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 191 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 | ||
) |
Enable sending the async scope ID as a header.
ctx | the context to enable this for |
header_name | name of the header to send. |
Definition at line 309 of file curl.c.
References GNUNET_CURL_Context::async_scope_id_header.
int 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.
See setup_job_headers, logic related to GNUNET_CURL_enable_async_scope_header() for the code that generates such a scope_id.
Definition at line 326 of file curl.c.
References GNUNET_NO, and GNUNET_YES.