diff options
Diffstat (limited to 'toxmsi/toxmsi_message.h')
-rw-r--r-- | toxmsi/toxmsi_message.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/toxmsi/toxmsi_message.h b/toxmsi/toxmsi_message.h new file mode 100644 index 00000000..87dfccc2 --- /dev/null +++ b/toxmsi/toxmsi_message.h | |||
@@ -0,0 +1,120 @@ | |||
1 | #ifndef _MSI_MESSAGE_H_ | ||
2 | #define _MSI_MESSAGE_H_ | ||
3 | |||
4 | #ifdef HAVE_CONFIG_H | ||
5 | #include "config.h" | ||
6 | #endif /* HAVE_CONFIG_H */ | ||
7 | |||
8 | #include <inttypes.h> | ||
9 | #include "../toxcore/network.h" | ||
10 | #include "../toxcore/tox.h" | ||
11 | |||
12 | #include "toxmsi_header.h" | ||
13 | |||
14 | #define TYPE_REQUEST 1 | ||
15 | #define TYPE_RESPONSE 2 | ||
16 | |||
17 | #define VERSION_STRING "0.2.2" | ||
18 | |||
19 | #define MSI_MAXMSG_SIZE 65535 | ||
20 | |||
21 | typedef enum { | ||
22 | _invite, | ||
23 | _start, | ||
24 | _cancel, | ||
25 | _reject, | ||
26 | _end, | ||
27 | |||
28 | } msi_request_t; | ||
29 | |||
30 | static inline const uint8_t *stringify_request(msi_request_t _request) | ||
31 | { | ||
32 | static const uint8_t* strings[] = | ||
33 | { | ||
34 | (uint8_t*)"INVITE", | ||
35 | (uint8_t*)"START", | ||
36 | (uint8_t*)"CANCEL", | ||
37 | (uint8_t*)"REJECT", | ||
38 | (uint8_t*)"END" | ||
39 | }; | ||
40 | |||
41 | return strings[_request]; | ||
42 | } | ||
43 | |||
44 | typedef enum { | ||
45 | _trying, | ||
46 | _ringing, | ||
47 | _starting, | ||
48 | _ending, | ||
49 | _error | ||
50 | |||
51 | } msi_response_t; | ||
52 | |||
53 | static inline const uint8_t *stringify_response(msi_response_t _response) | ||
54 | { | ||
55 | static const uint8_t* strings[] = | ||
56 | { | ||
57 | (uint8_t*)"trying", | ||
58 | (uint8_t*)"ringing", | ||
59 | (uint8_t*)"starting", | ||
60 | (uint8_t*)"ending", | ||
61 | (uint8_t*)"error" | ||
62 | }; | ||
63 | |||
64 | return strings[_response]; | ||
65 | } | ||
66 | |||
67 | |||
68 | typedef struct msi_msg_s { | ||
69 | /* This is the header list which contains unparsed headers */ | ||
70 | msi_header_t* _headers; | ||
71 | |||
72 | /* Headers parsed */ | ||
73 | msi_header_version_t* _version; | ||
74 | msi_header_request_t* _request; | ||
75 | msi_header_response_t* _response; | ||
76 | msi_header_friendid_t* _friend_id; | ||
77 | msi_header_call_type_t* _call_type; | ||
78 | msi_header_user_agent_t* _user_agent; | ||
79 | msi_header_info_t* _info; | ||
80 | msi_header_reason_t* _reason; | ||
81 | msi_header_call_id_t* _call_id; | ||
82 | |||
83 | /* Pointer to next member since it's list duuh */ | ||
84 | struct msi_msg_s* _next; | ||
85 | |||
86 | } msi_msg_t; | ||
87 | |||
88 | |||
89 | /* | ||
90 | * Parse data received from socket | ||
91 | */ | ||
92 | msi_msg_t* msi_parse_msg ( const uint8_t* _data ); | ||
93 | |||
94 | /* | ||
95 | * Make new message. Arguments: _type: (request, response); _type_field ( value ) | ||
96 | */ | ||
97 | msi_msg_t* msi_msg_new ( uint8_t _type, const uint8_t* _type_field ); | ||
98 | |||
99 | /* Header setting */ | ||
100 | void msi_msg_set_call_type ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
101 | void msi_msg_set_user_agent ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
102 | void msi_msg_set_friend_id ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
103 | void msi_msg_set_info ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
104 | void msi_msg_set_reason ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
105 | void msi_msg_set_call_id ( msi_msg_t* _msg, const uint8_t* _header_field ); | ||
106 | |||
107 | |||
108 | uint8_t* msi_genterate_call_id ( uint8_t* _storage, size_t _len ); | ||
109 | /* | ||
110 | * Parses message struct to string. | ||
111 | * Allocates memory so don't forget to free it | ||
112 | */ | ||
113 | uint8_t* msi_msg_to_string ( msi_msg_t* _msg ); | ||
114 | |||
115 | /* | ||
116 | * msi_msg_s struct deallocator | ||
117 | */ | ||
118 | void msi_free_msg ( msi_msg_t* _msg ); | ||
119 | |||
120 | #endif /* _MSI_MESSAGE_H_ */ | ||