GNUnet 0.21.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 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...
 
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...
 
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, 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...
 
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_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...
 
void ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 
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 39 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 44 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 49 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 54 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_PUBKEY

#define GNUNET_REST_IDENTITY_PARAM_PUBKEY   "pubkey"

Parameter public key.

Definition at line 59 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_PRIVKEY

#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY   "privkey"

Parameter private key.

Definition at line 64 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_NAME

#define GNUNET_REST_IDENTITY_PARAM_NAME   "name"

Parameter name.

Definition at line 69 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_TYPE

#define GNUNET_REST_IDENTITY_PARAM_TYPE   "type"

Parameter type.

Definition at line 74 of file identity_plugin.c.

◆ GNUNET_REST_IDENTITY_PARAM_NEWNAME

#define GNUNET_REST_IDENTITY_PARAM_NEWNAME   "newname"

Parameter new name.

Definition at line 79 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 84 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 89 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 94 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 99 of file identity_plugin.c.

◆ ID_REST_STATE_INIT

#define ID_REST_STATE_INIT   0

State while collecting all egos.

Definition at line 104 of file identity_plugin.c.

◆ ID_REST_STATE_POST_INIT

#define ID_REST_STATE_POST_INIT   1

Done collecting egos.

Definition at line 109 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 266 of file identity_plugin.c.

267{
268 struct RequestHandle *handle = cls;
269
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
271 if (NULL != handle->timeout_task)
272 {
273 GNUNET_SCHEDULER_cancel (handle->timeout_task);
274 handle->timeout_task = NULL;
275 }
276
277 if (NULL != handle->url)
278 GNUNET_free (handle->url);
279 if (NULL != handle->name)
280 GNUNET_free (handle->name);
283 handle);
285}
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:981
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
The request handle.
Definition: config_plugin.c:46

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

295{
296 struct RequestHandle *handle = cls;
297 struct MHD_Response *resp;
298 json_t *json_error = json_object ();
299 char *response;
300 int response_code;
301
302 json_object_set_new (json_error, "error",
303 json_string (GNUNET_ErrorCode_get_hint (handle->ec)));
304 json_object_set_new (json_error, "error_code", json_integer (handle->ec));
305 response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
306 if (0 == response_code)
307 response_code = MHD_HTTP_OK;
308 response = json_dumps (json_error, 0);
310 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
311 "Content-Type",
312 "application/json"));
313 handle->proc (handle->proc_cls, resp, response_code);
314 json_decref (json_error);
317}
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:1305
@ 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()

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

331{
332 struct EgoEntry *ego_entry;
333
334 if (NULL != pubkey)
335 {
336 for (ego_entry = ego_head; NULL != ego_entry;
337 ego_entry = ego_entry->next)
338 {
339 if (0 != strcasecmp (pubkey, ego_entry->keystring))
340 continue;
341 return ego_entry;
342 }
343 }
344 if (NULL != name)
345 {
346 for (ego_entry = ego_head; NULL != ego_entry;
347 ego_entry = ego_entry->next)
348 {
349 if (0 != strcasecmp (name, ego_entry->identifier))
350 continue;
351 return ego_entry;
352 }
353 }
354 return NULL;
355}
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()

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

369{
370 struct RequestHandle *handle = cls;
371 struct EgoEntry *ego_entry;
372 struct MHD_Response *resp;
373 struct GNUNET_HashCode key;
374 json_t *json_root;
375 json_t *json_ego;
376 char *result_str;
377 char *privkey_str;
378
379 json_root = json_array ();
380 // Return ego/egos
381 for (ego_entry = ego_head; NULL != ego_entry;
382 ego_entry = ego_entry->next)
383 {
384 json_ego = json_object ();
385 json_object_set_new (json_ego,
387 json_string (ego_entry->keystring));
388 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
389 if (GNUNET_YES ==
391 handle->rest_handle->url_param_map, &key))
392 {
395 json_object_set_new (json_ego,
397 json_string (privkey_str));
398 GNUNET_free (privkey_str);
399 }
400
401 json_object_set_new (json_ego,
403 json_string (ego_entry->identifier));
404 json_array_append (json_root, json_ego);
405 json_decref (json_ego);
406 }
407
408 result_str = json_dumps (json_root, 0);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
410 resp = GNUNET_REST_create_response (result_str);
411 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
412 "Content-Type",
413 "application/json"));
414 json_decref (json_root);
415 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
416 GNUNET_free (result_str);
418}
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:404
@ 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()

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

