GNUnet  0.17.6
Data Structures | Functions
curl_reschedule.c File Reference

API for event loop integration with GNUnet SCHEDULER. More...

#include "platform.h"
#include <jansson.h>
#include "gnunet_curl_lib.h"
#include "gnunet_util_lib.h"
Include dependency graph for curl_reschedule.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CURL_RescheduleContext
 Closure for GNUNET_CURL_gnunet_scheduler_reschedule(). More...


void * GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
struct GNUNET_CURL_RescheduleContextGNUNET_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. More...
static void clean_result (void *response)
 Just a wrapper to avoid casting of function pointers. More...
struct GNUNET_CURL_RescheduleContextGNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx)
 Initialize reschedule context. More...
void GNUNET_CURL_gnunet_rc_destroy (struct GNUNET_CURL_RescheduleContext *rc)
 Destroy reschedule context. More...
static void context_task (void *cls)
 Task that runs the context's event loop with the GNUnet scheduler. More...
void GNUNET_CURL_gnunet_scheduler_reschedule (void *cls)
 Implementation of the GNUNET_CURL_RescheduleCallback for GNUnet's scheduler. More...

Detailed Description

API for event loop integration with GNUnet SCHEDULER.

Christian Grothoff

Definition in file curl_reschedule.c.

Function Documentation

◆ GNUNET_CURL_download_get_result_()

void* GNUNET_CURL_download_get_result_ ( struct GNUNET_CURL_DownloadBuffer db,
CURL *  eh,
long *  response_code 

Definition at line 639 of file curl.c.

642 {
643  json_t *json;
644  json_error_t error;
645  char *ct;
648  "Downloaded body: %.*s\n",
649  (int) db->buf_size,
650  (char *) db->buf);
651  if (CURLE_OK !=
652  curl_easy_getinfo (eh,
654  response_code))
655  {
656  /* unexpected error... */
657  GNUNET_break (0);
658  *response_code = 0;
659  }
660  if ((CURLE_OK !=
661  curl_easy_getinfo (eh,
663  &ct)) ||
664  (NULL == ct) ||
665  (! is_json (ct)))
666  {
667  /* No content type or explicitly not JSON, refuse to parse
668  (but keep response code) */
669  if (0 != db->buf_size)
671  "Did NOT detect response `%.*s' as JSON\n",
672  (int) db->buf_size,
673  (const char *) db->buf);
674  return NULL;
675  }
676  if (MHD_HTTP_NO_CONTENT == *response_code)
677  return NULL;
678  if (0 == *response_code)
679  {
680  char *url;
682  if (CURLE_OK !=
683  curl_easy_getinfo (eh,
685  &url))
686  url = "<unknown URL>";
688  "Failed to download response from `%s': \n",
689  url);
690  return NULL;
691  }
692  json = NULL;
693  if (0 == db->eno)
694  {
695  json = json_loadb (db->buf,
696  db->buf_size,
698  &error);
699  if (NULL == json)
700  {
701  JSON_WARN (error);
702  *response_code = 0;
703  }
704  }
705  GNUNET_free (db->buf);
706  db->buf = NULL;
707  db->buf_size = 0;
708  return json;
709 }
static bool is_json(const char *ct)
Test if the given content type ct is JSON.
Definition: curl.c:611
#define JSON_WARN(error)
Print JSON parsing related error information.
Definition: curl.c:54
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:94
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.

Referenced by GNUNET_CURL_gnunet_rc_create(), and GNUNET_CURL_perform().

Here is the caller graph for this function:

◆ clean_result()

static void clean_result ( void *  response)

Just a wrapper to avoid casting of function pointers.

responsethe (JSON) response to clean.

Definition at line 84 of file curl_reschedule.c.

85 {
86  json_decref (response);
87 }
static struct MHD_Response * response
Our canonical response.

References response.

Referenced by GNUNET_CURL_gnunet_rc_create().

Here is the caller graph for this function:

◆ context_task()

static void context_task ( void *  cls)

Task that runs the context's event loop with the GNUnet scheduler.

clsa struct GNUNET_CURL_RescheduleContext *

Definition at line 118 of file curl_reschedule.c.

119 {
120  struct GNUNET_CURL_RescheduleContext *rc = cls;
121  long timeout;
122  int max_fd;
123  fd_set read_fd_set;
124  fd_set write_fd_set;
125  fd_set except_fd_set;
126  struct GNUNET_NETWORK_FDSet *rs;
127  struct GNUNET_NETWORK_FDSet *ws;
130  rc->task = NULL;
131  GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner);
132  max_fd = -1;
133  timeout = -1;
134  FD_ZERO (&read_fd_set);
135  FD_ZERO (&write_fd_set);
136  FD_ZERO (&except_fd_set);
138  &read_fd_set,
139  &write_fd_set,
140  &except_fd_set,
141  &max_fd,
142  &timeout);
143  if (timeout >= 0)
144  delay =
146  timeout);
147  else
151  &read_fd_set,
152  max_fd + 1);
155  &write_fd_set,
156  max_fd + 1);
157  if (NULL == rc->task)
159  delay,
160  rs,
161  ws,
162  &context_task,
163  rc);
166 }
static void context_task(void *cls)
Task that runs the context's event loop with the GNUnet scheduler.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
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:789
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:726
Run with the default priority (normal P2P operations).
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1193
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1209
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:1063
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:1826
Constant used to specify "forever".
One millisecond.
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:483
Closure for GNUNET_CURL_gnunet_scheduler_reschedule().
struct GNUNET_SCHEDULER_Task * task
Just the task.
GNUNET_CURL_RawParser parser
Parser of the raw response.
struct GNUNET_CURL_Context * ctx
Context we manage.
GNUNET_CURL_ResponseCleaner cleaner
Deallocate the response object.
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

References GNUNET_CURL_RescheduleContext::cleaner, GNUNET_CURL_RescheduleContext::ctx, delay, GNUNET_CURL_get_select_info(), GNUNET_CURL_perform2(), GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_CURL_RescheduleContext::parser, GNUNET_CURL_RescheduleContext::task, and timeout.

Referenced by GNUNET_CURL_gnunet_scheduler_reschedule().

Here is the call graph for this function:
Here is the caller graph for this function: