aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-12-08 14:25:00 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-12-08 14:25:00 +0000
commit36b0e18395e097759f51908a05888a3da6751643 (patch)
treed37e5c338df4e01ff8620655b24b7fb6c9beab94 /src/namestore
parent9c6313641929f6dadcd53a9dc476cd166580ac0a (diff)
downloadgnunet-36b0e18395e097759f51908a05888a3da6751643.tar.gz
gnunet-36b0e18395e097759f51908a05888a3da6751643.zip
-update
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/plugin_rest_namestore.c103
1 files changed, 100 insertions, 3 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 6ae3e7967..42a9f6356 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -34,8 +34,14 @@
34 34
35#define GNUNET_REST_API_NS_NAMESTORE "/names" 35#define GNUNET_REST_API_NS_NAMESTORE "/names"
36 36
37#define GNUNET_REST_API_NS_NAMESTORE_ZKEY "/names/zkey"
38
37#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record" 39#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record"
38 40
41#define GNUNET_REST_JSONAPI_NAMESTORE_NAME "name"
42
43#define GNUNET_REST_JSONAPI_NAMESTORE_REVINFO "revinfo"
44
39#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO 45#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO
40 46
41#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type" 47#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type"
@@ -48,6 +54,8 @@
48 54
49#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey" 55#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey"
50 56
57#define GNUNET_REST_JSONAPI_NAMESTORE_ZKEY "zkey"
58
51#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration" 59#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration"
52 60
53#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego" 61#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego"
@@ -160,6 +168,11 @@ struct RequestHandle
160 char *value; 168 char *value;
161 169
162 /** 170 /**
171 * Zkey string
172 */
173 const char* zkey_str;
174
175 /**
163 * record type 176 * record type
164 */ 177 */
165 uint32_t type; 178 uint32_t type;
@@ -174,12 +187,17 @@ struct RequestHandle
174 */ 187 */
175 unsigned int rd_count; 188 unsigned int rd_count;
176 189
177 /** 190 /**
178 * NAMESTORE Operation 191 * NAMESTORE Operation
179 */ 192 */
180 struct GNUNET_NAMESTORE_QueueEntry *add_qe; 193 struct GNUNET_NAMESTORE_QueueEntry *add_qe;
181 194
182 /** 195 /**
196 * NAMESTORE Operation
197 */
198 struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
199
200 /**
183 * Desired timeout for the lookup (default is no timeout). 201 * Desired timeout for the lookup (default is no timeout).
184 */ 202 */
185 struct GNUNET_TIME_Relative timeout; 203 struct GNUNET_TIME_Relative timeout;
@@ -213,7 +231,7 @@ struct RequestHandle
213 * the length of the REST data 231 * the length of the REST data
214 */ 232 */
215 size_t data_size; 233 size_t data_size;
216 234
217 /** 235 /**
218 * Cfg 236 * Cfg
219 */ 237 */
@@ -416,7 +434,7 @@ namestore_list_response (void *cls,
416 json_array_append (result_array, record_obj); 434 json_array_append (result_array, record_obj);
417 json_decref (record_obj); 435 json_decref (record_obj);
418 } 436 }
419 437
420 if (0 < json_array_size(result_array)) 438 if (0 < json_array_size(result_array))
421 { 439 {
422 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO, 440 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
@@ -774,9 +792,87 @@ namestore_create_cont (struct RestConnectionDataHandle *con,
774 &create_new_record_cont, handle ); 792 &create_new_record_cont, handle );
775} 793}
776 794
795static void
796namestore_zkey_response (void *cls,
797 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
798 const char *label,
799 unsigned int rd_count,
800 const struct GNUNET_GNSRECORD_Data *rd)
801{
802 struct RequestHandle *handle = cls;
803 struct MHD_Response *resp;
804 struct JsonApiObject *json_obj;
805 struct JsonApiResource *json_res;
806 json_t *name_json;
807 char* result;
808
809 handle->reverse_qe = NULL;
810 json_obj = GNUNET_REST_jsonapi_object_new ();
811 if (NULL != label)
812 {
813 name_json = json_string (label);
814 json_res = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_REVINFO,
815 handle->zkey_str);
816 GNUNET_REST_jsonapi_resource_add_attr (json_res,
817 GNUNET_REST_JSONAPI_NAMESTORE_NAME,
818 name_json);
819 GNUNET_REST_jsonapi_object_resource_add (json_obj, json_res);
820 json_decref (name_json);
821 }
822 //Handle response
823 if (GNUNET_SYSERR == GNUNET_REST_jsonapi_data_serialize (json_obj, &result))
824 {
825 GNUNET_REST_jsonapi_object_delete (json_obj);
826 GNUNET_SCHEDULER_add_now (&do_error, handle);
827 return;
828 }
829 resp = GNUNET_REST_create_json_response (result);
830 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
831 GNUNET_free (result);
832 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
833 return;
777 834
835}
778 836
837static void
838namestore_zkey_cont (struct RestConnectionDataHandle *con,
839 const char *url,
840 void *cls)
841{
842 struct RequestHandle *handle = cls;
843 struct GNUNET_HashCode key;
844 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
779 845
846 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY,
847 strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY),
848 &key);
849 if ( GNUNET_NO ==
850 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
851 &key) )
852 {
853 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
854 "No zkey given %s\n", handle->url);
855 GNUNET_SCHEDULER_add_now (&do_error, handle);
856 return;
857 }
858 handle->zkey_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
859 &key);
860 if (GNUNET_OK !=
861 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str,
862 strlen (handle->zkey_str),
863 &pubkey))
864 {
865 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
866 "Zkey invalid %s\n", handle->zkey_str);
867 GNUNET_SCHEDULER_add_now (&do_error, handle);
868 return;
869 }
870 handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
871 &handle->zone_pkey,
872 &pubkey,
873 &namestore_zkey_response,
874 handle);
875}
780 876
781static void 877static void
782namestore_info_cont (struct RestConnectionDataHandle *con, 878namestore_info_cont (struct RestConnectionDataHandle *con,
@@ -837,6 +933,7 @@ testservice_task (void *cls,
837{ 933{
838 struct RequestHandle *handle = cls; 934 struct RequestHandle *handle = cls;
839 static const struct GNUNET_REST_RestConnectionHandler handlers[] = { 935 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
936 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse
840 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list 937 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list
841 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create 938 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create
842 // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH 939 // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH