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.

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

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

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

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

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

◆ GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM

#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM   "subsystem"

Parameter subsystem.

Definition at line 67 of file plugin_rest_identity.c.

◆ GNUNET_REST_IDENTITY_PARAM_NAME

#define GNUNET_REST_IDENTITY_PARAM_NAME   "name"

Parameter name.

Definition at line 72 of file plugin_rest_identity.c.

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

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

◆ GNUNET_REST_IDENTITY_NOT_FOUND

#define GNUNET_REST_IDENTITY_NOT_FOUND   "No identity found"

Error message No identity found.

Definition at line 87 of file plugin_rest_identity.c.

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

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

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

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

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

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

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.

280 {
281  struct RequestHandle *handle = cls;
282 
283  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
284  if (NULL != handle->timeout_task)
285  {
286  GNUNET_SCHEDULER_cancel (handle->timeout_task);
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);
300 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_log(kind,...)
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_ERROR_TYPE_DEBUG
#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
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
The request handle.

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.

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

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.

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);
325  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
326  "Content-Type",
327  "application/json"));
328  handle->proc (handle->proc_cls, resp, handle->response_code);
329  json_decref (json_error);
332 }
static struct MHD_Response * response
Our canonical response.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
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_ERROR_UNKNOWN
Error message Unknown Error.
static void cleanup_handle(void *cls)
Cleanup lookup handle.

References cleanup_handle(), GNUNET_assert, GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_ERROR_UNKNOWN, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, and response.

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

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 345 of file plugin_rest_identity.c.

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

References ego_head, EgoEntry::identifier, EgoEntry::keystring, name, EgoEntry::next, and pubkey.

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

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 382 of file plugin_rest_identity.c.

386 {
387  struct RequestHandle *handle = cls;
388  struct MHD_Response *resp;
389  struct GNUNET_IDENTITY_PublicKey public_key;
390  json_t *json_root;
391  char *result_str;
392  char *public_key_string;
393 
394  if (NULL == ego)
395  {
396  handle->response_code = MHD_HTTP_NOT_FOUND;
399  return;
400  }
401 
402  GNUNET_IDENTITY_ego_get_public_key (ego, &public_key);
403  public_key_string = GNUNET_IDENTITY_public_key_to_string (&public_key);
404 
405  // create json with subsystem identity
406  json_root = json_object ();
407  json_object_set_new (json_root,
409  json_string (public_key_string));
410  json_object_set_new (json_root,
412  json_string (name));
413 
414  result_str = json_dumps (json_root, 0);
415  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
416  resp = GNUNET_REST_create_response (result_str);
417  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
418  "Content-Type",
419  "application/json"));
420  json_decref (json_root);
421  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
422  GNUNET_free (result_str);
423  GNUNET_free (public_key_string);
425 }
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
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
static void do_error(void *cls)
Task run on errors.
An identity key as per LSD0001.

References cleanup_handle(), do_error(), GNUNET_assert, 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, and name.

Referenced by ego_get_subsystem().

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 436 of file plugin_rest_identity.c.

