From 9c8ece1538d31dba9a416c9f29f88e18510f4c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sat, 18 May 2019 16:32:20 +0300 Subject: Whole-project: partial implementation of protocol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is part of ticket #31. Branch is not in a compiling state. Work is being done on utility functions and protocol implementation. To be completed later. Signed-off-by: Ramūnas Mažeikis --- src/common/protocol_private.h | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/common/protocol_private.h (limited to 'src/common/protocol_private.h') diff --git a/src/common/protocol_private.h b/src/common/protocol_private.h new file mode 100644 index 0000000..3a4b1b2 --- /dev/null +++ b/src/common/protocol_private.h @@ -0,0 +1,66 @@ +/* + * Usurpataion --- server-client protocol private interface. + * + * Copyright (C) 2019 Ramūnas Mažeikis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef PROTOCOL_H_PRIVATE +#define PROTOCOL_H_PRIVATE + +#define TLV_ARR_SIZE (16) + +/* Pease don't rape the buffer with long messages, daemon-kun. */ +#define MSG_BUF_SIZE (257) + +/* UDP can carry bigger packets but memory is hard to come by and more won't be + * needed anyway. + * */ +#define PACKET_MAX_SIZE (512) + +/* Returns the amount of tlv's int a packet. + * + * If a tlv reports length that goes beyond the end of a packet, errno is set + * to TLV_OVERFLOW. To check this, set errno to 0 first. + * */ +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. + * + * To check for errors, set errno to 0 and check after calling. + * */ +size_t get_tlvs( const struct packet_data * const data, + const struct tlv *buf, + size_t buf_size); + +/* Takes a null-terminated string and appends it to the next outgoing packet. + * */ +void push_string(char *str); + +void push_fpi1(fpi1_t num); + +void push_timestamp(char *data); + +void push_request(char *data); + +void push_reply(char *data); + +void push_uuid(char *data); + + + +#endif /* PROTOCOL_H_PRIVATE */ -- cgit v1.2.3