aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
committerPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
commit4df7069dcd17ac39c786ee6f21455c96e6a6dbf4 (patch)
tree80fe63630f82dd79f73f24cbb954c0703cd873f3 /src/namestore
parent89485145a0f33984a70bffdf0f766667b4a3e75e (diff)
downloadgnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.tar.gz
gnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.zip
Changed Namestore API, changed error handling, changed gns record json
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/plugin_rest_namestore.c407
-rwxr-xr-xsrc/namestore/test_plugin_rest_namestore.sh137
2 files changed, 216 insertions, 328 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index f14707cce..1d72d13ff 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -32,22 +32,40 @@
32#include "microhttpd.h" 32#include "microhttpd.h"
33#include <jansson.h> 33#include <jansson.h>
34 34
35 35/**
36 * Namestore Namespace
37 */
36#define GNUNET_REST_API_NS_NAMESTORE "/namestore" 38#define GNUNET_REST_API_NS_NAMESTORE "/namestore"
37#define GNUNET_REST_SUBSYSTEM_NAMESTORE "namestore"
38 39
39/** 40/**
40 * Parameter names 41 * Error message Unknown Error
41 */ 42 */
42#define GNUNET_REST_API_PARAM_PUBKEY "pubkey" 43#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error"
43#define GNUNET_REST_API_PARAM_NAME "name"
44 44
45/** 45/**
46 * Error messages 46 * Error message No identity found
47 */ 47 */
48#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" 48#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found"
49 49
50#define GNUNET_REST_NAMESTORE_RD_COUNT 1 50/**
51 * Error message No default zone specified
52 */
53#define GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE "No default zone specified"
54
55/**
56 * Error message Failed request
57 */
58#define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed"
59
60/**
61 * Error message invalid data
62 */
63#define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid"
64
65/**
66 * Error message No data
67 */
68#define GNUNET_REST_NAMESTORE_NO_DATA "No data"
51 69
52/** 70/**
53 * State while collecting all egos 71 * State while collecting all egos
@@ -107,13 +125,15 @@ struct EgoEntry
107 struct GNUNET_IDENTITY_Ego *ego; 125 struct GNUNET_IDENTITY_Ego *ego;
108}; 126};
109 127
110 128/**
129 * The request handle
130 */
111struct RequestHandle 131struct RequestHandle
112{ 132{
113 /** 133 /**
114 * Records to store 134 * Records to store
115 */ 135 */
116 char *label_name; 136 char *record_name;
117 137
118 /** 138 /**
119 * Records to store 139 * Records to store
@@ -211,7 +231,7 @@ struct RequestHandle
211 char *emsg; 231 char *emsg;
212 232
213 /** 233 /**
214 * Reponse code 234 * Response code
215 */ 235 */
216 int response_code; 236 int response_code;
217 237
@@ -235,8 +255,8 @@ cleanup_handle (void *cls)
235 GNUNET_SCHEDULER_cancel (handle->timeout_task); 255 GNUNET_SCHEDULER_cancel (handle->timeout_task);
236 handle->timeout_task = NULL; 256 handle->timeout_task = NULL;
237 } 257 }
238 if (NULL != handle->label_name) 258 if (NULL != handle->record_name)
239 GNUNET_free(handle->label_name); 259 GNUNET_free(handle->record_name);
240 if (NULL != handle->url) 260 if (NULL != handle->url)
241 GNUNET_free(handle->url); 261 GNUNET_free(handle->url);
242 if (NULL != handle->emsg) 262 if (NULL != handle->emsg)
@@ -318,20 +338,9 @@ do_error (void *cls)
318 * @return EgoEntry or NULL if not found 338 * @return EgoEntry or NULL if not found
319 */ 339 */
320struct EgoEntry* 340struct EgoEntry*
321get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) 341get_egoentry_namestore(struct RequestHandle *handle, char *name)
322{ 342{
323 struct EgoEntry *ego_entry; 343 struct EgoEntry *ego_entry;
324 if (NULL != pubkey)
325 {
326 for (ego_entry = handle->ego_head;
327 NULL != ego_entry;
328 ego_entry = ego_entry->next)
329 {
330 if (0 != strcasecmp (pubkey, ego_entry->keystring))
331 continue;
332 return ego_entry;
333 }
334 }
335 if (NULL != name) 344 if (NULL != name)
336 { 345 {
337 for (ego_entry = handle->ego_head; 346 for (ego_entry = handle->ego_head;
@@ -349,17 +358,26 @@ get_egoentry(struct RequestHandle *handle, char* pubkey, char *name)
349 358
350/** 359/**
351 * Does internal server error when iteration failed. 360 * Does internal server error when iteration failed.
361 *
362 * @param cls the `struct RequestHandle`
352 */ 363 */
353static void 364static void
354namestore_iteration_error (void *cls) 365namestore_iteration_error (void *cls)
355{ 366{
356 struct RequestHandle *handle = cls; 367 struct RequestHandle *handle = cls;
357 struct MHD_Response *resp = GNUNET_REST_create_response (NULL); 368 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
358 handle->proc (handle->proc_cls, resp, MHD_HTTP_INTERNAL_SERVER_ERROR); 369 GNUNET_SCHEDULER_add_now (&do_error, handle);
359 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 370 return;
360} 371}
361 372
362 373
374/**
375 * Create finished callback
376 *
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)
380 */
363static void 381static void
364create_finished (void *cls, int32_t success, const char *emsg) 382create_finished (void *cls, int32_t success, const char *emsg)
365{ 383{
@@ -369,6 +387,12 @@ create_finished (void *cls, int32_t success, const char *emsg)
369 handle->add_qe = NULL; 387 handle->add_qe = NULL;
370 if (GNUNET_YES != success) 388 if (GNUNET_YES != success)
371 { 389 {
390 if (NULL != emsg)
391 {
392 handle->emsg = GNUNET_strdup(emsg);
393 GNUNET_SCHEDULER_add_now (&do_error, handle);
394 return;
395 }
372 handle->emsg = GNUNET_strdup("Error storing records"); 396 handle->emsg = GNUNET_strdup("Error storing records");
373 GNUNET_SCHEDULER_add_now (&do_error, handle); 397 GNUNET_SCHEDULER_add_now (&do_error, handle);
374 return; 398 return;
@@ -379,6 +403,13 @@ create_finished (void *cls, int32_t success, const char *emsg)
379} 403}
380 404
381 405
406/**
407 * Delete finished callback
408 *
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)
412 */
382static void 413static void
383del_finished (void *cls, int32_t success, const char *emsg) 414del_finished (void *cls, int32_t success, const char *emsg)
384{ 415{
@@ -387,12 +418,19 @@ del_finished (void *cls, int32_t success, const char *emsg)
387 handle->add_qe = NULL; 418 handle->add_qe = NULL;
388 if (GNUNET_NO == success) 419 if (GNUNET_NO == success)
389 { 420 {
390 handle->emsg = GNUNET_strdup("Deleting record failed. Record does not exist"); 421 handle->response_code = MHD_HTTP_NOT_FOUND;
422 handle->emsg = GNUNET_strdup("No record found");
391 GNUNET_SCHEDULER_add_now (&do_error, handle); 423 GNUNET_SCHEDULER_add_now (&do_error, handle);
392 return; 424 return;
393 } 425 }
394 if (GNUNET_SYSERR == success) 426 if (GNUNET_SYSERR == success)
395 { 427 {
428 if (NULL != emsg)
429 {
430 handle->emsg = GNUNET_strdup(emsg);
431 GNUNET_SCHEDULER_add_now (&do_error, handle);
432 return;
433 }
396 handle->emsg = GNUNET_strdup("Deleting record failed"); 434 handle->emsg = GNUNET_strdup("Deleting record failed");
397 GNUNET_SCHEDULER_add_now (&do_error, handle); 435 GNUNET_SCHEDULER_add_now (&do_error, handle);
398 return; 436 return;
@@ -452,17 +490,6 @@ namestore_list_iteration (void *cls,
452 if (NULL == handle->resp_object) 490 if (NULL == handle->resp_object)
453 handle->resp_object = json_array(); 491 handle->resp_object = json_array();
454 492
455 /*if ( (NULL != handle->ego_entry->identifier) &&
456 (0 != strcmp (handle->ego_entry->identifier,
457 rname)) )
458 {
459 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
460 "%s does not match %s\n", rname,
461 handle->ego_entry->identifier);
462 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
463 return;
464 }*/
465
466 for (unsigned int i = 0; i < rd_len; i++) 493 for (unsigned int i = 0; i < rd_len; i++)
467 { 494 {
468 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 495 if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
@@ -495,40 +522,22 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
495 void *cls) 522 void *cls)
496{ 523{
497 struct RequestHandle *handle = cls; 524 struct RequestHandle *handle = cls;
498 struct EgoEntry *ego_entry = NULL; 525 struct EgoEntry *ego_entry;
499 struct GNUNET_HashCode key; 526 char *egoname;
500 char *pubkey = NULL; 527
501 char *name = NULL; 528 egoname = NULL;
502 529 ego_entry = NULL;
503 //change zone if pubkey or name specified
504 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
505 strlen (GNUNET_REST_API_PARAM_PUBKEY),
506 &key);
507 if ( GNUNET_YES
508 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
509 &key))
510 {
511 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
512 &key);
513 }
514 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
515 strlen (GNUNET_REST_API_PARAM_NAME),
516 &key);
517 if ( GNUNET_YES
518 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
519 &key))
520 {
521 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
522 &key);
523 }
524 530
525 ego_entry = get_egoentry(handle,pubkey,name); 531 //set zone to name if given
526 if (NULL == ego_entry) 532 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
527 { 533 {
528 if (NULL != pubkey || NULL != name) 534 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
535 ego_entry = get_egoentry_namestore(handle, egoname);
536
537 if (NULL == ego_entry)
529 { 538 {
530 handle->emsg = GNUNET_strdup("Invalid identity");
531 handle->response_code = MHD_HTTP_NOT_FOUND; 539 handle->response_code = MHD_HTTP_NOT_FOUND;
540 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
532 GNUNET_SCHEDULER_add_now (&do_error, handle); 541 GNUNET_SCHEDULER_add_now (&do_error, handle);
533 return; 542 return;
534 } 543 }
@@ -537,6 +546,12 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
537 { 546 {
538 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 547 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
539 } 548 }
549 if (NULL == handle->zone_pkey)
550 {
551 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
552 GNUNET_SCHEDULER_add_now (&do_error, handle);
553 return;
554 }
540 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 555 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
541 handle->zone_pkey, 556 handle->zone_pkey,
542 &namestore_iteration_error, 557 &namestore_iteration_error,
@@ -545,53 +560,15 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
545 handle, 560 handle,
546 &namestore_list_finished, 561 &namestore_list_finished,
547 handle); 562 handle);
548} 563 if (NULL == handle->list_it)
549
550
551/**
552 * We're storing a new record; this requires
553 * that no record already exists
554 *
555 * @param cls closure, unused
556 * @param zone_key private key of the zone
557 * @param rec_name name that is being mapped (at most 255 characters long)
558 * @param rd_count number of entries in @a rd array
559 * @param rd array of records with data to store
560 */
561static void
562create_new_record_cont (void *cls,
563 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
564 const char *rec_name,
565 unsigned int rd_count,
566 const struct GNUNET_GNSRECORD_Data *rd)
567{
568 struct RequestHandle *handle = cls;
569
570 handle->add_qe = NULL;
571 if (0 != strcmp (rec_name, handle->label_name))
572 { 564 {
573 GNUNET_break (0); 565 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
574 GNUNET_SCHEDULER_add_now (&do_error, handle); 566 GNUNET_SCHEDULER_add_now (&do_error, handle);
575 return; 567 return;
576 } 568 }
577
578 if (0 != rd_count)
579 {
580 handle->proc (handle->proc_cls,
581 GNUNET_REST_create_response (NULL),
582 MHD_HTTP_CONFLICT);
583 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
584 return;
585 }
586 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
587 handle->zone_pkey,
588 handle->label_name,
589 GNUNET_REST_NAMESTORE_RD_COUNT,
590 handle->rd,
591 &create_finished,
592 handle);
593} 569}
594 570
571
595/** 572/**
596 * Handle namestore POST request 573 * Handle namestore POST request
597 * 574 *
@@ -606,30 +583,21 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
606{ 583{
607 struct RequestHandle *handle = cls; 584 struct RequestHandle *handle = cls;
608 struct GNUNET_GNSRECORD_Data *gns_record; 585 struct GNUNET_GNSRECORD_Data *gns_record;
586 struct EgoEntry *ego_entry;
587 char *egoname;
609 json_t *data_js; 588 json_t *data_js;
610 json_t *name_json; 589 json_t *name_json;
611 json_error_t err; 590 json_error_t err;
612
613 struct EgoEntry *ego_entry = NULL;
614 struct GNUNET_HashCode key;
615 char *pubkey = NULL;
616 char *name = NULL;
617
618 char term_data[handle->rest_handle->data_size + 1]; 591 char term_data[handle->rest_handle->data_size + 1];
592
619 struct GNUNET_JSON_Specification gnsspec[] = { 593 struct GNUNET_JSON_Specification gnsspec[] = {
620 GNUNET_JSON_spec_gnsrecord_data(&gns_record), 594 GNUNET_JSON_spec_gnsrecord_data(&gns_record),
621 GNUNET_JSON_spec_end () 595 GNUNET_JSON_spec_end ()
622 }; 596 };
623 597
624 if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
625 {
626 handle->emsg = GNUNET_strdup("Wrong URL");
627 GNUNET_SCHEDULER_add_now (&do_error, handle);
628 return;
629 }
630 if (0 >= handle->rest_handle->data_size) 598 if (0 >= handle->rest_handle->data_size)
631 { 599 {
632 handle->emsg = GNUNET_strdup("No data"); 600 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA);
633 GNUNET_SCHEDULER_add_now (&do_error, handle); 601 GNUNET_SCHEDULER_add_now (&do_error, handle);
634 return; 602 return;
635 } 603 }
@@ -639,7 +607,7 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
639 data_js = json_loads (term_data, JSON_DECODE_ANY, &err); 607 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
640 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) 608 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
641 { 609 {
642 handle->emsg = GNUNET_strdup("Invalid data"); 610 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
643 GNUNET_SCHEDULER_add_now (&do_error, handle); 611 GNUNET_SCHEDULER_add_now (&do_error, handle);
644 GNUNET_JSON_parse_free(gnsspec); 612 GNUNET_JSON_parse_free(gnsspec);
645 json_decref (data_js); 613 json_decref (data_js);
@@ -647,109 +615,74 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
647 } 615 }
648 handle->rd = gns_record; 616 handle->rd = gns_record;
649 617
650 name_json = json_object_get(data_js, "label"); 618 name_json = json_object_get(data_js, "record_name");
651 if (!json_is_string(name_json)) 619 if (!json_is_string(name_json))
652 { 620 {
653 handle->emsg = GNUNET_strdup("Missing name"); 621 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
654 GNUNET_SCHEDULER_add_now (&do_error, handle); 622 GNUNET_SCHEDULER_add_now (&do_error, handle);
655 json_decref (data_js); 623 json_decref (data_js);
656 return; 624 return;
657 } 625 }
658 handle->label_name = GNUNET_strdup(json_string_value(name_json)); 626 handle->record_name = GNUNET_strdup(json_string_value(name_json));
659 if(NULL == handle->label_name) 627 if(NULL == handle->record_name)
660 { 628 {
661 handle->emsg = GNUNET_strdup("Missing name"); 629 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
662 GNUNET_SCHEDULER_add_now (&do_error, handle); 630 GNUNET_SCHEDULER_add_now (&do_error, handle);
663 json_decref (data_js); 631 json_decref (data_js);
664 return; 632 return;
665 } 633 }
666 if (0 >= strlen(handle->label_name)) 634 if (0 >= strlen(handle->record_name))
667 { 635 {
668 handle->emsg = GNUNET_strdup("Missing name"); 636 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
669 GNUNET_SCHEDULER_add_now (&do_error, handle); 637 GNUNET_SCHEDULER_add_now (&do_error, handle);
670 json_decref (data_js); 638 json_decref (data_js);
671 return; 639 return;
672 } 640 }
673 json_decref (data_js); 641 json_decref (data_js);
674 642
675 //change zone if pubkey or name specified 643 egoname = NULL;
676 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, 644 ego_entry = NULL;
677 strlen (GNUNET_REST_API_PARAM_PUBKEY),
678 &key);
679 if ( GNUNET_YES
680 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
681 &key))
682 {
683 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
684 &key);
685 }
686 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
687 strlen (GNUNET_REST_API_PARAM_NAME),
688 &key);
689 if ( GNUNET_YES
690 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
691 &key))
692 {
693 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
694 &key);
695 }
696 645
697 ego_entry = get_egoentry(handle,pubkey,name); 646 //set zone to name if given
698 if (NULL == ego_entry) 647 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
699 { 648 {
700 if (NULL != pubkey || NULL != name) 649 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
650 ego_entry = get_egoentry_namestore(handle, egoname);
651
652 if (NULL == ego_entry)
701 { 653 {
702 handle->emsg = GNUNET_strdup("Invalid identity");
703 handle->response_code = MHD_HTTP_NOT_FOUND; 654 handle->response_code = MHD_HTTP_NOT_FOUND;
655 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
704 GNUNET_SCHEDULER_add_now (&do_error, handle); 656 GNUNET_SCHEDULER_add_now (&do_error, handle);
705 return; 657 return;
706 } 658 }
707 } 659 }
708 if ( NULL != ego_entry ) 660 if (NULL != ego_entry)
709 { 661 {
710 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 662 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
711 } 663 }
712 if (NULL == handle->zone_pkey) 664 if (NULL == handle->zone_pkey)
713 { 665 {
714 handle->emsg = GNUNET_strdup("No default identity for namestore"); 666 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
715 GNUNET_SCHEDULER_add_now (&do_error, handle); 667 GNUNET_SCHEDULER_add_now (&do_error, handle);
716 return; 668 return;
717 } 669 }
718 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 670 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
719 handle->zone_pkey, 671 handle->zone_pkey,
720 handle->label_name, 672 handle->record_name,
721 &do_error, 673 1,
722 handle, 674 handle->rd,
723 &create_new_record_cont, 675 &create_finished,
724 handle); 676 handle);
725} 677 if (NULL == handle->add_qe)
726
727
728static void
729del_cont (void *cls,
730 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
731 const char *label,
732 unsigned int rd_count,
733 const struct GNUNET_GNSRECORD_Data *rd)
734{
735 struct RequestHandle *handle = cls;
736
737 handle->add_qe = NULL;
738 if (0 == rd_count)
739 { 678 {
740 handle->emsg = GNUNET_strdup("Record not found"); 679 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
741 GNUNET_SCHEDULER_add_now (&do_error, handle); 680 GNUNET_SCHEDULER_add_now (&do_error, handle);
742 return; 681 return;
743 } 682 }
744
745 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
746 handle->zone_pkey,
747 handle->label_name,
748 0, NULL,
749 &del_finished,
750 handle);
751} 683}
752 684
685
753/** 686/**
754 * Handle namestore DELETE request 687 * Handle namestore DELETE request
755 * 688 *
@@ -764,39 +697,22 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
764{ 697{
765 struct RequestHandle *handle = cls; 698 struct RequestHandle *handle = cls;
766 struct GNUNET_HashCode key; 699 struct GNUNET_HashCode key;
767 struct EgoEntry *ego_entry = NULL; 700 struct EgoEntry *ego_entry;
768 char *pubkey = NULL; 701 char *egoname;
769 char *name = NULL; 702
770 703 egoname = NULL;
771 //change zone if pubkey or name specified 704 ego_entry = NULL;
772 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY,
773 strlen (GNUNET_REST_API_PARAM_PUBKEY),
774 &key);
775 if ( GNUNET_YES
776 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
777 &key))
778 {
779 pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
780 &key);
781 }
782 GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME,
783 strlen (GNUNET_REST_API_PARAM_NAME),
784 &key);
785 if ( GNUNET_YES
786 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
787 &key))
788 {
789 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
790 &key);
791 }
792 705
793 ego_entry = get_egoentry(handle,pubkey,name); 706 //set zone to name if given
794 if (NULL == ego_entry) 707 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
795 { 708 {
796 if (NULL != pubkey || NULL != name) 709 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1];
710 ego_entry = get_egoentry_namestore(handle, egoname);
711
712 if (NULL == ego_entry)
797 { 713 {
798 handle->emsg = GNUNET_strdup("Invalid identity");
799 handle->response_code = MHD_HTTP_NOT_FOUND; 714 handle->response_code = MHD_HTTP_NOT_FOUND;
715 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
800 GNUNET_SCHEDULER_add_now (&do_error, handle); 716 GNUNET_SCHEDULER_add_now (&do_error, handle);
801 return; 717 return;
802 } 718 }
@@ -806,33 +722,38 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
806 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 722 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
807 } 723 }
808 724
809 GNUNET_CRYPTO_hash ("label", strlen ("label"), &key); 725 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
810 if ( GNUNET_NO 726 if ( GNUNET_NO
811 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 727 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
812 &key)) 728 &key))
813 { 729 {
814 handle->emsg = GNUNET_strdup("Missing name"); 730 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
815 GNUNET_SCHEDULER_add_now (&do_error, handle); 731 GNUNET_SCHEDULER_add_now (&do_error, handle);
816 return; 732 return;
817 } 733 }
818 handle->label_name = GNUNET_strdup( 734 handle->record_name = GNUNET_strdup(
819 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); 735 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key));
820 736
821 if (NULL == handle->zone_pkey) 737 if (NULL == handle->zone_pkey)
822 { 738 {
823 handle->emsg = GNUNET_strdup("No default identity for namestore"); 739 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
824 GNUNET_SCHEDULER_add_now (&do_error, handle); 740 GNUNET_SCHEDULER_add_now (&do_error, handle);
825 return; 741 return;
826 } 742 }
827 743
828 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 744 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
829 handle->zone_pkey, 745 handle->zone_pkey,
830 handle->label_name, 746 handle->record_name,
831 &do_error, 747 0,
832 handle, 748 NULL,
833 &del_cont, 749 &del_finished,
834 handle); 750 handle);
835 751 if (NULL == handle->add_qe)
752 {
753 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
754 GNUNET_SCHEDULER_add_now (&do_error, handle);
755 return;
756 }
836} 757}
837 758
838 759
@@ -916,7 +837,35 @@ default_ego_cb (void *cls,
916 837
917 838
918/** 839/**
919 * Connect to identity callback 840 * This function is initially called for all egos and then again
841 * whenever a ego's identifier changes or if it is deleted. At the
842 * end of the initial pass over all egos, the function is once called
843 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
844 * be invoked in the future or that there was an error.
845 *
846 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
847 * this function is only called ONCE, and 'NULL' being passed in
848 * 'ego' does indicate an error (i.e. name is taken or no default
849 * value is known). If 'ego' is non-NULL and if '*ctx'
850 * is set in those callbacks, the value WILL be passed to a subsequent
851 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
852 * that one was not NULL).
853 *
854 * When an identity is renamed, this function is called with the
855 * (known) ego but the NEW identifier.
856 *
857 * When an identity is deleted, this function is called with the
858 * (known) ego and "NULL" for the 'identifier'. In this case,
859 * the 'ego' is henceforth invalid (and the 'ctx' should also be
860 * cleaned up).
861 *
862 * @param cls closure
863 * @param ego ego handle
864 * @param ctx context for application to store data for this ego
865 * (during the lifetime of this process, initially NULL)
866 * @param name identifier assigned by the user for this ego,
867 * NULL if the user just deleted the ego and it
868 * must thus no longer be used
920 */ 869 */
921static void 870static void
922id_connect_cb (void *cls, 871id_connect_cb (void *cls,
@@ -931,7 +880,7 @@ id_connect_cb (void *cls,
931 if ((NULL == ego) && (NULL == handle->zone_pkey)) 880 if ((NULL == ego) && (NULL == handle->zone_pkey))
932 { 881 {
933 handle->op = GNUNET_IDENTITY_get (handle->identity_handle, 882 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
934 GNUNET_REST_SUBSYSTEM_NAMESTORE, 883 "namestore",
935 &default_ego_cb, 884 &default_ego_cb,
936 handle); 885 handle);
937 } 886 }
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh
index de02dfafc..532c7caae 100755
--- a/src/namestore/test_plugin_rest_namestore.sh
+++ b/src/namestore/test_plugin_rest_namestore.sh
@@ -11,7 +11,7 @@ curl_get () {
11 #$1 is link 11 #$1 is link
12 #$2 is grep 12 #$2 is grep
13 cache="$(curl -v "$1" 2>&1 | grep "$2")" 13 cache="$(curl -v "$1" 2>&1 | grep "$2")"
14 #echo $cache 14 echo $cache
15 if [ "" == "$cache" ] 15 if [ "" == "$cache" ]
16 then 16 then
17 exit 1 17 exit 1
@@ -23,7 +23,7 @@ curl_post () {
23 #$2 is data 23 #$2 is data
24 #$3 is grep 24 #$3 is grep
25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" 25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
26 #echo $cache 26 echo $cache
27 if [ "" == "$cache" ] 27 if [ "" == "$cache" ]
28 then 28 then
29 exit 1 29 exit 1
@@ -34,7 +34,7 @@ curl_delete () {
34 #$1 is link 34 #$1 is link
35 #$2 is grep 35 #$2 is grep
36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" 36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
37 #echo $cache 37 echo $cache
38 if [ "" == "$cache" ] 38 if [ "" == "$cache" ]
39 then 39 then
40 exit 1 40 exit 1
@@ -64,141 +64,80 @@ public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{pr
64if [ "" == "$test" ] 64if [ "" == "$test" ]
65then 65then
66 #if no entries for test_plugin_rest_namestore 66 #if no entries for test_plugin_rest_namestore
67 curl_get "${namestore_link}?name=$name" "error" 67 curl_get "${namestore_link}/$name" "error"
68 curl_get "${namestore_link}?name=" "error" 68 curl_get "${namestore_link}/" "error"
69 curl_get "${namestore_link}?name=$public" "error" 69 curl_get "${namestore_link}/$public" "error"
70
71 curl_get "${namestore_link}?pubkey=$public" "error"
72 curl_get "${namestore_link}?pubkey=$name" "error"
73 curl_get "${namestore_link}?pubkey=" "error"
74else 70else
75 #if entries exists (that should not be possible) 71 #if entries exists (that should not be possible)
76 curl_get "${namestore_link}" "HTTP/1.1 200 OK" 72 curl_get "${namestore_link}" "HTTP/1.1 200 OK"
77 curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" 73 curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
78 curl_get "${namestore_link}?name=" "error" 74 curl_get "${namestore_link}/" "error"
79 curl_get "${namestore_link}?name=$public" "error" 75 curl_get "${namestore_link}/$public" "error"
80
81 curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
82 curl_get "${namestore_link}?pubkey=$name" "error"
83 curl_get "${namestore_link}?pubkey=" "error"
84fi 76fi
85gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 77gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
86curl_get "${namestore_link}" "HTTP/1.1 200 OK" 78curl_get "${namestore_link}" "HTTP/1.1 200 OK"
87curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" 79curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
88curl_get "${namestore_link}?name=" "error" 80curl_get "${namestore_link}/" "error"
89curl_get "${namestore_link}?name=$public" "error" 81curl_get "${namestore_link}/$public" "error"
90curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK"
91curl_get "${namestore_link}?pubkey=$name" "error"
92curl_get "${namestore_link}?pubkey=" "error"
93gnunet-namestore -z $name -d -n "test_entry" 82gnunet-namestore -z $name -d -n "test_entry"
94 83
95#Test POST with NAME 84#Test POST with NAME
96curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 85curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
97gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 86gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
98#value 87#value
99curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 88curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
100gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 89gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
101curl_post "${namestore_link}?name=$name" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 90curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
102gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 91gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
103curl_post "${namestore_link}?name=$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 92curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
104gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 93gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
105#time 94#time
106curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" 95curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
107gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 96gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
108curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" 97curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
109gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 98gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
110curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error" 99curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error"
111gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 100gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
112curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error" 101curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error"
113gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 102gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
114curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error" 103curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error"
115gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 104gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
116#flag 105#flag
117curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 106curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
118gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 107gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
119curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content" 108curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
120gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 109gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
121curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content" 110curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
122gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 111gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
123curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content" 112curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
124gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 113gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
125curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error" 114curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error"
126gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 115gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
127curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error" 116curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error"
128gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 117gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
129curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error" 118curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error"
130gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 119gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
131curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error" 120curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error"
132gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 121gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
133#label 122#record_name
134curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" 123curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
135curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409" 124curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
136gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 125gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
137curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error" 126curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error"
138gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 127gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
139curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error" 128curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error"
140gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
141
142#Test POST with PUBKEY
143curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
144gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
145#value
146curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
147gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
148curl_post "${namestore_link}?pubkey=$public" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
149gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
150curl_post "${namestore_link}?pubkey=$public" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
151gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
152#time
153curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
154gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
155curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204"
156gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
157curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error"
158gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
159curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error"
160gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
161curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error"
162gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
163#flag
164curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
165gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
166curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content"
167gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
168curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content"
169gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
170curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content"
171gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
172curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error"
173gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
174curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error"
175gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
176curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error"
177gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
178curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error"
179gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
180#label
181curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content"
182curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409"
183gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
184curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error"
185gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
186curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error"
187gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 129gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
188 130
189#wrong zone 131#wrong zone
190curl_post "${namestore_link}?name=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" 132curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
191gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
192curl_post "${namestore_link}?pubkey=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error"
193gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 133gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
194 134
195#Test DELETE 135#Test DELETE
196gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 136gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
197curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" 137curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204"
198gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 138curl_delete "${namestore_link}/$name?record_name=test_entry" "error"
199curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204"
200gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" 139gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
201curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404" 140curl_delete "${namestore_link}/$public?record_name=test_entry" "error"
202 141
203 142
204#Test default identity 143#Test default identity