439 {
440  struct RequestHandle *handle = cls;
441  char *subsystem;
442 
443  if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url))
444  {
445  handle->emsg = GNUNET_strdup ("Missing subsystem name");
447  return;
448  }
450  // requested default identity of subsystem
451  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem);
452 
454  subsystem,
456  handle);
457 
458  if (NULL == handle->op)
459  {
460  handle->response_code = MHD_HTTP_NOT_FOUND;
463  return;
464  }
465 }
static char * subsystem
Set to subsystem that we'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_REST_API_NS_IDENTITY_SUBSYSTEM
Identity Subsystem Namespace.
static void ego_get_for_subsystem(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Callback for GET Request with subsystem.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.

References do_error(), ego_get_for_subsystem(), 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, identity_handle, and subsystem.

Here is the call 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 476 of file plugin_rest_identity.c.

479 {
480  struct RequestHandle *handle = cls;
481  struct EgoEntry *ego_entry;
482  struct MHD_Response *resp;
483  struct GNUNET_HashCode key;
484  json_t *json_root;
485  json_t *json_ego;
486  char *result_str;
487  char *privkey_str;
488 
489  json_root = json_array ();
490  // Return ego/egos
491  for (ego_entry = ego_head; NULL != ego_entry;
492  ego_entry = ego_entry->next)
493  {
494  json_ego = json_object ();
495  json_object_set_new (json_ego,
497  json_string (ego_entry->keystring));
498  GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
499  if (GNUNET_YES ==
501  handle->rest_handle->url_param_map, &key))
502  {
505  json_object_set_new (json_ego,
507  json_string (privkey_str));
508  GNUNET_free (privkey_str);
509  }
510 
511  json_object_set_new (json_ego,
513  json_string (ego_entry->identifier));
514  json_array_append (json_root, json_ego);
515  json_decref (json_ego);
516  }
517 
518  result_str = json_dumps (json_root, 0);
519  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
520  resp = GNUNET_REST_create_response (result_str);
521  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
522  "Content-Type",
523  "application/json"));
524  json_decref (json_root);
525  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
526  GNUNET_free (result_str);
528 }
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_YES
Definition: gnunet_common.h:97
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
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).
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
char * GNUNET_IDENTITY_private_key_to_string(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates a (Base32) string representation of the private key.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
A 512-bit hashcode.

References cleanup_handle(), EgoEntry::ego, ego_head, GNUNET_assert, 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, key, EgoEntry::keystring, and EgoEntry::next.

Here is the call 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 538 of file plugin_rest_identity.c.

539 {
540  struct MHD_Response *resp;
541  struct GNUNET_HashCode key;
542  json_t *json_ego;
543  char *result_str;
544  char *privkey_str;
545 
546  json_ego = json_object ();
547  json_object_set_new (json_ego,
549  json_string (ego_entry->keystring));
550  json_object_set_new (json_ego,
552  json_string (ego_entry->identifier));
553  GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
554  if (GNUNET_YES ==
556  handle->rest_handle->url_param_map, &key))
557  {
560  json_object_set_new (json_ego,
562  json_string (privkey_str));
563  GNUNET_free (privkey_str);
564  }
565 
566  result_str = json_dumps (json_ego, 0);
567  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
568  resp = GNUNET_REST_create_response (result_str);
569  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
570  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
571  "Content-Type",
572  "application/json"));
573  json_decref (json_ego);
574  GNUNET_free (result_str);
576 }

References cleanup_handle(), EgoEntry::ego, GNUNET_assert, 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, key, and EgoEntry::keystring.

Referenced by ego_get_name(), and ego_get_pubkey().

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 587 of file plugin_rest_identity.c.

590 {
591  struct RequestHandle *handle = cls;
592  struct EgoEntry *ego_entry;
593  char *keystring;
594 
595  keystring = NULL;
596 
597  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
598  {
599  handle->response_code = MHD_HTTP_NOT_FOUND;
602  return;
603  }
605  ego_entry = get_egoentry (handle, keystring, NULL);
606 
607  if (NULL == ego_entry)
608  {
609  handle->response_code = MHD_HTTP_NOT_FOUND;
612  return;
613  }
614 
615  ego_get_response (handle, ego_entry);
616 }
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_IDENTITY_MISSING_PUBKEY
Error message Missing identity name.
void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.

References do_error(), ego_get_response(), 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, and EgoEntry::keystring.

Here is the call 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 627 of file plugin_rest_identity.c.

630 {
631  struct RequestHandle *handle = cls;
632  struct EgoEntry *ego_entry;
633  char *egoname;
634 
635  egoname = NULL;
636 
637  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
638  {
639  handle->response_code = MHD_HTTP_NOT_FOUND;
642  return;
643  }
644  egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
645  ego_entry = get_egoentry (handle, NULL, egoname);
646 
647  if (NULL == ego_entry)
648  {
649  handle->response_code = MHD_HTTP_NOT_FOUND;
652  return;
653  }
654 
655  ego_get_response (handle, ego_entry);
656 }
#define GNUNET_REST_IDENTITY_MISSING_NAME
Error message Missing identity name.
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.