429{
430 struct MHD_Response *resp;
431 struct GNUNET_HashCode key;
432 json_t *json_ego;
433 char *result_str;
434 char *privkey_str;
435
436 json_ego = json_object ();
437 json_object_set_new (json_ego,
439 json_string (ego_entry->keystring));
440 json_object_set_new (json_ego,
442 json_string (ego_entry->identifier));
443 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
444 if (GNUNET_YES ==
446 handle->rest_handle->url_param_map, &key))
447 {
450 json_object_set_new (json_ego,
452 json_string (privkey_str));
453 GNUNET_free (privkey_str);
454 }
455
456 result_str = json_dumps (json_ego, 0);
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
458 resp = GNUNET_REST_create_response (result_str);
459 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
460 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
461 "Content-Type",
462 "application/json"));
463 json_decref (json_ego);
464 GNUNET_free (result_str);
466}

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

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

480{
481 struct RequestHandle *handle = cls;
482 struct EgoEntry *ego_entry;
483 char *keystring;
484
485 keystring = NULL;
486
487 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
488 {
491 return;
492 }
494 ego_entry = get_egoentry (handle, keystring, NULL);
495
496 if (NULL == ego_entry)
497 {
500 return;
501 }
502
503 ego_get_response (handle, ego_entry);
504}
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,...
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()

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

518{
519 struct RequestHandle *handle = cls;
520 struct EgoEntry *ego_entry;
521 char *egoname;
522
523 egoname = NULL;
524
525 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
526 {
529 return;
530 }
531 egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
532 ego_entry = get_egoentry (handle, NULL, egoname);
533
534 if (NULL == ego_entry)
535 {
538 return;
539 }
540
541 ego_get_response (handle, ego_entry);
542}
static char * egoname
Ego Attribute String.
Definition: gnunet-did.c:93
#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 552 of file identity_plugin.c.

553{
554 struct RequestHandle *handle = cls;
555 struct MHD_Response *resp;
556 int response_code;
557
558 handle->op = NULL;
559 handle->ec = ec;
560 if (GNUNET_EC_NONE != ec)
561 {
563 return;
564 }
565 if (GNUNET_EC_NONE == handle->ec)
566 response_code = MHD_HTTP_NO_CONTENT;
567 else
568 response_code = GNUNET_ErrorCode_get_http_status (ec);
569 resp = GNUNET_REST_create_response (NULL);
570 handle->proc (handle->proc_cls, resp, response_code);
572}
@ MHD_HTTP_NO_CONTENT
No Content [RFC7231, Section 6.3.5].
@ GNUNET_EC_NONE
No error (success).

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

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

586{
587 struct RequestHandle *handle = cls;
588
589 (void) pk;
591}
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()

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

602{
603 json_t *data_js;
604 json_error_t err;
605 char *newname;
606 char term_data[handle->data_size + 1];
607 int json_state;
608
609 // if no data
610 if (0 >= handle->data_size)
611 {
614 return;
615 }
616 // if not json
617 term_data[handle->data_size] = '\0';
618 GNUNET_memcpy (term_data, handle->data, handle->data_size);
619 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
620
621 if (NULL == data_js)
622 {
625 return;
626 }
627
628 newname = NULL;
629 // NEW NAME
630 json_state = 0;
631 json_state = json_unpack (data_js,
632 "{s:s!}",
634 &newname);
635 // Change name with pubkey or name identifier
636 if (0 != json_state)
637 {
640 json_decref (data_js);
641 return;
642 }
643
644 if (NULL == newname)
645 {
648 json_decref (data_js);
649 return;
650 }
651
652 if (0 >= strlen (newname))
653 {
656 json_decref (data_js);
657 return;
658 }
659
661 ego_entry->identifier,
662 newname,
664 handle);
665 if (NULL == handle->op)
666 {
669 json_decref (data_js);
670 return;
671 }
672 json_decref (data_js);
673 return;
674}
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.
#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, 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 685 of file identity_plugin.c.

