network

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

commit bfcde0976bddc1f08f2b7958b8cb682a8ea7bb5a
parent fd9f5248555c47e82d45a54bbc4c6019d2f83eaa
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 15:38:54 +0100

Add(Helpers): pkg_build_resp_news

Diffstat:
Minc/package.h | 6++++++
Msrc/package.c | 23+++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -178,6 +178,10 @@ typedef struct resp_news_s { char *text; } SF_PACKED resp_news_t; +# define SIZEOF_RESP_NEWS(n) (sizeof(n->id) + sizeof(n->parent_id) + sizeof(n->author_len) + \ + sizeof(n->author_mail_len) + sizeof(n->text_len) + \ + n->author_len + n->author_mail_len + n->text_len) + typedef struct resp_cat_s { u64_t id; u64_t parent_id; @@ -203,5 +207,7 @@ void *pkg_build_resp_pkg(size_t *size, u64_t id, float comp_time, 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); +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); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -186,3 +186,26 @@ void *pkg_build_resp_file(size_t *size, u64_t id, u8_t type, u64_t parent_id, list_add(pkg->payload, file, SIZEOF_RESP_FILE(file)); return write_package(pkg, size); } + +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) { + resp_news_t *news; + package_t *pkg; + + news = malloc(sizeof(resp_news_t)); + news->id = id; + news->parent_id = parent_id; + news->author_len = strlen(author); + news->author_mail_len = strlen(author_mail); + news->text_len = strlen(text); + + news->author = strdup(author); + news->author_mail = strdup(author_mail); + news->text = strdup(text); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_RESP_FILE; + pkg->payload = NULL; + list_add(pkg->payload, news, SIZEOF_RESP_NEWS(news)); + return write_package(pkg, size); +}