From bb70fccb66f55e9cc2b9ed0bf366479828f41346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 20 May 2019 21:50:19 +0300 Subject: Protocol: implemented request and reply pushing to packet. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First implementation of complete protocol interface. While the first implementation does compile, the interface might change due to demands from other parts of the project. For now reqest is a tlv that is an unsigned int which represents what message to repeat from daemon. A reply is also a tlv made of two parts --- message sequence number of type msg_ixd_t and the actual null terminated string. All of the above is subject to change. More docs. Doxygen is on the way. Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/common/protocol.c') diff --git a/src/common/protocol.c b/src/common/protocol.c index 2ac8280..2243dad 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -113,14 +113,17 @@ static int push_timestamp(char *data) static int push_request(char *data) { - (void)data; - return 0; + return push_tlv_header(REQUEST, sizeof(msg_idx_t)) + | push_bytes(data, sizeof(msg_idx_t)); } static int push_reply(char *data) { - (void)data; - return 0; + int ret = 0; + size_t msglen = strlen(data + sizeof(msg_idx_t)); + ret |= push_tlv_header(REPLY, msglen + sizeof(msg_idx_t)); + ret |= push_bytes(data, msglen); + return ret; } static int push_uuid(char *data) @@ -129,7 +132,7 @@ static int push_uuid(char *data) | push_bytes(data, sizeof(uuid_t)); } -int push_tlv_header(enum tlv_type type, size_t size) +static int push_tlv_header(enum tlv_type type, size_t size) { if (size + sizeof(type) + packet_cursor >= PACKET_MAX_SIZE) { return E_PACKET_OVERFLOW; @@ -147,7 +150,6 @@ void get_last_data() msg_buf[0] = '\0'; msg_buf[1] = '\0'; tlv_cursor = 0; - /* Get packet here. Somehow. TODO */ get_tlvs(packet_buf, tlv_buf, TLV_BUF_SIZE); } -- cgit v1.2.3