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

GNUnet Identity REST plugin. More...

#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_identity_service.h"
#include "gnunet_rest_lib.h"
#include "microhttpd.h"
#include <jansson.h>
Include dependency graph for plugin_rest_identity.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_IDENTITY   "/identity"
 Identity Namespace. More...
 
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY   "/identity/pubkey"
 Identity Namespace with public key specifier. More...
 
#define GNUNET_REST_API_NS_IDENTITY_NAME   "/identity/name"
 Identity Namespace with public key specifier. More...
 
#define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM   "/identity/subsystem"
 Identity Subsystem Namespace. More...
 
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY   "pubkey"
 Parameter public key. More...
 
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY   "privkey"
 Parameter private key. More...
 
#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM   "subsystem"
 Parameter subsystem. More...
 
#define GNUNET_REST_IDENTITY_PARAM_NAME   "name"
 Parameter name. More...
 
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME   "newname"
 Parameter new name. More...
 
#define GNUNET_REST_IDENTITY_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_IDENTITY_MISSING_NAME   "Missing identity name"
 Error message Missing identity name. More...
 
#define GNUNET_REST_IDENTITY_MISSING_PUBKEY   "Missing identity public key"
 Error message Missing identity name. More...
 
#define GNUNET_REST_ERROR_NO_DATA   "No data"
 Error message No data. More...
 
#define GNUNET_REST_ERROR_DATA_INVALID   "Data invalid"
 Error message Data invalid. 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 (struct RequestHandle *handle, char *pubkey, 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 ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 Callback for GET Request with subsystem. More...
 
void ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request for subsystem. More...
 
void ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request - responds with all identities. More...
 
void ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
 Responds with the ego_entry identity. More...
 
void ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request with a public key. More...
 
void ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request with a name. More...
 
static void do_finished (void *cls, const char *emsg)
 Processing finished. More...
 
static void do_finished_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, const char *emsg)
 Processing finished, when creating an ego. More...
 
void ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry)
 Processing edit ego with EgoEntry ego_entry. More...
 
void ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity PUT request with public key. More...
 
void ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity PUT request with name. More...
 
void ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity subsystem PUT request with name. More...
 
void ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity POST request. More...
 
void ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity DELETE request with public key. More...
 
void ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity DELETE request with name. 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_identity_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_rest_identity_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_IDENTITY_Handleidentity_handle
 Handle to Identity service. More...
 
static struct RequestHandlerequests_head
 DLL. More...
 
static struct RequestHandlerequests_tail
 DLL. More...
 

Detailed Description

GNUnet Identity REST plugin.

Author
Martin Schanzenbach
Philippe Buschmann

Definition in file plugin_rest_identity.c.

Macro Definition Documentation

◆ GNUNET_REST_API_NS_IDENTITY

#define GNUNET_REST_API_NS_IDENTITY   "/identity"

Identity Namespace.

Definition at line 37 of file plugin_rest_identity.c.

Referenced by ego_create(), libgnunet_plugin_rest_identity_init(), and rest_process_request().

◆ GNUNET_REST_API_NS_IDENTITY_PUBKEY

#define GNUNET_REST_API_NS_IDENTITY_PUBKEY   "/identity/pubkey"

Identity Namespace with public key specifier.

Definition at line 42 of file plugin_rest_identity.c.

Referenced by ego_delete_pubkey(), ego_edit_pubkey(), ego_get_pubkey(), and rest_process_request().

◆ GNUNET_REST_API_NS_IDENTITY_NAME

#define GNUNET_REST_API_NS_IDENTITY_NAME   "/identity/name"

Identity Namespace with public key specifier.

Definition at line 47 of file plugin_rest_identity.c.

Referenced by ego_delete_name(), ego_edit_name(), ego_get_name(), and rest_process_request().

◆ GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM

#define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM   "/identity/subsystem"

Identity Subsystem Namespace.

Definition at line 52 of file plugin_rest_identity.c.

Referenced by ego_edit_subsystem(), ego_get_subsystem(), and rest_process_request().

◆ GNUNET_REST_IDENTITY_PARAM_PUBKEY

#define GNUNET_REST_IDENTITY_PARAM_PUBKEY   "pubkey"

Parameter public key.

Definition at line 57 of file plugin_rest_identity.c.

Referenced by ego_get_all(), ego_get_for_subsystem(), and ego_get_response().

◆ GNUNET_REST_IDENTITY_PARAM_PRIVKEY

#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY   "privkey"

Parameter private key.

Definition at line 62 of file plugin_rest_identity.c.

Referenced by ego_create(), ego_get_all(), and ego_get_response().

◆ GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM

#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM   "subsystem"

Parameter subsystem.

Definition at line 67 of file plugin_rest_identity.c.

Referenced by ego_edit_subsystem().

◆ GNUNET_REST_IDENTITY_PARAM_NAME

#define GNUNET_REST_IDENTITY_PARAM_NAME   "name"

Parameter name.

Definition at line 72 of file plugin_rest_identity.c.

Referenced by ego_create(), ego_get_all(), ego_get_for_subsystem(), and ego_get_response().

◆ GNUNET_REST_IDENTITY_PARAM_NEWNAME

#define GNUNET_REST_IDENTITY_PARAM_NEWNAME   "newname"

Parameter new name.

Definition at line 77 of file plugin_rest_identity.c.

Referenced by ego_edit().

◆ GNUNET_REST_IDENTITY_ERROR_UNKNOWN

#define GNUNET_REST_IDENTITY_ERROR_UNKNOWN   "Unknown Error"

