protocol

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

commit e692fafc021bd6eaad183ef755828fbc01ac87e0
parent 665944e40931805b7e323266f93d63cf1818fd2e
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 17 Mar 2017 21:50:59 +0100

Add(Helpers): pkg_build_req_get_file

Diffstat:
Minc/package.h | 4++++
Msrc/package.c | 17+++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -103,6 +103,8 @@ typedef struct req_get_file_s { char *path; } SF_PACKED req_get_file_t; +# define SIZEOF_REQ_GET_FILE(file) (sizeof(file->id) + sizeof(file->path_len) + file->path_len) + typedef struct req_get_news_s { time_t last_request; u16_t pkgs_ids_size; @@ -170,5 +172,7 @@ package_t *read_pkg(void *data); void *pkg_build_auth(size_t *size, int major_version, int minor_version); void *pkg_build_auth_ack(size_t *size, int major_version, int minor_version); void *pkg_build_error(size_t *size, error_type_t type, const char *error); +void *pkg_build_req_get_pkg(size_t *size, u64_t id, u8_t state, const char *name, +void *pkg_build_req_get_file(size_t *size, u64_t id, const char *path) { #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -71,3 +71,20 @@ void *pkg_build_req_get_pkg(size_t *size, u64_t id, u8_t state, const char *name list_add(pkg->payload, req, SIZEOF_REQ_GET_PKG(req)); return write_package(pkg, size); } + +void *pkg_build_req_get_file(size_t *size, u64_t id, const char *path) { + req_get_file_t *file; + package_t *pkg; + + file = malloc(sizeof(req_get_file_t)); + file->id = id; + file->path_len = strlen(path); + file->path = strdup(path); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_REQ_GET_FILE; + pkg->payload = NULL; + pkg->number = 1; + list_add(pkg->payload, file, SIZEOF_REQ_GET_FILE(file)); + return write_package(pkg, size); +}