References do_error(), ego_get_response(), get_egoentry(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_IDENTITY_MISSING_NAME, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.

Here is the call 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 666 of file plugin_rest_identity.c.

667 {
668  struct RequestHandle *handle = cls;
669  struct MHD_Response *resp;
670 
671  handle->op = NULL;
672  if (NULL != emsg)
673  {
674  handle->emsg = GNUNET_strdup (emsg);
676  return;
677  }
678  if (0 == handle->response_code)
679  {
680  handle->response_code = MHD_HTTP_NO_CONTENT;
681  }
682  resp = GNUNET_REST_create_response (NULL);
683  handle->proc (handle->proc_cls, resp, handle->response_code);
685 }

References cleanup_handle(), do_error(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.

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

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 696 of file plugin_rest_identity.c.

699 {
700  struct RequestHandle *handle = cls;
701 
702  (void) pk;
704 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static void do_finished(void *cls, const char *emsg)
Processing finished.
char * emsg
Error response message.

References do_finished(), RequestHandle::emsg, handle, and pk.

Referenced by ego_create().

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 714 of file plugin_rest_identity.c.

715 {
716  struct EgoEntry *ego_entry_tmp;
717  struct MHD_Response *resp;
718  json_t *data_js;
719  json_error_t err;
720  char *newname;
721  char term_data[handle->data_size + 1];
722  int json_state;
723 
724  // if no data
725  if (0 >= handle->data_size)
726  {
729  return;
730  }
731  // if not json
732  term_data[handle->data_size] = '\0';
733  GNUNET_memcpy (term_data, handle->data, handle->data_size);
734  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
735 
736  if (NULL == data_js)
737  {
740  return;
741  }
742 
743  newname = NULL;
744  // NEW NAME
745  json_state = 0;
746  json_state = json_unpack (data_js,
747  "{s:s!}",
749  &newname);
750  // Change name with pubkey or name identifier
751  if (0 != json_state)
752  {
755  json_decref (data_js);
756  return;
757  }
758 
759  if (NULL == newname)
760  {
763  json_decref (data_js);
764  return;
765  }
766 
767  if (0 >= strlen (newname))
768  {
771  json_decref (data_js);
772  return;
773  }
774 
775  ego_entry_tmp = get_egoentry (handle, NULL, newname);
776  if (NULL != ego_entry_tmp)
777  {
778  // Ego with same name not allowed (even if its the ego we change)
779  resp = GNUNET_REST_create_response (NULL);
780  handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
782  json_decref (data_js);
783  return;
784  }
786  ego_entry->identifier,
787  newname,
788  &do_finished,
789  handle);
790  if (NULL == handle->op)
791  {
792  handle->emsg = GNUNET_strdup ("Rename failed");
794  json_decref (data_js);
795  return;
796  }
797  json_decref (data_js);
798  return;
799 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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
#define GNUNET_REST_ERROR_NO_DATA
Error message No data.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
#define GNUNET_REST_ERROR_DATA_INVALID
Error message Data invalid.

References cleanup_handle(), do_error(), do_finished(), 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, handle, EgoEntry::identifier, and identity_handle.

Referenced by ego_edit_name(), and ego_edit_pubkey().

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 810 of file plugin_rest_identity.c.

813 {
814  struct RequestHandle *handle = cls;
815  struct EgoEntry *ego_entry;
816  char *keystring;
817 
818  keystring = NULL;
819 
820  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
821  {
822  handle->response_code = MHD_HTTP_NOT_FOUND;
825  return;
826  }
828  ego_entry = get_egoentry (handle, keystring, NULL);
829 
830  if (NULL == ego_entry)
831  {
832  handle->response_code = MHD_HTTP_NOT_FOUND;
835  return;
836  }
837 
838  ego_edit (handle, ego_entry);
839 }
void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.

References do_error(), ego_edit(), 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, and EgoEntry::keystring.

Here is the call 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 850 of file plugin_rest_identity.c.

853 {
854  struct RequestHandle *handle = cls;
855  struct EgoEntry *ego_entry;
856  char *name;
857 
858  name = NULL;
859 
860  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
861  {
862  handle->response_code = MHD_HTTP_NOT_FOUND;
865  return;
866  }
867  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
868  ego_entry = get_egoentry (handle, NULL, name);
869 
870  if (NULL == ego_entry)
871  {
872  handle->response_code = MHD_HTTP_NOT_FOUND;
875  return;
876  }
877 
878  ego_edit (handle, ego_entry);
879 }

References do_error(), ego_edit(), 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, and name.

Here is the call 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 890 of file plugin_rest_identity.c.

893 {
894  struct RequestHandle *handle = cls;
895  struct EgoEntry *ego_entry;
896  json_t *data_js;
897  json_error_t err;
898  char *newsubsys;
899  char *name;
900  char term_data[handle->data_size + 1];
901  int json_state;
902 
903  name = NULL;
904 
905  if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url))
906  {
907  handle->response_code = MHD_HTTP_NOT_FOUND;
910  return;
911  }
912  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1];
913  ego_entry = get_egoentry (handle, NULL, name);
914 
915  if (NULL == ego_entry)
916  {
917  handle->response_code = MHD_HTTP_NOT_FOUND;
920  return;
921  }
922 
923  // if no data
924  if (0 >= handle->data_size)
925  {
928  return;
929  }
930  // if not json
931  term_data[handle->data_size] = '\0';
932  GNUNET_memcpy (term_data, handle->data, handle->data_size);
933  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
934 
935  if (NULL == data_js)
936  {
939  return;
940  }
941 
942  newsubsys = NULL;
943  // SUBSYSTEM
944  json_state = 0;
945  json_state = json_unpack (data_js,
946  "{s:s!}",
948  &newsubsys);
949  // Change subsystem with pubkey or name identifier
950  if (0 != json_state)
951  {
954  json_decref (data_js);
955  return;
956  }
957 
958  if (NULL == newsubsys)
959  {
962  json_decref (data_js);
963  return;
964  }
965 
966  if (0 >= strlen (newsubsys))
967  {
970  json_decref (data_js);
971  return;
972  }
973 
974  handle->response_code = MHD_HTTP_NO_CONTENT;
976  newsubsys,
977  ego_entry->ego,
978  &do_finished,
979  handle);
980  if (NULL == handle->op)
981  {
982  handle->emsg = GNUNET_strdup ("Setting subsystem failed");
984  return;
985  }
986  json_decref (data_js);
987  return;
988 }
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
#define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM
Parameter subsystem.