Error message Unknown Error.

Definition at line 82 of file plugin_rest_identity.c.

Referenced by do_error().

◆ GNUNET_REST_IDENTITY_NOT_FOUND

#define GNUNET_REST_IDENTITY_NOT_FOUND   "No identity found"

◆ GNUNET_REST_IDENTITY_MISSING_NAME

#define GNUNET_REST_IDENTITY_MISSING_NAME   "Missing identity name"

Error message Missing identity name.

Definition at line 92 of file plugin_rest_identity.c.

Referenced by ego_delete_name(), ego_edit_name(), ego_edit_subsystem(), and ego_get_name().

◆ GNUNET_REST_IDENTITY_MISSING_PUBKEY

#define GNUNET_REST_IDENTITY_MISSING_PUBKEY   "Missing identity public key"

Error message Missing identity name.

Definition at line 97 of file plugin_rest_identity.c.

Referenced by ego_delete_pubkey(), ego_edit_pubkey(), and ego_get_pubkey().

◆ GNUNET_REST_ERROR_NO_DATA

#define GNUNET_REST_ERROR_NO_DATA   "No data"

Error message No data.

Definition at line 102 of file plugin_rest_identity.c.

Referenced by ego_create(), ego_edit(), and ego_edit_subsystem().

◆ GNUNET_REST_ERROR_DATA_INVALID

#define GNUNET_REST_ERROR_DATA_INVALID   "Data invalid"

Error message Data invalid.

Definition at line 107 of file plugin_rest_identity.c.

Referenced by ego_create(), ego_edit(), and ego_edit_subsystem().

◆ ID_REST_STATE_INIT

#define ID_REST_STATE_INIT   0

State while collecting all egos.

Definition at line 112 of file plugin_rest_identity.c.

Referenced by libgnunet_plugin_rest_identity_init(), and list_ego().

◆ ID_REST_STATE_POST_INIT

#define ID_REST_STATE_POST_INIT   1

Done collecting egos.

Definition at line 117 of file plugin_rest_identity.c.

Referenced by list_ego().

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
handleHandle to clean up

Definition at line 279 of file plugin_rest_identity.c.

References RequestHandle::emsg, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), handle, RequestHandle::name, RequestHandle::timeout_task, and RequestHandle::url.

Referenced by do_error(), do_finished(), ego_create(), ego_edit(), ego_get_all(), ego_get_for_subsystem(), ego_get_response(), libgnunet_plugin_rest_identity_done(), options_cont(), and rest_process_request().

280 {
281  struct RequestHandle *handle = cls;
282 
283  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
284  if (NULL != handle->timeout_task)
285  {
287  handle->timeout_task = NULL;
288  }
289 
290  if (NULL != handle->url)
291  GNUNET_free (handle->url);
292  if (NULL != handle->emsg)
293  GNUNET_free (handle->emsg);
294  if (NULL != handle->name)
295  GNUNET_free (handle->name);
298  handle);
299  GNUNET_free (handle);
300 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
The request handle.
char * name
Name to look up.
char * emsg
Error response message.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
#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 309 of file plugin_rest_identity.c.

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

