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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#ifndef _MSI_MESSAGE_H_
#define _MSI_MESSAGE_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <inttypes.h>
#include "../toxcore/network.h"
#include "../toxcore/tox.h"
#include "toxmsi_header.h"
#define TYPE_REQUEST 1
#define TYPE_RESPONSE 2
#define VERSION_STRING "0.2.2"
#define MSI_MAXMSG_SIZE 65535
typedef enum {
_invite,
_start,
_cancel,
_reject,
_end,
} msi_request_t;
static inline const uint8_t *stringify_request(msi_request_t _request)
{
static const uint8_t* strings[] =
{
(uint8_t*)"INVITE",
(uint8_t*)"START",
(uint8_t*)"CANCEL",
(uint8_t*)"REJECT",
(uint8_t*)"END"
};
return strings[_request];
}
typedef enum {
_trying,
_ringing,
_starting,
_ending,
_error
} msi_response_t;
static inline const uint8_t *stringify_response(msi_response_t _response)
{
static const uint8_t* strings[] =
{
(uint8_t*)"trying",
(uint8_t*)"ringing",
(uint8_t*)"starting",
(uint8_t*)"ending",
(uint8_t*)"error"
};
return strings[_response];
}
typedef struct msi_msg_s {
/* This is the header list which contains unparsed headers */
msi_header_t* _headers;
/* Headers parsed */
msi_header_version_t* _version;
msi_header_request_t* _request;
msi_header_response_t* _response;
msi_header_friendid_t* _friend_id;
msi_header_call_type_t* _call_type;
msi_header_user_agent_t* _user_agent;
msi_header_info_t* _info;
msi_header_reason_t* _reason;
msi_header_call_id_t* _call_id;
/* Pointer to next member since it's list duuh */
struct msi_msg_s* _next;
} msi_msg_t;
/*
* Parse data received from socket
*/
msi_msg_t* msi_parse_msg ( const uint8_t* _data );
/*
* Make new message. Arguments: _type: (request, response); _type_field ( value )
*/
msi_msg_t* msi_msg_new ( uint8_t _type, const uint8_t* _type_field );
/* Header setting */
void msi_msg_set_call_type ( msi_msg_t* _msg, const uint8_t* _header_field );
void msi_msg_set_user_agent ( msi_msg_t* _msg, const uint8_t* _header_field );
void msi_msg_set_friend_id ( msi_msg_t* _msg, const uint8_t* _header_field );
void msi_msg_set_info ( msi_msg_t* _msg, const uint8_t* _header_field );
void msi_msg_set_reason ( msi_msg_t* _msg, const uint8_t* _header_field );
void msi_msg_set_call_id ( msi_msg_t* _msg, const uint8_t* _header_field );
uint8_t* msi_genterate_call_id ( uint8_t* _storage, size_t _len );
/*
* Parses message struct to string.
* Allocates memory so don't forget to free it
*/
uint8_t* msi_msg_to_string ( msi_msg_t* _msg );
/*
* msi_msg_s struct deallocator
*/
void msi_free_msg ( msi_msg_t* _msg );
#endif /* _MSI_MESSAGE_H_ */
|