diff options
Diffstat (limited to 'src/include/gnunet_jsonapi_lib.h')
-rw-r--r-- | src/include/gnunet_jsonapi_lib.h | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/src/include/gnunet_jsonapi_lib.h b/src/include/gnunet_jsonapi_lib.h new file mode 100644 index 000000000..18dfbdf95 --- /dev/null +++ b/src/include/gnunet_jsonapi_lib.h | |||
@@ -0,0 +1,202 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2014, 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 | * @file gnunet_jsonapi_lib.h | ||
18 | * @brief functions to parse jsonapi objects | ||
19 | * @author Martin Schanzenbach | ||
20 | */ | ||
21 | #ifndef GNUNET_JSONAPI_LIB_H | ||
22 | #define GNUNET_JSONAPI_LIB_H | ||
23 | |||
24 | #include "gnunet_util_lib.h" | ||
25 | #include "gnunet_json_lib.h" | ||
26 | |||
27 | |||
28 | /* ****************** JSONAPI parsing ******************* */ | ||
29 | |||
30 | struct GNUNET_JSONAPI_Resource; | ||
31 | |||
32 | struct GNUNET_JSONAPI_Object; | ||
33 | |||
34 | /** | ||
35 | * Specification for parsing a jsonapi object. | ||
36 | * | ||
37 | * @param jsonapi_obj where to store the jsonapi object | ||
38 | */ | ||
39 | struct GNUNET_JSONAPI_Specification | ||
40 | GNUNET_JSONAPI_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj); | ||
41 | |||
42 | /** | ||
43 | * Create a JSON API resource | ||
44 | * | ||
45 | * @param type the JSON API resource type | ||
46 | * @param id the JSON API resource id | ||
47 | * @return a new JSON API resource or NULL on error. | ||
48 | */ | ||
49 | struct GNUNET_JSONAPI_Resource* | ||
50 | GNUNET_JSONAPI_resource_new (const char *type, const char *id); | ||
51 | |||
52 | /** | ||
53 | * Delete a JSON API resource | ||
54 | * | ||
55 | * @param res the JSON resource | ||
56 | * @param result Pointer where the resource should be stored | ||
57 | */ | ||
58 | void | ||
59 | GNUNET_JSONAPI_resource_delete (struct GNUNET_JSONAPI_Resource *resource); | ||
60 | |||
61 | /** | ||
62 | * Add a JSON API attribute | ||
63 | * | ||
64 | * @param res the JSON resource | ||
65 | * @param key the key for the attribute | ||
66 | * @param json the json_t attribute to add | ||
67 | * @return #GNUNET_OK if added successfully | ||
68 | * #GNUNET_SYSERR if not | ||
69 | */ | ||
70 | int | ||
71 | GNUNET_JSONAPI_resource_add_attr (const struct GNUNET_JSONAPI_Resource *resource, | ||
72 | const char* key, | ||
73 | json_t *json); | ||
74 | /** | ||
75 | * Read a JSON API attribute | ||
76 | * | ||
77 | * @param res the JSON resource | ||
78 | * @param key the key for the attribute | ||
79 | * @return the json attr | ||
80 | */ | ||
81 | json_t* | ||
82 | GNUNET_JSONAPI_resource_read_attr (const struct GNUNET_JSONAPI_Resource *resource, | ||
83 | const char* key); | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Check a JSON API resource id | ||
88 | * | ||
89 | * @param res the JSON resource | ||
90 | * @param id the expected id | ||
91 | * @return GNUNET_YES if id matches | ||
92 | */ | ||
93 | int | ||
94 | GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource, | ||
95 | const char* id); | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Check a JSON API resource type | ||
100 | * | ||
101 | * @param res the JSON resource | ||
102 | * @param type the expected type | ||
103 | * @return GNUNET_YES if id matches | ||
104 | */ | ||
105 | int | ||
106 | GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource, | ||
107 | const char* type); | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Create a JSON API primary data | ||
112 | * | ||
113 | * @param type the JSON API resource type | ||
114 | * @param id the JSON API resource id | ||
115 | * @return a new JSON API resource or NULL on error. | ||
116 | */ | ||
117 | struct GNUNET_JSONAPI_Object* | ||
118 | GNUNET_JSONAPI_object_new (); | ||
119 | |||
120 | |||
121 | /** | ||
122 | * Create a JSON API primary data from a string | ||
123 | * | ||
124 | * @param data the string of the JSON API data | ||
125 | * @return a new JSON API resource or NULL on error. | ||
126 | */ | ||
127 | struct GNUNET_JSONAPI_Object* | ||
128 | GNUNET_JSONAPI_object_parse (const char* data); | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Delete a JSON API primary data | ||
133 | * | ||
134 | * @param type the JSON API resource type | ||
135 | * @param id the JSON API resource id | ||
136 | * @return a new JSON API resource or NULL on error. | ||
137 | */ | ||
138 | void | ||
139 | GNUNET_JSONAPI_object_delete (struct GNUNET_JSONAPI_Object *resp); | ||
140 | |||
141 | /** | ||
142 | * Add a JSON API resource to primary data | ||
143 | * | ||
144 | * @param data The JSON API data to add to | ||
145 | * @param res the JSON API resource to add | ||
146 | * @return the new number of resources | ||
147 | */ | ||
148 | void | ||
149 | GNUNET_JSONAPI_object_resource_add (struct GNUNET_JSONAPI_Object *resp, | ||
150 | struct GNUNET_JSONAPI_Resource *res); | ||
151 | /** | ||
152 | * Get a JSON API object resource count | ||
153 | * | ||
154 | * @param resp the JSON API object | ||
155 | * @return the number of resources | ||
156 | */ | ||
157 | int | ||
158 | GNUNET_JSONAPI_object_resource_count (struct GNUNET_JSONAPI_Object *resp); | ||
159 | |||
160 | /** | ||
161 | * Get a JSON API object resource num | ||
162 | * | ||
163 | * @param resp the JSON API object | ||
164 | * @param num the number of the resource | ||
165 | * @return the resource | ||
166 | */ | ||
167 | struct GNUNET_JSONAPI_Resource* | ||
168 | GNUNET_JSONAPI_object_get_resource (struct GNUNET_JSONAPI_Object *resp, int num); | ||
169 | |||
170 | |||
171 | /** | ||
172 | * Add a JSON API resource to primary data | ||
173 | * | ||
174 | * @param resp The JSON API data to add to | ||
175 | * @param res the JSON API resource to add | ||
176 | * @return the new number of resources | ||
177 | */ | ||
178 | void | ||
179 | GNUNET_JSONAPI_data_resource_remove (struct GNUNET_JSONAPI_Object *resp, | ||
180 | struct GNUNET_JSONAPI_Resource *res); | ||
181 | |||
182 | /** | ||
183 | * String serialze jsonapi primary data | ||
184 | * | ||
185 | * @param data the JSON API primary data | ||
186 | * @param result where to store the result | ||
187 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
188 | */ | ||
189 | int | ||
190 | GNUNET_JSONAPI_data_serialize (const struct GNUNET_JSONAPI_Object *resp, | ||
191 | char **result); | ||
192 | |||
193 | /** | ||
194 | * Check a JSON API resource id | ||
195 | * | ||
196 | * @param res the JSON resource | ||
197 | * @return the resource id | ||
198 | */ | ||
199 | json_t* | ||
200 | GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource); | ||
201 | /* end of gnunet_jsonapi_lib.h */ | ||
202 | #endif | ||