Referenced by do_finished(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_edit_subsystem(), ego_get_for_subsystem(), ego_get_name(), ego_get_pubkey(), ego_get_subsystem(), and rest_process_request().

310 {
311  struct RequestHandle *handle = cls;
312  struct MHD_Response *resp;
313  json_t *json_error = json_object ();
314  char *response;
315 
316  if (NULL == handle->emsg)
318 
319  json_object_set_new (json_error, "error", json_string (handle->emsg));
320 
321  if (0 == handle->response_code)
322  handle->response_code = MHD_HTTP_OK;
323  response = json_dumps (json_error, 0);
324  resp = GNUNET_REST_create_response (response);
325  MHD_add_response_header (resp, "Content-Type", "application/json");
326  handle->proc (handle->proc_cls, resp, handle->response_code);
327  json_decref (json_error);
328  GNUNET_free (response);
330 }
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.
#define GNUNET_REST_IDENTITY_ERROR_UNKNOWN
Error message Unknown Error.
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.
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()

struct EgoEntry* get_egoentry ( struct RequestHandle handle,
char *  pubkey,
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 343 of file plugin_rest_identity.c.

References EgoEntry::identifier, EgoEntry::keystring, and EgoEntry::next.

Referenced by ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_edit_subsystem(), ego_get_name(), and ego_get_pubkey().

344 {
345  struct EgoEntry *ego_entry;
346 
347  if (NULL != pubkey)
348  {
349  for (ego_entry = ego_head; NULL != ego_entry;
350  ego_entry = ego_entry->next)
351  {
352  if (0 != strcasecmp (pubkey, ego_entry->keystring))
353  continue;
354  return ego_entry;
355  }
356  }
357  if (NULL != name)
358  {
359  for (ego_entry = ego_head; NULL != ego_entry;
360  ego_entry = ego_entry->next)
361  {
362  if (0 != strcasecmp (name, ego_entry->identifier))
363  continue;
364  return ego_entry;
365  }
366  }
367  return NULL;
368 }
static struct EgoEntry * ego_head
Ego list.
The ego list.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
char * keystring
Public key string.
char * identifier
Ego Identifier.
const char * name
struct EgoEntry * next
DLL.
Here is the caller graph for this function:

◆ ego_get_for_subsystem()

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

Callback for GET Request with subsystem.

Parameters
clsthe RequestHandle
egothe Ego found
ctxthe context
namethe id of the ego

Definition at line 380 of file plugin_rest_identity.c.

References cleanup_handle(), do_error(), RequestHandle::emsg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_IDENTITY_public_key_to_string(), GNUNET_log, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PUBKEY, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::response_code.

Referenced by ego_get_subsystem().

384 {
385  struct RequestHandle *handle = cls;
386  struct MHD_Response *resp;
387  struct GNUNET_IDENTITY_PublicKey public_key;
388  json_t *json_root;
389  char *result_str;
390  char *public_key_string;
391 
392  if (NULL == ego)
393  {
394  handle->response_code = MHD_HTTP_NOT_FOUND;
397  return;
398  }
399 
400  GNUNET_IDENTITY_ego_get_public_key (ego, &public_key);
401  public_key_string = GNUNET_IDENTITY_public_key_to_string (&public_key);
402 
403  // create json with subsystem identity
404  json_root = json_object ();
405  json_object_set_new (json_root,
407  json_string (public_key_string));
408  json_object_set_new (json_root,
410  json_string (name));
411 
412  result_str = json_dumps (json_root, 0);
413  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
414  resp = GNUNET_REST_create_response (result_str);
415  MHD_add_response_header (resp, "Content-Type", "application/json");
416  json_decref (json_root);
417  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
418  GNUNET_free (result_str);
419  GNUNET_free (public_key_string);
421 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
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_.
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.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
An identity key as per LSD0001.
const char * name
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
#define GNUNET_log(kind,...)
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_subsystem()

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

Handle identity GET request for subsystem.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 432 of file plugin_rest_identity.c.

References do_error(), ego_get_for_subsystem(), RequestHandle::emsg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_get(), GNUNET_log, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::op, RequestHandle::response_code, subsystem, and RequestHandle::url.

Referenced by rest_process_request().

435 {
436  struct RequestHandle *handle = cls;
437  char *subsystem;
438 
439  if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url))
440  {
441  handle->emsg = GNUNET_strdup ("Missing subsystem name");
443  return;
444  }
445  subsystem = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1];
446  // requested default identity of subsystem
447  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem);
448 
450  subsystem,
452  handle);
453 
454  if (NULL == handle->op)
455  {
456  handle->response_code = MHD_HTTP_NOT_FOUND;
459  return;
460  }
461 }
static char * subsystem
Set to subsystem that we&#39;re going to get stats for (or NULL for all).
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, const char *service_name, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Obtain the identity that is currently preferred/default for a service.
Definition: identity_api.c:675
#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.
#define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM
Identity Subsystem Namespace.
int response_code
Response code.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void ego_get_for_subsystem(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Callback for GET Request with subsystem.
#define GNUNET_log(kind,...)
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_all()

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

Handle identity GET request - responds with all identities.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 472 of file plugin_rest_identity.c.

References cleanup_handle(), EgoEntry::ego, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_private_key_to_string(), GNUNET_log, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_PUBKEY, GNUNET_SCHEDULER_add_now(), GNUNET_YES, handle, EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::rest_handle, and GNUNET_REST_RequestHandle::url_param_map.

Referenced by rest_process_request().

475 {
476  struct RequestHandle *handle = cls;
477  struct EgoEntry *ego_entry;
478  struct MHD_Response *resp;
479  struct GNUNET_HashCode key;
480  json_t *json_root;
481  json_t *json_ego;
482  char *result_str;
483  char *privkey_str;
484 
485  json_root = json_array ();
486  // Return ego/egos
487  for (ego_entry = ego_head; NULL != ego_entry;
488  ego_entry = ego_entry->next)
489  {
490  json_ego = json_object ();
491  json_object_set_new (json_ego,
493  json_string (ego_entry->keystring));
494  GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
495  if (GNUNET_YES ==
497  handle->rest_handle->url_param_map, &key))
498  {
501  json_object_set_new (json_ego,
503  json_string (privkey_str));
504  GNUNET_free (privkey_str);
505  }
506 
507  json_object_set_new (json_ego,
509  json_string (ego_entry->identifier));
510  json_array_append (json_root, json_ego);
511  json_decref (json_ego);
512  }
513 
514  result_str = json_dumps (json_root, 0);
515  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
516  resp = GNUNET_REST_create_response (result_str);
517  MHD_add_response_header (resp, "Content-Type", "application/json");
518  json_decref (json_root);
519  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
520  GNUNET_free (result_str);
522 }
static struct EgoEntry * ego_head
Ego list.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
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)...
void * proc_cls
The closure of the result processor.
The request handle.
The ego list.
char * GNUNET_IDENTITY_private_key_to_string(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates a (Base32) string representation of the private key.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
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.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
A 512-bit hashcode.
char * keystring
Public key string.
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
char * identifier
Ego Identifier.
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_IDENTITY_PARAM_PRIVKEY
Parameter private key.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
#define GNUNET_log(kind,...)
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
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:

◆ ego_get_response()

void ego_get_response ( struct RequestHandle handle,
struct EgoEntry ego_entry 
)

Responds with the ego_entry identity.

Parameters
handlethe struct RequestHandle
ego_entrythe struct EgoEntry for the response

Definition at line 532 of file plugin_rest_identity.c.

References cleanup_handle(), EgoEntry::ego, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_private_key_to_string(), GNUNET_log, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_PUBKEY, GNUNET_SCHEDULER_add_now(), GNUNET_YES, EgoEntry::identifier, EgoEntry::keystring, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::rest_handle, and GNUNET_REST_RequestHandle::url_param_map.

Referenced by ego_get_name(), and ego_get_pubkey().

533 {
534  struct MHD_Response *resp;
535  struct GNUNET_HashCode key;
536  json_t *json_ego;
537  char *result_str;
538  char *privkey_str;
539 
540  json_ego = json_object ();
541  json_object_set_new (json_ego,
543  json_string (ego_entry->keystring));
544  json_object_set_new (json_ego,
546  json_string (ego_entry->identifier));
547  GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
548  if (GNUNET_YES ==
550  handle->rest_handle->url_param_map, &key))
551  {
554  json_object_set_new (json_ego,
556  json_string (privkey_str));
557  GNUNET_free (privkey_str);
558  }
559 
560  result_str = json_dumps (json_ego, 0);
561  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
562  resp = GNUNET_REST_create_response (result_str);
563  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
564  MHD_add_response_header (resp, "Content-Type", "application/json");
565  json_decref (json_ego);
566  GNUNET_free (result_str);
568 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
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)...
void * proc_cls
The closure of the result processor.
char * GNUNET_IDENTITY_private_key_to_string(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates a (Base32) string representation of the private key.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
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
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
A 512-bit hashcode.
char * keystring
Public key string.
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
char * identifier
Ego Identifier.
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_IDENTITY_PARAM_PRIVKEY
Parameter private key.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
#define GNUNET_log(kind,...)
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_pubkey()

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

Handle identity GET request with a public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 579 of file plugin_rest_identity.c.

References do_error(), ego_get_response(), RequestHandle::emsg, get_egoentry(), GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_REST_IDENTITY_MISSING_PUBKEY, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::keystring, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

582 {
583  struct RequestHandle *handle = cls;
584  struct EgoEntry *ego_entry;
585  char *keystring;
586 
587  keystring = NULL;
588 
589  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
590  {
591  handle->response_code = MHD_HTTP_NOT_FOUND;
594  return;
595  }
596  keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1];
597  ego_entry = get_egoentry (handle, keystring, NULL);
598 
599  if (NULL == ego_entry)
600  {
601  handle->response_code = MHD_HTTP_NOT_FOUND;
604  return;
605  }
606 
607  ego_get_response (handle, ego_entry);
608 }
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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.
char * keystring
Public key string.
void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
#define GNUNET_REST_IDENTITY_MISSING_PUBKEY
Error message Missing identity name.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_name()

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

