protocol

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

commit 23213dbcfa53908e3b4e1e049a1e6a92e3ca676d
parent b9f94a53dbf755fc32552d47c39f788126ada83c
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu, 16 Mar 2017 18:04:22 +0100

Fix(Packages): Now properly building packages

Diffstat:
Minc/package.h | 1+
Msrc/client_test.c | 11+----------
Asrc/package.c | 16++++++++++++++++
Msrc/write_package.c | 2++
4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -158,5 +158,6 @@ typedef struct resp_cat_s { } SF_PACKED resp_cat_t; void *write_package(package_t *pkg, size_t *size); +void *pkg_build_auth(size_t *size, int major_version, int minor_version); #endif /* PACKAGE_H */ diff --git a/src/client_test.c b/src/client_test.c @@ -23,20 +23,11 @@ TEST(connect_1) { } TEST(pkg_auth_1) { - package_t *pkg; size_t size; - auth_t *auth; void *ret; TEST_ASSERT(sockfd, "Server is not responding"); - auth = malloc(sizeof(auth_t)); - auth->mpm_major_version = 1; - auth->mpm_minor_version = 1; - pkg = malloc(sizeof(pkg)); - pkg->type = PKG_TYPE_AUTH; - pkg->next_pkg_len = 0; - list_add(pkg->payload, auth, sizeof(auth_t)); - ret = write_package(pkg, &size); + ret = pkg_build_auth(&size, 0, 1); TEST_ASSERT(write(sockfd, ret, size) != 0, "Cannot send package to the server"); return TEST_SUCCESS; diff --git a/src/package.c b/src/package.c @@ -0,0 +1,16 @@ +# include "package.h" + +void *pkg_build_auth(size_t *size, int major_version, int minor_version) { + auth_t *auth; + package_t *pkg; + + auth = malloc(sizeof(auth_t)); + auth->mpm_major_version = major_version; + auth->mpm_minor_version = minor_version; + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_AUTH; + pkg->payload = NULL; + pkg->size = 0; + list_add(pkg->payload, auth, sizeof(auth_t)); + return write_package(pkg, size); +} diff --git a/src/write_package.c b/src/write_package.c @@ -280,6 +280,8 @@ void *write_package(package_t *pkg, size_t *size) { void *header, *payload, *ret; size_t header_size = 0, payload_size = 0; + pkg->size = 0; + pkg->next_pkg_len = 0; header = write_header(pkg, &header_size); payload = write_payload(pkg, &payload_size);