Skip to content
Snippets Groups Projects
Commit 8cf2892e authored by clohr's avatar clohr
Browse files

struct json_object

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/branches/version-0.7@2290 b32b6428-25c9-4566-ad07-03861ab6144f
parent a8b6e759
Branches
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@
* cbor2json
*/
struct json_object *xAAL_bytestring2json(cbor_item_t *item) {
json_object *xAAL_bytestring2json(cbor_item_t *item) {
unsigned char *bstr;
size_t len;
......@@ -50,7 +50,7 @@ struct json_object *xAAL_bytestring2json(cbor_item_t *item) {
return json_object_new_string(uuid);
} else {
struct json_object *jobj;
json_object *jobj;
base64_encodestate b64_state;
char *b64;
int b64_len;
......@@ -68,7 +68,7 @@ struct json_object *xAAL_bytestring2json(cbor_item_t *item) {
}
struct json_object *xAAL_cbor2json_ex(cbor_item_t *item, unsigned maxdepth) {
json_object *xAAL_cbor2json_ex(cbor_item_t *item, unsigned maxdepth) {
if (!maxdepth--)
return NULL;
switch ( cbor_typeof(item) ) {
......@@ -81,12 +81,12 @@ struct json_object *xAAL_cbor2json_ex(cbor_item_t *item, unsigned maxdepth) {
case CBOR_TYPE_STRING: {
size_t len;
char *str = xAAL_cbor_string_dup(item, &len);
struct json_object *jobj = json_object_new_string_len(str, len);
json_object *jobj = json_object_new_string_len(str, len);
free(str);
return jobj; }
case CBOR_TYPE_ARRAY: {
size_t i, len = cbor_array_size(item);
struct json_object *jobj = json_object_new_array();
json_object *jobj = json_object_new_array();
for (i=0; i < len; i++)
json_object_array_add(jobj, xAAL_cbor2json_ex(cbor_move(cbor_array_get(item, i)), maxdepth));
return jobj; }
......@@ -94,7 +94,7 @@ struct json_object *xAAL_cbor2json_ex(cbor_item_t *item, unsigned maxdepth) {
char *key;
size_t i, len, sz = cbor_map_size(item);
struct cbor_pair *map = cbor_map_handle(item);
struct json_object *jobj = json_object_new_object();
json_object *jobj = json_object_new_object();
for (i=0; i < sz; i++) {
key = xAAL_cbor_string_dup(map[i].key, &len);
if ( key ) {
......@@ -130,7 +130,7 @@ struct json_object *xAAL_cbor2json_ex(cbor_item_t *item, unsigned maxdepth) {
}
}
struct json_object *xAAL_cbor2json(cbor_item_t *item) {
json_object *xAAL_cbor2json(cbor_item_t *item) {
return xAAL_cbor2json_ex(item, MAXDEPTH);
}
......@@ -140,7 +140,7 @@ struct json_object *xAAL_cbor2json(cbor_item_t *item) {
* json2cbor
*/
cbor_item_t *xAAL_jsonstring2cbor(struct json_object *jobj) {
cbor_item_t *xAAL_jsonstring2cbor(json_object *jobj) {
const char *str = json_object_get_string(jobj);
int len = json_object_get_string_len(jobj);
uuid_t uuid;
......@@ -152,7 +152,7 @@ cbor_item_t *xAAL_jsonstring2cbor(struct json_object *jobj) {
}
cbor_item_t *xAAL_jsonb64_to_bytestring(struct json_object *jobj) {
cbor_item_t *xAAL_jsonb64_to_bytestring(json_object *jobj) {
const char *str = json_object_get_string(jobj);
int sz, len = json_object_get_string_len(jobj);
base64_decodestate b64_state;
......@@ -164,7 +164,7 @@ cbor_item_t *xAAL_jsonb64_to_bytestring(struct json_object *jobj) {
}
cbor_item_t *xAAL_json2cbor_ex(struct json_object *jobj, unsigned maxdepth) {
cbor_item_t *xAAL_json2cbor_ex(json_object *jobj, unsigned maxdepth) {
if (!maxdepth--)
return cbor_new_undef();
switch ( json_object_get_type(jobj) ) {
......@@ -194,6 +194,6 @@ cbor_item_t *xAAL_json2cbor_ex(struct json_object *jobj, unsigned maxdepth) {
return cbor_new_undef();
}
cbor_item_t *xAAL_json2cbor(struct json_object *jobj) {
cbor_item_t *xAAL_json2cbor(json_object *jobj) {
return xAAL_json2cbor_ex(jobj, MAXDEPTH);
}
......@@ -62,7 +62,7 @@ void cbor_to_json(char *file_in, char *file_out) {
exit(EXIT_FAILURE);
}
struct json_object *jitem;
json_object *jitem;
jitem = xAAL_cbor2json(citem);
cbor_decref(&citem);
munmap(map, sz);
......@@ -78,7 +78,7 @@ void cbor_to_json(char *file_in, char *file_out) {
void json_to_cbor(char *file_in, char *file_out) {
struct json_object *jitem;
json_object *jitem;
jitem = json_object_from_file(file_in);
if (json_object_is_type(jitem, json_type_null)) {
perror(file_in);
......
......@@ -33,11 +33,11 @@
/* Transcode a cbor bytestring into json string
* Note: bytestring[16] are encoded as uuid,
* other data are base64 encoded */
struct json_object *xAAL_bytestring2json(cbor_item_t *item);
json_object *xAAL_bytestring2json(cbor_item_t *item);
/* Do its best to transcode cbor data into json
* Strings are converted as above, tags are ignored */
struct json_object *xAAL_cbor2json(cbor_item_t *item);
json_object *xAAL_cbor2json(cbor_item_t *item);
/*
......@@ -47,14 +47,14 @@ struct json_object *xAAL_cbor2json(cbor_item_t *item);
/* Transcode a json string into cbor
* Note: if the string represents an uuid, parse it and return a bytestring[16],
* else return a cbor string */
cbor_item_t *xAAL_jsonstring2cbor(struct json_object *jobj);
cbor_item_t *xAAL_jsonstring2cbor(json_object *jobj);
/* Do its best to transcode json data into cbor
* Strings are converted as above */
cbor_item_t *xAAL_json2cbor(struct json_object *jobj);
cbor_item_t *xAAL_json2cbor(json_object *jobj);
/* Explicitly transcode a base64 data json string into a cbor bytestring */
cbor_item_t *xAAL_jsonb64_to_bytestring(struct json_object *jobj);
cbor_item_t *xAAL_jsonb64_to_bytestring(json_object *jobj);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment