GNUnet  0.10.x
plugin_rest_namestore.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2015 GNUnet e.V.
4 
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.
9 
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.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 #include "platform.h"
28 #include "gnunet_rest_plugin.h"
29 #include "gnunet_gns_service.h"
32 #include "gnunet_rest_lib.h"
33 #include "gnunet_json_lib.h"
34 #include "microhttpd.h"
35 #include <jansson.h>
36 
40 #define GNUNET_REST_API_NS_NAMESTORE "/namestore"
41 
45 #define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
46 
50 #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
51 
52 
56 #define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed"
57 
61 #define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid"
62 
66 #define GNUNET_REST_NAMESTORE_NO_DATA "No data"
67 
71 #define ID_REST_STATE_INIT 0
72 
76 #define ID_REST_STATE_POST_INIT 1
77 
81 
85 static char *allow_methods;
86 
90 struct Plugin {
91  const struct GNUNET_CONFIGURATION_Handle *cfg;
92 };
93 
97 struct EgoEntry {
101  struct EgoEntry *next;
102 
106  struct EgoEntry *prev;
107 
111  char *identifier;
112 
116  char *keystring;
117 
121  struct GNUNET_IDENTITY_Ego *ego;
122 };
123 
127 struct RequestHandle {
131  char *record_name;
132 
137 
141  unsigned int rd_count;
142 
147 
151  json_t *resp_object;
152 
156  int state;
157 
162 
167 
172 
177 
181  struct EgoEntry *ego_head;
182 
186  struct EgoEntry *ego_tail;
187 
192 
197 
201  struct GNUNET_REST_RequestHandle *rest_handle;
202 
207 
212 
217 
221  void *proc_cls;
222 
226  char *url;
227 
231  char *emsg;
232 
236  int response_code;
237 };
238 
243 static void
244 cleanup_handle(void *cls)
245 {
246  struct RequestHandle *handle = cls;
247  struct EgoEntry *ego_entry;
248  struct EgoEntry *ego_tmp;
249 
250  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
251  if (NULL != handle->timeout_task)
252  {
254  handle->timeout_task = NULL;
255  }
256  if (NULL != handle->record_name)
257  GNUNET_free(handle->record_name);
258  if (NULL != handle->url)
259  GNUNET_free(handle->url);
260  if (NULL != handle->emsg)
261  GNUNET_free(handle->emsg);
262  if (NULL != handle->rd)
263  {
264  for (int i = 0; i < handle->rd_count; i++)
265  {
266  if (NULL != handle->rd[i].data)
267  GNUNET_free((void *)handle->rd[i].data);
268  }
269  GNUNET_free(handle->rd);
270  }
271  if (NULL != handle->timeout_task)
273  if (NULL != handle->list_it)
275  if (NULL != handle->add_qe)
277  if (NULL != handle->identity_handle)
279  if (NULL != handle->ns_handle)
280  {
282  }
283 
284  for (ego_entry = handle->ego_head; NULL != ego_entry;)
285  {
286  ego_tmp = ego_entry;
287  ego_entry = ego_entry->next;
288  GNUNET_free(ego_tmp->identifier);
289  GNUNET_free(ego_tmp->keystring);
290  GNUNET_free(ego_tmp);
291  }
292 
293  if (NULL != handle->resp_object)
294  {
295  json_decref(handle->resp_object);
296  }
297 
298  GNUNET_free(handle);
299 }
300 
301 
307 static void
308 do_error(void *cls)
309 {
310  struct RequestHandle *handle = cls;
311  struct MHD_Response *resp;
312  json_t *json_error = json_object();
313  char *response;
314 
315  if (NULL == handle->emsg)
317 
318  json_object_set_new(json_error, "error", json_string(handle->emsg));
319 
320  if (0 == handle->response_code)
321  handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
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);
328 }
329 
330 
340 struct EgoEntry *
342 {
343  struct EgoEntry *ego_entry;
344 
345  if (NULL != name)
346  {
347  for (ego_entry = handle->ego_head; NULL != ego_entry;
348  ego_entry = ego_entry->next)
349  {
350  if (0 != strcasecmp(name, ego_entry->identifier))
351  continue;
352  return ego_entry;
353  }
354  }
355  return NULL;
356 }
357 
358 
364 static void
366 {
367  struct RequestHandle *handle = cls;
368 
371  return;
372 }
373 
374 
382 static void
383 create_finished(void *cls, int32_t success, const char *emsg)
384 {
385  struct RequestHandle *handle = cls;
386  struct MHD_Response *resp;
387 
388  handle->add_qe = NULL;
389  if (GNUNET_YES != success)
390  {
391  if (NULL != emsg)
392  {
393  handle->emsg = GNUNET_strdup(emsg);
395  return;
396  }
397  handle->emsg = GNUNET_strdup("Error storing records");
399  return;
400  }
401  resp = GNUNET_REST_create_response(NULL);
402  handle->proc(handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
404 }
405 
406 
414 static void
415 del_finished(void *cls, int32_t success, const char *emsg)
416 {
417  struct RequestHandle *handle = cls;
418 
419  handle->add_qe = NULL;
420  if (GNUNET_NO == success)
421  {
422  handle->response_code = MHD_HTTP_NOT_FOUND;
423  handle->emsg = GNUNET_strdup("No record found");
425  return;
426  }
427  if (GNUNET_SYSERR == success)
428  {
429  if (NULL != emsg)
430  {
431  handle->emsg = GNUNET_strdup(emsg);
433  return;
434  }
435  handle->emsg = GNUNET_strdup("Deleting record failed");
437  return;
438  }
439  handle->proc(handle->proc_cls,
441  MHD_HTTP_NO_CONTENT);
443 }
444 
445 
452 static void
454 {
455  struct RequestHandle *handle = cls;
456  char *result_str;
457  struct MHD_Response *resp;
458 
459  handle->list_it = NULL;
460 
461  if (NULL == handle->resp_object)
462  handle->resp_object = json_array();
463 
464  result_str = json_dumps(handle->resp_object, 0);
465  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
466  resp = GNUNET_REST_create_response(result_str);
467  handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
468  GNUNET_free_non_null(result_str);
470 }
471 
472 
478 static void
480  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
481  const char *rname,
482  unsigned int rd_len,
483  const struct GNUNET_GNSRECORD_Data *rd)
484 {
485  struct RequestHandle *handle = cls;
486  json_t *record_obj;
487 
488  if (NULL == handle->resp_object)
489  handle->resp_object = json_array();
490  record_obj = GNUNET_JSON_from_gnsrecord(rname,
491  rd,
492  rd_len);
493  json_array_append_new(handle->resp_object, record_obj);
495 }
496 
497 
505 void
507  const char *url,
508  void *cls)
509 {
510  struct RequestHandle *handle = cls;
511  struct EgoEntry *ego_entry;
512  char *egoname;
513 
514  egoname = NULL;
515  ego_entry = NULL;
516 
517  // set zone to name if given
518  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
519  {
520  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
521  ego_entry = get_egoentry_namestore(handle, egoname);
522 
523  if (NULL == ego_entry)
524  {
525  handle->response_code = MHD_HTTP_NOT_FOUND;
528  return;
529  }
530  }
531  if (NULL != ego_entry)
532  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
533 
534  handle->list_it =
536  handle->zone_pkey,
538  handle,
540  handle,
542  handle);
543  if (NULL == handle->list_it)
544  {
547  return;
548  }
549 }
550 
551 
552 static void
554 {
555  struct RequestHandle *handle = cls;
556 
559 }
560 
561 
562 static void
563 ns_lookup_cb(void *cls,
564  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
565  const char *label,
566  unsigned int rd_count,
567  const struct GNUNET_GNSRECORD_Data *rd)
568 {
569  struct RequestHandle *handle = cls;
570  struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count];
571 
572  for (int i = 0; i < rd_count; i++)
573  rd_new[i] = rd[i];
574  for (int j = 0; j < handle->rd_count; j++)
575  rd_new[rd_count + j] = handle->rd[j];
576  handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle,
577  handle->zone_pkey,
578  handle->record_name,
579  rd_count + handle->rd_count,
580  rd_new,
582  handle);
583  if (NULL == handle->add_qe)
584  {
587  return;
588  }
589 }
590 
591 
599 void
601  const char *url,
602  void *cls)
603 {
604  struct RequestHandle *handle = cls;
605  struct EgoEntry *ego_entry;
606  char *egoname;
607  json_t *data_js;
608  json_error_t err;
609 
610  char term_data[handle->rest_handle->data_size + 1];
611 
612  if (0 >= handle->rest_handle->data_size)
613  {
616  return;
617  }
618  term_data[handle->rest_handle->data_size] = '\0';
619  GNUNET_memcpy(term_data,
620  handle->rest_handle->data,
621  handle->rest_handle->data_size);
622  data_js = json_loads(term_data, JSON_DECODE_ANY, &err);
623  struct GNUNET_JSON_Specification gnsspec[] =
624  { GNUNET_JSON_spec_gnsrecord(&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end() };
625  if (GNUNET_OK != GNUNET_JSON_parse(data_js, gnsspec, NULL, NULL))
626  {
629  json_decref(data_js);
630  return;
631  }
632  GNUNET_JSON_parse_free(gnsspec);
633  if (0 >= strlen(handle->record_name))
634  {
637  json_decref(data_js);
638  return;
639  }
640  json_decref(data_js);
641 
642  egoname = NULL;
643  ego_entry = NULL;
644 
645  // set zone to name if given
646  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
647  {
648  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
649  ego_entry = get_egoentry_namestore(handle, egoname);
650 
651  if (NULL == ego_entry)
652  {
653  handle->response_code = MHD_HTTP_NOT_FOUND;
656  return;
657  }
658  }
659  if (NULL != ego_entry)
660  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
662  handle->zone_pkey,
663  handle->record_name,
665  handle,
666  &ns_lookup_cb,
667  handle);
668  if (NULL == handle->add_qe)
669  {
672  return;
673  }
674 }
675 
676 
684 void
686  const char *url,
687  void *cls)
688 {
689  struct RequestHandle *handle = cls;
690  struct GNUNET_HashCode key;
691  struct EgoEntry *ego_entry;
692  char *egoname;
693 
694  egoname = NULL;
695  ego_entry = NULL;
696 
697  // set zone to name if given
698  if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
699  {
700  egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
701  ego_entry = get_egoentry_namestore(handle, egoname);
702 
703  if (NULL == ego_entry)
704  {
705  handle->response_code = MHD_HTTP_NOT_FOUND;
708  return;
709  }
710  }
711  if (NULL != ego_entry)
712  handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
713 
714  GNUNET_CRYPTO_hash("record_name", strlen("record_name"), &key);
715  if (GNUNET_NO ==
717  {
720  return;
721  }
722  handle->record_name = GNUNET_strdup(
724 
726  handle->zone_pkey,
727  handle->record_name,
728  0,
729  NULL,
730  &del_finished,
731  handle);
732  if (NULL == handle->add_qe)
733  {
736  return;
737  }
738 }
739 
740 
748 static void
750  const char *url,
751  void *cls)
752 {
753  struct MHD_Response *resp;
754  struct RequestHandle *handle = cls;
755 
756  // independent of path return all options
757  resp = GNUNET_REST_create_response(NULL);
758  MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods);
759  handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
761  return;
762 }
763 
764 
770 static void
772 {
774  static const struct GNUNET_REST_RequestHandler handlers[] =
775  { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get },
776  { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
777  { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete },
778  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont },
780 
781  if (GNUNET_NO ==
782  GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle))
783  {
784  handle->response_code = err.error_code;
786  }
787 }
788 
789 
821 static void
822 id_connect_cb(void *cls,
823  struct GNUNET_IDENTITY_Ego *ego,
824  void **ctx,
825  const char *name)
826 {
827  struct RequestHandle *handle = cls;
828  struct EgoEntry *ego_entry;
830 
831  if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
832  {
833  handle->state = ID_REST_STATE_POST_INIT;
834  init_cont(handle);
835  return;
836  }
837  if (ID_REST_STATE_INIT == handle->state)
838  {
839  ego_entry = GNUNET_new(struct EgoEntry);
842  ego_entry->ego = ego;
843  GNUNET_asprintf(&ego_entry->identifier, "%s", name);
845  handle->ego_tail,
846  ego_entry);
847  }
848 }
849 
850 
862 static void
865  void *proc_cls)
866 {
867  struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
868 
869  handle->response_code = 0;
871  handle->proc_cls = proc_cls;
872  handle->proc = proc;
873  handle->rest_handle = rest_handle;
874  handle->zone_pkey = NULL;
875 
876  handle->url = GNUNET_strdup(rest_handle->url);
877  if (handle->url[strlen(handle->url) - 1] == '/')
878  handle->url[strlen(handle->url) - 1] = '\0';
879  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
880 
881  handle->ns_handle = GNUNET_NAMESTORE_connect(cfg);
882  handle->identity_handle =
883  GNUNET_IDENTITY_connect(cfg, &id_connect_cb, handle);
884  handle->timeout_task =
885  GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle);
886 
887  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
888 }
889 
890 
897 void *
899 {
900  static struct Plugin plugin;
901  struct GNUNET_REST_Plugin *api;
902 
903  cfg = cls;
904  if (NULL != plugin.cfg)
905  return NULL; /* can only initialize once! */
906  memset(&plugin, 0, sizeof(struct Plugin));
907  plugin.cfg = cfg;
908  api = GNUNET_new(struct GNUNET_REST_Plugin);
909  api->cls = &plugin;
913  "%s, %s, %s, %s, %s",
914  MHD_HTTP_METHOD_GET,
915  MHD_HTTP_METHOD_POST,
916  MHD_HTTP_METHOD_PUT,
917  MHD_HTTP_METHOD_DELETE,
918  MHD_HTTP_METHOD_OPTIONS);
919 
920  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Namestore REST API initialized\n"));
921  return api;
922 }
923 
924 
931 void *
933 {
934  struct GNUNET_REST_Plugin *api = cls;
935  struct Plugin *plugin = api->cls;
936 
937  plugin->cfg = NULL;
938 
940  GNUNET_free(api);
941  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
942  return NULL;
943 }
944 
945 /* end of plugin_rest_namestore.c */
946 
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:525
void * cls
Closure for parser and cleaner.
char * name
Plugin name.
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_NAMESTORE_FAILED
Error message Failed request.
#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN
Error message Unknown Error.
struct EgoEntry * ego_tail
Ego list.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
functions to parse JSON objects into GNUnet objects
static void namestore_iteration_error(void *cls)
Does internal server error when iteration failed.
void namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore DELETE request.
void * cls
The closure of the plugin.
void * libgnunet_plugin_rest_namestore_done(void *cls)
Exit point from the plugin.
size_t data_size
The POST data size.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
struct EgoEntry * get_egoentry_namestore(struct RequestHandle *handle, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL...
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * libgnunet_plugin_rest_namestore_init(void *cls)
Entry point for the plugin.
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:100
static void id_connect_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
This function is initially called for all egos and then again whenever a ego&#39;s identifier changes or ...
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:553
static void create_finished(void *cls, int32_t success, const char *emsg)
Create finished callback.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct returned by the initialization function of the plugin
#define GNUNET_NO
Definition: gnunet_common.h:78
Entry in parser specification for GNUNET_JSON_parse().
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void ns_lookup_error_cb(void *cls)
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
Private ECC key encoded for transmission.
struct GNUNET_NAMESTORE_QueueEntry * add_qe
NAMESTORE Operation.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
void(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
static void namestore_list_iteration(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Create a response with requested records.
Handle for an operation with the identity service.
Definition: identity_api.c:39
#define GNUNET_REST_HANDLER_END
static void rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:46
The request handle.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
The ego list.
static char * zone
Name of the zone we manage.
void namestore_add(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore POST request.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Handle for a zone iterator operation.
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:1237
Handle for an ego.
Definition: identity.h:237
char * record_name
Records to store.
enum State state
current state of profiling
json_t * resp_object
Response object.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
const void * data
Binary value stored in the DNS record.
static void ns_lookup_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
char * emsg
Error response message.
int GNUNET_JSON_parse(const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
Navigate and parse data in a JSON tree.
Definition: json.c:45
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
#define GNUNET_REST_IDENTITY_NOT_FOUND
Error message No identity found.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
const char * url
The url as string.
Connection to the NAMESTORE service.
Handle for the service.
Definition: identity_api.c:94
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:1264
char * name
Plugin name.
struct GNUNET_TIME_Relative timeout
Timeout.
unsigned int rd_count
Number of records in rd.
static struct GNUNET_IDENTITY_Handle * identity_handle
Identity handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:835
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
static void namestore_list_finished(void *cls)
Iteration over all results finished, build final response.
json_t * GNUNET_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert Gns record to JSON.
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:75
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
A 512-bit hashcode.
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
int response_code
HTTP response code.
int state
The processing state.
#define GNUNET_REST_NAMESTORE_NO_DATA
Error message No data.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
const char * data
The POST data.
char * keystring
Public key string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
static char * allow_methods
HTTP methods allows for this plugin.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define ID_REST_STATE_INIT
State while collecting all egos.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * zone_pkey
Private key for the zone.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_gnsrecord(struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
JSON Specification for GNS Records.
static void do_error(void *cls)
Task run on errors.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:119
static struct Ego * ego_head
Head of DLL of all egos.
void GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:566
#define GNUNET_REST_NAMESTORE_INVALID_DATA
Error message invalid data.
char * identifier
Ego Identifier.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
void namestore_get(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle namestore GET request.
struct GNUNET_NAMESTORE_Handle * ns_handle
Handle to NAMESTORE.
configuration data
Definition: configuration.c:83
struct EgoEntry * ego_head
Ego list.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_REST_API_NS_NAMESTORE
Namestore Namespace.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:131
static struct MHD_Response * response
Our canonical response.
struct GNUNET_GNSRECORD_Data * rd
Records to store.
static void del_finished(void *cls, int32_t success, const char *emsg)
Delete finished callback.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct EgoEntry * prev
DLL.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
static void init_cont(struct RequestHandle *handle)
Handle rest request.
static struct Ego * ego_tail
Tail of DLL of all egos.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct EgoEntry * ego_entry
IDENTITY Operation.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
char * url
The url.