summaryrefslogtreecommitdiffstats
path: root/src/common/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/protocol.c')
-rw-r--r--src/common/protocol.c102
1 files changed, 33 insertions, 69 deletions
diff --git a/src/common/protocol.c b/src/common/protocol.c
index 54d51f6..58a70f6 100644
--- a/src/common/protocol.c
+++ b/src/common/protocol.c
@@ -33,121 +33,85 @@
#define READ_AS(type, from) (*((type*)(from)))
-int push_data(cd_t connection, const char *data, enum tlv_type type)
+int push_data(enum tlv_type type)
{
- int ret = E_UNKNOWN_TYPE;
+ int ret = 0;
switch (type) {
case TEXT:
- ret = push_string(connection, data);
break;
case FPI1:
- ret = push_fpi1(connection, data);
break;
case TIMESTAMP:
- ret = push_timestamp(connection, data);
break;
case REQUEST:
- ret = push_request(connection, data);
break;
case REPLY:
- ret = push_reply(connection, data);
break;
case UUID:
- ret = push_uuid(connection, data);
break;
+ default:
+ ret = E_UNKNOWN_TYPE;
}
return ret;
}
-static int push_string(cd_t connection, const char *str)
+static int push_string(const char *str)
{
- int ret = 0;
- size_t size = strlen(str);
-
- ret |= push_tlv_header(connection, TEXT, size);
- ret |= push_bytes(connection, str, size);
- return ret;
+ return 0;
}
-static int push_fpi1(cd_t connection, const char *num)
+static int push_fpi1(const char *num)
{
- return push_tlv_header(connection, FPI1, sizeof(fpi1_t))
- | push_bytes(connection, num, sizeof(fpi1_t));
+ return 0;
}
-static int push_timestamp(cd_t connection, const char *data)
+static int push_timestamp(const char *data)
{
- return push_tlv_header(connection, TIMESTAMP, sizeof(time_t))
- | push_bytes(connection, data, sizeof(time_t));
+ return 0;
}
-static int push_request(cd_t connection, const char *data)
+static int push_request(const char *data)
{
- return push_tlv_header(connection, REQUEST, sizeof(msg_idx_t))
- | push_bytes(connection, data, sizeof(msg_idx_t));
+ return 0;
}
-static int push_reply(cd_t connection, const char *data)
+static int push_reply(const char *data)
{
- int ret = 0;
- size_t msglen = strlen(data + sizeof(msg_idx_t));
- ret |= push_tlv_header(connection, REPLY, msglen + sizeof(msg_idx_t));
- ret |= push_bytes(connection, data, msglen);
- return ret;
+ return 0;
}
-static int push_uuid(cd_t connection, const char *data)
+static int push_uuid(const char *data)
{
- return push_tlv_header(connection, UUID, sizeof(uuid_t))
- | push_bytes(connection, data, sizeof(uuid_t));
+ return 0;
}
size_t tlv_count(const struct packet_data * const packet)
{
- size_t cursor = 0;
- size_t length = 0;
- size_t ret = 0;
-
- while (cursor < packet->packet_size) {
- cursor += sizeof(enum tlv_type);
- length = READ_AS(enum tlv_type, packet->data + cursor);
- cursor += sizeof(size_t) + length;
- ret++;
- }
- if (cursor != packet->packet_size) {
- errno = E_TLV_OVERFLOW;
- }
- return ret;
+ return 0;
}
-size_t get_tlvs( const struct packet_data * const data,
- struct tlv *buf,
- size_t buf_size)
+size_t parse_tlv(const char *data, size_t cursor, struct tlv *t)
{
- size_t tlvs_read = 0;
- size_t cursor = 0;
+ return 0;
+}
- while (cursor < data->packet_size && tlvs_read <= buf_size) {
- cursor += parse_tlv(data->data, cursor, buf + tlvs_read);
- tlvs_read++;
- }
- if (cursor > data->packet_size) {
- errno = E_TLV_OVERFLOW;
- }
-
- return tlvs_read;
+int clear_data()
+{
+ return 0;
}
-size_t parse_tlv(const char *data, size_t cursor, struct tlv *t)
+static int push_bytes(const char *data, size_t size)
{
- const char *begin = data + cursor;
+ return 0;
+}
- t->type = READ_AS(enum tlv_type, data + cursor);
- cursor += sizeof(enum tlv_type);
- t->length += READ_AS(enum tlv_type ,data + cursor);
- data += sizeof(size_t);
- t->data = data + cursor;
+static int push_tlv_header(enum tlv_type type, size_t size)
+{
+ return 0;
+}
- return data + cursor - begin + 1UL;
+int get_tlv(struct tlv_parser *parser, struct tlv *ret)
+{
+ return 0;
}