diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-11 15:56:39 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-11 15:56:39 +0000 |
commit | c8aace43c41d50e03bd28b6e696b33c1da8b6c4c (patch) | |
tree | 375181e89bd4f099e0a2039ed0962bf7cfd48131 | |
parent | a12f20bd4c621a7b5e88ca52830ad1bb74a8e2d8 (diff) | |
download | gnunet-c8aace43c41d50e03bd28b6e696b33c1da8b6c4c.tar.gz gnunet-c8aace43c41d50e03bd28b6e696b33c1da8b6c4c.zip |
- move rest plugins into rest directory where they belong
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gns/Makefile.am | 18 | ||||
-rw-r--r-- | src/identity/Makefile.am | 45 | ||||
-rw-r--r-- | src/namestore/Makefile.am | 18 | ||||
-rw-r--r-- | src/rest/Makefile.am | 39 | ||||
-rw-r--r-- | src/rest/plugin_rest_gns.c (renamed from src/gns/plugin_rest_gns.c) | 0 | ||||
-rw-r--r-- | src/rest/plugin_rest_identity.c (renamed from src/identity/plugin_rest_identity.c) | 11 | ||||
-rw-r--r-- | src/rest/plugin_rest_namestore.c (renamed from src/namestore/plugin_rest_namestore.c) | 62 | ||||
-rw-r--r-- | src/rest/rest.c | 9 |
9 files changed, 122 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8e3d02993..ea3852cec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -65,7 +65,6 @@ SUBDIRS = \ | |||
65 | peerinfo \ | 65 | peerinfo \ |
66 | $(MYSQL_DIR) \ | 66 | $(MYSQL_DIR) \ |
67 | $(POSTGRES_DIR) \ | 67 | $(POSTGRES_DIR) \ |
68 | $(REST_DIR) \ | ||
69 | datacache \ | 68 | datacache \ |
70 | datastore \ | 69 | datastore \ |
71 | template \ | 70 | template \ |
@@ -99,6 +98,7 @@ SUBDIRS = \ | |||
99 | fs \ | 98 | fs \ |
100 | exit \ | 99 | exit \ |
101 | pt \ | 100 | pt \ |
101 | $(REST_DIR) \ | ||
102 | integration-tests \ | 102 | integration-tests \ |
103 | $(EXP_DIR) | 103 | $(EXP_DIR) |
104 | 104 | ||
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index d4c65031e..728b5636c 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -85,27 +85,11 @@ bin_PROGRAMS += gnunet-bcd | |||
85 | endif | 85 | endif |
86 | endif | 86 | endif |
87 | 87 | ||
88 | if HAVE_REST | ||
89 | REST_PLUGIN = libgnunet_plugin_rest_gns.la | ||
90 | endif | ||
91 | |||
92 | bin_SCRIPTS = gnunet-gns-proxy-setup-ca | 88 | bin_SCRIPTS = gnunet-gns-proxy-setup-ca |
93 | 89 | ||
94 | plugin_LTLIBRARIES = \ | 90 | plugin_LTLIBRARIES = \ |
95 | libgnunet_plugin_block_gns.la \ | 91 | libgnunet_plugin_block_gns.la \ |
96 | libgnunet_plugin_gnsrecord_gns.la \ | 92 | libgnunet_plugin_gnsrecord_gns.la |
97 | $(REST_PLUGIN) | ||
98 | |||
99 | libgnunet_plugin_rest_gns_la_SOURCES = \ | ||
100 | plugin_rest_gns.c | ||
101 | libgnunet_plugin_rest_gns_la_LIBADD = \ | ||
102 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
103 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
104 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
105 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
106 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
107 | libgnunet_plugin_rest_gns_la_LDFLAGS = \ | ||
108 | $(GN_PLUGIN_LDFLAGS) | ||
109 | 93 | ||
110 | libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ | 94 | libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ |
111 | plugin_gnsrecord_gns.c | 95 | plugin_gnsrecord_gns.c |
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index af4ad5821..f1f0c3851 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am | |||
@@ -19,39 +19,9 @@ libexecdir= $(pkglibdir)/libexec/ | |||
19 | pkgcfg_DATA = \ | 19 | pkgcfg_DATA = \ |
20 | identity.conf | 20 | identity.conf |
21 | 21 | ||
22 | if HAVE_REST | ||
23 | REST_PLUGIN = libgnunet_plugin_rest_identity.la | ||
24 | plugin_LTLIBRARIES = ${REST_PLUGIN} | ||
25 | endif | ||
26 | |||
27 | lib_LTLIBRARIES = \ | 22 | lib_LTLIBRARIES = \ |
28 | libgnunetidentity.la | 23 | libgnunetidentity.la \ |
29 | 24 | libgnunet_plugin_gnsrecord_identity.la | |
30 | if HAVE_REST | ||
31 | plugin_LTLIBRARIES += \ | ||
32 | libgnunet_plugin_gnsrecord_identity.la | ||
33 | |||
34 | |||
35 | libgnunet_plugin_gnsrecord_identity_la_SOURCES = \ | ||
36 | plugin_gnsrecord_identity.c | ||
37 | libgnunet_plugin_gnsrecord_identity_la_LIBADD = \ | ||
38 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
39 | $(LTLIBINTL) | ||
40 | libgnunet_plugin_gnsrecord_identity_la_LDFLAGS = \ | ||
41 | $(GN_PLUGIN_LDFLAGS) | ||
42 | endif | ||
43 | |||
44 | libgnunet_plugin_rest_identity_la_SOURCES = \ | ||
45 | plugin_rest_identity.c | ||
46 | libgnunet_plugin_rest_identity_la_LIBADD = \ | ||
47 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
48 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
49 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
50 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
51 | libgnunet_plugin_rest_identity_la_LDFLAGS = \ | ||
52 | $(GN_PLUGIN_LDFLAGS) | ||
53 | |||
54 | |||
55 | 25 | ||
56 | libgnunetidentity_la_SOURCES = \ | 26 | libgnunetidentity_la_SOURCES = \ |
57 | identity_api.c \ | 27 | identity_api.c \ |
@@ -69,10 +39,12 @@ bin_PROGRAMS = \ | |||
69 | 39 | ||
70 | libexec_PROGRAMS = \ | 40 | libexec_PROGRAMS = \ |
71 | gnunet-service-identity | 41 | gnunet-service-identity |
42 | |||
72 | if HAVE_REST | 43 | if HAVE_REST |
73 | bin_PROGRAMS += \ | 44 | bin_PROGRAMS += \ |
74 | gnunet-identity-token | 45 | gnunet-identity-token |
75 | endif | 46 | endif |
47 | |||
76 | gnunet_service_identity_SOURCES = \ | 48 | gnunet_service_identity_SOURCES = \ |
77 | gnunet-service-identity.c | 49 | gnunet-service-identity.c |
78 | gnunet_service_identity_LDADD = \ | 50 | gnunet_service_identity_LDADD = \ |
@@ -80,6 +52,15 @@ gnunet_service_identity_LDADD = \ | |||
80 | $(top_builddir)/src/util/libgnunetutil.la \ | 52 | $(top_builddir)/src/util/libgnunetutil.la \ |
81 | $(GN_LIBINTL) | 53 | $(GN_LIBINTL) |
82 | 54 | ||
55 | libgnunet_plugin_gnsrecord_identity_la_SOURCES = \ | ||
56 | plugin_gnsrecord_identity.c | ||
57 | libgnunet_plugin_gnsrecord_identity_la_LIBADD = \ | ||
58 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
59 | $(LTLIBINTL) | ||
60 | libgnunet_plugin_gnsrecord_identity_la_LDFLAGS = \ | ||
61 | $(GN_PLUGIN_LDFLAGS) | ||
62 | |||
63 | |||
83 | gnunet_identity_SOURCES = \ | 64 | gnunet_identity_SOURCES = \ |
84 | gnunet-identity.c | 65 | gnunet-identity.c |
85 | gnunet_identity_LDADD = \ | 66 | gnunet_identity_LDADD = \ |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 221e88a91..8ebcac0a1 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -106,21 +106,6 @@ libexec_PROGRAMS += \ | |||
106 | gnunet-namestore-fcfsd | 106 | gnunet-namestore-fcfsd |
107 | endif | 107 | endif |
108 | 108 | ||
109 | if HAVE_REST | ||
110 | REST_PLUGIN = libgnunet_plugin_rest_namestore.la | ||
111 | endif | ||
112 | |||
113 | libgnunet_plugin_rest_namestore_la_SOURCES = \ | ||
114 | plugin_rest_namestore.c | ||
115 | libgnunet_plugin_rest_namestore_la_LIBADD = \ | ||
116 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
117 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
118 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
119 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
120 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
121 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ | ||
122 | $(GN_PLUGIN_LDFLAGS) | ||
123 | |||
124 | 109 | ||
125 | gnunet_namestore_SOURCES = \ | 110 | gnunet_namestore_SOURCES = \ |
126 | gnunet-namestore.c | 111 | gnunet-namestore.c |
@@ -158,8 +143,7 @@ gnunet_service_namestore_LDADD = \ | |||
158 | plugin_LTLIBRARIES = \ | 143 | plugin_LTLIBRARIES = \ |
159 | $(SQLITE_PLUGIN) \ | 144 | $(SQLITE_PLUGIN) \ |
160 | $(POSTGRES_PLUGIN) \ | 145 | $(POSTGRES_PLUGIN) \ |
161 | $(FLAT_PLUGIN) \ | 146 | $(FLAT_PLUGIN) |
162 | $(REST_PLUGIN) | ||
163 | 147 | ||
164 | libgnunet_plugin_namestore_flat_la_SOURCES = \ | 148 | libgnunet_plugin_namestore_flat_la_SOURCES = \ |
165 | plugin_namestore_flat.c | 149 | plugin_namestore_flat.c |
diff --git a/src/rest/Makefile.am b/src/rest/Makefile.am index 8ea87fc6a..cd429abc1 100644 --- a/src/rest/Makefile.am +++ b/src/rest/Makefile.am | |||
@@ -20,12 +20,18 @@ if USE_COVERAGE | |||
20 | XLIBS = -lgcov | 20 | XLIBS = -lgcov |
21 | endif | 21 | endif |
22 | 22 | ||
23 | REST_PLUGINS = libgnunet_plugin_rest_gns.la \ | ||
24 | libgnunet_plugin_rest_identity.la \ | ||
25 | libgnunet_plugin_rest_namestore.la | ||
26 | |||
23 | lib_LTLIBRARIES = \ | 27 | lib_LTLIBRARIES = \ |
24 | libgnunetrest.la | 28 | libgnunetrest.la \ |
29 | $(REST_PLUGINS) | ||
25 | 30 | ||
26 | libexec_PROGRAMS = \ | 31 | libexec_PROGRAMS = \ |
27 | gnunet-rest-server | 32 | gnunet-rest-server |
28 | 33 | ||
34 | |||
29 | gnunet_rest_server_SOURCES = \ | 35 | gnunet_rest_server_SOURCES = \ |
30 | gnunet-rest-server.c | 36 | gnunet-rest-server.c |
31 | 37 | ||
@@ -41,3 +47,34 @@ libgnunetrest_la_LIBADD = \ | |||
41 | libgnunetrest_la_LDFLAGS = \ | 47 | libgnunetrest_la_LDFLAGS = \ |
42 | $(GN_LIB_LDFLAGS) \ | 48 | $(GN_LIB_LDFLAGS) \ |
43 | -version-info 0:0:0 | 49 | -version-info 0:0:0 |
50 | |||
51 | libgnunet_plugin_rest_gns_la_SOURCES = \ | ||
52 | plugin_rest_gns.c | ||
53 | libgnunet_plugin_rest_gns_la_LIBADD = \ | ||
54 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
55 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
56 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
57 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
58 | libgnunet_plugin_rest_gns_la_LDFLAGS = \ | ||
59 | $(GN_PLUGIN_LDFLAGS) | ||
60 | |||
61 | |||
62 | libgnunet_plugin_rest_identity_la_SOURCES = \ | ||
63 | plugin_rest_namestore.c | ||
64 | libgnunet_plugin_rest_identity_la_LIBADD = \ | ||
65 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
66 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
67 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
68 | libgnunet_plugin_rest_identity_la_LDFLAGS = \ | ||
69 | $(GN_PLUGIN_LDFLAGS) | ||
70 | |||
71 | libgnunet_plugin_rest_namestore_la_SOURCES = \ | ||
72 | plugin_rest_namestore.c | ||
73 | libgnunet_plugin_rest_namestore_la_LIBADD = \ | ||
74 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
75 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
76 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
77 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
78 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ | ||
79 | $(GN_PLUGIN_LDFLAGS) | ||
80 | |||
diff --git a/src/gns/plugin_rest_gns.c b/src/rest/plugin_rest_gns.c index 3ebbfb925..3ebbfb925 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/rest/plugin_rest_gns.c | |||
diff --git a/src/identity/plugin_rest_identity.c b/src/rest/plugin_rest_identity.c index 870ed3446..e5abe00ee 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/rest/plugin_rest_identity.c | |||
@@ -89,7 +89,7 @@ | |||
89 | /** | 89 | /** |
90 | * GNUid token lifetime | 90 | * GNUid token lifetime |
91 | */ | 91 | */ |
92 | #define GNUNET_GNUID_TOKEN_EXPIRATION_SECONDS 360 | 92 | #define GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS 300000000 |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * The configuration handle | 95 | * The configuration handle |
@@ -307,11 +307,13 @@ make_gnuid_token (struct RequestHandle *handle, | |||
307 | char **token) | 307 | char **token) |
308 | { | 308 | { |
309 | uint64_t time; | 309 | uint64_t time; |
310 | uint64_t lbl; | ||
310 | char *header_str; | 311 | char *header_str; |
311 | char *payload_str; | 312 | char *payload_str; |
312 | char *header_base64; | 313 | char *header_base64; |
313 | char *payload_base64; | 314 | char *payload_base64; |
314 | char *sig_str; | 315 | char *sig_str; |
316 | char *lbl_str; | ||
315 | json_t *header; | 317 | json_t *header; |
316 | json_t *payload; | 318 | json_t *payload; |
317 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 319 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
@@ -319,16 +321,20 @@ make_gnuid_token (struct RequestHandle *handle, | |||
319 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | 321 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; |
320 | 322 | ||
321 | time = GNUNET_TIME_absolute_get().abs_value_us; | 323 | time = GNUNET_TIME_absolute_get().abs_value_us; |
324 | lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
325 | GNUNET_STRINGS_base64_encode ((char*)&lbl, sizeof (uint64_t), &lbl_str); | ||
326 | |||
322 | header = json_object (); | 327 | header = json_object (); |
323 | json_object_set_new (header, "alg", json_string ("ED512")); | 328 | json_object_set_new (header, "alg", json_string ("ED512")); |
324 | json_object_set_new (header, "typ", json_string ("JWT")); | 329 | json_object_set_new (header, "typ", json_string ("JWT")); |
325 | 330 | ||
326 | payload = json_object (); | 331 | payload = json_object (); |
327 | json_object_set_new (payload, "iss", json_string (ego_entry->keystring)); | 332 | json_object_set_new (payload, "iss", json_string (ego_entry->keystring)); |
333 | json_object_set_new (payload, "lbl", json_string (lbl_str)); | ||
328 | json_object_set_new (payload, "sub", json_string (name)); | 334 | json_object_set_new (payload, "sub", json_string (name)); |
329 | json_object_set_new (payload, "nbf", json_integer (time)); | 335 | json_object_set_new (payload, "nbf", json_integer (time)); |
330 | json_object_set_new (payload, "iat", json_integer (time)); | 336 | json_object_set_new (payload, "iat", json_integer (time)); |
331 | json_object_set_new (payload, "exp", json_integer (time+GNUNET_GNUID_TOKEN_EXPIRATION_SECONDS)); | 337 | json_object_set_new (payload, "exp", json_integer (time+GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS)); |
332 | json_object_set_new (payload, "aud", json_string (token_aud)); | 338 | json_object_set_new (payload, "aud", json_string (token_aud)); |
333 | header_str = json_dumps (header, JSON_COMPACT); | 339 | header_str = json_dumps (header, JSON_COMPACT); |
334 | GNUNET_STRINGS_base64_encode (header_str, | 340 | GNUNET_STRINGS_base64_encode (header_str, |
@@ -370,6 +376,7 @@ make_gnuid_token (struct RequestHandle *handle, | |||
370 | GNUNET_free (payload_str); | 376 | GNUNET_free (payload_str); |
371 | GNUNET_free (payload_base64); | 377 | GNUNET_free (payload_base64); |
372 | GNUNET_free (purpose); | 378 | GNUNET_free (purpose); |
379 | GNUNET_free (lbl_str); | ||
373 | json_decref (header); | 380 | json_decref (header); |
374 | json_decref (payload); | 381 | json_decref (payload); |
375 | } | 382 | } |
diff --git a/src/namestore/plugin_rest_namestore.c b/src/rest/plugin_rest_namestore.c index 9b6b5c57c..5ece83064 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/rest/plugin_rest_namestore.c | |||
@@ -60,6 +60,12 @@ struct Plugin | |||
60 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 60 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | |||
64 | /** | ||
65 | * HTTP methods allows for this plugin | ||
66 | */ | ||
67 | static char* allow_methods; | ||
68 | |||
63 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 69 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
64 | 70 | ||
65 | struct RecordEntry | 71 | struct RecordEntry |
@@ -409,13 +415,16 @@ namestore_list_response (void *cls, | |||
409 | json_array_append (result_array, record_obj); | 415 | json_array_append (result_array, record_obj); |
410 | json_decref (record_obj); | 416 | json_decref (record_obj); |
411 | } | 417 | } |
412 | 418 | ||
413 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO, | 419 | if (0 < json_array_size(result_array)) |
414 | rname); | 420 | { |
415 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, | 421 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO, |
416 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD, | 422 | rname); |
417 | result_array); | 423 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, |
418 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); | 424 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD, |
425 | result_array); | ||
426 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); | ||
427 | } | ||
419 | 428 | ||
420 | json_decref (result_array); | 429 | json_decref (result_array); |
421 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it); | 430 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it); |
@@ -789,6 +798,31 @@ get_name_from_url (const char* url) | |||
789 | } | 798 | } |
790 | 799 | ||
791 | /** | 800 | /** |
801 | * Respond to OPTIONS request | ||
802 | * | ||
803 | * @param con_handle the connection handle | ||
804 | * @param url the url | ||
805 | * @param cls the RequestHandle | ||
806 | */ | ||
807 | static void | ||
808 | options_cont (struct RestConnectionDataHandle *con_handle, | ||
809 | const char* url, | ||
810 | void *cls) | ||
811 | { | ||
812 | struct MHD_Response *resp; | ||
813 | struct RequestHandle *handle = cls; | ||
814 | |||
815 | //For now, independent of path return all options | ||
816 | resp = GNUNET_REST_create_json_response (NULL); | ||
817 | MHD_add_response_header (resp, | ||
818 | "Access-Control-Allow-Methods", | ||
819 | allow_methods); | ||
820 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
821 | cleanup_handle (handle); | ||
822 | return; | ||
823 | } | ||
824 | |||
825 | /** | ||
792 | * Function called with the result from the check if the namestore | 826 | * Function called with the result from the check if the namestore |
793 | * service is actually running. If it is, we start the actual | 827 | * service is actually running. If it is, we start the actual |
794 | * operation. | 828 | * operation. |
@@ -806,6 +840,7 @@ testservice_task (void *cls, | |||
806 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create | 840 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create |
807 | // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH | 841 | // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH |
808 | {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete_cont}, //delete | 842 | {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete_cont}, //delete |
843 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont}, | ||
809 | GNUNET_REST_HANDLER_END | 844 | GNUNET_REST_HANDLER_END |
810 | }; | 845 | }; |
811 | 846 | ||
@@ -935,7 +970,7 @@ testservice_id_task (void *cls, int result) | |||
935 | &key); | 970 | &key); |
936 | } | 971 | } |
937 | 972 | ||
938 | type = GNUNET_GNSRECORD_TYPE_ANY; | 973 | handle->type = GNUNET_GNSRECORD_TYPE_ANY; |
939 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE, | 974 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE, |
940 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE), | 975 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE), |
941 | &key); | 976 | &key); |
@@ -945,8 +980,9 @@ testservice_id_task (void *cls, int result) | |||
945 | { | 980 | { |
946 | type = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | 981 | type = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, |
947 | &key); | 982 | &key); |
983 | |||
984 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); | ||
948 | } | 985 | } |
949 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); | ||
950 | name = get_name_from_url (handle->url); | 986 | name = get_name_from_url (handle->url); |
951 | if (NULL != ego) | 987 | if (NULL != ego) |
952 | GNUNET_asprintf (&handle->ego_name, "%s", ego); | 988 | GNUNET_asprintf (&handle->ego_name, "%s", ego); |
@@ -1035,6 +1071,13 @@ libgnunet_plugin_rest_namestore_init (void *cls) | |||
1035 | api->cls = &plugin; | 1071 | api->cls = &plugin; |
1036 | api->name = GNUNET_REST_API_NS_NAMESTORE; | 1072 | api->name = GNUNET_REST_API_NS_NAMESTORE; |
1037 | api->process_request = &rest_identity_process_request; | 1073 | api->process_request = &rest_identity_process_request; |
1074 | GNUNET_asprintf (&allow_methods, | ||
1075 | "%s, %s, %s, %s, %s", | ||
1076 | MHD_HTTP_METHOD_GET, | ||
1077 | MHD_HTTP_METHOD_POST, | ||
1078 | MHD_HTTP_METHOD_PUT, | ||
1079 | MHD_HTTP_METHOD_DELETE, | ||
1080 | MHD_HTTP_METHOD_OPTIONS); | ||
1038 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1081 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1039 | _("Namestore REST API initialized\n")); | 1082 | _("Namestore REST API initialized\n")); |
1040 | return api; | 1083 | return api; |
@@ -1055,6 +1098,7 @@ libgnunet_plugin_rest_namestore_done (void *cls) | |||
1055 | 1098 | ||
1056 | plugin->cfg = NULL; | 1099 | plugin->cfg = NULL; |
1057 | GNUNET_free (api); | 1100 | GNUNET_free (api); |
1101 | GNUNET_free_non_null (allow_methods); | ||
1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1059 | "Namestore REST plugin is finished\n"); | 1103 | "Namestore REST plugin is finished\n"); |
1060 | return NULL; | 1104 | return NULL; |
diff --git a/src/rest/rest.c b/src/rest/rest.c index 3a27c6813..77427ef6c 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c | |||
@@ -403,12 +403,15 @@ GNUNET_REST_jsonapi_data_serialize (const struct JsonApiObject *resp, | |||
403 | json_t *root_json; | 403 | json_t *root_json; |
404 | json_t *res_arr; | 404 | json_t *res_arr; |
405 | 405 | ||
406 | if ( (NULL == resp) || | 406 | if ((NULL == resp)) |
407 | (0 == resp->res_count) ) | ||
408 | return GNUNET_SYSERR; | 407 | return GNUNET_SYSERR; |
409 | 408 | ||
410 | root_json = json_object (); | 409 | root_json = json_object (); |
411 | if (1 == resp->res_count) | 410 | if (0 == resp->res_count) |
411 | { | ||
412 | json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, json_array()); | ||
413 | } | ||
414 | else if (1 == resp->res_count) | ||
412 | { | 415 | { |
413 | json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, resp->res_list_head->res_obj); | 416 | json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, resp->res_list_head->res_obj); |
414 | } | 417 | } |