Handle identity GET request with a name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 619 of file plugin_rest_identity.c.

References do_error(), ego_get_response(), RequestHandle::emsg, get_egoentry(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_IDENTITY_MISSING_NAME, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

622 {
623  struct RequestHandle *handle = cls;
624  struct EgoEntry *ego_entry;
625  char *egoname;
626 
627  egoname = NULL;
628 
629  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
630  {
631  handle->response_code = MHD_HTTP_NOT_FOUND;
634  return;
635  }
636  egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
637  ego_entry = get_egoentry (handle, NULL, egoname);
638 
639  if (NULL == ego_entry)
640  {
641  handle->response_code = MHD_HTTP_NOT_FOUND;
644  return;
645  }
646 
647  ego_get_response (handle, ego_entry);
648 }
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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
#define GNUNET_REST_IDENTITY_MISSING_NAME
Error message Missing identity name.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_finished()

static void do_finished ( void *  cls,
const char *  emsg 
)
static

Processing finished.

Parameters
clsrequest handle
emsgerror message

Definition at line 658 of file plugin_rest_identity.c.

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

Referenced by do_finished_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), and ego_edit_subsystem().

659 {
660  struct RequestHandle *handle = cls;
661  struct MHD_Response *resp;
662 
663  handle->op = NULL;
664  if (NULL != emsg)
665  {
666  handle->emsg = GNUNET_strdup (emsg);
668  return;
669  }
670  if (0 == handle->response_code)
671  {
672  handle->response_code = MHD_HTTP_NO_CONTENT;
673  }
674  resp = GNUNET_REST_create_response (NULL);
675  handle->proc (handle->proc_cls, resp, handle->response_code);
677 }
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.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_finished_create()

static void do_finished_create ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey pk,
const char *  emsg 
)
static

Processing finished, when creating an ego.

Parameters
clsrequest handle
privatekey of the ego, or NULL on error
emsgerror message

Definition at line 688 of file plugin_rest_identity.c.

References do_finished(), and handle.

Referenced by ego_create().

691 {
692  struct RequestHandle *handle = cls;
693 
694  (void) pk;
695  do_finished (handle, emsg);
696 }
static void do_finished(void *cls, const char *emsg)
Processing finished.
The request handle.
char * emsg
Error response message.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_edit()

void ego_edit ( struct RequestHandle handle,
struct EgoEntry ego_entry 
)

Processing edit ego with EgoEntry ego_entry.

Parameters
handlethe struct RequestHandle
ego_entrythe struct EgoEntry we want to edit

Definition at line 706 of file plugin_rest_identity.c.

References cleanup_handle(), RequestHandle::data, RequestHandle::data_size, do_error(), do_finished(), RequestHandle::emsg, get_egoentry(), GNUNET_IDENTITY_rename(), GNUNET_memcpy, GNUNET_REST_create_response(), GNUNET_REST_ERROR_DATA_INVALID, GNUNET_REST_ERROR_NO_DATA, GNUNET_REST_IDENTITY_PARAM_NEWNAME, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, EgoEntry::identifier, RequestHandle::op, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by ego_edit_name(), and ego_edit_pubkey().

