summaryrefslogtreecommitdiff
path: root/toxav/msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/msi.c')
-rw-r--r--toxav/msi.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index b7926e07..0bd04c56 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -99,9 +99,9 @@ void handle_msi_packet ( Messenger *m, uint32_t friend_id, const uint8_t *data,
99 */ 99 */
100void msi_register_callback ( MSISession *session, MSICallbackType callback, MSICallbackID id) 100void msi_register_callback ( MSISession *session, MSICallbackType callback, MSICallbackID id)
101{ 101{
102 LOGGED_LOCK(session->mutex); 102 pthread_mutex_lock(session->mutex);
103 session->callbacks[id] = callback; 103 session->callbacks[id] = callback;
104 LOGGED_UNLOCK(session->mutex); 104 pthread_mutex_unlock(session->mutex);
105} 105}
106MSISession *msi_new ( Messenger *messenger ) 106MSISession *msi_new ( Messenger *messenger )
107{ 107{
@@ -141,7 +141,7 @@ int msi_kill ( MSISession *session )
141 } 141 }
142 142
143 m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL); 143 m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL);
144 LOGGED_LOCK(session->mutex); 144 pthread_mutex_lock(session->mutex);
145 145
146 if (session->calls) { 146 if (session->calls) {
147 MSIMessage msg; 147 MSIMessage msg;
@@ -154,7 +154,7 @@ int msi_kill ( MSISession *session )
154 } 154 }
155 } 155 }
156 156
157 LOGGED_UNLOCK(session->mutex); 157 pthread_mutex_unlock(session->mutex);
158 pthread_mutex_destroy(session->mutex); 158 pthread_mutex_destroy(session->mutex);
159 159
160 LOGGER_DEBUG("Terminated session: %p", session); 160 LOGGER_DEBUG("Terminated session: %p", session);
@@ -165,17 +165,17 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_
165{ 165{
166 LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); 166 LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id);
167 167
168 LOGGED_LOCK(session->mutex); 168 pthread_mutex_lock(session->mutex);
169 if (get_call(session, friend_id) != NULL) { 169 if (get_call(session, friend_id) != NULL) {
170 LOGGER_ERROR("Already in a call"); 170 LOGGER_ERROR("Already in a call");
171 LOGGED_UNLOCK(session->mutex); 171 pthread_mutex_unlock(session->mutex);
172 return -1; 172 return -1;
173 } 173 }
174 174
175 (*call) = new_call ( session, friend_id ); 175 (*call) = new_call ( session, friend_id );
176 176
177 if ( *call == NULL ) { 177 if ( *call == NULL ) {
178 LOGGED_UNLOCK(session->mutex); 178 pthread_mutex_unlock(session->mutex);
179 return -1; 179 return -1;
180 } 180 }
181 181
@@ -195,7 +195,7 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_
195 (*call)->state = msi_CallRequesting; 195 (*call)->state = msi_CallRequesting;
196 196
197 LOGGER_DEBUG("Invite sent"); 197 LOGGER_DEBUG("Invite sent");
198 LOGGED_UNLOCK(session->mutex); 198 pthread_mutex_unlock(session->mutex);
199 return 0; 199 return 0;
200} 200}
201int msi_hangup ( MSICall* call ) 201int msi_hangup ( MSICall* call )
@@ -203,7 +203,7 @@ int msi_hangup ( MSICall* call )
203 LOGGER_DEBUG("Session: %p Hanging up call with friend: %u", call->session, call->friend_id); 203 LOGGER_DEBUG("Session: %p Hanging up call with friend: %u", call->session, call->friend_id);
204 204
205 MSISession* session = call->session; 205 MSISession* session = call->session;
206 LOGGED_LOCK(session->mutex); 206 pthread_mutex_lock(session->mutex);
207 207
208 MSIMessage msg; 208 MSIMessage msg;
209 msg_init(&msg, requ_pop); 209 msg_init(&msg, requ_pop);
@@ -211,7 +211,7 @@ int msi_hangup ( MSICall* call )
211 send_message ( session->messenger, call->friend_id, &msg ); 211 send_message ( session->messenger, call->friend_id, &msg );
212 212
213 kill_call(call); 213 kill_call(call);
214 LOGGED_UNLOCK(session->mutex); 214 pthread_mutex_unlock(session->mutex);
215 return 0; 215 return 0;
216} 216}
217int msi_answer ( MSICall* call, uint8_t capabilities ) 217int msi_answer ( MSICall* call, uint8_t capabilities )
@@ -219,13 +219,13 @@ int msi_answer ( MSICall* call, uint8_t capabilities )
219 LOGGER_DEBUG("Session: %p Answering call from: %u", call->session, call->friend_id); 219 LOGGER_DEBUG("Session: %p Answering call from: %u", call->session, call->friend_id);
220 220
221 MSISession* session = call->session; 221 MSISession* session = call->session;
222 LOGGED_LOCK(session->mutex); 222 pthread_mutex_lock(session->mutex);
223 223
224 if ( call->state != msi_CallRequested ) { 224 if ( call->state != msi_CallRequested ) {
225 /* Though sending in invalid state will not cause anything wierd 225 /* Though sending in invalid state will not cause anything wierd
226 * Its better to not do it like a maniac */ 226 * Its better to not do it like a maniac */
227 LOGGER_ERROR("Call is in invalid state!"); 227 LOGGER_ERROR("Call is in invalid state!");
228 LOGGED_UNLOCK(session->mutex); 228 pthread_mutex_unlock(session->mutex);
229 return -1; 229 return -1;
230 } 230 }
231 231
@@ -243,7 +243,7 @@ int msi_answer ( MSICall* call, uint8_t capabilities )
243 send_message ( session->messenger, call->friend_id, &msg ); 243 send_message ( session->messenger, call->friend_id, &msg );
244 244
245 call->state = msi_CallActive; 245 call->state = msi_CallActive;
246 LOGGED_UNLOCK(session->mutex); 246 pthread_mutex_unlock(session->mutex);
247 247
248 return 0; 248 return 0;
249} 249}
@@ -252,7 +252,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities )
252 LOGGER_DEBUG("Session: %p Trying to change capabilities to friend %u", call->session, call->friend_id); 252 LOGGER_DEBUG("Session: %p Trying to change capabilities to friend %u", call->session, call->friend_id);
253 253
254 MSISession* session = call->session; 254 MSISession* session = call->session;
255 LOGGED_LOCK(session->mutex); 255 pthread_mutex_lock(session->mutex);
256 256
257 if ( call->state != msi_CallActive ) { 257 if ( call->state != msi_CallActive ) {
258 /* Sending capabilities change can cause error on other side if 258 /* Sending capabilities change can cause error on other side if
@@ -263,7 +263,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities )
263 * like new. TODO: explain this better 263 * like new. TODO: explain this better
264 */ 264 */
265 LOGGER_ERROR("Call is in invalid state!"); 265 LOGGER_ERROR("Call is in invalid state!");
266 LOGGED_UNLOCK(session->mutex); 266 pthread_mutex_unlock(session->mutex);
267 return -1; 267 return -1;
268 } 268 }
269 269
@@ -277,7 +277,7 @@ int msi_change_capabilities( MSICall* call, uint8_t capabilities )
277 277
278 send_message ( call->session->messenger, call->friend_id, &msg ); 278 send_message ( call->session->messenger, call->friend_id, &msg );
279 279
280 LOGGED_UNLOCK(session->mutex); 280 pthread_mutex_unlock(session->mutex);
281 return 0; 281 return 0;
282} 282}
283 283
@@ -349,7 +349,7 @@ int msg_parse_in ( MSIMessage *dest, const uint8_t *data, uint16_t length )
349 case IDVFPSZ: 349 case IDVFPSZ:
350 CHECK_SIZE(it, size_constraint, 2); 350 CHECK_SIZE(it, size_constraint, 2);
351 SET_UINT16(it, dest->vfpsz); 351 SET_UINT16(it, dest->vfpsz);
352 dest->vfpsz = ntohs(dest->vfpsz); 352 dest->vfpsz.value = ntohs(dest->vfpsz.value);
353 353
354 if (dest->vfpsz.value > 1200) { 354 if (dest->vfpsz.value > 1200) {
355 LOGGER_ERROR("Invalid vfpsz param"); 355 LOGGER_ERROR("Invalid vfpsz param");
@@ -425,7 +425,7 @@ int send_message ( Messenger* m, uint32_t friend_id, const MSIMessage *msg )
425 } 425 }
426 426
427 if (msg->vfpsz.exists) { 427 if (msg->vfpsz.exists) {
428 uint16_t nb_vfpsz = htons(msg->vfpsz); 428 uint16_t nb_vfpsz = htons(msg->vfpsz.value);
429 it = msg_parse_header_out(IDVFPSZ, it, &nb_vfpsz, 429 it = msg_parse_header_out(IDVFPSZ, it, &nb_vfpsz,
430 sizeof(nb_vfpsz), &size); 430 sizeof(nb_vfpsz), &size);
431 } 431 }
@@ -588,17 +588,17 @@ void on_peer_status(Messenger* m, uint32_t friend_id, uint8_t status, void* data
588 case 0: { /* Friend is now offline */ 588 case 0: { /* Friend is now offline */
589 LOGGER_DEBUG("Friend %d is now offline", friend_id); 589 LOGGER_DEBUG("Friend %d is now offline", friend_id);
590 590
591 LOGGED_LOCK(session->mutex); 591 pthread_mutex_lock(session->mutex);
592 MSICall* call = get_call(session, friend_id); 592 MSICall* call = get_call(session, friend_id);
593 593
594 if (call == NULL) { 594 if (call == NULL) {
595 LOGGED_UNLOCK(session->mutex); 595 pthread_mutex_unlock(session->mutex);
596 return; 596 return;
597 } 597 }
598 598
599 invoke_callback(call, msi_OnPeerTimeout); /* Failure is ignored */ 599 invoke_callback(call, msi_OnPeerTimeout); /* Failure is ignored */
600 kill_call(call); 600 kill_call(call);
601 LOGGED_UNLOCK(session->mutex); 601 pthread_mutex_unlock(session->mutex);
602 } 602 }
603 break; 603 break;
604 604
@@ -766,20 +766,20 @@ void handle_msi_packet ( Messenger* m, uint32_t friend_id, const uint8_t* data,
766 LOGGER_DEBUG("Successfully parsed message"); 766 LOGGER_DEBUG("Successfully parsed message");
767 } 767 }
768 768
769 LOGGED_LOCK(session->mutex); 769 pthread_mutex_lock(session->mutex);
770 MSICall *call = get_call(session, friend_id); 770 MSICall *call = get_call(session, friend_id);
771 771
772 if (call == NULL) { 772 if (call == NULL) {
773 if (msg.request.value != requ_push) { 773 if (msg.request.value != requ_push) {
774 send_error(m, friend_id, msi_EStrayMessage); 774 send_error(m, friend_id, msi_EStrayMessage);
775 LOGGED_UNLOCK(session->mutex); 775 pthread_mutex_unlock(session->mutex);
776 return; 776 return;
777 } 777 }
778 778
779 call = new_call(session, friend_id); 779 call = new_call(session, friend_id);
780 if (call == NULL) { 780 if (call == NULL) {
781 send_error(m, friend_id, msi_ESystem); 781 send_error(m, friend_id, msi_ESystem);
782 LOGGED_UNLOCK(session->mutex); 782 pthread_mutex_unlock(session->mutex);
783 return; 783 return;
784 } 784 }
785 } 785 }
@@ -789,5 +789,5 @@ void handle_msi_packet ( Messenger* m, uint32_t friend_id, const uint8_t* data,
789 else 789 else
790 handle_pop(call, &msg); /* always kills the call */ 790 handle_pop(call, &msg); /* always kills the call */
791 791
792 LOGGED_UNLOCK(session->mutex); 792 pthread_mutex_unlock(session->mutex);
793} 793}