GNUnet 0.22.2
identity_plugin.c File Reference
#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_identity_service.h"
#include "gnunet_rest_lib.h"
#include "../../service/identity/identity.h"
#include "gnunet_util_lib.h"
#include "microhttpd.h"
#include <jansson.h>
#include "identity_plugin.h"
Include dependency graph for identity_plugin.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  EgoEntry
 The default namestore ego. More...
 
struct  RequestHandle
 The request handle. More...
 
struct  ego_sign_data_cls
 

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_SIGN   "/sign"
 Identity Namespace with sign specifier. 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_NAME   "name"
 Parameter name. More...
 
#define GNUNET_REST_IDENTITY_PARAM_TYPE   "type"
 Parameter type. More...
 
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME   "newname"
 Parameter new name. 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...
 
static 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_all (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request - responds with all identities. More...
 
static void ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
 Responds with the ego_entry identity. More...
 
static void ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity GET request with a public key. More...
 
static 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, enum GNUNET_ErrorCode ec)
 Processing finished. More...
 
static void do_finished_create (void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
 Processing finished, when creating an ego. More...
 
static void ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry)
 Processing edit ego with EgoEntry ego_entry. More...
 
static void ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity PUT request with public key. More...
 
static void ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity PUT request with name. More...
 
static void ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity POST request. More...
 
static void ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity DELETE request with public key. More...
 
static void ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle identity DELETE request with name. More...
 
static void ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 
static void ego_sign_data (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 
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)
 
enum GNUNET_GenericReturnValue REST_identity_process_request (void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
 Function processing the REST call. More...
 
void * REST_identity_init (const struct GNUNET_CONFIGURATION_Handle *c)
 Entry point for the plugin. More...
 
void REST_identity_done (struct GNUNET_REST_Plugin *api)
 Exit point from the plugin. More...
 

Variables

const struct GNUNET_CONFIGURATION_Handleid_cfg
 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...
 

Macro Definition Documentation

◆ GNUNET_REST_API_NS_IDENTITY

#define GNUNET_REST_API_NS_IDENTITY   "/identity"

Identity Namespace.

Definition at line 40 of file identity_plugin.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 45 of file identity_plugin.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 50 of file identity_plugin.c.

◆ GNUNET_REST_API_NS_SIGN

#define GNUNET_REST_API_NS_SIGN   "/sign"

Identity Namespace with sign specifier.

Definition at line 55 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_PUBKEY

#define GNUNET_REST_IDENTITY_PARAM_PUBKEY   "pubkey"

Parameter public key.

Definition at line 60 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_PRIVKEY

#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY   "privkey"

Parameter private key.

Definition at line 65 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_NAME

#define GNUNET_REST_IDENTITY_PARAM_NAME   "name"

Parameter name.

Definition at line 70 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_TYPE

#define GNUNET_REST_IDENTITY_PARAM_TYPE   "type"

Parameter type.

Definition at line 75 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_NEWNAME

#define GNUNET_REST_IDENTITY_PARAM_NEWNAME   "newname"

Parameter new name.

Definition at line 80 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_MISSING_NAME

#define GNUNET_REST_IDENTITY_MISSING_NAME   "Missing identity name"

Error message Missing identity name.

Definition at line 85 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_MISSING_PUBKEY

#define GNUNET_REST_IDENTITY_MISSING_PUBKEY   "Missing identity public key"

Error message Missing identity name.

Definition at line 90 of file identity_plugin.c.

◆ GNUNET_REST_ERROR_NO_DATA

#define GNUNET_REST_ERROR_NO_DATA   "No data"

Error message No data.

Definition at line 95 of file identity_plugin.c.

◆ GNUNET_REST_ERROR_DATA_INVALID

#define GNUNET_REST_ERROR_DATA_INVALID   "Data invalid"

Error message Data invalid.

Definition at line 100 of file identity_plugin.c.

◆ ID_REST_STATE_INIT

#define ID_REST_STATE_INIT   0

State while collecting all egos.

Definition at line 105 of file identity_plugin.c.

◆ ID_REST_STATE_POST_INIT

#define ID_REST_STATE_POST_INIT   1

Done collecting egos.

Definition at line 110 of file identity_plugin.c.

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
clsHandle to clean up

Definition at line 274 of file identity_plugin.c.

275{
276 struct RequestHandle *handle = cls;
277
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
279 if (NULL != handle->timeout_task)
280 {
281 GNUNET_SCHEDULER_cancel (handle->timeout_task);
282 handle->timeout_task = NULL;
283 }
284
285 if (NULL != handle->url)
286 GNUNET_free (handle->url);
287 if (NULL != handle->name)
288 GNUNET_free (handle->name);
291 handle);
293}
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ 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:980
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
The request handle.
Definition: config_plugin.c:47

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_get_all(), ego_get_response(), ego_sign_data_cb(), options_cont(), REST_identity_done(), and REST_identity_process_request().

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 302 of file identity_plugin.c.

