summaryrefslogtreecommitdiffstats
path: root/src/common/protocol_private.h
diff options
context:
space:
mode:
authorGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-19 17:50:53 +0300
committerGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-19 17:50:53 +0300
commit031caaf9b7745bfc552cc86fb475de1f18d0fd6d (patch)
treec58ce9782d781f2984fefc587c59ea37cf75a73d /src/common/protocol_private.h
parentb4165ee0b257aaa9064c5ac82200ff2569a02955 (diff)
downloadusurpation-031caaf9b7745bfc552cc86fb475de1f18d0fd6d.tar.gz
usurpation-031caaf9b7745bfc552cc86fb475de1f18d0fd6d.tar.bz2
usurpation-031caaf9b7745bfc552cc86fb475de1f18d0fd6d.zip
Protocol: Implemented protocol error reporting.
Now public functions of the protocol can return an error code. More work is done on actual logic. Protocol code has bare-bones doxygen documentation. Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/common/protocol_private.h')
-rw-r--r--src/common/protocol_private.h44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/common/protocol_private.h b/src/common/protocol_private.h
index 653d19c..0c0b7f9 100644
--- a/src/common/protocol_private.h
+++ b/src/common/protocol_private.h
@@ -23,37 +23,44 @@
#include "utils.h"
+#define E_PACKET_OVERFLOW (1 << 0)
+
+/** Read as "A maximum of 16 tlv's per packet". */
#define TLV_BUF_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.
+/* Maximum size of packet that can fit into the packet buffer. 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.
+/** 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.
+ *
+ * @param packet data parsed from a packet. Function cannot use raw packets.
+ *
+ * @return Amount of tlv's in a packet.
* */
-size_t tlv_count(const struct packet_data * const packet);
-
+size_t tlv_count(const struct packet_data * const packet_data);
/**
* 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.
* */
@@ -61,34 +68,37 @@ 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.
+/** Takes a null-terminated string and appends it to the next outgoing packet.
+ *
+ * @return Returns 0 on success. Otherwise: E_PACKET_OVERFLOW.
+ *
* */
-void push_string(char *str);
+int push_string(char *str);
/* Reinterprets char * as fpi1_t * and appends it to the outgoing packet as a
* tlv.
*/
-void push_fpi1(char *num);
+int push_fpi1(char *num);
/* Reinterprets char * as time_t * and appends it to the outgoing packet as a
* tlv.
*/
-void push_timestamp(char *data);
+int push_timestamp(char *data);
/* Not implemented yet. */
-void push_request(char *data);
+int push_request(char *data);
/* Not implemented yet. */
-void push_reply(char *data);
+int push_reply(char *data);
/* Reinterprets char * as uuid_t * and appends it to the outgoing packet as a
* tlv.
*/
-void push_uuid(char *data);
+int 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);
+int push_tlv_header(enum tlv_type type, size_t size);
#endif /* PROTOCOL_H_PRIVATE */