network

low level network subjects
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/network

commit 72c8fd926150fb382609c6ffb1e3f6c6cc4ccc58
parent fa7d82dec2343887f319da9b3bc12c1219e255db
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 17 Mar 2017 22:03:36 +0100

Add(Helpers): pkg_build_req_get_cat

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

diff --git a/inc/package.h b/inc/package.h @@ -119,6 +119,8 @@ typedef struct req_get_cat_s { u64_t *categories; } SF_PACKED req_get_cat_t; +# define SIZEOF_REQ_GET_CAT(cat) (sizeof(cat->cat_len) + sizeof(*cat->categories) * cat->cat_len) + typedef struct req_get_upd_s { u64_t pkg_len; u64_t *packages; @@ -180,5 +182,6 @@ 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); 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); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -107,3 +107,20 @@ void *pkg_build_req_get_news(size_t *size, time_t last_request, u16_t ids_size, list_add(pkg->payload, news, SIZEOF_REQ_GET_NEWS(news)); return write_package(pkg, size); } + +void *pkg_build_req_get_cat(size_t *size, u16_t len, u64_t *a_cat) { + req_get_cat_t *cat; + package_t *pkg; + + cat = malloc(sizeof(req_get_cat_t)); + cat->cat_len = len; + cat->categories = malloc(sizeof(*a_cat) * len); + memcpy(cat->categories, a_cat, sizeof(*a_cat) * len); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_REQ_CAT; + pkg->payload = NULL; + pkg->number = 1; + list_add(pkg->payload, cat, SIZEOF_REQ_GET_CAT(cat)); + return write_package(pkg, size); +}