GNUnet  0.11.x
gnunet_curl_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
30 #ifndef GNUNET_CURL_LIB_H
31 #define GNUNET_CURL_LIB_H
32 #if HAVE_LIBCURL
33 #include <curl/curl.h>
34 #elif HAVE_LIBGNURL
35 #include <gnurl/curl.h>
36 #else
37 #error "needs curl or gnurl"
38 #endif
39 #include "gnunet_util_lib.h"
40 
41 
50 typedef void
52 
58 {
62  void *buf;
63 
67  size_t buf_size;
68 
73  int eno;
74 };
75 
76 
85 typedef void *
86 (*GNUNET_CURL_RawParser) (struct GNUNET_CURL_DownloadBuffer *db,
87  CURL *eh,
88  long *response_code);
89 
95 typedef void
97 
106 struct GNUNET_CURL_Context *
108  void *cb_cls);
109 
110 
137 void
139  fd_set *read_fd_set,
140  fd_set *write_fd_set,
141  fd_set *except_fd_set,
142  int *max_fd,
143  long *timeout);
144 
145 
153 int
155  const char *header);
156 
162 void
164 
165 
174 void
178 
186 void
188 
189 
193 struct GNUNET_CURL_Job;
194 
202 typedef void
204  long response_code,
205  const void *response);
206 
207 
216 typedef void
218  long response_code,
219  const void *body,
220  size_t body_size);
221 
222 
239 struct GNUNET_CURL_Job *
241  CURL *eh,
242  int add_json,
244  void *jcc_cls);
245 
246 
263 struct GNUNET_CURL_Job *
265  CURL *eh,
266  const struct curl_slist *job_headers,
268  void *jcc_cls);
269 
270 
286 struct GNUNET_CURL_Job *
288  CURL *eh,
289  const struct curl_slist *job_headers,
291  void *jcc_cls);
292 
293 
300 void
302 
303 
304 /* ******* GNUnet SCHEDULER integration ************ */
305 
306 
311 
312 
321 
332 
333 
339 void
341 
342 
352 void
354 
355 
362 void
364  char *header_name);
365 
366 
367 #endif
368  /* end of group */
369 
370 /* end of gnunet_curl_lib.h */
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.
Definition: curl.c:421
int GNUNET_CURL_append_header(struct GNUNET_CURL_Context *ctx, const char *header)
Add custom request header.
Definition: curl.c:604
void GNUNET_CURL_fini(struct GNUNET_CURL_Context *ctx)
Cleanup library initialisation resources.
Definition: curl.c:827
GNUNET_CURL_RescheduleCallback cb
Function we need to call whenever the event loop&#39;s socket set changed.
Definition: curl.c:166
void(* GNUNET_CURL_JobCompletionCallback)(void *cls, long response_code, const void *response)
Function to call upon completion of a job.
void GNUNET_CURL_job_cancel(struct GNUNET_CURL_Job *job)
Cancel a job.
Definition: curl.c:491
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
void GNUNET_CURL_gnunet_scheduler_reschedule(void *cls)
Implementation of the GNUNET_CURL_RescheduleCallback for GNUnet&#39;s scheduler.
void * jcc_cls
Closure for jcc.
Definition: curl.c:101
Closure for GNUNET_CURL_gnunet_scheduler_reschedule().
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.
Definition: curl.c:378
void *(* GNUNET_CURL_RawParser)(struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
Parses the raw response we got from the Web server.
GNUNET_CURL_JobCompletionCallback jcc
Function to call upon completion.
Definition: curl.c:96
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
Context.
Definition: curl.c:129
void(* GNUNET_CURL_ResponseCleaner)(void *response)
Deallocate the response.
static struct GNUNET_SCHEDULER_Task * job
Task for main job.
Definition: gnunet-cadet.c:137
struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create_with_parser(struct GNUNET_CURL_Context *ctx, GNUNET_CURL_RawParser rp, GNUNET_CURL_ResponseCleaner rc)
Initialize reschedule context; with custom response parser.
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...
Definition: curl.c:790
void GNUNET_CURL_gnunet_rc_destroy(struct GNUNET_CURL_RescheduleContext *rc)
Destroy reschedule context.
Buffer data structure we use to buffer the HTTP download before giving it to the JSON parser...
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:41
void GNUNET_CURL_perform(struct GNUNET_CURL_Context *ctx)
Run the main event loop for the CURL interaction.
Definition: curl.c:753
void * buf
Download buffer.
void(* GNUNET_CURL_RescheduleCallback)(void *cls)
Function called by the context to ask for the event loop to be rescheduled, that is the application s...
void * cb_cls
Closure for cb.
Definition: curl.c:171
Jobs are CURL requests running within a struct GNUNET_CURL_Context.
Definition: curl.c:71
struct GNUNET_CURL_Context * GNUNET_CURL_init(GNUNET_CURL_RescheduleCallback cb, void *cb_cls)
Initialise this library.
Definition: curl.c:184
static char * rp
Relying party.
static struct MHD_Response * response
Our canonical response.
void(* GNUNET_CURL_RawJobCompletionCallback)(void *cls, long response_code, const void *body, size_t body_size)
Function to call upon completion of a raw job.
struct GNUNET_CURL_Job * GNUNET_CURL_job_add(struct GNUNET_CURL_Context *ctx, CURL *eh, int add_json, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls)
Schedule a CURL request to be executed and call the given jcc upon its completion.
Definition: curl.c:462
size_t buf_size
The size of the download buffer.
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.
Definition: curl.c:693
struct curl_slist * job_headers
Headers used for this job, the list needs to be freed after the job has finished. ...
Definition: curl.c:122
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.
Definition: curl.c:223
struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create(struct GNUNET_CURL_Context *ctx)
Initialize reschedule context.
int eno
Error code (based on libc errno) if we failed to download (i.e.