707 {
708  struct EgoEntry *ego_entry_tmp;
709  struct MHD_Response *resp;
710  json_t *data_js;
711  json_error_t err;
712  char *newname;
713  char term_data[handle->data_size + 1];
714  int json_state;
715 
716  // if no data
717  if (0 >= handle->data_size)
718  {
721  return;
722  }
723  // if not json
724  term_data[handle->data_size] = '\0';
725  GNUNET_memcpy (term_data, handle->data, handle->data_size);
726  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
727 
728  if (NULL == data_js)
729  {
732  return;
733  }
734 
735  newname = NULL;
736  // NEW NAME
737  json_state = 0;
738  json_state = json_unpack (data_js,
739  "{s:s!}",
741  &newname);
742  // Change name with pubkey or name identifier
743  if (0 != json_state)
744  {
747  json_decref (data_js);
748  return;
749  }
750 
751  if (NULL == newname)
752  {
755  json_decref (data_js);
756  return;
757  }
758 
759  if (0 >= strlen (newname))
760  {
763  json_decref (data_js);
764  return;
765  }
766 
767  ego_entry_tmp = get_egoentry (handle, NULL, newname);
768  if (NULL != ego_entry_tmp)
769  {
770  // Ego with same name not allowed (even if its the ego we change)
771  resp = GNUNET_REST_create_response (NULL);
772  handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
774  json_decref (data_js);
775  return;
776  }
778  ego_entry->identifier,
779  newname,
780  &do_finished,
781  handle);
782  if (NULL == handle->op)
783  {
784  handle->emsg = GNUNET_strdup ("Rename failed");
786  json_decref (data_js);
787  return;
788  }
789  json_decref (data_js);
790  return;
791 }
#define GNUNET_REST_ERROR_NO_DATA
Error message No data.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
size_t data_size
the length of the REST data
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void do_finished(void *cls, const char *emsg)
Processing finished.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
The ego list.
#define GNUNET_REST_ERROR_DATA_INVALID
Error message Data invalid.
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_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
char * identifier
Ego Identifier.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
const char * data
The data from the REST request.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing identity.
Definition: identity_api.c:810
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_edit_pubkey()

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

Handle identity PUT request with public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 802 of file plugin_rest_identity.c.

References do_error(), ego_edit(), RequestHandle::emsg, get_egoentry(), GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_REST_IDENTITY_MISSING_PUBKEY, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::keystring, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

805 {
806  struct RequestHandle *handle = cls;
807  struct EgoEntry *ego_entry;
808  char *keystring;
809 
810  keystring = NULL;
811 
812  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
813  {
814  handle->response_code = MHD_HTTP_NOT_FOUND;
817  return;
818  }
819  keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1];
820  ego_entry = get_egoentry (handle, keystring, NULL);
821 
822  if (NULL == ego_entry)
823  {
824  handle->response_code = MHD_HTTP_NOT_FOUND;
827  return;
828  }
829 
830  ego_edit (handle, ego_entry);
831 }
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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.
void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
int response_code
Response code.
char * keystring
Public key string.
#define GNUNET_REST_IDENTITY_MISSING_PUBKEY
Error message Missing identity name.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_edit_name()

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

Handle identity PUT request with name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 842 of file plugin_rest_identity.c.

References do_error(), ego_edit(), RequestHandle::emsg, get_egoentry(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_IDENTITY_MISSING_NAME, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, Plugin::name, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

845 {
846  struct RequestHandle *handle = cls;
847  struct EgoEntry *ego_entry;
848  char *name;
849 
850  name = NULL;
851 
852  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
853  {
854  handle->response_code = MHD_HTTP_NOT_FOUND;
857  return;
858  }
859  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
860  ego_entry = get_egoentry (handle, NULL, name);
861 
862  if (NULL == ego_entry)
863  {
864  handle->response_code = MHD_HTTP_NOT_FOUND;
867  return;
868  }
869 
870  ego_edit (handle, ego_entry);
871 }
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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
#define GNUNET_REST_IDENTITY_MISSING_NAME
Error message Missing identity name.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
int response_code
Response code.
const char * name
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_edit_subsystem()

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

Handle identity subsystem PUT request with name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 882 of file plugin_rest_identity.c.

References RequestHandle::data, RequestHandle::data_size, do_error(), do_finished(), EgoEntry::ego, RequestHandle::emsg, get_egoentry(), GNUNET_IDENTITY_set(), GNUNET_memcpy, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, GNUNET_REST_ERROR_DATA_INVALID, GNUNET_REST_ERROR_NO_DATA, GNUNET_REST_IDENTITY_MISSING_NAME, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, Plugin::name, RequestHandle::op, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

885 {
886  struct RequestHandle *handle = cls;
887  struct EgoEntry *ego_entry;
888  json_t *data_js;
889  json_error_t err;
890  char *newsubsys;
891  char *name;
892  char term_data[handle->data_size + 1];
893  int json_state;
894 
895  name = NULL;
896 
897  if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url))
898  {
899  handle->response_code = MHD_HTTP_NOT_FOUND;
902  return;
903  }
904  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1];
905  ego_entry = get_egoentry (handle, NULL, name);
906 
907  if (NULL == ego_entry)
908  {
909  handle->response_code = MHD_HTTP_NOT_FOUND;
912  return;
913  }
914 
915  // if no data
916  if (0 >= handle->data_size)
917  {
920  return;
921  }
922  // if not json
923  term_data[handle->data_size] = '\0';
924  GNUNET_memcpy (term_data, handle->data, handle->data_size);
925  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
926 
927  if (NULL == data_js)
928  {
931  return;
932  }
933 
934  newsubsys = NULL;
935  // SUBSYSTEM
936  json_state = 0;
937  json_state = json_unpack (data_js,
938  "{s:s!}",
940  &newsubsys);
941  // Change subsystem with pubkey or name identifier
942  if (0 != json_state)
943  {
946  json_decref (data_js);
947  return;
948  }
949 
950  if (NULL == newsubsys)
951  {
954  json_decref (data_js);
955  return;
956  }
957 
958  if (0 >= strlen (newsubsys))
959  {
962  json_decref (data_js);
963  return;
964  }
965 
966  handle->response_code = MHD_HTTP_NO_CONTENT;
968  newsubsys,
969  ego_entry->ego,
970  &do_finished,
971  handle);
972  if (NULL == handle->op)
973  {
974  handle->emsg = GNUNET_strdup ("Setting subsystem failed");
976  return;
977  }
978  json_decref (data_js);
979  return;
980 }
#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM
Parameter subsystem.
#define GNUNET_REST_ERROR_NO_DATA
Error message No data.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h, const char *service_name, struct GNUNET_IDENTITY_Ego *ego, GNUNET_IDENTITY_Continuation cont, void *cont_cls)
Set the preferred/default identity for a service.
Definition: identity_api.c:720
size_t data_size
the length of the REST data
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void do_finished(void *cls, const char *emsg)
Processing finished.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
#define GNUNET_REST_ERROR_DATA_INVALID
Error message Data invalid.
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
#define GNUNET_REST_IDENTITY_MISSING_NAME
Error message Missing identity name.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM
Identity Subsystem Namespace.
int response_code
Response code.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
const char * name
const char * data
The data from the REST request.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_create()

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