303{
304 struct RequestHandle *handle = cls;
305 struct MHD_Response *resp;
306 json_t *json_error = json_object ();
307 char *response;
308 int response_code;
309
310 json_object_set_new (json_error, "error",
311 json_string (GNUNET_ErrorCode_get_hint (handle->ec)));
312 json_object_set_new (json_error, "error_code", json_integer (handle->ec));
313 response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
314 if (0 == response_code)
315 response_code = MHD_HTTP_OK;
316 response = json_dumps (json_error, 0);
318 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
319 "Content-Type",
320 "application/json"));
321 handle->proc (handle->proc_cls, resp, response_code);
322 json_decref (json_error);
325}
static struct MHD_Response * response
Our canonical response.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
static void cleanup_handle(void *cls)
Cleanup lookup handle.
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
unsigned int GNUNET_ErrorCode_get_http_status(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code.

References cleanup_handle(), GNUNET_assert, GNUNET_ErrorCode_get_hint(), GNUNET_ErrorCode_get_http_status(), GNUNET_free, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, MHD_HTTP_OK, and response.

Referenced by do_finished(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_get_name(), ego_get_pubkey(), ego_sign_data(), ego_sign_data_cb(), and REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_egoentry()

static struct EgoEntry * get_egoentry ( struct RequestHandle handle,
char *  pubkey,
char *  name 
)
static

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 338 of file identity_plugin.c.

339{
340 struct EgoEntry *ego_entry;
341
342 if (NULL != pubkey)
343 {
344 for (ego_entry = ego_head; NULL != ego_entry;
345 ego_entry = ego_entry->next)
346 {
347 if (0 != strcasecmp (pubkey, ego_entry->keystring))
348 continue;
349 return ego_entry;
350 }
351 }
352 if (NULL != name)
353 {
354 for (ego_entry = ego_head; NULL != ego_entry;
355 ego_entry = ego_entry->next)
356 {
357 if (0 != strcasecmp (name, ego_entry->identifier))
358 continue;
359 return ego_entry;
360 }
361 }
362 return NULL;
363}
static char * name
Name (label) of the records to list.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static struct EgoEntry * ego_head
Ego list.
The default namestore ego.
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_name(), ego_edit_pubkey(), ego_get_name(), and ego_get_pubkey().

Here is the caller graph for this function:

◆ ego_get_all()

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

Handle identity GET request - responds with all identities.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 374 of file identity_plugin.c.

377{
378 struct RequestHandle *handle = cls;
379 struct EgoEntry *ego_entry;
380 struct MHD_Response *resp;
381 struct GNUNET_HashCode key;
382 json_t *json_root;
383 json_t *json_ego;
384 char *result_str;
385 char *privkey_str;
386
387 json_root = json_array ();
388 // Return ego/egos
389 for (ego_entry = ego_head; NULL != ego_entry;
390 ego_entry = ego_entry->next)
391 {
392 json_ego = json_object ();
393 json_object_set_new (json_ego,
395 json_string (ego_entry->keystring));
396 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
397 if (GNUNET_YES ==
399 handle->rest_handle->url_param_map, &key))
400 {
403 json_object_set_new (json_ego,
405 json_string (privkey_str));
406 GNUNET_free (privkey_str);
407 }
408
409 json_object_set_new (json_ego,
411 json_string (ego_entry->identifier));
412 json_array_append (json_root, json_ego);
413 json_decref (json_ego);
414 }
415
416 result_str = json_dumps (json_root, 0);
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
418 resp = GNUNET_REST_create_response (result_str);
419 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
420 "Content-Type",
421 "application/json"));
422 json_decref (json_root);
423 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
424 GNUNET_free (result_str);
426}
struct GNUNET_HashCode key
The key used in the DHT.
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
enum GNUNET_GenericReturnValue 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_CRYPTO_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:517
char * GNUNET_CRYPTO_private_key_to_string(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates a (Base32) string representation of the private key.
Definition: crypto_pkey.c:389
@ GNUNET_YES
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public 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_CRYPTO_private_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), 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, MHD_HTTP_OK, and EgoEntry::next.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_response()

