diff options
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c index 8551d50..1486034 100644 --- a/src/client.c +++ b/src/client.c @@ -421,6 +421,59 @@ static int og_update_cache_info(struct og_dbi *dbi, struct list_head *cache_list return 0; } +static int og_resp_update_cache(json_t *data, struct og_client *cli) +{ + struct og_computer computer = {}; + json_t *value, *cache = NULL; + LIST_HEAD(cache_list); + struct og_dbi *dbi; + const char *key; + int err = 0; + + if (json_typeof(data) != JSON_OBJECT) { + og_cache_image_free(&cache_list); + return -1; + } + + json_object_foreach(data, key, value) { + if (!strcmp(key, "cache")) { + err = og_json_parse_cache(value, &cache_list); + cache = value; + } + } + + if (!cache) { + og_cache_image_free(&cache_list); + return 0; + } + + dbi = og_dbi_open(&ogconfig.db); + if (!dbi) { + og_cache_image_free(&cache_list); + syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", + __func__, __LINE__); + return -1; + } + + err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr); + if (err < 0) { + og_cache_image_free(&cache_list); + og_dbi_close(dbi); + return -1; + } + + err = og_update_cache_info(dbi, &cache_list, computer.id); + if (err < 0) { + og_cache_image_free(&cache_list); + og_dbi_close(dbi); + return -1; + } + + og_cache_image_free(&cache_list); + og_dbi_close(dbi); + return 0; +} + static int og_resp_refresh(json_t *data, struct og_client *cli) { struct og_partition partitions[OG_PARTITION_MAX] = {}; @@ -1013,6 +1066,9 @@ int og_agent_state_process_response(struct og_client *cli) case OG_CMD_IMAGE_RESTORE: err = og_resp_image_restore(root, cli); break; + case OG_CMD_CACHE_DELETE: + err = og_resp_update_cache(root, cli); + break; default: err = -1; break; |