summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
Diffstat (limited to 'toxav')
-rw-r--r--toxav/msi.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 26b37292..dca5fe1e 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -207,7 +207,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
207 * @retval -1 Error occurred. 207 * @retval -1 Error occurred.
208 * @retval 0 Success. 208 * @retval 0 Success.
209 */ 209 */
210int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length ) 210static int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length )
211{ 211{
212 212
213#define ON_HEADER(iterator, size_con, header, descriptor, type_size_const) \ 213#define ON_HEADER(iterator, size_con, header, descriptor, type_size_const) \
@@ -308,7 +308,7 @@ var.size = t_size; }
308 * @param msg The message. 308 * @param msg The message.
309 * @return void 309 * @return void
310 */ 310 */
311void free_message ( MSIMessage *msg ) 311static void free_message ( MSIMessage *msg )
312{ 312{
313 if ( msg == NULL ) { 313 if ( msg == NULL ) {
314 LOGGER_WARNING("Tried to free empty message"); 314 LOGGER_WARNING("Tried to free empty message");
@@ -335,7 +335,7 @@ void free_message ( MSIMessage *msg )
335 * @return MSIMessage* Created message. 335 * @return MSIMessage* Created message.
336 * @retval NULL Error occurred. 336 * @retval NULL Error occurred.
337 */ 337 */
338MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id ) 338static MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
339{ 339{
340 MSIMessage *_retu = calloc ( sizeof ( MSIMessage ), 1 ); 340 MSIMessage *_retu = calloc ( sizeof ( MSIMessage ), 1 );
341 341
@@ -368,7 +368,7 @@ MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
368 * @return MSIMessage* Parsed message. 368 * @return MSIMessage* Parsed message.
369 * @retval NULL Error occurred. 369 * @retval NULL Error occurred.
370 */ 370 */
371MSIMessage *parse_message ( const uint8_t *data, uint16_t length ) 371static MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
372{ 372{
373 if ( data == NULL ) { 373 if ( data == NULL ) {
374 LOGGER_WARNING("Tried to parse empty message!"); 374 LOGGER_WARNING("Tried to parse empty message!");
@@ -411,7 +411,7 @@ MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
411 * @param length Pointer to container length. 411 * @param length Pointer to container length.
412 * @return uint8_t* Iterated container. 412 * @return uint8_t* Iterated container.
413 */ 413 */
414uint8_t *append_header_to_string ( 414static uint8_t *append_header_to_string (
415 uint8_t *dest, 415 uint8_t *dest,
416 const uint8_t *header_field, 416 const uint8_t *header_field,
417 const uint8_t *header_value, 417 const uint8_t *header_value,
@@ -490,7 +490,7 @@ uint8_t *append_header_to_string (
490 * @param dest Destination. 490 * @param dest Destination.
491 * @return uint16_t It's final size. 491 * @return uint16_t It's final size.
492 */ 492 */
493uint16_t message_to_send ( MSIMessage *msg, uint8_t *dest ) 493static uint16_t message_to_send ( MSIMessage *msg, uint8_t *dest )
494{ 494{
495#define CLEAN_ASSIGN(added, var, field, header)\ 495#define CLEAN_ASSIGN(added, var, field, header)\
496 if ( header.header_value ) { var = append_header_to_string(var, (const uint8_t*)field, header.header_value, header.size, &added); } 496 if ( header.header_value ) { var = append_header_to_string(var, (const uint8_t*)field, header.header_value, header.size, &added); }
@@ -572,7 +572,7 @@ struct timer_function_args {
572 * @param timeout Timeout in ms 572 * @param timeout Timeout in ms
573 * @return int 573 * @return int
574 */ 574 */
575int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *arg1, int arg2, unsigned timeout) 575static int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *arg1, int arg2, unsigned timeout)
576{ 576{
577 static int timer_id; 577 static int timer_id;
578 pthread_mutex_lock(&timers_container->mutex); 578 pthread_mutex_lock(&timers_container->mutex);
@@ -629,7 +629,7 @@ int timer_alloc ( TimerHandler *timers_container, void *(func)(void *), void *ar
629 * @param lock_mutex (does the mutex need to be locked) 629 * @param lock_mutex (does the mutex need to be locked)
630 * @return int 630 * @return int
631 */ 631 */
632int timer_release ( TimerHandler *timers_container, int idx , int lock_mutex) 632static int timer_release ( TimerHandler *timers_container, int idx , int lock_mutex)
633{ 633{
634 if (lock_mutex) 634 if (lock_mutex)
635 pthread_mutex_lock(&timers_container->mutex); 635 pthread_mutex_lock(&timers_container->mutex);
@@ -679,7 +679,7 @@ int timer_release ( TimerHandler *timers_container, int idx , int lock_mutex)
679 * @param arg ... 679 * @param arg ...
680 * @return void* 680 * @return void*
681 */ 681 */
682void *timer_poll( void *arg ) 682static void *timer_poll( void *arg )
683{ 683{
684 TimerHandler *handler = arg; 684 TimerHandler *handler = arg;
685 685
@@ -726,7 +726,7 @@ void *timer_poll( void *arg )
726 * @param resolution ... 726 * @param resolution ...
727 * @return TimerHandler* 727 * @return TimerHandler*
728 */ 728 */
729TimerHandler *timer_init_session (int max_capacity, int resolution) 729static TimerHandler *timer_init_session (int max_capacity, int resolution)
730{ 730{
731 TimerHandler *handler = calloc(1, sizeof(TimerHandler)); 731 TimerHandler *handler = calloc(1, sizeof(TimerHandler));
732 732
@@ -768,7 +768,7 @@ TimerHandler *timer_init_session (int max_capacity, int resolution)
768 * @param handler The timer handler 768 * @param handler The timer handler
769 * @return void 769 * @return void
770 */ 770 */
771void timer_terminate_session(TimerHandler *handler) 771static void timer_terminate_session(TimerHandler *handler)
772{ 772{
773 pthread_mutex_lock(&handler->mutex); 773 pthread_mutex_lock(&handler->mutex);
774 774
@@ -793,7 +793,7 @@ void timer_terminate_session(TimerHandler *handler)
793 * @param size Size of string. 793 * @param size Size of string.
794 * @return void 794 * @return void
795 */ 795 */
796void t_randomstr ( uint8_t *str, uint32_t size ) 796static void t_randomstr ( uint8_t *str, uint32_t size )
797{ 797{
798 if (str == NULL) { 798 if (str == NULL) {
799 LOGGER_DEBUG("Empty destination!"); 799 LOGGER_DEBUG("Empty destination!");
@@ -881,7 +881,7 @@ static inline__ const uint8_t *stringify_error_code ( MSICallError error_code )
881 * @retval -1 Error occurred. 881 * @retval -1 Error occurred.
882 * @retval 0 Success. 882 * @retval 0 Success.
883 */ 883 */
884int send_message ( MSISession *session, MSICall *call, MSIMessage *msg, uint32_t to ) 884static int send_message ( MSISession *session, MSICall *call, MSIMessage *msg, uint32_t to )
885{ 885{
886 msi_msg_set_callid ( msg, call->id, CALL_ID_LEN ); 886 msi_msg_set_callid ( msg, call->id, CALL_ID_LEN );
887 887
@@ -911,7 +911,7 @@ int send_message ( MSISession *session, MSICall *call, MSIMessage *msg, uint32_t
911 * @retval 0 it's first 911 * @retval 0 it's first
912 * @retval 1 it's second 912 * @retval 1 it's second
913 */ 913 */
914int call_id_bigger( const uint8_t *first, const uint8_t *second) 914static int call_id_bigger( const uint8_t *first, const uint8_t *second)
915{ 915{
916 return (memcmp(first, second, CALL_ID_LEN) < 0); 916 return (memcmp(first, second, CALL_ID_LEN) < 0);
917} 917}
@@ -925,7 +925,7 @@ int call_id_bigger( const uint8_t *first, const uint8_t *second)
925 * @param peer_id The peer. 925 * @param peer_id The peer.
926 * @return void 926 * @return void
927 */ 927 */
928void flush_peer_type ( MSICall *call, MSIMessage *msg, int peer_id ) 928static void flush_peer_type ( MSICall *call, MSIMessage *msg, int peer_id )
929{ 929{
930 if ( msg->calltype.header_value ) { 930 if ( msg->calltype.header_value ) {
931 uint8_t hdrval [MSI_MAXMSG_SIZE]; /* Make sure no overflow */ 931 uint8_t hdrval [MSI_MAXMSG_SIZE]; /* Make sure no overflow */
@@ -942,7 +942,9 @@ void flush_peer_type ( MSICall *call, MSIMessage *msg, int peer_id )
942 } else {} /* Error */ 942 } else {} /* Error */
943} 943}
944 944
945void handle_remote_connection_change(Messenger *messenger, int friend_num, uint8_t status, void *session_p) 945static int terminate_call ( MSISession *session, MSICall *call );
946
947static void handle_remote_connection_change(Messenger *messenger, int friend_num, uint8_t status, void *session_p)
946{ 948{
947 MSISession *session = session_p; 949 MSISession *session = session_p;
948 950
@@ -972,7 +974,7 @@ void handle_remote_connection_change(Messenger *messenger, int friend_num, uint8
972 } 974 }
973} 975}
974 976
975MSICall *find_call ( MSISession *session, uint8_t *call_id ) 977static MSICall *find_call ( MSISession *session, uint8_t *call_id )
976{ 978{
977 if ( call_id == NULL ) return NULL; 979 if ( call_id == NULL ) return NULL;
978 980
@@ -1000,7 +1002,7 @@ MSICall *find_call ( MSISession *session, uint8_t *call_id )
1000 * @return int 1002 * @return int
1001 * @retval -1/0 It's usually always success. 1003 * @retval -1/0 It's usually always success.
1002 */ 1004 */
1003int send_error ( MSISession *session, MSICall *call, MSICallError errid, uint32_t to ) 1005static int send_error ( MSISession *session, MSICall *call, MSICallError errid, uint32_t to )
1004{ 1006{
1005 if (!call) { 1007 if (!call) {
1006 LOGGER_WARNING("Cannot handle error on 'null' call"); 1008 LOGGER_WARNING("Cannot handle error on 'null' call");
@@ -1034,7 +1036,7 @@ int send_error ( MSISession *session, MSICall *call, MSICallError errid, uint32_
1034 * @param peer_id Its id. 1036 * @param peer_id Its id.
1035 * @return void 1037 * @return void
1036 */ 1038 */
1037void add_peer( MSICall *call, int peer_id ) 1039static void add_peer( MSICall *call, int peer_id )
1038{ 1040{
1039 uint32_t *peers = !call->peers ? peers = calloc(sizeof(uint32_t), 1) : 1041 uint32_t *peers = !call->peers ? peers = calloc(sizeof(uint32_t), 1) :
1040 realloc( call->peers, sizeof(uint32_t) * call->peer_count); 1042 realloc( call->peers, sizeof(uint32_t) * call->peer_count);
@@ -1060,7 +1062,7 @@ void add_peer( MSICall *call, int peer_id )
1060 * @param ringing_timeout Ringing timeout. 1062 * @param ringing_timeout Ringing timeout.
1061 * @return MSICall* The created call. 1063 * @return MSICall* The created call.
1062 */ 1064 */
1063MSICall *init_call ( MSISession *session, int peers, int ringing_timeout ) 1065static MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
1064{ 1066{
1065 1067
1066 if (peers == 0) { 1068 if (peers == 0) {
@@ -1122,7 +1124,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
1122 * @retval -1 Error occurred. 1124 * @retval -1 Error occurred.
1123 * @retval 0 Success. 1125 * @retval 0 Success.
1124 */ 1126 */
1125int terminate_call ( MSISession *session, MSICall *call ) 1127static int terminate_call ( MSISession *session, MSICall *call )
1126{ 1128{
1127 if ( !call ) { 1129 if ( !call ) {
1128 LOGGER_WARNING("Tried to terminate non-existing call!"); 1130 LOGGER_WARNING("Tried to terminate non-existing call!");
@@ -1167,7 +1169,7 @@ int terminate_call ( MSISession *session, MSICall *call )
1167 * @param arg Control session 1169 * @param arg Control session
1168 * @return void* 1170 * @return void*
1169 */ 1171 */
1170void *handle_timeout ( void *arg ) 1172static void *handle_timeout ( void *arg )
1171{ 1173{
1172 /* TODO: Cancel might not arrive there; set up 1174 /* TODO: Cancel might not arrive there; set up
1173 * timers on these cancels and terminate call on 1175 * timers on these cancels and terminate call on
@@ -1199,7 +1201,7 @@ void *handle_timeout ( void *arg )
1199 1201
1200 1202
1201/********** Request handlers **********/ 1203/********** Request handlers **********/
1202int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) 1204static int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1203{ 1205{
1204 LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new"); 1206 LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new");
1205 1207
@@ -1273,7 +1275,8 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
1273 1275
1274 return 1; 1276 return 1;
1275} 1277}
1276int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg ) 1278
1279static int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
1277{ 1280{
1278 if ( !call ) { 1281 if ( !call ) {
1279 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1282 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1293,7 +1296,8 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
1293 invoke_callback(call->call_idx, MSI_OnStart); 1296 invoke_callback(call->call_idx, MSI_OnStart);
1294 return 1; 1297 return 1;
1295} 1298}
1296int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg ) 1299
1300static int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
1297{ 1301{
1298 if ( !call ) { 1302 if ( !call ) {
1299 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1303 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1316,7 +1320,8 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
1316 terminate_call(session, call); 1320 terminate_call(session, call);
1317 return 1; 1321 return 1;
1318} 1322}
1319int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg ) 1323
1324static int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
1320{ 1325{
1321 if ( !call ) { 1326 if ( !call ) {
1322 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1327 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1335,7 +1340,8 @@ int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
1335 terminate_call ( session, call ); 1340 terminate_call ( session, call );
1336 return 1; 1341 return 1;
1337} 1342}
1338int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg ) 1343
1344static int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
1339{ 1345{
1340 if ( !call ) { 1346 if ( !call ) {
1341 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1347 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1359,7 +1365,7 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
1359} 1365}
1360 1366
1361/********** Response handlers **********/ 1367/********** Response handlers **********/
1362int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg ) 1368static int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
1363{ 1369{
1364 if ( !call ) { 1370 if ( !call ) {
1365 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1371 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1384,7 +1390,7 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
1384 invoke_callback(call->call_idx, MSI_OnRinging); 1390 invoke_callback(call->call_idx, MSI_OnRinging);
1385 return 1; 1391 return 1;
1386} 1392}
1387int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg ) 1393static int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
1388{ 1394{
1389 if ( !call ) { 1395 if ( !call ) {
1390 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1396 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1410,7 +1416,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
1410 invoke_callback(call->call_idx, MSI_OnStarting); 1416 invoke_callback(call->call_idx, MSI_OnStarting);
1411 return 1; 1417 return 1;
1412} 1418}
1413int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg ) 1419static int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
1414{ 1420{
1415 if ( !call ) { 1421 if ( !call ) {
1416 LOGGER_WARNING("Session: %p Handling 'start' on no call"); 1422 LOGGER_WARNING("Session: %p Handling 'start' on no call");
@@ -1433,7 +1439,7 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
1433 1439
1434 return 1; 1440 return 1;
1435} 1441}
1436int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) 1442static int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
1437{ 1443{
1438 pthread_mutex_lock(&session->mutex); 1444 pthread_mutex_lock(&session->mutex);
1439 1445
@@ -1494,7 +1500,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
1494 * 1500 *
1495 * 1501 *
1496 */ 1502 */
1497void msi_handle_packet ( Messenger *messenger, int source, const uint8_t *data, uint16_t length, void *object ) 1503static void msi_handle_packet ( Messenger *messenger, int source, const uint8_t *data, uint16_t length, void *object )
1498{ 1504{
1499 LOGGER_DEBUG("Got msi message"); 1505 LOGGER_DEBUG("Got msi message");
1500 /* Unused */ 1506 /* Unused */