From b4165ee0b257aaa9064c5ac82200ff2569a02955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 19 May 2019 13:52:43 +0300 Subject: Protocol: more work on protocol implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additional functions implemented for protocol and basic functions to work with uuid. Source is buildable but actual build files are not edited to accomodate the changes. Signed-off-by: Ramūnas Mažeikis --- src/common/protocol_private.h | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'src/common/protocol_private.h') diff --git a/src/common/protocol_private.h b/src/common/protocol_private.h index 3a4b1b2..653d19c 100644 --- a/src/common/protocol_private.h +++ b/src/common/protocol_private.h @@ -18,10 +18,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifdef PROTOCOL_H_PRIVATE +#ifndef PROTOCOL_H_PRIVATE #define PROTOCOL_H_PRIVATE -#define TLV_ARR_SIZE (16) +#include "utils.h" + +#define TLV_BUF_SIZE (16) /* Pease don't rape the buffer with long messages, daemon-kun. */ #define MSG_BUF_SIZE (257) @@ -38,10 +40,22 @@ * */ size_t tlv_count(const struct packet_data * const packet); -/* Parses a data packet, fills buffer of tlv's of size `buf_size` and returns - * the number of tlv's actually parsed. + +/** + * Parses tlv's from packet data and writes them to a buffer of given size. + * + * Returns how many tlv's were actually parsed. * * To check for errors, set errno to 0 and check after calling. + * + * Not yet implemented. + * + * @param data Data from network packet + * @param buf Buffer to store parsed tlv's + * @param buf_size Size of buffer used to store tlv's + * + * @return Number of tlv's actually parsed. Greter than or equal to buffer + * size, if an error occurs. * */ size_t get_tlvs( const struct packet_data * const data, const struct tlv *buf, @@ -51,16 +65,30 @@ size_t get_tlvs( const struct packet_data * const data, * */ void push_string(char *str); -void push_fpi1(fpi1_t num); +/* Reinterprets char * as fpi1_t * and appends it to the outgoing packet as a + * tlv. + */ +void push_fpi1(char *num); +/* Reinterprets char * as time_t * and appends it to the outgoing packet as a + * tlv. + */ void push_timestamp(char *data); +/* Not implemented yet. */ void push_request(char *data); +/* Not implemented yet. */ void push_reply(char *data); +/* Reinterprets char * as uuid_t * and appends it to the outgoing packet as a + * tlv. + */ void push_uuid(char *data); - +/* Appends tlv_type and size of data to a packet effectively creating a tlv + * header. + */ +void push_tlv_header(enum tlv_type type, size_t size); #endif /* PROTOCOL_H_PRIVATE */ -- cgit v1.2.3