From 19271862f6f312fe40670e297494064c1a5644b0 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 17 Oct 2024 12:24:58 +0200 Subject: [PATCH] Remove unused JSON functions Both functions seem to be unused, means it's safe to remove them for now. Signed-off-by: Sascha Grunert --- src/ocispec/json_common.c | 119 -------------------------------------- src/ocispec/json_common.h | 4 -- 2 files changed, 123 deletions(-) diff --git a/src/ocispec/json_common.c b/src/ocispec/json_common.c index fb2b8829..cee4e7a3 100644 --- a/src/ocispec/json_common.c +++ b/src/ocispec/json_common.c @@ -1600,122 +1600,3 @@ clone_map_string_string (json_map_string_string *src) } return move_ptr (ret); } - -int -append_json_map_string_string (json_map_string_string *map, const char *key, const char *val) -{ - size_t len, i; - __auto_free char **keys = NULL; - __auto_free char **values = NULL; - __auto_free char *new_key = NULL; - __auto_free char *new_value = NULL; - - if (map == NULL) - return -1; - - for (i = 0; i < map->len; i++) - { - if (strcmp (map->keys[i], key) == 0) - { - char *v = strdup (val ? val : ""); - if (v == NULL) - return -1; - free (map->values[i]); - map->values[i] = v; - return 0; - } - } - - if ((SIZE_MAX / sizeof (char *) - 1) < map->len) - return -1; - - new_key = strdup (key ? key : ""); - if (new_key == NULL) - return -1; - - new_value = strdup (val ? val : ""); - if (new_value == NULL) - return -1; - - len = map->len + 1; - keys = realloc (map->keys, len * sizeof (char *)); - if (keys == NULL) - return -1; - map->keys = keys; - keys = NULL; - map->keys[map->len] = NULL; - - values = realloc (map->values, len * sizeof (char *)); - if (values == NULL) - return -1; - - map->keys[map->len] = new_key; - new_key = NULL; - map->values = values; - values = NULL; - map->values[map->len] = new_value; - new_value = NULL; - - map->len++; - 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; -} diff --git a/src/ocispec/json_common.h b/src/ocispec/json_common.h index 41c73f59..729cc2b9 100644 --- a/src/ocispec/json_common.h +++ b/src/ocispec/json_common.h @@ -227,10 +227,6 @@ json_map_string_string *make_json_map_string_string (yajl_val src, const struct 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 append_json_map_string_string (json_map_string_string *map, const char *key, const char *val); - -char *json_marshal_string (const char *str, size_t length, const struct parser_context *ctx, parser_error *err); - #ifdef __cplusplus } #endif