summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
index 675be74..17bc8a7 100644
--- a/src/client.c
+++ b/src/client.c
@@ -435,6 +435,45 @@ static int og_update_cache_info(struct og_dbi *dbi, struct list_head *cache_list
return 0;
}
+static int og_update_boot_entries(struct og_dbi *dbi, struct list_head *boot_entry_list, int client_id)
+{
+ struct og_boot_entry *boot_entry;
+ const char *msglog;
+ dbi_result result;
+
+ /* Remove old boot entries */
+ result = dbi_conn_queryf(dbi->conn,
+ "DELETE FROM boot_entries WHERE client_id=%d;", client_id);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+ /* Add new boot entries */
+ list_for_each_entry(boot_entry, boot_entry_list, list) {
+ result = dbi_conn_queryf(dbi->conn,
+ "INSERT INTO boot_entries (client_id, name, active, description, entry_order)"
+ "VALUES (%d, '%s', %d, '%s', %d)",
+ client_id,
+ boot_entry->name,
+ boot_entry->active ? 1 : 0,
+ boot_entry->description,
+ boot_entry->order == UINT64_MAX ? -1 : boot_entry->order);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+ }
+ return 0;
+}
+
static int og_resp_update_cache(json_t *data, struct og_client *cli)
{
struct og_computer computer = {};
@@ -496,6 +535,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
struct og_computer computer = {};
json_t *value, *cache = NULL;
const char *status = NULL;
+ LIST_HEAD(boot_entry_list);
LIST_HEAD(cache_list);
char cfg[4096] = {};
struct og_dbi *dbi;
@@ -519,6 +559,8 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
err = og_json_parse_string(value, &status);
} else if (!strcmp(key, "link")) {
err = og_json_parse_uint(value, &link);
+ } 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_list);
cache = value;
@@ -595,6 +637,12 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
goto err_out;
}
+ res = og_update_boot_entries(dbi, &boot_entry_list, computer.id);
+ if (err < 0) {
+ og_dbi_close(dbi);
+ goto err_out;
+ }
+
res = actualizaConfiguracion(dbi, cfg, computer.id);
og_dbi_close(dbi);
@@ -611,9 +659,11 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
}
og_cache_image_free(&cache_list);
+ og_boot_entry_free(&boot_entry_list);
return 0;
err_out:
og_cache_image_free(&cache_list);
+ og_boot_entry_free(&boot_entry_list);
return -1;
}