diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-07-11 23:07:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-07-11 23:07:36 +0200 |
commit | 6170dbbf37d8312539bb2beddc0091c7bf54fe6c (patch) | |
tree | c65dde6631a7a7703dbeb2f69f67f5922b56e61c /src/mint-lib/mint_api_context.h | |
parent | a74f55754aaeb3e28cb6943b1dd50e4a4117070b (diff) | |
download | exchange-6170dbbf37d8312539bb2beddc0091c7bf54fe6c.tar.xz |
share more code in mint API, misc bugfixes
Diffstat (limited to 'src/mint-lib/mint_api_context.h')
-rw-r--r-- | src/mint-lib/mint_api_context.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/mint-lib/mint_api_context.h b/src/mint-lib/mint_api_context.h index 235c32bd1..c545a3fe7 100644 --- a/src/mint-lib/mint_api_context.h +++ b/src/mint-lib/mint_api_context.h @@ -50,15 +50,20 @@ typedef void * instead use #MAC_easy_to_closure to extract the @a jcc_cls argument * from a valid @a eh afterwards. * + * This function modifies the CURL handle to add the + * "Content-Type: application/json" header if @a add_json is set. + * * @param ctx context to execute the job in * @param eh curl easy handle for the request, will * be executed AND cleaned up + * @param add_json add "application/json" content type header * @param jcc callback to invoke upon completion * @param jcc_cls closure for @a jcc */ struct MAC_Job * MAC_job_add (struct TALER_MINT_Context *ctx, CURL *eh, + int add_json, MAC_JobCompletionCallback jcc, void *jcc_cls); @@ -84,4 +89,81 @@ void MAC_job_cancel (struct MAC_Job *job); +/** + * Buffer data structure we use to buffer the HTTP download + * before giving it to the JSON parser. + */ +struct MAC_DownloadBuffer +{ + + /** + * Download buffer + */ + void *buf; + + /** + * The size of the download buffer + */ + size_t buf_size; + + /** + * Error code (based on libc errno) if we failed to download + * (i.e. response too large). + */ + int eno; + +}; + + +/** + * Callback used when downloading the reply to an HTTP request. + * Just appends all of the data to the `buf` in the + * `struct MAC_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. + * + * Should be used by the various routines as the + * CURLOPT_WRITEFUNCTION. A `struct MAC_DownloadBuffer` needs to be + * passed to the CURLOPT_WRITEDATA. + * + * Afterwards, `eno` needs to be checked to ensure that the download + * completed correctly. + * + * @param bufptr data downloaded via HTTP + * @param size size of an item in @a bufptr + * @param nitems number of items in @a bufptr + * @param cls the `struct KeysRequest` + * @return number of bytes processed from @a bufptr + */ +size_t +MAC_download_cb (char *bufptr, + size_t size, + size_t nitems, + void *cls); + + +/** + * Obtain information about the final result about the + * HTTP download. If the download was successful, parses + * the JSON in the @a db and returns it. Also returns + * the HTTP @a response_code. If the download failed, + * the return value is NULL. The response code is set + * in any case, on download errors to zero. + * + * Calling this function also cleans up @a db. + * + * @param db download buffer + * @param eh CURL handle (to get the response code) + * @param[out] response_code set to the HTTP response code + * (or zero if we aborted the download, i.e. + * because the response was too big, or if + * the JSON we received was malformed). + * @return NULL if downloading a JSON reply failed + */ +json_t * +MAC_download_get_result (struct MAC_DownloadBuffer *db, + CURL *eh, + long *response_code); + + /* end of mint_api_context.h */ |