static void ego_get_response ( struct RequestHandle handle,
struct EgoEntry ego_entry 
)
static

Responds with the ego_entry identity.

Parameters
handlethe struct RequestHandle
ego_entrythe struct EgoEntry for the response

Definition at line 436 of file identity_plugin.c.

437{
438 struct MHD_Response *resp;
439 struct GNUNET_HashCode key;
440 json_t *json_ego;
441 char *result_str;
442 char *privkey_str;
443
444 json_ego = json_object ();
445 json_object_set_new (json_ego,
447 json_string (ego_entry->keystring));
448 json_object_set_new (json_ego,
450 json_string (ego_entry->identifier));
451 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
452 if (GNUNET_YES ==
454 handle->rest_handle->url_param_map, &key))
455 {
458 json_object_set_new (json_ego,
460 json_string (privkey_str));
461 GNUNET_free (privkey_str);
462 }
463
464 result_str = json_dumps (json_ego, 0);
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
466 resp = GNUNET_REST_create_response (result_str);
467 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
468 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
469 "Content-Type",
470 "application/json"));
471 json_decref (json_ego);
472 GNUNET_free (result_str);
474}

References cleanup_handle(), EgoEntry::ego, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_private_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), 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 MHD_HTTP_OK.

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

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

Handle identity GET request with a public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 485 of file identity_plugin.c.

488{
489 struct RequestHandle *handle = cls;
490 struct EgoEntry *ego_entry;
491 char *keystring;
492
493 keystring = NULL;
494
495 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
496 {
499 return;
500 }
502 ego_entry = get_egoentry (handle, keystring, NULL);
503
504 if (NULL == ego_entry)
505 {
508 return;
509 }
510
511 ego_get_response (handle, ego_entry);
512}
static 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 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.
static void do_error(void *cls)
Task run on errors.
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.

References do_error(), ego_get_response(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, and EgoEntry::keystring.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_get_name()

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

Handle identity GET request with a name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 523 of file identity_plugin.c.

526{
527 struct RequestHandle *handle = cls;
528 struct EgoEntry *ego_entry;
529 char *egoname;
530
531 egoname = NULL;
532
533 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
534 {
537 return;
538 }
539 egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
540 ego_entry = get_egoentry (handle, NULL, egoname);
541
542 if (NULL == ego_entry)
543 {
546 return;
547 }
548
549 ego_get_response (handle, ego_entry);
550}
static char * egoname
Ego Attribute String.
Definition: gnunet-did.c:92
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.

References do_error(), ego_get_response(), egoname, get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), and handle.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_finished()

static void do_finished ( void *  cls,
enum GNUNET_ErrorCode  ec 
)
static

Processing finished.

Parameters
clsrequest handle
ecerror code

Definition at line 560 of file identity_plugin.c.

