1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* 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
*/
#ifndef PROTOCOL_H_PRIVATE
#define PROTOCOL_H_PRIVATE
#include "utils.h"
#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.
* */
#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 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,
size_t buf_size);
/* Takes a null-terminated string and appends it to the next outgoing packet.
* */
void push_string(char *str);
/* 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 */
|