2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see
15 <http://www.gnu.org/licenses/>
18 * @file src/include/gnunet_curl_lib.h
19 * @brief library to make it easy to download JSON replies over HTTP
20 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
21 * @author Christian Grothoff
23 * @defgroup curl CURL integration library
24 * Download JSON using libcurl.
27 #ifndef GNUNET_CURL_LIB_H
28 #define GNUNET_CURL_LIB_H
30 #include <curl/curl.h>
31 #elif HAVE_GNURL_CURL_H
32 #include <gnurl/curl.h>
35 #include "gnunet_util_lib.h"
39 * Initialise this library. This function should be called before using any of
40 * the following functions.
42 * @return library context
44 struct GNUNET_CURL_Context *
45 GNUNET_CURL_init (void);
49 * Obtain the information for a select() call to wait until
50 * #GNUNET_CURL_perform() is ready again. Note that calling
51 * any other TALER_EXCHANGE-API may also imply that the library
52 * is again ready for #GNUNET_CURL_perform().
54 * Basically, a client should use this API to prepare for select(),
55 * then block on select(), then call #GNUNET_CURL_perform() and then
56 * start again until the work with the context is done.
58 * This function will NOT zero out the sets and assumes that @a max_fd
59 * and @a timeout are already set to minimal applicable values. It is
60 * safe to give this API FD-sets and @a max_fd and @a timeout that are
61 * already initialized to some other descriptors that need to go into
64 * @param ctx context to get the event loop information for
65 * @param read_fd_set will be set for any pending read operations
66 * @param write_fd_set will be set for any pending write operations
67 * @param except_fd_set is here because curl_multi_fdset() has this argument
68 * @param max_fd set to the highest FD included in any set;
69 * if the existing sets have no FDs in it, the initial
70 * value should be "-1". (Note that `max_fd + 1` will need
71 * to be passed to select().)
72 * @param timeout set to the timeout in milliseconds (!); -1 means
73 * no timeout (NULL, blocking forever is OK), 0 means to
74 * proceed immediately with #GNUNET_CURL_perform().
77 GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
80 fd_set *except_fd_set,
86 * Run the main event loop for the Taler interaction.
88 * @param ctx the library context
91 GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx);
95 * Cleanup library initialisation resources. This function should be called
96 * after using this library to cleanup the resources occupied during library's
99 * @param ctx the library context
102 GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx);
106 * Entry in the context's job queue.
108 struct GNUNET_CURL_Job;
111 * Function to call upon completion of a job.
114 * @param response_code HTTP response code from server, 0 on hard error
115 * @param json response, NULL if response was not in JSON format
118 (*GNUNET_CURL_JobCompletionCallback)(void *cls,
124 * Schedule a CURL request to be executed and call the given @a jcc
125 * upon its completion. Note that the context will make use of the
126 * CURLOPT_PRIVATE facility of the CURL @a eh.
128 * This function modifies the CURL handle to add the
129 * "Content-Type: application/json" header if @a add_json is set.
131 * @param ctx context to execute the job in
132 * @param eh curl easy handle for the request, will
133 * be executed AND cleaned up
134 * @param add_json add "application/json" content type header
135 * @param jcc callback to invoke upon completion
136 * @param jcc_cls closure for @a jcc
137 * @return NULL on error (in this case, @eh is still released!)
139 struct GNUNET_CURL_Job *
140 GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
143 GNUNET_CURL_JobCompletionCallback jcc,
148 * Cancel a job. Must only be called before the job completion
149 * callback is called for the respective job.
151 * @param job job to cancel
154 GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job);
157 /** @} */ /* end of group */
159 /* end of gnunet_curl_lib.h */