aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/plugin_rest_identity.c80
-rwxr-xr-xsrc/identity/test_plugin_rest_identity.sh4
2 files changed, 60 insertions, 24 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 49fa9f0fb..83bf4075d 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -326,13 +326,13 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
326 struct GNUNET_HashCode key; 326 struct GNUNET_HashCode key;
327 struct MHD_Response *resp; 327 struct MHD_Response *resp;
328 char *keystring; 328 char *keystring;
329 const char *egoname; 329 char *egoname;
330 json_t *json_root; 330 json_t *json_root;
331 json_t *json_ego; 331 json_t *json_ego;
332 char *result_str; 332 char *result_str;
333 size_t index; 333 size_t index;
334 334
335 //if subsystem 335 //requested default identity of subsystem
336 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_SUBSYSTEM, 336 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_SUBSYSTEM,
337 strlen (GNUNET_REST_PARAM_SUBSYSTEM), &key); 337 strlen (GNUNET_REST_PARAM_SUBSYSTEM), &key);
338 if ( GNUNET_YES 338 if ( GNUNET_YES
@@ -360,7 +360,7 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
360 egoname = NULL; 360 egoname = NULL;
361 keystring = NULL; 361 keystring = NULL;
362 362
363 //if only one identity requested with key 363 //one identity requested with key
364 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY, 364 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY,
365 strlen (GNUNET_REST_PARAM_PUBKEY), 365 strlen (GNUNET_REST_PARAM_PUBKEY),
366 &key); 366 &key);
@@ -381,7 +381,7 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
381 } 381 }
382 } 382 }
383 383
384 //if only one identity requested with name 384 //one identity requested with name
385 if (NULL == egoname) 385 if (NULL == egoname)
386 { 386 {
387 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME, 387 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME,
@@ -393,6 +393,8 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
393 { 393 {
394 egoname = GNUNET_CONTAINER_multihashmap_get ( 394 egoname = GNUNET_CONTAINER_multihashmap_get (
395 handle->rest_handle->url_param_map, &key); 395 handle->rest_handle->url_param_map, &key);
396 //LOWERCASE ego names?
397 GNUNET_STRINGS_utf8_tolower(egoname, egoname);
396 } 398 }
397 } 399 }
398 400
@@ -410,10 +412,10 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
410 412
411 json_ego = json_object (); 413 json_ego = json_object ();
412 json_object_set_new (json_ego, 414 json_object_set_new (json_ego,
413 GNUNET_REST_PARAM_PUBKEY, 415 GNUNET_REST_PARAM_PUBKEY,
414 json_string (ego_entry->keystring)); 416 json_string (ego_entry->keystring));
415 json_object_set_new (json_ego, 417 json_object_set_new (json_ego,
416 GNUNET_REST_PARAM_NAME, 418 GNUNET_REST_PARAM_NAME,
417 json_string (ego_entry->identifier)); 419 json_string (ego_entry->identifier));
418 json_array_append (json_root, json_ego); 420 json_array_append (json_root, json_ego);
419 } 421 }
@@ -645,7 +647,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
645 term_data[handle->data_size] = '\0'; 647 term_data[handle->data_size] = '\0';
646 GNUNET_memcpy(term_data, handle->data, handle->data_size); 648 GNUNET_memcpy(term_data, handle->data, handle->data_size);
647 data_js = json_loads (term_data, 649 data_js = json_loads (term_data,
648 JSON_DECODE_ANY, 650 JSON_DECODE_ANY,
649 &err); 651 &err);
650 652
651 if (NULL == data_js) 653 if (NULL == data_js)
@@ -717,35 +719,69 @@ void
717ego_delete (struct GNUNET_REST_RequestHandle *con_handle, const char* url, 719ego_delete (struct GNUNET_REST_RequestHandle *con_handle, const char* url,
718 void *cls) 720 void *cls)
719{ 721{
720 const char *keystring; 722 struct RequestHandle *handle = cls;
721 struct EgoEntry *ego_entry; 723 struct EgoEntry *ego_entry;
722 struct GNUNET_HashCode key; 724 struct GNUNET_HashCode key;
723 struct MHD_Response *resp; 725 struct MHD_Response *resp;
724 struct RequestHandle *handle = cls; 726 const char *keystring;
727 char *egoname;
725 int ego_exists = GNUNET_NO; 728 int ego_exists = GNUNET_NO;
726 729
727 //if only one identity requested 730 keystring = NULL;
731 egoname = NULL;
732
733 //delete with pubkey
728 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY, 734 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY,
729 strlen (GNUNET_REST_PARAM_PUBKEY), &key); 735 strlen (GNUNET_REST_PARAM_PUBKEY), &key);
730 if ( GNUNET_NO 736 if ( GNUNET_YES
731 == GNUNET_CONTAINER_multihashmap_contains ( 737 == GNUNET_CONTAINER_multihashmap_contains (
732 handle->rest_handle->url_param_map, &key)) 738 handle->rest_handle->url_param_map, &key))
733 { 739 {
734 handle->emsg = GNUNET_strdup("Missing parameter pubkey"); 740 keystring = GNUNET_CONTAINER_multihashmap_get (
735 GNUNET_SCHEDULER_add_now (&do_error, handle); 741 handle->rest_handle->url_param_map,&key);
736 return;
737 } 742 }
738 743
739 keystring = GNUNET_CONTAINER_multihashmap_get ( 744 GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME,
740 handle->rest_handle->url_param_map,&key); 745 strlen (GNUNET_REST_PARAM_NAME), &key);
741 for (ego_entry = handle->ego_head; 746 if ( GNUNET_YES
742 NULL != ego_entry; ego_entry = ego_entry->next) 747 == GNUNET_CONTAINER_multihashmap_contains (
748 handle->rest_handle->url_param_map, &key))
743 { 749 {
744 if (0 != strcasecmp (keystring, ego_entry->keystring)) 750 egoname = GNUNET_CONTAINER_multihashmap_get (
745 continue; 751 handle->rest_handle->url_param_map, &key);
746 ego_exists = GNUNET_YES; 752 //LOWERCASE ego names?
747 break; 753 GNUNET_STRINGS_utf8_tolower(egoname, egoname);
754 }
755
756 if (NULL != keystring)
757 {
758 for (ego_entry = handle->ego_head;
759 NULL != ego_entry; ego_entry = ego_entry->next)
760 {
761 if (0 != strcasecmp (keystring, ego_entry->keystring))
762 continue;
763 ego_exists = GNUNET_YES;
764 break;
765 }
748 } 766 }
767 else if (NULL != egoname)
768 {
769 for (ego_entry = handle->ego_head;
770 NULL != ego_entry; ego_entry = ego_entry->next)
771 {
772 if (0 != strcasecmp (egoname, ego_entry->identifier))
773 continue;
774 ego_exists = GNUNET_YES;
775 break;
776 }
777 }
778 else
779 {
780 handle->emsg = GNUNET_strdup("Missing parameter pubkey or name");
781 GNUNET_SCHEDULER_add_now (&do_error, handle);
782 return;
783 }
784
749 if (GNUNET_NO == ego_exists) 785 if (GNUNET_NO == ego_exists)
750 { 786 {
751 resp = GNUNET_REST_create_response (NULL); 787 resp = GNUNET_REST_create_response (NULL);
diff --git a/src/identity/test_plugin_rest_identity.sh b/src/identity/test_plugin_rest_identity.sh
index 170f3e928..f391f827f 100755
--- a/src/identity/test_plugin_rest_identity.sh
+++ b/src/identity/test_plugin_rest_identity.sh
@@ -84,8 +84,9 @@ fi
84 84
85id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")" 85id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
86#Test GET (one identity) for success and error json 86#Test GET (one identity) for success and error json
87#Only lowercase
87cache="$(curl --silent "${link_to_api}?name=Test" | grep "error")" 88cache="$(curl --silent "${link_to_api}?name=Test" | grep "error")"
88if [ "" != "$cache" ] 89if [ "" == "$cache" ]
89then 90then
90 exit 1 91 exit 1
91fi 92fi
@@ -96,7 +97,6 @@ then
96 exit 1 97 exit 1
97fi 98fi
98 99
99
100#Test DELETE success code, error response code and error json 100#Test DELETE success code, error response code and error json
101#echo "Next tests for DELETE will probably fail when POST fails" 101#echo "Next tests for DELETE will probably fail when POST fails"
102cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")" 102cache="$(curl -v -X "DELETE" "${link_to_api}?pubkey=$id" 2>&1 | grep "HTTP/1.1 404")"