Skip to content

Commit 139cfa7

Browse files
committed
Merge branch 'master' of https://github.com/mannol1/toxcore
2 parents 87be366 + 6f46dd5 commit 139cfa7

File tree

2 files changed

+47
-71
lines changed

2 files changed

+47
-71
lines changed

auto_tests/toxav_basic_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ START_TEST(test_AV_flows)
317317
}
318318

319319
toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
320+
320321
// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
321322

322323
/* Both receive */

toxav/msi.c

Lines changed: 46 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <unistd.h>
3636
#include <string.h>
3737
#include <stdlib.h>
38+
#include <stdbool.h>
3839

3940
#define same(x, y) strcmp((const char*) x, (const char*) y) == 0
4041

@@ -628,7 +629,8 @@ void t_randomstr ( uint8_t *str, size_t size )
628629

629630

630631
typedef enum {
631-
error_deadcall = 1, /* has call id but it's from old call */
632+
error_none,
633+
error_deadcall, /* has call id but it's from old call */
632634
error_id_mismatch, /* non-existing call */
633635

634636
error_no_callid, /* not having call id */
@@ -820,9 +822,9 @@ MSICall *find_call ( MSISession *session, uint8_t *call_id )
820822
* @param errid The id.
821823
* @param to Where to?
822824
* @return int
823-
* @retval 0 It's always success.
825+
* @retval -1/0 It's usually always success.
824826
*/
825-
int handle_error ( MSISession *session, MSICall *call, MSICallError errid, uint32_t to )
827+
int send_error ( MSISession *session, MSICall *call, MSICallError errid, uint32_t to )
826828
{
827829
if (!call) {
828830
LOGGER_WARNING("Cannot handle error on 'null' call");
@@ -842,38 +844,12 @@ int handle_error ( MSISession *session, MSICall *call, MSICallError errid, uint3
842844
session->last_error_id = errid;
843845
session->last_error_str = stringify_error ( errid );
844846

845-
invoke_callback(call->call_idx, MSI_OnError);
847+
/* invoke_callback(call->call_idx, MSI_OnError); */
846848

847849
return 0;
848850
}
849851

850852

851-
/**
852-
* @brief Determine the error if any.
853-
*
854-
* @param session Control session.
855-
* @param msg The message.
856-
* @return int
857-
* @retval -1 No error.
858-
* @retval 0 Error occurred and response sent.
859-
*/
860-
int has_call_error ( MSISession *session, MSICall *call, MSIMessage *msg )
861-
{
862-
if ( !msg->callid.header_value ) {
863-
return handle_error ( session, call, error_no_callid, msg->friend_id );
864-
865-
} else if ( !call ) {
866-
LOGGER_WARNING("Handling message while no call!");
867-
return 0;
868-
869-
} else if ( memcmp ( call->id, msg->callid.header_value, CALL_ID_LEN ) != 0 ) {
870-
return handle_error ( session, call, error_id_mismatch, msg->friend_id );
871-
872-
}
873-
874-
return -1;
875-
}
876-
877853

878854
/**
879855
* @brief Add peer to peer list.
@@ -1083,7 +1059,8 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
10831059
}
10841060

10851061
} else {
1086-
handle_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/
1062+
send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/
1063+
terminate_call(session, call);
10871064
pthread_mutex_unlock(&session->mutex);
10881065
return 0;
10891066
}
@@ -1098,7 +1075,8 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
10981075
}
10991076

11001077
if ( !msg->callid.header_value ) {
1101-
handle_error ( session, call, error_no_callid, msg->friend_id );
1078+
send_error ( session, call, error_no_callid, msg->friend_id );
1079+
terminate_call(session, call);
11021080
pthread_mutex_unlock(&session->mutex);
11031081
return 0;
11041082
}
@@ -1122,17 +1100,18 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg )
11221100
}
11231101
int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
11241102
{
1103+
if ( !call ) {
1104+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
1105+
return 0;
1106+
}
1107+
11251108
LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id );
11261109

11271110
pthread_mutex_lock(&session->mutex);
11281111

1129-
if ( has_call_error ( session, call, msg ) == 0 ) {
1130-
pthread_mutex_unlock(&session->mutex);
1131-
return -1;
1132-
}
1133-
11341112
if ( !msg->cryptokey.header_value ) {
1135-
int rc = handle_error ( session, call, error_no_crypto_key, msg->friend_id );
1113+
int rc = send_error ( session, call, error_no_crypto_key, msg->friend_id );
1114+
terminate_call(session, call);
11361115
pthread_mutex_unlock(&session->mutex);
11371116
return rc;
11381117
}
@@ -1154,15 +1133,14 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg )
11541133
}
11551134
int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
11561135
{
1157-
LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id);
1158-
1159-
pthread_mutex_lock(&session->mutex);
1160-
1161-
if ( has_call_error ( session, call, msg ) == 0 ) {
1162-
pthread_mutex_unlock(&session->mutex);
1136+
if ( !call ) {
1137+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
11631138
return 0;
11641139
}
11651140

1141+
LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id);
1142+
1143+
pthread_mutex_lock(&session->mutex);
11661144

11671145
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
11681146
send_message ( session, call, _msg_ending, msg->friend_id );
@@ -1182,20 +1160,16 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg )
11821160
}
11831161
int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
11841162
{
1163+
if ( !call ) {
1164+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
1165+
return 0;
1166+
}
1167+
11851168
LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id );
11861169

11871170
pthread_mutex_lock(&session->mutex);
11881171

1189-
if ( has_call_error ( session, call, msg ) == 0 ) {
1190-
pthread_mutex_unlock(&session->mutex);
1191-
return 0;
1192-
}
1193-
11941172
/* Act as end message */
1195-
/*
1196-
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
1197-
send_message ( session, call, _msg_ending, msg->friend_id );
1198-
free_message ( _msg_ending );*/
11991173

12001174
pthread_mutex_unlock(&session->mutex);
12011175
invoke_callback(call->call_idx, MSI_OnCancel);
@@ -1205,15 +1179,15 @@ int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg )
12051179
}
12061180
int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
12071181
{
1182+
if ( !call ) {
1183+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
1184+
return 0;
1185+
}
1186+
12081187
LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id );
12091188

12101189
pthread_mutex_lock(&session->mutex);
12111190

1212-
if ( has_call_error ( session, call, msg ) == 0 ) {
1213-
pthread_mutex_unlock(&session->mutex);
1214-
return 0;
1215-
}
1216-
12171191
MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) );
12181192
send_message ( session, call, _msg_ending, msg->friend_id );
12191193
free_message ( _msg_ending );
@@ -1229,13 +1203,13 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg )
12291203
/********** Response handlers **********/
12301204
int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
12311205
{
1232-
pthread_mutex_lock(&session->mutex);
1233-
1234-
if ( has_call_error ( session, call, msg ) == 0 ) {
1235-
pthread_mutex_unlock(&session->mutex);
1206+
if ( !call ) {
1207+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
12361208
return 0;
12371209
}
12381210

1211+
pthread_mutex_lock(&session->mutex);
1212+
12391213
LOGGER_DEBUG("Session: %p Handling 'ringing' on call: %s", session, call->id );
12401214

12411215
call->ringing_timer_id = event.timer_alloc ( handle_timeout, call, call->ringing_tout_ms );
@@ -1247,18 +1221,19 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg )
12471221
}
12481222
int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
12491223
{
1250-
pthread_mutex_lock(&session->mutex);
1251-
1252-
if ( has_call_error ( session, call, msg ) == 0 ) {
1253-
pthread_mutex_unlock(&session->mutex);
1224+
if ( !call ) {
1225+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
12541226
return 0;
12551227
}
12561228

1229+
pthread_mutex_lock(&session->mutex);
1230+
12571231
LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id );
12581232

12591233

12601234
if ( !msg->cryptokey.header_value ) {
1261-
int rc = handle_error ( session, call, error_no_crypto_key, msg->friend_id );
1235+
int rc = send_error ( session, call, error_no_crypto_key, msg->friend_id );
1236+
terminate_call(session, call);
12621237
pthread_mutex_unlock(&session->mutex);
12631238
return rc;
12641239
}
@@ -1296,13 +1271,13 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg )
12961271
}
12971272
int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg )
12981273
{
1299-
pthread_mutex_lock(&session->mutex);
1300-
1301-
if ( has_call_error ( session, call, msg ) == 0 ) {
1302-
pthread_mutex_unlock(&session->mutex);
1274+
if ( !call ) {
1275+
LOGGER_WARNING("Session: %p Handling 'start' on no call");
13031276
return 0;
13041277
}
13051278

1279+
pthread_mutex_lock(&session->mutex);
1280+
13061281
LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id );
13071282

13081283
/* Stop timer */

0 commit comments

Comments
 (0)