aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gnsrecord/json_gnsrecord.c114
-rw-r--r--src/namestore/Makefile.am5
-rw-r--r--src/namestore/plugin_rest_namestore.c2
-rwxr-xr-xsrc/namestore/test_plugin_rest_namestore.sh21
4 files changed, 71 insertions, 71 deletions
diff --git a/src/gnsrecord/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c
index 94916292f..707e88668 100644
--- a/src/gnsrecord/json_gnsrecord.c
+++ b/src/gnsrecord/json_gnsrecord.c
@@ -31,13 +31,13 @@
31#define GNUNET_JSON_GNSRECORD_VALUE "value" 31#define GNUNET_JSON_GNSRECORD_VALUE "value"
32#define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" 32#define GNUNET_JSON_GNSRECORD_RECORD_DATA "data"
33#define GNUNET_JSON_GNSRECORD_TYPE "record_type" 33#define GNUNET_JSON_GNSRECORD_TYPE "record_type"
34#define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" 34#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME "relative_expiration"
35#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME "absolute_expiration"
35#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "is_private" 36#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "is_private"
36#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "supplemental" 37#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "is_supplemental"
37#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "is_relative_expiration" 38#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "is_relative_expiration"
38#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "shadow" 39#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "is_shadow"
39#define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" 40#define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name"
40#define GNUNET_JSON_GNSRECORD_NEVER "never"
41 41
42struct GnsRecordInfo 42struct GnsRecordInfo
43{ 43{
@@ -82,39 +82,66 @@ cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info)
82static int 82static int
83parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) 83parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
84{ 84{
85 struct GNUNET_TIME_Absolute abs_expiration_time; 85 struct GNUNET_TIME_Absolute abs_exp;
86 struct GNUNET_TIME_Relative rel_expiration_time; 86 struct GNUNET_TIME_Relative rel_exp;
87 const char *value; 87 const char *value;
88 const char *record_type; 88 const char *record_type;
89 const char *expiration_time;
90 int private; 89 int private;
91 int supplemental; 90 int supplemental;
92 int rel_exp; 91 int is_rel_exp;
93 int shadow; 92 int shadow;
94 int unpack_state = 0; 93 int unpack_state = 0;
94 json_error_t err;
95 95
96 // interpret single gns record 96 // interpret single gns record
97 unpack_state = json_unpack (data, 97 unpack_state = json_unpack_ex (data,
98 "{s:s, s:s, s:s, s:b, s:b, s:b, s:b}", 98 &err,
99 GNUNET_JSON_GNSRECORD_VALUE, 99 0,
100 &value, 100 "{s:s, s:s, s:i, s:b, s:b, s:b, s:b}",
101 GNUNET_JSON_GNSRECORD_TYPE, 101 GNUNET_JSON_GNSRECORD_VALUE,
102 &record_type, 102 &value,
103 GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, 103 GNUNET_JSON_GNSRECORD_TYPE,
104 &expiration_time, 104 &record_type,
105 GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, 105 GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME,
106 &private, 106 &rel_exp.rel_value_us,
107 GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, 107 GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
108 &supplemental, 108 &private,
109 GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, 109 GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
110 &rel_exp, 110 &supplemental,
111 GNUNET_JSON_GNSRECORD_FLAG_SHADOW, 111 GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
112 &shadow); 112 &is_rel_exp,
113 GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
114 &shadow);
113 if (0 != unpack_state) 115 if (0 != unpack_state)
114 { 116 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Error gnsdata object has a wrong format!\n"); 118 "Error gnsdata object has a wrong format: `%s'!\n",
117 return GNUNET_SYSERR; 119 err.text);
120 unpack_state = json_unpack_ex (data,
121 &err,
122 0,
123 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b}",
124 GNUNET_JSON_GNSRECORD_VALUE,
125 &value,
126 GNUNET_JSON_GNSRECORD_TYPE,
127 &record_type,
128 GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME,
129 &abs_exp.abs_value_us,
130 GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
131 &private,
132 GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
133 &supplemental,
134 GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
135 &is_rel_exp,
136 GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
137 &shadow);
138 if ((0 != unpack_state) || (is_rel_exp))
139 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 "Error gnsdata object has a wrong format: `%s'!\n",
142 (is_rel_exp) ? "No relative expiration given" : err.text);
143 return GNUNET_SYSERR;
144 }
118 } 145 }
119 rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type); 146 rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type);
120 if (UINT32_MAX == rd->record_type) 147 if (UINT32_MAX == rd->record_type)
@@ -131,29 +158,8 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
131 return GNUNET_SYSERR; 158 return GNUNET_SYSERR;
132 } 159 }
133 160
134 if (0 == strcmp (expiration_time, GNUNET_JSON_GNSRECORD_NEVER)) 161 if (is_rel_exp)
135 {
136 rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
137 }
138 else if ((1 != rel_exp) &&
139 (GNUNET_OK ==
140 GNUNET_STRINGS_fancy_time_to_absolute (expiration_time,
141 &abs_expiration_time)))
142 {
143 rd->expiration_time = abs_expiration_time.abs_value_us;
144 }
145 else if (GNUNET_OK ==
146 GNUNET_STRINGS_fancy_time_to_relative (expiration_time,
147 &rel_expiration_time))
148 {
149 rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 162 rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
150 rd->expiration_time = rel_expiration_time.rel_value_us;
151 }
152 else
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n");
155 return GNUNET_SYSERR;
156 }
157 if (1 == private) 163 if (1 == private)
158 rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE; 164 rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
159 if (1 == supplemental) 165 if (1 == supplemental)
@@ -260,8 +266,8 @@ clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec)
260 */ 266 */
261struct GNUNET_JSON_Specification 267struct GNUNET_JSON_Specification
262GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, 268GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
263 unsigned int *rd_count, 269 unsigned int *rd_count,
264 char **name) 270 char **name)
265{ 271{
266 struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo); 272 struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
267 273
@@ -289,8 +295,8 @@ GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
289 */ 295 */
290json_t * 296json_t *
291GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, 297GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
292 const struct GNUNET_GNSRECORD_Data *rd, 298 const struct GNUNET_GNSRECORD_Data *rd,
293 unsigned int rd_count) 299 unsigned int rd_count)
294{ 300{
295 struct GNUNET_TIME_Absolute abs_exp; 301 struct GNUNET_TIME_Absolute abs_exp;
296 struct GNUNET_TIME_Relative rel_exp; 302 struct GNUNET_TIME_Relative rel_exp;
@@ -387,5 +393,3 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
387 } 393 }
388 return data; 394 return data;
389} 395}
390
391
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 4b4839f2a..2a1558e09 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -519,9 +519,8 @@ check_SCRIPTS = \
519 test_namestore_delete.sh \ 519 test_namestore_delete.sh \
520 test_namestore_zonefile_import.sh 520 test_namestore_zonefile_import.sh
521 521
522# FIXME 522check_SCRIPTS += \
523#check_SCRIPTS += \ 523 test_plugin_rest_namestore.sh
524# test_plugin_rest_namestore.sh
525 524
526EXTRA_DIST = \ 525EXTRA_DIST = \
527 test_common.c \ 526 test_common.c \
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 05495c23b..2618b4ca0 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -339,7 +339,7 @@ do_error (void *cls)
339 if (0 != handle->ec) 339 if (0 != handle->ec)
340 emsg = GNUNET_strdup (GNUNET_ErrorCode_get_hint (handle->ec)); 340 emsg = GNUNET_strdup (GNUNET_ErrorCode_get_hint (handle->ec));
341 json_object_set_new (json_error, "error", json_string (emsg)); 341 json_object_set_new (json_error, "error", json_string (emsg));
342 342 json_object_set_new (json_error, "error_code", json_integer (handle->ec));
343 response_code = GNUNET_ErrorCode_get_http_status (handle->ec); 343 response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
344 if (0 == response_code) 344 if (0 == response_code)
345 response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 345 response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh
index cd4162abe..4f117db8b 100755
--- a/src/namestore/test_plugin_rest_namestore.sh
+++ b/src/namestore/test_plugin_rest_namestore.sh
@@ -92,37 +92,34 @@ curl_get "${namestore_link}/$public" "error"
92gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf 92gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf
93 93
94#Test POST with NAME 94#Test POST with NAME
95curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content" 95curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "relative_expiration": 86400000000, "is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
96gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 96gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
97 97
98# invalid values 98# invalid values
99curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" 99curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "relative_expiration": 86400000000, "is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":"test_entry"}' "error"
100gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 100gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
101 101
102 102
103curl_post "${namestore_link}/$name" '{"data": [{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name"}]:"test_entry"}' "error" 103curl_post "${namestore_link}/$name" '{"data": [{"value":"", "record_type":"PKEY", "relative_expiration": 86400000000,"flag":0,"record_name"}]:"test_entry"}' "error"
104gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 104gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
105 105
106curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error" 106curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "relative_expiration": 86400000000,"flag":0}],"record_name":"test_entry"}' "error"
107gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 107gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
108 108
109#expirations 109#expirations
110curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"0d","is_private": false, "is_relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" 110curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "relative_expiration":0, "is_relative_expiration": true, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":"test_entry"}' "HTTP/1.1 204"
111gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 111gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
112 112
113curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"10000d","is_private": false, "is_relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" 113curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "relative_expiration":864000000000000, "is_relative_expiration": true, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":"test_entry"}' "HTTP/1.1 204"
114gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 114gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
115 115
116curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"now","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" 116curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time_missing":"1d", "is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":"test_entry"}' "error"
117gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
118
119curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time_missing":"1d","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error"
120gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 117gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
121 118
122#record_name 119#record_name
123curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":""}' "error" 120curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "relative_expiration":86400000000, "is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name":""}' "error"
124gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 121gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
125curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","is_private": false, "is_relative_expiration": false, "supplemental": false, "shadow": false}],"record_name_missing":"test_entry"}' "error" 122curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "relative_expiration":"1d", "is_relative_expiration": false, "is_supplemental": false, "is_shadow": false, "is_private": false}],"record_name_missing":"test_entry"}' "error"
126gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 123gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
127 124
128#Test DELETE 125#Test DELETE