aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_jsonapi_lib.h
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-05-04 17:18:02 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-05-04 17:18:02 +0000
commita44744499d8f3df64cc1d15cd6b40b4b0e4a3683 (patch)
tree27621a6ee20cbe8e344ffdc18c05754e67d67bf3 /src/include/gnunet_jsonapi_lib.h
parentca11046195a840932edb04900669a38cd60ae682 (diff)
downloadgnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.tar.gz
gnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.zip
Update jsonapi to current specs, refactor
Diffstat (limited to 'src/include/gnunet_jsonapi_lib.h')
-rw-r--r--src/include/gnunet_jsonapi_lib.h169
1 files changed, 147 insertions, 22 deletions
diff --git a/src/include/gnunet_jsonapi_lib.h b/src/include/gnunet_jsonapi_lib.h
index d4556c174..5535cb2aa 100644
--- a/src/include/gnunet_jsonapi_lib.h
+++ b/src/include/gnunet_jsonapi_lib.h
@@ -25,12 +25,63 @@
25#include "gnunet_rest_lib.h" 25#include "gnunet_rest_lib.h"
26#include "gnunet_json_lib.h" 26#include "gnunet_json_lib.h"
27 27
28#define GNUNET_JSONAPI_KEY_DATA "data"
29
30#define GNUNET_JSONAPI_KEY_ID "id"
31
32#define GNUNET_JSONAPI_KEY_TYPE "type"
33
34#define GNUNET_JSONAPI_KEY_META "meta"
35
36#define GNUNET_JSONAPI_KEY_ATTRIBUTES "attributes"
37
38#define GNUNET_JSONAPI_KEY_CODE "code"
39
40#define GNUNET_JSONAPI_KEY_TITLE "title"
41
42#define GNUNET_JSONAPI_KEY_DETAIL "detail"
43
44#define GNUNET_JSONAPI_KEY_SOURCE "source"
45
46#define GNUNET_JSONAPI_KEY_LINKS "links"
47
48#define GNUNET_JSONAPI_KEY_STATUS "status"
49
50#define GNUNET_JSONAPI_KEY_ERRORS "errors"
28 51
29/* ****************** JSONAPI parsing ******************* */ 52/* ****************** JSONAPI parsing ******************* */
30 53
54struct GNUNET_JSONAPI_Relationship;
55
56struct GNUNET_JSONAPI_Error;
57
31struct GNUNET_JSONAPI_Resource; 58struct GNUNET_JSONAPI_Resource;
32 59
33struct GNUNET_JSONAPI_Object; 60struct GNUNET_JSONAPI_Document;
61
62/**
63 * Specification for parsing a jsonapi relationship.
64 *
65 * @param jsonapi_obj where to store the jsonapi relationship
66 */
67struct GNUNET_JSON_Specification
68GNUNET_JSON_spec_jsonapi_relationship (struct GNUNET_JSONAPI_Relationship **jsonapi_obj);
69
70/**
71 * Specification for parsing a jsonapi error.
72 *
73 * @param jsonapi_obj where to store the jsonapi error
74 */
75struct GNUNET_JSON_Specification
76GNUNET_JSON_spec_jsonapi_error (struct GNUNET_JSONAPI_Error **jsonapi_obj);
77
78/**
79 * Specification for parsing a jsonapi resource.
80 *
81 * @param jsonapi_obj where to store the jsonapi resource
82 */
83struct GNUNET_JSON_Specification
84GNUNET_JSON_spec_jsonapi_resource (struct GNUNET_JSONAPI_Resource **jsonapi_obj);
34 85
35/** 86/**
36 * Specification for parsing a jsonapi object. 87 * Specification for parsing a jsonapi object.
@@ -38,7 +89,58 @@ struct GNUNET_JSONAPI_Object;
38 * @param jsonapi_obj where to store the jsonapi object 89 * @param jsonapi_obj where to store the jsonapi object
39 */ 90 */
40struct GNUNET_JSON_Specification 91struct GNUNET_JSON_Specification
41GNUNET_JSON_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj); 92GNUNET_JSON_spec_jsonapi_document (struct GNUNET_JSONAPI_Document **jsonapi_obj);
93
94/**
95 * Delete a JSON API relationship
96 *
97 * @param res the JSON resource
98 * @param result Pointer where the resource should be stored
99 */
100void
101GNUNET_JSONAPI_relationship_delete (struct GNUNET_JSONAPI_Relationship *rel);
102
103
104/**
105 * Add a JSON API error to document
106 *
107 * @param data The JSON API document to add to
108 * @param res the JSON API error to add
109 * @return the new number of resources
110 */
111void
112GNUNET_JSONAPI_document_error_add (struct GNUNET_JSONAPI_Document *doc,
113 struct GNUNET_JSONAPI_Error *err);
114
115/**
116 * String serialze jsonapi error to json
117 *
118 * @param data the JSON API error
119 * @param result where to store the result
120 * @return GNUNET_SYSERR on error else GNUNET_OK
121 */
122int
123GNUNET_JSONAPI_error_to_json (const struct GNUNET_JSONAPI_Error *err,
124 json_t **result);
125
126/**
127 * Parse json to error object
128 *
129 * @param err_json JSON object
130 * @param[out] err error object
131 * @return GNUNET_OK on success
132 */
133int
134GNUNET_JSONAPI_json_to_error (json_t *err_json,
135 struct GNUNET_JSONAPI_Error **err);
136
137/**
138 * Delete a JSON API error
139 *
140 * @param res the JSON error
141 */
142void
143GNUNET_JSONAPI_error_delete (struct GNUNET_JSONAPI_Error *error);
42 144
43/** 145/**
44 * Create a JSON API resource 146 * Create a JSON API resource
@@ -50,6 +152,29 @@ GNUNET_JSON_spec_jsonapi (struct GNUNET_JSONAPI_Object **jsonapi_obj);
50struct GNUNET_JSONAPI_Resource* 152struct GNUNET_JSONAPI_Resource*
51GNUNET_JSONAPI_resource_new (const char *type, const char *id); 153GNUNET_JSONAPI_resource_new (const char *type, const char *id);
52 154
155
156/**
157 * String serialze jsonapi to json
158 *
159 * @param data the JSON API resource
160 * @param result where to store the result
161 * @return GNUNET_SYSERR on error else GNUNET_OK
162 */
163int
164GNUNET_JSONAPI_resource_to_json (const struct GNUNET_JSONAPI_Resource *res,
165 json_t **result);
166
167/**
168 * Parse json to resource object
169 *
170 * @param res_json JSON object
171 * @param[out] res resource object
172 * @return GNUNET_OK on success
173 */
174int
175GNUNET_JSONAPI_json_to_resource (json_t *res_json,
176 struct GNUNET_JSONAPI_Resource **res);
177
53/** 178/**
54 * Delete a JSON API resource 179 * Delete a JSON API resource
55 * 180 *
@@ -69,9 +194,9 @@ GNUNET_JSONAPI_resource_delete (struct GNUNET_JSONAPI_Resource *resource);
69 * #GNUNET_SYSERR if not 194 * #GNUNET_SYSERR if not
70 */ 195 */
71int 196int
72GNUNET_JSONAPI_resource_add_attr (const struct GNUNET_JSONAPI_Resource *resource, 197GNUNET_JSONAPI_resource_add_attr (struct GNUNET_JSONAPI_Resource *resource,
73 const char* key, 198 const char* key,
74 json_t *json); 199 json_t *json);
75/** 200/**
76 * Read a JSON API attribute 201 * Read a JSON API attribute
77 * 202 *
@@ -81,7 +206,7 @@ GNUNET_JSONAPI_resource_add_attr (const struct GNUNET_JSONAPI_Resource *resource
81 */ 206 */
82json_t* 207json_t*
83GNUNET_JSONAPI_resource_read_attr (const struct GNUNET_JSONAPI_Resource *resource, 208GNUNET_JSONAPI_resource_read_attr (const struct GNUNET_JSONAPI_Resource *resource,
84 const char* key); 209 const char* key);
85 210
86 211
87/** 212/**
@@ -93,7 +218,7 @@ GNUNET_JSONAPI_resource_read_attr (const struct GNUNET_JSONAPI_Resource *resourc
93 */ 218 */
94int 219int
95GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource, 220GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource,
96 const char* id); 221 const char* id);
97 222
98 223
99/** 224/**
@@ -105,7 +230,7 @@ GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource
105 */ 230 */
106int 231int
107GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource, 232GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource,
108 const char* type); 233 const char* type);
109 234
110 235
111/** 236/**
@@ -115,8 +240,8 @@ GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resour
115 * @param id the JSON API resource id 240 * @param id the JSON API resource id
116 * @return a new JSON API resource or NULL on error. 241 * @return a new JSON API resource or NULL on error.
117 */ 242 */
118struct GNUNET_JSONAPI_Object* 243struct GNUNET_JSONAPI_Document*
119GNUNET_JSONAPI_object_new (); 244GNUNET_JSONAPI_document_new ();
120 245
121 246
122/** 247/**
@@ -127,8 +252,8 @@ GNUNET_JSONAPI_object_new ();
127 * @return GNUNET_OK on success 252 * @return GNUNET_OK on success
128 */ 253 */
129int 254int
130GNUNET_JSONAPI_object_parse (const char* data, 255GNUNET_JSONAPI_document_parse (const char* data,
131 struct GNUNET_JSONAPI_Object** obj); 256 struct GNUNET_JSONAPI_Document** obj);
132 257
133 258
134/** 259/**
@@ -139,7 +264,7 @@ GNUNET_JSONAPI_object_parse (const char* data,
139 * @return a new JSON API resource or NULL on error. 264 * @return a new JSON API resource or NULL on error.
140 */ 265 */
141void 266void
142GNUNET_JSONAPI_object_delete (struct GNUNET_JSONAPI_Object *resp); 267GNUNET_JSONAPI_document_delete (struct GNUNET_JSONAPI_Document *resp);
143 268
144/** 269/**
145 * Add a JSON API resource to primary data 270 * Add a JSON API resource to primary data
@@ -149,8 +274,8 @@ GNUNET_JSONAPI_object_delete (struct GNUNET_JSONAPI_Object *resp);
149 * @return the new number of resources 274 * @return the new number of resources
150 */ 275 */
151void 276void
152GNUNET_JSONAPI_object_resource_add (struct GNUNET_JSONAPI_Object *resp, 277GNUNET_JSONAPI_document_resource_add (struct GNUNET_JSONAPI_Document *resp,
153 struct GNUNET_JSONAPI_Resource *res); 278 struct GNUNET_JSONAPI_Resource *res);
154/** 279/**
155 * Get a JSON API object resource count 280 * Get a JSON API object resource count
156 * 281 *
@@ -158,7 +283,7 @@ GNUNET_JSONAPI_object_resource_add (struct GNUNET_JSONAPI_Object *resp,
158 * @return the number of resources 283 * @return the number of resources
159 */ 284 */
160int 285int
161GNUNET_JSONAPI_object_resource_count (struct GNUNET_JSONAPI_Object *resp); 286GNUNET_JSONAPI_document_resource_count (struct GNUNET_JSONAPI_Document *resp);
162 287
163/** 288/**
164 * Get a JSON API object resource num 289 * Get a JSON API object resource num
@@ -168,7 +293,7 @@ GNUNET_JSONAPI_object_resource_count (struct GNUNET_JSONAPI_Object *resp);
168 * @return the resource 293 * @return the resource
169 */ 294 */
170struct GNUNET_JSONAPI_Resource* 295struct GNUNET_JSONAPI_Resource*
171GNUNET_JSONAPI_object_get_resource (struct GNUNET_JSONAPI_Object *resp, int num); 296GNUNET_JSONAPI_document_get_resource (struct GNUNET_JSONAPI_Document *resp, int num);
172 297
173 298
174/** 299/**
@@ -179,8 +304,8 @@ GNUNET_JSONAPI_object_get_resource (struct GNUNET_JSONAPI_Object *resp, int num)
179 * @return the new number of resources 304 * @return the new number of resources
180 */ 305 */
181void 306void
182GNUNET_JSONAPI_data_resource_remove (struct GNUNET_JSONAPI_Object *resp, 307GNUNET_JSONAPI_document_resource_remove (struct GNUNET_JSONAPI_Document *resp,
183 struct GNUNET_JSONAPI_Resource *res); 308 struct GNUNET_JSONAPI_Resource *res);
184 309
185/** 310/**
186 * String serialze jsonapi primary data 311 * String serialze jsonapi primary data
@@ -190,8 +315,8 @@ GNUNET_JSONAPI_data_resource_remove (struct GNUNET_JSONAPI_Object *resp,
190 * @return GNUNET_SYSERR on error else GNUNET_OK 315 * @return GNUNET_SYSERR on error else GNUNET_OK
191 */ 316 */
192int 317int
193GNUNET_JSONAPI_data_serialize (const struct GNUNET_JSONAPI_Object *resp, 318GNUNET_JSONAPI_document_serialize (const struct GNUNET_JSONAPI_Document *resp,
194 char **result); 319 char **result);
195 320
196/** 321/**
197 * Check a JSON API resource id 322 * Check a JSON API resource id
@@ -199,7 +324,7 @@ GNUNET_JSONAPI_data_serialize (const struct GNUNET_JSONAPI_Object *resp,
199 * @param res the JSON resource 324 * @param res the JSON resource
200 * @return the resource id 325 * @return the resource id
201 */ 326 */
202json_t* 327char*
203GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource); 328GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource);
204 329
205 330