protocol

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

commit fd9f5248555c47e82d45a54bbc4c6019d2f83eaa
parent 230bbe50e453297fcb3804d0b2f53982e250f391
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 15:33:01 +0100

Add(Helpers): pkg_build_resp_file

Diffstat:
Minc/package.h | 5+++++
Msrc/package.c | 22++++++++++++++++++++--
2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -164,6 +164,9 @@ typedef struct resp_file_s { char *path; } SF_PACKED resp_file_t; +# define SIZEOF_RESP_FILE(f) (sizeof(f->id) + sizeof(f->type) + sizeof(f->parent_id) + \ + sizeof(f->path_len) + f->path_len) + typedef struct resp_news_s { u64_t id; u64_t parent_id; @@ -198,5 +201,7 @@ 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); +void *pkg_build_resp_file(size_t *size, u64_t id, u8_t type, u64_t parent_id, + const char *path); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -137,8 +137,7 @@ 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) -{ + const char *checksum, u16_t dep_size, u64_t *dependencies) { resp_pkg_t *pkg; package_t *ptr; @@ -168,3 +167,22 @@ void *pkg_build_resp_pkg(size_t *size, u64_t id, float comp_time, list_add(ptr->payload, pkg, SIZEOF_RESP_PKG(pkg)); return write_package(ptr, size); } + +void *pkg_build_resp_file(size_t *size, u64_t id, u8_t type, u64_t parent_id, + const char *path) { + resp_file_t *file; + package_t *pkg; + + file = malloc(sizeof(resp_file_t)); + file->id = id; + file->type = type; + file->parent_id = parent_id; + file->path_len = strlen(path); + file->path = strdup(path); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_RESP_FILE; + pkg->payload = NULL; + list_add(pkg->payload, file, SIZEOF_RESP_FILE(file)); + return write_package(pkg, size); +}