summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/client.c b/src/client.c
index bbe4c15..6e568b5 100644
--- a/src/client.c
+++ b/src/client.c
@@ -407,7 +407,7 @@ static int og_json_parse_partition_array(json_t *value,
return 0;
}
-static int og_update_cache_info(struct og_dbi *dbi, struct og_cache_data *cache_data, struct list_head *cache_list, int clientid)
+static int og_update_cache_info(struct og_dbi *dbi, struct og_cache_data *cache_data, int clientid)
{
struct og_cache_image *cache_image;
const char *msglog;
@@ -426,7 +426,7 @@ static int og_update_cache_info(struct og_dbi *dbi, struct og_cache_data *cache_
dbi_result_free(result);
/* Add new cache image info */
- list_for_each_entry(cache_image, cache_list, list) {
+ list_for_each_entry(cache_image, &cache_data->image_list, list) {
result = dbi_conn_queryf(dbi->conn,
"INSERT INTO cache (clientid, imagename, size, checksum)"
"VALUES (%d, '%s', %lu, '%s')",
@@ -508,36 +508,37 @@ static int og_resp_update_cache(json_t *data, struct og_client *cli)
struct og_cache_data cache_data = {};
struct og_computer computer = {};
json_t *value, *cache = NULL;
- LIST_HEAD(cache_list);
struct og_dbi *dbi;
const char *key;
int err = 0;
+ og_cache_data_init(&cache_data);
+
if (json_typeof(data) != JSON_OBJECT) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
return -1;
}
json_object_foreach(data, key, value) {
if (!strcmp(key, "cache")) {
- err = og_json_parse_cache(value, &cache_data, &cache_list);
+ err = og_json_parse_cache(value, &cache_data);
cache = value;
}
if (err < 0) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
return err;
}
}
if (!cache) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
return 0;
}
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
return -1;
@@ -545,19 +546,19 @@ static int og_resp_update_cache(json_t *data, struct og_client *cli)
err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr);
if (err < 0) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
og_dbi_close(dbi);
return -1;
}
- err = og_update_cache_info(dbi, &cache_data, &cache_list, computer.id);
+ err = og_update_cache_info(dbi, &cache_data, computer.id);
if (err < 0) {
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
og_dbi_close(dbi);
return -1;
}
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
og_dbi_close(dbi);
return 0;
}
@@ -823,7 +824,6 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
struct og_computer computer = {};
const char *status = NULL;
LIST_HEAD(boot_entry_list);
- LIST_HEAD(cache_list);
json_t *value = NULL;
struct og_dbi *dbi;
uint32_t link = 0;
@@ -831,6 +831,8 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
int err = 0;
bool res;
+ og_cache_data_init(&cache_data);
+
if (json_typeof(data) != JSON_OBJECT)
goto err_out;
@@ -850,7 +852,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
} else if (!strcmp(key, "efi")) {
err = og_json_parse_efi(value, &boot_entry_list);
} else if (!strcmp(key, "cache")) {
- err = og_json_parse_cache(value, &cache_data, &cache_list);
+ err = og_json_parse_cache(value, &cache_data);
}
if (err < 0)
@@ -886,7 +888,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
goto err_out;
}
- if (og_update_cache_info(dbi, &cache_data, &cache_list, computer.id) < 0) {
+ if (og_update_cache_info(dbi, &cache_data, computer.id) < 0) {
og_dbi_close(dbi);
goto err_out;
}
@@ -907,13 +909,13 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
goto err_out;
}
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
og_boot_entry_free(&boot_entry_list);
return 0;
err_out:
syslog(LOG_ERR, "Failed to refresh info from client %s\n",
inet_ntoa(cli->addr.sin_addr));
- og_cache_image_free(&cache_list);
+ og_cache_data_free(&cache_data);
og_boot_entry_free(&boot_entry_list);
return -1;
}