561{
562 struct RequestHandle *handle = cls;
563 struct MHD_Response *resp;
564 int response_code;
565
566 handle->op = NULL;
567 handle->ec = ec;
568 if (GNUNET_EC_NONE != handle->ec)
569 {
571 return;
572 }
573
574 if (0 != handle->success_code)
575 response_code = handle->success_code;
576 else
577 response_code = MHD_HTTP_OK;
578
579 resp = GNUNET_REST_create_response (NULL);
580 handle->proc (handle->proc_cls, resp, response_code);
582}
@ GNUNET_EC_NONE
No error (success).

References cleanup_handle(), do_error(), GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.

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

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_CRYPTO_PrivateKey pk,
enum GNUNET_ErrorCode  ec 
)
static

Processing finished, when creating an ego.

Parameters
clsrequest handle
pkprivate key of the ego, or NULL on error
ecerror code

Definition at line 593 of file identity_plugin.c.

596{
597 struct RequestHandle *handle = cls;
598
599 (void) pk;
601}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
enum GNUNET_ErrorCode ec
Error code.

References do_finished(), RequestHandle::ec, 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()

static void ego_edit ( struct RequestHandle handle,
struct EgoEntry ego_entry 
)
static

Processing edit ego with EgoEntry ego_entry.

Parameters
handlethe struct RequestHandle
ego_entrythe struct EgoEntry we want to edit

Definition at line 611 of file identity_plugin.c.

612{
613 json_t *data_js;
614 json_error_t err;
615 char *newname;
616 char term_data[handle->data_size + 1];
617 int json_state;
618
619 // if no data
620 if (0 >= handle->data_size)
621 {
624 return;
625 }
626 // if not json
627 term_data[handle->data_size] = '\0';
628 GNUNET_memcpy (term_data, handle->data, handle->data_size);
629 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
630
631 if (NULL == data_js)
632 {
635 return;
636 }
637
638 newname = NULL;
639 // NEW NAME
640 json_state = 0;
641 json_state = json_unpack (data_js,
642 "{s:s!}",
644 &newname);
645 // Change name with pubkey or name identifier
646 if (0 != json_state)
647 {
650 json_decref (data_js);
651 return;
652 }
653
654 if (NULL == newname)
655 {
658 json_decref (data_js);
659 return;
660 }
661
662 if (0 >= strlen (newname))
663 {
666 json_decref (data_js);
667 return;
668 }
669
670 handle->success_code = MHD_HTTP_NO_CONTENT;
672 ego_entry->identifier,
673 newname,
675 handle);
676 if (NULL == handle->op)
677 {
680 json_decref (data_js);
681 return;
682 }
683 json_decref (data_js);
684 return;
685}
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *id, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing ego.
Definition: identity_api.c:621
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ MHD_HTTP_NO_CONTENT
No Content [RFC7231, Section 6.3.5].
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
@ GNUNET_EC_IDENTITY_INVALID
The given ego is invalid or malformed.
@ GNUNET_EC_UNKNOWN
Unknown and unspecified error.

References do_error(), do_finished(), RequestHandle::ego_entry, GNUNET_EC_IDENTITY_INVALID, GNUNET_EC_UNKNOWN, GNUNET_IDENTITY_rename(), GNUNET_memcpy, GNUNET_REST_IDENTITY_PARAM_NEWNAME, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity_handle, and MHD_HTTP_NO_CONTENT.

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

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

Handle identity PUT request with public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 696 of file identity_plugin.c.

699{
700 struct RequestHandle *handle = cls;
701 struct EgoEntry *ego_entry;
702 char *keystring;
703
704 keystring = NULL;
705
706 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
707 {
710 return;
711 }
713 ego_entry = get_egoentry (handle, keystring, NULL);
714
715 if (NULL == ego_entry)
716 {
719 return;
720 }
721
722 ego_edit (handle, ego_entry);
723}
static 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_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, and EgoEntry::keystring.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_edit_name()

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

Handle identity PUT request with name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 734 of file identity_plugin.c.

