GNUnet  0.10.x
curl_reschedule.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 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  */
25 #include "platform.h"
26 #include <jansson.h>
27 #include "gnunet_curl_lib.h"
28 #include "gnunet_util_lib.h"
29 
30 extern void *
32  CURL *eh,
33  long *response_code);
34 
39 {
44 
49 
54 
59 };
60 
61 
72 {
73  struct GNUNET_CURL_RescheduleContext *rctx;
74 
76  rctx->ctx = ctx;
77  rctx->parser = rp;
78  rctx->cleaner = rc;
79 
80  return rctx;
81 }
82 
83 
89 static void
91 {
92  json_decref (response);
93 }
94 
95 
104 {
106 
108  rc->ctx = ctx;
110  rc->cleaner = &clean_result;
111  return rc;
112 }
113 
114 
120 void
122 {
123  if (NULL != rc->task)
125  GNUNET_free (rc);
126 }
127 
128 
134 static void
135 context_task (void *cls)
136 {
137  struct GNUNET_CURL_RescheduleContext *rc = cls;
138  long timeout;
139  int max_fd;
140  fd_set read_fd_set;
141  fd_set write_fd_set;
142  fd_set except_fd_set;
143  struct GNUNET_NETWORK_FDSet *rs;
144  struct GNUNET_NETWORK_FDSet *ws;
145  struct GNUNET_TIME_Relative delay;
146 
147  rc->task = NULL;
148  GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner);
149  max_fd = -1;
150  timeout = -1;
151  FD_ZERO (&read_fd_set);
152  FD_ZERO (&write_fd_set);
153  FD_ZERO (&except_fd_set);
155  &read_fd_set,
156  &write_fd_set,
157  &except_fd_set,
158  &max_fd,
159  &timeout);
160  if (timeout >= 0)
161  delay =
163  else
166  GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, max_fd + 1);
168  GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, max_fd + 1);
169  if (NULL == rc->task)
171  delay,
172  rs,
173  ws,
174  &context_task,
175  rc);
178 }
179 
180 
190 void
192 {
193  struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls;
194 
195  if (NULL != rc->task)
198 }
199 
200 /* end of curl_reschedule.c */
library to make it easy to download JSON replies over HTTP
struct GNUNET_CURL_Context * ctx
Context we manage.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_CURL_ResponseCleaner cleaner
Deallocate the response object.
GNUNET_CURL_RawParser parser
Parser of the raw response.
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1108
void GNUNET_CURL_gnunet_scheduler_reschedule(void *cls)
Implementation of the GNUNET_CURL_RescheduleCallback for GNUnet&#39;s scheduler.
Closure for GNUNET_CURL_gnunet_scheduler_reschedule().
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1254
void *(* GNUNET_CURL_RawParser)(struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
Parses the raw response we got from the Web server.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1238
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1784
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void clean_result(void *response)
Just a wrapper to avoid casting of function pointers.
Context.
Definition: curl.c:119
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
void(* GNUNET_CURL_ResponseCleaner)(void *response)
Deallocate the response.
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.
struct GNUNET_SCHEDULER_Task * task
Just the task.
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:658
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
Entry in list of pending tasks.
Definition: scheduler.c:131
static char * rp
Relying party.
static struct MHD_Response * response
Our canonical response.
void * GNUNET_CURL_download_get_result_(struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
Obtain information about the final result about the HTTP download.
Definition: curl.c:433
void GNUNET_CURL_perform2(struct GNUNET_CURL_Context *ctx, GNUNET_CURL_RawParser rp, GNUNET_CURL_ResponseCleaner rc)
Run the main event loop for the Taler interaction.
Definition: curl.c:520
Run with the default priority (normal P2P operations).
static void context_task(void *cls)
Task that runs the context&#39;s event loop with the GNUnet scheduler.
struct GNUNET_CURL_RescheduleContext * GNUNET_CURL_gnunet_rc_create(struct GNUNET_CURL_Context *ctx)
Initialize reschedule context.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956