diff options
Diffstat (limited to 'toxav/msi.c')
-rw-r--r-- | toxav/msi.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index c7d729b9..6a529699 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -167,11 +167,11 @@ typedef enum { | |||
167 | static inline__ const uint8_t *stringify_request ( MSIRequest request ) | 167 | static inline__ const uint8_t *stringify_request ( MSIRequest request ) |
168 | { | 168 | { |
169 | static const uint8_t *strings[] = { | 169 | static const uint8_t *strings[] = { |
170 | ( uint8_t * ) "INVITE", | 170 | ( uint8_t *) "INVITE", |
171 | ( uint8_t * ) "START", | 171 | ( uint8_t *) "START", |
172 | ( uint8_t * ) "CANCEL", | 172 | ( uint8_t *) "CANCEL", |
173 | ( uint8_t * ) "REJECT", | 173 | ( uint8_t *) "REJECT", |
174 | ( uint8_t * ) "END" | 174 | ( uint8_t *) "END" |
175 | }; | 175 | }; |
176 | 176 | ||
177 | return strings[request]; | 177 | return strings[request]; |
@@ -196,10 +196,10 @@ typedef enum { | |||
196 | static inline__ const uint8_t *stringify_response ( MSIResponse response ) | 196 | static inline__ const uint8_t *stringify_response ( MSIResponse response ) |
197 | { | 197 | { |
198 | static const uint8_t *strings[] = { | 198 | static const uint8_t *strings[] = { |
199 | ( uint8_t * ) "ringing", | 199 | ( uint8_t *) "ringing", |
200 | ( uint8_t * ) "starting", | 200 | ( uint8_t *) "starting", |
201 | ( uint8_t * ) "ending", | 201 | ( uint8_t *) "ending", |
202 | ( uint8_t * ) "error" | 202 | ( uint8_t *) "error" |
203 | }; | 203 | }; |
204 | 204 | ||
205 | return strings[response]; | 205 | return strings[response]; |
@@ -243,7 +243,7 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte | |||
243 | 243 | ||
244 | const uint8_t *_it = data; | 244 | const uint8_t *_it = data; |
245 | uint16_t size_max = length; | 245 | uint16_t size_max = length; |
246 | 246 | ||
247 | while ( *_it ) {/* until end_byte is hit */ | 247 | while ( *_it ) {/* until end_byte is hit */ |
248 | 248 | ||
249 | uint16_t itedlen = (_it - data) + 2; | 249 | uint16_t itedlen = (_it - data) + 2; |
@@ -251,14 +251,14 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte | |||
251 | if ( *_it == field_byte && itedlen < length ) { | 251 | if ( *_it == field_byte && itedlen < length ) { |
252 | 252 | ||
253 | uint16_t _size; | 253 | uint16_t _size; |
254 | memcpy(&_size, _it + 1, sizeof(_size)); | 254 | memcpy(&_size, _it + 1, sizeof(_size)); |
255 | _size = ntohs(_size); | 255 | _size = ntohs(_size); |
256 | 256 | ||
257 | if ( itedlen + _size > length ) return -1; | 257 | if ( itedlen + _size > length ) return -1; |
258 | 258 | ||
259 | _it += 3; /* place it at the field value beginning */ | 259 | _it += 3; /* place it at the field value beginning */ |
260 | size_max -= 3; | 260 | size_max -= 3; |
261 | 261 | ||
262 | switch ( _size ) { /* Compare the size of the hardcoded values ( vary fast and convenient ) */ | 262 | switch ( _size ) { /* Compare the size of the hardcoded values ( vary fast and convenient ) */ |
263 | 263 | ||
264 | case 4: { /* INFO header */ | 264 | case 4: { /* INFO header */ |
@@ -278,9 +278,9 @@ iterator = iterator + 2 + _value_size; /* set iterator at new header or end_byte | |||
278 | 278 | ||
279 | case 7: { /* Version, Request, Call-id headers */ | 279 | case 7: { /* Version, Request, Call-id headers */ |
280 | if ON_HEADER ( _it, size_max, msg->version, VERSION_FIELD, 7 ) | 280 | if ON_HEADER ( _it, size_max, msg->version, VERSION_FIELD, 7 ) |
281 | else if ON_HEADER ( _it, size_max, msg->request, REQUEST_FIELD, 7 ) | 281 | else if ON_HEADER ( _it, size_max, msg->request, REQUEST_FIELD, 7 ) |
282 | else if ON_HEADER ( _it, size_max, msg->callid, CALLID_FIELD, 7 ) | 282 | else if ON_HEADER ( _it, size_max, msg->callid, CALLID_FIELD, 7 ) |
283 | } | 283 | } |
284 | break; | 284 | break; |
285 | 285 | ||
286 | case 8: { /* Response header */ | 286 | case 8: { /* Response header */ |
@@ -513,9 +513,10 @@ uint8_t *append_header_to_string ( | |||
513 | 513 | ||
514 | /* Now set the length of the field byte */ | 514 | /* Now set the length of the field byte */ |
515 | uint16_t _convert; | 515 | uint16_t _convert; |
516 | 516 | ||
517 | 517 | ||
518 | _convert = htons(_i); | 518 | _convert = htons(_i); |
519 | |||
519 | memcpy(_getback_byte, &_convert, sizeof(_convert)); | 520 | memcpy(_getback_byte, &_convert, sizeof(_convert)); |
520 | 521 | ||
521 | /* for value part do it regulary */ | 522 | /* for value part do it regulary */ |
@@ -523,11 +524,12 @@ uint8_t *append_header_to_string ( | |||
523 | 524 | ||
524 | dest++; | 525 | dest++; |
525 | 526 | ||
526 | 527 | ||
527 | _convert = htons(value_len); | 528 | _convert = htons(value_len); |
529 | |||
528 | memcpy(dest, &_convert, sizeof(_convert)); | 530 | memcpy(dest, &_convert, sizeof(_convert)); |
529 | 531 | ||
530 | dest+=2; | 532 | dest += 2; |
531 | 533 | ||
532 | for ( _i = value_len; _i; --_i ) { | 534 | for ( _i = value_len; _i; --_i ) { |
533 | *dest = *_hvit; | 535 | *dest = *_hvit; |
@@ -645,13 +647,13 @@ typedef enum { | |||
645 | static inline__ const uint8_t *stringify_error ( MSICallError error_code ) | 647 | static inline__ const uint8_t *stringify_error ( MSICallError error_code ) |
646 | { | 648 | { |
647 | static const uint8_t *strings[] = { | 649 | static const uint8_t *strings[] = { |
648 | ( uint8_t * ) "", | 650 | ( uint8_t *) "", |
649 | ( uint8_t * ) "Using dead call", | 651 | ( uint8_t *) "Using dead call", |
650 | ( uint8_t * ) "Call id not set to any call", | 652 | ( uint8_t *) "Call id not set to any call", |
651 | ( uint8_t * ) "Call id not available", | 653 | ( uint8_t *) "Call id not available", |
652 | ( uint8_t * ) "No active call in session", | 654 | ( uint8_t *) "No active call in session", |
653 | ( uint8_t * ) "No Crypto-key set", | 655 | ( uint8_t *) "No Crypto-key set", |
654 | ( uint8_t * ) "Callee busy" | 656 | ( uint8_t *) "Callee busy" |
655 | }; | 657 | }; |
656 | 658 | ||
657 | return strings[error_code]; | 659 | return strings[error_code]; |
@@ -667,13 +669,13 @@ static inline__ const uint8_t *stringify_error ( MSICallError error_code ) | |||
667 | static inline__ const uint8_t *stringify_error_code ( MSICallError error_code ) | 669 | static inline__ const uint8_t *stringify_error_code ( MSICallError error_code ) |
668 | { | 670 | { |
669 | static const uint8_t *strings[] = { | 671 | static const uint8_t *strings[] = { |
670 | ( uint8_t * ) "", | 672 | ( uint8_t *) "", |
671 | ( uint8_t * ) "1", | 673 | ( uint8_t *) "1", |
672 | ( uint8_t * ) "2", | 674 | ( uint8_t *) "2", |
673 | ( uint8_t * ) "3", | 675 | ( uint8_t *) "3", |
674 | ( uint8_t * ) "4", | 676 | ( uint8_t *) "4", |
675 | ( uint8_t * ) "5", | 677 | ( uint8_t *) "5", |
676 | ( uint8_t * ) "6" | 678 | ( uint8_t *) "6" |
677 | }; | 679 | }; |
678 | 680 | ||
679 | return strings[error_code]; | 681 | return strings[error_code]; |
@@ -756,10 +758,10 @@ void flush_peer_type ( MSICall *call, MSIMessage *msg, int peer_id ) | |||
756 | memcpy(hdrval, msg->calltype.header_value, msg->calltype.size); | 758 | memcpy(hdrval, msg->calltype.header_value, msg->calltype.size); |
757 | hdrval[msg->calltype.size] = '\0'; | 759 | hdrval[msg->calltype.size] = '\0'; |
758 | 760 | ||
759 | if ( strcmp ( ( const char * ) hdrval, CT_AUDIO_HEADER_VALUE ) == 0 ) { | 761 | if ( strcmp ( ( const char *) hdrval, CT_AUDIO_HEADER_VALUE ) == 0 ) { |
760 | call->type_peer[peer_id] = type_audio; | 762 | call->type_peer[peer_id] = type_audio; |
761 | 763 | ||
762 | } else if ( strcmp ( ( const char * ) hdrval, CT_VIDEO_HEADER_VALUE ) == 0 ) { | 764 | } else if ( strcmp ( ( const char *) hdrval, CT_VIDEO_HEADER_VALUE ) == 0 ) { |
763 | call->type_peer[peer_id] = type_video; | 765 | call->type_peer[peer_id] = type_video; |
764 | } else {} /* Error */ | 766 | } else {} /* Error */ |
765 | } else {} /* Error */ | 767 | } else {} /* Error */ |
@@ -831,7 +833,7 @@ int handle_error ( MSISession *session, MSICall *call, MSICallError errid, uint3 | |||
831 | 833 | ||
832 | const uint8_t *_error_code_str = stringify_error_code ( errid ); | 834 | const uint8_t *_error_code_str = stringify_error_code ( errid ); |
833 | 835 | ||
834 | msi_msg_set_reason ( _msg_error, _error_code_str, strlen ( ( const char * ) _error_code_str ) ); | 836 | msi_msg_set_reason ( _msg_error, _error_code_str, strlen ( ( const char *) _error_code_str ) ); |
835 | send_message ( session, call, _msg_error, to ); | 837 | send_message ( session, call, _msg_error, to ); |
836 | free_message ( _msg_error ); | 838 | free_message ( _msg_error ); |
837 | 839 | ||
@@ -1325,7 +1327,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1325 | 1327 | ||
1326 | /* Handle error accordingly */ | 1328 | /* Handle error accordingly */ |
1327 | if ( msg->reason.header_value ) { | 1329 | if ( msg->reason.header_value ) { |
1328 | session->last_error_id = atoi ( ( const char * ) msg->reason.header_value ); | 1330 | session->last_error_id = atoi ( ( const char *) msg->reason.header_value ); |
1329 | session->last_error_str = stringify_error ( session->last_error_id ); | 1331 | session->last_error_str = stringify_error ( session->last_error_id ); |
1330 | LOGGER_DEBUG("Error reason: %s", session->last_error_str); | 1332 | LOGGER_DEBUG("Error reason: %s", session->last_error_str); |
1331 | } | 1333 | } |
@@ -1612,9 +1614,9 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type | |||
1612 | 1614 | ||
1613 | /* Do whatever with message */ | 1615 | /* Do whatever with message */ |
1614 | if ( call_type == type_audio ) { | 1616 | if ( call_type == type_audio ) { |
1615 | msi_msg_set_calltype ( _msg_invite, ( const uint8_t * ) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); | 1617 | msi_msg_set_calltype ( _msg_invite, ( const uint8_t *) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); |
1616 | } else { | 1618 | } else { |
1617 | msi_msg_set_calltype ( _msg_invite, ( const uint8_t * ) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); | 1619 | msi_msg_set_calltype ( _msg_invite, ( const uint8_t *) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); |
1618 | } | 1620 | } |
1619 | 1621 | ||
1620 | send_message ( session, _call, _msg_invite, friend_id ); | 1622 | send_message ( session, _call, _msg_invite, friend_id ); |
@@ -1702,10 +1704,10 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type | |||
1702 | 1704 | ||
1703 | if ( call_type == type_audio ) { | 1705 | if ( call_type == type_audio ) { |
1704 | msi_msg_set_calltype | 1706 | msi_msg_set_calltype |
1705 | ( _msg_starting, ( const uint8_t * ) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); | 1707 | ( _msg_starting, ( const uint8_t *) CT_AUDIO_HEADER_VALUE, strlen ( CT_AUDIO_HEADER_VALUE ) ); |
1706 | } else { | 1708 | } else { |
1707 | msi_msg_set_calltype | 1709 | msi_msg_set_calltype |
1708 | ( _msg_starting, ( const uint8_t * ) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); | 1710 | ( _msg_starting, ( const uint8_t *) CT_VIDEO_HEADER_VALUE, strlen ( CT_VIDEO_HEADER_VALUE ) ); |
1709 | } | 1711 | } |
1710 | 1712 | ||
1711 | /* Now set the local encryption key and pass it with STARTING message */ | 1713 | /* Now set the local encryption key and pass it with STARTING message */ |