737{
738 struct RequestHandle *handle = cls;
739 struct EgoEntry *ego_entry;
740 char *name;
741
742 name = NULL;
743
744 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
745 {
748 return;
749 }
750 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
751 ego_entry = get_egoentry (handle, NULL, name);
752
753 if (NULL == ego_entry)
754 {
757 return;
758 }
759
760 ego_edit (handle, ego_entry);
761}

References do_error(), ego_edit(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), handle, and name.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_create()

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

Handle identity POST request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 772 of file identity_plugin.c.

775{
776 struct RequestHandle *handle = cls;
777 json_t *data_js;
778 json_error_t err;
779 char *egoname;
780 char *egotype;
781 char *privkey;
783 struct GNUNET_CRYPTO_PrivateKey *pk_ptr;
784 int json_unpack_state;
785 int type;
786 char term_data[handle->data_size + 1];
787
788 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
789 {
791 return;
792 }
793
794 if (0 >= handle->data_size)
795 {
798 return;
799 }
800 term_data[handle->data_size] = '\0';
801 GNUNET_memcpy (term_data, handle->data, handle->data_size);
802 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
803 if (NULL == data_js)
804 {
807 json_decref (data_js);
808 return;
809 }
810 json_unpack_state = 0;
811 privkey = NULL;
812 json_unpack_state =
813 json_unpack (data_js, "{s:s, s?:s, s?:s}",
817 if (0 != json_unpack_state)
818 {
821 json_decref (data_js);
822 return;
823 }
825 if ((NULL != egotype) && (0 == strcasecmp (egotype, "EDDSA")))
827 if (NULL == egoname)
828 {
831 json_decref (data_js);
832 return;
833 }
834 if (0 >= strlen (egoname))
835 {
837 json_decref (data_js);
839 return;
840 }
842 handle->name = GNUNET_strdup (egoname);
843 if (NULL != privkey)
844 {
846 strlen (privkey),
847 &pk,
848 sizeof(struct
850 pk_ptr = &pk;
851 }
852 else
853 pk_ptr = NULL;
854 json_decref (data_js);
855 handle->success_code = MHD_HTTP_CREATED;
857 handle->name,
858 pk_ptr,
859 type,
861 handle);
862}
static uint32_t type
Type string converted to DNS type value.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *id, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:561
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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:812
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:459
@ MHD_HTTP_CREATED
Created [RFC7231, Section 6.3.2].
static void do_finished_create(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
Processing finished, when creating an ego.
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
#define GNUNET_REST_IDENTITY_PARAM_TYPE
Parameter type.
A private key for an identity as per LSD0001.

References do_error(), do_finished_create(), egoname, GNUNET_EC_IDENTITY_INVALID, GNUNET_IDENTITY_create(), GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_REST_API_NS_IDENTITY, GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_TYPE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_STRINGS_string_to_data(), GNUNET_STRINGS_utf8_tolower(), handle, identity_handle, MHD_HTTP_CREATED, pk, and type.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_delete_pubkey()

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

Handle identity DELETE request with public key.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 873 of file identity_plugin.c.

876{
877 struct RequestHandle *handle = cls;
878 struct EgoEntry *ego_entry;
879 char *keystring;
880
881 keystring = NULL;
882
883 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
884 {
887 return;
888 }
890 ego_entry = get_egoentry (handle, keystring, NULL);
891
892 if (NULL == ego_entry)
893 {
896 return;
897 }
898
899 handle->success_code = MHD_HTTP_NO_CONTENT;
901 ego_entry->identifier,
903 handle);
904}
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *id, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing ego.
Definition: identity_api.c:674

References do_error(), do_finished(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity_handle, EgoEntry::keystring, and MHD_HTTP_NO_CONTENT.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_delete_name()

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

Handle identity DELETE request with name.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 915 of file identity_plugin.c.

918{
919 struct RequestHandle *handle = cls;
920 struct EgoEntry *ego_entry;
921 char *name;
922
923 name = NULL;
924
925 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
926 {
929 return;
930 }
931 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
932 ego_entry = get_egoentry (handle, NULL, name);
933
934 if (NULL == ego_entry)
935 {
938 return;
939 }
940
941 handle->success_code = MHD_HTTP_NO_CONTENT;
943 ego_entry->identifier,
945 handle);
946}

References do_error(), do_finished(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity_handle, MHD_HTTP_NO_CONTENT, and name.

Referenced by REST_identity_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_sign_data_cb()

static void ego_sign_data_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Definition at line 956 of file identity_plugin.c.

957{
958 struct RequestHandle *handle = ((struct ego_sign_data_cls *) cls)->handle;
959 unsigned char *data
960 = (unsigned char *) ((struct ego_sign_data_cls *) cls)->data; // data is url decoded
961 struct MHD_Response *resp;
963 char *sig_str;
964 char *result;
965
966 if (ego == NULL)
967 {
970 return;
971 }
972
973 if (ntohl (ego->pk.type) != GNUNET_PUBLIC_KEY_TYPE_EDDSA)
974 {
977 return;
978 }
979
981 (void *) data,
982 strlen ( (char*) data),
983 &sig))
984 {
987 return;
988 }
989
991 sizeof (struct GNUNET_CRYPTO_EddsaSignature),
992 &sig_str);
993
995 "{\"signature\": \"%s\"}",
996 sig_str);
997
999 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1000
1001 free (data);
1002 free (sig_str);
1003 free (result);
1004 free (cls);
1006}
static char * data
The data to insert into the dht.
static int result
Global testing status.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig)
Definition: crypto_ecc.c:604
@ GNUNET_OK
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1648
an ECC signature using EdDSA.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
struct GNUNET_CRYPTO_PrivateKey pk
The identity key pair.
Definition: identity.h:51