688{
689 struct RequestHandle *handle = cls;
690 struct EgoEntry *ego_entry;
691 char *keystring;
692
693 keystring = NULL;
694
695 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
696 {
699 return;
700 }
702 ego_entry = get_egoentry (handle, keystring, NULL);
703
704 if (NULL == ego_entry)
705 {
708 return;
709 }
710
711 ego_edit (handle, ego_entry);
712}
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()

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

726{
727 struct RequestHandle *handle = cls;
728 struct EgoEntry *ego_entry;
729 char *name;
730
731 name = NULL;
732
733 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
734 {
737 return;
738 }
739 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
740 ego_entry = get_egoentry (handle, NULL, name);
741
742 if (NULL == ego_entry)
743 {
746 return;
747 }
748
749 ego_edit (handle, ego_entry);
750}

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

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

764{
765 struct RequestHandle *handle = cls;
766 json_t *data_js;
767 json_error_t err;
768 char *egoname;
769 char *egotype;
770 char *privkey;
772 struct GNUNET_CRYPTO_PrivateKey *pk_ptr;
773 int json_unpack_state;
774 char term_data[handle->data_size + 1];
775
776 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
777 {
779 return;
780 }
781
782 if (0 >= handle->data_size)
783 {
786 return;
787 }
788 term_data[handle->data_size] = '\0';
789 GNUNET_memcpy (term_data, handle->data, handle->data_size);
790 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
791 if (NULL == data_js)
792 {
795 json_decref (data_js);
796 return;
797 }
798 json_unpack_state = 0;
799 privkey = NULL;
800 json_unpack_state =
801 json_unpack (data_js, "{s:s, s?:s, s?:s}",
805 if (0 != json_unpack_state)
806 {
809 json_decref (data_js);
810 return;
811 }
813 if ((NULL != egotype) && (0 == strcasecmp (egotype, "EDDSA")))
815 if (NULL == egoname)
816 {
819 json_decref (data_js);
820 return;
821 }
822 if (0 >= strlen (egoname))
823 {
825 json_decref (data_js);
827 return;
828 }
830 handle->name = GNUNET_strdup (egoname);
831 if (NULL != privkey)
832 {
834 strlen (privkey),
835 &pk,
836 sizeof(struct
838 pk_ptr = &pk;
839 }
840 else
841 pk_ptr = NULL;
842 json_decref (data_js);
844 handle->name,
845 pk_ptr,
846 type,
848 handle);
849}
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:789
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:450
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, 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()

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

863{
864 struct RequestHandle *handle = cls;
865 struct EgoEntry *ego_entry;
866 char *keystring;
867
868 keystring = NULL;
869
870 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
871 {
874 return;
875 }
877 ego_entry = get_egoentry (handle, keystring, NULL);
878
879 if (NULL == ego_entry)
880 {
883 return;
884 }
885
887 ego_entry->identifier,
889 handle);
890}
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, 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_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 901 of file identity_plugin.c.

904{
905 struct RequestHandle *handle = cls;
906 struct EgoEntry *ego_entry;
907 char *name;
908
909 name = NULL;
910
911 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
912 {
915 return;
916 }
917 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
918 ego_entry = get_egoentry (handle, NULL, name);
919
920 if (NULL == ego_entry)
921 {
924 return;
925 }
926
928 ego_entry->identifier,
930 handle);
931}

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

void ego_sign_data_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)

