Skip to content

Commit

Permalink
Remove unused JSON functions
Browse files Browse the repository at this point in the history
Both functions seem to be unused, means it's safe to remove them for
now.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Oct 17, 2024
1 parent 388c91b commit 1927186
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 123 deletions.
119 changes: 0 additions & 119 deletions src/ocispec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions src/ocispec/json_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1927186

Please sign in to comment.