diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 6 | ||||
-rw-r--r-- | src/include/gnunet_jsonapi_lib.h | 12 | ||||
-rw-r--r-- | src/jsonapi/Makefile.am | 20 | ||||
-rw-r--r-- | src/jsonapi/test_jsonapi.c | 104 | ||||
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 3 |
5 files changed, 127 insertions, 18 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index b827bfb2b..10836f103 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -504,7 +504,8 @@ ego_create_cont (struct RestConnectionDataHandle *con, | |||
504 | } | 504 | } |
505 | term_data[handle->data_size] = '\0'; | 505 | term_data[handle->data_size] = '\0'; |
506 | memcpy (term_data, handle->data, handle->data_size); | 506 | memcpy (term_data, handle->data, handle->data_size); |
507 | json_obj = GNUNET_JSONAPI_object_parse (term_data); | 507 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, |
508 | &json_obj)); | ||
508 | if (NULL == json_obj) | 509 | if (NULL == json_obj) |
509 | { | 510 | { |
510 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 511 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
@@ -618,7 +619,8 @@ ego_edit_cont (struct RestConnectionDataHandle *con, | |||
618 | 619 | ||
619 | term_data[handle->data_size] = '\0'; | 620 | term_data[handle->data_size] = '\0'; |
620 | memcpy (term_data, handle->data, handle->data_size); | 621 | memcpy (term_data, handle->data, handle->data_size); |
621 | json_obj = GNUNET_JSONAPI_object_parse (term_data); | 622 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, |
623 | &json_obj)); | ||
622 | 624 | ||
623 | if (NULL == json_obj) | 625 | if (NULL == json_obj) |
624 | { | 626 | { |
diff --git a/src/include/gnunet_jsonapi_lib.h b/src/include/gnunet_jsonapi_lib.h index 18dfbdf95..1e540f6b6 100644 --- a/src/include/gnunet_jsonapi_lib.h +++ b/src/include/gnunet_jsonapi_lib.h | |||
@@ -36,8 +36,8 @@ struct GNUNET_JSONAPI_Object; | |||
36 | * | 36 | * |
37 | * @param jsonapi_obj where to store the jsonapi object | 37 | * @param jsonapi_obj where to store the jsonapi object |
38 | */ | 38 | */ |
39 | struct GNUNET_JSONAPI_Specification | 39 | struct GNUNET_JSON_Specification |
40 | GNUNET_JSONAPI_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj); | 40 | GNUNET_JSON_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj); |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Create a JSON API resource | 43 | * Create a JSON API resource |
@@ -122,10 +122,12 @@ GNUNET_JSONAPI_object_new (); | |||
122 | * Create a JSON API primary data from a string | 122 | * Create a JSON API primary data from a string |
123 | * | 123 | * |
124 | * @param data the string of the JSON API data | 124 | * @param data the string of the JSON API data |
125 | * @return a new JSON API resource or NULL on error. | 125 | * @param Pointer where to store new jsonapi Object. |
126 | * @return GNUNET_OK on success | ||
126 | */ | 127 | */ |
127 | struct GNUNET_JSONAPI_Object* | 128 | int |
128 | GNUNET_JSONAPI_object_parse (const char* data); | 129 | GNUNET_JSONAPI_object_parse (const char* data, |
130 | struct GNUNET_JSONAPI_Object** obj); | ||
129 | 131 | ||
130 | 132 | ||
131 | /** | 133 | /** |
diff --git a/src/jsonapi/Makefile.am b/src/jsonapi/Makefile.am index 1d3fcc760..8a702440d 100644 --- a/src/jsonapi/Makefile.am +++ b/src/jsonapi/Makefile.am | |||
@@ -20,15 +20,15 @@ libgnunetjsonapi_la_LIBADD = \ | |||
20 | -ljansson \ | 20 | -ljansson \ |
21 | $(XLIB) | 21 | $(XLIB) |
22 | 22 | ||
23 | #check_PROGRAMS = \ | 23 | check_PROGRAMS = \ |
24 | # test_json | 24 | test_jsonapi |
25 | 25 | ||
26 | #TESTS = \ | 26 | TESTS = \ |
27 | # $(check_PROGRAMS) | 27 | $(check_PROGRAMS) |
28 | 28 | ||
29 | #test_json_SOURCES = \ | 29 | test_jsonapi_SOURCES = \ |
30 | # test_json.c | 30 | test_jsonapi.c |
31 | #test_json_LDADD = \ | 31 | test_jsonapi_LDADD = \ |
32 | # libgnunetjson.la \ | 32 | libgnunetjsonapi.la \ |
33 | # $(top_builddir)/src/util/libgnunetutil.la \ | 33 | $(top_builddir)/src/util/libgnunetutil.la \ |
34 | # -ljansson | 34 | -ljansson |
diff --git a/src/jsonapi/test_jsonapi.c b/src/jsonapi/test_jsonapi.c new file mode 100644 index 000000000..e9c85eaf6 --- /dev/null +++ b/src/jsonapi/test_jsonapi.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2015, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file json/test_jsonapi.c | ||
19 | * @brief Tests for jsonapi conversion functions | ||
20 | * @author Martin Schanzenbach | ||
21 | */ | ||
22 | #include "platform.h" | ||
23 | #include "gnunet_util_lib.h" | ||
24 | #include "gnunet_jsonapi_lib.h" | ||
25 | #include "gnunet_json_lib.h" | ||
26 | |||
27 | static int | ||
28 | test_serialize () | ||
29 | { | ||
30 | struct GNUNET_JSONAPI_Object *obj; | ||
31 | char* data = "{\"data\":[{\"id\":\"1\", \"type\":\"test\"}]}"; | ||
32 | char* tmp_data; | ||
33 | json_t* data_js; | ||
34 | json_t* tmp_data_js; | ||
35 | json_error_t err; | ||
36 | struct GNUNET_JSON_Specification jsonapispec[] = { | ||
37 | GNUNET_JSON_spec_jsonapi (&obj), | ||
38 | GNUNET_JSON_spec_end() | ||
39 | }; | ||
40 | data_js = json_loads (data, JSON_DECODE_ANY, &err); | ||
41 | GNUNET_assert (NULL != data_js); | ||
42 | GNUNET_assert (GNUNET_OK == | ||
43 | GNUNET_JSON_parse (data_js, jsonapispec, | ||
44 | NULL, NULL)); | ||
45 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_data_serialize (obj, | ||
46 | &tmp_data)); | ||
47 | GNUNET_JSON_parse_free (jsonapispec); | ||
48 | tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err); | ||
49 | GNUNET_assert (NULL != tmp_data_js); | ||
50 | GNUNET_assert (0 != json_equal (tmp_data_js, data_js)); | ||
51 | json_decref (data_js); | ||
52 | json_decref (tmp_data_js); | ||
53 | GNUNET_free (tmp_data); | ||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Test rsa conversions from/to JSON. | ||
59 | * | ||
60 | * @return 0 on success | ||
61 | */ | ||
62 | static int | ||
63 | test_spec_jsonapi () | ||
64 | { | ||
65 | struct GNUNET_JSONAPI_Object *obj; | ||
66 | struct GNUNET_JSONAPI_Resource *res; | ||
67 | const char* data = "{\"data\":{\"id\":\"1\", \"type\":\"test\"}}"; | ||
68 | json_t* data_js; | ||
69 | json_error_t err; | ||
70 | |||
71 | struct GNUNET_JSON_Specification jsonapispec[] = { | ||
72 | GNUNET_JSON_spec_jsonapi (&obj), | ||
73 | GNUNET_JSON_spec_end() | ||
74 | }; | ||
75 | data_js = json_loads (data, JSON_DECODE_ANY, &err); | ||
76 | GNUNET_assert (NULL != data_js); | ||
77 | GNUNET_assert (GNUNET_OK == | ||
78 | GNUNET_JSON_parse (data_js, jsonapispec, | ||
79 | NULL, NULL)); | ||
80 | json_decref (data_js); | ||
81 | res = GNUNET_JSONAPI_object_get_resource (obj, 0); | ||
82 | GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_id (res, "1")); | ||
83 | GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_type (res, "test")); | ||
84 | GNUNET_assert (1 == GNUNET_JSONAPI_object_resource_count (obj)); | ||
85 | GNUNET_JSON_parse_free (jsonapispec); | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | |||
90 | int | ||
91 | main(int argc, | ||
92 | const char *const argv[]) | ||
93 | { | ||
94 | GNUNET_log_setup ("test-jsonapi", | ||
95 | "WARNING", | ||
96 | NULL); | ||
97 | if (0 != test_spec_jsonapi ()) | ||
98 | return 1; | ||
99 | if (0 != test_serialize ()) | ||
100 | return 1; | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | /* end of test_json.c */ | ||
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index d33bf483b..c47a6a3c8 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -744,7 +744,8 @@ namestore_create_cont (struct RestConnectionDataHandle *con, | |||
744 | } | 744 | } |
745 | term_data[handle->data_size] = '\0'; | 745 | term_data[handle->data_size] = '\0'; |
746 | memcpy (term_data, handle->data, handle->data_size); | 746 | memcpy (term_data, handle->data, handle->data_size); |
747 | json_obj = GNUNET_JSONAPI_object_parse (term_data); | 747 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, |
748 | &json_obj)); | ||
748 | if (NULL == json_obj) | 749 | if (NULL == json_obj) |
749 | { | 750 | { |
750 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 751 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |