protocol

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

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

Add(Helpers): pkg_build_req_get_news

Diffstat:
Minc/package.h | 8+++++++-
Msrc/package.c | 19+++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/inc/package.h b/inc/package.h @@ -111,6 +111,9 @@ typedef struct req_get_news_s { u64_t *pkgs_ids; } SF_PACKED req_get_news_t; +# define SIZEOF_REQ_GET_NEWS(news) (sizeof(news->last_request) + sizeof(news->pkgs_ids_size) + \ + sizeof(*news->pkgs_ids) * news->pkgs_ids_size) + typedef struct req_get_cat_s { u16_t cat_len; u64_t *categories; @@ -173,6 +176,9 @@ 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) { + const char *category, const char *version); +void *pkg_build_req_get_file(size_t *size, u64_t id, const char *path); +void *pkg_build_req_get_news(size_t *size, time_t last_request, u16_t ids_size, + u64_t *ids); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -88,3 +88,22 @@ void *pkg_build_req_get_file(size_t *size, u64_t id, const char *path) { list_add(pkg->payload, file, SIZEOF_REQ_GET_FILE(file)); return write_package(pkg, size); } + +void *pkg_build_req_get_news(size_t *size, time_t last_request, u16_t ids_size, + u64_t *ids) { + req_get_news_t *news; + package_t *pkg; + + news = malloc(sizeof(req_get_news_t)); + news->last_request = last_request; + news->pkgs_ids_size = ids_size; + news->pkgs_ids = malloc(sizeof(*ids) * ids_size); + memcpy(news->pkgs_ids, ids, sizeof(*ids) * ids_size); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_REQ_GET_NEWS; + pkg->payload = NULL; + pkg->number = 1; + list_add(pkg->payload, news, SIZEOF_REQ_GET_NEWS(news)); + return write_package(pkg, size); +}