summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-03 13:59:59 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-05 13:32:31 +0200
commit3f02d64104fede43074df2e0f229f514d24363fe (patch)
tree2010f57893ab3a49128bc2a83ddf001bdb471036
parent23bd5f1a0703ffa1f6593489b1b544d8306bb82f (diff)
rest: add checksum to GET /images
Add a new checksum attribute to GET /images, extend database to add a new checksum field to images table.
-rw-r--r--src/client.c13
-rw-r--r--src/dbi.h3
-rw-r--r--src/rest.c8
-rw-r--r--src/schema.c30
4 files changed, 49 insertions, 5 deletions
diff --git a/src/client.c b/src/client.c
index 91927d7..4876f78 100644
--- a/src/client.c
+++ b/src/client.c
@@ -710,7 +710,8 @@ static bool og_dbi_update_image(struct og_dbi *dbi,
static int update_image_info(struct og_dbi *dbi, const char *image_id,
const char *clonator, const char *compressor,
const char *filesystem, const uint64_t datasize,
- uint64_t size, uint64_t lastupdate, uint32_t perms)
+ uint64_t size, uint64_t lastupdate, uint32_t perms,
+ const char *checksum)
{
const char *msglog;
dbi_result result;
@@ -719,9 +720,9 @@ static int update_image_info(struct og_dbi *dbi, const char *image_id,
"UPDATE imagenes"
" SET clonator='%s', compressor='%s',"
" filesystem='%s', datasize=%lld, "
- " size=%lld, lastupdate=%lld, permissions=%u "
+ " size=%lld, lastupdate=%lld, permissions=%u, checksum='%s' "
" WHERE idimagen=%s", clonator, compressor, filesystem,
- datasize, size, lastupdate, perms, image_id);
+ datasize, size, lastupdate, perms, checksum, image_id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
@@ -743,6 +744,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
const char *compressor = NULL;
const char *filesystem = NULL;
const char *partition = NULL;
+ const char *checksum = NULL;
const char *software = NULL;
const char *image_id = NULL;
const char *clonator = NULL;
@@ -789,6 +791,8 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
err = og_json_parse_uint64(value, &lastupdate);
else if (!strcmp(key, "perms"))
err = og_json_parse_uint(value, &perms);
+ else if (!strcmp(key, "checksum"))
+ err = og_json_parse_string(value, &checksum);
if (err < 0)
return err;
@@ -846,7 +850,8 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
}
res = update_image_info(dbi, image_id, clonator, compressor,
- filesystem, datasize, size, lastupdate, perms);
+ filesystem, datasize, size, lastupdate, perms,
+ checksum);
og_dbi_close(dbi);
if (res) {
diff --git a/src/dbi.h b/src/dbi.h
index d6de474..f7aaea3 100644
--- a/src/dbi.h
+++ b/src/dbi.h
@@ -53,9 +53,12 @@ struct og_image_legacy {
char code[OG_DB_INT8_MAXLEN + 1];
};
+#define OG_DB_CHECKSUM 128
+
struct og_image {
char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1];
+ char checksum[OG_DB_CHECKSUM + 1];
uint64_t software_id;
uint64_t center_id;
uint64_t datasize;
diff --git a/src/rest.c b/src/rest.c
index 81c3dd9..d415f0f 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -3325,6 +3325,8 @@ static json_t *og_json_image_alloc(struct og_image *image)
json_integer(image->repo_id));
json_object_set_new(image_json, "description",
json_string(image->description));
+ json_object_set_new(image_json, "checksum",
+ json_string(image->checksum));
return image_json;
}
@@ -3366,7 +3368,7 @@ static int og_cmd_images(char *buffer_reply)
" i.lastupdate, i.permissions, "
" i.idperfilsoft, i.tipo, "
" i.idimagen, i.idrepositorio, "
- " i.descripcion "
+ " i.descripcion, i.checksum "
"FROM imagenes i "
"LEFT JOIN ordenadores o "
"ON i.idordenador = o.idordenador ");
@@ -3381,10 +3383,14 @@ static int og_cmd_images(char *buffer_reply)
image.type = dbi_result_get_ulonglong(result, "tipo");
image.id = dbi_result_get_ulonglong(result, "idimagen");
image.repo_id = dbi_result_get_ulonglong(result, "idrepositorio");
+ snprintf(image.checksum, sizeof(image.checksum), "%s",
+ dbi_result_get_string(result, "checksum"));
snprintf(image.name, sizeof(image.name), "%s",
dbi_result_get_string(result, "nombreca"));
snprintf(image.description, sizeof(image.description), "%s",
dbi_result_get_string(result, "descripcion"));
+ snprintf(image.checksum, sizeof(image.checksum), "%s",
+ dbi_result_get_string(result, "checksum"));
image_json = og_json_image_alloc(&image);
if (!image_json) {
diff --git a/src/schema.c b/src/schema.c
index d5a2269..002fd56 100644
--- a/src/schema.c
+++ b/src/schema.c
@@ -306,6 +306,35 @@ static int og_dbi_schema_v6(struct og_dbi *dbi)
return 0;
}
+static int og_dbi_schema_v7(struct og_dbi *dbi)
+{
+ const char *msglog;
+ dbi_result result;
+
+ syslog(LOG_DEBUG, "Adding checksum to imagenes\n");
+ result = dbi_conn_query(dbi->conn,
+ "ALTER TABLE `imagenes` "
+ "ADD `checksum` varchar(128) NOT NULL DEFAULT ''");
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_INFO, "Error when adding checksum (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+
+ result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 7");
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_INFO, "Could not update version row (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+
+ return 0;
+}
+
static struct og_schema_version {
int version;
int (*update)(struct og_dbi *dbi);
@@ -316,6 +345,7 @@ static struct og_schema_version {
{ .version = 4, .update = og_dbi_schema_v4 },
{ .version = 5, .update = og_dbi_schema_v5 },
{ .version = 6, .update = og_dbi_schema_v6 },
+ { .version = 7, .update = og_dbi_schema_v7, },
{ 0, NULL },
};