GNUnet  0.10.x
Data Structures | Macros | 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_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...
 

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_CRYPTO_EcdsaPrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
 Create a response with requested records. More...
 
void namestore_get (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle namestore GET request. More...
 
static void ns_lookup_error_cb (void *cls)
 
static void ns_lookup_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 
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 init_cont (struct RequestHandle *handle)
 Handle rest request. More...
 
static void id_connect_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 This function is initially called for all egos and then again whenever a ego's identifier changes or if it is deleted. 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_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...
 

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(), namestore_delete(), and namestore_get().

◆ GNUNET_REST_NAMESTORE_FAILED

#define GNUNET_REST_NAMESTORE_FAILED   "Namestore action failed"

Error message Failed request.

Definition at line 56 of file plugin_rest_namestore.c.

Referenced by namestore_add(), namestore_delete(), namestore_get(), namestore_iteration_error(), ns_lookup_cb(), and ns_lookup_error_cb().

◆ 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(), and namestore_delete().

◆ 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().

◆ 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 id_connect_cb().

◆ 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 id_connect_cb().

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
handleHandle to clean up

Definition at line 244 of file plugin_rest_namestore.c.

References RequestHandle::add_qe, GNUNET_GNSRECORD_Data::data, RequestHandle::ego_head, RequestHandle::emsg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_log, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_disconnect(), GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, EgoEntry::identifier, RequestHandle::identity_handle, EgoEntry::keystring, RequestHandle::list_it, EgoEntry::next, RequestHandle::ns_handle, 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(), and options_cont().

245 {
246  struct RequestHandle *handle = cls;
247  struct EgoEntry *ego_entry;
248  struct EgoEntry *ego_tmp;
249 
250  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
251  if (NULL != handle->timeout_task)
252  {
254  handle->timeout_task = NULL;
255  }
256  if (NULL != handle->record_name)
257  GNUNET_free(handle->record_name);
258  if (NULL != handle->url)
259  GNUNET_free(handle->url);
260  if (NULL != handle->emsg)
261  GNUNET_free(handle->emsg);
262  if (NULL != handle->rd)
263  {
264  for (int i = 0; i < handle->rd_count; i++)
265  {
266  if (NULL != handle->rd[i].data)
267  GNUNET_free((void *)handle->rd[i].data);
268  }
269  GNUNET_free(handle->rd);
270  }
271  if (NULL != handle->timeout_task)
273  if (NULL != handle->list_it)
275  if (NULL != handle->add_qe)
277  if (NULL != handle->identity_handle)
279  if (NULL != handle->ns_handle)
280  {
282  }
283 
284  for (ego_entry = handle->ego_head; NULL != ego_entry;)
285  {
286  ego_tmp = ego_entry;
287  ego_entry = ego_entry->next;
288  GNUNET_free(ego_tmp->identifier);
289  GNUNET_free(ego_tmp->keystring);
290  GNUNET_free(ego_tmp);
291  }
292 
293  if (NULL != handle->resp_object)
294  {
295  json_decref(handle->resp_object);
296  }
297 
298  GNUNET_free(handle);
299 }
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
The request handle.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
The ego list.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
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_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:835
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
char * keystring
Public key string.
char * identifier
Ego Identifier.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
struct EgoEntry * ego_head
Ego list.
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.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
#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:956
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 308 of file plugin_rest_namestore.c.

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

Referenced by create_finished(), del_finished(), init_cont(), namestore_add(), namestore_delete(), namestore_get(), namestore_iteration_error(), ns_lookup_cb(), ns_lookup_error_cb(), and rest_process_request().

309 {
310  struct RequestHandle *handle = cls;
311  struct MHD_Response *resp;
312  json_t *json_error = json_object();
313  char *response;
314 
315  if (NULL == handle->emsg)
317 
318  json_object_set_new(json_error, "error", json_string(handle->emsg));
319 
320  if (0 == handle->response_code)
321  handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
322  response = json_dumps(json_error, 0);
323  resp = GNUNET_REST_create_response(response);
324  handle->proc(handle->proc_cls, resp, handle->response_code);
325  json_decref(json_error);
326  GNUNET_free(response);
328 }
#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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
HTTP 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:56
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 341 of file plugin_rest_namestore.c.

References RequestHandle::ego_head, EgoEntry::identifier, and EgoEntry::next.

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

342 {
343  struct EgoEntry *ego_entry;
344 
345  if (NULL != name)
346  {
347  for (ego_entry = handle->ego_head; NULL != ego_entry;
348  ego_entry = ego_entry->next)
349  {
350  if (0 != strcasecmp(name, ego_entry->identifier))
351  continue;
352  return ego_entry;
353  }
354  }
355  return NULL;
356 }
The ego list.
const char * name
char * identifier
Ego Identifier.
struct EgoEntry * ego_head
Ego list.
struct EgoEntry * next
DLL.
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 365 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().

366 {
367  struct RequestHandle *handle = cls;
368 
371  return;
372 }
#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:1264
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 383 of file plugin_rest_namestore.c.

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

Referenced by ns_lookup_cb().

384 {
385  struct RequestHandle *handle = cls;
386  struct MHD_Response *resp;
387 
388  handle->add_qe = NULL;
389  if (GNUNET_YES != success)
390  {
391  if (NULL != emsg)
392  {
393  handle->emsg = GNUNET_strdup(emsg);
395  return;
396  }
397  handle->emsg = GNUNET_strdup("Error storing records");
399  return;
400  }
401  resp = GNUNET_REST_create_response(NULL);
402  handle->proc(handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
404 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
#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:1264
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 MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
#define GNUNET_YES
Definition: gnunet_common.h:77
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 415 of file plugin_rest_namestore.c.

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

Referenced by namestore_delete().

416 {
417  struct RequestHandle *handle = cls;
418 
419  handle->add_qe = NULL;
420  if (GNUNET_NO == success)
421  {
422  handle->response_code = MHD_HTTP_NOT_FOUND;
423  handle->emsg = GNUNET_strdup("No record found");
425  return;
426  }
427  if (GNUNET_SYSERR == success)
428  {
429  if (NULL != emsg)
430  {
431  handle->emsg = GNUNET_strdup(emsg);
433  return;
434  }
435  handle->emsg = GNUNET_strdup("Deleting record failed");
437  return;
438  }
439  handle->proc(handle->proc_cls,
441  MHD_HTTP_NO_CONTENT);
443 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
#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:1264
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
HTTP response code.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void do_error(void *cls)
Task run on errors.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
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 453 of file plugin_rest_namestore.c.

References cleanup_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, 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().

454 {
455  struct RequestHandle *handle = cls;
456  char *result_str;
457  struct MHD_Response *resp;
458 
459  handle->list_it = NULL;
460 
461  if (NULL == handle->resp_object)
462  handle->resp_object = json_array();
463 
464  result_str = json_dumps(handle->resp_object, 0);
465  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
466  resp = GNUNET_REST_create_response(result_str);
467  handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
468  GNUNET_free_non_null(result_str);
470 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:1264
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
#define GNUNET_log(kind,...)
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_CRYPTO_EcdsaPrivateKey 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

Definition at line 479 of file plugin_rest_namestore.c.

References GNUNET_JSON_from_gnsrecord(), GNUNET_NAMESTORE_zone_iterator_next(), handle, RequestHandle::list_it, and RequestHandle::resp_object.

Referenced by namestore_get().

484 {
485  struct RequestHandle *handle = cls;
486  json_t *record_obj;
487 
488  if (NULL == handle->resp_object)
489  handle->resp_object = json_array();
490  record_obj = GNUNET_JSON_from_gnsrecord(rname,
491  rd,
492  rd_len);
493  json_array_append_new(handle->resp_object, record_obj);
495 }
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.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
json_t * GNUNET_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert Gns record to JSON.
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 506 of file plugin_rest_namestore.c.

References do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::list_it, namestore_iteration_error(), namestore_list_finished(), namestore_list_iteration(), RequestHandle::ns_handle, RequestHandle::response_code, RequestHandle::url, and RequestHandle::zone_pkey.

Referenced by init_cont().

509 {
510  struct RequestHandle *handle = cls;
511  struct EgoEntry *ego_entry;
512  char *egoname;
513 
514  egoname = NULL;
515  ego_entry = NULL;
516 
517  // set zone to name if given
518  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
519  {
520  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
521  ego_entry = get_egoentry_namestore(handle, egoname);
522 
523  if (NULL == ego_entry)
524  {
525  handle->response_code = MHD_HTTP_NOT_FOUND;
528  return;
529  }
530  }
531  if (NULL != ego_entry)
532  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
533 
534  handle->list_it =
536  handle->zone_pkey,
538  handle,
540  handle,
542  handle);
543  if (NULL == handle->list_it)
544  {
547  return;
548  }
549 }
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
static void namestore_iteration_error(void *cls)
Does internal server error when iteration failed.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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)...
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...
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:553
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static void namestore_list_iteration(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Create a response with requested records.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
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:1264
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.
int response_code
HTTP response code.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#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_error_cb()

static void ns_lookup_error_cb ( void *  cls)
static

Definition at line 553 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().

554 {
555  struct RequestHandle *handle = cls;
556 
559 }
#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:1264
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_lookup_cb()

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

Definition at line 563 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, and handle.

Referenced by namestore_add().

568 {
569  struct RequestHandle *handle = cls;
570  struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count];
571 
572  for (int i = 0; i < rd_count; i++)
573  rd_new[i] = rd[i];
574  for (int j = 0; j < handle->rd_count; j++)
575  rd_new[rd_count + j] = handle->rd[j];
577  handle->zone_pkey,
578  handle->record_name,
579  rd_count + handle->rd_count,
580  rd_new,
582  handle);
583  if (NULL == handle->add_qe)
584  {
587  return;
588  }
589 }
#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 * add_qe
NAMESTORE Operation.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
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:1264
unsigned int rd_count
Number of records in rd.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
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()

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 600 of file plugin_rest_namestore.c.

References RequestHandle::add_qe, GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_gnsrecord(), 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, RequestHandle::ns_handle, ns_lookup_cb(), ns_lookup_error_cb(), RequestHandle::rd, RequestHandle::rd_count, RequestHandle::record_name, RequestHandle::response_code, RequestHandle::rest_handle, RequestHandle::url, and RequestHandle::zone_pkey.

Referenced by init_cont().

603 {
604  struct RequestHandle *handle = cls;
605  struct EgoEntry *ego_entry;
606  char *egoname;
607  json_t *data_js;
608  json_error_t err;
609 
610  char term_data[handle->rest_handle->data_size + 1];
611 
612  if (0 >= handle->rest_handle->data_size)
613  {
616  return;
617  }
618  term_data[handle->rest_handle->data_size] = '\0';
619  GNUNET_memcpy(term_data,
620  handle->rest_handle->data,
621  handle->rest_handle->data_size);
622  data_js = json_loads(term_data, JSON_DECODE_ANY, &err);
623  struct GNUNET_JSON_Specification gnsspec[] =
624  { GNUNET_JSON_spec_gnsrecord(&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end() };
625  if (GNUNET_OK != GNUNET_JSON_parse(data_js, gnsspec, NULL, NULL))
626  {
629  json_decref(data_js);
630  return;
631  }
632  GNUNET_JSON_parse_free(gnsspec);
633  if (0 >= strlen(handle->record_name))
634  {
637  json_decref(data_js);
638  return;
639  }
640  json_decref(data_js);
641 
642  egoname = NULL;
643  ego_entry = NULL;
644 
645  // set zone to name if given
646  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
647  {
648  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
649  ego_entry = get_egoentry_namestore(handle, egoname);
650 
651  if (NULL == ego_entry)
652  {
653  handle->response_code = MHD_HTTP_NOT_FOUND;
656  return;
657  }
658  }
659  if (NULL != ego_entry)
660  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
662  handle->zone_pkey,
663  handle->record_name,
665  handle,
666  &ns_lookup_cb,
667  handle);
668  if (NULL == handle->add_qe)
669  {
672  return;
673  }
674 }
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
size_t data_size
The POST data size.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
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...
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:100
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:553
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void ns_lookup_error_cb(void *cls)
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
#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.
static void ns_lookup_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
char * emsg
Error response message.
int 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
#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:1264
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
Handle to rest request.
int response_code
HTTP response code.
#define GNUNET_REST_NAMESTORE_NO_DATA
Error message No data.
const char * data
The POST data.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
struct GNUNET_JSON_Specification GNUNET_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_Handle * ns_handle
Handle to NAMESTORE.
#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:35
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 685 of file plugin_rest_namestore.c.

References RequestHandle::add_qe, del_finished(), do_error(), EgoEntry::ego, RequestHandle::emsg, get_egoentry_namestore(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_store(), GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_REST_NAMESTORE_INVALID_DATA, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::ns_handle, RequestHandle::record_name, RequestHandle::response_code, RequestHandle::url, GNUNET_REST_RequestHandle::url_param_map, and RequestHandle::zone_pkey.

Referenced by init_cont().

688 {
689  struct RequestHandle *handle = cls;
690  struct GNUNET_HashCode key;
691  struct EgoEntry *ego_entry;
692  char *egoname;
693 
694  egoname = NULL;
695  ego_entry = NULL;
696 
697  // set zone to name if given
698  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
699  {
700  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
701  ego_entry = get_egoentry_namestore(handle, egoname);
702 
703  if (NULL == ego_entry)
704  {
705  handle->response_code = MHD_HTTP_NOT_FOUND;
708  return;
709  }
710  }
711  if (NULL != ego_entry)
712  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
713 
714  GNUNET_CRYPTO_hash("record_name", strlen("record_name"), &key);
715  if (GNUNET_NO ==
717  {
720  return;
721  }
722  handle->record_name = GNUNET_strdup(
724 
726  handle->zone_pkey,
727  handle->record_name,
728  0,
729  NULL,
730  &del_finished,
731  handle);
732  if (NULL == handle->add_qe)
733  {
736  return;
737  }
738 }
#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...
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:553
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
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: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:1264
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
int response_code
HTTP response code.
struct GNUNET_HashCode key
The key used in the DHT.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_NAMESTORE_INVALID_DATA
Error message invalid data.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
#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 749 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 init_cont().

752 {
753  struct MHD_Response *resp;
754  struct RequestHandle *handle = cls;
755 
756  // independent of path return all options
757  resp = GNUNET_REST_create_response(NULL);
758  MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods);
759  handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
761  return;
762 }
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:1264
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:56
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 771 of file plugin_rest_namestore.c.

References do_error(), GNUNET_REST_RequestHandlerError::error_code, GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_now(), namestore_add(), namestore_delete(), namestore_get(), options_cont(), RequestHandle::response_code, and RequestHandle::rest_handle.

Referenced by id_connect_cb().

772 {
774  static const struct GNUNET_REST_RequestHandler handlers[] =
775  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get },
776  { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
777  { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete },
778  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont },
780 
781  if (GNUNET_NO ==
782  GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle))
783  {
784  handle->response_code = err.error_code;
786  }
787 }
void namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore DELETE request.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_REST_HANDLER_END
void namestore_add(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore POST request.
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:1264
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:75
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.
void namestore_get(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore GET request.
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ id_connect_cb()

static void id_connect_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  name 
)
static

This function is initially called for all egos and then again whenever a ego's identifier changes or if it is deleted.

At the end of the initial pass over all egos, the function is once called with 'NULL' for 'ego'. That does NOT mean that the callback won't be invoked in the future or that there was an error.

When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', this function is only called ONCE, and 'NULL' being passed in 'ego' does indicate an error (i.e. name is taken or no default value is known). If 'ego' is non-NULL and if '*ctx' is set in those callbacks, the value WILL be passed to a subsequent call to the identity callback of 'GNUNET_IDENTITY_connect' (if that one was not NULL).

When an identity is renamed, this function is called with the (known) ego but the NEW identifier.

When an identity is deleted, this function is called with the (known) ego and "NULL" for the 'identifier'. In this case, the 'ego' is henceforth invalid (and the 'ctx' should also be cleaned up).

Parameters
clsclosure
egoego handle
ctxcontext for application to store data for this ego (during the lifetime of this process, initially NULL)
nameidentifier assigned by the user for this ego, NULL if the user just deleted the ego and it must thus no longer be used

Definition at line 822 of file plugin_rest_namestore.c.

References EgoEntry::ego, RequestHandle::ego_head, RequestHandle::ego_tail, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_IDENTITY_ego_get_public_key(), GNUNET_new, handle, ID_REST_STATE_INIT, ID_REST_STATE_POST_INIT, EgoEntry::identifier, init_cont(), EgoEntry::keystring, and RequestHandle::state.

Referenced by rest_process_request().

826 {
827  struct RequestHandle *handle = cls;
828  struct EgoEntry *ego_entry;
830 
831  if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
832  {
833  handle->state = ID_REST_STATE_POST_INIT;
834  init_cont(handle);
835  return;
836  }
837  if (ID_REST_STATE_INIT == handle->state)
838  {
839  ego_entry = GNUNET_new(struct EgoEntry);
842  ego_entry->ego = ego;
843  GNUNET_asprintf(&ego_entry->identifier, "%s", name);
845  handle->ego_tail,
846  ego_entry);
847  }
848 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
struct EgoEntry * ego_tail
Ego list.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int state
The processing state.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
char * keystring
Public key string.
#define ID_REST_STATE_INIT
State while collecting all egos.
const char * name
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:566
char * identifier
Ego Identifier.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
struct EgoEntry * ego_head
Ego list.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
static void init_cont(struct RequestHandle *handle)
Handle rest 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 863 of file plugin_rest_namestore.c.

References do_error(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_NAMESTORE_connect(), GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, handle, id_connect_cb(), RequestHandle::identity_handle, RequestHandle::ns_handle, 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().

866 {
867  struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
868 
869  handle->response_code = 0;
871  handle->proc_cls = proc_cls;
872  handle->proc = proc;
873  handle->rest_handle = rest_handle;
874  handle->zone_pkey = NULL;
875 
876  handle->url = GNUNET_strdup(rest_handle->url);
877  if (handle->url[strlen(handle->url) - 1] == '/')
878  handle->url[strlen(handle->url) - 1] = '\0';
879  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
880 
882  handle->identity_handle =
884  handle->timeout_task =
885  GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle);
886 
887  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
888 }
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:525
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
static void id_connect_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
This function is initially called for all egos and then again whenever a ego&#39;s identifier changes or ...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#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:1237
const char * url
The url as string.
struct GNUNET_TIME_Relative timeout
Timeout.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
int response_code
HTTP response code.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
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 898 of file plugin_rest_namestore.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_NAMESTORE, GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, and rest_process_request().

899 {
900  static struct Plugin plugin;
901  struct GNUNET_REST_Plugin *api;
902 
903  cfg = cls;
904  if (NULL != plugin.cfg)
905  return NULL; /* can only initialize once! */
906  memset(&plugin, 0, sizeof(struct Plugin));
907  plugin.cfg = cfg;
908  api = GNUNET_new(struct GNUNET_REST_Plugin);
909  api->cls = &plugin;
913  "%s, %s, %s, %s, %s",
914  MHD_HTTP_METHOD_GET,
915  MHD_HTTP_METHOD_POST,
916  MHD_HTTP_METHOD_PUT,
917  MHD_HTTP_METHOD_DELETE,
918  MHD_HTTP_METHOD_OPTIONS);
919 
920  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Namestore REST API initialized\n"));
921  return api;
922 }
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.
void(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
static void rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * name
Plugin name.
static char * allow_methods
HTTP methods allows for this plugin.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
#define GNUNET_log(kind,...)
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 932 of file plugin_rest_namestore.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.

933 {
934  struct GNUNET_REST_Plugin *api = cls;
935  struct Plugin *plugin = api->cls;
936 
937  plugin->cfg = NULL;
938 
940  GNUNET_free(api);
941  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
942  return NULL;
943 }
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.
static char * allow_methods
HTTP methods allows for this plugin.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.

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().