diff options
Diffstat (limited to 'toxav/msi.c')
-rw-r--r-- | toxav/msi.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index 3a0577ae..71a138d2 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -1043,12 +1043,12 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout ) | |||
1043 | return NULL; | 1043 | return NULL; |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | int32_t _call_idx = 0; | 1046 | int32_t call_idx = 0; |
1047 | 1047 | ||
1048 | for (; _call_idx < session->max_calls; _call_idx ++) { | 1048 | for (; call_idx < session->max_calls; call_idx ++) { |
1049 | if ( !session->calls[_call_idx] ) { | 1049 | if ( !session->calls[call_idx] ) { |
1050 | 1050 | ||
1051 | if (!(session->calls[_call_idx] = calloc ( sizeof ( MSICall ), 1 ))) { | 1051 | if (!(session->calls[call_idx] = calloc ( sizeof ( MSICall ), 1 ))) { |
1052 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); | 1052 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); |
1053 | return NULL; | 1053 | return NULL; |
1054 | } | 1054 | } |
@@ -1057,35 +1057,35 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout ) | |||
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | if ( _call_idx == session->max_calls ) { | 1060 | if ( call_idx == session->max_calls ) { |
1061 | LOGGER_WARNING("Reached maximum amount of calls!"); | 1061 | LOGGER_WARNING("Reached maximum amount of calls!"); |
1062 | return NULL; | 1062 | return NULL; |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | 1065 | ||
1066 | MSICall *_call = session->calls[_call_idx]; | 1066 | MSICall *call = session->calls[call_idx]; |
1067 | 1067 | ||
1068 | _call->call_idx = _call_idx; | 1068 | call->call_idx = call_idx; |
1069 | 1069 | ||
1070 | if ( !(_call->type_peer = calloc ( sizeof ( MSICallType ), peers )) ) { | 1070 | if ( !(call->type_peer = calloc ( sizeof ( MSICallType ), peers )) ) { |
1071 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); | 1071 | LOGGER_WARNING("Allocation failed! Program might misbehave!"); |
1072 | free(_call); | 1072 | free(call); |
1073 | return NULL; | 1073 | return NULL; |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | _call->session = session; | 1076 | call->session = session; |
1077 | 1077 | ||
1078 | /*_call->_participant_count = _peers;*/ | 1078 | /*_call->_participant_count = _peers;*/ |
1079 | 1079 | ||
1080 | _call->request_timer_id = 0; | 1080 | call->request_timer_id = 0; |
1081 | _call->ringing_timer_id = 0; | 1081 | call->ringing_timer_id = 0; |
1082 | 1082 | ||
1083 | _call->ringing_tout_ms = ringing_timeout; | 1083 | call->ringing_tout_ms = ringing_timeout; |
1084 | 1084 | ||
1085 | pthread_mutex_init ( &_call->mutex, NULL ); | 1085 | pthread_mutex_init ( call->mutex, NULL ); |
1086 | 1086 | ||
1087 | LOGGER_DEBUG("Started new call with index: %u", _call_idx); | 1087 | LOGGER_DEBUG("Started new call with index: %u", call_idx); |
1088 | return _call; | 1088 | return call; |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | 1091 | ||
@@ -1104,7 +1104,7 @@ int terminate_call ( MSISession *session, MSICall *call ) | |||
1104 | return -1; | 1104 | return -1; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | int rc = pthread_mutex_trylock(&session->mutex); /* Lock if not locked */ | 1107 | int rc = pthread_mutex_trylock(session->mutex); /* Lock if not locked */ |
1108 | 1108 | ||
1109 | LOGGER_DEBUG("Terminated call id: %d", call->call_idx); | 1109 | LOGGER_DEBUG("Terminated call id: %d", call->call_idx); |
1110 | /* Check event loop and cancel timed events if there are any | 1110 | /* Check event loop and cancel timed events if there are any |
@@ -1115,7 +1115,7 @@ int terminate_call ( MSISession *session, MSICall *call ) | |||
1115 | timer_release ( session->timer_handler, call->ringing_timer_id ); | 1115 | timer_release ( session->timer_handler, call->ringing_timer_id ); |
1116 | 1116 | ||
1117 | /* Get a handle */ | 1117 | /* Get a handle */ |
1118 | pthread_mutex_lock ( &call->mutex ); | 1118 | pthread_mutex_lock ( call->mutex ); |
1119 | 1119 | ||
1120 | session->calls[call->call_idx] = NULL; | 1120 | session->calls[call->call_idx] = NULL; |
1121 | 1121 | ||
@@ -1123,14 +1123,14 @@ int terminate_call ( MSISession *session, MSICall *call ) | |||
1123 | free ( call->peers); | 1123 | free ( call->peers); |
1124 | 1124 | ||
1125 | /* Release handle */ | 1125 | /* Release handle */ |
1126 | pthread_mutex_unlock ( &call->mutex ); | 1126 | pthread_mutex_unlock ( call->mutex ); |
1127 | 1127 | ||
1128 | pthread_mutex_destroy ( &call->mutex ); | 1128 | pthread_mutex_destroy ( call->mutex ); |
1129 | 1129 | ||
1130 | free ( call ); | 1130 | free ( call ); |
1131 | 1131 | ||
1132 | if ( rc != EBUSY ) /* Unlock if locked by this call */ | 1132 | if ( rc != EBUSY ) /* Unlock if locked by this call */ |
1133 | pthread_mutex_unlock(&session->mutex); | 1133 | pthread_mutex_unlock(session->mutex); |
1134 | 1134 | ||
1135 | return 0; | 1135 | return 0; |
1136 | } | 1136 | } |
@@ -1174,7 +1174,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1174 | { | 1174 | { |
1175 | LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new"); | 1175 | LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new"); |
1176 | 1176 | ||
1177 | pthread_mutex_lock(&session->mutex); | 1177 | pthread_mutex_lock(session->mutex); |
1178 | 1178 | ||
1179 | 1179 | ||
1180 | if ( call ) { | 1180 | if ( call ) { |
@@ -1194,27 +1194,27 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1194 | call = init_call ( session, 1, 0 ); | 1194 | call = init_call ( session, 1, 0 ); |
1195 | 1195 | ||
1196 | if ( !call ) { | 1196 | if ( !call ) { |
1197 | pthread_mutex_unlock(&session->mutex); | 1197 | pthread_mutex_unlock(session->mutex); |
1198 | LOGGER_ERROR("Starting call"); | 1198 | LOGGER_ERROR("Starting call"); |
1199 | return 0; | 1199 | return 0; |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | } else { | 1202 | } else { |
1203 | pthread_mutex_unlock(&session->mutex); | 1203 | pthread_mutex_unlock(session->mutex); |
1204 | return 0; /* Wait for ringing from peer */ | 1204 | return 0; /* Wait for ringing from peer */ |
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | } else { | 1207 | } else { |
1208 | send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/ | 1208 | send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/ |
1209 | terminate_call(session, call); | 1209 | terminate_call(session, call); |
1210 | pthread_mutex_unlock(&session->mutex); | 1210 | pthread_mutex_unlock(session->mutex); |
1211 | return 0; | 1211 | return 0; |
1212 | } | 1212 | } |
1213 | } else { | 1213 | } else { |
1214 | call = init_call ( session, 1, 0 ); | 1214 | call = init_call ( session, 1, 0 ); |
1215 | 1215 | ||
1216 | if ( !call ) { | 1216 | if ( !call ) { |
1217 | pthread_mutex_unlock(&session->mutex); | 1217 | pthread_mutex_unlock(session->mutex); |
1218 | LOGGER_ERROR("Starting call"); | 1218 | LOGGER_ERROR("Starting call"); |
1219 | return 0; | 1219 | return 0; |
1220 | } | 1220 | } |
@@ -1223,7 +1223,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1223 | if ( !msg->callid.header_value ) { | 1223 | if ( !msg->callid.header_value ) { |
1224 | send_error ( session, call, error_no_callid, msg->friend_id ); | 1224 | send_error ( session, call, error_no_callid, msg->friend_id ); |
1225 | terminate_call(session, call); | 1225 | terminate_call(session, call); |
1226 | pthread_mutex_unlock(&session->mutex); | 1226 | pthread_mutex_unlock(session->mutex); |
1227 | return 0; | 1227 | return 0; |
1228 | } | 1228 | } |
1229 | 1229 | ||
@@ -1238,7 +1238,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1238 | send_message ( session, call, _msg_ringing, msg->friend_id ); | 1238 | send_message ( session, call, _msg_ringing, msg->friend_id ); |
1239 | free_message ( _msg_ringing ); | 1239 | free_message ( _msg_ringing ); |
1240 | 1240 | ||
1241 | pthread_mutex_unlock(&session->mutex); | 1241 | pthread_mutex_unlock(session->mutex); |
1242 | 1242 | ||
1243 | invoke_callback(call->call_idx, MSI_OnInvite); | 1243 | invoke_callback(call->call_idx, MSI_OnInvite); |
1244 | 1244 | ||
@@ -1253,13 +1253,13 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1253 | 1253 | ||
1254 | LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id ); | 1254 | LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id ); |
1255 | 1255 | ||
1256 | pthread_mutex_lock(&session->mutex); | 1256 | pthread_mutex_lock(session->mutex); |
1257 | 1257 | ||
1258 | call->state = call_active; | 1258 | call->state = call_active; |
1259 | 1259 | ||
1260 | flush_peer_type ( call, msg, 0 ); | 1260 | flush_peer_type ( call, msg, 0 ); |
1261 | 1261 | ||
1262 | pthread_mutex_unlock(&session->mutex); | 1262 | pthread_mutex_unlock(session->mutex); |
1263 | 1263 | ||
1264 | invoke_callback(call->call_idx, MSI_OnStart); | 1264 | invoke_callback(call->call_idx, MSI_OnStart); |
1265 | return 1; | 1265 | return 1; |
@@ -1273,14 +1273,14 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1273 | 1273 | ||
1274 | LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id); | 1274 | LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id); |
1275 | 1275 | ||
1276 | pthread_mutex_lock(&session->mutex); | 1276 | pthread_mutex_lock(session->mutex); |
1277 | 1277 | ||
1278 | MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); | 1278 | MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); |
1279 | send_message ( session, call, _msg_ending, msg->friend_id ); | 1279 | send_message ( session, call, _msg_ending, msg->friend_id ); |
1280 | free_message ( _msg_ending ); | 1280 | free_message ( _msg_ending ); |
1281 | 1281 | ||
1282 | 1282 | ||
1283 | pthread_mutex_unlock(&session->mutex); | 1283 | pthread_mutex_unlock(session->mutex); |
1284 | 1284 | ||
1285 | invoke_callback(call->call_idx, MSI_OnReject); | 1285 | invoke_callback(call->call_idx, MSI_OnReject); |
1286 | 1286 | ||
@@ -1296,11 +1296,11 @@ int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1296 | 1296 | ||
1297 | LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id ); | 1297 | LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id ); |
1298 | 1298 | ||
1299 | pthread_mutex_lock(&session->mutex); | 1299 | pthread_mutex_lock(session->mutex); |
1300 | 1300 | ||
1301 | /* Act as end message */ | 1301 | /* Act as end message */ |
1302 | 1302 | ||
1303 | pthread_mutex_unlock(&session->mutex); | 1303 | pthread_mutex_unlock(session->mutex); |
1304 | invoke_callback(call->call_idx, MSI_OnCancel); | 1304 | invoke_callback(call->call_idx, MSI_OnCancel); |
1305 | 1305 | ||
1306 | terminate_call ( session, call ); | 1306 | terminate_call ( session, call ); |
@@ -1315,13 +1315,13 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1315 | 1315 | ||
1316 | LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id ); | 1316 | LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id ); |
1317 | 1317 | ||
1318 | pthread_mutex_lock(&session->mutex); | 1318 | pthread_mutex_lock(session->mutex); |
1319 | 1319 | ||
1320 | MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); | 1320 | MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); |
1321 | send_message ( session, call, _msg_ending, msg->friend_id ); | 1321 | send_message ( session, call, _msg_ending, msg->friend_id ); |
1322 | free_message ( _msg_ending ); | 1322 | free_message ( _msg_ending ); |
1323 | 1323 | ||
1324 | pthread_mutex_unlock(&session->mutex); | 1324 | pthread_mutex_unlock(session->mutex); |
1325 | 1325 | ||
1326 | invoke_callback(call->call_idx, MSI_OnEnd); | 1326 | invoke_callback(call->call_idx, MSI_OnEnd); |
1327 | 1327 | ||
@@ -1337,11 +1337,11 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1337 | return 0; | 1337 | return 0; |
1338 | } | 1338 | } |
1339 | 1339 | ||
1340 | pthread_mutex_lock(&session->mutex); | 1340 | pthread_mutex_lock(session->mutex); |
1341 | 1341 | ||
1342 | if ( call->ringing_timer_id ) { | 1342 | if ( call->ringing_timer_id ) { |
1343 | LOGGER_WARNING("Call already ringing"); | 1343 | LOGGER_WARNING("Call already ringing"); |
1344 | pthread_mutex_unlock(&session->mutex); | 1344 | pthread_mutex_unlock(session->mutex); |
1345 | return 0; | 1345 | return 0; |
1346 | } | 1346 | } |
1347 | 1347 | ||
@@ -1349,7 +1349,7 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1349 | 1349 | ||
1350 | call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms ); | 1350 | call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms ); |
1351 | 1351 | ||
1352 | pthread_mutex_unlock(&session->mutex); | 1352 | pthread_mutex_unlock(session->mutex); |
1353 | 1353 | ||
1354 | invoke_callback(call->call_idx, MSI_OnRinging); | 1354 | invoke_callback(call->call_idx, MSI_OnRinging); |
1355 | return 1; | 1355 | return 1; |
@@ -1361,7 +1361,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1361 | return 0; | 1361 | return 0; |
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | pthread_mutex_lock(&session->mutex); | 1364 | pthread_mutex_lock(session->mutex); |
1365 | 1365 | ||
1366 | LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id ); | 1366 | LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id ); |
1367 | 1367 | ||
@@ -1375,7 +1375,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1375 | 1375 | ||
1376 | 1376 | ||
1377 | timer_release ( session->timer_handler, call->ringing_timer_id ); | 1377 | timer_release ( session->timer_handler, call->ringing_timer_id ); |
1378 | pthread_mutex_unlock(&session->mutex); | 1378 | pthread_mutex_unlock(session->mutex); |
1379 | 1379 | ||
1380 | invoke_callback(call->call_idx, MSI_OnStarting); | 1380 | invoke_callback(call->call_idx, MSI_OnStarting); |
1381 | return 1; | 1381 | return 1; |
@@ -1387,14 +1387,14 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1387 | return 0; | 1387 | return 0; |
1388 | } | 1388 | } |
1389 | 1389 | ||
1390 | pthread_mutex_lock(&session->mutex); | 1390 | pthread_mutex_lock(session->mutex); |
1391 | 1391 | ||
1392 | LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id ); | 1392 | LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id ); |
1393 | 1393 | ||
1394 | /* Stop timer */ | 1394 | /* Stop timer */ |
1395 | timer_release ( session->timer_handler, call->request_timer_id ); | 1395 | timer_release ( session->timer_handler, call->request_timer_id ); |
1396 | 1396 | ||
1397 | pthread_mutex_unlock(&session->mutex); | 1397 | pthread_mutex_unlock(session->mutex); |
1398 | 1398 | ||
1399 | invoke_callback(call->call_idx, MSI_OnEnding); | 1399 | invoke_callback(call->call_idx, MSI_OnEnding); |
1400 | 1400 | ||
@@ -1405,11 +1405,11 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1405 | } | 1405 | } |
1406 | int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) | 1406 | int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) |
1407 | { | 1407 | { |
1408 | pthread_mutex_lock(&session->mutex); | 1408 | pthread_mutex_lock(session->mutex); |
1409 | 1409 | ||
1410 | if ( !call ) { | 1410 | if ( !call ) { |
1411 | LOGGER_WARNING("Handling 'error' on non-existing call!"); | 1411 | LOGGER_WARNING("Handling 'error' on non-existing call!"); |
1412 | pthread_mutex_unlock(&session->mutex); | 1412 | pthread_mutex_unlock(session->mutex); |
1413 | return -1; | 1413 | return -1; |
1414 | } | 1414 | } |
1415 | 1415 | ||
@@ -1422,7 +1422,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) | |||
1422 | LOGGER_DEBUG("Error reason: %s", session->last_error_str); | 1422 | LOGGER_DEBUG("Error reason: %s", session->last_error_str); |
1423 | } | 1423 | } |
1424 | 1424 | ||
1425 | pthread_mutex_unlock(&session->mutex); | 1425 | pthread_mutex_unlock(session->mutex); |
1426 | 1426 | ||
1427 | invoke_callback(call->call_idx, MSI_OnEnding); | 1427 | invoke_callback(call->call_idx, MSI_OnEnding); |
1428 | 1428 | ||
@@ -1603,38 +1603,38 @@ MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls ) | |||
1603 | return NULL; | 1603 | return NULL; |
1604 | } | 1604 | } |
1605 | 1605 | ||
1606 | MSISession *_retu = calloc ( sizeof ( MSISession ), 1 ); | 1606 | MSISession *retu = calloc ( sizeof ( MSISession ), 1 ); |
1607 | 1607 | ||
1608 | if (_retu == NULL) { | 1608 | if (retu == NULL) { |
1609 | LOGGER_ERROR("Allocation failed! Program might misbehave!"); | 1609 | LOGGER_ERROR("Allocation failed! Program might misbehave!"); |
1610 | return NULL; | 1610 | return NULL; |
1611 | } | 1611 | } |
1612 | 1612 | ||
1613 | _retu->messenger_handle = messenger; | 1613 | retu->messenger_handle = messenger; |
1614 | _retu->agent_handler = NULL; | 1614 | retu->agent_handler = NULL; |
1615 | _retu->timer_handler = handler; | 1615 | retu->timer_handler = handler; |
1616 | 1616 | ||
1617 | if (!(_retu->calls = calloc( sizeof (MSICall *), max_calls ))) { | 1617 | if (!(retu->calls = calloc( sizeof (MSICall *), max_calls ))) { |
1618 | LOGGER_ERROR("Allocation failed! Program might misbehave!"); | 1618 | LOGGER_ERROR("Allocation failed! Program might misbehave!"); |
1619 | free(_retu); | 1619 | free(retu); |
1620 | return NULL; | 1620 | return NULL; |
1621 | } | 1621 | } |
1622 | 1622 | ||
1623 | _retu->max_calls = max_calls; | 1623 | retu->max_calls = max_calls; |
1624 | 1624 | ||
1625 | _retu->frequ = 10000; /* default value? */ | 1625 | retu->frequ = 10000; /* default value? */ |
1626 | _retu->call_timeout = 30000; /* default value? */ | 1626 | retu->call_timeout = 30000; /* default value? */ |
1627 | 1627 | ||
1628 | 1628 | ||
1629 | m_callback_msi_packet(messenger, msi_handle_packet, _retu ); | 1629 | m_callback_msi_packet(messenger, msi_handle_packet, retu ); |
1630 | 1630 | ||
1631 | /* This is called when remote terminates session */ | 1631 | /* This is called when remote terminates session */ |
1632 | m_callback_connectionstatus_internal_av(messenger, handle_remote_connection_change, _retu); | 1632 | m_callback_connectionstatus_internal_av(messenger, handle_remote_connection_change, retu); |
1633 | 1633 | ||
1634 | pthread_mutex_init(&_retu->mutex, NULL); | 1634 | pthread_mutex_init(retu->mutex, NULL); |
1635 | 1635 | ||
1636 | LOGGER_DEBUG("New msi session: %p max calls: %u", _retu, max_calls); | 1636 | LOGGER_DEBUG("New msi session: %p max calls: %u", retu, max_calls); |
1637 | return _retu; | 1637 | return retu; |
1638 | } | 1638 | } |
1639 | 1639 | ||
1640 | 1640 | ||
@@ -1651,9 +1651,9 @@ int msi_terminate_session ( MSISession *session ) | |||
1651 | return -1; | 1651 | return -1; |
1652 | } | 1652 | } |
1653 | 1653 | ||
1654 | pthread_mutex_lock(&session->mutex); | 1654 | pthread_mutex_lock(session->mutex); |
1655 | m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL); | 1655 | m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL); |
1656 | pthread_mutex_unlock(&session->mutex); | 1656 | pthread_mutex_unlock(session->mutex); |
1657 | 1657 | ||
1658 | int _status = 0; | 1658 | int _status = 0; |
1659 | 1659 | ||
@@ -1671,7 +1671,7 @@ int msi_terminate_session ( MSISession *session ) | |||
1671 | 1671 | ||
1672 | timer_terminate_session(session->timer_handler); | 1672 | timer_terminate_session(session->timer_handler); |
1673 | 1673 | ||
1674 | pthread_mutex_destroy(&session->mutex); | 1674 | pthread_mutex_destroy(session->mutex); |
1675 | 1675 | ||
1676 | LOGGER_DEBUG("Terminated session: %p", session); | 1676 | LOGGER_DEBUG("Terminated session: %p", session); |
1677 | free ( session ); | 1677 | free ( session ); |
@@ -1690,7 +1690,7 @@ int msi_terminate_session ( MSISession *session ) | |||
1690 | */ | 1690 | */ |
1691 | int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id ) | 1691 | int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id ) |
1692 | { | 1692 | { |
1693 | pthread_mutex_lock(&session->mutex); | 1693 | pthread_mutex_lock(session->mutex); |
1694 | 1694 | ||
1695 | LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); | 1695 | LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); |
1696 | 1696 | ||
@@ -1698,7 +1698,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type | |||
1698 | MSICall *_call = init_call ( session, 1, rngsec ); /* Just one peer for now */ | 1698 | MSICall *_call = init_call ( session, 1, rngsec ); /* Just one peer for now */ |
1699 | 1699 | ||
1700 | if ( !_call ) { | 1700 | if ( !_call ) { |
1701 | pthread_mutex_unlock(&session->mutex); | 1701 | pthread_mutex_unlock(session->mutex); |
1702 | LOGGER_ERROR("Cannot handle more calls"); | 1702 | LOGGER_ERROR("Cannot handle more calls"); |
1703 | return -1; | 1703 | return -1; |
1704 | } | 1704 | } |
@@ -1729,7 +1729,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type | |||
1729 | 1729 | ||
1730 | LOGGER_DEBUG("Invite sent"); | 1730 | LOGGER_DEBUG("Invite sent"); |
1731 | 1731 | ||
1732 | pthread_mutex_unlock(&session->mutex); | 1732 | pthread_mutex_unlock(session->mutex); |
1733 | 1733 | ||
1734 | return 0; | 1734 | return 0; |
1735 | } | 1735 | } |
@@ -1746,18 +1746,18 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type | |||
1746 | */ | 1746 | */ |
1747 | int msi_hangup ( MSISession *session, int32_t call_index ) | 1747 | int msi_hangup ( MSISession *session, int32_t call_index ) |
1748 | { | 1748 | { |
1749 | pthread_mutex_lock(&session->mutex); | 1749 | pthread_mutex_lock(session->mutex); |
1750 | LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index); | 1750 | LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index); |
1751 | 1751 | ||
1752 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { | 1752 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { |
1753 | LOGGER_ERROR("Invalid call index!"); | 1753 | LOGGER_ERROR("Invalid call index!"); |
1754 | pthread_mutex_unlock(&session->mutex); | 1754 | pthread_mutex_unlock(session->mutex); |
1755 | return -1; | 1755 | return -1; |
1756 | } | 1756 | } |
1757 | 1757 | ||
1758 | if ( !session->calls[call_index] || session->calls[call_index]->state != call_active ) { | 1758 | if ( !session->calls[call_index] || session->calls[call_index]->state != call_active ) { |
1759 | LOGGER_ERROR("No call with such index or call is not active!"); | 1759 | LOGGER_ERROR("No call with such index or call is not active!"); |
1760 | pthread_mutex_unlock(&session->mutex); | 1760 | pthread_mutex_unlock(session->mutex); |
1761 | return -1; | 1761 | return -1; |
1762 | } | 1762 | } |
1763 | 1763 | ||
@@ -1776,7 +1776,7 @@ int msi_hangup ( MSISession *session, int32_t call_index ) | |||
1776 | session->calls[call_index]->request_timer_id = | 1776 | session->calls[call_index]->request_timer_id = |
1777 | timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); | 1777 | timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); |
1778 | 1778 | ||
1779 | pthread_mutex_unlock(&session->mutex); | 1779 | pthread_mutex_unlock(session->mutex); |
1780 | return 0; | 1780 | return 0; |
1781 | } | 1781 | } |
1782 | 1782 | ||
@@ -1791,12 +1791,12 @@ int msi_hangup ( MSISession *session, int32_t call_index ) | |||
1791 | */ | 1791 | */ |
1792 | int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type ) | 1792 | int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type ) |
1793 | { | 1793 | { |
1794 | pthread_mutex_lock(&session->mutex); | 1794 | pthread_mutex_lock(session->mutex); |
1795 | LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index); | 1795 | LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index); |
1796 | 1796 | ||
1797 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { | 1797 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { |
1798 | LOGGER_ERROR("Invalid call index!"); | 1798 | LOGGER_ERROR("Invalid call index!"); |
1799 | pthread_mutex_unlock(&session->mutex); | 1799 | pthread_mutex_unlock(session->mutex); |
1800 | return -1; | 1800 | return -1; |
1801 | } | 1801 | } |
1802 | 1802 | ||
@@ -1818,7 +1818,7 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type | |||
1818 | 1818 | ||
1819 | session->calls[call_index]->state = call_active; | 1819 | session->calls[call_index]->state = call_active; |
1820 | 1820 | ||
1821 | pthread_mutex_unlock(&session->mutex); | 1821 | pthread_mutex_unlock(session->mutex); |
1822 | return 0; | 1822 | return 0; |
1823 | } | 1823 | } |
1824 | 1824 | ||
@@ -1833,12 +1833,12 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type | |||
1833 | */ | 1833 | */ |
1834 | int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason ) | 1834 | int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason ) |
1835 | { | 1835 | { |
1836 | pthread_mutex_lock(&session->mutex); | 1836 | pthread_mutex_lock(session->mutex); |
1837 | LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason ? reason : "Unknown"); | 1837 | LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason ? reason : "Unknown"); |
1838 | 1838 | ||
1839 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { | 1839 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { |
1840 | LOGGER_ERROR("Invalid call index!"); | 1840 | LOGGER_ERROR("Invalid call index!"); |
1841 | pthread_mutex_unlock(&session->mutex); | 1841 | pthread_mutex_unlock(session->mutex); |
1842 | return -1; | 1842 | return -1; |
1843 | } | 1843 | } |
1844 | 1844 | ||
@@ -1852,7 +1852,7 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c | |||
1852 | /*session->calls[call_index]->state = call_hanged_up; | 1852 | /*session->calls[call_index]->state = call_hanged_up; |
1853 | session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/ | 1853 | session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/ |
1854 | terminate_call ( session, session->calls[call_index] ); | 1854 | terminate_call ( session, session->calls[call_index] ); |
1855 | pthread_mutex_unlock(&session->mutex); | 1855 | pthread_mutex_unlock(session->mutex); |
1856 | 1856 | ||
1857 | return 0; | 1857 | return 0; |
1858 | } | 1858 | } |
@@ -1867,12 +1867,12 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c | |||
1867 | */ | 1867 | */ |
1868 | int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason ) | 1868 | int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason ) |
1869 | { | 1869 | { |
1870 | pthread_mutex_lock(&session->mutex); | 1870 | pthread_mutex_lock(session->mutex); |
1871 | LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason ? (char *)reason : "Unknown"); | 1871 | LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason ? (char *)reason : "Unknown"); |
1872 | 1872 | ||
1873 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { | 1873 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { |
1874 | LOGGER_ERROR("Invalid call index!"); | 1874 | LOGGER_ERROR("Invalid call index!"); |
1875 | pthread_mutex_unlock(&session->mutex); | 1875 | pthread_mutex_unlock(session->mutex); |
1876 | return -1; | 1876 | return -1; |
1877 | } | 1877 | } |
1878 | 1878 | ||
@@ -1889,7 +1889,7 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason | |||
1889 | session->calls[call_index]->request_timer_id = | 1889 | session->calls[call_index]->request_timer_id = |
1890 | timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); | 1890 | timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); |
1891 | 1891 | ||
1892 | pthread_mutex_unlock(&session->mutex); | 1892 | pthread_mutex_unlock(session->mutex); |
1893 | return 0; | 1893 | return 0; |
1894 | } | 1894 | } |
1895 | 1895 | ||
@@ -1903,11 +1903,11 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason | |||
1903 | */ | 1903 | */ |
1904 | int msi_stopcall ( MSISession *session, int32_t call_index ) | 1904 | int msi_stopcall ( MSISession *session, int32_t call_index ) |
1905 | { | 1905 | { |
1906 | pthread_mutex_lock(&session->mutex); | 1906 | pthread_mutex_lock(session->mutex); |
1907 | LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index); | 1907 | LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index); |
1908 | 1908 | ||
1909 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { | 1909 | if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { |
1910 | pthread_mutex_unlock(&session->mutex); | 1910 | pthread_mutex_unlock(session->mutex); |
1911 | return -1; | 1911 | return -1; |
1912 | } | 1912 | } |
1913 | 1913 | ||
@@ -1915,6 +1915,6 @@ int msi_stopcall ( MSISession *session, int32_t call_index ) | |||
1915 | 1915 | ||
1916 | terminate_call ( session, session->calls[call_index] ); | 1916 | terminate_call ( session, session->calls[call_index] ); |
1917 | 1917 | ||
1918 | pthread_mutex_unlock(&session->mutex); | 1918 | pthread_mutex_unlock(session->mutex); |
1919 | return 0; | 1919 | return 0; |
1920 | } | 1920 | } |