diff options
Diffstat (limited to 'toxav/toxmsi.c')
-rwxr-xr-x | toxav/toxmsi.c | 237 |
1 files changed, 122 insertions, 115 deletions
diff --git a/toxav/toxmsi.c b/toxav/toxmsi.c index cf0914ab..d504838a 100755 --- a/toxav/toxmsi.c +++ b/toxav/toxmsi.c | |||
@@ -119,7 +119,7 @@ typedef struct _MSIMessage { | |||
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | static MSICallback callbacks[9] = {0}; | 122 | static MSICallback callbacks[10] = {0}; |
123 | 123 | ||
124 | 124 | ||
125 | /* define strings for the identifiers */ | 125 | /* define strings for the identifiers */ |
@@ -330,10 +330,10 @@ MSIMessage* msi_new_message ( uint8_t type, const uint8_t* type_id ) { | |||
330 | memset ( _retu, 0, sizeof ( MSIMessage ) ); | 330 | memset ( _retu, 0, sizeof ( MSIMessage ) ); |
331 | 331 | ||
332 | if ( type == TYPE_REQUEST ) { | 332 | if ( type == TYPE_REQUEST ) { |
333 | ALLOCATE_HEADER ( _retu->request, type_id, strlen ( type_id ) ) | 333 | ALLOCATE_HEADER ( _retu->request, type_id, strlen ( (const char*)type_id ) ) |
334 | 334 | ||
335 | } else if ( type == TYPE_RESPONSE ) { | 335 | } else if ( type == TYPE_RESPONSE ) { |
336 | ALLOCATE_HEADER ( _retu->response, type_id, strlen ( type_id ) ) | 336 | ALLOCATE_HEADER ( _retu->response, type_id, strlen ( (const char*)type_id ) ) |
337 | 337 | ||
338 | } else { | 338 | } else { |
339 | free_message ( _retu ); | 339 | free_message ( _retu ); |
@@ -507,7 +507,7 @@ void t_randomstr ( uint8_t* str, size_t size ) { | |||
507 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 507 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
508 | "abcdefghijklmnopqrstuvwxyz"; | 508 | "abcdefghijklmnopqrstuvwxyz"; |
509 | 509 | ||
510 | int _it = 0; | 510 | size_t _it = 0; |
511 | 511 | ||
512 | for ( ; _it < size; _it++ ) { | 512 | for ( ; _it < size; _it++ ) { |
513 | str[_it] = _bytes[ randombytes_random() % 61 ]; | 513 | str[_it] = _bytes[ randombytes_random() % 61 ]; |
@@ -523,7 +523,7 @@ typedef enum { | |||
523 | error_no_call, /* no call in session */ | 523 | error_no_call, /* no call in session */ |
524 | error_no_crypto_key, /* no crypto key */ | 524 | error_no_crypto_key, /* no crypto key */ |
525 | 525 | ||
526 | error_busy, | 526 | error_busy |
527 | 527 | ||
528 | } MSICallError; /* Error codes */ | 528 | } MSICallError; /* Error codes */ |
529 | 529 | ||
@@ -675,15 +675,18 @@ void* handle_timeout ( void* arg ) | |||
675 | /* Send hangup either way */ | 675 | /* Send hangup either way */ |
676 | MSISession* _session = arg; | 676 | MSISession* _session = arg; |
677 | 677 | ||
678 | uint32_t* _peers = _session->call->peers; | 678 | if ( _session && _session->call ) { |
679 | uint16_t _peer_count = _session->call->peer_count; | 679 | |
680 | 680 | uint32_t* _peers = _session->call->peers; | |
681 | 681 | uint16_t _peer_count = _session->call->peer_count; | |
682 | /* Cancel all? */ | 682 | |
683 | uint16_t _it = 0; | 683 | |
684 | for ( ; _it < _peer_count; _it++ ) | 684 | /* Cancel all? */ |
685 | msi_cancel ( arg, _peers[_it] ); | 685 | uint16_t _it = 0; |
686 | 686 | for ( ; _it < _peer_count; _it++ ) | |
687 | msi_cancel ( arg, _peers[_it] ); | ||
688 | |||
689 | } | ||
687 | 690 | ||
688 | ( *callbacks[cb_timeout] ) ( arg ); | 691 | ( *callbacks[cb_timeout] ) ( arg ); |
689 | ( *callbacks[cb_ending ] ) ( arg ); | 692 | ( *callbacks[cb_ending ] ) ( arg ); |
@@ -714,107 +717,6 @@ void add_peer( MSICall* call, int peer_id ) | |||
714 | 717 | ||
715 | 718 | ||
716 | /** | 719 | /** |
717 | * @brief BASIC call flow: | ||
718 | * | ||
719 | * ALICE BOB | ||
720 | * | invite --> | | ||
721 | * | | | ||
722 | * | <-- ringing | | ||
723 | * | | | ||
724 | * | <-- starting | | ||
725 | * | | | ||
726 | * | start --> | | ||
727 | * | | | ||
728 | * | <-- MEDIA TRANS --> | | ||
729 | * | | | ||
730 | * | end --> | | ||
731 | * | | | ||
732 | * | <-- ending | | ||
733 | * | ||
734 | * Alice calls Bob by sending invite packet. | ||
735 | * Bob recvs the packet and sends an ringing packet; | ||
736 | * which notifies Alice that her invite is acknowledged. | ||
737 | * Ringing screen shown on both sides. | ||
738 | * Bob accepts the invite for a call by sending starting packet. | ||
739 | * Alice recvs the starting packet and sends the started packet to | ||
740 | * inform Bob that she recved the starting packet. | ||
741 | * Now the media transmission is established ( i.e. RTP transmission ). | ||
742 | * Alice hangs up and sends end packet. | ||
743 | * Bob recves the end packet and sends ending packet | ||
744 | * as the acknowledgement that the call is ending. | ||
745 | * | ||
746 | * | ||
747 | */ | ||
748 | void msi_handle_packet ( Messenger* messenger, int source, uint8_t* data, uint16_t length, void* object ) | ||
749 | { | ||
750 | MSISession* _session = object; | ||
751 | MSIMessage* _msg; | ||
752 | |||
753 | _msg = parse_message ( data ); | ||
754 | |||
755 | if ( !_msg ) return; | ||
756 | |||
757 | _msg->friend_id = source; | ||
758 | |||
759 | |||
760 | /* Now handle message */ | ||
761 | |||
762 | if ( _msg->request.header_value ) { /* Handle request */ | ||
763 | |||
764 | const uint8_t* _request_value = _msg->request.header_value; | ||
765 | |||
766 | if ( same ( _request_value, stringify_request ( invite ) ) ) { | ||
767 | handle_recv_invite ( _session, _msg ); | ||
768 | |||
769 | } else if ( same ( _request_value, stringify_request ( start ) ) ) { | ||
770 | handle_recv_start ( _session, _msg ); | ||
771 | |||
772 | } else if ( same ( _request_value, stringify_request ( cancel ) ) ) { | ||
773 | handle_recv_cancel ( _session, _msg ); | ||
774 | |||
775 | } else if ( same ( _request_value, stringify_request ( reject ) ) ) { | ||
776 | handle_recv_reject ( _session, _msg ); | ||
777 | |||
778 | } else if ( same ( _request_value, stringify_request ( end ) ) ) { | ||
779 | handle_recv_end ( _session, _msg ); | ||
780 | } | ||
781 | |||
782 | else { | ||
783 | free_message ( _msg ); | ||
784 | return; | ||
785 | } | ||
786 | |||
787 | } else if ( _msg->response.header_value ) { /* Handle response */ | ||
788 | |||
789 | const uint8_t* _response_value = _msg->response.header_value; | ||
790 | |||
791 | if ( same ( _response_value, stringify_response ( ringing ) ) ) { | ||
792 | handle_recv_ringing ( _session, _msg ); | ||
793 | |||
794 | } else if ( same ( _response_value, stringify_response ( starting ) ) ) { | ||
795 | handle_recv_starting ( _session, _msg ); | ||
796 | |||
797 | } else if ( same ( _response_value, stringify_response ( ending ) ) ) { | ||
798 | handle_recv_ending ( _session, _msg ); | ||
799 | |||
800 | } else if ( same ( _response_value, stringify_response ( error ) ) ) { | ||
801 | handle_recv_error ( _session, _msg ); | ||
802 | } else { | ||
803 | free_message ( _msg ); | ||
804 | return; | ||
805 | } | ||
806 | |||
807 | /* Got response so cancel timer */ | ||
808 | if ( _session->call ) | ||
809 | event.timer_release ( _session->call->request_timer_id ); | ||
810 | |||
811 | } | ||
812 | |||
813 | free_message ( _msg ); | ||
814 | } | ||
815 | |||
816 | |||
817 | /** | ||
818 | * @brief Speaks for it self. | 720 | * @brief Speaks for it self. |
819 | * | 721 | * |
820 | * @param session Control session. | 722 | * @param session Control session. |
@@ -1076,6 +978,111 @@ int handle_recv_error ( MSISession* session, MSIMessage* msg ) { | |||
1076 | } | 978 | } |
1077 | 979 | ||
1078 | 980 | ||
981 | /** | ||
982 | * @brief BASIC call flow: | ||
983 | * | ||
984 | * ALICE BOB | ||
985 | * | invite --> | | ||
986 | * | | | ||
987 | * | <-- ringing | | ||
988 | * | | | ||
989 | * | <-- starting | | ||
990 | * | | | ||
991 | * | start --> | | ||
992 | * | | | ||
993 | * | <-- MEDIA TRANS --> | | ||
994 | * | | | ||
995 | * | end --> | | ||
996 | * | | | ||
997 | * | <-- ending | | ||
998 | * | ||
999 | * Alice calls Bob by sending invite packet. | ||
1000 | * Bob recvs the packet and sends an ringing packet; | ||
1001 | * which notifies Alice that her invite is acknowledged. | ||
1002 | * Ringing screen shown on both sides. | ||
1003 | * Bob accepts the invite for a call by sending starting packet. | ||
1004 | * Alice recvs the starting packet and sends the started packet to | ||
1005 | * inform Bob that she recved the starting packet. | ||
1006 | * Now the media transmission is established ( i.e. RTP transmission ). | ||
1007 | * Alice hangs up and sends end packet. | ||
1008 | * Bob recves the end packet and sends ending packet | ||
1009 | * as the acknowledgement that the call is ending. | ||
1010 | * | ||
1011 | * | ||
1012 | */ | ||
1013 | void msi_handle_packet ( Messenger* messenger, int source, uint8_t* data, uint16_t length, void* object ) | ||
1014 | { | ||
1015 | /* Unused */ | ||
1016 | (void)messenger; | ||
1017 | (void)&length; | ||
1018 | |||
1019 | MSISession* _session = object; | ||
1020 | MSIMessage* _msg; | ||
1021 | |||
1022 | _msg = parse_message ( data ); | ||
1023 | |||
1024 | if ( !_msg ) return; | ||
1025 | |||
1026 | _msg->friend_id = source; | ||
1027 | |||
1028 | |||
1029 | /* Now handle message */ | ||
1030 | |||
1031 | if ( _msg->request.header_value ) { /* Handle request */ | ||
1032 | |||
1033 | const uint8_t* _request_value = _msg->request.header_value; | ||
1034 | |||
1035 | if ( same ( _request_value, stringify_request ( invite ) ) ) { | ||
1036 | handle_recv_invite ( _session, _msg ); | ||
1037 | |||
1038 | } else if ( same ( _request_value, stringify_request ( start ) ) ) { | ||
1039 | handle_recv_start ( _session, _msg ); | ||
1040 | |||
1041 | } else if ( same ( _request_value, stringify_request ( cancel ) ) ) { | ||
1042 | handle_recv_cancel ( _session, _msg ); | ||
1043 | |||
1044 | } else if ( same ( _request_value, stringify_request ( reject ) ) ) { | ||
1045 | handle_recv_reject ( _session, _msg ); | ||
1046 | |||
1047 | } else if ( same ( _request_value, stringify_request ( end ) ) ) { | ||
1048 | handle_recv_end ( _session, _msg ); | ||
1049 | } | ||
1050 | |||
1051 | else { | ||
1052 | free_message ( _msg ); | ||
1053 | return; | ||
1054 | } | ||
1055 | |||
1056 | } else if ( _msg->response.header_value ) { /* Handle response */ | ||
1057 | |||
1058 | const uint8_t* _response_value = _msg->response.header_value; | ||
1059 | |||
1060 | if ( same ( _response_value, stringify_response ( ringing ) ) ) { | ||
1061 | handle_recv_ringing ( _session, _msg ); | ||
1062 | |||
1063 | } else if ( same ( _response_value, stringify_response ( starting ) ) ) { | ||
1064 | handle_recv_starting ( _session, _msg ); | ||
1065 | |||
1066 | } else if ( same ( _response_value, stringify_response ( ending ) ) ) { | ||
1067 | handle_recv_ending ( _session, _msg ); | ||
1068 | |||
1069 | } else if ( same ( _response_value, stringify_response ( error ) ) ) { | ||
1070 | handle_recv_error ( _session, _msg ); | ||
1071 | } else { | ||
1072 | free_message ( _msg ); | ||
1073 | return; | ||
1074 | } | ||
1075 | |||
1076 | /* Got response so cancel timer */ | ||
1077 | if ( _session->call ) | ||
1078 | event.timer_release ( _session->call->request_timer_id ); | ||
1079 | |||
1080 | } | ||
1081 | |||
1082 | free_message ( _msg ); | ||
1083 | } | ||
1084 | |||
1085 | |||
1079 | /******************************************************************************************************************** | 1086 | /******************************************************************************************************************** |
1080 | * ******************************************************************************************************************* | 1087 | * ******************************************************************************************************************* |
1081 | ******************************************************************************************************************** | 1088 | ******************************************************************************************************************** |