diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-05 10:17:37 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-05 10:17:37 +0000 |
commit | 9bfec4362916ca79314265af464a096706a1c963 (patch) | |
tree | b3ce3a417842bff6df2496c0f4ebd979836d4dcb /src/include/gnunet_jsonapi_lib.h | |
parent | e2e045f3fef2231c435ae7dacbb5e947a0193a20 (diff) | |
download | gnunet-9bfec4362916ca79314265af464a096706a1c963.tar.gz gnunet-9bfec4362916ca79314265af464a096706a1c963.zip |
- refactor jsonpi utils, add test
Diffstat (limited to 'src/include/gnunet_jsonapi_lib.h')
-rw-r--r-- | src/include/gnunet_jsonapi_lib.h | 119 |
1 files changed, 59 insertions, 60 deletions
diff --git a/src/include/gnunet_jsonapi_lib.h b/src/include/gnunet_jsonapi_lib.h index 5535cb2aa..ce41c33f1 100644 --- a/src/include/gnunet_jsonapi_lib.h +++ b/src/include/gnunet_jsonapi_lib.h | |||
@@ -22,7 +22,6 @@ | |||
22 | #define GNUNET_JSONAPI_LIB_H | 22 | #define GNUNET_JSONAPI_LIB_H |
23 | 23 | ||
24 | #include "gnunet_util_lib.h" | 24 | #include "gnunet_util_lib.h" |
25 | #include "gnunet_rest_lib.h" | ||
26 | #include "gnunet_json_lib.h" | 25 | #include "gnunet_json_lib.h" |
27 | 26 | ||
28 | #define GNUNET_JSONAPI_KEY_DATA "data" | 27 | #define GNUNET_JSONAPI_KEY_DATA "data" |
@@ -101,6 +100,32 @@ void | |||
101 | GNUNET_JSONAPI_relationship_delete (struct GNUNET_JSONAPI_Relationship *rel); | 100 | GNUNET_JSONAPI_relationship_delete (struct GNUNET_JSONAPI_Relationship *rel); |
102 | 101 | ||
103 | 102 | ||
103 | /****************** jsonapi Error API ********************/ | ||
104 | |||
105 | /** | ||
106 | * Create a JSON API error | ||
107 | * | ||
108 | * @param res the JSON error | ||
109 | */ | ||
110 | struct GNUNET_JSONAPI_Error* | ||
111 | GNUNET_JSONAPI_error_new (const char *id, | ||
112 | const char *status, | ||
113 | const char *code, | ||
114 | const char *title, | ||
115 | const char *detail, | ||
116 | json_t *links, | ||
117 | json_t *source, | ||
118 | json_t *meta); | ||
119 | |||
120 | /** | ||
121 | * Delete a JSON API error | ||
122 | * | ||
123 | * @param res the JSON error | ||
124 | */ | ||
125 | void | ||
126 | GNUNET_JSONAPI_error_delete (struct GNUNET_JSONAPI_Error *error); | ||
127 | |||
128 | |||
104 | /** | 129 | /** |
105 | * Add a JSON API error to document | 130 | * Add a JSON API error to document |
106 | * | 131 | * |
@@ -134,13 +159,7 @@ int | |||
134 | GNUNET_JSONAPI_json_to_error (json_t *err_json, | 159 | GNUNET_JSONAPI_json_to_error (json_t *err_json, |
135 | struct GNUNET_JSONAPI_Error **err); | 160 | struct GNUNET_JSONAPI_Error **err); |
136 | 161 | ||
137 | /** | 162 | /****************** jsonapi Resource API ********************/ |
138 | * Delete a JSON API error | ||
139 | * | ||
140 | * @param res the JSON error | ||
141 | */ | ||
142 | void | ||
143 | GNUNET_JSONAPI_error_delete (struct GNUNET_JSONAPI_Error *error); | ||
144 | 163 | ||
145 | /** | 164 | /** |
146 | * Create a JSON API resource | 165 | * Create a JSON API resource |
@@ -154,6 +173,16 @@ GNUNET_JSONAPI_resource_new (const char *type, const char *id); | |||
154 | 173 | ||
155 | 174 | ||
156 | /** | 175 | /** |
176 | * Delete a JSON API resource | ||
177 | * | ||
178 | * @param res the JSON resource | ||
179 | * @param result Pointer where the resource should be stored | ||
180 | */ | ||
181 | void | ||
182 | GNUNET_JSONAPI_resource_delete (struct GNUNET_JSONAPI_Resource *resource); | ||
183 | |||
184 | |||
185 | /** | ||
157 | * String serialze jsonapi to json | 186 | * String serialze jsonapi to json |
158 | * | 187 | * |
159 | * @param data the JSON API resource | 188 | * @param data the JSON API resource |
@@ -164,6 +193,7 @@ int | |||
164 | GNUNET_JSONAPI_resource_to_json (const struct GNUNET_JSONAPI_Resource *res, | 193 | GNUNET_JSONAPI_resource_to_json (const struct GNUNET_JSONAPI_Resource *res, |
165 | json_t **result); | 194 | json_t **result); |
166 | 195 | ||
196 | |||
167 | /** | 197 | /** |
168 | * Parse json to resource object | 198 | * Parse json to resource object |
169 | * | 199 | * |
@@ -175,14 +205,6 @@ int | |||
175 | GNUNET_JSONAPI_json_to_resource (json_t *res_json, | 205 | GNUNET_JSONAPI_json_to_resource (json_t *res_json, |
176 | struct GNUNET_JSONAPI_Resource **res); | 206 | struct GNUNET_JSONAPI_Resource **res); |
177 | 207 | ||
178 | /** | ||
179 | * Delete a JSON API resource | ||
180 | * | ||
181 | * @param res the JSON resource | ||
182 | * @param result Pointer where the resource should be stored | ||
183 | */ | ||
184 | void | ||
185 | GNUNET_JSONAPI_resource_delete (struct GNUNET_JSONAPI_Resource *resource); | ||
186 | 208 | ||
187 | /** | 209 | /** |
188 | * Add a JSON API attribute | 210 | * Add a JSON API attribute |
@@ -220,6 +242,15 @@ int | |||
220 | GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource, | 242 | GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource, |
221 | const char* id); | 243 | const char* id); |
222 | 244 | ||
245 | /** | ||
246 | * Check a JSON API resource id | ||
247 | * | ||
248 | * @param res the JSON resource | ||
249 | * @return the resource id | ||
250 | */ | ||
251 | char* | ||
252 | GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource); | ||
253 | |||
223 | 254 | ||
224 | /** | 255 | /** |
225 | * Check a JSON API resource type | 256 | * Check a JSON API resource type |
@@ -232,6 +263,7 @@ int | |||
232 | GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource, | 263 | GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource, |
233 | const char* type); | 264 | const char* type); |
234 | 265 | ||
266 | /****************** jsonapi Document API ********************/ | ||
235 | 267 | ||
236 | /** | 268 | /** |
237 | * Create a JSON API primary data | 269 | * Create a JSON API primary data |
@@ -267,6 +299,17 @@ void | |||
267 | GNUNET_JSONAPI_document_delete (struct GNUNET_JSONAPI_Document *resp); | 299 | GNUNET_JSONAPI_document_delete (struct GNUNET_JSONAPI_Document *resp); |
268 | 300 | ||
269 | /** | 301 | /** |
302 | * String serialze jsonapi primary data | ||
303 | * | ||
304 | * @param data the JSON API primary data | ||
305 | * @param result where to store the result | ||
306 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
307 | */ | ||
308 | int | ||
309 | GNUNET_JSONAPI_document_to_json (const struct GNUNET_JSONAPI_Document *doc, | ||
310 | json_t **root_json); | ||
311 | |||
312 | /** | ||
270 | * Add a JSON API resource to primary data | 313 | * Add a JSON API resource to primary data |
271 | * | 314 | * |
272 | * @param data The JSON API data to add to | 315 | * @param data The JSON API data to add to |
@@ -318,49 +361,5 @@ int | |||
318 | GNUNET_JSONAPI_document_serialize (const struct GNUNET_JSONAPI_Document *resp, | 361 | GNUNET_JSONAPI_document_serialize (const struct GNUNET_JSONAPI_Document *resp, |
319 | char **result); | 362 | char **result); |
320 | 363 | ||
321 | /** | ||
322 | * Check a JSON API resource id | ||
323 | * | ||
324 | * @param res the JSON resource | ||
325 | * @return the resource id | ||
326 | */ | ||
327 | char* | ||
328 | GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource); | ||
329 | |||
330 | |||
331 | /* end of gnunet_jsonapi_lib.h */ | 364 | /* end of gnunet_jsonapi_lib.h */ |
332 | |||
333 | /** | ||
334 | * Check rest request for validity | ||
335 | * | ||
336 | * @param req handle to the request | ||
337 | * @return GNUNET_OK if valid | ||
338 | */ | ||
339 | int | ||
340 | GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req); | ||
341 | |||
342 | /** | ||
343 | * Check rest request for validity | ||
344 | * | ||
345 | * @param req handle to the request | ||
346 | * @return GNUNET_OK if valid | ||
347 | */ | ||
348 | int | ||
349 | GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req); | ||
350 | |||
351 | |||
352 | /** | ||
353 | * Handle jsonapi rest request. Checks request headers for jsonapi compliance | ||
354 | * | ||
355 | * @param req rest request handle | ||
356 | * @param handler rest request handlers | ||
357 | * @param cls closure | ||
358 | * @return GNUNET_OK if successful | ||
359 | */ | ||
360 | int | ||
361 | GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *req, | ||
362 | const struct GNUNET_REST_RequestHandler *handlers, | ||
363 | struct GNUNET_REST_RequestHandlerError *err, | ||
364 | void *cls); | ||
365 | |||
366 | #endif | 365 | #endif |