mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'master' of https://github.com/mannol1/ProjectTox-Core into mannol1-master
This commit is contained in:
commit
6b152d2bac
104
toxav/msi.c
104
toxav/msi.c
|
@ -1038,7 +1038,9 @@ void *handle_timeout ( void *arg )
|
|||
int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new");
|
||||
|
||||
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( call ) {
|
||||
if ( call->peers[0] == msg->friend_id ) {
|
||||
/* The glare case. A calls B when at the same time
|
||||
|
@ -1051,17 +1053,20 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
if ( call_id_bigger (call->id, msg->callid.header_value) == 1 ) { /* Peer has advantage */
|
||||
terminate_call(session, call);
|
||||
} else {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0; /* Wait for ringing from peer */
|
||||
}
|
||||
|
||||
} else {
|
||||
handle_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !msg->callid.header_value ) {
|
||||
handle_error ( session, call, error_no_callid, msg->friend_id );
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1069,6 +1074,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
|
||||
if ( !new_call ) {
|
||||
handle_error ( session, call, error_busy, msg->friend_id );
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1083,20 +1089,28 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
send_message ( session, new_call, _msg_ringing, msg->friend_id );
|
||||
free_message ( _msg_ringing );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(new_call->call_idx, MSI_OnInvite);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id );
|
||||
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return -1;
|
||||
|
||||
if ( !msg->cryptokey.header_value )
|
||||
return handle_error ( session, call, error_no_crypto_key, msg->friend_id );
|
||||
|
||||
}
|
||||
|
||||
if ( !msg->cryptokey.header_value ) {
|
||||
int rc = handle_error ( session, call, error_no_crypto_key, msg->friend_id );
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return rc;
|
||||
}
|
||||
call->state = call_active;
|
||||
|
||||
call->key_peer = calloc ( sizeof ( uint8_t ), crypto_box_KEYBYTES );
|
||||
|
@ -1107,16 +1121,21 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
|
||||
flush_peer_type ( call, msg, 0 );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnStart);
|
||||
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
|
||||
|
@ -1124,6 +1143,8 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
free_message ( _msg_ending );
|
||||
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnReject);
|
||||
/*
|
||||
event.timer_release ( session->call->request_timer_id );
|
||||
|
@ -1131,40 +1152,47 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
*/
|
||||
|
||||
terminate_call(session, call);
|
||||
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id );
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* Act as end message */
|
||||
/*
|
||||
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
|
||||
send_message ( session, call, _msg_ending, msg->friend_id );
|
||||
free_message ( _msg_ending );*/
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
invoke_callback(call->call_idx, MSI_OnCancel);
|
||||
|
||||
terminate_call ( session, call );
|
||||
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id );
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
|
||||
send_message ( session, call, _msg_ending, msg->friend_id );
|
||||
free_message ( _msg_ending );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnEnd);
|
||||
|
||||
terminate_call ( session, call );
|
||||
|
@ -1174,27 +1202,37 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
/********** Response handlers **********/
|
||||
int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
|
||||
}
|
||||
LOGGER_DEBUG("Session: %p Handling 'ringing' on call: %s", session, call->id );
|
||||
|
||||
call->ringing_timer_id = event.timer_alloc ( handle_timeout, call, call->ringing_tout_ms );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnRinging);
|
||||
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id );
|
||||
|
||||
|
||||
if ( !msg->cryptokey.header_value ) {
|
||||
return handle_error ( session, call, error_no_crypto_key, msg->friend_id );
|
||||
int rc = handle_error ( session, call, error_no_crypto_key, msg->friend_id );
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Generate local key/nonce to send */
|
||||
|
@ -1221,22 +1259,28 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
|
||||
flush_peer_type ( call, msg, 0 );
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnStarting);
|
||||
|
||||
event.timer_release ( call->ringing_timer_id );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnStarting);
|
||||
return 1;
|
||||
}
|
||||
int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
if ( has_call_error ( session, call, msg ) == 0 )
|
||||
return 0;
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( has_call_error ( session, call, msg ) == 0 ) {
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return 0;
|
||||
}
|
||||
LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id );
|
||||
|
||||
/* Stop timer */
|
||||
event.timer_release ( call->request_timer_id );
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnEnding);
|
||||
|
||||
/* Terminate call */
|
||||
|
@ -1246,8 +1290,11 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
}
|
||||
int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
|
||||
{
|
||||
pthread_mutex_lock(&session->mutex);
|
||||
|
||||
if ( !call ) {
|
||||
LOGGER_WARNING("Handling 'error' on non-existing call!");
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1260,9 +1307,12 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg )
|
|||
LOGGER_DEBUG("Error reason: %s", session->last_error_str);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&session->mutex);
|
||||
|
||||
invoke_callback(call->call_idx, MSI_OnEnding);
|
||||
|
||||
terminate_call ( session, call );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1324,13 +1374,10 @@ void msi_handle_packet ( Messenger *messenger, int source, uint8_t *data, uint16
|
|||
|
||||
_msg->friend_id = source;
|
||||
|
||||
pthread_mutex_lock(&_session->mutex);
|
||||
|
||||
/* Find what call */
|
||||
MSICall *_call = _msg->callid.header_value ? find_call(_session, _msg->callid.header_value ) : NULL;
|
||||
|
||||
|
||||
|
||||
/* Now handle message */
|
||||
|
||||
if ( _msg->request.header_value ) { /* Handle request */
|
||||
|
@ -1403,7 +1450,6 @@ void msi_handle_packet ( Messenger *messenger, int source, uint8_t *data, uint16
|
|||
|
||||
free_end:
|
||||
free_message ( _msg );
|
||||
pthread_mutex_unlock(&_session->mutex);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user