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
29 #include <curl/curl.h>
31 #include <gnunet/gnunet_util_lib.h>
35 * Initialise this library. This function should be called before using any of
36 * the following functions.
38 * @return library context
40 struct GNUNET_CURL_Context *
41 GNUNET_CURL_init (void);
45 * Obtain the information for a select() call to wait until
46 * #GNUNET_CURL_perform() is ready again. Note that calling
47 * any other TALER_EXCHANGE-API may also imply that the library
48 * is again ready for #GNUNET_CURL_perform().
50 * Basically, a client should use this API to prepare for select(),
51 * then block on select(), then call #GNUNET_CURL_perform() and then
52 * start again until the work with the context is done.
54 * This function will NOT zero out the sets and assumes that @a max_fd
55 * and @a timeout are already set to minimal applicable values. It is
56 * safe to give this API FD-sets and @a max_fd and @a timeout that are
57 * already initialized to some other descriptors that need to go into
60 * @param ctx context to get the event loop information for
61 * @param read_fd_set will be set for any pending read operations
62 * @param write_fd_set will be set for any pending write operations
63 * @param except_fd_set is here because curl_multi_fdset() has this argument
64 * @param max_fd set to the highest FD included in any set;
65 * if the existing sets have no FDs in it, the initial
66 * value should be "-1". (Note that `max_fd + 1` will need
67 * to be passed to select().)
68 * @param timeout set to the timeout in milliseconds (!); -1 means
69 * no timeout (NULL, blocking forever is OK), 0 means to
70 * proceed immediately with #GNUNET_CURL_perform().
73 GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
76 fd_set *except_fd_set,
82 * Run the main event loop for the Taler interaction.
84 * @param ctx the library context
87 GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx);
91 * Cleanup library initialisation resources. This function should be called
92 * after using this library to cleanup the resources occupied during library's
95 * @param ctx the library context
98 GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx);
102 * Entry in the context's job queue.
104 struct GNUNET_CURL_Job;
107 * Function to call upon completion of a job.
110 * @param response_code HTTP response code from server, 0 on hard error
111 * @param json response, NULL if response was not in JSON format
114 (*GNUNET_CURL_JobCompletionCallback)(void *cls,
120 * Schedule a CURL request to be executed and call the given @a jcc
121 * upon its completion. Note that the context will make use of the
122 * CURLOPT_PRIVATE facility of the CURL @a eh.
124 * This function modifies the CURL handle to add the
125 * "Content-Type: application/json" header if @a add_json is set.
127 * @param ctx context to execute the job in
128 * @param eh curl easy handle for the request, will
129 * be executed AND cleaned up
130 * @param add_json add "application/json" content type header
131 * @param jcc callback to invoke upon completion
132 * @param jcc_cls closure for @a jcc
133 * @return NULL on error (in this case, @eh is still released!)
135 struct GNUNET_CURL_Job *
136 GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
139 GNUNET_CURL_JobCompletionCallback jcc,
144 * Cancel a job. Must only be called before the job completion
145 * callback is called for the respective job.
147 * @param job job to cancel
150 GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job);
153 /** @} */ /* end of group */
155 /* end of gnunet_curl_lib.h */