GNUnet  0.11.x
Data Structures | Macros | Enumerations | Functions | Variables
plugin_rest_namestore.c File Reference

GNUnet Namestore REST plugin. More...

#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_gns_service.h"
#include "gnunet_namestore_service.h"
#include "gnunet_identity_service.h"
#include "gnunet_rest_lib.h"
#include "gnunet_gnsrecord_json_lib.h"
#include "microhttpd.h"
#include <jansson.h>
Include dependency graph for plugin_rest_namestore.c:

Go to the source code of this file.

Data Structures

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

Macros

#define GNUNET_REST_API_NS_NAMESTORE   "/namestore"
 Namestore Namespace. More...
 
#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN   "Unknown Error"
 Error message Unknown Error. More...
 
#define GNUNET_REST_IDENTITY_NOT_FOUND   "No identity found"
 Error message No identity found. More...
 
#define GNUNET_REST_NAMESTORE_FAILED   "Namestore action failed"
 Error message Failed request. More...
 
#define GNUNET_REST_NAMESTORE_INVALID_DATA   "Data invalid"
 Error message invalid data. More...
 
#define GNUNET_REST_NAMESTORE_NO_DATA   "No data"
 Error message No data. More...
 
#define ID_REST_STATE_INIT   0
 State while collecting all egos. More...
 
#define ID_REST_STATE_POST_INIT   1
 Done collecting egos. More...
 

Enumerations

enum  UpdateStrategy { UPDATE_STRATEGY_REPLACE, UPDATE_STRATEGY_APPEND }
 

Functions

static void cleanup_handle (void *cls)
 Cleanup lookup handle. More...
 
static void do_error (void *cls)
 Task run on errors. More...
 
struct EgoEntryget_egoentry_namestore (struct RequestHandle *handle, char *name)
 Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first. More...
 
static void namestore_iteration_error (void *cls)
 Does internal server error when iteration failed. More...
 
static void create_finished (void *cls, int32_t success, const char *emsg)
 Create finished callback. More...
 
static void del_finished (void *cls, int32_t success, const char *emsg)
 Delete finished callback. More...
 
static void namestore_list_finished (void *cls)
 Iteration over all results finished, build final response. More...
 
