network

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

commit 4fb9be0537b83226bfa581d4749e10da38298f1c
parent bfcde0976bddc1f08f2b7958b8cb682a8ea7bb5a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 15:42:23 +0100

Add(Helpers): pkg_build_resp_cat

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 @@ -189,6 +189,9 @@ typedef struct resp_cat_s { char *name; } SF_PACKED resp_cat_t; +# define SIZEOF_RESP_CAT(c) (sizeof(c->id) + sizeof(c->parent_id) + \ + sizeof(c->name_len) + c->name_len) + void *write_package(package_t *pkg, size_t *size); package_t *read_pkg(void *data); void *pkg_build_auth(size_t *size, int major_version, int minor_version); @@ -209,5 +212,6 @@ void *pkg_build_resp_file(size_t *size, u64_t id, u8_t type, u64_t parent_id, const char *path); void *pkg_build_resp_news(size_t *size, u64_t id, u64_t parent_id, const char *author, const char *author_mail, const char *text); +void *pkg_build_resp_cat(size_t *size, u64_t id, u64_t parent_id, const char *name); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -209,3 +209,20 @@ void *pkg_build_resp_news(size_t *size, u64_t id, u64_t parent_id, const char *a list_add(pkg->payload, news, SIZEOF_RESP_NEWS(news)); return write_package(pkg, size); } + +void *pkg_build_resp_cat(size_t *size, u64_t id, u64_t parent_id, const char *name) { + resp_cat_t *cat; + package_t *pkg; + + cat = malloc(sizeof(resp_cat_t)); + cat->id = id; + cat->parent_id = parent_id; + cat->name_len = strlen(name); + cat->name = strdup(name); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_RESP_CAT; + pkg->payload = NULL; + list_add(pkg->payload, cat, SIZEOF_RESP_CAT(cat)); + return write_package(pkg, size); +}