Definition at line 941 of file identity_plugin.c.

942{
943 struct RequestHandle *handle = ((struct ego_sign_data_cls *) cls)->handle;
944 unsigned char *data
945 = (unsigned char *) ((struct ego_sign_data_cls *) cls)->data; // data is url decoded
946 struct MHD_Response *resp;
948 char *sig_str;
949 char *result;
950
951 if (ego == NULL)
952 {
955 return;
956 }
957
958 if (ntohl (ego->pk.type) != GNUNET_PUBLIC_KEY_TYPE_EDDSA)
959 {
962 return;
963 }
964
966 (void *) data,
967 strlen ( (char*) data),
968 &sig))
969 {
972 return;
973 }
974
976 sizeof (struct GNUNET_CRYPTO_EddsaSignature),
977 &sig_str);
978
980 "{\"signature\": \"%s\"}",
981 sig_str);
982
984 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
985
986 free (data);
987 free (sig_str);
988 free (result);
989 free (cls);
991}
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:1671
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()

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

Definition at line 1001 of file identity_plugin.c.

1004{
1005 // TODO: replace with precompiler #define
1006 const char *username_key = "user";
1007 const char *data_key = "data";
1008
1009 struct RequestHandle *handle = cls;
1010 struct GNUNET_HashCode cache_key_username;
1011 struct GNUNET_HashCode cache_key_data;
1012 char *username;
1013 char *data;
1014
1015 struct ego_sign_data_cls *cls2;
1016
1017 GNUNET_CRYPTO_hash (username_key, strlen (username_key), &cache_key_username);
1018 GNUNET_CRYPTO_hash (data_key, strlen (data_key), &cache_key_data);
1019
1021 handle->rest_handle->url_param_map,
1022 &cache_key_username)) ||
1024 handle->rest_handle->url_param_map,
1025 &cache_key_data)))
1026 {
1029 return;
1030 }
1031
1032 username = (char *) GNUNET_CONTAINER_multihashmap_get (
1033 handle->rest_handle->url_param_map,
1034 &cache_key_username);
1035
1037 handle->rest_handle->url_param_map,
1038 &cache_key_data);
1039
1040 cls2 = malloc (sizeof(struct ego_sign_data_cls));
1041 cls2->data = (void *) GNUNET_strdup (data);
1042 cls2->handle = handle;
1043
1045 username,
1047 cls2);
1048}
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.
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 1059 of file identity_plugin.c.

1062{
1063 struct MHD_Response *resp;
1064 struct RequestHandle *handle = cls;
1065
1066 // For now, independent of path return all options
1067 resp = GNUNET_REST_create_response (NULL);
1068 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1069 "Access-Control-Allow-Methods",
1070 allow_methods));
1071 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1073 return;
1074}
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 1078 of file identity_plugin.c.

1082{
1083 struct EgoEntry *ego_entry;
1085
1086 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1087 {
1089 return;
1090 }
1091 if (NULL == ego)
1092 {
1094 "Called with NULL ego\n");
1095 return;
1096 }
1098 {
1099 ego_entry = GNUNET_new (struct EgoEntry);
1102 ego_entry->ego = ego;
1103 ego_entry->identifier = GNUNET_strdup (identifier);
1105 ego_tail,
1106 ego_entry);
1107 }
1108 /* Ego renamed or added */
1109 if (identifier != NULL)
1110 {
1111 for (ego_entry = ego_head; NULL != ego_entry;
1112 ego_entry = ego_entry->next)
1113 {
1114 if (ego_entry->ego == ego)
1115 {
1116 /* Rename */
1117 GNUNET_free (ego_entry->identifier);
1118 ego_entry->identifier = GNUNET_strdup (identifier);
1119 break;
1120 }
1121 }
1122 if (NULL == ego_entry)
1123 {
1124 /* Add */
1125 ego_entry = GNUNET_new (struct EgoEntry);
1128 ego_entry->ego = ego;
1129 ego_entry->identifier = GNUNET_strdup (identifier);
1131 ego_tail,
1132 ego_entry);
1133 }
1134 }
1135 else
1136 {
1137 /* Delete */
1138 for (ego_entry = ego_head; NULL != ego_entry;
1139 ego_entry = ego_entry->next)
1140 {
1141 if (ego_entry->ego == ego)
1142 break;
1143 }
1144 if (NULL == ego_entry)
1145 return; /* Not found */
1146
1148 ego_tail,
1149 ego_entry);
1150 GNUNET_free (ego_entry->identifier);
1151 GNUNET_free (ego_entry->keystring);
1152 GNUNET_free (ego_entry);
1153 return;
1154 }
1155
1156}
#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:394
@ 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 1171 of file identity_plugin.c.

