GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
plugin_rest_gns.c File Reference

GNUnet Gns REST plugin. More...

#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_rest_lib.h"
#include "gnunet_json_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gns_service.h"
#include "microhttpd.h"
#include <jansson.h>
Include dependency graph for plugin_rest_gns.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  RequestHandle
 The request handle. More...
 

Macros

#define GNUNET_REST_API_NS_GNS   "/gns"
 Rest API GNS Namespace. More...
 
#define GNUNET_REST_GNS_PARAM_RECORD_TYPE   "record_type"
 Rest API GNS Parameter record_type. More...
 
#define GNUNET_REST_GNS_ERROR_UNKNOWN   "Unknown Error"
 Rest API GNS ERROR Unknown Error. More...
 
#define GNUNET_REST_GNS_NOT_FOUND   "Record not found"
 Rest API GNS ERROR Record not found. More...
 

Functions

static void cleanup_handle (void *cls)
 Cleanup lookup handle. More...
 
static void do_error (void *cls)
 Task run on errors. More...
 
static void do_timeout (void *cls)
 
static void handle_gns_response (void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Iterator called on obtained result for a GNS lookup. More...
 
void get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle gns GET request. More...
 
static void options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Respond to OPTIONS request. More...
 
static void init_cont (struct RequestHandle *handle)
 Handle rest request. More...
 
static void rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
 Function processing the REST call. More...
 
void * libgnunet_plugin_rest_gns_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_rest_gns_done (void *cls)
 Exit point from the plugin. More...
 

Variables

const struct GNUNET_CONFIGURATION_Handlecfg
 The configuration handle. More...
 
static char * allow_methods
 HTTP methods allows for this plugin. More...
 

Detailed Description

GNUnet Gns REST plugin.

Author
Philippe Buschmann

Definition in file plugin_rest_gns.c.

Macro Definition Documentation

◆ GNUNET_REST_API_NS_GNS

#define GNUNET_REST_API_NS_GNS   "/gns"

Rest API GNS Namespace.

Definition at line 38 of file plugin_rest_gns.c.

Referenced by get_gns_cont(), init_cont(), and libgnunet_plugin_rest_gns_init().

◆ GNUNET_REST_GNS_PARAM_RECORD_TYPE

#define GNUNET_REST_GNS_PARAM_RECORD_TYPE   "record_type"

Rest API GNS Parameter record_type.

Definition at line 43 of file plugin_rest_gns.c.

Referenced by get_gns_cont().

◆ GNUNET_REST_GNS_ERROR_UNKNOWN

#define GNUNET_REST_GNS_ERROR_UNKNOWN   "Unknown Error"

Rest API GNS ERROR Unknown Error.

Definition at line 48 of file plugin_rest_gns.c.

Referenced by do_error().

◆ GNUNET_REST_GNS_NOT_FOUND

#define GNUNET_REST_GNS_NOT_FOUND   "Record not found"

Rest API GNS ERROR Record not found.

Definition at line 53 of file plugin_rest_gns.c.

Referenced by get_gns_cont(), and handle_gns_response().

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
handleHandle to clean up

Definition at line 146 of file plugin_rest_gns.c.

References RequestHandle::emsg, RequestHandle::gns, RequestHandle::gns_lookup, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNS_disconnect(), GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_log, GNUNET_SCHEDULER_cancel(), handle, RequestHandle::name, RequestHandle::timeout_task, and RequestHandle::url.

Referenced by do_error(), handle_gns_response(), and options_cont().

147 {
148  struct RequestHandle *handle = cls;
149  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
150 
151  if (NULL != handle->gns_lookup)
152  {
154  handle->gns_lookup = NULL;
155  }
156  if (NULL != handle->gns)
157  {
158  GNUNET_GNS_disconnect (handle->gns);
159  handle->gns = NULL;
160  }
161 
162  if (NULL != handle->timeout_task)
163  {
165  handle->timeout_task = NULL;
166  }
167  if (NULL != handle->url)
168  GNUNET_free (handle->url);
169  if (NULL != handle->name)
170  GNUNET_free (handle->name);
171  if (NULL != handle->emsg)
172  GNUNET_free (handle->emsg);
173 
174  GNUNET_free (handle);
175 }
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:330
The request handle.
char * name
Name to look up.
char * emsg
Error response message.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:285
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_GNS_LookupWithTldRequest * gns_lookup
Active GNS lookup.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
struct GNUNET_GNS_Handle * gns
Connection to GNS.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_error()

static void do_error ( void *  cls)
static

Task run on errors.

Reports an error and cleans up everything.

Parameters
clsthe struct RequestHandle

Definition at line 184 of file plugin_rest_gns.c.

References cleanup_handle(), RequestHandle::emsg, GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_GNS_ERROR_UNKNOWN, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_strdup, handle, RequestHandle::proc, RequestHandle::proc_cls, response, RequestHandle::response_code, and RequestHandle::timeout_task.

Referenced by do_timeout(), get_gns_cont(), handle_gns_response(), and init_cont().

185 {
186  struct RequestHandle *handle = cls;
187  struct MHD_Response *resp;
188  json_t *json_error = json_object ();
189  char *response;
190 
191  if (NULL != handle->timeout_task)
193  handle->timeout_task = NULL;
194  if (NULL == handle->emsg)
196 
197  json_object_set_new (json_error, "error", json_string (handle->emsg));
198 
199  if (0 == handle->response_code)
200  handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
201  response = json_dumps (json_error, 0);
202  resp = GNUNET_REST_create_response (response);
203  handle->proc (handle->proc_cls, resp, handle->response_code);
204  json_decref (json_error);
205  GNUNET_free (response);
207 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
The request handle.
char * emsg
Error response message.
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:1273
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
int response_code
HTTP response code.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
#define GNUNET_REST_GNS_ERROR_UNKNOWN
Rest API GNS ERROR Unknown Error.
static struct MHD_Response * response
Our canonical response.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Definition at line 211 of file plugin_rest_gns.c.

References do_error(), handle, RequestHandle::response_code, and RequestHandle::timeout_task.

Referenced by rest_process_request().

212 {
213  struct RequestHandle *handle = cls;
214  handle->timeout_task = NULL;
215  handle->response_code = MHD_HTTP_REQUEST_TIMEOUT;
216  do_error (handle);
217 }
The request handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
HTTP response code.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_gns_response()

static void handle_gns_response ( void *  cls,
int  was_gns,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Iterator called on obtained result for a GNS lookup.

Parameters
clsclosure with the object
was_gnsGNUNET_NO if name was not a GNS name
rd_countnumber of records in rd
rdthe records in reply

Definition at line 229 of file plugin_rest_gns.c.

References cleanup_handle(), do_error(), RequestHandle::emsg, RequestHandle::gns_lookup, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_JSON_from_gnsrecord(), GNUNET_log, GNUNET_NO, GNUNET_REST_create_response(), GNUNET_REST_GNS_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::name, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, and result.

Referenced by get_gns_cont().

233 {
234  struct RequestHandle *handle = cls;
235  struct MHD_Response *resp;
236  json_t *result_obj;
237  char *result;
238 
239  handle->gns_lookup = NULL;
240 
241  if (GNUNET_NO == was_gns)
242  {
243  handle->response_code = MHD_HTTP_NOT_FOUND;
246  return;
247  }
248 
249  result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count);
250 
251  result = json_dumps (result_obj, 0);
252  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
253  resp = GNUNET_REST_create_response (result);
254  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
255  GNUNET_free (result);
256  json_decref (result_obj);
258 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
The request handle.
#define GNUNET_REST_GNS_NOT_FOUND
Rest API GNS ERROR Record not found.
char * name
Name to look up.
char * emsg
Error response message.
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:1273
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
json_t * GNUNET_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert Gns record to JSON.
int response_code
HTTP response code.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_GNS_LookupWithTldRequest * gns_lookup
Active GNS lookup.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_gns_cont()

void get_gns_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)

Handle gns GET request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 269 of file plugin_rest_gns.c.

References do_error(), RequestHandle::emsg, RequestHandle::gns, RequestHandle::gns_lookup, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_GNS_lookup_with_tld(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_NO, GNUNET_REST_API_NS_GNS, GNUNET_REST_GNS_NOT_FOUND, GNUNET_REST_GNS_PARAM_RECORD_TYPE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, handle, handle_gns_response(), RequestHandle::name, Plugin::name, RequestHandle::record_type, RequestHandle::response_code, RequestHandle::url, and GNUNET_REST_RequestHandle::url_param_map.

Referenced by init_cont().

272 {
273  struct RequestHandle *handle = cls;
274  struct GNUNET_HashCode key;
275  char *record_type;
276  char *name;
277 
278  name = NULL;
279  handle->name = NULL;
280  if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
281  {
282  name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
283  }
284 
285  if (NULL == name)
286  {
287  handle->response_code = MHD_HTTP_NOT_FOUND;
290  return;
291  }
292  if (0 >= strlen (name))
293  {
294  handle->response_code = MHD_HTTP_NOT_FOUND;
297  return;
298  }
299  handle->name = GNUNET_strdup (name);
300 
301  handle->record_type = UINT32_MAX;
304  &key);
305  if (GNUNET_YES ==
307  {
308  record_type =
310  handle->record_type = GNUNET_GNSRECORD_typename_to_number (record_type);
311  }
312 
313  if (UINT32_MAX == handle->record_type)
314  {
316  }
317 
318  handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
319  handle->name,
320  handle->record_type,
321  GNUNET_NO,
323  handle);
324 }
int record_type
Record type to look up.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (i.e.
Definition: gnsrecord.c:204
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
static void handle_gns_response(void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Iterator called on obtained result for a GNS lookup.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
Definition: gns_tld_api.c:242
#define GNUNET_NO
Definition: gnunet_common.h:81
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_REST_GNS_NOT_FOUND
Rest API GNS ERROR Record not found.
char * name
Name to look up.
#define GNUNET_REST_GNS_PARAM_RECORD_TYPE
Rest API GNS Parameter record_type.
char * emsg
Error response message.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
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:1273
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
int response_code
HTTP response code.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_HashCode key
The key used in the DHT.
const char * name
struct GNUNET_GNS_LookupWithTldRequest * gns_lookup
Active GNS lookup.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_REST_API_NS_GNS
Rest API GNS Namespace.
struct GNUNET_GNS_Handle * gns
Connection to GNS.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ options_cont()

static void options_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Respond to OPTIONS request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 335 of file plugin_rest_gns.c.

References allow_methods, cleanup_handle(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by init_cont().

338 {
339  struct MHD_Response *resp;
340  struct RequestHandle *handle = cls;
341 
342  //independent of path return all options
343  resp = GNUNET_REST_create_response (NULL);
344  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
345  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
347  return;
348 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
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:1273
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
static char * allow_methods
HTTP methods allows for this plugin.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_cont()

static void init_cont ( struct RequestHandle handle)
static

Handle rest request.

Parameters
handlethe request handle

Definition at line 357 of file plugin_rest_gns.c.

References do_error(), GNUNET_REST_RequestHandlerError::error_code, get_gns_cont(), GNUNET_NO, GNUNET_REST_API_NS_GNS, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_now(), options_cont(), RequestHandle::response_code, and RequestHandle::rest_handle.

Referenced by rest_process_request().

358 {
360  static const struct GNUNET_REST_RequestHandler handlers[] =
361  {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
362  {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
364 
365  if (GNUNET_NO ==
366  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
367  {
368  handle->response_code = err.error_code;
370  }
371 }
#define GNUNET_NO
Definition: gnunet_common.h:81
void get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle gns GET request.
#define GNUNET_REST_HANDLER_END
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1273
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
Definition: rest.c:76
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
int response_code
HTTP response code.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_API_NS_GNS
Rest API GNS Namespace.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rest_process_request()

static void rest_process_request ( struct GNUNET_REST_RequestHandle rest_handle,
GNUNET_REST_ResultProcessor  proc,
void *  proc_cls 
)
static

Function processing the REST call.

Parameters
methodHTTP method
urlURL of the HTTP request
databody of the HTTP request (optional)
data_sizelength of the body
proccallback function for the result
proc_clsclosure for callback function
Returns
GNUNET_OK if request accepted

Definition at line 386 of file plugin_rest_gns.c.

References do_timeout(), RequestHandle::gns, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNS_connect(), GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, handle, init_cont(), RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, RequestHandle::rest_handle, RequestHandle::timeout, RequestHandle::timeout_task, GNUNET_REST_RequestHandle::url, and RequestHandle::url.

Referenced by libgnunet_plugin_rest_gns_init().

389 {
390  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
391 
392  handle->response_code = 0;
393  handle->timeout =
395  handle->proc_cls = proc_cls;
396  handle->proc = proc;
397  handle->rest_handle = rest_handle;
398 
399  handle->url = GNUNET_strdup (rest_handle->url);
400  if (handle->url[strlen (handle->url) - 1] == '/')
401  handle->url[strlen (handle->url) - 1] = '\0';
402  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
403  handle->gns = GNUNET_GNS_connect (cfg);
404  init_cont (handle);
405 
406  handle->timeout_task =
407  GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
408 
409  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
410 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void init_cont(struct RequestHandle *handle)
Handle rest request.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
The request handle.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
const char * url
The url as string.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
struct GNUNET_TIME_Relative timeout
Timeout.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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:439
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:263
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
int response_code
HTTP response code.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
struct GNUNET_GNS_Handle * gns
Connection to GNS.
static void do_timeout(void *cls)
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_rest_gns_init()

void* libgnunet_plugin_rest_gns_init ( void *  cls)

Entry point for the plugin.

Parameters
clsConfig info
Returns
NULL on error, otherwise the plugin context

Definition at line 420 of file plugin_rest_gns.c.

References _, allow_methods, Plugin::api, Plugin::cfg, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_GNS, GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, and rest_process_request().

421 {
422  static struct Plugin plugin;
423  struct GNUNET_REST_Plugin *api;
424 
425  cfg = cls;
426  if (NULL != plugin.cfg)
427  return NULL; /* can only initialize once! */
428  memset (&plugin, 0, sizeof (struct Plugin));
429  plugin.cfg = cfg;
430  api = GNUNET_new (struct GNUNET_REST_Plugin);
431  api->cls = &plugin;
435  "%s, %s, %s, %s, %s",
436  MHD_HTTP_METHOD_GET,
437  MHD_HTTP_METHOD_POST,
438  MHD_HTTP_METHOD_PUT,
439  MHD_HTTP_METHOD_DELETE,
440  MHD_HTTP_METHOD_OPTIONS);
441 
442  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n"));
443  return api;
444 }
static void rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
void * cls
The closure of the plugin.
struct returned by the initialization function of the plugin
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * name
Plugin name.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_REST_API_NS_GNS
Rest API GNS Namespace.
static char * allow_methods
HTTP methods allows for this plugin.
Here is the call graph for this function:

◆ libgnunet_plugin_rest_gns_done()

void* libgnunet_plugin_rest_gns_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 454 of file plugin_rest_gns.c.

References allow_methods, Plugin::api, Plugin::cfg, GNUNET_REST_Plugin::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_log, and plugin.

455 {
456  struct GNUNET_REST_Plugin *api = cls;
457  struct Plugin *plugin = api->cls;
458  plugin->cfg = NULL;
459 
461  GNUNET_free (api);
462  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Gns REST plugin is finished\n");
463  return NULL;
464 }
void * cls
The closure of the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct returned by the initialization function of the plugin
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
static char * allow_methods
HTTP methods allows for this plugin.

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

The configuration handle.

Handle to our configuration.

Definition at line 58 of file plugin_rest_gns.c.

◆ allow_methods

char* allow_methods
static

HTTP methods allows for this plugin.

Definition at line 63 of file plugin_rest_gns.c.

Referenced by libgnunet_plugin_rest_gns_done(), libgnunet_plugin_rest_gns_init(), and options_cont().