2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Martin Schanzenbach
22 * @file identity/plugin_rest_identity.c
23 * @brief GNUnet Namestore REST plugin
28 #include "gnunet_rest_plugin.h"
29 #include "gnunet_identity_service.h"
30 #include "gnunet_rest_lib.h"
31 #include "gnunet_jsonapi_lib.h"
32 #include "gnunet_jsonapi_util.h"
33 #include "microhttpd.h"
35 #include "gnunet_signatures.h"
40 #define GNUNET_REST_API_NS_IDENTITY "/identity"
43 * State while collecting all egos
45 #define ID_REST_STATE_INIT 0
48 * Done collecting egos
50 #define ID_REST_STATE_POST_INIT 1
55 #define GNUNET_REST_JSONAPI_IDENTITY_EGO "ego"
60 #define GNUNET_REST_JSONAPI_IDENTITY_NAME "name"
63 * Attribute to rename "name" TODO we changed id to the pubkey
64 * so this can be unified with "name"
66 #define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname"
69 * URL parameter to change the subsytem for ego
71 #define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem"
77 #define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid"
78 #define GNUNET_REST_ERROR_NO_DATA "No data"
81 * GNUid token lifetime
83 #define GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS 300000000
86 * The configuration handle
88 const struct GNUNET_CONFIGURATION_Handle *cfg;
91 * HTTP methods allows for this plugin
93 static char* allow_methods;
96 * @brief struct returned by the initialization function of the plugin
100 const struct GNUNET_CONFIGURATION_Handle *cfg;
111 struct EgoEntry *next;
116 struct EgoEntry *prev;
131 struct GNUNET_IDENTITY_Ego *ego;
140 struct EgoEntry *ego_head;
145 struct EgoEntry *ego_tail;
148 * Handle to the rest connection
150 struct GNUNET_REST_RequestHandle *conndata_handle;
158 * The processing state
163 * Handle to GNS service.
165 struct GNUNET_IDENTITY_Handle *identity_handle;
170 struct GNUNET_IDENTITY_Operation *op;
173 * Desired timeout for the lookup (default is no timeout).
175 struct GNUNET_TIME_Relative timeout;
178 * ID of a task associated with the resolution process.
180 struct GNUNET_SCHEDULER_Task * timeout_task;
183 * The plugin result processor
185 GNUNET_REST_ResultProcessor proc;
188 * The closure of the result processor
193 * The name to look up
198 * The subsystem set from REST
208 * The data from the REST request
213 * the length of the REST data
223 * Error response message
231 * Cleanup lookup handle
232 * @param handle Handle to clean up
235 cleanup_handle (struct RequestHandle *handle)
237 struct EgoEntry *ego_entry;
238 struct EgoEntry *ego_tmp;
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 if (NULL != handle->name)
242 GNUNET_free (handle->name);
243 if (NULL != handle->timeout_task)
244 GNUNET_SCHEDULER_cancel (handle->timeout_task);
245 if (NULL != handle->identity_handle)
246 GNUNET_IDENTITY_disconnect (handle->identity_handle);
247 if (NULL != handle->subsys)
248 GNUNET_free (handle->subsys);
249 if (NULL != handle->url)
250 GNUNET_free (handle->url);
251 if (NULL != handle->emsg)
252 GNUNET_free (handle->emsg);
253 for (ego_entry = handle->ego_head;
257 ego_entry = ego_entry->next;
258 GNUNET_free (ego_tmp->identifier);
259 GNUNET_free (ego_tmp->keystring);
260 GNUNET_free (ego_tmp);
262 GNUNET_free (handle);
267 * Task run on errors. Reports an error and cleans up everything.
269 * @param cls the `struct RequestHandle`
274 struct RequestHandle *handle = cls;
275 struct MHD_Response *resp;
278 GNUNET_asprintf (&json_error,
279 "{Error while processing request: %s}",
282 resp = GNUNET_REST_create_json_response (json_error);
283 handle->proc (handle->proc_cls,
285 handle->response_code);
286 cleanup_handle (handle);
287 GNUNET_free (json_error);
292 * Callback for IDENTITY_get()
294 * @param cls the RequestHandle
295 * @param ego the Ego found
296 * @param ctx the context
297 * @param name the id of the ego
300 get_ego_for_subsys (void *cls,
301 struct GNUNET_IDENTITY_Ego *ego,
305 struct RequestHandle *handle = cls;
306 struct GNUNET_JSONAPI_Document *json_document;
307 struct GNUNET_JSONAPI_Resource *json_resource;
308 struct EgoEntry *ego_entry;
309 struct MHD_Response *resp;
313 json_document = GNUNET_JSONAPI_document_new ();
315 for (ego_entry = handle->ego_head;
317 ego_entry = ego_entry->next)
319 if ( (NULL != name) && (0 != strcmp (name, ego_entry->identifier)) )
323 json_resource = GNUNET_JSONAPI_resource_new
324 (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring);
325 name_json = json_string (ego_entry->identifier);
326 GNUNET_JSONAPI_resource_add_attr (json_resource,
327 GNUNET_REST_JSONAPI_IDENTITY_NAME,
329 json_decref (name_json);
330 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
333 if (0 == GNUNET_JSONAPI_document_resource_count (json_document))
335 GNUNET_JSONAPI_document_delete (json_document);
336 handle->emsg = GNUNET_strdup("No identity matches results!");
337 GNUNET_SCHEDULER_add_now (&do_error, handle);
340 GNUNET_JSONAPI_document_serialize (json_document, &result_str);
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
342 resp = GNUNET_REST_create_json_response (result_str);
343 GNUNET_JSONAPI_document_delete (json_document);
344 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
345 GNUNET_free (result_str);
346 cleanup_handle (handle);
350 * Create a response with requested ego(s)
352 * @param con the Rest handle
353 * @param url the requested url
354 * @param cls the request handle
357 ego_info_response (struct GNUNET_REST_RequestHandle *con,
365 struct RequestHandle *handle = cls;
366 struct EgoEntry *ego_entry;
367 struct GNUNET_HashCode key;
368 struct MHD_Response *resp;
369 struct GNUNET_JSONAPI_Document *json_document;
370 struct GNUNET_JSONAPI_Resource *json_resource;
373 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY))
375 resp = GNUNET_REST_create_json_response (NULL);
376 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
377 cleanup_handle (handle);
382 if (strlen (GNUNET_REST_API_NS_IDENTITY) < strlen (handle->url))
384 keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY)+1];
386 for (ego_entry = handle->ego_head;
388 ego_entry = ego_entry->next)
390 if ( (NULL != keystring) && (0 != strcmp (keystring, ego_entry->keystring)) )
392 egoname = ego_entry->identifier;
396 if ( NULL == egoname ) {
397 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM,
398 strlen (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM),
401 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
404 subsys_val = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
406 if (NULL != subsys_val)
408 GNUNET_asprintf (&handle->subsys, "%s", subsys_val);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsys_val);
410 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
419 json_document = GNUNET_JSONAPI_document_new ();
422 for (ego_entry = handle->ego_head;
424 ego_entry = ego_entry->next)
426 if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) )
428 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO,
429 ego_entry->keystring);
430 name_str = json_string (ego_entry->identifier);
431 GNUNET_JSONAPI_resource_add_attr (
433 GNUNET_REST_JSONAPI_IDENTITY_NAME,
435 json_decref (name_str);
436 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
438 if (0 == GNUNET_JSONAPI_document_resource_count (json_document))
440 GNUNET_JSONAPI_document_delete (json_document);
441 handle->emsg = GNUNET_strdup ("No identities found!");
442 GNUNET_SCHEDULER_add_now (&do_error, handle);
445 GNUNET_JSONAPI_document_serialize (json_document, &result_str);
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
447 resp = GNUNET_REST_create_json_response (result_str);
448 GNUNET_JSONAPI_document_delete (json_document);
449 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
450 GNUNET_free (result_str);
451 cleanup_handle (handle);
455 * Processing finished
457 * @param cls request handle
458 * @param emsg error message
461 do_finished (void *cls, const char *emsg)
463 struct RequestHandle *handle = cls;
464 struct MHD_Response *resp;
469 handle->emsg = GNUNET_strdup (emsg);
470 GNUNET_SCHEDULER_add_now (&do_error, handle);
473 resp = GNUNET_REST_create_json_response (NULL);
474 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
475 cleanup_handle (handle);
481 * @param con rest handle
483 * @param cls request handle
486 ego_create_cont (struct GNUNET_REST_RequestHandle *con,
490 struct RequestHandle *handle = cls;
491 struct EgoEntry *ego_entry;
492 struct MHD_Response *resp;
493 struct GNUNET_JSONAPI_Document *json_obj;
494 struct GNUNET_JSONAPI_Resource *json_res;
495 json_t *egoname_json;
497 char term_data[handle->data_size+1];
499 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
501 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
502 GNUNET_SCHEDULER_add_now (&do_error, handle);
505 if (0 >= handle->data_size)
507 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
508 GNUNET_SCHEDULER_add_now (&do_error, handle);
511 term_data[handle->data_size] = '\0';
512 memcpy (term_data, handle->data, handle->data_size);
513 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_parse (term_data,
515 if (NULL == json_obj)
517 GNUNET_SCHEDULER_add_now (&do_error, handle);
520 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
522 GNUNET_JSONAPI_document_delete (json_obj);
523 handle->emsg = GNUNET_strdup ("Provided resource count invalid");
524 GNUNET_SCHEDULER_add_now (&do_error, handle);
527 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
528 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
530 GNUNET_JSONAPI_document_delete (json_obj);
531 resp = GNUNET_REST_create_json_response (NULL);
532 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
533 cleanup_handle (handle);
536 egoname_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME);
537 if (!json_is_string (egoname_json))
539 GNUNET_JSONAPI_document_delete (json_obj);
540 handle->emsg = GNUNET_strdup ("No name provided");
541 GNUNET_SCHEDULER_add_now (&do_error, handle);
544 egoname = json_string_value (egoname_json);
545 for (ego_entry = handle->ego_head;
547 ego_entry = ego_entry->next)
549 if (0 == strcasecmp (egoname, ego_entry->identifier))
551 GNUNET_JSONAPI_document_delete (json_obj);
552 resp = GNUNET_REST_create_json_response (NULL);
553 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
554 cleanup_handle (handle);
558 GNUNET_asprintf (&handle->name, "%s", egoname);
559 GNUNET_JSONAPI_document_delete (json_obj);
560 handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
568 * Handle ego edit request
570 * @param con rest connection handle
571 * @param url the url that is requested
572 * @param cls the RequestHandle
575 ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
579 struct GNUNET_JSONAPI_Document *json_obj;
580 struct GNUNET_JSONAPI_Resource *json_res;
581 struct RequestHandle *handle = cls;
582 struct EgoEntry *ego_entry;
583 struct MHD_Response *resp;
586 const char *keystring;
589 char term_data[handle->data_size+1];
590 int ego_exists = GNUNET_NO;
592 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
594 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
595 GNUNET_SCHEDULER_add_now (&do_error, handle);
599 keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
601 for (ego_entry = handle->ego_head;
603 ego_entry = ego_entry->next)
605 if (0 != strcasecmp (keystring, ego_entry->keystring))
607 ego_exists = GNUNET_YES;
611 if (GNUNET_NO == ego_exists)
613 resp = GNUNET_REST_create_json_response (NULL);
614 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
615 cleanup_handle (handle);
619 if (0 >= handle->data_size)
621 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
622 GNUNET_SCHEDULER_add_now (&do_error, handle);
626 term_data[handle->data_size] = '\0';
627 memcpy (term_data, handle->data, handle->data_size);
628 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_parse (term_data,
631 if (NULL == json_obj)
633 handle->emsg = GNUNET_strdup ("Data invalid");
634 GNUNET_SCHEDULER_add_now (&do_error, handle);
638 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
640 GNUNET_JSONAPI_document_delete (json_obj);
641 handle->emsg = GNUNET_strdup ("Resource amount invalid");
642 GNUNET_SCHEDULER_add_now (&do_error, handle);
645 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
647 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
649 GNUNET_JSONAPI_document_delete (json_obj);
650 handle->emsg = GNUNET_strdup ("Resource type invalid");
651 GNUNET_SCHEDULER_add_now (&do_error, handle);
656 name_json = GNUNET_JSONAPI_resource_read_attr (json_res,
657 GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
658 if ((NULL != name_json) && json_is_string (name_json))
660 newname = json_string_value (name_json);
661 for (ego_entry = handle->ego_head;
663 ego_entry = ego_entry->next)
665 if (0 == strcasecmp (newname, ego_entry->identifier) &&
666 0 != strcasecmp (keystring, ego_entry->keystring))
668 //Ego with same name not allowed
669 GNUNET_JSONAPI_document_delete (json_obj);
670 resp = GNUNET_REST_create_json_response (NULL);
671 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
672 cleanup_handle (handle);
676 handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
677 ego_entry->identifier,
681 GNUNET_JSONAPI_document_delete (json_obj);
686 subsys_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
687 if ( (NULL != subsys_json) && json_is_string (subsys_json))
689 subsys = json_string_value (subsys_json);
690 GNUNET_asprintf (&handle->subsys, "%s", subsys);
691 GNUNET_JSONAPI_document_delete (json_obj);
692 handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
699 GNUNET_JSONAPI_document_delete (json_obj);
700 handle->emsg = GNUNET_strdup ("Subsystem not provided");
701 GNUNET_SCHEDULER_add_now (&do_error, handle);
705 ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle,
709 const char *keystring;
710 struct EgoEntry *ego_entry;
711 struct MHD_Response *resp;
712 struct RequestHandle *handle = cls;
713 int ego_exists = GNUNET_NO;
715 if (strlen (GNUNET_REST_API_NS_IDENTITY) >= strlen (handle->url))
717 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
718 GNUNET_SCHEDULER_add_now (&do_error, handle);
722 keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
723 for (ego_entry = handle->ego_head;
725 ego_entry = ego_entry->next)
727 if (0 != strcasecmp (keystring, ego_entry->keystring))
729 ego_exists = GNUNET_YES;
732 if (GNUNET_NO == ego_exists)
734 resp = GNUNET_REST_create_json_response (NULL);
735 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
736 cleanup_handle (handle);
739 handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
740 ego_entry->identifier,
748 * Respond to OPTIONS request
750 * @param con_handle the connection handle
752 * @param cls the RequestHandle
755 options_cont (struct GNUNET_REST_RequestHandle *con_handle,
759 struct MHD_Response *resp;
760 struct RequestHandle *handle = cls;
762 //For now, independent of path return all options
763 resp = GNUNET_REST_create_json_response (NULL);
764 MHD_add_response_header (resp,
765 "Access-Control-Allow-Methods",
767 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
768 cleanup_handle (handle);
773 * Handle rest request
775 * @param handle the request handle
778 init_cont (struct RequestHandle *handle)
780 struct GNUNET_REST_RequestHandlerError err;
781 static const struct GNUNET_REST_RequestHandler handlers[] = {
782 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
783 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
784 {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont},
785 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
786 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont},
787 GNUNET_REST_HANDLER_END
790 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (handle->conndata_handle,
795 handle->response_code = err.error_code;
796 GNUNET_SCHEDULER_add_now (&do_error, handle);
801 * If listing is enabled, prints information about the egos.
803 * This function is initially called for all egos and then again
804 * whenever a ego's identifier changes or if it is deleted. At the
805 * end of the initial pass over all egos, the function is once called
806 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
807 * be invoked in the future or that there was an error.
809 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
810 * this function is only called ONCE, and 'NULL' being passed in
811 * 'ego' does indicate an error (i.e. name is taken or no default
812 * value is known). If 'ego' is non-NULL and if '*ctx'
813 * is set in those callbacks, the value WILL be passed to a subsequent
814 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
815 * that one was not NULL).
817 * When an identity is renamed, this function is called with the
818 * (known) ego but the NEW identifier.
820 * When an identity is deleted, this function is called with the
821 * (known) ego and "NULL" for the 'identifier'. In this case,
822 * the 'ego' is henceforth invalid (and the 'ctx' should also be
826 * @param ego ego handle
827 * @param ctx context for application to store data for this ego
828 * (during the lifetime of this process, initially NULL)
829 * @param identifier identifier assigned by the user for this ego,
830 * NULL if the user just deleted the ego and it
831 * must thus no longer be used
835 struct GNUNET_IDENTITY_Ego *ego,
837 const char *identifier)
839 struct RequestHandle *handle = cls;
840 struct EgoEntry *ego_entry;
841 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
843 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
845 handle->state = ID_REST_STATE_POST_INIT;
849 if (ID_REST_STATE_INIT == handle->state) {
850 ego_entry = GNUNET_new (struct EgoEntry);
851 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
852 ego_entry->keystring =
853 GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
854 ego_entry->ego = ego;
855 GNUNET_asprintf (&ego_entry->identifier, "%s", identifier);
856 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, ego_entry);
862 * Function processing the REST call
864 * @param method HTTP method
865 * @param url URL of the HTTP request
866 * @param data body of the HTTP request (optional)
867 * @param data_size length of the body
868 * @param proc callback function for the result
869 * @param proc_cls closure for callback function
870 * @return GNUNET_OK if request accepted
873 rest_identity_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
874 GNUNET_REST_ResultProcessor proc,
877 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
881 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
883 handle->proc_cls = proc_cls;
885 handle->state = ID_REST_STATE_INIT;
886 handle->conndata_handle = conndata_handle;
887 handle->data = conndata_handle->data;
888 handle->data_size = conndata_handle->data_size;
889 handle->method = conndata_handle->method;
890 GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
891 if (handle->url[strlen (handle->url)-1] == '/')
892 handle->url[strlen (handle->url)-1] = '\0';
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 handle->identity_handle = GNUNET_IDENTITY_connect (cfg,
898 handle->timeout_task =
899 GNUNET_SCHEDULER_add_delayed (handle->timeout,
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 * Entry point for the plugin.
911 * @param cls Config info
912 * @return NULL on error, otherwise the plugin context
915 libgnunet_plugin_rest_identity_init (void *cls)
917 static struct Plugin plugin;
918 struct GNUNET_REST_Plugin *api;
921 if (NULL != plugin.cfg)
922 return NULL; /* can only initialize once! */
923 memset (&plugin, 0, sizeof (struct Plugin));
925 api = GNUNET_new (struct GNUNET_REST_Plugin);
927 api->name = GNUNET_REST_API_NS_IDENTITY;
928 api->process_request = &rest_identity_process_request;
929 GNUNET_asprintf (&allow_methods,
930 "%s, %s, %s, %s, %s",
932 MHD_HTTP_METHOD_POST,
934 MHD_HTTP_METHOD_DELETE,
935 MHD_HTTP_METHOD_OPTIONS);
937 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
938 _("Identity REST API initialized\n"));
944 * Exit point from the plugin.
946 * @param cls the plugin context (as returned by "init")
947 * @return always NULL
950 libgnunet_plugin_rest_identity_done (void *cls)
952 struct GNUNET_REST_Plugin *api = cls;
953 struct Plugin *plugin = api->cls;
956 GNUNET_free_non_null (allow_methods);
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Identity REST plugin is finished\n");
963 /* end of plugin_rest_gns.c */