diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-11-21 14:52:14 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-11-25 10:33:47 +0100 |
commit | 232e6eb30830eb74aac63e22e766f0f0848fb878 (patch) | |
tree | 2b50db6bcf1eb0acb734d8a6d028824b45720e40 /src | |
parent | c110bd7d8dc76d167adb5c2a0781f4d09365dfcf (diff) |
rest: add og_boot_params_find() and og_boot_params_free() and use them
Prepare to reuse this code for the new live system.
Add two new fields to represent server and repository IP.
Diffstat (limited to 'src')
-rw-r--r-- | src/rest.c | 132 |
1 files changed, 77 insertions, 55 deletions
@@ -1471,6 +1471,8 @@ static int og_create_boot_file(unsigned int boot_type, const char *mac, } struct og_boot_mode_params { + const char *server_ip; + const char *repo_ip; const char *ntp; const char *dns; const char *proxy; @@ -1489,17 +1491,33 @@ struct og_boot_mode_params { int has_unit; }; -static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *params, size_t params_size) +static void og_boot_params_free(struct og_boot_mode_params *boot_params) +{ + free((void *)boot_params->server_ip); + free((void *)boot_params->repo_ip); + free((void *)boot_params->ip); + free((void *)boot_params->router); + free((void *)boot_params->netmask); + free((void *)boot_params->nombreordenador); + free((void *)boot_params->netiface); + free((void *)boot_params->nombreaula); + free((void *)boot_params->oglivedir); + free((void *)boot_params->hardprofile); + free((void *)boot_params->ntp); + free((void *)boot_params->dns); + free((void *)boot_params->proxy); + free((void *)boot_params->directorio); + free((void *)boot_params->resolucion); +} + +static int og_boot_params_find(struct og_dbi *dbi, + struct og_boot_mode_params *boot_params, + const char *mac) { char repository_ip[OG_DB_IP_MAXLEN + 1] = {}; - struct og_boot_mode_params boot_params = {}; char server_ip[OG_DB_IP_MAXLEN + 1] = {}; - const char *res_prefix = " vga="; - const char *res_value = "788"; - char *lang = getenv("LANG"); const char *msglog; dbi_result result; - int err = 0; result = dbi_conn_queryf(dbi->conn, "SELECT " @@ -1543,62 +1561,79 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char * return -1; } - boot_params.ip = dbi_result_get_string_copy(result, "ip"); - boot_params.router = dbi_result_get_string_copy(result, "router"); - boot_params.netmask = dbi_result_get_string_copy(result, "netmask"); - boot_params.nombreordenador = dbi_result_get_string_copy(result, "nombreordenador"); - boot_params.netiface = dbi_result_get_string_copy(result, "netiface"); - boot_params.nombreaula = dbi_result_get_string_copy(result, "nombreaula"); - boot_params.oglivedir = dbi_result_get_string_copy(result, "oglivedir"); - boot_params.hardprofile = dbi_result_get_string_copy(result, "hardprofile"); - boot_params.ntp = dbi_result_get_string_copy(result, "ntp"); - boot_params.dns = dbi_result_get_string_copy(result, "dns"); - boot_params.proxy = dbi_result_get_string_copy(result, "proxy"); - boot_params.directorio = dbi_result_get_string_copy(result, "directorio"); - boot_params.resolucion = dbi_result_get_string_copy(result, "resolucion"); - boot_params.repoid = dbi_result_get_uint(result, "repoid"); - boot_params.has_unit = dbi_result_get_uint(result, "has_unit"); - boot_params.is_prof = dbi_result_get_uint(result, "is_prof"); - - if (boot_params.resolucion[0]) { - res_value = boot_params.resolucion; - if (strchr(boot_params.resolucion, ':')) - res_prefix = " video="; - } + boot_params->ip = dbi_result_get_string_copy(result, "ip"); + boot_params->router = dbi_result_get_string_copy(result, "router"); + boot_params->netmask = dbi_result_get_string_copy(result, "netmask"); + boot_params->nombreordenador = dbi_result_get_string_copy(result, "nombreordenador"); + boot_params->netiface = dbi_result_get_string_copy(result, "netiface"); + boot_params->nombreaula = dbi_result_get_string_copy(result, "nombreaula"); + boot_params->oglivedir = dbi_result_get_string_copy(result, "oglivedir"); + boot_params->hardprofile = dbi_result_get_string_copy(result, "hardprofile"); + boot_params->ntp = dbi_result_get_string_copy(result, "ntp"); + boot_params->dns = dbi_result_get_string_copy(result, "dns"); + boot_params->proxy = dbi_result_get_string_copy(result, "proxy"); + boot_params->directorio = dbi_result_get_string_copy(result, "directorio"); + boot_params->resolucion = dbi_result_get_string_copy(result, "resolucion"); + boot_params->repoid = dbi_result_get_uint(result, "repoid"); + boot_params->has_unit = dbi_result_get_uint(result, "has_unit"); + boot_params->is_prof = dbi_result_get_uint(result, "is_prof"); dbi_result_free(result); - if (og_dbi_get_server_ip(dbi, boot_params.ip, server_ip) < 0) { - err = -1; + if (og_dbi_get_server_ip(dbi, boot_params->ip, server_ip) < 0) goto err_out; - } - if (og_dbi_get_repository_ip(dbi, boot_params.repoid, boot_params.ip, - repository_ip) < 0) { - err = -1; + boot_params->server_ip = strdup(server_ip); + + if (og_dbi_get_repository_ip(dbi, boot_params->repoid, boot_params->ip, + repository_ip) < 0) goto err_out; + + boot_params->repo_ip = strdup(repository_ip); + + return 0; +err_out: + og_boot_params_free(boot_params); + return -1; +} + +static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *params, size_t params_size) +{ + struct og_boot_mode_params boot_params = {}; + const char *res_prefix = " vga="; + const char *res_value = "788"; + char *lang = getenv("LANG"); + int err = 0; + + if (og_boot_params_find(dbi, &boot_params, mac) < 0) + return -1; + + if (boot_params.resolucion[0]) { + res_value = boot_params.resolucion; + if (strchr(boot_params.resolucion, ':')) + res_prefix = " video="; } if (!strncmp(boot_params.oglivedir, "ogReLive", strlen("ogReLive"))) snprintf(params, params_size, " ip=%s:%s:%s:%s:%s:%s:none ogrepo=%s oglivedir=%s fetch=http://%s/%s/filesystem.squashfs", - boot_params.ip, server_ip, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface, - repository_ip, + boot_params.ip, boot_params.server_ip, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface, + boot_params.repo_ip, boot_params.oglivedir, - repository_ip, + boot_params.repo_ip, boot_params.oglivedir); else snprintf(params, params_size, " LANG=%s ip=%s:%s:%s:%s:%s:%s:none group=%s ogrepo=%s oglive=%s oglog=%s ogshare=%s oglivedir=%s ogprof=%s server=%s" "%s%s%s%s%s%s%s%s%s%s%s%s", lang, - boot_params.ip, server_ip, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface, + boot_params.ip, boot_params.server_ip, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface, boot_params.nombreaula, - repository_ip, - server_ip, server_ip, server_ip, + boot_params.repo_ip, + boot_params.server_ip, boot_params.server_ip, boot_params.server_ip, boot_params.oglivedir, boot_params.is_prof ? "true" : "false", - server_ip, + boot_params.server_ip, boot_params.hardprofile[0] ? " hardprofile=" : "", boot_params.hardprofile[0] ? boot_params.hardprofile: "", boot_params.ntp[0] ? " ogntp=" : "", boot_params.ntp[0] ? boot_params.ntp : "", boot_params.dns[0] ? " ogdns=" : "", boot_params.dns[0] ? boot_params.dns : "", @@ -1606,20 +1641,7 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char * boot_params.has_unit ? " ogunit=" : "", boot_params.has_unit ? boot_params.directorio : "", res_prefix, res_value); -err_out: - free((void *)boot_params.ip); - free((void *)boot_params.router); - free((void *)boot_params.netmask); - free((void *)boot_params.nombreordenador); - free((void *)boot_params.netiface); - free((void *)boot_params.nombreaula); - free((void *)boot_params.oglivedir); - free((void *)boot_params.hardprofile); - free((void *)boot_params.ntp); - free((void *)boot_params.dns); - free((void *)boot_params.proxy); - free((void *)boot_params.directorio); - free((void *)boot_params.resolucion); + og_boot_params_free(&boot_params); return err; } |