References do_error(), do_finished(), EgoEntry::ego, 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, identity_handle, and name.

Here is the call 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 999 of file plugin_rest_identity.c.

1002 {
1003  struct RequestHandle *handle = cls;
1004  struct EgoEntry *ego_entry;
1005  struct MHD_Response *resp;
1006  json_t *data_js;
1007  json_error_t err;
1008  char *egoname;
1009  char *privkey;
1011  struct GNUNET_IDENTITY_PrivateKey *pk_ptr;
1012  int json_unpack_state;
1013  char term_data[handle->data_size + 1];
1014 
1015  if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
1016  {
1018  return;
1019  }
1020 
1021  if (0 >= handle->data_size)
1022  {
1025  return;
1026  }
1027  term_data[handle->data_size] = '\0';
1028  GNUNET_memcpy (term_data, handle->data, handle->data_size);
1029  data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
1030  if (NULL == data_js)
1031  {
1034  json_decref (data_js);
1035  return;
1036  }
1037  json_unpack_state = 0;
1038  privkey = NULL;
1039  json_unpack_state =
1040  json_unpack (data_js, "{s:s, s?:s!}",
1043  if (0 != json_unpack_state)
1044  {
1047  json_decref (data_js);
1048  return;
1049  }
1050 
1051  if (NULL == egoname)
1052  {
1055  json_decref (data_js);
1056  return;
1057  }
1058  if (0 >= strlen (egoname))
1059  {
1060  json_decref (data_js);
1063  return;
1064  }
1065  GNUNET_STRINGS_utf8_tolower (egoname, egoname);
1066  for (ego_entry = ego_head; NULL != ego_entry;
1067  ego_entry = ego_entry->next)
1068  {
1069  if (0 == strcasecmp (egoname, ego_entry->identifier))
1070  {
1071  resp = GNUNET_REST_create_response (NULL);
1072  handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
1074  json_decref (data_js);
1075  return;
1076  }
1077  }
1078  handle->name = GNUNET_strdup (egoname);
1079  if (NULL != privkey)
1080  {
1082  strlen (privkey),
1083  &pk,
1084  sizeof(struct
1086  pk_ptr = &pk;
1087  }
1088  else
1089  pk_ptr = NULL;
1090  json_decref (data_js);
1091  handle->response_code = MHD_HTTP_CREATED;
1093  handle->name,
1094  pk_ptr,
1097  handle);
1098 }
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
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
enum GNUNET_GenericReturnValue 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:775
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:444
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
static void do_finished_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, const char *emsg)
Processing finished, when creating an ego.
A private key for an identity as per LSD0001.

References cleanup_handle(), do_error(), do_finished_create(), ego_head, 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, identity_handle, EgoEntry::next, and pk.

Here is the call 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 1109 of file plugin_rest_identity.c.

