X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Finclude%2Fgnunet_curl_lib.h;h=0cbef9c73702de8a0a3cf495671282e7ef52803d;hb=200d05b44a96d6fec00e28736038c838c679f650;hp=098b4dc37bd193aa787cbfccbb052057d89e13d8;hpb=16642c4cb25faae335591b39795c71dedbeb37f1;p=oweals%2Fgnunet.git diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h index 098b4dc37..0cbef9c73 100644 --- a/src/include/gnunet_curl_lib.h +++ b/src/include/gnunet_curl_lib.h @@ -2,17 +2,20 @@ This file is part of GNUnet Copyright (C) 2014, 2015, 2016 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. - GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . - You should have received a copy of the GNU General Public License along with - GNUnet; see the file COPYING. If not, If not, see - + SPDX-License-Identifier: AGPL3.0-or-later */ /** * @file src/include/gnunet_curl_lib.h @@ -26,26 +29,91 @@ */ #ifndef GNUNET_CURL_LIB_H #define GNUNET_CURL_LIB_H +#if HAVE_CURL_CURL_H #include +#elif HAVE_GNURL_CURL_H +#include +#else +#error "needs curl or gnurl" +#endif #include -#include +#include "gnunet_util_lib.h" + + +/** + * 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. + * + * @param cls closure + */ +typedef void +(*GNUNET_CURL_RescheduleCallback)(void *cls); + +/** + * @brief Buffer data structure we use to buffer the HTTP download + * before giving it to the JSON parser. + */ +struct GNUNET_CURL_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; + +}; + +/** + * Parses the raw response we got from the Web server. + * + * @param db the raw data + * @param eh handle + * @param response_code HTTP response code + * @return the parsed object + */ +typedef void * +(*GNUNET_CURL_RawParser) (struct GNUNET_CURL_DownloadBuffer *db, + CURL *eh, + long *response_code); + +/** + * Deallocate the response. + * + * @param response object to clean + */ +typedef void +(*GNUNET_CURL_ResponseCleaner) (void *response); /** * Initialise this library. This function should be called before using any of * the following functions. * + * @param cb function to call when rescheduling is required + * @param cb_cls closure for @a cb * @return library context */ struct GNUNET_CURL_Context * -GNUNET_CURL_init (void); +GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, + void *cb_cls); /** * Obtain the information for a select() call to wait until - * #GNUNET_CURL_perform() is ready again. Note that calling - * any other TALER_EXCHANGE-API may also imply that the library - * is again ready for #GNUNET_CURL_perform(). + * #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 @@ -79,7 +147,18 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx, /** - * Run the main event loop for the Taler interaction. + * Add custom request header. + * + * @param ctx cURL context. + * @param header header string; will be given to the context AS IS. + * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise. + */ +int +GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, + const char *header); + +/** + * Run the main event loop for the CURL interaction. * * @param ctx the library context */ @@ -87,6 +166,19 @@ void GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx); +/** + * Run the main event loop for the Taler interaction. + * + * @param ctx the library context + * @param rp parses the raw response returned from + * the Web server. + * @param rc cleans/frees the response + */ +void +GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, + GNUNET_CURL_RawParser rp, + GNUNET_CURL_ResponseCleaner rc); + /** * Cleanup library initialisation resources. This function should be called * after using this library to cleanup the resources occupied during library's @@ -113,7 +205,7 @@ struct GNUNET_CURL_Job; typedef void (*GNUNET_CURL_JobCompletionCallback)(void *cls, long response_code, - json_t *json); + const void *response); /** @@ -149,6 +241,59 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, void GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job); + +/* ******* GNUnet SCHEDULER integration ************ */ + + +/** + * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). + */ +struct GNUNET_CURL_RescheduleContext; + + +/** + * Initialize reschedule context. + * + * @param ctx context to manage + * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). + */ +struct GNUNET_CURL_RescheduleContext * +GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx); + +/** + * Initialize reschedule context; with custom response parser + * + * @param ctx context to manage + * @return closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). + */ +struct GNUNET_CURL_RescheduleContext * +GNUNET_CURL_gnunet_rc_create_with_parser (struct GNUNET_CURL_Context *ctx, + GNUNET_CURL_RawParser rp, + GNUNET_CURL_ResponseCleaner rc); + + +/** + * Destroy reschedule context. + * + * @param rc context to destroy + */ +void +GNUNET_CURL_gnunet_rc_destroy (struct GNUNET_CURL_RescheduleContext *rc); + + +/** + * 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(). + * + * @param cls must point to a `struct GNUNET_CURL_RescheduleContext *` + * (pointer to a pointer!) + */ +void +GNUNET_CURL_gnunet_scheduler_reschedule (void *cls); + + #endif /** @} */ /* end of group */