static void namestore_list_iteration (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
 Create a response with requested records. More...
 
static void ns_lookup_error_cb (void *cls)
 Handle lookup error. More...
 
static void ns_get_lookup_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
 
void namestore_get (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore GET request. More...
 
static void ns_lookup_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 
void namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore POST/PUT request. More...
 
void namestore_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore PUT request. More...
 
void namestore_add (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore POST request. More...
 
void namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore DELETE request. More...
 
static void options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Respond to OPTIONS request. More...
 
static void list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
 
static enum GNUNET_GenericReturnValue 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_namestore_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_rest_namestore_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...
 
static struct EgoEntryego_head
 Ego list. More...
 
static struct EgoEntryego_tail
 Ego list. More...
 
static int state
 The processing state. More...
 
static struct GNUNET_NAMESTORE_Handlens_handle
 Handle to NAMESTORE. More...
 
static struct GNUNET_IDENTITY_Handleidentity_handle
 Handle to Identity service. More...
 
static struct RequestHandlerequests_head
 DLL. More...
 
static struct RequestHandlerequests_tail
 DLL. More...
 

Detailed Description

GNUnet Namestore REST plugin.

Author
Martin Schanzenbach
Philippe Buschmann

Definition in file plugin_rest_namestore.c.

Macro Definition Documentation

◆ GNUNET_REST_API_NS_NAMESTORE

#define GNUNET_REST_API_NS_NAMESTORE   "/namestore"

◆ GNUNET_REST_NAMESTORE_ERROR_UNKNOWN

#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN   "Unknown Error"

Error message Unknown Error.

Definition at line 45 of file plugin_rest_namestore.c.

Referenced by do_error().

◆ GNUNET_REST_IDENTITY_NOT_FOUND

#define GNUNET_REST_IDENTITY_NOT_FOUND   "No identity found"

Error message No identity found.

Definition at line 50 of file plugin_rest_namestore.c.

Referenced by namestore_add_or_update(), namestore_delete(), and namestore_get().

◆ GNUNET_REST_NAMESTORE_FAILED

#define GNUNET_REST_NAMESTORE_FAILED   "Namestore action failed"

◆ GNUNET_REST_NAMESTORE_INVALID_DATA

#define GNUNET_REST_NAMESTORE_INVALID_DATA   "Data invalid"

Error message invalid data.

Definition at line 61 of file plugin_rest_namestore.c.

Referenced by namestore_add_or_update().

◆ GNUNET_REST_NAMESTORE_NO_DATA

#define GNUNET_REST_NAMESTORE_NO_DATA   "No data"

Error message No data.

Definition at line 66 of file plugin_rest_namestore.c.

Referenced by namestore_add_or_update().

◆ ID_REST_STATE_INIT

#define ID_REST_STATE_INIT   0

State while collecting all egos.

Definition at line 71 of file plugin_rest_namestore.c.

Referenced by libgnunet_plugin_rest_namestore_init(), and list_ego().

◆ ID_REST_STATE_POST_INIT

#define ID_REST_STATE_POST_INIT   1

Done collecting egos.

Definition at line 76 of file plugin_rest_namestore.c.

Referenced by list_ego().

Enumeration Type Documentation

◆ UpdateStrategy

Enumerator
UPDATE_STRATEGY_REPLACE 
UPDATE_STRATEGY_APPEND 

Definition at line 152 of file plugin_rest_namestore.c.

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
handleHandle to clean up

Definition at line 286 of file plugin_rest_namestore.c.

References GNUNET_GNSRECORD_Data::data, RequestHandle::emsg, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_nz, GNUNET_log, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, RequestHandle::list_it, RequestHandle::ns_qe, RequestHandle::rd, RequestHandle::rd_count, RequestHandle::record_name, RequestHandle::resp_object, RequestHandle::timeout_task, and RequestHandle::url.

Referenced by create_finished(), del_finished(), do_error(), namestore_list_finished(), options_cont(), and rest_process_request().

287 {
288  struct RequestHandle *handle = cls;
289 
290  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
291  if (NULL != handle->timeout_task)
292  {
294  handle->timeout_task = NULL;
295  }
296  if (NULL != handle->record_name)
297  GNUNET_free (handle->record_name);
298  if (NULL != handle->url)
299  GNUNET_free (handle->url);
300  if (NULL != handle->emsg)
301  GNUNET_free (handle->emsg);
302  if (NULL != handle->rd)
303  {
304  for (int i = 0; i < handle->rd_count; i++)
305  {
306  if (NULL != handle->rd[i].data)
307  GNUNET_free_nz ((void *) handle->rd[i].data);
308  }
309  GNUNET_free (handle->rd);
310  }
311  if (NULL != handle->timeout_task)
313  if (NULL != handle->list_it)
315  if (NULL != handle->ns_qe)
316  GNUNET_NAMESTORE_cancel (handle->ns_qe);
317 
318  if (NULL != handle->resp_object)
319  {
320  json_decref (handle->resp_object);
321  }
324  handle);
325  GNUNET_free (handle);
326 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
The request handle.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
static struct RequestHandle * requests_head
DLL.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
char * record_name
Records to store.
json_t * resp_object
Response object.
const void * data
Binary value stored in the DNS record.
char * emsg
Error response message.
unsigned int rd_count
Number of records in rd.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
struct GNUNET_GNSRECORD_Data * rd
Records to store.
static struct RequestHandle * requests_tail
DLL.
#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:972
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 335 of file plugin_rest_namestore.c.

References cleanup_handle(), RequestHandle::emsg, GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_NAMESTORE_ERROR_UNKNOWN, GNUNET_strdup, handle, RequestHandle::proc, RequestHandle::proc_cls, response, and RequestHandle::response_code.

Referenced by create_finished(), del_finished(), libgnunet_plugin_rest_namestore_done(), namestore_add_or_update(), namestore_delete(), namestore_get(), namestore_iteration_error(), ns_lookup_cb(), ns_lookup_error_cb(), and rest_process_request().

336 {
337  struct RequestHandle *handle = cls;
338  struct MHD_Response *resp;
339  json_t *json_error = json_object ();
340  char *response;
341 
342  if (NULL == handle->emsg)
344 
345  json_object_set_new (json_error, "error", json_string (handle->emsg));
346 
347  if (0 == handle->response_code)
348  handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
349  response = json_dumps (json_error, 0);
350  resp = GNUNET_REST_create_response (response);
351  MHD_add_response_header (resp, "Content-Type", "application/json");
352  handle->proc (handle->proc_cls, resp, handle->response_code);
353  json_decref (json_error);
354  GNUNET_free (response);
355  cleanup_handle (handle);
356 }
#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN
Error message Unknown Error.
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.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
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:57
static struct MHD_Response * response
Our canonical response.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_egoentry_namestore()

struct EgoEntry* get_egoentry_namestore ( struct RequestHandle handle,
char *  name 
)

Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first.

Parameters
handlethe RequestHandle
pubkeythe public key of an identity (only one can be NULL)
namethe name of an identity (only one can be NULL)
Returns
EgoEntry or NULL if not found

Definition at line 369 of file plugin_rest_namestore.c.

References GNUNET_free, GNUNET_strdup, EgoEntry::identifier, and EgoEntry::next.

Referenced by namestore_add_or_update(), namestore_delete(), and namestore_get().

370 {
371  struct EgoEntry *ego_entry;
372  char *copy = GNUNET_strdup (name);
373  char *tmp;
374 
375  if (NULL == name)
376  return NULL;
377  tmp = strtok (copy, "/");
378  if (NULL == tmp)
379  return NULL;
380  for (ego_entry = ego_head; NULL != ego_entry;
381  ego_entry = ego_entry->next)
382  {
383  if (0 != strcasecmp (tmp, ego_entry->identifier))
384  continue;
385  GNUNET_free (copy);
386  return ego_entry;
387  }
388  GNUNET_free (copy);
389  return NULL;
390 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The ego list.
static struct EgoEntry * ego_head
Ego list.
char * identifier
Ego Identifier.
const char * name
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ namestore_iteration_error()

static void namestore_iteration_error ( void *  cls)
static

Does internal server error when iteration failed.

Parameters
clsthe struct RequestHandle

Definition at line 399 of file plugin_rest_namestore.c.

References do_error(), RequestHandle::emsg, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.

Referenced by namestore_get().

400 {
401  struct RequestHandle *handle = cls;
402 
405  return;
406 }
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void do_error(void *cls)
Task run on errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_finished()

static void create_finished ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Create finished callback.

Parameters
clsthe struct RequestHandle
successthe success indicating integer, GNUNET_OK on success
emsgthe error message (can be NULL)

Definition at line 417 of file plugin_rest_namestore.c.

References cleanup_handle(), do_error(), RequestHandle::emsg, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, handle, RequestHandle::ns_qe, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by ns_lookup_cb().

418 {
419  struct RequestHandle *handle = cls;
420  struct MHD_Response *resp;
421 
422  handle->ns_qe = NULL;
423  if (GNUNET_YES != success)
424  {
425  if (NULL != emsg)
426  {
427  handle->emsg = GNUNET_strdup (emsg);
429  return;
430  }
431  handle->emsg = GNUNET_strdup ("Error storing records");
433  return;
434  }
435  resp = GNUNET_REST_create_response (NULL);
436  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
438 }
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ del_finished()

static void del_finished ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Delete finished callback.

Parameters
clsthe struct RequestHandle
successthe success indicating integer, GNUNET_OK on success
emsgthe error message (can be NULL)

Definition at line 449 of file plugin_rest_namestore.c.

References cleanup_handle(), do_error(), RequestHandle::emsg, GNUNET_NO, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_SYSERR, handle, RequestHandle::ns_qe, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::response_code.

Referenced by namestore_delete().

450 {
451  struct RequestHandle *handle = cls;
452 
453  handle->ns_qe = NULL;
454  if (GNUNET_NO == success)
455  {
456  handle->response_code = MHD_HTTP_NOT_FOUND;
457  handle->emsg = GNUNET_strdup ("No record found");
459  return;
460  }
461  if (GNUNET_SYSERR == success)
462  {
463  if (NULL != emsg)
464  {
465  handle->emsg = GNUNET_strdup (emsg);
467  return;
468  }
469  handle->emsg = GNUNET_strdup ("Deleting record failed");
471  return;
472  }
473  handle->proc (handle->proc_cls,
475  MHD_HTTP_NO_CONTENT);
477 }
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_list_finished()

static void namestore_list_finished ( void *  cls)
static

Iteration over all results finished, build final response.

Parameters
clsthe struct RequestHandle

Definition at line 487 of file plugin_rest_namestore.c.

References cleanup_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, RequestHandle::list_it, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::resp_object.

Referenced by namestore_get(), and ns_get_lookup_cb().

488 {
489  struct RequestHandle *handle = cls;
490  char *result_str;
491  struct MHD_Response *resp;
492 
493  handle->list_it = NULL;
494 
495  if (NULL == handle->resp_object)
496  handle->resp_object = json_array ();
497 
498  result_str = json_dumps (handle->resp_object, 0);
499  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
500  resp = GNUNET_REST_create_response (result_str);
501  MHD_add_response_header (resp, "Content-Type", "application/json");
502  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
503  GNUNET_free (result_str);
505 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
json_t * resp_object
Response object.
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:1296
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:57
#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:

◆ namestore_list_iteration()

static void namestore_list_iteration ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone_key,
const char *  rname,
unsigned int  rd_len,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Create a response with requested records.

Parameters
handlethe RequestHandle

Only add if not empty

Definition at line 514 of file plugin_rest_namestore.c.

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_NAMESTORE_zone_iterator_next(), handle, RequestHandle::list_it, RequestHandle::record_type, GNUNET_GNSRECORD_Data::record_type, and RequestHandle::resp_object.

Referenced by namestore_get().

519 {
520  struct RequestHandle *handle = cls;
521  struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
522  json_t *record_obj;
523  int i = 0;
524  int j = 0;
525 
526  if (NULL == handle->resp_object)
527  handle->resp_object = json_array ();
528  for (i = 0; i < rd_len; i++)
529  {
530  if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
531  (rd[i].record_type != handle->record_type))
532  continue; /* Apply filter */
533  rd_filtered[j] = rd[i];
534  rd_filtered[j].data = rd[i].data;
535  j++;
536  }
538  if (j > 0)
539  {
540  record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname,
541  rd_filtered,
542  j);
543  json_array_append_new (handle->resp_object, record_obj);
544  }
546 }
int record_type
Record type to look up.
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
The request handle.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
json_t * resp_object
Response object.
const void * data
Binary value stored in the DNS record.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert GNS record to JSON.
uint32_t record_type
Type of the GNS/DNS record.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ns_lookup_error_cb()

static void ns_lookup_error_cb ( void *  cls)
static

Handle lookup error.

Parameters
clsthe request handle

Definition at line 555 of file plugin_rest_namestore.c.

References do_error(), RequestHandle::emsg, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.

Referenced by namestore_add_or_update(), and namestore_get().

556 {
557  struct RequestHandle *handle = cls;
558 
561 }
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void do_error(void *cls)
Task run on errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ns_get_lookup_cb()

static void ns_get_lookup_cb ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
const char *  label,
unsigned int  rd_len,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Only add if not empty

Definition at line 565 of file plugin_rest_namestore.c.

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_SCHEDULER_add_now(), handle, namestore_list_finished(), RequestHandle::ns_qe, RequestHandle::record_type, GNUNET_GNSRECORD_Data::record_type, and RequestHandle::resp_object.

Referenced by namestore_get().

570 {
571  struct RequestHandle *handle = cls;
572  struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
573  json_t *record_obj;
574  int i = 0;
575  int j = 0;
576 
577  handle->ns_qe = NULL;
578  if (NULL == handle->resp_object)
579  handle->resp_object = json_array ();
580  for (i = 0; i < rd_len; i++)
581  {
582  if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
583  (rd[i].record_type != handle->record_type))
584  continue; /* Apply filter */
585  rd_filtered[j] = rd[i];
586  rd_filtered[j].data = rd[i].data;
587  j++;
588  }
590  if (j > 0)
591  {
592  record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
593  rd_filtered,
594  j);
595  json_array_append_new (handle->resp_object, record_obj);
596  }
598 }
int record_type
Record type to look up.
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
The request handle.
json_t * resp_object
Response object.
const void * data
Binary value stored in the DNS record.
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void namestore_list_finished(void *cls)
Iteration over all results finished, build final response.
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert GNS record to JSON.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
uint32_t record_type
Type of the GNS/DNS record.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_get()

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

Handle namestore GET request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 609 of file plugin_rest_namestore.c.

References do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_lookup(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, RequestHandle::list_it, namestore_iteration_error(), namestore_list_finished(), namestore_list_iteration(), ns_get_lookup_cb(), ns_lookup_error_cb(), RequestHandle::ns_qe, RequestHandle::record_name, RequestHandle::record_type, RequestHandle::response_code, RequestHandle::url, GNUNET_REST_RequestHandle::url_param_map, and RequestHandle::zone_pkey.

Referenced by rest_process_request().

612 {
613  struct RequestHandle *handle = cls;
614  struct EgoEntry *ego_entry;
615  struct GNUNET_HashCode key;
616  char *egoname;
617  char *labelname;
618  char *typename;
619 
620  egoname = NULL;
621  ego_entry = NULL;
622 
623  // set zone to name if given
624  if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
625  {
626  handle->response_code = MHD_HTTP_NOT_FOUND;
629  return;
630  }
631  egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
632  ego_entry = get_egoentry_namestore (handle, egoname);
633  if (NULL == ego_entry)
634  {
635  handle->response_code = MHD_HTTP_NOT_FOUND;
638  return;
639  }
640  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
641 
642  GNUNET_CRYPTO_hash ("record_type", strlen ("record_type"), &key);
643  if (GNUNET_NO ==
645  {
647  }
648  else
649  {
650  typename = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
651  &key);
653  }
654  labelname = &egoname[strlen (ego_entry->identifier)];
655  // set zone to name if given
656  if (1 >= strlen (labelname))
657  {
658  handle->list_it =
660  handle->zone_pkey,
662  handle,
664  handle,
666  handle);
667  if (NULL == handle->list_it)
668  {
671  return;
672  }
673  return;
674  }
675  handle->record_name = GNUNET_strdup (labelname + 1);
677  handle->zone_pkey,
678  handle->record_name,
680  handle,
682  handle);
683  if (NULL == handle->ns_qe)
684  {
687  return;
688  }
689 }
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
int record_type
Record type to look up.
static void namestore_iteration_error(void *cls)
Does internal server error when iteration failed.
struct EgoEntry * get_egoentry_namestore(struct RequestHandle *handle, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g "AAAA") to the corresponding number.
Definition: gnsrecord.c:217
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
static void namestore_list_iteration(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Create a response with requested records.
static void ns_get_lookup_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
static void ns_lookup_error_cb(void *cls)
Handle lookup error.
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.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
char * record_name
Records to store.
char * emsg
Error response message.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void namestore_list_finished(void *cls)
Iteration over all results finished, build final response.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
A 512-bit hashcode.
int response_code
Response code.
struct GNUNET_HashCode key
The key used in the DHT.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
char * identifier
Ego Identifier.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
const struct GNUNET_IDENTITY_PrivateKey * zone_pkey
Private key for the zone.
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ns_lookup_cb()

static void ns_lookup_cb ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Definition at line 693 of file plugin_rest_namestore.c.

References create_finished(), do_error(), GNUNET_NAMESTORE_records_store(), GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, and UPDATE_STRATEGY_APPEND.

Referenced by namestore_add_or_update().

698 {
699  struct RequestHandle *handle = cls;
700  struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count];
701  int i = 0;
702  int j = 0;
703 
705  {
706  for (i = 0; i < rd_count; i++)
707  rd_new[i] = rd[i];
708  }
709  for (j = 0; j < handle->rd_count; j++)
710  rd_new[i + j] = handle->rd[j];
712  handle->zone_pkey,
713  handle->record_name,
714  i + j,
715  rd_new,
717  handle);
718  if (NULL == handle->ns_qe)
719  {
722  return;
723  }
724 }
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
static void create_finished(void *cls, int32_t success, const char *emsg)
Create finished callback.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
char * record_name
Records to store.
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:1296
unsigned int rd_count
Number of records in rd.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
enum UpdateStrategy update_strategy
How to update the record set.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
const struct GNUNET_IDENTITY_PrivateKey * zone_pkey
Private key for the zone.
struct GNUNET_GNSRECORD_Data * rd
Records to store.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_add_or_update()

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

