libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 8c14ac6ef83e74523f8f4310be8866dd268cd2fd
parent 998df99397444150331f5280801c93f7722001e3
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 28 May 2017 22:07:05 +0200

Add(Packer): Add the category, installation size and SBU in package.json / MPX archive

Diffstat:
Minc/packer.h | 6++++++
Msrc/packer.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Mtests/packer/right/package.json | 5++++-
Atests/packer/wrong_package_section_6/package.json | 25+++++++++++++++++++++++++
Atests/packer/wrong_package_section_7/package.json | 27+++++++++++++++++++++++++++
Atests/packer/wrong_package_section_8/package.json | 28++++++++++++++++++++++++++++
Mtests/test_packer.c | 32++++++++++++++++++++++++++++++++
7 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/inc/packer.h b/inc/packer.h @@ -49,6 +49,9 @@ typedef enum packer_type_e { # define PACKER_CONF_PACKAGE_NAME_TOKEN "name" # define PACKER_CONF_PACKAGE_VERSION_TOKEN "version" # define PACKER_CONF_PACKAGE_DESC_TOKEN "description" +# define PACKER_CONF_PACKAGE_SBU_TOKEN "SBU" +# define PACKER_CONF_PACKAGE_CATEG_TOKEN "category" +# define PACKER_CONF_PACKAGE_INST_SIZE_TOKEN "inst_size" # define PACKER_CONF_COMP_TOKEN "compilation" # define PACKER_CONF_COMP_CONF_TOKEN "configure" # define PACKER_CONF_COMP_MAKE_TOKEN "make" @@ -67,6 +70,9 @@ typedef struct packer_header_package_s { char *name; /*!< Name of the package */ char *version; /*!< Version of the package */ char *description; /*!< Description of the package */ + double _sbu; /*!< SBU (Installation time) */ + char *categ; /*!< Category of the package */ + double inst_size; /*!< Installation size */ } packer_header_package_t; typedef struct packer_conf_opt_s { diff --git a/src/packer.c b/src/packer.c @@ -48,6 +48,9 @@ MPX_STATIC packer_header_package_t *packer_header_package_init(void) { ret->name = NULL; ret->version = NULL; ret->description = NULL; + ret->_sbu = 0; + ret->categ = NULL; + ret->inst_size = 0; return ret; } @@ -57,6 +60,7 @@ MPX_STATIC void packer_header_package_free(packer_header_package_t *ptr) { free(ptr->name); free(ptr->version); free(ptr->description); + free(ptr->categ); free(ptr); } } @@ -400,6 +404,26 @@ MPX_STATIC bool packer_read_config_package(packer_t *ctx, struct json_object *ob goto cleanup; ctx->header->package->description = strdup(json_object_get_string(tmp)); } + else if (strcmp(name, PACKER_CONF_PACKAGE_SBU_TOKEN) == 0) + { + if (json_object_get_type(tmp) != json_type_double + && json_object_get_type(tmp) != json_type_int) + goto cleanup; + ctx->header->package->_sbu = json_object_get_double(tmp); + } + else if (strcmp(name, PACKER_CONF_PACKAGE_CATEG_TOKEN) == 0) + { + if (json_object_get_type(tmp) != json_type_string) + goto cleanup; + ctx->header->package->categ = strdup(json_object_get_string(tmp)); + } + else if (strcmp(name, PACKER_CONF_PACKAGE_INST_SIZE_TOKEN) == 0) + { + if (json_object_get_type(tmp) != json_type_double + && json_object_get_type(tmp) != json_type_int) + goto cleanup; + ctx->header->package->inst_size = json_object_get_double(tmp); + } /* Wrong token */ else goto cleanup; @@ -487,11 +511,18 @@ MPX_STATIC void write_package_header(FILE *fd, packer_t *ctx) { packer_conf_opt_t *opt = NULL; const char *tmp_str = NULL; u32_t list_len = 0, conf_len = 0; + double sbu, inst_size; fprintf(fd, PACKER_MPX_MAGIC); fprintf(fd, "%s%c", h->package->name, 0); fprintf(fd, "%s%c", h->package->version, 0); fprintf(fd, "%s%c", h->package->description, 0); + fprintf(fd, "%s%c", h->package->categ, 0); + + sbu = htonl(h->package->_sbu); + fwrite(&sbu, sizeof(sbu), 1, fd); + inst_size = htonl(h->package->inst_size); + fwrite(&inst_size, sizeof(inst_size), 1, fd); conf_len = htonl(list_size(h->compilation->configure)); fwrite(&conf_len, sizeof(u32_t), 1, fd); @@ -613,6 +644,7 @@ MPX_STATIC int read_package_header_package(const char *file, packer_t *ctx) { int ret = 0; packer_header_package_t *pkg = NULL; + double sbu, inst_size; pkg = packer_header_package_init(); if (pkg == NULL) @@ -634,6 +666,19 @@ MPX_STATIC int read_package_header_package(const char *file, packer_t *ctx) goto cleanup; ret += strlen(pkg->description) + 1; + pkg->categ = strdup(file + ret); + if (pkg->categ == NULL) + goto cleanup; + ret += strlen(pkg->categ) + 1; + + memcpy(&sbu, file + ret, sizeof(sbu)); + pkg->_sbu = ntohl(sbu); + ret += sizeof(sbu); + + memcpy(&inst_size, file + ret, sizeof(inst_size)); + pkg->inst_size = ntohl(inst_size); + ret += sizeof(inst_size); + ctx->header->package = pkg; return ret; diff --git a/tests/packer/right/package.json b/tests/packer/right/package.json @@ -2,7 +2,10 @@ "package": { "name": "test", "version": "2.0", - "description": "This is a description. Yeah I know, mind blowing." + "description": "This is a description. Yeah I know, mind blowing.", + "SBU": 14, + "category": "main", + "inst_size": 244 }, "compilation": { "configure": [ diff --git a/tests/packer/wrong_package_section_6/package.json b/tests/packer/wrong_package_section_6/package.json @@ -0,0 +1,25 @@ +{ + "package": { + "name": "test", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing.", + "category": [] + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_7/package.json b/tests/packer/wrong_package_section_7/package.json @@ -0,0 +1,27 @@ +{ + "package": { + "name": "test", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing.", + "category": "truc", + "SBU": "machine" + }, + + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_8/package.json b/tests/packer/wrong_package_section_8/package.json @@ -0,0 +1,28 @@ +{ + "package": { + "name": "test", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing.", + "category": "truc", + "SBU": 244, + "inst_size": [] + }, + + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -138,6 +138,33 @@ TEST(packer_wrong_package_section_5) { return TEST_SUCCESS; } +TEST(packer_wrong_package_section_6) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_6/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_7) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_7/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_8) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_8/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + TEST(packer_wrong_comp_section_1) { packer_t *ptr; @@ -466,6 +493,8 @@ TEST(packer_read_package_header_package) { TEST_ASSERT(read_package_header_package(tmp, NULL) == 0, "Wrong return"); set_strdup_fail(2); TEST_ASSERT(read_package_header_package(tmp, NULL) == 0, "Wrong return"); + set_strdup_fail(3); + TEST_ASSERT(read_package_header_package(tmp, NULL) == 0, "Wrong return"); return TEST_SUCCESS; } @@ -620,6 +649,9 @@ void register_test_packer(void) { reg_test("packer", packer_wrong_package_section_3); reg_test("packer", packer_wrong_package_section_4); reg_test("packer", packer_wrong_package_section_5); + reg_test("packer", packer_wrong_package_section_6); + reg_test("packer", packer_wrong_package_section_7); + reg_test("packer", packer_wrong_package_section_8); reg_test("packer", packer_wrong_comp_section_1); reg_test("packer", packer_wrong_comp_section_2); reg_test("packer", packer_wrong_comp_section_3);