API for downloading JSON via CURL. More...
#include "platform.h"
#include <jansson.h>
#include <microhttpd.h>
#include "gnunet_curl_lib.h"
#include "curl_internal.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_CURL_Job |
Jobs are CURL requests running within a struct GNUNET_CURL_Context . More... | |
struct | GNUNET_CURL_Context |
Context. More... | |
Macros | |
#define | DEBUG 0 |
Set to 1 for extra debug logging. More... | |
#define | CURL_STRERROR(type, function, code) |
Log error related to CURL operations. More... | |
#define | JSON_WARN(error) |
Print JSON parsing related error information. More... | |
Functions | |
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_Context * | GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) |
Initialise this library. 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... | |
static size_t | download_cb (char *bufptr, size_t size, size_t nitems, void *cls) |
Callback used when downloading the reply to an HTTP request. More... | |
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. More... | |
static struct GNUNET_CURL_Job * | setup_job (CURL *eh, struct GNUNET_CURL_Context *ctx, struct curl_slist *all_headers) |
Create a job. 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... | |
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... | |
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_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... | |
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... | |
void | GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) |
Cancel a job. More... | |
static bool | is_json (const char *ct) |
Test if the given content type ct is JSON. More... | |
void * | GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code) |
enum GNUNET_GenericReturnValue | GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, const char *header) |
Add custom request header. 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_perform (struct GNUNET_CURL_Context *ctx) |
Run the main event loop for the CURL interaction. 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... | |
void | GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx) |
Cleanup library initialisation resources. More... | |
void | GNUNET_CURL_constructor__ (void) |
void | __attribute__ ((constructor)) |
Initial global setup logic, specifically runs the Curl setup. More... | |
void | GNUNET_CURL_destructor__ (void) |
void | __attribute__ ((destructor)) |
Cleans up after us, specifically runs the Curl cleanup. More... | |
Variables | |
static int | curl_fail |
Failsafe flag. More... | |
API for downloading JSON via CURL.
Definition in file curl.c.
#define CURL_STRERROR | ( | type, | |
function, | |||
code | |||
) |
Log error related to CURL operations.
type | log level |
function | which function failed to run |
code | what was the curl error code |
#define JSON_WARN | ( | error | ) |
Print JSON parsing related error information.
|
static |
Callback used when downloading the reply to an HTTP request.
Just appends all of the data to the buf
in the struct DownloadBuffer
for further processing. The size of the download is limited to GNUNET_MAX_MALLOC_CHECKED, if the download exceeds this size, we abort with an error.
bufptr | data downloaded via HTTP |
size | size of an item in bufptr |
nitems | number of items in bufptr |
cls | the struct DownloadBuffer |
Definition at line 315 of file curl.c.
References GNUNET_CURL_DownloadBuffer::buf, db, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, GNUNET_realloc, and size.
Referenced by setup_job().
|
static |
Create the HTTP headers for the request.
ctx | context we run in |
job_headers | job-specific headers |
Definition at line 352 of file curl.c.
References ctx, GNUNET_assert, GNUNET_async_scope_get(), GNUNET_free, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, and GNUNET_AsyncScopeSave::scope_id.
Referenced by GNUNET_CURL_job_add2(), and GNUNET_CURL_job_add_raw().
|
static |
Create a job.
eh | easy handle to use |
ctx | context to run the job in |
all_headers | HTTP client headers to use (free'd) |
Definition at line 407 of file curl.c.
References ctx, download_cb(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_new, GNUNET_TIME_absolute_get(), and job.
Referenced by GNUNET_CURL_job_add2(), and GNUNET_CURL_job_add_raw().
|
static |
Test if the given content type ct is JSON.
ct | a content type, e.g. "application/json; charset=UTF-8" |
Definition at line 623 of file curl.c.
Referenced by GNUNET_CURL_download_get_result_().
void * GNUNET_CURL_download_get_result_ | ( | struct GNUNET_CURL_DownloadBuffer * | db, |
CURL * | eh, | ||
long * | response_code | ||
) |
Definition at line 651 of file curl.c.
References db, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, is_json(), and JSON_WARN.
Referenced by GNUNET_CURL_gnunet_rc_create(), and GNUNET_CURL_perform().
void GNUNET_CURL_constructor__ | ( | void | ) |
void __attribute__ | ( | (constructor) | ) |
Initial global setup logic, specifically runs the Curl setup.
Definition at line 888 of file curl.c.
References curl_fail, CURL_STRERROR, GNUNET_ERROR_TYPE_ERROR, and ret.
void GNUNET_CURL_destructor__ | ( | void | ) |
void __attribute__ | ( | (destructor) | ) |
|
static |
Failsafe flag.
Raised if our constructor fails to initialize the Curl library.
Definition at line 72 of file curl.c.
Referenced by __attribute__(), and GNUNET_CURL_init().