aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-05-09 20:11:30 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-05-09 20:11:30 +0200
commit3075891e02b15a7625d13a946324eb9873e0f0d3 (patch)
tree370508422cc6e13b48f9fb4c7d6f0843f9714de7 /src
parentfbdc2fbb450684e4c98cd67574182481dcbd286b (diff)
downloadgnunet-3075891e02b15a7625d13a946324eb9873e0f0d3.tar.gz
gnunet-3075891e02b15a7625d13a946324eb9873e0f0d3.zip
add filtering and modify deletion API
Diffstat (limited to 'src')
-rw-r--r--src/namestore/plugin_rest_namestore.c156
1 files changed, 100 insertions, 56 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index c0bf4b048..20b253895 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -134,6 +134,11 @@ struct RequestHandle
134 char *record_name; 134 char *record_name;
135 135
136 /** 136 /**
137 * Record type filter
138 */
139 uint32_t record_type;
140
141 /**
137 * Records to store 142 * Records to store
138 */ 143 */
139 struct GNUNET_GNSRECORD_Data *rd; 144 struct GNUNET_GNSRECORD_Data *rd;
@@ -344,17 +349,21 @@ struct EgoEntry *
344get_egoentry_namestore (struct RequestHandle *handle, char *name) 349get_egoentry_namestore (struct RequestHandle *handle, char *name)
345{ 350{
346 struct EgoEntry *ego_entry; 351 struct EgoEntry *ego_entry;
347 352 char *copy = GNUNET_strdup (name);
348 if (NULL != name) 353 char *tmp;
354
355 if (NULL == name)
356 return NULL;
357 tmp = strtok (copy, "/");
358 for (ego_entry = handle->ego_head; NULL != ego_entry;
359 ego_entry = ego_entry->next)
349 { 360 {
350 for (ego_entry = handle->ego_head; NULL != ego_entry; 361 if (0 != strcasecmp (tmp, ego_entry->identifier))
351 ego_entry = ego_entry->next) 362 continue;
352 { 363 GNUNET_free (copy);
353 if (0 != strcasecmp (name, ego_entry->identifier)) 364 return ego_entry;
354 continue;
355 return ego_entry;
356 }
357 } 365 }
366 GNUNET_free (copy);
358 return NULL; 367 return NULL;
359} 368}
360 369
@@ -486,13 +495,25 @@ namestore_list_iteration (void *cls,
486 const struct GNUNET_GNSRECORD_Data *rd) 495 const struct GNUNET_GNSRECORD_Data *rd)
487{ 496{
488 struct RequestHandle *handle = cls; 497 struct RequestHandle *handle = cls;
498 struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
489 json_t *record_obj; 499 json_t *record_obj;
500 int i = 0;
501 int j = 0;
490 502
491 if (NULL == handle->resp_object) 503 if (NULL == handle->resp_object)
492 handle->resp_object = json_array (); 504 handle->resp_object = json_array ();
505 for (i = 0; i < rd_len; i++)
506 {
507 if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
508 (rd[i].record_type != handle->record_type))
509 continue; /* Apply filter */
510 rd_filtered[j] = rd[i];
511 rd_filtered[j].data = rd[i].data;
512 j++;
513 }
493 record_obj = GNUNET_JSON_from_gnsrecord (rname, 514 record_obj = GNUNET_JSON_from_gnsrecord (rname,
494 rd, 515 rd_filtered,
495 rd_len); 516 j);
496 json_array_append_new (handle->resp_object, record_obj); 517 json_array_append_new (handle->resp_object, record_obj);
497 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); 518 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
498} 519}
@@ -512,27 +533,44 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
512{ 533{
513 struct RequestHandle *handle = cls; 534 struct RequestHandle *handle = cls;
514 struct EgoEntry *ego_entry; 535 struct EgoEntry *ego_entry;
536 struct GNUNET_HashCode key;
515 char *egoname; 537 char *egoname;
538 char *typename;
516 539
517 egoname = NULL; 540 egoname = NULL;
518 ego_entry = NULL; 541 ego_entry = NULL;
519 542
520 // set zone to name if given 543 // set zone to name if given
521 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 544 if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
522 { 545 {
523 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; 546 handle->response_code = MHD_HTTP_NOT_FOUND;
524 ego_entry = get_egoentry_namestore (handle, egoname); 547 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
548 GNUNET_SCHEDULER_add_now (&do_error, handle);
549 return;
550 }
551 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
552 ego_entry = get_egoentry_namestore (handle, egoname);
553 if (NULL == ego_entry)
554 {
555 handle->response_code = MHD_HTTP_NOT_FOUND;
556 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
557 GNUNET_SCHEDULER_add_now (&do_error, handle);
558 return;
559 }
560 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
525 561
526 if (NULL == ego_entry) 562 GNUNET_CRYPTO_hash ("record_type", strlen ("record_type"), &key);
527 { 563 if (GNUNET_NO ==
528 handle->response_code = MHD_HTTP_NOT_FOUND; 564 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
529 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); 565 {
530 GNUNET_SCHEDULER_add_now (&do_error, handle); 566 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
531 return; 567 }
532 } 568 else
569 {
570 typename = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
571 &key);
572 handle->record_type = GNUNET_GNSRECORD_typename_to_number (typename);
533 } 573 }
534 if (NULL != ego_entry)
535 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
536 574
537 handle->list_it = 575 handle->list_it =
538 GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 576 GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
@@ -614,6 +652,7 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
614 652
615 if (0 >= handle->rest_handle->data_size) 653 if (0 >= handle->rest_handle->data_size)
616 { 654 {
655 handle->response_code = MHD_HTTP_BAD_REQUEST;
617 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); 656 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA);
618 GNUNET_SCHEDULER_add_now (&do_error, handle); 657 GNUNET_SCHEDULER_add_now (&do_error, handle);
619 return; 658 return;
@@ -637,6 +676,7 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
637 GNUNET_JSON_parse_free (gnsspec); 676 GNUNET_JSON_parse_free (gnsspec);
638 if (0 >= strlen (handle->record_name)) 677 if (0 >= strlen (handle->record_name))
639 { 678 {
679 handle->response_code = MHD_HTTP_BAD_REQUEST;
640 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); 680 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
641 GNUNET_SCHEDULER_add_now (&do_error, handle); 681 GNUNET_SCHEDULER_add_now (&do_error, handle);
642 json_decref (data_js); 682 json_decref (data_js);
@@ -648,21 +688,24 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
648 ego_entry = NULL; 688 ego_entry = NULL;
649 689
650 // set zone to name if given 690 // set zone to name if given
651 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 691 if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
652 { 692 {
653 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; 693 handle->response_code = MHD_HTTP_NOT_FOUND;
654 ego_entry = get_egoentry_namestore (handle, egoname); 694 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
695 GNUNET_SCHEDULER_add_now (&do_error, handle);
696 return;
697 }
698 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
699 ego_entry = get_egoentry_namestore (handle, egoname);
655 700
656 if (NULL == ego_entry) 701 if (NULL == ego_entry)
657 { 702 {
658 handle->response_code = MHD_HTTP_NOT_FOUND; 703 handle->response_code = MHD_HTTP_NOT_FOUND;
659 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); 704 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
660 GNUNET_SCHEDULER_add_now (&do_error, handle); 705 GNUNET_SCHEDULER_add_now (&do_error, handle);
661 return; 706 return;
662 }
663 } 707 }
664 if (NULL != ego_entry) 708 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
665 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
666 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 709 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
667 handle->zone_pkey, 710 handle->zone_pkey,
668 handle->record_name, 711 handle->record_name,
@@ -692,41 +735,42 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
692 void *cls) 735 void *cls)
693{ 736{
694 struct RequestHandle *handle = cls; 737 struct RequestHandle *handle = cls;
695 struct GNUNET_HashCode key;
696 struct EgoEntry *ego_entry; 738 struct EgoEntry *ego_entry;
697 char *egoname; 739 char *egoname;
740 char *labelname;
698 741
699 egoname = NULL; 742 egoname = NULL;
700 ego_entry = NULL; 743 ego_entry = NULL;
701 744
702 // set zone to name if given 745 // set zone to name if given
703 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 746 if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url))
704 { 747 {
705 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; 748 handle->response_code = MHD_HTTP_NOT_FOUND;
706 ego_entry = get_egoentry_namestore (handle, egoname); 749 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
707 750 GNUNET_SCHEDULER_add_now (&do_error, handle);
708 if (NULL == ego_entry) 751 return;
709 {
710 handle->response_code = MHD_HTTP_NOT_FOUND;
711 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
712 GNUNET_SCHEDULER_add_now (&do_error, handle);
713 return;
714 }
715 } 752 }
716 if (NULL != ego_entry) 753 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
717 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 754 ego_entry = get_egoentry_namestore (handle, egoname);
718 755 if (NULL == ego_entry)
719 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
720 if (GNUNET_NO ==
721 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
722 { 756 {
723 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); 757 handle->response_code = MHD_HTTP_NOT_FOUND;
758 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
724 GNUNET_SCHEDULER_add_now (&do_error, handle); 759 GNUNET_SCHEDULER_add_now (&do_error, handle);
725 return; 760 return;
726 } 761 }
727 handle->record_name = GNUNET_strdup ( 762 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
728 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); 763 labelname = &egoname[strlen (ego_entry->identifier)];
764 // set zone to name if given
765 if (1 >= strlen (labelname))
766 {
767 /* label is only "/" */
768 handle->response_code = MHD_HTTP_BAD_REQUEST;
769 handle->emsg = GNUNET_strdup ("Label missing");
770 GNUNET_SCHEDULER_add_now (&do_error, handle);
771 }
729 772
773 handle->record_name = GNUNET_strdup (labelname + 1);
730 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, 774 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
731 handle->zone_pkey, 775 handle->zone_pkey,
732 handle->record_name, 776 handle->record_name,