1175{
1176 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1178 static const struct GNUNET_REST_RequestHandler handlers[] =
1179 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1180 &ego_get_pubkey },
1181 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1182 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1183 { MHD_HTTP_METHOD_PUT,
1185 &ego_edit_pubkey },
1186 { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1187 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1188 { MHD_HTTP_METHOD_DELETE,
1191 { MHD_HTTP_METHOD_DELETE,
1193 &ego_delete_name },
1194 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1195 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_SIGN, &ego_sign_data},
1197
1198
1200 handle->proc_cls = proc_cls;
1201 handle->proc = proc;
1202 handle->rest_handle = rest_handle;
1203 handle->data = rest_handle->data;
1204 handle->data_size = rest_handle->data_size;
1205
1206 handle->url = GNUNET_strdup (rest_handle->url);
1207 if (handle->url[strlen (handle->url) - 1] == '/')
1208 handle->url[strlen (handle->url) - 1] = '\0';
1209 handle->timeout_task =
1213 handle);
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1215 if (GNUNET_NO ==
1216 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1217 {
1219 return GNUNET_NO;
1220 }
1221
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1223 return GNUNET_YES;
1224}
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:1278
#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_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
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.
#define GNUNET_REST_API_NS_SIGN
Identity Namespace with sign specifier.
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_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.

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

1235{
1236 static struct Plugin plugin;
1237 struct GNUNET_REST_Plugin *api;
1238
1239 id_cfg = c;
1240 if (NULL != plugin.cfg)
1241 return NULL; /* can only initialize once! */
1242 memset (&plugin, 0, sizeof(struct Plugin));
1243 plugin.cfg = c;
1244 api = GNUNET_new (struct GNUNET_REST_Plugin);
1245 api->cls = &plugin;
1248 "%s, %s, %s, %s, %s",
1249 MHD_HTTP_METHOD_GET,
1250 MHD_HTTP_METHOD_POST,
1251 MHD_HTTP_METHOD_PUT,
1252 MHD_HTTP_METHOD_DELETE,
1253 MHD_HTTP_METHOD_OPTIONS);
1256
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1258 return api;
1259}
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
char * name
Plugin name.
void * cls
The closure of the plugin.
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 1269 of file identity_plugin.c.

1270{
1271 struct Plugin *plugin = api->cls;
1272 struct EgoEntry *ego_entry;
1273 struct EgoEntry *ego_tmp;
1274
1275 plugin->cfg = NULL;
1276 while (NULL != requests_head)
1278 if (NULL != identity_handle)
1280
1281 for (ego_entry = ego_head; NULL != ego_entry;)
1282 {
1283 ego_tmp = ego_entry;
1284 ego_entry = ego_entry->next;
1285 GNUNET_free (ego_tmp->identifier);
1286 GNUNET_free (ego_tmp->keystring);
1287 GNUNET_free (ego_tmp);
1288 }
1289
1291 GNUNET_free (api);
1292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1293}
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 114 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 119 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 124 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 129 of file identity_plugin.c.

Referenced by list_ego().

◆ state

int state
static

The processing state.

Definition at line 134 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 139 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 254 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 259 of file identity_plugin.c.

Referenced by cleanup_handle(), and REST_identity_process_request().