network

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

commit 0c0e4eb20de5a6cdd195611818e9d4563cd9ff3b
parent f88668b76035f36df7ebb7bb16a15a59900c7ba4
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 15:18:46 +0100

Add(Helpers): pkg_build_req_get_upd

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

diff --git a/inc/package.h b/inc/package.h @@ -126,6 +126,8 @@ typedef struct req_get_upd_s { u64_t *packages; } SF_PACKED req_get_upd_t; +# define SIZEOF_REQ_GET_UPD(upd) (sizeof(upd->pkg_len) + sizeof(*upd->packages) * upd->pkg_len) + typedef struct resp_pkg_s { u64_t id; float comp_time; @@ -183,5 +185,6 @@ 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); +void *pkg_build_req_get_upd(size_t *size, u64_t len, u64_t *a_pkgs); #endif /* PACKAGE_H */ diff --git a/src/package.c b/src/package.c @@ -117,3 +117,19 @@ void *pkg_build_req_get_cat(size_t *size, u16_t len, u64_t *a_cat) { list_add(pkg->payload, cat, SIZEOF_REQ_GET_CAT(cat)); return write_package(pkg, size); } + +void *pkg_build_req_get_upd(size_t *size, u64_t len, u64_t *a_pkgs) { + req_get_upd_t *upd; + package_t *pkg; + + upd = malloc(sizeof(req_get_upd_t)); + upd->pkg_len = len; + upd->packages = malloc(sizeof(*a_pkgs) * len); + memcpy(upd->packages, a_pkgs, sizeof(*a_pkgs) * len); + + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_REQ_UPD; + pkg->payload = NULL; + list_add(pkg->payload, upd, SIZEOF_REQ_GET_UPD(upd)); + return write_package(pkg, size); +}