Handle namestore POST/PUT request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 735 of file plugin_rest_namestore.c.

References GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_GNSRECORD_JSON_spec_gnsrecord(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_memcpy, GNUNET_NAMESTORE_records_lookup(), GNUNET_OK, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_REST_NAMESTORE_INVALID_DATA, GNUNET_REST_NAMESTORE_NO_DATA, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, ns_lookup_cb(), ns_lookup_error_cb(), RequestHandle::ns_qe, RequestHandle::rd, RequestHandle::rd_count, RequestHandle::record_name, RequestHandle::response_code, RequestHandle::rest_handle, RequestHandle::url, and RequestHandle::zone_pkey.

Referenced by namestore_add(), and namestore_update().

738 {
739  struct RequestHandle *handle = cls;
740  struct EgoEntry *ego_entry;
741  char *egoname;
742  json_t *data_js;
743  json_error_t err;
744 
745  char term_data[handle->rest_handle->data_size + 1];
746 
747  if (0 >= handle->rest_handle->data_size)
748  {
749  handle->response_code = MHD_HTTP_BAD_REQUEST;
752  return;
753  }
754  term_data[handle->rest_handle->data_size] = '\0';
755  GNUNET_memcpy (term_data,
756  handle->rest_handle->data,
757  handle->rest_handle->data_size);
758  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
759  struct GNUNET_JSON_Specification gnsspec[] =
760  { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
761  &handle->record_name),
763  if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
764  {
767  json_decref (data_js);
768  return;
769  }
770  GNUNET_JSON_parse_free (gnsspec);
771  if (0 >= strlen (handle->record_name))
772  {
773  handle->response_code = MHD_HTTP_BAD_REQUEST;
776  json_decref (data_js);
777  return;
778  }
779  json_decref (data_js);
780 
781  egoname = NULL;
782  ego_entry = NULL;
783 
784  // set zone to name if given
785  if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
786  {
787  handle->response_code = MHD_HTTP_NOT_FOUND;
790  return;
791  }
792  egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
793  ego_entry = get_egoentry_namestore (handle, egoname);
794 
795  if (NULL == ego_entry)
796  {
797  handle->response_code = MHD_HTTP_NOT_FOUND;
800  return;
801  }
802  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
804  handle->zone_pkey,
805  handle->record_name,
807  handle,
808  &ns_lookup_cb,
809  handle);
810  if (NULL == handle->ns_qe)
811  {
814  return;
815  }
816 }
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
size_t data_size
The POST data size.
struct EgoEntry * get_egoentry_namestore(struct RequestHandle *handle, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
enum GNUNET_GenericReturnValue GNUNET_JSON_parse(const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
Navigate and parse data in a JSON tree.
Definition: json.c:45
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:106
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
static void ns_lookup_error_cb(void *cls)
Handle lookup error.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
char * record_name
Records to store.
char * emsg
Error response message.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
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:1296
unsigned int rd_count
Number of records in rd.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
int response_code
Response code.
#define GNUNET_REST_NAMESTORE_NO_DATA
Error message No data.
const char * data
The POST data.
static void ns_lookup_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord(struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
JSON Specification for GNS Records.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_NAMESTORE_INVALID_DATA
Error message invalid data.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
const struct GNUNET_IDENTITY_PrivateKey * zone_pkey
Private key for the zone.
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
struct GNUNET_GNSRECORD_Data * rd
Records to store.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:32
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_update()

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

Handle namestore PUT request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 827 of file plugin_rest_namestore.c.

References handle, namestore_add_or_update(), RequestHandle::update_strategy, and UPDATE_STRATEGY_REPLACE.

Referenced by rest_process_request().

830 {
831  struct RequestHandle *handle = cls;
833  namestore_add_or_update (con_handle, url, cls);
834 }
The request handle.
void namestore_add_or_update(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore POST/PUT request.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
enum UpdateStrategy update_strategy
How to update the record set.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_add()

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

Handle namestore POST request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 845 of file plugin_rest_namestore.c.

References handle, namestore_add_or_update(), RequestHandle::update_strategy, and UPDATE_STRATEGY_APPEND.

Referenced by rest_process_request().

848 {
849  struct RequestHandle *handle = cls;
851  namestore_add_or_update (con_handle, url, cls);
852 }
The request handle.
void namestore_add_or_update(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore POST/PUT request.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
enum UpdateStrategy update_strategy
How to update the record set.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_delete()

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

Handle namestore DELETE request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 863 of file plugin_rest_namestore.c.

References del_finished(), do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_store(), GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, RequestHandle::ns_qe, RequestHandle::record_name, RequestHandle::response_code, RequestHandle::url, and RequestHandle::zone_pkey.

Referenced by rest_process_request().

866 {
867  struct RequestHandle *handle = cls;
868  struct EgoEntry *ego_entry;
869  char *egoname;
870  char *labelname;
871 
872  egoname = NULL;
873  ego_entry = NULL;
874 
875  // set zone to name if given
876  if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
877  {
878  handle->response_code = MHD_HTTP_NOT_FOUND;
881  return;
882  }
883  egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
884  ego_entry = get_egoentry_namestore (handle, egoname);
885  if (NULL == ego_entry)
886  {
887  handle->response_code = MHD_HTTP_NOT_FOUND;
890  return;
891  }
892  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
893  labelname = &egoname[strlen (ego_entry->identifier)];
894  // set zone to name if given
895  if (1 >= strlen (labelname))
896  {
897  /* label is only "/" */
898  handle->response_code = MHD_HTTP_BAD_REQUEST;
899  handle->emsg = GNUNET_strdup ("Label missing");
901  }
902 
903  handle->record_name = GNUNET_strdup (labelname + 1);
905  handle->zone_pkey,
906  handle->record_name,
907  0,
908  NULL,
909  &del_finished,
910  handle);
911  if (NULL == handle->ns_qe)
912  {
915  return;
916  }
917 }
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
struct EgoEntry * get_egoentry_namestore(struct RequestHandle *handle, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
char * record_name
Records to store.
char * emsg
Error response message.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_QueueEntry * ns_qe
NAMESTORE Operation.
char * identifier
Ego Identifier.
const struct GNUNET_IDENTITY_PrivateKey * zone_pkey
Private key for the zone.
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
static void del_finished(void *cls, int32_t success, const char *emsg)
Delete finished callback.
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 928 of file plugin_rest_namestore.c.

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

Referenced by rest_process_request().

931 {
932  struct MHD_Response *resp;
933  struct RequestHandle *handle = cls;
934 
935  // independent of path return all options
936  resp = GNUNET_REST_create_response (NULL);
937  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
938  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
940  return;
941 }
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:1296
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static char * allow_methods
HTTP methods allows for this plugin.
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:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_ego()

static void list_ego ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  identifier 
)
static

Definition at line 945 of file plugin_rest_namestore.c.

References EgoEntry::ego, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_IDENTITY_public_key_to_string(), GNUNET_new, GNUNET_strdup, ID_REST_STATE_INIT, ID_REST_STATE_POST_INIT, EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, and state.

Referenced by libgnunet_plugin_rest_namestore_init().

949 {
950  struct EgoEntry *ego_entry;
952 
953  if ((NULL == ego) && (ID_REST_STATE_INIT == state))
954  {
956  return;
957  }
958  if (ID_REST_STATE_INIT == state)
959  {
960  ego_entry = GNUNET_new (struct EgoEntry);
963  ego_entry->ego = ego;
964  ego_entry->identifier = GNUNET_strdup (identifier);
966  ego_tail,
967  ego_entry);
968  }
969  /* Ego renamed or added */
970  if (identifier != NULL)
971  {
972  for (ego_entry = ego_head; NULL != ego_entry;
973  ego_entry = ego_entry->next)
974  {
975  if (ego_entry->ego == ego)
976  {
977  /* Rename */
978  GNUNET_free (ego_entry->identifier);
979  ego_entry->identifier = GNUNET_strdup (identifier);
980  break;
981  }
982  }
983  if (NULL == ego_entry)
984  {
985  /* Add */
986  ego_entry = GNUNET_new (struct EgoEntry);
989  ego_entry->ego = ego;
990  ego_entry->identifier = GNUNET_strdup (identifier);
992  ego_tail,
993  ego_entry);
994  }
995  }
996  else
997  {
998  /* Delete */
999  for (ego_entry = ego_head; NULL != ego_entry;
1000  ego_entry = ego_entry->next)
1001  {
1002  if (ego_entry->ego == ego)
1003  break;
1004  }
1005  if (NULL == ego_entry)
1006  return; /* Not found */
1007 
1009  ego_tail,
1010  ego_entry);
1011  GNUNET_free (ego_entry->identifier);
1012  GNUNET_free (ego_entry->keystring);
1013  GNUNET_free (ego_entry);
1014  return;
1015  }
1016 
1017 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:652
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
static struct EgoEntry * ego_tail
Ego list.
static int state
The processing state.
static struct EgoEntry * ego_head
Ego list.
char * keystring
Public key string.
#define ID_REST_STATE_INIT
State while collecting all egos.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
char * identifier
Ego Identifier.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rest_process_request()

static enum GNUNET_GenericReturnValue 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 1032 of file plugin_rest_namestore.c.

References cleanup_handle(), do_error(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, namestore_add(), namestore_delete(), namestore_get(), namestore_update(), options_cont(), GNUNET_REST_RequestHandler::proc, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, RequestHandle::rest_handle, RequestHandle::timeout, RequestHandle::timeout_task, GNUNET_REST_RequestHandle::url, RequestHandle::url, and RequestHandle::zone_pkey.

Referenced by libgnunet_plugin_rest_namestore_init().

1035 {
1036  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1038  static const struct GNUNET_REST_RequestHandler handlers[] =
1039  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get },
1040  { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
1041  { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_update },
1042  { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete },
1043  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont },
1045 
1046  handle->response_code = 0;
1048  handle->proc_cls = proc_cls;
1049  handle->proc = proc;
1050  handle->rest_handle = rest_handle;
1051  handle->zone_pkey = NULL;
1052  handle->timeout_task =
1053  GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle);
1054  handle->url = GNUNET_strdup (rest_handle->url);
1055  if (handle->url[strlen (handle->url) - 1] == '/')
1056  handle->url[strlen (handle->url) - 1] = '\0';
1058  requests_tail,
1059  handle);
1060  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1061  if (GNUNET_NO ==
1062  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1063  {
1064  cleanup_handle (handle);
1065  return GNUNET_NO;
1066  }
1067 
1068  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1069  return GNUNET_YES;
1070 }
void namestore_update(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore PUT request.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore DELETE request.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
#define GNUNET_REST_HANDLER_END
The request handle.
static struct RequestHandle * requests_head
DLL.
void namestore_add(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore POST request.
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:1269
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
const char * url
The url as string.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
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:77
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
int response_code
Response code.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void do_error(void *cls)
Task run on errors.
void namestore_get(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore GET request.
const struct GNUNET_IDENTITY_PrivateKey * zone_pkey
Private key for the zone.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
#define GNUNET_log(kind,...)
static struct RequestHandle * requests_tail
DLL.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_rest_namestore_init()

void* libgnunet_plugin_rest_namestore_init ( void *  cls)

Entry point for the plugin.

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

Definition at line 1080 of file plugin_rest_namestore.c.

References _, allow_methods, Plugin::api, Plugin::cfg, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_NAMESTORE_connect(), GNUNET_new, GNUNET_REST_API_NS_NAMESTORE, ID_REST_STATE_INIT, list_ego(), GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, rest_process_request(), and state.

1081 {
1082  static struct Plugin plugin;
1083  struct GNUNET_REST_Plugin *api;
1084 
1085  cfg = cls;
1086  if (NULL != plugin.cfg)
1087  return NULL; /* can only initialize once! */
1088  memset (&plugin, 0, sizeof(struct Plugin));
1089  plugin.cfg = cfg;
1090  api = GNUNET_new (struct GNUNET_REST_Plugin);
1091  api->cls = &plugin;
1096  "%s, %s, %s, %s, %s",
1097  MHD_HTTP_METHOD_GET,
1098  MHD_HTTP_METHOD_POST,
1099  MHD_HTTP_METHOD_PUT,
1100  MHD_HTTP_METHOD_DELETE,
1101  MHD_HTTP_METHOD_OPTIONS);
1104 
1105  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n"));
1106  return api;
1107 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
static enum GNUNET_GenericReturnValue rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static int state
The processing state.
char * name
Plugin name.
static char * plugin
Solver plugin name as string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static char * allow_methods
HTTP methods allows for this plugin.
#define ID_REST_STATE_INIT
State while collecting all egos.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
Handle for a plugin.
Definition: block.c:37
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
Here is the call graph for this function:

◆ libgnunet_plugin_rest_namestore_done()

void* libgnunet_plugin_rest_namestore_done ( void *  cls)

Exit point from the plugin.

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

Definition at line 1117 of file plugin_rest_namestore.c.

References allow_methods, Plugin::api, Plugin::cfg, GNUNET_REST_Plugin::cls, do_error(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_log, GNUNET_NAMESTORE_disconnect(), EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, plugin, and request.

1118 {
1119  struct GNUNET_REST_Plugin *api = cls;
1120  struct Plugin *plugin = api->cls;
1121  struct RequestHandle *request;
1122  struct EgoEntry *ego_entry;
1123  struct EgoEntry *ego_tmp;
1124 
1125  plugin->cfg = NULL;
1126  while (NULL != (request = requests_head))
1127  do_error (request);
1128  if (NULL != identity_handle)
1130  if (NULL != ns_handle)
1132 
1133  for (ego_entry = ego_head; NULL != ego_entry;)
1134  {
1135  ego_tmp = ego_entry;
1136  ego_entry = ego_entry->next;
1137  GNUNET_free (ego_tmp->identifier);
1138  GNUNET_free (ego_tmp->keystring);
1139  GNUNET_free (ego_tmp);
1140  }
1141 
1143  GNUNET_free (api);
1144  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
1145  return NULL;
1146 }
static struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
void * cls
The closure of the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct returned by the initialization function of the plugin
The request handle.
static struct RequestHandle * requests_head
DLL.
The ego list.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
static struct EgoEntry * ego_head
Ego list.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
static char * plugin
Solver plugin name as string.
char * keystring
Public key string.
static char * allow_methods
HTTP methods allows for this plugin.
static void do_error(void *cls)
Task run on errors.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
char * identifier
Ego Identifier.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

The configuration handle.

Handle to our configuration.

Definition at line 80 of file plugin_rest_namestore.c.

◆ allow_methods

char* allow_methods
static

HTTP methods allows for this plugin.

Definition at line 85 of file plugin_rest_namestore.c.

Referenced by libgnunet_plugin_rest_namestore_done(), libgnunet_plugin_rest_namestore_init(), and options_cont().

◆ ego_head

struct EgoEntry* ego_head
static

Ego list.

Definition at line 90 of file plugin_rest_namestore.c.

◆ ego_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 95 of file plugin_rest_namestore.c.

◆ state

int state
static

The processing state.

Definition at line 100 of file plugin_rest_namestore.c.

Referenced by libgnunet_plugin_rest_namestore_init(), and list_ego().

◆ ns_handle

struct GNUNET_NAMESTORE_Handle* ns_handle
static

Handle to NAMESTORE.

Definition at line 105 of file plugin_rest_namestore.c.

◆ identity_handle

struct GNUNET_IDENTITY_Handle* identity_handle
static

Handle to Identity service.

Definition at line 110 of file plugin_rest_namestore.c.

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 273 of file plugin_rest_namestore.c.

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 278 of file plugin_rest_namestore.c.