Handle identity POST request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 991 of file plugin_rest_identity.c.

References cleanup_handle(), RequestHandle::data, RequestHandle::data_size, do_error(), do_finished_create(), RequestHandle::emsg, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_memcpy, GNUNET_REST_API_NS_IDENTITY, GNUNET_REST_create_response(), GNUNET_REST_ERROR_DATA_INVALID, GNUNET_REST_ERROR_NO_DATA, GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_STRINGS_string_to_data(), GNUNET_STRINGS_utf8_tolower(), handle, EgoEntry::identifier, RequestHandle::name, EgoEntry::next, RequestHandle::op, pk, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

994 {
995  struct RequestHandle *handle = cls;
996  struct EgoEntry *ego_entry;
997  struct MHD_Response *resp;
998  json_t *data_js;
999  json_error_t err;
1000  char *egoname;
1001  char *privkey;
1003  struct GNUNET_IDENTITY_PrivateKey *pk_ptr;
1004  int json_unpack_state;
1005  char term_data[handle->data_size + 1];
1006 
1007  if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
1008  {
1010  return;
1011  }
1012 
1013  if (0 >= handle->data_size)
1014  {
1017  return;
1018  }
1019  term_data[handle->data_size] = '\0';
1020  GNUNET_memcpy (term_data, handle->data, handle->data_size);
1021  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
1022  if (NULL == data_js)
1023  {
1026  json_decref (data_js);
1027  return;
1028  }
1029  json_unpack_state = 0;
1030  privkey = NULL;
1031  json_unpack_state =
1032  json_unpack (data_js, "{s:s, s?:s!}",
1035  if (0 != json_unpack_state)
1036  {
1039  json_decref (data_js);
1040  return;
1041  }
1042 
1043  if (NULL == egoname)
1044  {
1047  json_decref (data_js);
1048  return;
1049  }
1050  if (0 >= strlen (egoname))
1051  {
1052  json_decref (data_js);
1055  return;
1056  }
1057  GNUNET_STRINGS_utf8_tolower (egoname, egoname);
1058  for (ego_entry = ego_head; NULL != ego_entry;
1059  ego_entry = ego_entry->next)
1060  {
1061  if (0 == strcasecmp (egoname, ego_entry->identifier))
1062  {
1063  resp = GNUNET_REST_create_response (NULL);
1064  handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
1066  json_decref (data_js);
1067  return;
1068  }
1069  }
1070  handle->name = GNUNET_strdup (egoname);
1071  if (NULL != privkey)
1072  {
1074  strlen (privkey),
1075  &pk,
1076  sizeof(struct
1078  pk_ptr = &pk;
1079  }
1080  else
1081  pk_ptr = NULL;
1082  json_decref (data_js);
1083  handle->response_code = MHD_HTTP_CREATED;
1085  handle->name,
1086  pk_ptr,
1089  handle);
1090 }
#define GNUNET_REST_ERROR_NO_DATA
Error message No data.
static struct EgoEntry * ego_head
Ego list.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
size_t data_size
the length of the REST data
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
The request handle.
The ego list.
#define GNUNET_REST_ERROR_DATA_INVALID
Error message Data invalid.
char * name
Name to look up.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:757
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 do_finished_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, const char *emsg)
Processing finished, when creating an ego.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
char * identifier
Ego Identifier.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
const char * data
The data from the REST request.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
static void do_error(void *cls)
Task run on errors.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
struct EgoEntry * next
DLL.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:568
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_delete_pubkey()

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

Handle identity DELETE request with public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1101 of file plugin_rest_identity.c.

References do_error(), do_finished(), RequestHandle::emsg, get_egoentry(), GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_REST_IDENTITY_MISSING_PUBKEY, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, EgoEntry::keystring, RequestHandle::op, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