1112 {
1113  struct RequestHandle *handle = cls;
1114  struct EgoEntry *ego_entry;
1115  char *keystring;
1116 
1117  keystring = NULL;
1118 
1119  if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
1120  {
1121  handle->response_code = MHD_HTTP_NOT_FOUND;
1124  return;
1125  }
1126  keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1];
1127  ego_entry = get_egoentry (handle, keystring, NULL);
1128 
1129  if (NULL == ego_entry)
1130  {
1131  handle->response_code = MHD_HTTP_NOT_FOUND;
1134  return;
1135  }
1136 
1137  handle->response_code = MHD_HTTP_NO_CONTENT;
1139  ego_entry->identifier,
1140  &do_finished,
1141  handle);
1142 }
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

References do_error(), do_finished(), 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, identity_handle, and EgoEntry::keystring.

Here is the call 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 1153 of file plugin_rest_identity.c.

1156 {
1157  struct RequestHandle *handle = cls;
1158  struct EgoEntry *ego_entry;
1159  char *name;
1160 
1161  name = NULL;
1162 
1163  if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
1164  {
1165  handle->response_code = MHD_HTTP_NOT_FOUND;
1168  return;
1169  }
1170  name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
1171  ego_entry = get_egoentry (handle, NULL, name);
1172 
1173  if (NULL == ego_entry)
1174  {
1175  handle->response_code = MHD_HTTP_NOT_FOUND;
1178  return;
1179  }
1180 
1181  handle->response_code = MHD_HTTP_NO_CONTENT;
1183  ego_entry->identifier,
1184  &do_finished,
1185  handle);
1186 }

References do_error(), do_finished(), 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, identity_handle, and name.

Here is the call 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 1197 of file plugin_rest_identity.c.

1200 {
1201  struct MHD_Response *resp;
1202  struct RequestHandle *handle = cls;
1203 
1204  // For now, independent of path return all options
1205  resp = GNUNET_REST_create_response (NULL);
1206  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1207  "Access-Control-Allow-Methods",
1208  allow_methods));
1209  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1211  return;
1212 }
static char * allow_methods
HTTP methods allows for this plugin.

References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.

Here is the call 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 1216 of file plugin_rest_identity.c.

1220 {
1221  struct EgoEntry *ego_entry;
1223 
1224  if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1225  {
1227  return;
1228  }
1229  if (NULL == ego)
1230  {
1232  "Called with NULL ego\n");
1233  return;
1234  }
1235  if (ID_REST_STATE_INIT == state)
1236  {
1237  ego_entry = GNUNET_new (struct EgoEntry);
1240  ego_entry->ego = ego;
1241  ego_entry->identifier = GNUNET_strdup (identifier);
1243  ego_tail,
1244  ego_entry);
1245  }
1246  /* Ego renamed or added */
1247  if (identifier != NULL)
1248  {
1249  for (ego_entry = ego_head; NULL != ego_entry;
1250  ego_entry = ego_entry->next)
1251  {
1252  if (ego_entry->ego == ego)
1253  {
1254  /* Rename */
1255  GNUNET_free (ego_entry->identifier);
1256  ego_entry->identifier = GNUNET_strdup (identifier);
1257  break;
1258  }
1259  }
1260  if (NULL == ego_entry)
1261  {
1262  /* Add */
1263  ego_entry = GNUNET_new (struct EgoEntry);
1266  ego_entry->ego = ego;
1267  ego_entry->identifier = GNUNET_strdup (identifier);
1269  ego_tail,
1270  ego_entry);
1271  }
1272  }
1273  else
1274  {
1275  /* Delete */
1276  for (ego_entry = ego_head; NULL != ego_entry;
1277  ego_entry = ego_entry->next)
1278  {
1279  if (ego_entry->ego == ego)
1280  break;
1281  }
1282  if (NULL == ego_entry)
1283  return; /* Not found */
1284 
1286  ego_tail,
1287  ego_entry);
1288  GNUNET_free (ego_entry->identifier);
1289  GNUNET_free (ego_entry->keystring);
1290  GNUNET_free (ego_entry);
1291  return;
1292  }
1293 
1294 }
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct EgoEntry * ego_tail
Ego list.
#define ID_REST_STATE_INIT
State while collecting all egos.
static int state
The processing state.
#define ID_REST_STATE_POST_INIT
Done collecting egos.

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

