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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Martin Schanzenbach
20 * @author Philippe Buschmann
21 * @file namestore/plugin_rest_namestore.c
22 * @brief GNUnet Namestore REST plugin
26 #include "gnunet_rest_plugin.h"
27 #include "gnunet_gns_service.h"
28 #include "gnunet_namestore_service.h"
29 #include "gnunet_identity_service.h"
30 #include "gnunet_rest_lib.h"
31 #include "gnunet_json_lib.h"
32 #include "microhttpd.h"
38 #define GNUNET_REST_API_NS_NAMESTORE "/namestore"
41 * Error message Unknown Error
43 #define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
46 * Error message No identity found
48 #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
51 * Error message No default zone specified
53 #define GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE "No default zone specified"
56 * Error message Failed request
58 #define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed"
61 * Error message invalid data
63 #define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid"
66 * Error message No data
68 #define GNUNET_REST_NAMESTORE_NO_DATA "No data"
71 * State while collecting all egos
73 #define ID_REST_STATE_INIT 0
76 * Done collecting egos
78 #define ID_REST_STATE_POST_INIT 1
80 * The configuration handle
82 const struct GNUNET_CONFIGURATION_Handle *cfg;
85 * HTTP methods allows for this plugin
87 static char* allow_methods;
90 * @brief struct returned by the initialization function of the plugin
94 const struct GNUNET_CONFIGURATION_Handle *cfg;
98 * The default namestore ego
105 struct EgoEntry *next;
110 struct EgoEntry *prev;
125 struct GNUNET_IDENTITY_Ego *ego;
141 struct GNUNET_GNSRECORD_Data *rd;
144 * NAMESTORE Operation
146 struct GNUNET_NAMESTORE_QueueEntry *add_qe;
154 * The processing state
159 * Handle to NAMESTORE
161 struct GNUNET_NAMESTORE_Handle *ns_handle;
164 * Handle to NAMESTORE it
166 struct GNUNET_NAMESTORE_ZoneIterator *list_it;
169 * Private key for the zone
171 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey;
176 struct EgoEntry *ego_entry;
181 struct EgoEntry *ego_head;
186 struct EgoEntry *ego_tail;
191 struct GNUNET_IDENTITY_Operation *op;
194 * Handle to Identity service.
196 struct GNUNET_IDENTITY_Handle *identity_handle;
201 struct GNUNET_REST_RequestHandle *rest_handle;
204 * Desired timeout for the lookup (default is no timeout).
206 struct GNUNET_TIME_Relative timeout;
209 * ID of a task associated with the resolution process.
211 struct GNUNET_SCHEDULER_Task *timeout_task;
214 * The plugin result processor
216 GNUNET_REST_ResultProcessor proc;
219 * The closure of the result processor
229 * Error response message
241 * Cleanup lookup handle
242 * @param handle Handle to clean up
245 cleanup_handle (void *cls)
247 struct RequestHandle *handle = cls;
248 struct EgoEntry *ego_entry;
249 struct EgoEntry *ego_tmp;
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 if (NULL != handle->timeout_task)
255 GNUNET_SCHEDULER_cancel (handle->timeout_task);
256 handle->timeout_task = NULL;
258 if (NULL != handle->record_name)
259 GNUNET_free(handle->record_name);
260 if (NULL != handle->url)
261 GNUNET_free(handle->url);
262 if (NULL != handle->emsg)
263 GNUNET_free(handle->emsg);
264 if (NULL != handle->rd)
266 if (NULL != handle->rd->data)
267 GNUNET_free((void*)handle->rd->data);
268 GNUNET_free(handle->rd);
270 if (NULL != handle->timeout_task)
271 GNUNET_SCHEDULER_cancel(handle->timeout_task);
272 if (NULL != handle->list_it)
273 GNUNET_NAMESTORE_zone_iteration_stop(handle->list_it);
274 if (NULL != handle->add_qe)
275 GNUNET_NAMESTORE_cancel(handle->add_qe);
276 if (NULL != handle->identity_handle)
277 GNUNET_IDENTITY_disconnect(handle->identity_handle);
278 if (NULL != handle->ns_handle)
280 GNUNET_NAMESTORE_disconnect(handle->ns_handle);
283 for (ego_entry = handle->ego_head;
287 ego_entry = ego_entry->next;
288 GNUNET_free(ego_tmp->identifier);
289 GNUNET_free(ego_tmp->keystring);
290 GNUNET_free(ego_tmp);
293 if(NULL != handle->resp_object)
295 json_decref(handle->resp_object);
298 GNUNET_free (handle);
303 * Task run on errors. Reports an error and cleans up everything.
305 * @param cls the `struct RequestHandle`
310 struct RequestHandle *handle = cls;
311 struct MHD_Response *resp;
312 json_t *json_error = json_object();
315 if (NULL == handle->emsg)
316 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_ERROR_UNKNOWN);
318 json_object_set_new(json_error,"error", json_string(handle->emsg));
320 if (0 == handle->response_code)
321 handle->response_code = MHD_HTTP_OK;
322 response = json_dumps (json_error, 0);
323 resp = GNUNET_REST_create_response (response);
324 handle->proc (handle->proc_cls, resp, handle->response_code);
325 json_decref(json_error);
326 GNUNET_free(response);
327 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
332 * Get EgoEntry from list with either a public key or a name
333 * If public key and name are not NULL, it returns the public key result first
335 * @param handle the RequestHandle
336 * @param pubkey the public key of an identity (only one can be NULL)
337 * @param name the name of an identity (only one can be NULL)
338 * @return EgoEntry or NULL if not found
341 get_egoentry_namestore(struct RequestHandle *handle, char *name)
343 struct EgoEntry *ego_entry;
346 for (ego_entry = handle->ego_head;
348 ego_entry = ego_entry->next)
350 if (0 != strcasecmp (name, ego_entry->identifier))
360 * Does internal server error when iteration failed.
362 * @param cls the `struct RequestHandle`
365 namestore_iteration_error (void *cls)
367 struct RequestHandle *handle = cls;
368 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
369 GNUNET_SCHEDULER_add_now (&do_error, handle);
375 * Create finished callback
377 * @param cls the `struct RequestHandle`
378 * @param success the success indicating integer, GNUNET_OK on success
379 * @param emsg the error message (can be NULL)
382 create_finished (void *cls, int32_t success, const char *emsg)
384 struct RequestHandle *handle = cls;
385 struct MHD_Response *resp;
387 handle->add_qe = NULL;
388 if (GNUNET_YES != success)
392 handle->emsg = GNUNET_strdup(emsg);
393 GNUNET_SCHEDULER_add_now (&do_error, handle);
396 handle->emsg = GNUNET_strdup("Error storing records");
397 GNUNET_SCHEDULER_add_now (&do_error, handle);
400 resp = GNUNET_REST_create_response (NULL);
401 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
402 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
407 * Delete finished callback
409 * @param cls the `struct RequestHandle`
410 * @param success the success indicating integer, GNUNET_OK on success
411 * @param emsg the error message (can be NULL)
414 del_finished (void *cls, int32_t success, const char *emsg)
416 struct RequestHandle *handle = cls;
418 handle->add_qe = NULL;
419 if (GNUNET_NO == success)
421 handle->response_code = MHD_HTTP_NOT_FOUND;
422 handle->emsg = GNUNET_strdup("No record found");
423 GNUNET_SCHEDULER_add_now (&do_error, handle);
426 if (GNUNET_SYSERR == success)
430 handle->emsg = GNUNET_strdup(emsg);
431 GNUNET_SCHEDULER_add_now (&do_error, handle);
434 handle->emsg = GNUNET_strdup("Deleting record failed");
435 GNUNET_SCHEDULER_add_now (&do_error, handle);
438 handle->proc (handle->proc_cls,
439 GNUNET_REST_create_response (NULL),
440 MHD_HTTP_NO_CONTENT);
441 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
446 * Iteration over all results finished, build final
449 * @param cls the `struct RequestHandle`
452 namestore_list_finished (void *cls)
454 struct RequestHandle *handle = cls;
456 struct MHD_Response *resp;
458 handle->list_it = NULL;
460 if (NULL == handle->resp_object)
461 handle->resp_object = json_array();
463 result_str = json_dumps (handle->resp_object, 0);
464 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
465 resp = GNUNET_REST_create_response (result_str);
466 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
467 GNUNET_free_non_null (result_str);
468 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
473 * Create a response with requested records
475 * @param handle the RequestHandle
478 namestore_list_iteration (void *cls,
479 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
482 const struct GNUNET_GNSRECORD_Data *rd)
484 struct RequestHandle *handle = cls;
487 if (NULL == handle->resp_object)
488 handle->resp_object = json_array();
490 for (unsigned int i = 0; i < rd_len; i++)
492 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
493 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)) )
496 record_obj = GNUNET_JSON_from_gns_record(rname,rd);
498 if(NULL == record_obj)
501 json_array_append (handle->resp_object, record_obj);
502 json_decref (record_obj);
505 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
510 * @param ego ego handle
511 * @param ctx context for application to store data for this ego
512 * (during the lifetime of this process, initially NULL)
513 * @param identifier identifier assigned by the user for this ego,
514 * NULL if the user just deleted the ego and it
515 * must thus no longer be used
518 default_ego_get (void *cls,
519 struct GNUNET_IDENTITY_Ego *ego,
521 const char *identifier)
523 struct RequestHandle *handle = cls;
528 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
529 GNUNET_SCHEDULER_add_now (&do_error, handle);
532 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
534 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
536 &namestore_iteration_error,
538 &namestore_list_iteration,
540 &namestore_list_finished,
542 if (NULL == handle->list_it)
544 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
545 GNUNET_SCHEDULER_add_now (&do_error, handle);
552 * Handle namestore GET request
554 * @param con_handle the connection handle
556 * @param cls the RequestHandle
559 namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
563 struct RequestHandle *handle = cls;
564 struct EgoEntry *ego_entry;
570 //set zone to name if given
571 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
573 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
574 ego_entry = get_egoentry_namestore(handle, egoname);
576 if (NULL == ego_entry)
578 handle->response_code = MHD_HTTP_NOT_FOUND;
579 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
580 GNUNET_SCHEDULER_add_now (&do_error, handle);
584 if ( NULL != ego_entry )
586 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
589 if (NULL == handle->zone_pkey)
591 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
597 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
599 &namestore_iteration_error,
601 &namestore_list_iteration,
603 &namestore_list_finished,
605 if (NULL == handle->list_it)
607 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
608 GNUNET_SCHEDULER_add_now (&do_error, handle);
616 * @param ego ego handle
617 * @param ctx context for application to store data for this ego
618 * (during the lifetime of this process, initially NULL)
619 * @param identifier identifier assigned by the user for this ego,
620 * NULL if the user just deleted the ego and it
621 * must thus no longer be used
624 default_ego_post (void *cls,
625 struct GNUNET_IDENTITY_Ego *ego,
627 const char *identifier)
629 struct RequestHandle *handle = cls;
634 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
635 GNUNET_SCHEDULER_add_now (&do_error, handle);
638 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
640 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
647 if (NULL == handle->add_qe)
649 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
650 GNUNET_SCHEDULER_add_now (&do_error, handle);
657 * Handle namestore POST request
659 * @param con_handle the connection handle
661 * @param cls the RequestHandle
664 namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
668 struct RequestHandle *handle = cls;
669 struct GNUNET_GNSRECORD_Data *gns_record;
670 struct EgoEntry *ego_entry;
675 char term_data[handle->rest_handle->data_size + 1];
677 struct GNUNET_JSON_Specification gnsspec[] = {
678 GNUNET_JSON_spec_gnsrecord_data(&gns_record),
679 GNUNET_JSON_spec_end ()
682 if (0 >= handle->rest_handle->data_size)
684 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA);
685 GNUNET_SCHEDULER_add_now (&do_error, handle);
688 term_data[handle->rest_handle->data_size] = '\0';
689 GNUNET_memcpy(term_data, handle->rest_handle->data,
690 handle->rest_handle->data_size);
691 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
692 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
694 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
695 GNUNET_SCHEDULER_add_now (&do_error, handle);
696 GNUNET_JSON_parse_free(gnsspec);
697 json_decref (data_js);
700 handle->rd = gns_record;
702 name_json = json_object_get(data_js, "record_name");
703 if (!json_is_string(name_json))
705 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
706 GNUNET_SCHEDULER_add_now (&do_error, handle);
707 json_decref (data_js);
710 handle->record_name = GNUNET_strdup(json_string_value(name_json));
711 if(NULL == handle->record_name)
713 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
714 GNUNET_SCHEDULER_add_now (&do_error, handle);
715 json_decref (data_js);
718 if (0 >= strlen(handle->record_name))
720 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
721 GNUNET_SCHEDULER_add_now (&do_error, handle);
722 json_decref (data_js);
725 json_decref (data_js);
730 //set zone to name if given
731 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
733 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
734 ego_entry = get_egoentry_namestore(handle, egoname);
736 if (NULL == ego_entry)
738 handle->response_code = MHD_HTTP_NOT_FOUND;
739 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
740 GNUNET_SCHEDULER_add_now (&do_error, handle);
744 if (NULL != ego_entry)
746 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
748 if (NULL == handle->zone_pkey)
750 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
756 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
763 if (NULL == handle->add_qe)
765 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
766 GNUNET_SCHEDULER_add_now (&do_error, handle);
774 * @param ego ego handle
775 * @param ctx context for application to store data for this ego
776 * (during the lifetime of this process, initially NULL)
777 * @param identifier identifier assigned by the user for this ego,
778 * NULL if the user just deleted the ego and it
779 * must thus no longer be used
782 default_ego_delete (void *cls,
783 struct GNUNET_IDENTITY_Ego *ego,
785 const char *identifier)
787 struct RequestHandle *handle = cls;
792 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
793 GNUNET_SCHEDULER_add_now (&do_error, handle);
796 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
798 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
805 if (NULL == handle->add_qe)
807 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
808 GNUNET_SCHEDULER_add_now (&do_error, handle);
815 * Handle namestore DELETE request
817 * @param con_handle the connection handle
819 * @param cls the RequestHandle
822 namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
826 struct RequestHandle *handle = cls;
827 struct GNUNET_HashCode key;
828 struct EgoEntry *ego_entry;
834 //set zone to name if given
835 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
837 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
838 ego_entry = get_egoentry_namestore(handle, egoname);
840 if (NULL == ego_entry)
842 handle->response_code = MHD_HTTP_NOT_FOUND;
843 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
844 GNUNET_SCHEDULER_add_now (&do_error, handle);
848 if ( NULL != ego_entry )
850 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
853 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
855 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
858 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
859 GNUNET_SCHEDULER_add_now (&do_error, handle);
862 handle->record_name = GNUNET_strdup(
863 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key));
865 if (NULL == handle->zone_pkey)
867 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
874 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
881 if (NULL == handle->add_qe)
883 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
884 GNUNET_SCHEDULER_add_now (&do_error, handle);
892 * Respond to OPTIONS request
894 * @param con_handle the connection handle
896 * @param cls the RequestHandle
899 options_cont (struct GNUNET_REST_RequestHandle *con_handle,
903 struct MHD_Response *resp;
904 struct RequestHandle *handle = cls;
906 //independent of path return all options
907 resp = GNUNET_REST_create_response (NULL);
908 MHD_add_response_header (resp,
909 "Access-Control-Allow-Methods",
911 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
912 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
918 * Handle rest request
920 * @param handle the request handle
923 init_cont (struct RequestHandle *handle)
925 struct GNUNET_REST_RequestHandlerError err;
926 static const struct GNUNET_REST_RequestHandler handlers[] = {
927 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get},
928 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add},
929 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete},
930 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont},
931 GNUNET_REST_HANDLER_END
934 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle,
939 handle->response_code = err.error_code;
940 GNUNET_SCHEDULER_add_now (&do_error, handle);
946 * This function is initially called for all egos and then again
947 * whenever a ego's identifier changes or if it is deleted. At the
948 * end of the initial pass over all egos, the function is once called
949 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
950 * be invoked in the future or that there was an error.
952 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
953 * this function is only called ONCE, and 'NULL' being passed in
954 * 'ego' does indicate an error (i.e. name is taken or no default
955 * value is known). If 'ego' is non-NULL and if '*ctx'
956 * is set in those callbacks, the value WILL be passed to a subsequent
957 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
958 * that one was not NULL).
960 * When an identity is renamed, this function is called with the
961 * (known) ego but the NEW identifier.
963 * When an identity is deleted, this function is called with the
964 * (known) ego and "NULL" for the 'identifier'. In this case,
965 * the 'ego' is henceforth invalid (and the 'ctx' should also be
969 * @param ego ego handle
970 * @param ctx context for application to store data for this ego
971 * (during the lifetime of this process, initially NULL)
972 * @param name identifier assigned by the user for this ego,
973 * NULL if the user just deleted the ego and it
974 * must thus no longer be used
977 id_connect_cb (void *cls,
978 struct GNUNET_IDENTITY_Ego *ego,
982 struct RequestHandle *handle = cls;
983 struct EgoEntry *ego_entry;
984 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
986 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
988 handle->state = ID_REST_STATE_POST_INIT;
992 if (ID_REST_STATE_INIT == handle->state)
994 ego_entry = GNUNET_new(struct EgoEntry);
995 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
996 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
997 ego_entry->ego = ego;
998 GNUNET_asprintf (&ego_entry->identifier, "%s", name);
999 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, handle->ego_tail,
1007 * Function processing the REST call
1009 * @param method HTTP method
1010 * @param url URL of the HTTP request
1011 * @param data body of the HTTP request (optional)
1012 * @param data_size length of the body
1013 * @param proc callback function for the result
1014 * @param proc_cls closure for callback function
1015 * @return GNUNET_OK if request accepted
1018 rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1019 GNUNET_REST_ResultProcessor proc,
1022 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1024 handle->response_code = 0;
1025 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1026 handle->proc_cls = proc_cls;
1027 handle->proc = proc;
1028 handle->rest_handle = rest_handle;
1029 handle->zone_pkey = NULL;
1031 handle->url = GNUNET_strdup (rest_handle->url);
1032 if (handle->url[strlen (handle->url)-1] == '/')
1033 handle->url[strlen (handle->url)-1] = '\0';
1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1036 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
1037 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
1038 handle->timeout_task =
1039 GNUNET_SCHEDULER_add_delayed (handle->timeout,
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1048 * Entry point for the plugin.
1050 * @param cls Config info
1051 * @return NULL on error, otherwise the plugin context
1054 libgnunet_plugin_rest_namestore_init (void *cls)
1056 static struct Plugin plugin;
1057 struct GNUNET_REST_Plugin *api;
1060 if (NULL != plugin.cfg)
1061 return NULL; /* can only initialize once! */
1062 memset (&plugin, 0, sizeof (struct Plugin));
1064 api = GNUNET_new (struct GNUNET_REST_Plugin);
1066 api->name = GNUNET_REST_API_NS_NAMESTORE;
1067 api->process_request = &rest_process_request;
1068 GNUNET_asprintf (&allow_methods,
1069 "%s, %s, %s, %s, %s",
1070 MHD_HTTP_METHOD_GET,
1071 MHD_HTTP_METHOD_POST,
1072 MHD_HTTP_METHOD_PUT,
1073 MHD_HTTP_METHOD_DELETE,
1074 MHD_HTTP_METHOD_OPTIONS);
1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1077 _("Namestore REST API initialized\n"));
1083 * Exit point from the plugin.
1085 * @param cls the plugin context (as returned by "init")
1086 * @return always NULL
1089 libgnunet_plugin_rest_namestore_done (void *cls)
1091 struct GNUNET_REST_Plugin *api = cls;
1092 struct Plugin *plugin = api->cls;
1095 GNUNET_free_non_null (allow_methods);
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1098 "Namestore REST plugin is finished\n");
1102 /* end of plugin_rest_namestore.c */