diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-09-18 15:29:47 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-09-18 15:38:16 +0200 |
commit | d7e2022bdd1626fbcb614710bec20b4a42278f9a (patch) | |
tree | dbb7b32f9ce1e887b3882fff84a0199b0b324a91 /src/client.c | |
parent | 3cb98c7187b3f9b9bc02f202cbed3181a82fde76 (diff) |
#941 pass og_dbi to og_dbi_get_computer_info()
Reuse the existing dbi handler, instead of opening a new one.
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/src/client.c b/src/client.c index 2bec54c..b56e861 100644 --- a/src/client.c +++ b/src/client.c @@ -129,14 +129,6 @@ static int og_resp_hardware(json_t *data, struct og_client *cli) return -1; } - err = og_dbi_get_computer_info(&computer, cli->addr.sin_addr); - if (err < 0) - return -1; - - snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center); - snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id); - snprintf(legacy.hardware, sizeof(legacy.hardware), "%s", hardware); - dbi = og_dbi_open(&dbi_config); if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", @@ -144,6 +136,16 @@ static int og_resp_hardware(json_t *data, struct og_client *cli) return -1; } + err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr); + if (err < 0) { + og_dbi_close(dbi); + return -1; + } + + snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center); + snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id); + snprintf(legacy.hardware, sizeof(legacy.hardware), "%s", hardware); + res = actualizaHardware(dbi, legacy.hardware, legacy.id, computer.name, legacy.center); og_dbi_close(dbi); @@ -195,15 +197,6 @@ static int og_resp_software(json_t *data, struct og_client *cli) return -1; } - err = og_dbi_get_computer_info(&computer, cli->addr.sin_addr); - if (err < 0) - return -1; - - snprintf(legacy.software, sizeof(legacy.software), "%s", software); - snprintf(legacy.part, sizeof(legacy.part), "%s", partition); - snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id); - snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center); - dbi = og_dbi_open(&dbi_config); if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", @@ -211,6 +204,17 @@ static int og_resp_software(json_t *data, struct og_client *cli) return -1; } + err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr); + if (err < 0) { + og_dbi_close(dbi); + return -1; + } + + snprintf(legacy.software, sizeof(legacy.software), "%s", software); + snprintf(legacy.part, sizeof(legacy.part), "%s", partition); + snprintf(legacy.id, sizeof(legacy.id), "%d", computer.id); + snprintf(legacy.center, sizeof(legacy.center), "%d", computer.center); + res = actualizaSoftware(dbi, legacy.software, legacy.part, legacy.id, computer.name, legacy.center); og_dbi_close(dbi); @@ -310,10 +314,6 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) return err; } - err = og_dbi_get_computer_info(&computer, cli->addr.sin_addr); - if (err < 0) - return -1; - if (strlen(serial_number) > 0) snprintf(cfg, sizeof(cfg), "ser=%s\n", serial_number); @@ -349,6 +349,13 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) __func__, __LINE__); return -1; } + + err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr); + if (err < 0) { + og_dbi_close(dbi); + return -1; + } + res = actualizaConfiguracion(dbi, cfg, computer.id); og_dbi_close(dbi); @@ -453,9 +460,18 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) return -1; } - err = og_dbi_get_computer_info(&computer, cli->addr.sin_addr); - if (err < 0) + dbi = og_dbi_open(&dbi_config); + if (!dbi) { + 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_dbi_close(dbi); return -1; + } snprintf(soft_legacy.center, sizeof(soft_legacy.center), "%d", computer.center); @@ -470,13 +486,6 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) snprintf(img_legacy.name, sizeof(img_legacy.name), "%s", name); snprintf(img_legacy.repo, sizeof(img_legacy.repo), "%s", repo); - dbi = og_dbi_open(&dbi_config); - if (!dbi) { - syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", - __func__, __LINE__); - return -1; - } - res = actualizaSoftware(dbi, soft_legacy.software, img_legacy.part, @@ -551,16 +560,6 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli) return -1; } - err = og_dbi_get_computer_info(&computer, cli->addr.sin_addr); - if (err < 0) - return -1; - - snprintf(img_legacy.image_id, sizeof(img_legacy.image_id), "%s", - image_id); - snprintf(img_legacy.part, sizeof(img_legacy.part), "%s", partition); - snprintf(img_legacy.disk, sizeof(img_legacy.disk), "%s", disk); - snprintf(soft_legacy.id, sizeof(soft_legacy.id), "%d", computer.id); - dbi = og_dbi_open(&dbi_config); if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", @@ -587,6 +586,18 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli) "%d", dbi_result_get_uint(query_result, "idperfilsoft")); dbi_result_free(query_result); + err = og_dbi_get_computer_info(dbi, &computer, cli->addr.sin_addr); + if (err < 0) { + og_dbi_close(dbi); + return -1; + } + + snprintf(img_legacy.image_id, sizeof(img_legacy.image_id), "%s", + image_id); + snprintf(img_legacy.part, sizeof(img_legacy.part), "%s", partition); + snprintf(img_legacy.disk, sizeof(img_legacy.disk), "%s", disk); + snprintf(soft_legacy.id, sizeof(soft_legacy.id), "%d", computer.id); + res = actualizaRestauracionImagen(dbi, img_legacy.image_id, img_legacy.disk, |