Referenced by libgnunet_plugin_rest_identity_init().

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 1216 of file plugin_rest_identity.c.

1312 {
1313  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1315  static const struct GNUNET_REST_RequestHandler handlers[] =
1316  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1317  &ego_get_pubkey },
1318  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1319  { MHD_HTTP_METHOD_GET,
1321  &ego_get_subsystem },
1322  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1323  { MHD_HTTP_METHOD_PUT,
1325  &ego_edit_pubkey },
1326  { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1327  { MHD_HTTP_METHOD_PUT,
1329  &ego_edit_subsystem },
1330  { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1331  { MHD_HTTP_METHOD_DELETE,
1333  &ego_delete_pubkey },
1334  { MHD_HTTP_METHOD_DELETE,
1336  &ego_delete_name },
1337  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1339 
1340 
1341  handle->response_code = 0;
1343  handle->proc_cls = proc_cls;
1344  handle->proc = proc;
1345  handle->rest_handle = rest_handle;
1346  handle->data = rest_handle->data;
1347  handle->data_size = rest_handle->data_size;
1348 
1349  handle->url = GNUNET_strdup (rest_handle->url);
1350  if (handle->url[strlen (handle->url) - 1] == '/')
1351  handle->url[strlen (handle->url) - 1] = '\0';
1352  handle->timeout_task =
1355  requests_tail,
1356  handle);
1357  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1358  if (GNUNET_NO ==
1359  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1360  {
1362  return GNUNET_NO;
1363  }
1364 
1365  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1366  return GNUNET_YES;
1367 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
@ GNUNET_NO
Definition: gnunet_common.h:94
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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
#define GNUNET_REST_HANDLER_END
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
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_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
void ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with name.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS 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_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
void ego_get_subsystem(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request for subsystem.
void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
const char * data
The POST data.
const char * url
The url as string.
size_t data_size
The POST data size.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.

Referenced by libgnunet_plugin_rest_identity_init().

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 1377 of file plugin_rest_identity.c.

1378 {
1379  static struct Plugin plugin;
1380  struct GNUNET_REST_Plugin *api;
1381 
1382  cfg = cls;
1383  if (NULL != plugin.cfg)
1384  return NULL; /* can only initialize once! */
1385  memset (&plugin, 0, sizeof(struct Plugin));
1386  plugin.cfg = cfg;
1387  api = GNUNET_new (struct GNUNET_REST_Plugin);
1388  api->cls = &plugin;
1392  "%s, %s, %s, %s, %s",
1393  MHD_HTTP_METHOD_GET,
1394  MHD_HTTP_METHOD_POST,
1395  MHD_HTTP_METHOD_PUT,
1396  MHD_HTTP_METHOD_DELETE,
1397  MHD_HTTP_METHOD_OPTIONS);
1400 
1401  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1402  return api;
1403 }
struct Plugin * plugin
The process handle to the testbed service.
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
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
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.
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
struct returned by the initialization function of the plugin
char * name
Plugin name.
void * cls
The closure of the plugin.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
Handle for a plugin.
Definition: block.c:38
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.

References _, allow_methods, Plugin::cfg, 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, identity_handle, list_ego(), GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, rest_process_request(), and state.

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 1413 of file plugin_rest_identity.c.

1414 {
1415  struct GNUNET_REST_Plugin *api = cls;
1416  struct Plugin *plugin = api->cls;
1417  struct EgoEntry *ego_entry;
1418  struct EgoEntry *ego_tmp;
1419 
1420  plugin->cfg = NULL;
1421  while (NULL != requests_head)
1423  if (NULL != identity_handle)
1425 
1426  for (ego_entry = ego_head; NULL != ego_entry;)
1427  {
1428  ego_tmp = ego_entry;
1429  ego_entry = ego_entry->next;
1430  GNUNET_free (ego_tmp->identifier);
1431  GNUNET_free (ego_tmp->keystring);
1432  GNUNET_free (ego_tmp);
1433  }
1434 
1436  GNUNET_free (api);
1437  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1438  return NULL;
1439 }
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

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

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.

Referenced by libgnunet_plugin_rest_identity_init().

◆ 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_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 137 of file plugin_rest_identity.c.

Referenced by list_ego().

◆ 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

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 267 of file plugin_rest_identity.c.

Referenced by cleanup_handle(), and libgnunet_plugin_rest_identity_done().

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 272 of file plugin_rest_identity.c.

Referenced by cleanup_handle().