1104 {
1105  struct RequestHandle *handle = cls;
1106  struct EgoEntry *ego_entry;
1107  char *keystring;
1108 
1109  keystring = NULL;
1110 
1111  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
1112  {
1113  handle->response_code = MHD_HTTP_NOT_FOUND;
1116  return;
1117  }
1118  keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1];
1119  ego_entry = get_egoentry (handle, keystring, NULL);
1120 
1121  if (NULL == ego_entry)
1122  {
1123  handle->response_code = MHD_HTTP_NOT_FOUND;
1126  return;
1127  }
1128 
1129  handle->response_code = MHD_HTTP_NO_CONTENT;
1131  ego_entry->identifier,
1132  &do_finished,
1133  handle);
1134 }
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing identity.
Definition: identity_api.c:863
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
static void do_finished(void *cls, const char *emsg)
Processing finished.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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.
char * keystring
Public key string.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
char * identifier
Ego Identifier.
#define GNUNET_REST_IDENTITY_MISSING_PUBKEY
Error message Missing identity name.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_delete_name()

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

Handle identity DELETE request with name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1145 of file plugin_rest_identity.c.

References do_error(), do_finished(), RequestHandle::emsg, get_egoentry(), GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_IDENTITY_MISSING_NAME, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, Plugin::name, RequestHandle::op, RequestHandle::response_code, and RequestHandle::url.

Referenced by rest_process_request().

1148 {
1149  struct RequestHandle *handle = cls;
1150  struct EgoEntry *ego_entry;
1151  char *name;
1152 
1153  name = NULL;
1154 
1155  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
1156  {
1157  handle->response_code = MHD_HTTP_NOT_FOUND;
1160  return;
1161  }
1162  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
1163  ego_entry = get_egoentry (handle, NULL, name);
1164 
1165  if (NULL == ego_entry)
1166  {
1167  handle->response_code = MHD_HTTP_NOT_FOUND;
1170  return;
1171  }
1172 
1173  handle->response_code = MHD_HTTP_NO_CONTENT;
1175  ego_entry->identifier,
1176  &do_finished,
1177  handle);
1178 }
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing identity.
Definition: identity_api.c:863
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
static void do_finished(void *cls, const char *emsg)
Processing finished.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
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
#define GNUNET_REST_IDENTITY_MISSING_NAME
Error message Missing identity name.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
char * identifier
Ego Identifier.
const char * name
static void do_error(void *cls)
Task run on errors.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
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 1189 of file plugin_rest_identity.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().

1192 {
1193  struct MHD_Response *resp;
1194  struct RequestHandle *handle = cls;
1195 
1196  // For now, independent of path return all options
1197  resp = GNUNET_REST_create_response (NULL);
1198  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
1199  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1201  return;
1202 }
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 void cleanup_handle(void *cls)
Cleanup lookup handle.
static char * allow_methods
HTTP methods allows for this plugin.
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 1206 of file plugin_rest_identity.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_identity_init().

1210 {
1211  struct EgoEntry *ego_entry;
1213 
1214  if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1215  {
1217  return;
1218  }
1219  if (ID_REST_STATE_INIT == state)
1220  {
1221  ego_entry = GNUNET_new (struct EgoEntry);
1224  ego_entry->ego = ego;
1225  ego_entry->identifier = GNUNET_strdup (identifier);
1227  ego_tail,
1228  ego_entry);
1229  }
1230  /* Ego renamed or added */
1231  if (identifier != NULL)
1232  {
1233  for (ego_entry = ego_head; NULL != ego_entry;
1234  ego_entry = ego_entry->next)
1235  {
1236  if (ego_entry->ego == ego)
1237  {
1238  /* Rename */
1239  GNUNET_free (ego_entry->identifier);
1240  ego_entry->identifier = GNUNET_strdup (identifier);
1241  break;
1242  }
1243  }
1244  if (NULL == ego_entry)
1245  {
1246  /* Add */
1247  ego_entry = GNUNET_new (struct EgoEntry);
1250  ego_entry->ego = ego;
1251  ego_entry->identifier = GNUNET_strdup (identifier);
1253  ego_tail,
1254  ego_entry);
1255  }
1256  }
1257  else
1258  {
1259  /* Delete */
1260  for (ego_entry = ego_head; NULL != ego_entry;
1261  ego_entry = ego_entry->next)
1262  {
1263  if (ego_entry->ego == ego)
1264  break;
1265  }
1266  if (NULL == ego_entry)
1267  return; /* Not found */
1268 
1270  ego_tail,
1271  ego_entry);
1272  GNUNET_free (ego_entry->identifier);
1273  GNUNET_free (ego_entry->keystring);
1274  GNUNET_free (ego_entry);
1275  return;
1276  }
1277 
1278 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
static struct EgoEntry * ego_head
Ego list.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
static struct EgoEntry * ego_tail
Ego list.
#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.
char * keystring
Public key string.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
char * identifier
Ego Identifier.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static int state
The processing state.
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
#define ID_REST_STATE_INIT
State while collecting all egos.
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 1293 of file plugin_rest_identity.c.

