summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/protocol.h7
-rw-r--r--include/utils.h3
-rw-r--r--src/common/protocol.c14
-rw-r--r--src/common/protocol_private.h26
4 files changed, 39 insertions, 11 deletions
diff --git a/include/protocol.h b/include/protocol.h
index 9d5b518..ac83154 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -32,6 +32,13 @@ enum packet_type {
DISCOVERY
};
+/**
+ * Message sequence number since beggining of sesssion.
+ *
+ * Mainly used for identifying lost messages.
+ */
+typedef unsigned int msg_idx_t;
+
enum tlv_type {
/** NULL-terminated string. */
TEXT,
diff --git a/include/utils.h b/include/utils.h
index e4feb9a..f92e0fa 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -9,6 +9,9 @@ typedef struct uuid_s {
int cmp_uuid(uuid_t *first, uuid_t *second);
+/**
+ * Fixed point number with one decimal digit of precision.
+ */
typedef int fpi1_t;
fpi1_t add(fpi1_t a, fpi1_t b);
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);
}
diff --git a/src/common/protocol_private.h b/src/common/protocol_private.h
index 0c0b7f9..b74c0eb 100644
--- a/src/common/protocol_private.h
+++ b/src/common/protocol_private.h
@@ -75,23 +75,39 @@ size_t get_tlvs( const struct packet_data * const data,
* */
int push_string(char *str);
-/* Reinterprets char * as fpi1_t * and appends it to the outgoing packet as a
+/** Reinterprets char * as fpi1_t * and appends it to the outgoing packet as a
* tlv.
*/
int push_fpi1(char *num);
-/* Reinterprets char * as time_t * and appends it to the outgoing packet as a
+/** Reinterprets char * as time_t * and appends it to the outgoing packet as a
* tlv.
*/
int push_timestamp(char *data);
-/* Not implemented yet. */
+/**
+ * Pushes a request for daemon to repeat a message identified by a msg_index_t.
+ *
+ * @param data Pointer to a msg_index_t.
+ *
+ * @return 0 on success or E_PACKET_OVERFLOW, if not enough space is available
+ * to push all the data.
+ */
int push_request(char *data);
-/* Not implemented yet. */
+/**
+ * Pushes a message to the outgoing packet buffer as a reply. A reply is just
+ * a null terminated string.
+ *
+ * @param data msg_idx_t representing sequence number since beggining of
+ * connection and a null-terminated string.
+ *
+ * @return On success --- 0 or E_PACKET_OVERFLOW, if not enough buffer is
+ * available.
+ */
int push_reply(char *data);
-/* Reinterprets char * as uuid_t * and appends it to the outgoing packet as a
+/** Reinterprets char * as uuid_t * and appends it to the outgoing packet as a
* tlv.
*/
int push_uuid(char *data);