From d8953ab6bc645a62475c8bb661713a5aa0d792d2 Mon Sep 17 00:00:00 2001 From: Sourav Moitra Date: Fri, 22 Nov 2024 22:33:14 +0530 Subject: [PATCH 1/2] Switch all jtree to tree Signed-off-by: Sourav Moitra --- src/ocispec/sources.py | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ocispec/sources.py b/src/ocispec/sources.py index e27ac520..9950a1e1 100755 --- a/src/ocispec/sources.py +++ b/src/ocispec/sources.py @@ -55,11 +55,11 @@ def parse_map_string_obj(obj, c_file, prefix, obj_typename): childname = child.subtypname else: childname = helpers.get_prefixed_name(child.name, prefix) - c_file.append(' if (json_is_object(jtree))\n') + c_file.append(' if (json_is_object(tree))\n') c_file.append(' {\n') c_file.append(' size_t i;\n') - c_file.append(' size_t len = json_object_size(jtree);\n') - c_file.append(' jansson_object_keys_values *kvobj = json_object_to_keys_values(jtree);\n') + c_file.append(' size_t len = json_object_size(tree);\n') + c_file.append(' jansson_object_keys_values *kvobj = json_object_to_keys_values(tree);\n') c_file.append(' const char **keys = kvobj->keys;\n') c_file.append(' json_t *values = kvobj->values;\n') c_file.append(' ret->len = len;\n') @@ -92,7 +92,7 @@ def parse_obj_type_array(obj, c_file, prefix, obj_typename): typename = helpers.get_name_substr(obj.name, prefix) c_file.append(' do\n') c_file.append(' {\n') - c_file.append(f' json_t *tmp = json_object_get (jtree, "{obj.origname}");\n') + c_file.append(f' json_t *tmp = json_object_get (tree, "{obj.origname}");\n') c_file.append(f' jansson_array_values *jarray = json_array_to_struct(tmp);') c_file.append(' if (tmp != NULL && jarray != NULL)\n') c_file.append(' {\n') @@ -162,7 +162,7 @@ def parse_obj_type_array(obj, c_file, prefix, obj_typename): else: c_file.append(' do\n') c_file.append(' {\n') - c_file.append(f' json_t *tmp = json_object_get (jtree, "{obj.origname}");\n') + c_file.append(f' json_t *tmp = json_object_get (tree, "{obj.origname}");\n') c_file.append(' if (tmp != NULL && (tmp) != NULL)\n') c_file.append(' {\n') c_file.append(' size_t i;\n') @@ -207,35 +207,35 @@ def parse_obj_type(obj, c_file, prefix, obj_typename): if obj.typ == 'string': c_file.append(' do\n') c_file.append(' {\n') - read_val_generator(c_file, 2, f'json_object_get (jtree, "{obj.origname}")', \ + read_val_generator(c_file, 2, f'json_object_get (tree, "{obj.origname}")', \ f"ret->{obj.fixname}", obj.typ, obj.origname, obj_typename) c_file.append(' }\n') c_file.append(' while (0);\n') elif helpers.judge_data_type(obj.typ): c_file.append(' do\n') c_file.append(' {\n') - read_val_generator(c_file, 2, f'json_object_get (jtree, "{obj.origname}")', \ + read_val_generator(c_file, 2, f'json_object_get (tree, "{obj.origname}")', \ f"ret->{obj.fixname}", obj.typ, obj.origname, obj_typename) c_file.append(' }\n') c_file.append(' while (0);\n') elif helpers.judge_data_pointer_type(obj.typ): c_file.append(' do\n') c_file.append(' {\n') - read_val_generator(c_file, 2, f'json_object_get (jtree, "{obj.origname}")', \ + read_val_generator(c_file, 2, f'json_object_get (tree, "{obj.origname}")', \ f"ret->{obj.fixname}", obj.typ, obj.origname, obj_typename) c_file.append(' }\n') c_file.append(' while (0);\n') if obj.typ == 'boolean': c_file.append(' do\n') c_file.append(' {\n') - read_val_generator(c_file, 2, f'json_object_get (jtree, "{obj.origname}")', \ + read_val_generator(c_file, 2, f'json_object_get (tree, "{obj.origname}")', \ f"ret->{obj.fixname}", obj.typ, obj.origname, obj_typename) c_file.append(' }\n') c_file.append(' while (0);\n') if obj.typ == 'booleanPointer': c_file.append(' do\n') c_file.append(' {\n') - read_val_generator(c_file, 2, f'json_object_get (jtree, "{obj.origname}")', \ + read_val_generator(c_file, 2, f'json_object_get (tree, "{obj.origname}")', \ f"ret->{obj.fixname}", obj.typ, obj.origname, obj_typename) c_file.append(' }\n') c_file.append(' while (0);\n') @@ -245,7 +245,7 @@ def parse_obj_type(obj, c_file, prefix, obj_typename): else: typename = helpers.get_prefixed_name(obj.name, prefix) c_file.append( - f' ret->{obj.fixname} = make_{typename} (json_object_get (jtree, "{obj.origname}"), ctx, err);\n') + f' ret->{obj.fixname} = make_{typename} (json_object_get (tree, "{obj.origname}"), ctx, err);\n') c_file.append(f" if (ret->{obj.fixname} == NULL && *err != 0)\n") c_file.append(" return NULL;\n") elif obj.typ == 'array': @@ -253,7 +253,7 @@ def parse_obj_type(obj, c_file, prefix, obj_typename): elif helpers.valid_basic_map_name(obj.typ): c_file.append(' do\n') c_file.append(' {\n') - c_file.append(f' json_t *tmp = json_object_get (jtree, "{obj.origname}");\n') + c_file.append(f' json_t *tmp = json_object_get (tree, "{obj.origname}");\n') c_file.append(' if (tmp != NULL)\n') c_file.append(' {\n') c_file.append(f' ret->{obj.fixname} = make_{helpers.make_basic_map_name(obj.typ)} (tmp, ctx, err);\n') @@ -298,18 +298,18 @@ def parse_obj_arr_obj(obj, c_file, prefix, obj_typename): condition = ", ".join([f'"{i.origname}"' for i in obj.children]) c_file.append(""" - if (json_is_object(jtree)) + if (json_is_object(tree)) { if (ctx->options & OPT_PARSE_FULLKEY) { - if (jtree == NULL) + if (tree == NULL) return NULL; } """ f"const char *excluded[] = {'{'}{condition}{'}'};" """ - size_t len = json_object_size(jtree); - json_t *resi = copy_unmatched_fields(jtree, excluded, len); + size_t len = json_object_size(tree); + json_t *resi = copy_unmatched_fields(tree, excluded, len); size_t resilen = json_object_size(resi); @@ -337,12 +337,12 @@ def parse_json_to_c(obj, c_file, prefix): if objs is None or obj.subtypname: return c_file.append(f"define_cleaner_function ({typename} *, free_{typename})\n") - c_file.append(f"{typename} *\nmake_{typename} (json_t *jtree, const struct parser_context *ctx, parser_error *err)\n") + c_file.append(f"{typename} *\nmake_{typename} (json_t *tree, const struct parser_context *ctx, parser_error *err)\n") c_file.append("{\n") c_file.append(f" __auto_cleanup(free_{typename}) {typename} *ret = NULL;\n") c_file.append(" *err = NULL;\n") c_file.append(" (void) ctx; /* Silence compiler warning. */\n") - c_file.append(" if (jtree == NULL)\n") + c_file.append(" if (tree == NULL)\n") c_file.append(" return NULL;\n") c_file.append(" ret = calloc (1, sizeof (*ret));\n") c_file.append(" if (ret == NULL)\n") @@ -797,7 +797,7 @@ def read_val_generator(c_file, level, src, dest, typ, keyname, obj_typename): c_file.append(f'{" " * (level)} }}\n') c_file.append(f"{' ' * level}else\n") c_file.append(f'{" " * (level)} {{\n') - c_file.append(f'{" " * (level + 1)}val = json_object_get (jtree, "{keyname}");\n') + c_file.append(f'{" " * (level + 1)}val = json_object_get (tree, "{keyname}");\n') c_file.append(f"{' ' * (level + 1)}if (val != NULL)\n") c_file.append(f'{" " * (level + 1)} {{\n') c_file.append(f"{' ' * (level + 2)}{dest} = calloc (1, sizeof (bool));\n") @@ -1208,17 +1208,17 @@ def get_c_epilog_for_array_make_parse(c_file, prefix, typ, obj): c_file.append(f"\ndefine_cleaner_function ({typename} *, free_{typename})\n" + f"{typename}\n" + - f"*make_{typename} (json_t *jtree, const struct parser_context *ctx, parser_error *err)\n" + + f"*make_{typename} (json_t *tree, const struct parser_context *ctx, parser_error *err)\n" + "{\n" + f" __auto_cleanup(free_{typename}) {typename} *ptr = NULL;\n" + f" size_t i, alen;\n" + f" "+ f" (void) ctx;\n" + f" "+ - f" if (jtree == NULL || err == NULL || !json_is_array (jtree))\n" + + f" if (tree == NULL || err == NULL || !json_is_array (tree))\n" + f" return NULL;\n" + f" *err = NULL;\n" + - f" alen = json_array_size (jtree);\n" + + f" alen = json_array_size (tree);\n" + f" if (alen == 0)\n" + f" return NULL;\n" + f" ptr = calloc (1, sizeof ({typename}));\n" + @@ -1238,7 +1238,7 @@ def get_c_epilog_for_array_make_parse(c_file, prefix, typ, obj): c_file.append("""\n for (i = 0; i < alen; i++) { - json_t *work = &json_array_to_struct (jtree)->values[i]; + json_t *work = &json_array_to_struct (tree)->values[i]; """) if obj.subtypobj or obj.subtyp == 'object': @@ -1266,12 +1266,12 @@ def get_c_epilog_for_array_make_parse(c_file, prefix, typ, obj): c_file.append(" return NULL;\n") elif obj.subtyp == 'byte': if obj.doublearray: - c_file.append(' char *str = YAJL_GET_STRING (work);\n') + c_file.append(' char *str = json_string_value (work);\n') c_file.append(' ptr->items[j] = (uint8_t *)strdup (str ? str : "");\n') c_file.append(' if (ptr->items[j] == NULL)\n') c_file.append(" return NULL;\n") else: - c_file.append(' char *str = json_string_value (jtree);\n') + c_file.append(' char *str = json_string_value (tree);\n') c_file.append(' memcpy(ptr->items, str ? str : "", strlen(str ? str : ""));\n') c_file.append(' break;\n') else: From 7e8fb07d25b1ee8c901ab3c628d4b1c2a390ed49 Mon Sep 17 00:00:00 2001 From: Sourav Moitra Date: Tue, 26 Nov 2024 21:19:40 +0530 Subject: [PATCH 2/2] Converted json generation using jansson and removed yajl imports Signed-off-by: Sourav Moitra --- src/ocispec/headers.py | 6 +- src/ocispec/json_common.c | 1170 +------------------------------------ src/ocispec/json_common.h | 71 +-- src/ocispec/sources.py | 357 ++++------- tests/test-1.c | 2 +- tests/test-10.c | 14 +- tests/test-11.c | 2 +- tests/test-3.c | 2 +- tests/test-4.c | 2 +- tests/test-5.c | 2 +- tests/test-6.c | 2 +- tests/test-7.c | 2 +- tests/test-8.c | 2 +- tests/test-9.c | 2 +- 14 files changed, 169 insertions(+), 1467 deletions(-) diff --git a/src/ocispec/headers.py b/src/ocispec/headers.py index 34b04746..8252a7ab 100755 --- a/src/ocispec/headers.py +++ b/src/ocispec/headers.py @@ -174,7 +174,7 @@ def append_type_c_header(obj, header, prefix): header.append(f"void free_{typename} ({typename} *ptr);\n\n") header.append(f"{typename} *clone_{typename} ({typename} *src);\n") header.append(f"{typename} *make_{typename} (json_t *jtree, const struct parser_context *ctx, parser_error *err);\n\n") - header.append(f"yajl_gen_status gen_{typename} (yajl_gen g, const {typename} *ptr, const struct parser_context *ctx, parser_error *err);\n\n") + header.append(f"int gen_{typename} (json_t *root, const {typename} *ptr, parser_error *err);\n\n") def header_reflect_top_array(obj, prefix, header): c_typ = helpers.get_prefixed_pointer(obj.name, obj.subtyp, prefix) or \ @@ -206,7 +206,7 @@ def header_reflect_top_array(obj, prefix, header): header.append(f"{typename} *{typename}_parse_data(const char *jsondata, const struct "\ "parser_context *ctx, parser_error *err);\n\n") header.append(f"char *{typename}_generate_json(const {typename} *ptr, "\ - "const struct parser_context *ctx, parser_error *err);\n\n") + "parser_error *err);\n\n") def header_reflect(structs, schema_info, header): ''' @@ -239,7 +239,7 @@ def header_reflect(structs, schema_info, header): "parser_error *err);\n\n") header.append(f"{prefix} *{prefix}_parse_data (const char *jsondata, const struct parser_context *ctx, "\ "parser_error *err);\n\n") - header.append(f"char *{prefix}_generate_json (const {prefix} *ptr, const struct parser_context *ctx, "\ + header.append(f"char *{prefix}_generate_json (const {prefix} *ptr,"\ "parser_error *err);\n\n") elif toptype == 'array': header_reflect_top_array(structs[length - 1], prefix, header) diff --git a/src/ocispec/json_common.c b/src/ocispec/json_common.c index 0ab01c63..6d56b4ff 100644 --- a/src/ocispec/json_common.c +++ b/src/ocispec/json_common.c @@ -10,168 +10,6 @@ #define MAX_NUM_STR_LEN 21 -static yajl_gen_status gen_yajl_val (yajl_val obj, yajl_gen g, parser_error *err); - -static yajl_gen_status -gen_yajl_val_obj (yajl_val obj, yajl_gen g, parser_error *err) -{ - size_t i; - yajl_gen_status stat = yajl_gen_status_ok; - - stat = yajl_gen_map_open (g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - - for (i = 0; i < obj->u.object.len; i++) - { - stat = yajl_gen_string (g, (const unsigned char *) obj->u.object.keys[i], strlen (obj->u.object.keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = gen_yajl_val (obj->u.object.values[i], g, err); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close (g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - return yajl_gen_status_ok; -} - -static yajl_gen_status -gen_yajl_val_array (yajl_val arr, yajl_gen g, parser_error *err) -{ - size_t i; - yajl_gen_status stat = yajl_gen_status_ok; - - stat = yajl_gen_array_open (g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - - for (i = 0; i < arr->u.array.len; i++) - { - stat = gen_yajl_val (arr->u.array.values[i], g, err); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_array_close (g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - return yajl_gen_status_ok; -} - -static yajl_gen_status -gen_yajl_val (yajl_val obj, yajl_gen g, parser_error *err) -{ - yajl_gen_status __stat = yajl_gen_status_ok; - char *__tstr; - - switch (obj->type) - { - case yajl_t_string: - __tstr = YAJL_GET_STRING (obj); - if (__tstr == NULL) - { - return __stat; - } - __stat = yajl_gen_string (g, (const unsigned char *) __tstr, strlen (__tstr)); - if (yajl_gen_status_ok != __stat) - GEN_SET_ERROR_AND_RETURN (__stat, err); - return yajl_gen_status_ok; - case yajl_t_number: - __tstr = YAJL_GET_NUMBER (obj); - if (__tstr == NULL) - { - return __stat; - } - __stat = yajl_gen_number (g, __tstr, strlen (__tstr)); - if (yajl_gen_status_ok != __stat) - GEN_SET_ERROR_AND_RETURN (__stat, err); - return yajl_gen_status_ok; - case yajl_t_object: - return gen_yajl_val_obj (obj, g, err); - case yajl_t_array: - return gen_yajl_val_array (obj, g, err); - case yajl_t_true: - return yajl_gen_bool (g, true); - case yajl_t_false: - return yajl_gen_bool (g, false); - case yajl_t_null: - return yajl_gen_null(g); - case yajl_t_any: - return __stat; - } - return __stat; -} - -yajl_gen_status -gen_yajl_object_residual (json_t *j, yajl_gen g, parser_error *err) -{ - size_t i; - yajl_val obj = json_to_yajl(j); - yajl_gen_status stat = yajl_gen_status_ok; - - for (i = 0; i < obj->u.object.len; i++) - { - if (obj->u.object.keys[i] == NULL) - { - continue; - } - stat = yajl_gen_string (g, (const unsigned char *) obj->u.object.keys[i], strlen (obj->u.object.keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = gen_yajl_val (obj->u.object.values[i], g, err); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - return yajl_gen_status_ok; -} - -yajl_gen_status -map_uint (void *ctx, long long unsigned int num) -{ - char numstr[MAX_NUM_STR_LEN]; - int ret; - - ret = snprintf (numstr, sizeof (numstr), "%llu", num); - if (ret < 0 || (size_t) ret >= sizeof (numstr)) - return yajl_gen_in_error_state; - return yajl_gen_number ((yajl_gen) ctx, (const char *) numstr, strlen (numstr)); -} - -yajl_gen_status -map_int (void *ctx, long long int num) -{ - char numstr[MAX_NUM_STR_LEN]; - int ret; - - ret = snprintf (numstr, sizeof (numstr), "%lld", num); - if (ret < 0 || (size_t) ret >= sizeof (numstr)) - return yajl_gen_in_error_state; - return yajl_gen_number ((yajl_gen) ctx, (const char *) numstr, strlen (numstr)); -} - -bool -json_gen_init (yajl_gen *g, const struct parser_context *ctx) -{ - *g = yajl_gen_alloc (NULL); - if (NULL == *g) - return false; - - yajl_gen_config (*g, yajl_gen_beautify, (int) (! (ctx->options & OPT_GEN_SIMPLIFY))); - yajl_gen_config (*g, yajl_gen_validate_utf8, (int) (! (ctx->options & OPT_GEN_NO_VALIDATE_UTF8))); - return true; -} - -yajl_val -get_val (yajl_val tree, const char *name, yajl_type type) -{ - const char *path[] = { name, NULL }; - return yajl_tree_get (tree, path, type); -} - char * safe_strdup (const char *src) { @@ -197,264 +35,6 @@ safe_malloc (size_t size) return ret; } -int -common_safe_double (const char *numstr, double *converted) -{ - char *err_str = NULL; - double d; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - d = strtod (numstr, &err_str); - if (errno > 0) - return -errno; - - if (err_str == NULL || err_str == numstr || *err_str != '\0') - return -EINVAL; - - *converted = d; - return 0; -} - -int -common_safe_uint8 (const char *numstr, uint8_t *converted) -{ - char *err = NULL; - unsigned long int uli; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - uli = strtoul (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (uli > UINT8_MAX) - return -ERANGE; - - *converted = (uint8_t) uli; - return 0; -} - -int -common_safe_uint16 (const char *numstr, uint16_t *converted) -{ - char *err = NULL; - unsigned long int uli; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - uli = strtoul (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (uli > UINT16_MAX) - return -ERANGE; - - *converted = (uint16_t) uli; - return 0; -} - -int -common_safe_uint32 (const char *numstr, uint32_t *converted) -{ - char *err = NULL; - unsigned long long int ull; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - ull = strtoull (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (ull > UINT32_MAX) - return -ERANGE; - - *converted = (uint32_t) ull; - return 0; -} - -int -common_safe_uint64 (const char *numstr, uint64_t *converted) -{ - char *err = NULL; - unsigned long long int ull; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - ull = strtoull (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - *converted = (uint64_t) ull; - return 0; -} - -int -common_safe_uint (const char *numstr, unsigned int *converted) -{ - char *err = NULL; - unsigned long long int ull; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - ull = strtoull (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (ull > UINT_MAX) - return -ERANGE; - - *converted = (unsigned int) ull; - return 0; -} - -int -common_safe_int8 (const char *numstr, int8_t *converted) -{ - char *err = NULL; - long int li; - - if (numstr == NULL) - { - return -EINVAL; - } - - errno = 0; - li = strtol (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (li > INT8_MAX || li < INT8_MIN) - return -ERANGE; - - *converted = (int8_t) li; - return 0; -} - -int -common_safe_int16 (const char *numstr, int16_t *converted) -{ - char *err = NULL; - long int li; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - li = strtol (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (li > INT16_MAX || li < INT16_MIN) - return -ERANGE; - - *converted = (int16_t) li; - return 0; -} - -int -common_safe_int32 (const char *numstr, int32_t *converted) -{ - char *err = NULL; - long long int lli; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - lli = strtol (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (lli > INT32_MAX || lli < INT32_MIN) - - return -ERANGE; - - *converted = (int32_t) lli; - return 0; -} - -int -common_safe_int64 (const char *numstr, int64_t *converted) -{ - char *err = NULL; - long long int lli; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - lli = strtoll (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - *converted = (int64_t) lli; - return 0; -} - -int -common_safe_int (const char *numstr, int *converted) -{ - char *err = NULL; - long long int lli; - - if (numstr == NULL) - return -EINVAL; - - errno = 0; - lli = strtol (numstr, &err, 0); - if (errno > 0) - return -errno; - - if (err == NULL || err == numstr || *err != '\0') - return -EINVAL; - - if (lli > INT_MAX || lli < INT_MIN) - return -ERANGE; - - *converted = (int) lli; - return 0; -} - /* * This function converts double to int * Input: double d, int *converted @@ -635,47 +215,6 @@ json_double_to_double (double d, double *converted) return 0; } - -yajl_gen_status -gen_json_map_int_int (void *ctx, const json_map_int_int *map, const struct parser_context *ptx, parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - for (i = 0; i < len; i++) - { - char numstr[MAX_NUM_STR_LEN]; - int nret; - nret = snprintf (numstr, sizeof (numstr), "%lld", (long long int) map->keys[i]); - if (nret < 0 || (size_t) nret >= sizeof (numstr)) - { - if (! *err) - *err = strdup ("Error to print string"); - return yajl_gen_in_error_state; - } - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) numstr, strlen (numstr)); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = map_int (g, map->values[i]); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; -} - void free_json_map_int_int (json_map_int_int *map) { @@ -691,85 +230,6 @@ free_json_map_int_int (json_map_int_int *map) define_cleaner_function (json_map_int_int *, free_json_map_int_int) -json_map_int_int * -make_json_map_int_int (yajl_val src, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (free_json_map_int_int) json_map_int_int *ret = NULL; - size_t i; - size_t len; - - (void) ctx; /* Silence compiler warning. */ - - if (src == NULL || YAJL_GET_OBJECT (src) == NULL) - return NULL; - - len = YAJL_GET_OBJECT_NO_CHECK (src)->len; - ret = calloc (1, sizeof (*ret)); - if (ret == NULL) - return NULL; - - ret->len = 0; - ret->keys = calloc (len + 1, sizeof (int)); - if (ret->keys == NULL) - { - return NULL; - } - - ret->values = calloc (len + 1, sizeof (int)); - if (ret->values == NULL) - { - return NULL; - } - - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT_NO_CHECK (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT_NO_CHECK (src)->values[i]; - - ret->keys[i] = 0; - ret->values[i] = 0; - ret->len = i + 1; - - if (srckey != NULL) - { - int invalid = common_safe_int (srckey, &(ret->keys[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid key '%s' with type 'int': %s", srckey, strerror (-invalid)) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - - if (srcval != NULL) - { - int invalid; - if (! YAJL_IS_NUMBER (srcval)) - { - if (*err == NULL && asprintf (err, "Invalid value with type 'int' for key '%s'", srckey) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - invalid = common_safe_int (YAJL_GET_NUMBER (srcval), &(ret->values[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror (-invalid)) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - } - return move_ptr (ret); -} - int append_json_map_int_int (json_map_int_int *map, int key, int val) { @@ -811,46 +271,6 @@ append_json_map_int_int (json_map_int_int *map, int key, int val) return 0; } -yajl_gen_status -gen_json_map_int_bool (void *ctx, const json_map_int_bool *map, const struct parser_context *ptx, parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - for (i = 0; i < len; i++) - { - char numstr[MAX_NUM_STR_LEN]; - int nret; - nret = snprintf (numstr, sizeof (numstr), "%lld", (long long int) map->keys[i]); - if (nret < 0 || (size_t) nret >= sizeof (numstr)) - { - if (! *err) - *err = strdup ("Error to print string"); - return yajl_gen_in_error_state; - } - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) numstr, strlen (numstr)); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = yajl_gen_bool ((yajl_gen) g, (int) (map->values[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; -} - void free_json_map_int_bool (json_map_int_bool *map) { @@ -872,74 +292,6 @@ free_json_map_int_bool (json_map_int_bool *map) define_cleaner_function (json_map_int_bool *, free_json_map_int_bool) -json_map_int_bool * -make_json_map_int_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (free_json_map_int_bool) json_map_int_bool *ret = NULL; - size_t i; - size_t len; - - (void) ctx; /* Silence compiler warning. */ - - if (src == NULL || YAJL_GET_OBJECT (src) == NULL) - return NULL; - - len = YAJL_GET_OBJECT_NO_CHECK (src)->len; - ret = calloc (1, sizeof (*ret)); - if (ret == NULL) - return NULL; - ret->len = 0; - ret->keys = calloc (len + 1, sizeof (int)); - if (ret->keys == NULL) - { - return NULL; - } - ret->values = calloc (len + 1, sizeof (bool)); - if (ret->values == NULL) - { - return NULL; - } - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT_NO_CHECK (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT_NO_CHECK (src)->values[i]; - - ret->keys[i] = 0; - ret->values[i] = false; - ret->len = i + 1; - - if (srckey != NULL) - { - int invalid = common_safe_int (srckey, &(ret->keys[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid key '%s' with type 'int': %s", srckey, strerror (-invalid)) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - - if (srcval != NULL) - { - if (YAJL_IS_TRUE (srcval)) - ret->values[i] = true; - else if (YAJL_IS_FALSE (srcval)) - ret->values[i] = false; - else - { - if (*err == NULL && asprintf (err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - } - return move_ptr (ret); -} int append_json_map_int_bool (json_map_int_bool *map, int key, bool val) @@ -966,61 +318,20 @@ append_json_map_int_bool (json_map_int_bool *map, int key, bool val) if (map->len) { - (void) memcpy (keys, map->keys, map->len * sizeof (int)); - (void) memcpy (vals, map->values, map->len * sizeof (bool)); - } - free (map->keys); - map->keys = keys; - keys = NULL; - free (map->values); - map->values = vals; - vals = NULL; - map->keys[map->len] = key; - map->values[map->len] = val; - - map->len++; - return 0; -} - -yajl_gen_status -gen_json_map_int_string (void *ctx, const json_map_int_string *map, const struct parser_context *ptx, parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - for (i = 0; i < len; i++) - { - char numstr[MAX_NUM_STR_LEN]; - int nret; - nret = snprintf (numstr, sizeof (numstr), "%lld", (long long int) map->keys[i]); - if (nret < 0 || (size_t) nret >= sizeof (numstr)) - { - if (! *err) - *err = strdup ("Error to print string"); - return yajl_gen_in_error_state; - } - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) numstr, strlen (numstr)); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->values[i]), strlen (map->values[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); + (void) memcpy (keys, map->keys, map->len * sizeof (int)); + (void) memcpy (vals, map->values, map->len * sizeof (bool)); } + free (map->keys); + map->keys = keys; + keys = NULL; + free (map->values); + map->values = vals; + vals = NULL; + map->keys[map->len] = key; + map->values[map->len] = val; - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; + map->len++; + return 0; } void @@ -1045,78 +356,6 @@ free_json_map_int_string (json_map_int_string *map) define_cleaner_function (json_map_int_string *, free_json_map_int_string) -json_map_int_string * -make_json_map_int_string (yajl_val src, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (free_json_map_int_string) json_map_int_string *ret = NULL; - size_t i; - size_t len; - - if (src == NULL || YAJL_GET_OBJECT (src) == NULL) - return NULL; - - (void) ctx; /* Silence compiler warning. */ - - len = YAJL_GET_OBJECT_NO_CHECK (src)->len; - - ret = calloc (1, sizeof (*ret)); - if (ret == NULL) - return NULL; - - ret->len = 0; - ret->keys = calloc (len + 1, sizeof (int)); - if (ret->keys == NULL) - { - return NULL; - } - - ret->values = calloc (len + 1, sizeof (char *)); - if (ret->values == NULL) - { - return NULL; - } - - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT_NO_CHECK (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT_NO_CHECK (src)->values[i]; - - ret->keys[i] = 0; - ret->values[i] = NULL; - ret->len = i + 1; - - if (srckey != NULL) - { - int invalid; - invalid = common_safe_int (srckey, &(ret->keys[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid key '%s' with type 'int': %s", srckey, strerror (-invalid)) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - - if (srcval != NULL) - { - if (! YAJL_IS_STRING (srcval)) - { - if (*err == NULL && asprintf (err, "Invalid value with type 'string' for key '%s'", srckey) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - char *str = YAJL_GET_STRING_NO_CHECK (srcval); - ret->values[i] = strdup (str ? str : ""); - } - } - return move_ptr (ret); -} - int append_json_map_int_string (json_map_int_string *map, int key, const char *val) { @@ -1153,36 +392,6 @@ append_json_map_int_string (json_map_int_string *map, int key, const char *val) return 0; } -yajl_gen_status -gen_json_map_string_int (void *ctx, const json_map_string_int *map, const struct parser_context *ptx, parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - for (i = 0; i < len; i++) - { - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->keys[i]), strlen (map->keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = map_int (g, map->values[i]); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; -} void free_json_map_string_int (json_map_string_int *map) @@ -1205,79 +414,6 @@ free_json_map_string_int (json_map_string_int *map) define_cleaner_function (json_map_string_int *, free_json_map_string_int) -json_map_string_int * -make_json_map_string_int (yajl_val src, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (free_json_map_string_int) json_map_string_int *ret = NULL; - size_t i; - size_t len; - - (void) ctx; /* Silence compiler warning. */ - - if (src == NULL || YAJL_GET_OBJECT (src) == NULL) - return NULL; - - len = YAJL_GET_OBJECT_NO_CHECK (src)->len; - ret = calloc (1, sizeof (*ret)); - if (ret == NULL) - { - *(err) = strdup ("error allocating memory"); - return NULL; - } - ret->len = 0; - ret->keys = calloc (len + 1, sizeof (char *)); - if (ret->keys == NULL) - { - *(err) = strdup ("error allocating memory"); - return NULL; - } - ret->values = calloc (len + 1, sizeof (int)); - if (ret->values == NULL) - { - *(err) = strdup ("error allocating memory"); - return NULL; - } - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT_NO_CHECK (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT_NO_CHECK (src)->values[i]; - - ret->keys[i] = NULL; - ret->values[i] = 0; - ret->len = i + 1; - - ret->keys[i] = strdup (srckey ? srckey : ""); - if (ret->keys[i] == NULL) - { - *(err) = strdup ("error allocating memory"); - return NULL; - } - - if (srcval != NULL) - { - int invalid; - if (! YAJL_IS_NUMBER (srcval)) - { - if (*err == NULL && asprintf (err, "Invalid value with type 'int' for key '%s'", srckey) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - invalid = common_safe_int (YAJL_GET_NUMBER (srcval), &(ret->values[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror (-invalid)) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - } - return move_ptr (ret); -} int append_json_map_string_int (json_map_string_int *map, const char *key, int val) @@ -1313,38 +449,6 @@ append_json_map_string_int (json_map_string_int *map, const char *key, int val) return 0; } -yajl_gen_status -gen_json_map_string_int64 (void *ctx, const json_map_string_int64 *map, const struct parser_context *ptx, - parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - - for (i = 0; i < len; i++) - { - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->keys[i]), strlen (map->keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = map_int (g, map->values[i]); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; -} void free_json_map_string_int64 (json_map_string_int64 *map) @@ -1367,55 +471,6 @@ free_json_map_string_int64 (json_map_string_int64 *map) define_cleaner_function (json_map_string_int64 *, free_json_map_string_int64) -json_map_string_int64 * -make_json_map_string_int64 (yajl_val src, const struct parser_context *ctx, - parser_error *err) -{ - __auto_cleanup (free_json_map_string_int64) json_map_string_int64 *ret = NULL; - - (void) ctx; /* Silence compiler warning. */ - - if (src != NULL && YAJL_GET_OBJECT (src) != NULL) - { - size_t i; - size_t len = YAJL_GET_OBJECT (src)->len; - ret = safe_malloc (sizeof (*ret)); - ret->len = len; - ret->keys = safe_malloc ((len + 1) * sizeof (char *)); - ret->values = safe_malloc ((len + 1) * sizeof (int64_t)); - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT (src)->values[i]; - ret->keys[i] = safe_strdup (srckey ? srckey : ""); - - if (srcval != NULL) - { - int64_t invalid; - if (! YAJL_IS_NUMBER (srcval)) - { - if (*err == NULL && asprintf (err, "Invalid value with type 'int' for key '%s'", srckey) < 0) - { - *(err) = safe_strdup ("error allocating memory"); - } - return NULL; - } - invalid = common_safe_int64 (YAJL_GET_NUMBER (srcval), &(ret->values[i])); - if (invalid) - { - if (*err == NULL - && asprintf (err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror (-invalid)) - < 0) - { - *(err) = safe_strdup ("error allocating memory"); - } - return NULL; - } - } - } - } - return move_ptr (ret); -} int append_json_map_string_int64 (json_map_string_int64 *map, const char *key, int64_t val) { @@ -1449,38 +504,6 @@ append_json_map_string_int64 (json_map_string_int64 *map, const char *key, int64 return 0; } -yajl_gen_status -gen_json_map_string_bool (void *ctx, const json_map_string_bool *map, const struct parser_context *ptx, - parser_error *err) -{ - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; - size_t len = 0, i = 0; - if (map != NULL) - len = map->len; - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - for (i = 0; i < len; i++) - { - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->keys[i]), strlen (map->keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = yajl_gen_bool ((yajl_gen) g, (int) (map->values[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; -} - void free_json_map_string_bool (json_map_string_bool *map) { @@ -1503,69 +526,6 @@ free_json_map_string_bool (json_map_string_bool *map) define_cleaner_function (json_map_string_bool *, free_json_map_string_bool) -json_map_string_bool * -make_json_map_string_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (free_json_map_string_bool) json_map_string_bool *ret = NULL; - size_t i; - size_t len; - - (void) ctx; /* Silence compiler warning. */ - - len = YAJL_GET_OBJECT_NO_CHECK (src)->len; - - if (src == NULL || YAJL_GET_OBJECT (src) == NULL) - return NULL; - - ret = calloc (1, sizeof (*ret)); - if (ret == NULL) - return NULL; - ret->len = 0; - ret->keys = calloc (len + 1, sizeof (char *)); - if (ret->keys == NULL) - { - return NULL; - } - - ret->values = calloc (len + 1, sizeof (bool)); - if (ret->values == NULL) - { - return NULL; - } - for (i = 0; i < len; i++) - { - const char *srckey = YAJL_GET_OBJECT_NO_CHECK (src)->keys[i]; - yajl_val srcval = YAJL_GET_OBJECT_NO_CHECK (src)->values[i]; - - ret->keys[i] = NULL; - ret->values[i] = NULL; - ret->len = i + 1; - - ret->keys[i] = strdup (srckey ? srckey : ""); - if (ret->keys[i] == NULL) - { - *(err) = strdup ("error allocating memory"); - return NULL; - } - if (srcval != NULL) - { - if (YAJL_IS_TRUE (srcval)) - ret->values[i] = true; - else if (YAJL_IS_FALSE (srcval)) - ret->values[i] = false; - else - { - if (*err == NULL && asprintf (err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) - { - *err = strdup ("error allocating memory"); - } - return NULL; - } - } - } - return move_ptr (ret); -} - int append_json_map_string_bool (json_map_string_bool *map, const char *key, bool val) { @@ -1615,39 +575,21 @@ append_json_map_string_bool (json_map_string_bool *map, const char *key, bool va return 0; } -yajl_gen_status -gen_json_map_string_string (void *ctx, const json_map_string_string *map, const struct parser_context *ptx, - parser_error *err) +int +gen_json_map_string_string (json_t *root, const json_map_string_string *map, parser_error *err) { - yajl_gen_status stat = yajl_gen_status_ok; - yajl_gen g = (yajl_gen) ctx; + int stat = JSON_GEN_SUCCESS; size_t len = 0, i = 0; if (map != NULL) len = map->len; - - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 0); - - stat = yajl_gen_map_open ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - + for (i = 0; i < len; i++) { - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->keys[i]), strlen (map->keys[i])); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) (map->values[i]), strlen (map->values[i])); - if (yajl_gen_status_ok != stat) + stat = json_object_set(root, (const char *)(map->keys[i]), json_string((const char *)(map->values[i]))); + if (JSON_GEN_SUCCESS != stat) GEN_SET_ERROR_AND_RETURN (stat, err); } - - stat = yajl_gen_map_close ((yajl_gen) g); - if (yajl_gen_status_ok != stat) - GEN_SET_ERROR_AND_RETURN (stat, err); - if (! len && ! (ptx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - return yajl_gen_status_ok; + return JSON_GEN_SUCCESS; } void @@ -1713,7 +655,7 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx, for (i = 0; i < len; i++) { const char *srckey = json_object_to_keys_values (src)->keys[i]; - json_t *srcval = &json_object_to_keys_values (src)->values[i]; + const json_t *srcval = &json_object_to_keys_values (src)->values[i]; ret->keys[i] = NULL; ret->values[i] = NULL; @@ -1727,7 +669,7 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx, if (srcval != NULL) { char *str; - if (! YAJL_IS_STRING (srcval)) + if (! json_is_string (srcval)) { if (*err == NULL && asprintf (err, "Invalid value with type 'string' for key '%s'", srckey) < 0) { @@ -1843,65 +785,6 @@ append_json_map_string_string (json_map_string_string *map, const char *key, con return 0; } -static void -cleanup_yajl_gen (yajl_gen g) -{ - if (! g) - return; - yajl_gen_clear (g); - yajl_gen_free (g); -} - -define_cleaner_function (yajl_gen, cleanup_yajl_gen) - -char * -json_marshal_string (const char *str, size_t length, const struct parser_context *ctx, parser_error *err) -{ - __auto_cleanup (cleanup_yajl_gen) yajl_gen g = NULL; - struct parser_context tmp_ctx = { 0 }; - const unsigned char *gen_buf = NULL; - char *json_buf = NULL; - size_t gen_len = 0; - yajl_gen_status stat; - - if (str == NULL || err == NULL) - return NULL; - - *err = NULL; - if (ctx == NULL) - ctx = (const struct parser_context *) (&tmp_ctx); - - if (! json_gen_init (&g, ctx)) - { - *err = strdup ("Json_gen init failed"); - return json_buf; - } - stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *) str, length); - if (yajl_gen_status_ok != stat) - { - if (asprintf (err, "error generating json, errcode: %d", (int) stat) < 0) - *err = strdup ("error allocating memory"); - return json_buf; - } - yajl_gen_get_buf (g, &gen_buf, &gen_len); - if (gen_buf == NULL) - { - *err = strdup ("Error to get generated json"); - return json_buf; - } - - json_buf = calloc (1, gen_len + 1); - if (json_buf == NULL) - { - *err = strdup ("error allocating memory"); - return json_buf; - } - - (void) memcpy (json_buf, gen_buf, gen_len); - json_buf[gen_len] = '\0'; - - return json_buf; -} /** * json_array_to_struct This function extracts keys and values and stores it in struct @@ -2010,15 +893,4 @@ json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys, size_t num } return dst; -} - -/** Temporary function we will not need it once transformation is done */ -yajl_val json_to_yajl(json_t *json) { - char errbuf[1024]; - - char *json_string = json_dumps(json, JSON_INDENT(2)); - if (!json_string) { - return NULL; - } - return yajl_tree_parse((const char *)json_string, errbuf, sizeof(errbuf)); } \ No newline at end of file diff --git a/src/ocispec/json_common.h b/src/ocispec/json_common.h index 538fab47..78dc8e92 100644 --- a/src/ocispec/json_common.h +++ b/src/ocispec/json_common.h @@ -6,8 +6,6 @@ #include #include #include -#include -#include #include #ifdef __cplusplus @@ -36,6 +34,12 @@ extern "C" { // options not to validate utf8 data #define OPT_GEN_NO_VALIDATE_UTF8 0x10 +// Generating json succeded +#define JSON_GEN_SUCCESS 0 + +// Generating json failed +#define JSON_GEN_FAILED -1 + #define define_cleaner_function(type, cleaner) \ static inline void cleaner##_function (type *ptr) \ { \ @@ -80,42 +84,10 @@ struct parser_context FILE *errfile; }; -yajl_gen_status gen_yajl_object_residual (json_t *j, yajl_gen g, parser_error *err); - -yajl_gen_status map_uint (void *ctx, long long unsigned int num); - -yajl_gen_status map_int (void *ctx, long long int num); - -bool json_gen_init (yajl_gen *g, const struct parser_context *ctx); - -yajl_val get_val (yajl_val tree, const char *name, yajl_type type); - char *safe_strdup (const char *src); void *safe_malloc (size_t size); -int common_safe_double (const char *numstr, double *converted); - -int common_safe_uint8 (const char *numstr, uint8_t *converted); - -int common_safe_uint16 (const char *numstr, uint16_t *converted); - -int common_safe_uint32 (const char *numstr, uint32_t *converted); - -int common_safe_uint64 (const char *numstr, uint64_t *converted); - -int common_safe_uint (const char *numstr, unsigned int *converted); - -int common_safe_int8 (const char *numstr, int8_t *converted); - -int common_safe_int16 (const char *numstr, int16_t *converted); - -int common_safe_int32 (const char *numstr, int32_t *converted); - -int common_safe_int64 (const char *numstr, int64_t *converted); - -int common_safe_int (const char *numstr, int *converted); - int json_double_to_int (double d, int *converted); int json_double_to_int64 (double d, int64_t *converted); @@ -147,9 +119,7 @@ typedef struct void free_json_map_int_int (json_map_int_int *map); -json_map_int_int *make_json_map_int_int (yajl_val src, const struct parser_context *ctx, parser_error *err); - -yajl_gen_status gen_json_map_int_int (void *ctx, const json_map_int_int *map, const struct parser_context *ptx, +int gen_json_map_int_int (json_t *root, const json_map_int_int *map, parser_error *err); int append_json_map_int_int (json_map_int_int *map, int key, int val); @@ -163,9 +133,7 @@ typedef struct void free_json_map_int_bool (json_map_int_bool *map); -json_map_int_bool *make_json_map_int_bool (yajl_val src, const struct parser_context *ctx, parser_error *err); - -yajl_gen_status gen_json_map_int_bool (void *ctx, const json_map_int_bool *map, const struct parser_context *ptx, +int gen_json_map_int_bool (json_t *root, const json_map_int_bool *map, parser_error *err); int append_json_map_int_bool (json_map_int_bool *map, int key, bool val); @@ -179,9 +147,7 @@ typedef struct void free_json_map_int_string (json_map_int_string *map); -json_map_int_string *make_json_map_int_string (yajl_val src, const struct parser_context *ctx, parser_error *err); - -yajl_gen_status gen_json_map_int_string (void *ctx, const json_map_int_string *map, const struct parser_context *ptx, +int gen_json_map_int_string (json_t *root, const json_map_int_string *map, parser_error *err); int append_json_map_int_string (json_map_int_string *map, int key, const char *val); @@ -195,9 +161,7 @@ typedef struct void free_json_map_string_int (json_map_string_int *map); -json_map_string_int *make_json_map_string_int (yajl_val src, const struct parser_context *ctx, parser_error *err); - -yajl_gen_status gen_json_map_string_int (void *ctx, const json_map_string_int *map, const struct parser_context *ptx, +int gen_json_map_string_int (json_t *root, const json_map_string_int *map, parser_error *err); int append_json_map_string_int (json_map_string_int *map, const char *key, int val); @@ -211,8 +175,6 @@ typedef struct void free_json_map_string_bool (json_map_string_bool *map); -json_map_string_bool *make_json_map_string_bool (yajl_val src, const struct parser_context *ctx, parser_error *err); - typedef struct { char **keys; @@ -222,14 +184,12 @@ typedef struct void free_json_map_string_int64 (json_map_string_int64 *map); -json_map_string_int64 *make_json_map_string_int64 (yajl_val src, const struct parser_context *ctx, parser_error *err); - -yajl_gen_status gen_json_map_string_int64 (void *ctx, const json_map_string_int64 *map, - const struct parser_context *ptx, parser_error *err); +int gen_json_map_string_int64 (json_t *root, const json_map_string_int64 *map, + parser_error *err); int append_json_map_string_int64 (json_map_string_int64 *map, const char *key, int64_t val); -yajl_gen_status gen_json_map_string_bool (void *ctx, const json_map_string_bool *map, const struct parser_context *ptx, +int gen_json_map_string_bool (json_t *root, const json_map_string_bool *map, parser_error *err); int append_json_map_string_bool (json_map_string_bool *map, const char *key, bool val); @@ -247,8 +207,7 @@ json_map_string_string *clone_map_string_string (json_map_string_string *src); json_map_string_string *make_json_map_string_string (json_t *src, const struct parser_context *ctx, parser_error *err); -yajl_gen_status gen_json_map_string_string (void *ctx, const json_map_string_string *map, - const struct parser_context *ptx, parser_error *err); +int gen_json_map_string_string (json_t *root, const json_map_string_string *map, parser_error *err); int append_json_map_string_string (json_map_string_string *map, const char *key, const char *val); @@ -273,8 +232,6 @@ jansson_object_keys_values *json_object_to_keys_values(json_t *object); json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys, size_t num_keys); -yajl_val json_to_yajl(json_t *json); - #ifdef __cplusplus } #endif diff --git a/src/ocispec/sources.py b/src/ocispec/sources.py index 9950a1e1..0d9ae742 100755 --- a/src/ocispec/sources.py +++ b/src/ocispec/sources.py @@ -373,30 +373,20 @@ def get_map_string_obj(obj, c_file, prefix): c_file.append(' size_t len = 0, i;\n') c_file.append(" if (ptr != NULL)\n") c_file.append(" len = ptr->len;\n") - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 0);\n') - c_file.append(" stat = yajl_gen_map_open ((yajl_gen) g);\n") - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(f' if (len || (ptr != NULL && ptr->keys != NULL && ptr->{child.fixname} != NULL))\n') c_file.append(' {\n') c_file.append(' for (i = 0; i < len; i++)\n') c_file.append(' {\n') - c_file.append(' char *str = ptr->keys[i] ? ptr->keys[i] : "";\n') - c_file.append(' stat = yajl_gen_string ((yajl_gen) g, \ -(const unsigned char *)str, strlen (str));\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(' json_t *subroot = json_object();\n') + c_file.append(f' stat = gen_{childname} (subroot, ptr->{child.fixname}[i], err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f' stat = gen_{childname} (g, ptr->{child.fixname}[i], ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(' char *str = ptr->keys[i] ? ptr->keys[i] : "";\n') + c_file.append(' stat = json_object_set (root, (const char *)str, subroot);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' }\n') c_file.append(' }\n') - c_file.append(" stat = yajl_gen_map_close ((yajl_gen) g);\n") - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 1);\n') def get_obj_arr_obj_array(obj, c_file, prefix): if obj.subtypobj or obj.subtyp == 'object': @@ -405,57 +395,39 @@ def get_obj_arr_obj_array(obj, c_file, prefix): typename = obj.subtypname else: typename = helpers.get_name_substr(obj.name, prefix) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n') c_file.append(' {\n') c_file.append(' size_t len = 0, i;\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {int(l)} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") c_file.append(f" len = ptr->{obj.fixname}_len;\n") - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 0);\n') - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(' json_t *subroot = json_array();\n') c_file.append(' for (i = 0; i < len; i++)\n') c_file.append(' {\n') if obj.doublearray: - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(' json_t *subsubroot = json_array();\n') c_file.append(" size_t j;\n") c_file.append(f' for (j = 0; j < ptr->{obj.fixname}_item_lens[i]; j++)\n') c_file.append(' {\n') - c_file.append(f' stat = gen_{typename} (g, ptr->{obj.fixname}[i][j], ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = gen_{typename} (subsubroot, ptr->{obj.fixname}[i][j], err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') + c_file.append(' stat = json_array_append(subroot, subsubroot);\n') else: - c_file.append(f' stat = gen_{typename} (g, ptr->{obj.fixname}[i], ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = gen_{typename} (subroot, ptr->{obj.fixname}[i], err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 1);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), subroot);\n') c_file.append(' }\n') elif obj.subtyp == 'byte': l = len(obj.origname) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL && ptr->{obj.fixname}_len))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL && ptr->{obj.fixname}_len)\n') c_file.append(' {\n') c_file.append(' const char *str = "";\n') c_file.append(' size_t len = 0;\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") if obj.doublearray: - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(' json_t *subroot = json_array();\n') c_file.append(" {\n") c_file.append(" size_t i;\n") c_file.append(f" for (i = 0; i < ptr->{obj.fixname}_len; i++)\n") @@ -464,61 +436,46 @@ def get_obj_arr_obj_array(obj, c_file, prefix): c_file.append(f" str = (const char *)ptr->{obj.fixname}[i];\n") c_file.append(" else ()\n") c_file.append(" str = "";\n") - c_file.append(' stat = yajl_gen_string ((yajl_gen) g, \ - (const unsigned char *)str, strlen(str));\n') + c_file.append(' stat = json_array_append (subroot, json_string((const char *)str));\n') c_file.append(" }\n") c_file.append(" }\n") - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') + c_file.append(f' stat = json_object_set (root, (const char *)("{obj.origname}"), subroot);\n') else: c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") c_file.append(" {\n") c_file.append(f" str = (const char *)ptr->{obj.fixname};\n") c_file.append(f" len = ptr->{obj.fixname}_len;\n") c_file.append(" }\n") - c_file.append(' stat = yajl_gen_string ((yajl_gen) g, \ - (const unsigned char *)str, len);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = json_object_set (root, (const char *)("{obj.origname}"), json_string((const char *)str));\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") else: - l = len(obj.origname) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n') c_file.append(' {\n') c_file.append(' size_t len = 0, i;\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(' json_t *subroot = json_array();\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") c_file.append(f" len = ptr->{obj.fixname}_len;\n") - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 0);\n') - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' for (i = 0; i < len; i++)\n') c_file.append(' {\n') if obj.doublearray: typename = helpers.get_map_c_types(obj.subtyp) - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(' json_t *subsubroot = json_array();\n') c_file.append(" size_t j;\n") c_file.append(f' for (j = 0; j < ptr->{obj.fixname}_item_lens[i]; j++)\n') c_file.append(' {\n') - json_value_generator(c_file, 4, f"ptr->{obj.fixname}[i][j]", 'g', 'ctx', obj.subtyp) + json_value_generator(c_file, 4, f"ptr->{obj.fixname}[i][j]", 'subsubroot', obj.subtyp) c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') + c_file.append(' stat = json_array_append(subroot, subsubroot);\n') else: - json_value_generator(c_file, 3, f"ptr->{obj.fixname}[i]", 'g', 'ctx', obj.subtyp) - + json_value_generator(c_file, 3, f"ptr->{obj.fixname}[i]", 'subroot', obj.subtyp) c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(" if (!len && !(ctx->options & OPT_GEN_SIMPLIFY))\n") - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 1);\n') - c_file.append(' }\n') + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), subroot);\n') + c_file.append(' }\n') def get_obj_arr_obj(obj, c_file, prefix): """ @@ -528,64 +485,39 @@ def get_obj_arr_obj(obj, c_file, prefix): """ if obj.typ == 'string': l = len(obj.origname) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL))\n' ) + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n' ) c_file.append(' {\n') - c_file.append(' char *str = "";\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), json_string(ptr->{obj.fixname}));\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") - c_file.append(f" str = ptr->{obj.fixname};\n") - json_value_generator(c_file, 2, "str", 'g', 'ctx', obj.typ) c_file.append(" }\n") elif helpers.judge_data_type(obj.typ): - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname}_present))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname}_present)\n') c_file.append(' {\n') + json_conv = 'json_real' if obj.typ == 'double': numtyp = 'double' - elif obj.typ.startswith("uint") or obj.typ == 'GID' or obj.typ == 'UID': - numtyp = 'long long unsigned int' else: - numtyp = 'long long int' + numtyp = 'json_int_t' + json_conv = 'json_integer' l = len(obj.origname) - c_file.append(f' {numtyp} num = 0;\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f" if (ptr != NULL && ptr->{obj.fixname})\n") + c_file.append(f' {numtyp} num = 0;\n') + c_file.append(f" if (ptr != NULL && ptr->{obj.fixname})\n") c_file.append(f" num = ({numtyp})ptr->{obj.fixname};\n") - json_value_generator(c_file, 2, "num", 'g', 'ctx', obj.typ) - c_file.append(" }\n") - elif helpers.judge_data_pointer_type(obj.typ): - c_file.append(f' if ((ptr != NULL && ptr->{obj.fixname} != NULL))\n') - c_file.append(' {\n') - numtyp = helpers.obtain_data_pointer_type(obj.typ) - if numtyp == "": - return - l = len(obj.origname) - c_file.append(f' {helpers.get_map_c_types(numtyp)} num = 0;\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, \ -(const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), {json_conv}(num));\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") - c_file.append(" {\n") - c_file.append(f" num = ({helpers.get_map_c_types(numtyp)})*(ptr->{obj.fixname});\n") - c_file.append(" }\n") - json_value_generator(c_file, 2, "num", 'g', 'ctx', numtyp) c_file.append(" }\n") elif obj.typ == 'boolean': - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname}_present))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname}_present)\n') c_file.append(' {\n') c_file.append(' bool b = false;\n') - l = len(obj.origname) - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f" if (ptr != NULL && ptr->{obj.fixname})\n") + c_file.append(f" b = ptr->{obj.fixname};\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), json_boolean(b));\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f" if (ptr != NULL && ptr->{obj.fixname})\n") - c_file.append(f" b = ptr->{obj.fixname};\n") c_file.append(" \n") - json_value_generator(c_file, 2, "b", 'g', 'ctx', obj.typ) c_file.append(" }\n") elif obj.typ == 'object' or obj.typ == 'mapStringObject': l = len(obj.origname) @@ -593,26 +525,28 @@ def get_obj_arr_obj(obj, c_file, prefix): typename = obj.subtypname else: typename = helpers.get_prefixed_name(obj.name, prefix) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n') c_file.append(" {\n") - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.origname}"), {l} /* strlen ("{obj.origname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(' json_t *subroot = json_object();\n') + c_file.append(f' stat = gen_{typename} (subroot, ptr != NULL ? ptr->{obj.fixname} : NULL, err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f' stat = gen_{typename} (g, ptr != NULL ? ptr->{obj.fixname} : NULL, ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.origname}"), subroot);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") elif obj.typ == 'array': get_obj_arr_obj_array(obj, c_file, prefix) elif helpers.valid_basic_map_name(obj.typ): l = len(obj.origname) - c_file.append(f' if ((ctx->options & OPT_GEN_KEY_VALUE) || (ptr != NULL && ptr->{obj.fixname} != NULL))\n') + c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n') c_file.append(' {\n') - c_file.append(f' stat = yajl_gen_string ((yajl_gen) g, (const unsigned char *)("{obj.fixname}"), {l} /* strlen ("{obj.fixname}") */);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(' json_t *subroot = json_object();\n') + c_file.append(f' stat = gen_{helpers.make_basic_map_name(obj.typ)} (subroot, ptr ? ptr->{obj.fixname} : NULL, err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - c_file.append(f' stat = gen_{helpers.make_basic_map_name(obj.typ)} (g, ptr ? ptr->{obj.fixname} : NULL, ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = json_object_set(root, (const char *)("{obj.fixname}"), subroot);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") @@ -633,40 +567,27 @@ def get_c_json(obj, c_file, prefix): if objs is None: return c_file.append( - f"yajl_gen_status\ngen_{typename} (yajl_gen g, const {typename} *ptr, const struct parser_context " \ - "*ctx, parser_error *err)\n") + f"int\ngen_{typename} (json_t *root, const {typename} *ptr, " \ + "parser_error *err)\n") c_file.append("{\n") - c_file.append(" yajl_gen_status stat = yajl_gen_status_ok;\n") + c_file.append(" int stat = JSON_GEN_SUCCESS;\n") c_file.append(" *err = NULL;\n") c_file.append(" (void) ptr; /* Silence compiler warning. */\n") if obj.typ == 'mapStringObject': get_map_string_obj(obj, c_file, prefix) elif obj.typ == 'object' or (obj.typ == 'array' and obj.subtypobj): nodes = obj.children if obj.typ == 'object' else obj.subtypobj - if nodes is None: - c_file.append(' if (!(ctx->options & OPT_GEN_SIMPLIFY))\n') - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 0);\n') - - c_file.append(" stat = yajl_gen_map_open ((yajl_gen) g);\n") - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") for i in nodes or []: get_obj_arr_obj(i, c_file, prefix) if obj.typ == 'object': if obj.children is not None: c_file.append(" if (ptr != NULL && ptr->_residual != NULL)\n") c_file.append(" {\n") - c_file.append(" stat = gen_yajl_object_residual (ptr->_residual, g, err);\n") - c_file.append(" if (yajl_gen_status_ok != stat)\n") + c_file.append(" stat = json_object_update_missing(root, ptr->_residual);\n") + c_file.append(" if (JSON_GEN_SUCCESS != stat)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") - c_file.append(" stat = yajl_gen_map_close ((yajl_gen) g);\n") - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") - if nodes is None: - c_file.append(' if (!(ctx->options & OPT_GEN_SIMPLIFY))\n') - c_file.append(' yajl_gen_config (g, yajl_gen_beautify, 1);\n') - c_file.append(' return yajl_gen_status_ok;\n') + c_file.append(' return JSON_GEN_SUCCESS;\n') c_file.append("}\n\n") @@ -697,7 +618,7 @@ def read_val_generator(c_file, level, src, dest, typ, keyname, obj_typename): c_file.append(f"{' ' * level}const json_t *val = {src};\n") c_file.append(f"{' ' * level}if (val != NULL)\n") c_file.append(f"{' ' * (level)} {{\n") - c_file.append(f"{' ' * (level + 1)}char *str = json_string_value (val);\n") + c_file.append(f"{' ' * (level + 1)}const char *str = json_string_value (val);\n") c_file.append(f"{' ' * (level + 1)}{dest} = strdup (str ? str : \"\");\n") c_file.append(f"{' ' * (level + 1)}if ({dest} == NULL)\n") c_file.append(f"{' ' * (level + 1)} return NULL;\n") @@ -952,32 +873,32 @@ def make_clone(obj, c_file, prefix): c_file.append("}\n\n") -def json_value_generator(c_file, level, src, dst, ptx, typ): +def json_value_generator(c_file, level, src, dst, typ): """ Description: json value generateor Interface: None History: 2019-06-17 """ if helpers.valid_basic_map_name(typ): - c_file.append(f'{" " * (level)}stat = gen_{helpers.make_basic_map_name(typ)} ({dst}, {src}, {ptx}, err);\n') - c_file.append(f"{' ' * level}if (stat != yajl_gen_status_ok)\n") + c_file.append(f'{" " * (level)}stat = gen_{helpers.make_basic_map_name(typ)} ({dst}, {src}, err);\n') + c_file.append(f"{' ' * level}if (stat != JSON_GEN_SUCCESS)\n") c_file.append(f"{' ' * (level + 1)}GEN_SET_ERROR_AND_RETURN (stat, err);\n") elif typ == 'string': - c_file.append(f'{" " * (level)}stat = yajl_gen_string ((yajl_gen){dst}, (const unsigned char *)({src}), strlen ({src}));\n') - c_file.append(f"{' ' * level}if (stat != yajl_gen_status_ok)\n") + c_file.append(f'{" " * (level)}stat = json_array_append({dst}, json_string({src}));\n') + c_file.append(f"{' ' * level}if (stat != JSON_GEN_SUCCESS)\n") c_file.append(f"{' ' * (level + 1)}GEN_SET_ERROR_AND_RETURN (stat, err);\n") elif helpers.judge_data_type(typ): if typ == 'double': - c_file.append(f'{" " * (level)}stat = yajl_gen_double ((yajl_gen){dst}, {src});\n') + c_file.append(f'{" " * (level)}stat = json_array_append({dst}, json_real({src}));\n') elif typ.startswith("uint") or typ == 'GID' or typ == 'UID': - c_file.append(f"{' ' * level}stat = map_uint ({dst}, {src});\n") + c_file.append(f"{' ' * level}stat = json_array_append ({dst}, json_integer({src}));\n") else: - c_file.append(f"{' ' * level}stat = map_int ({dst}, {src});\n") - c_file.append(f"{' ' * level}if (stat != yajl_gen_status_ok)\n") + c_file.append(f"{' ' * level}stat = json_array_append({dst}, json_integer({src}));\n") + c_file.append(f"{' ' * level}if (stat != JSON_GEN_SUCCESS)\n") c_file.append(f"{' ' * (level + 1)}GEN_SET_ERROR_AND_RETURN (stat, err);\n") elif typ == 'boolean': - c_file.append(f'{" " * (level)}stat = yajl_gen_bool ((yajl_gen){dst}, (int)({src}));\n') - c_file.append(f"{' ' * level}if (stat != yajl_gen_status_ok)\n") + c_file.append(f'{" " * (level)}stat = json_array_append({dst}, json_boolean({src}));\n') + c_file.append(f"{' ' * level}if (stat != JSON_GEN_SUCCESS)\n") c_file.append(f"{' ' * (level + 1)}GEN_SET_ERROR_AND_RETURN (stat, err);\n") def make_c_array_free (i, c_file, prefix): @@ -1266,12 +1187,12 @@ def get_c_epilog_for_array_make_parse(c_file, prefix, typ, obj): c_file.append(" return NULL;\n") elif obj.subtyp == 'byte': if obj.doublearray: - c_file.append(' char *str = json_string_value (work);\n') + c_file.append(' const char *str = json_string_value (work);\n') c_file.append(' ptr->items[j] = (uint8_t *)strdup (str ? str : "");\n') c_file.append(' if (ptr->items[j] == NULL)\n') c_file.append(" return NULL;\n") else: - c_file.append(' char *str = json_string_value (tree);\n') + c_file.append(' const char *str = json_string_value (tree);\n') c_file.append(' memcpy(ptr->items, str ? str : "", strlen(str ? str : ""));\n') c_file.append(' break;\n') else: @@ -1394,24 +1315,18 @@ def get_c_epilog_for_array_make_gen(c_file, prefix, typ, obj): return typename = helpers.get_top_array_type_name(obj.name, prefix) - c_file.append(f"yajl_gen_status gen_{typename} (yajl_gen g, const {typename} *ptr, const struct parser_context *ctx," + """ + c_file.append(f"int gen_{typename} (json_t *root, const {typename} *ptr, " + """ parser_error *err) { - yajl_gen_status stat; size_t i; - + int stat; if (ptr == NULL) - return yajl_gen_status_ok; - *err = NULL; + return JSON_GEN_SUCCESS; """) if obj.subtypobj or obj.subtyp == 'object': c_file.append("""\n - stat = yajl_gen_array_open ((yajl_gen) g); - if (stat != yajl_gen_status_ok) - GEN_SET_ERROR_AND_RETURN (stat, err); for (i = 0; i < ptr->len; i++) - { """) if obj.subtypname: @@ -1420,89 +1335,85 @@ def get_c_epilog_for_array_make_gen(c_file, prefix, typ, obj): subtypename = helpers.get_name_substr(obj.name, prefix) c_file.append(' {\n') if obj.doublearray: - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") + c_file.append(" json_t *subroot = json_array();\n") c_file.append(" size_t j;\n") c_file.append(' for (j = 0; j < ptr->subitem_lens[i]; j++)\n') c_file.append(' {\n') - c_file.append(f' stat = gen_{subtypename} (g, ptr->items[i][j], ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = gen_{subtypename} (subroot, ptr->items[i][j], err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') + c_file.append(" int stat = json_array_append(root, subroot);\n") + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") + c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") else: - c_file.append(f' stat = gen_{subtypename} (g, ptr->items[i], ctx, err);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") + c_file.append(f' stat = gen_{subtypename} (root, ptr->items[i], err);\n') + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append("""\n } - } - stat = yajl_gen_array_close ((yajl_gen) g); """) elif obj.subtyp == 'byte': c_file.append(' {\n') c_file.append(' const char *str = NULL;\n') if obj.doublearray: - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" {\n") c_file.append(" size_t i;\n") + c_file.append(" json_t *subroot = json_array();\n") c_file.append(" for (i = 0; i < ptr->len; i++)\n") c_file.append(" {\n") c_file.append(" if (ptr->items[i] != NULL)\n") c_file.append(" str = (const char *)ptr->items[i];\n") c_file.append(" else ()\n") c_file.append(" str = "";\n") - c_file.append(' stat = yajl_gen_string ((yajl_gen) g, \ - (const unsigned char *)str, strlen(str));\n') + c_file.append(" json_t *jstr = json_string(str);\n") + c_file.append(" int stat = json_array_append(subroot, jstr);\n") + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") + c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") + c_file.append(" int stat = json_array_append(root, subroot);\n") + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") + c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" }\n") - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') else: c_file.append(" if (ptr != NULL && ptr->items != NULL)\n") c_file.append(" {\n") c_file.append(" str = (const char *)ptr->items;\n") c_file.append(" }\n") - c_file.append(' stat = yajl_gen_string ((yajl_gen) g, \ - (const unsigned char *)str, ptr->len);\n') + c_file.append(" json_t *jstr = json_string(str);\n") + c_file.append(" int stat = json_array_append(root, jstr);\n") + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") + c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(' }\n') else: c_file.append("""\n - stat = yajl_gen_array_open ((yajl_gen) g); - if (stat != yajl_gen_status_ok) - GEN_SET_ERROR_AND_RETURN (stat, err); for (i = 0; i < ptr->len; i++) { """) c_file.append(' {\n') if obj.doublearray: - c_file.append(' stat = yajl_gen_array_open ((yajl_gen) g);\n') - c_file.append(" if (stat != yajl_gen_status_ok)\n") - c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") c_file.append(" size_t j;\n") + c_file.append(" json_t *subroot = json_array();\n") c_file.append(' for (j = 0; j < ptr->subitem_lens[i]; j++)\n') c_file.append(' {\n') - json_value_generator(c_file, 4, "ptr->items[i][j]", 'g', 'ctx', obj.subtyp) + json_value_generator(c_file, 4, "ptr->items[i][j]", 'subroot', obj.subtyp) c_file.append(' }\n') - c_file.append(' stat = yajl_gen_array_close ((yajl_gen) g);\n') + c_file.append(" int stat = json_array_append(root, subroot);\n") + c_file.append(" if (stat != JSON_GEN_SUCCESS)\n") + c_file.append(" GEN_SET_ERROR_AND_RETURN (stat, err);\n") else: - json_value_generator(c_file, 3, "ptr->items[i]", 'g', 'ctx', obj.subtyp) + json_value_generator(c_file, 3, "ptr->items[i]", 'root', obj.subtyp) c_file.append("""\n } } - stat = yajl_gen_array_close ((yajl_gen) g); """) c_file.append("""\n - if (ptr->len > 0 && !(ctx->options & OPT_GEN_SIMPLIFY)) - yajl_gen_config (g, yajl_gen_beautify, 1); - if (stat != yajl_gen_status_ok) + if (stat != JSON_GEN_SUCCESS) GEN_SET_ERROR_AND_RETURN (stat, err); - return yajl_gen_status_ok; + return JSON_GEN_SUCCESS; } """) @@ -1599,63 +1510,25 @@ def get_c_epilog(c_file, prefix, typ, obj): "\treturn ptr; \n}\n" ) - c_file.append("""\nstatic void\ncleanup_yajl_gen (yajl_gen g) -{ - if (!g) - return; - yajl_gen_clear (g); - yajl_gen_free (g); -} - -define_cleaner_function (yajl_gen, cleanup_yajl_gen) - -""") - c_file.append("\n char * \n" + -f"{typename}_generate_json (const {typename} *ptr, const struct parser_context *ctx, parser_error *err)" + +f"{typename}_generate_json (const {typename} *ptr, parser_error *err)" + """{ - __auto_cleanup(cleanup_yajl_gen) yajl_gen g = NULL; - struct parser_context tmp_ctx = { 0 }; - const unsigned char *gen_buf = NULL; - char *json_buf = NULL; - size_t gen_len = 0; + __auto_cleanup(json_decref) json_t *root = json_object(); if (ptr == NULL || err == NULL) return NULL; *err = NULL; - if (ctx == NULL) - ctx = (const struct parser_context *)(&tmp_ctx); - - if (!json_gen_init(&g, ctx)) - { - *err = strdup ("Json_gen init failed"); - return json_buf; - } \n """ + - f"if (yajl_gen_status_ok != gen_{typename} (g, ptr, ctx, err))" + + f"if (JSON_GEN_FAILED == gen_{typename} (root, ptr, err))" + """ { if (*err == NULL) *err = strdup ("Failed to generate json"); - return json_buf; - } - - yajl_gen_get_buf (g, &gen_buf, &gen_len); - if (gen_buf == NULL) - { - *err = strdup ("Error to get generated json"); - return json_buf; + return NULL; } - json_buf = calloc (1, gen_len + 1); - if (json_buf == NULL) - { - *err = strdup ("Cannot allocate memory"); - return json_buf; - } - (void) memcpy (json_buf, gen_buf, gen_len); - json_buf[gen_len] = '\\0'; + char *json_str = json_dumps(root, JSON_INDENT(2)); - return json_buf; + return json_str; } """) diff --git a/tests/test-1.c b/tests/test-1.c index 6e35b424..b87a7d56 100644 --- a/tests/test-1.c +++ b/tests/test-1.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = runtime_spec_schema_config_schema_generate_json(container, 0, &err); + json_buf = runtime_spec_schema_config_schema_generate_json(container, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-10.c b/tests/test-10.c index 4cb884ff..38c052d7 100644 --- a/tests/test-10.c +++ b/tests/test-10.c @@ -239,7 +239,7 @@ do_test_object_double_array() free(test_data->refobjarrays[0][0]->item1); test_data->refobjarrays[0][0]->item1 = strdup("objectrefstr"); - json_buf = basic_test_double_array_generate_json(test_data, &ctx, &err); + json_buf = basic_test_double_array_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); ret = 1; @@ -312,7 +312,7 @@ int do_test_top_array_of_int() } } test_data->items[0] = 111; - json_buf = basic_test_top_array_int_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_array_int_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); @@ -369,7 +369,7 @@ int do_test_top_array_of_string() } free(test_data->items[0]); test_data->items[0] = strdup("hello"); - json_buf = basic_test_top_array_string_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_array_string_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); @@ -437,7 +437,7 @@ int do_test_top_double_array_of_string() } free(test_data->items[0][0]); test_data->items[0][0] = strdup("hello"); - json_buf = basic_test_top_double_array_string_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_double_array_string_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); @@ -504,7 +504,7 @@ int do_test_top_double_array_of_int() } } test_data->items[0][0] = 888; - json_buf = basic_test_top_double_array_int_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_double_array_int_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); @@ -587,7 +587,7 @@ int do_test_top_double_array_of_obj() test_data->items[0][0]->second = 999; free(test_data->items[0][1]->third); test_data->items[0][1]->third = strdup("hello"); - json_buf = basic_test_top_double_array_obj_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_double_array_obj_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); @@ -676,7 +676,7 @@ int do_test_top_double_array_of_refobj() test_data->items[0][0]->item2 = 999; free(test_data->items[0][1]->item1); test_data->items[0][1]->item1 = strdup("hello"); - json_buf = basic_test_top_double_array_refobj_container_generate_json(test_data, &ctx, &err); + json_buf = basic_test_top_double_array_refobj_container_generate_json(test_data, &err); if (json_buf == NULL) { printf("gen error %s\n", err); diff --git a/tests/test-11.c b/tests/test-11.c index 20c5f492..488aff70 100644 --- a/tests/test-11.c +++ b/tests/test-11.c @@ -41,7 +41,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, &ctx, &err); + json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, &err); if (json_buf == NULL) { printf("gen error %s\n", err); free(err); diff --git a/tests/test-3.c b/tests/test-3.c index 26f267aa..5f51295a 100644 --- a/tests/test-3.c +++ b/tests/test-3.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_config_schema_generate_json(image, 0, &err); + json_buf = image_spec_schema_config_schema_generate_json(image, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-4.c b/tests/test-4.c index f1055416..33bb99d8 100644 --- a/tests/test-4.c +++ b/tests/test-4.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_image_index_schema_generate_json(image_index, 0, &err); + json_buf = image_spec_schema_image_index_schema_generate_json(image_index, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-5.c b/tests/test-5.c index e96cab12..31d48fbc 100644 --- a/tests/test-5.c +++ b/tests/test-5.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, 0, &err); + json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-6.c b/tests/test-6.c index a5ad7f4e..76826dc4 100644 --- a/tests/test-6.c +++ b/tests/test-6.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_image_manifest_schema_generate_json(manifest, 0, &err); + json_buf = image_spec_schema_image_manifest_schema_generate_json(manifest, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-7.c b/tests/test-7.c index 226d466e..c0dd8ae7 100644 --- a/tests/test-7.c +++ b/tests/test-7.c @@ -34,7 +34,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_config_schema_generate_json(image, 0, &err); + json_buf = image_spec_schema_config_schema_generate_json(image, &err); if (json_buf == NULL) { printf("gen error %s\n", err); exit (1); diff --git a/tests/test-8.c b/tests/test-8.c index f066660a..c8eca592 100644 --- a/tests/test-8.c +++ b/tests/test-8.c @@ -36,7 +36,7 @@ main () exit (1); } json_buf = image_manifest_items_image_manifest_items_schema_container_generate_json ( - (const image_manifest_items_image_manifest_items_schema_container*)image_items, 0, &err); + (const image_manifest_items_image_manifest_items_schema_container*)image_items, &err); if (json_buf == NULL) { printf ("gen error %s\n", err); exit (1); diff --git a/tests/test-9.c b/tests/test-9.c index e7a358d6..595d82c1 100644 --- a/tests/test-9.c +++ b/tests/test-9.c @@ -41,7 +41,7 @@ main () printf ("error %s\n", err); exit (1); } - json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, &ctx, &err); + json_buf = image_spec_schema_image_layout_schema_generate_json(image_layout, &err); if (json_buf == NULL) { printf("gen error %s\n", err); free(err);