protocol

protocol tests
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/protocol

commit 230bbe50e453297fcb3804d0b2f53982e250f391
parent 0c0e4eb20de5a6cdd195611818e9d4563cd9ff3b
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 15:28:52 +0100

Add(Helpers): pkg_build_resp_pkg

Diffstat:
Minc/package.h | 12++++++++++++
Msrc/package.c | 35+++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -148,6 +148,14 @@ typedef struct resp_pkg_s { u64_t *dependencies; } SF_PACKED resp_pkg_t; +# define SIZEOF_RESP_PKG(pkg) (sizeof(pkg->id) + sizeof(pkg->comp_time) + sizeof(pkg->inst_size) + \ + sizeof(pkg->arch_size) + sizeof(pkg->state) + sizeof(pkg->name_len) + \ + sizeof(pkg->category_len) + sizeof(pkg->version_len) + \ + sizeof(pkg->archive_len) + sizeof(pkg->checksum_len) + \ + sizeof(pkg->dependencies_size) + pkg->name_len + \ + pkg->category_len + pkg->version_len + pkg->archive_len + \ + pkg->checksum_len + (sizeof(*pkg->dependencies) * pkg->dependencies_size)) + typedef struct resp_file_s { u64_t id; u8_t type; @@ -186,5 +194,9 @@ void *pkg_build_req_get_news(size_t *size, time_t last_request, u16_t ids_size, u64_t *ids); void *pkg_build_req_get_cat(size_t *size, u16_t len, u64_t *a_cat); void *pkg_build_req_get_upd(size_t *size, u64_t len, u64_t *a_pkgs); +void *pkg_build_resp_pkg(size_t *size, u64_t id, float comp_time, + float inst_size, float arch_size, u8_t state, const char *name, + const char *category, const char *version, const char *archive, + const char *checksum, u16_t dep_size, u64_t *dependencies); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -133,3 +133,38 @@ void *pkg_build_req_get_upd(size_t *size, u64_t len, u64_t *a_pkgs) { list_add(pkg->payload, upd, SIZEOF_REQ_GET_UPD(upd)); return write_package(pkg, size); } + +void *pkg_build_resp_pkg(size_t *size, u64_t id, float comp_time, + float inst_size, float arch_size, u8_t state, const char *name, + const char *category, const char *version, const char *archive, + const char *checksum, u16_t dep_size, u64_t *dependencies) +{ + resp_pkg_t *pkg; + package_t *ptr; + + pkg = malloc(sizeof(resp_pkg_t)); + pkg->id = id; + pkg->comp_time = comp_time; + pkg->inst_size = inst_size; + pkg->arch_size = arch_size; + pkg->state = state; + pkg->name_len = strlen(name); + pkg->category_len = strlen(name); + pkg->version_len = strlen(version); + pkg->checksum_len = strlen(checksum); + pkg->dependencies_size = dep_size; + + pkg->name = strdup(name); + pkg->category = strdup(category); + pkg->version = strdup(version); + pkg->archive = strdup(archive); + pkg->checksum = strdup(checksum); + pkg->dependencies = malloc(sizeof(*dependencies) * dep_size); + memcpy(pkg->dependencies, dependencies, sizeof(*dependencies) * dep_size); + + ptr = malloc(sizeof(package_t)); + ptr->type = PKG_TYPE_RESP_PKG; + ptr->payload = NULL; + list_add(ptr->payload, pkg, SIZEOF_RESP_PKG(pkg)); + return write_package(ptr, size); +}