summaryrefslogtreecommitdiff
path: root/toxav/msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/msi.c')
-rwxr-xr-xtoxav/msi.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 17c0b5c3..7cc55de2 100755
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -36,6 +36,8 @@
36#include <string.h> 36#include <string.h>
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#define inline__ inline __attribute__((always_inline))
40
39#define same(x, y) strcmp((const char*) x, (const char*) y) == 0 41#define same(x, y) strcmp((const char*) x, (const char*) y) == 0
40 42
41#define MSI_MAXMSG_SIZE 1024 43#define MSI_MAXMSG_SIZE 1024
@@ -117,6 +119,12 @@ static struct _Callbacks {
117 void* data; 119 void* data;
118} callbacks[10] = {0}; 120} callbacks[10] = {0};
119 121
122inline__ void invoke_callback(MSICallbackID id)
123{
124 /*if ( callbacks[id].function ) event.rise ( callbacks[id].function, callbacks[id].data );*/
125 if ( callbacks[id].function ) callbacks[id].function ( callbacks[id].data );
126}
127
120/*static MSICallback callbacks[10] = {0};*/ 128/*static MSICallback callbacks[10] = {0};*/
121 129
122 130
@@ -153,7 +161,7 @@ typedef enum {
153 * @param request The request. 161 * @param request The request.
154 * @return const uint8_t* The string 162 * @return const uint8_t* The string
155 */ 163 */
156static inline const uint8_t *stringify_request ( MSIRequest request ) 164static inline__ const uint8_t *stringify_request ( MSIRequest request )
157{ 165{
158 static const uint8_t *strings[] = { 166 static const uint8_t *strings[] = {
159 ( uint8_t * ) "INVITE", 167 ( uint8_t * ) "INVITE",
@@ -182,7 +190,7 @@ typedef enum {
182 * @param response The response. 190 * @param response The response.
183 * @return const uint8_t* The string 191 * @return const uint8_t* The string
184 */ 192 */
185static inline const uint8_t *stringify_response ( MSIResponse response ) 193static inline__ const uint8_t *stringify_response ( MSIResponse response )
186{ 194{
187 static const uint8_t *strings[] = { 195 static const uint8_t *strings[] = {
188 ( uint8_t * ) "ringing", 196 ( uint8_t * ) "ringing",
@@ -550,7 +558,7 @@ typedef enum {
550 * @param error_code The code. 558 * @param error_code The code.
551 * @return const uint8_t* The string. 559 * @return const uint8_t* The string.
552 */ 560 */
553static inline const uint8_t *stringify_error ( MSICallError error_code ) 561static inline__ const uint8_t *stringify_error ( MSICallError error_code )
554{ 562{
555 static const uint8_t *strings[] = { 563 static const uint8_t *strings[] = {
556 ( uint8_t * ) "", 564 ( uint8_t * ) "",
@@ -572,7 +580,7 @@ static inline const uint8_t *stringify_error ( MSICallError error_code )
572 * @param error_code The code. 580 * @param error_code The code.
573 * @return const uint8_t* The string. 581 * @return const uint8_t* The string.
574 */ 582 */
575static inline const uint8_t *stringify_error_code ( MSICallError error_code ) 583static inline__ const uint8_t *stringify_error_code ( MSICallError error_code )
576{ 584{
577 static const uint8_t *strings[] = { 585 static const uint8_t *strings[] = {
578 ( uint8_t * ) "", 586 ( uint8_t * ) "",
@@ -679,7 +687,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to )
679 session->last_error_id = errid; 687 session->last_error_id = errid;
680 session->last_error_str = stringify_error ( errid ); 688 session->last_error_str = stringify_error ( errid );
681 689
682 if ( callbacks[MSI_OnError].function ) event.rise ( callbacks[MSI_OnError].function, callbacks[MSI_OnError].data ); 690 invoke_callback(MSI_OnError);
683 691
684 return 0; 692 return 0;
685} 693}
@@ -873,7 +881,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg )
873 send_message ( session, _msg_ringing, msg->friend_id ); 881 send_message ( session, _msg_ringing, msg->friend_id );
874 free_message ( _msg_ringing ); 882 free_message ( _msg_ringing );
875 883
876 if ( callbacks[MSI_OnInvite].function ) event.rise ( callbacks[MSI_OnInvite].function, callbacks[MSI_OnInvite].data ); 884 invoke_callback(MSI_OnInvite);
877 885
878 return 1; 886 return 1;
879} 887}
@@ -897,7 +905,7 @@ int handle_recv_start ( MSISession *session, MSIMessage *msg )
897 905
898 flush_peer_type ( session, msg, 0 ); 906 flush_peer_type ( session, msg, 0 );
899 907
900 if ( callbacks[MSI_OnStart].function ) event.rise ( callbacks[MSI_OnStart].function, callbacks[MSI_OnStart].data ); 908 invoke_callback(MSI_OnStart);
901 909
902 return 1; 910 return 1;
903} 911}
@@ -914,7 +922,9 @@ int handle_recv_reject ( MSISession *session, MSIMessage *msg )
914 free_message ( _msg_end ); 922 free_message ( _msg_end );
915 923
916 event.timer_release ( session->call->request_timer_id ); 924 event.timer_release ( session->call->request_timer_id );
917 if ( callbacks[MSI_OnReject].function ) event.rise ( callbacks[MSI_OnReject].function, callbacks[MSI_OnReject].data ); 925
926 invoke_callback(MSI_OnReject);
927
918 session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout ); 928 session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout );
919 929
920 return 1; 930 return 1;
@@ -925,12 +935,11 @@ int handle_recv_cancel ( MSISession *session, MSIMessage *msg )
925 935
926 if ( has_call_error ( session, msg ) == 0 ) 936 if ( has_call_error ( session, msg ) == 0 )
927 return 0; 937 return 0;
928 938
929 939 invoke_callback(MSI_OnCancel);
940
930 terminate_call ( session ); 941 terminate_call ( session );
931 942
932 if ( callbacks[MSI_OnCancel].function ) event.rise ( callbacks[MSI_OnCancel].function, callbacks[MSI_OnCancel].data );
933
934 return 1; 943 return 1;
935} 944}
936int handle_recv_end ( MSISession *session, MSIMessage *msg ) 945int handle_recv_end ( MSISession *session, MSIMessage *msg )
@@ -945,10 +954,9 @@ int handle_recv_end ( MSISession *session, MSIMessage *msg )
945 send_message ( session, _msg_ending, msg->friend_id ); 954 send_message ( session, _msg_ending, msg->friend_id );
946 free_message ( _msg_ending ); 955 free_message ( _msg_ending );
947 956
948 terminate_call ( session ); 957 invoke_callback(MSI_OnEnd);
949
950 if ( callbacks[MSI_OnEnd].function ) event.rise ( callbacks[MSI_OnEnd].function, callbacks[MSI_OnEnd].data );
951 958
959 terminate_call ( session );
952 return 1; 960 return 1;
953} 961}
954 962
@@ -961,7 +969,8 @@ int handle_recv_ringing ( MSISession *session, MSIMessage *msg )
961 return 0; 969 return 0;
962 970
963 session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms ); 971 session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms );
964 if ( callbacks[MSI_OnRinging].function ) event.rise ( callbacks[MSI_OnRinging].function, callbacks[MSI_OnRinging].data ); 972
973 invoke_callback(MSI_OnRinging);
965 974
966 return 1; 975 return 1;
967} 976}
@@ -1000,7 +1009,8 @@ int handle_recv_starting ( MSISession *session, MSIMessage *msg )
1000 1009
1001 flush_peer_type ( session, msg, 0 ); 1010 flush_peer_type ( session, msg, 0 );
1002 1011
1003 if ( callbacks[MSI_OnStarting].function ) event.rise ( callbacks[MSI_OnStarting].function, callbacks[MSI_OnStarting].data ); 1012 invoke_callback(MSI_OnStarting);
1013
1004 event.timer_release ( session->call->ringing_timer_id ); 1014 event.timer_release ( session->call->ringing_timer_id );
1005 1015
1006 return 1; 1016 return 1;
@@ -1015,8 +1025,7 @@ int handle_recv_ending ( MSISession *session, MSIMessage *msg )
1015 /* Stop timer */ 1025 /* Stop timer */
1016 event.timer_release ( session->call->request_timer_id ); 1026 event.timer_release ( session->call->request_timer_id );
1017 1027
1018 /* Call callback */ 1028 invoke_callback(MSI_OnEnding);
1019 if ( callbacks[MSI_OnEnding].function ) callbacks[MSI_OnEnding].function (callbacks[MSI_OnEnding].data);
1020 1029
1021 /* Terminate call */ 1030 /* Terminate call */
1022 terminate_call ( session ); 1031 terminate_call ( session );
@@ -1034,10 +1043,9 @@ int handle_recv_error ( MSISession *session, MSIMessage *msg )
1034 session->last_error_str = stringify_error ( session->last_error_id ); 1043 session->last_error_str = stringify_error ( session->last_error_id );
1035 } 1044 }
1036 1045
1046 invoke_callback(MSI_OnEnding);
1047
1037 terminate_call ( session ); 1048 terminate_call ( session );
1038
1039 if ( callbacks[MSI_OnEnding].function ) event.rise ( callbacks[MSI_OnEnding].function, callbacks[MSI_OnEnding].data );
1040
1041 return 1; 1049 return 1;
1042} 1050}
1043 1051