References cleanup_handle(), data, do_error(), GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_asprintf(), GNUNET_CRYPTO_eddsa_sign_raw(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_EC_UNKNOWN, GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_base64url_encode(), handle, MHD_HTTP_OK, GNUNET_IDENTITY_Ego::pk, result, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by ego_sign_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ego_sign_data()

static void ego_sign_data ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static
Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1016 of file identity_plugin.c.

1019{
1020 // TODO: replace with precompiler #define
1021 const char *username_key = "user";
1022 const char *data_key = "data";
1023
1024 struct RequestHandle *handle = cls;
1025 struct GNUNET_HashCode cache_key_username;
1026 struct GNUNET_HashCode cache_key_data;
1027 char *username;
1028 char *data;
1029
1030 struct ego_sign_data_cls *cls2;
1031
1032 GNUNET_CRYPTO_hash (username_key, strlen (username_key), &cache_key_username);
1033 GNUNET_CRYPTO_hash (data_key, strlen (data_key), &cache_key_data);
1034
1036 handle->rest_handle->url_param_map,
1037 &cache_key_username)) ||
1039 handle->rest_handle->url_param_map,
1040 &cache_key_data)))
1041 {
1044 return;
1045 }
1046
1047 username = (char *) GNUNET_CONTAINER_multihashmap_get (
1048 handle->rest_handle->url_param_map,
1049 &cache_key_username);
1050
1052 handle->rest_handle->url_param_map,
1053 &cache_key_data);
1054
1055 cls2 = malloc (sizeof(struct ego_sign_data_cls));
1056 cls2->data = (void *) GNUNET_strdup (data);
1057 cls2->handle = handle;
1058
1060 username,
1062 cls2);
1063}
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
@ GNUNET_NO
const struct GNUNET_CONFIGURATION_Handle * id_cfg
The configuration handle.
static void ego_sign_data_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
struct RequestHandle * handle

References data, ego_sign_data_cls::data, do_error(), ego_sign_data_cb(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_EC_UNKNOWN, GNUNET_IDENTITY_ego_lookup(), GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, ego_sign_data_cls::handle, and id_cfg.

Referenced by REST_identity_process_request().

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 1074 of file identity_plugin.c.

1077{
1078 struct MHD_Response *resp;
1079 struct RequestHandle *handle = cls;
1080
1081 // For now, independent of path return all options
1082 resp = GNUNET_REST_create_response (NULL);
1083 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1084 "Access-Control-Allow-Methods",
1085 allow_methods));
1086 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1088 return;
1089}
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(), handle, and MHD_HTTP_OK.

