summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/json.c b/src/json.c
index d33c647..05b725c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -128,8 +128,11 @@ int og_json_parse_partition(json_t *element, struct og_partition *part,
err = og_json_parse_string(value, &part->os);
flags |= OG_PARAM_PART_OS;
} else if (!strcmp(key, "used_size")) {
- err = og_json_parse_string(value, &part->used_size);
+ err = og_json_parse_uint64(value, &part->used_size);
flags |= OG_PARAM_PART_USED_SIZE;
+ } else if (!strcmp(key, "free_size")) {
+ err = og_json_parse_uint64(value, &part->free_size);
+ flags |= OG_PARAM_PART_FREE_SIZE;
}
if (err < 0)
@@ -248,7 +251,7 @@ void og_cache_image_free(struct list_head *cache_list)
}
}
-int og_json_parse_cache(json_t *element, struct list_head *cache_list)
+static int og_json_parse_cache_images(json_t *element, struct list_head *cache_list)
{
uint64_t required_flags = OG_PARAM_IMG_NAME | OG_PARAM_IMG_SIZE | OG_PARAM_IMG_CHECKSUM;
struct og_cache_image *cache_item;
@@ -305,6 +308,44 @@ int og_json_parse_cache(json_t *element, struct list_head *cache_list)
return err;
}
+int og_json_parse_cache(json_t *element, struct og_cache_data *cache_data, struct list_head *cache_list)
+{
+ uint64_t required_flags = OG_PARAM_CACHE_FREE_SIZE | OG_PARAM_CACHE_USED_SIZE | OG_PARAM_CACHE_IMAGES;
+ uint64_t flags = 0UL;
+ const char *key;
+ json_t *value;
+ int err = 0;
+
+ if (json_typeof(element) != JSON_OBJECT)
+ return -1;
+
+ if (json_object_size(element) == 0)
+ return 0;
+
+ json_object_foreach(element, key, value) {
+ if (!strcmp(key, "used_size")) {
+ err = og_json_parse_uint64(value, &cache_data->used_size);
+ flags |= OG_PARAM_CACHE_USED_SIZE;
+ } else if (!strcmp(key, "free_size")) {
+ err = og_json_parse_uint64(value, &cache_data->free_size);
+ flags |= OG_PARAM_CACHE_FREE_SIZE;
+ } else if (!strcmp(key, "images")) {
+ err = og_json_parse_cache_images(value, cache_list);
+ flags |= OG_PARAM_CACHE_IMAGES;
+ } else
+ err = -1;
+
+ if (err < 0) {
+ return err;
+ }
+ }
+
+ if ((flags & required_flags) != required_flags)
+ return -1;
+
+ return err;
+}
+
void og_boot_entry_free(struct list_head *boot_entry_list)
{
struct og_boot_entry *boot_entry, *tmp;