References cleanup_handle(), GNUNET_REST_RequestHandle::data, RequestHandle::data, GNUNET_REST_RequestHandle::data_size, RequestHandle::data_size, do_error(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit_name(), ego_edit_pubkey(), ego_edit_subsystem(), ego_get_all(), ego_get_name(), ego_get_pubkey(), ego_get_subsystem(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_IDENTITY, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, 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, and RequestHandle::url.

Referenced by libgnunet_plugin_rest_identity_init().

1296 {
1297  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1299  static const struct GNUNET_REST_RequestHandler handlers[] =
1300  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1301  &ego_get_pubkey },
1302  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1303  { MHD_HTTP_METHOD_GET,
1305  &ego_get_subsystem },
1306  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1307  { MHD_HTTP_METHOD_PUT,
1309  &ego_edit_pubkey },
1310  { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1311  { MHD_HTTP_METHOD_PUT,
1313  &ego_edit_subsystem },
1314  { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1315  { MHD_HTTP_METHOD_DELETE,
1317  &ego_delete_pubkey },
1318  { MHD_HTTP_METHOD_DELETE,
1320  &ego_delete_name },
1321  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1323 
1324 
1325  handle->response_code = 0;
1327  handle->proc_cls = proc_cls;
1328  handle->proc = proc;
1329  handle->rest_handle = rest_handle;
1330  handle->data = rest_handle->data;
1331  handle->data_size = rest_handle->data_size;
1332 
1333  handle->url = GNUNET_strdup (rest_handle->url);
1334  if (handle->url[strlen (handle->url) - 1] == '/')
1335  handle->url[strlen (handle->url) - 1] = '\0';
1336  handle->timeout_task =
1337  GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle);
1339  requests_tail,
1340  handle);
1341  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1342  if (GNUNET_NO ==
1343  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1344  {
1345  cleanup_handle (handle);
1346  return GNUNET_NO;
1347  }
1348 
1349  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1350  return GNUNET_YES;
1351 }
void ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with name.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
size_t data_size
The POST data size.
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
void ego_get_subsystem(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request for subsystem.
size_t data_size
the length of the REST data
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
void * proc_cls
The closure of the result processor.
#define GNUNET_REST_HANDLER_END
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
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: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".
#define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM
Identity Subsystem Namespace.
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.
const char * data
The POST data.
void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
const char * data
The data from the REST request.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
#define GNUNET_log(kind,...)
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
static void do_error(void *cls)
Task run on errors.
void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
void ego_edit_subsystem(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity subsystem PUT request with name.
void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
char * url
The url.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_rest_identity_init()

void* libgnunet_plugin_rest_identity_init ( void *  cls)

Entry point for the plugin.

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

Definition at line 1361 of file plugin_rest_identity.c.

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

1362 {
1363  static struct Plugin plugin;
1364  struct GNUNET_REST_Plugin *api;
1365 
1366  cfg = cls;
1367  if (NULL != plugin.cfg)
1368  return NULL; /* can only initialize once! */
1369  memset (&plugin, 0, sizeof(struct Plugin));
1370  plugin.cfg = cfg;
1371  api = GNUNET_new (struct GNUNET_REST_Plugin);
1372  api->cls = &plugin;
1376  "%s, %s, %s, %s, %s",
1377  MHD_HTTP_METHOD_GET,
1378  MHD_HTTP_METHOD_POST,
1379  MHD_HTTP_METHOD_PUT,
1380  MHD_HTTP_METHOD_DELETE,
1381  MHD_HTTP_METHOD_OPTIONS);
1384 
1385  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1386  return api;
1387 }
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
void * cls
The closure of the plugin.
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.
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:184
char * name
Plugin name.
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
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 struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static char * allow_methods
HTTP methods allows for this plugin.
Handle for a plugin.
Definition: block.c:37
static int state
The processing state.
#define GNUNET_log(kind,...)
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
#define ID_REST_STATE_INIT
State while collecting all egos.
Here is the call graph for this function:

◆ libgnunet_plugin_rest_identity_done()

void* libgnunet_plugin_rest_identity_done ( void *  cls)

Exit point from the plugin.

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

Definition at line 1397 of file plugin_rest_identity.c.

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

1398 {
1399  struct GNUNET_REST_Plugin *api = cls;
1400  struct Plugin *plugin = api->cls;
1401  struct EgoEntry *ego_entry;
1402  struct EgoEntry *ego_tmp;
1403 
1404  plugin->cfg = NULL;
1405  while (NULL != requests_head)
1407  if (NULL != identity_handle)
1409 
1410  for (ego_entry = ego_head; NULL != ego_entry;)
1411  {
1412  ego_tmp = ego_entry;
1413  ego_entry = ego_entry->next;
1414  GNUNET_free (ego_tmp->identifier);
1415  GNUNET_free (ego_tmp->keystring);
1416  GNUNET_free (ego_tmp);
1417  }
1418 
1420  GNUNET_free (api);
1421  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1422  return NULL;
1423 }
void * cls
The closure of the plugin.
static struct EgoEntry * ego_head
Ego list.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct returned by the initialization function of the plugin
static struct RequestHandle * requests_head
DLL.
The 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 struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static char * allow_methods
HTTP methods allows for this plugin.
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 122 of file plugin_rest_identity.c.

◆ allow_methods

char* allow_methods
static

HTTP methods allows for this plugin.

Definition at line 127 of file plugin_rest_identity.c.

Referenced by libgnunet_plugin_rest_identity_done(), libgnunet_plugin_rest_identity_init(), and options_cont().

◆ ego_head

struct EgoEntry* ego_head
static

Ego list.

Definition at line 132 of file plugin_rest_identity.c.

◆ ego_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 137 of file plugin_rest_identity.c.

◆ state

int state
static

The processing state.

Definition at line 142 of file plugin_rest_identity.c.

Referenced by libgnunet_plugin_rest_identity_init(), and list_ego().

◆ identity_handle

struct GNUNET_IDENTITY_Handle* identity_handle
static

Handle to Identity service.

Definition at line 147 of file plugin_rest_identity.c.

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 267 of file plugin_rest_identity.c.

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 272 of file plugin_rest_identity.c.