Referenced by REST_identity_process_request().

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 1093 of file identity_plugin.c.

1097{
1098 struct EgoEntry *ego_entry;
1100
1101 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1102 {
1104 return;
1105 }
1106 if (NULL == ego)
1107 {
1109 "Called with NULL ego\n");
1110 return;
1111 }
1113 {
1114 ego_entry = GNUNET_new (struct EgoEntry);
1117 ego_entry->ego = ego;
1118 ego_entry->identifier = GNUNET_strdup (identifier);
1120 ego_tail,
1121 ego_entry);
1122 }
1123 /* Ego renamed or added */
1124 if (identifier != NULL)
1125 {
1126 for (ego_entry = ego_head; NULL != ego_entry;
1127 ego_entry = ego_entry->next)
1128 {
1129 if (ego_entry->ego == ego)
1130 {
1131 /* Rename */
1132 GNUNET_free (ego_entry->identifier);
1133 ego_entry->identifier = GNUNET_strdup (identifier);
1134 break;
1135 }
1136 }
1137 if (NULL == ego_entry)
1138 {
1139 /* Add */
1140 ego_entry = GNUNET_new (struct EgoEntry);
1143 ego_entry->ego = ego;
1144 ego_entry->identifier = GNUNET_strdup (identifier);
1146 ego_tail,
1147 ego_entry);
1148 }
1149 }
1150 else
1151 {
1152 /* Delete */
1153 for (ego_entry = ego_head; NULL != ego_entry;
1154 ego_entry = ego_entry->next)
1155 {
1156 if (ego_entry->ego == ego)
1157 break;
1158 }
1159 if (NULL == ego_entry)
1160 return; /* Not found */
1161
1163 ego_tail,
1164 ego_entry);
1165 GNUNET_free (ego_entry->identifier);
1166 GNUNET_free (ego_entry->keystring);
1167 GNUNET_free (ego_entry);
1168 return;
1169 }
1170
1171}
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:529
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
@ 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.
An identity key as per LSD0001.

References EgoEntry::ego, ego_head, ego_tail, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_public_key_to_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), 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 REST_identity_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REST_identity_process_request()

enum GNUNET_GenericReturnValue REST_identity_process_request ( void *  plugin,
struct GNUNET_REST_RequestHandle rest_handle,
GNUNET_REST_ResultProcessor  proc,
void *  proc_cls 
)

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 1186 of file identity_plugin.c.

1190{
1191 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1193 static const struct GNUNET_REST_RequestHandler handlers[] =
1194 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1195 &ego_get_pubkey },
1196 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1197 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1198 { MHD_HTTP_METHOD_PUT,
1200 &ego_edit_pubkey },
1201 { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1202 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1203 { MHD_HTTP_METHOD_DELETE,
1206 { MHD_HTTP_METHOD_DELETE,
1208 &ego_delete_name },
1209 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1210 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_SIGN, &ego_sign_data},
1212
1213
1215 handle->proc_cls = proc_cls;
1216 handle->proc = proc;
1217 handle->rest_handle = rest_handle;
1218 handle->data = rest_handle->data;
1219 handle->data_size = rest_handle->data_size;
1220
1221 handle->url = GNUNET_strdup (rest_handle->url);
1222 if (handle->url[strlen (handle->url) - 1] == '/')
1223 handle->url[strlen (handle->url) - 1] = '\0';
1224 handle->timeout_task =
1228 handle);
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1230 if (GNUNET_NO ==
1231 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1232 {
1234 return GNUNET_NO;
1235 }
1236
1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1238 return GNUNET_YES;
1239}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
#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:64
#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:1277
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void ego_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
static void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
static void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
static void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
static void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
static void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
#define GNUNET_REST_API_NS_SIGN
Identity Namespace with sign specifier.
static void ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with name.
static void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
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.

References cleanup_handle(), GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit_name(), ego_edit_pubkey(), ego_get_all(), ego_get_name(), ego_get_pubkey(), ego_sign_data(), 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_SIGN, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, handlers, options_cont(), GNUNET_REST_RequestHandler::proc, requests_head, requests_tail, and GNUNET_REST_RequestHandle::url.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REST_identity_init()

void * REST_identity_init ( const struct GNUNET_CONFIGURATION_Handle c)

Entry point for the plugin.

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

Definition at line 1249 of file identity_plugin.c.

1250{
1251 static struct Plugin plugin;
1252 struct GNUNET_REST_Plugin *api;
1253
1254 id_cfg = c;
1255 if (NULL != plugin.cfg)
1256 return NULL; /* can only initialize once! */
1257 memset (&plugin, 0, sizeof(struct Plugin));
1258 plugin.cfg = c;
1259 api = GNUNET_new (struct GNUNET_REST_Plugin);
1260 api->cls = &plugin;
1263 "%s, %s, %s, %s, %s",
1264 MHD_HTTP_METHOD_GET,
1265 MHD_HTTP_METHOD_POST,
1266 MHD_HTTP_METHOD_PUT,
1267 MHD_HTTP_METHOD_DELETE,
1268 MHD_HTTP_METHOD_OPTIONS);
1271
1272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1273 return api;
1274}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
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:487
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
const char * name
Plugin name.
Handle for a plugin.
Definition: block.c:38

References _, allow_methods, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_IDENTITY, id_cfg, ID_REST_STATE_INIT, identity_handle, list_ego(), GNUNET_REST_Plugin::name, plugin, and state.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REST_identity_done()

void REST_identity_done ( struct GNUNET_REST_Plugin api)

Exit point from the plugin.

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

Definition at line 1284 of file identity_plugin.c.

1285{
1286 struct Plugin *plugin = api->cls;
1287 struct EgoEntry *ego_entry;
1288 struct EgoEntry *ego_tmp;
1289
1290 plugin->cfg = NULL;
1291 while (NULL != requests_head)
1293 if (NULL != identity_handle)
1295
1296 for (ego_entry = ego_head; NULL != ego_entry;)
1297 {
1298 ego_tmp = ego_entry;
1299 ego_entry = ego_entry->next;
1300 GNUNET_free (ego_tmp->identifier);
1301 GNUNET_free (ego_tmp->keystring);
1302 GNUNET_free (ego_tmp);
1303 }
1304
1306 GNUNET_free (api);
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1308}
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:732
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References allow_methods, Plugin::api, cleanup_handle(), GNUNET_BLOCK_PluginFunctions::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.

Referenced by do_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ id_cfg

const struct GNUNET_CONFIGURATION_Handle* id_cfg

The configuration handle.

Definition at line 115 of file identity_plugin.c.

Referenced by ego_sign_data(), and REST_identity_init().

◆ allow_methods

char* allow_methods
static

HTTP methods allows for this plugin.

Definition at line 120 of file identity_plugin.c.

Referenced by options_cont(), REST_identity_done(), and REST_identity_init().

◆ ego_head

struct EgoEntry* ego_head
static

Ego list.

Definition at line 125 of file identity_plugin.c.

Referenced by ego_get_all(), get_egoentry(), list_ego(), and REST_identity_done().

◆ ego_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 130 of file identity_plugin.c.

Referenced by list_ego().

◆ state

int state
static

The processing state.

Definition at line 135 of file identity_plugin.c.

Referenced by list_ego(), and REST_identity_init().

◆ identity_handle

struct GNUNET_IDENTITY_Handle* identity_handle
static

Handle to Identity service.

Definition at line 140 of file identity_plugin.c.

Referenced by ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), REST_identity_done(), and REST_identity_init().

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 262 of file identity_plugin.c.

Referenced by cleanup_handle(), REST_identity_done(), and REST_identity_process_request().

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 267 of file identity_plugin.c.

Referenced by cleanup_handle(), and REST_identity_process_request().