summaryrefslogtreecommitdiff
path: root/toxav/msi.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2015-02-20 00:23:38 +0100
committermannol <eniz_vukovic@hotmail.com>2015-02-20 00:23:38 +0100
commitefe31ec92f476faffd6502714d05cce0a7dfadc7 (patch)
tree4afedbb1b005962cb10505c2446c8e5133a51dda /toxav/msi.c
parent6e259d5fcb4666ee0959ddb0bb91deace32703d4 (diff)
Removed extra msi header and started testing
Diffstat (limited to 'toxav/msi.c')
-rw-r--r--toxav/msi.c111
1 files changed, 27 insertions, 84 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index cc855613..16476364 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -50,8 +50,7 @@ typedef enum {
50 IDResponse, 50 IDResponse,
51 IDError, 51 IDError,
52 IDCapabilities, 52 IDCapabilities,
53 IDMVFSZ, 53 IDVFPSZ,
54 IDMVFPSZ,
55 54
56} MSIHeaderID; 55} MSIHeaderID;
57 56
@@ -79,8 +78,7 @@ GENERIC_HEADER ( Request, MSIRequest );
79GENERIC_HEADER ( Response, MSIResponse ); 78GENERIC_HEADER ( Response, MSIResponse );
80GENERIC_HEADER ( Error, MSIError ); 79GENERIC_HEADER ( Error, MSIError );
81GENERIC_HEADER ( Capabilities, uint8_t ); 80GENERIC_HEADER ( Capabilities, uint8_t );
82GENERIC_HEADER ( MVFSZ, uint16_t ); 81GENERIC_HEADER ( VFPSZ, uint16_t );
83GENERIC_HEADER ( MVFPSZ, uint16_t );
84 82
85 83
86typedef struct { 84typedef struct {
@@ -88,8 +86,7 @@ typedef struct {
88 MSIHeaderResponse response; 86 MSIHeaderResponse response;
89 MSIHeaderError error; 87 MSIHeaderError error;
90 MSIHeaderCapabilities capabilities; 88 MSIHeaderCapabilities capabilities;
91 MSIHeaderMVFSZ mvfsz; /* Max video frame size. NOTE: Value must be in network b-order */ 89 MSIHeaderVFPSZ vfpsz; /* Video frame piece size. NOTE: Value must be in network b-order */
92 MSIHeaderMVFPSZ mvfpsz; /* Max video frame piece size. NOTE: Value must be in network b-order */
93} MSIMessage; 90} MSIMessage;
94 91
95 92
@@ -200,12 +197,9 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_
200 197
201 msg_invite.capabilities.exists = true; 198 msg_invite.capabilities.exists = true;
202 msg_invite.capabilities.value = capabilities; 199 msg_invite.capabilities.value = capabilities;
203 200
204 msg_invite.mvfsz.exists = true; 201 msg_invite.vfpsz.exists = true;
205 msg_invite.mvfsz.value = htons(D_MVFSZ); 202 msg_invite.vfpsz.value = htons(VIDEOFRAME_PIECE_SIZE);
206
207 msg_invite.mvfpsz.exists = true;
208 msg_invite.mvfpsz.value = htons(D_MVFPSZ);
209 203
210 send_message ( (*call)->session->messenger, (*call)->friend_id, &msg_invite ); 204 send_message ( (*call)->session->messenger, (*call)->friend_id, &msg_invite );
211 205
@@ -216,7 +210,7 @@ int msi_invite ( MSISession *session, MSICall **call, uint32_t friend_id, uint8_
216} 210}
217int msi_hangup ( MSICall* call ) 211int msi_hangup ( MSICall* call )
218{ 212{
219 LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index); 213 LOGGER_DEBUG("Session: %p Hanging up call with friend: %u", call->session, call->friend_id);
220 214
221 MSIMessage msg_end; 215 MSIMessage msg_end;
222 msg_end.request.exists = true; 216 msg_end.request.exists = true;
@@ -244,11 +238,8 @@ int msi_answer ( MSICall* call, uint8_t capabilities )
244 msg_starting.capabilities.exists = true; 238 msg_starting.capabilities.exists = true;
245 msg_starting.capabilities.value = capabilities; 239 msg_starting.capabilities.value = capabilities;
246 240
247 msg_starting.mvfsz.exists = true; 241 msg_starting.vfpsz.exists = true;
248 msg_starting.mvfsz.value = htons(D_MVFSZ); 242 msg_starting.vfpsz.value = htons(VIDEOFRAME_PIECE_SIZE);
249
250 msg_starting.mvfpsz.exists = true;
251 msg_starting.mvfpsz.value = htons(D_MVFPSZ);
252 243
253 send_message ( call->session->messenger, call->friend_id, &msg_starting ); 244 send_message ( call->session->messenger, call->friend_id, &msg_starting );
254 245
@@ -256,7 +247,7 @@ int msi_answer ( MSICall* call, uint8_t capabilities )
256} 247}
257int msi_reject ( MSICall* call ) 248int msi_reject ( MSICall* call )
258{ 249{
259 LOGGER_DEBUG("Session: %p Rejecting call: %u; reason: %s", session, call_index, reason ? reason : "Unknown"); 250 LOGGER_DEBUG("Session: %p Rejecting call with friend: %u", call->session, call->friend_id);
260 251
261 if ( call->state != msi_CallRequested ) { 252 if ( call->state != msi_CallRequested ) {
262 LOGGER_ERROR("Call is in invalid state!"); 253 LOGGER_ERROR("Call is in invalid state!");
@@ -353,14 +344,9 @@ int msg_parse_in ( MSIMessage *dest, const uint8_t *data, uint16_t length )
353 SET_UINT8(it, dest->capabilities); 344 SET_UINT8(it, dest->capabilities);
354 break; 345 break;
355 346
356 case IDMVFSZ: 347 case IDVFPSZ:
357 CHECK_SIZE(it, size_constraint, 2);
358 SET_UINT16(it, dest->mvfsz);
359 break;
360
361 case IDMVFPSZ:
362 CHECK_SIZE(it, size_constraint, 2); 348 CHECK_SIZE(it, size_constraint, 2);
363 SET_UINT16(it, dest->mvfpsz); 349 SET_UINT16(it, dest->vfpsz);
364 break; 350 break;
365 351
366 default: 352 default:
@@ -408,33 +394,28 @@ int send_message ( Messenger* m, uint32_t friend_id, const MSIMessage *msg )
408 if (msg->request.exists) { 394 if (msg->request.exists) {
409 uint8_t cast = msg->request.value; 395 uint8_t cast = msg->request.value;
410 it = msg_parse_header_out(IDRequest, it, &cast, 396 it = msg_parse_header_out(IDRequest, it, &cast,
411 sizeof(cast), &size); 397 sizeof(cast), &size);
412 } 398 }
413 399
414 if (msg->response.exists) { 400 if (msg->response.exists) {
415 uint8_t cast = msg->response.value; 401 uint8_t cast = msg->response.value;
416 it = msg_parse_header_out(IDResponse, it, &cast, 402 it = msg_parse_header_out(IDResponse, it, &cast,
417 sizeof(cast), &size); 403 sizeof(cast), &size);
418 } 404 }
419 405
420 if (msg->error.exists) { 406 if (msg->error.exists) {
421 it = msg_parse_header_out(IDError, it, &msg->error.value, 407 it = msg_parse_header_out(IDError, it, &msg->error.value,
422 sizeof(msg->error.value), &size); 408 sizeof(msg->error.value), &size);
423 } 409 }
424 410
425 if (msg->capabilities.exists) { 411 if (msg->capabilities.exists) {
426 it = msg_parse_header_out(IDCapabilities, it, &msg->capabilities.value, 412 it = msg_parse_header_out(IDCapabilities, it, &msg->capabilities.value,
427 sizeof(msg->capabilities.value), &size); 413 sizeof(msg->capabilities.value), &size);
428 } 414 }
429 415
430 if (msg->mvfsz.exists) { 416 if (msg->vfpsz.exists) {
431 it = msg_parse_header_out(IDMVFSZ, it, &msg->mvfsz.value, 417 it = msg_parse_header_out(IDVFPSZ, it, &msg->vfpsz.value,
432 sizeof(msg->mvfsz.value), &size); 418 sizeof(msg->vfpsz.value), &size);
433 }
434
435 if (msg->mvfpsz.exists) {
436 it = msg_parse_header_out(IDMVFPSZ, it, &msg->mvfpsz.value,
437 sizeof(msg->mvfpsz.value), &size);
438 } 419 }
439 420
440 *it = 0; 421 *it = 0;
@@ -494,6 +475,7 @@ MSICall *new_call ( MSISession *session, uint32_t friend_id )
494 if (rc == NULL) 475 if (rc == NULL)
495 return NULL; 476 return NULL;
496 477
478 rc->session = session;
497 rc->friend_id = friend_id; 479 rc->friend_id = friend_id;
498 480
499 if (session->calls == NULL) { /* Creating */ 481 if (session->calls == NULL) { /* Creating */
@@ -617,28 +599,14 @@ int handle_recv_invite ( MSICall *call, const MSIMessage *msg )
617 599
618 LOGGER_DEBUG("Glare detected!"); 600 LOGGER_DEBUG("Glare detected!");
619 601
620 if (!msg->mvfsz.exists) { 602 if (!msg->vfpsz.exists) {
621 LOGGER_WARNING("Session: %p Invalid mvfsz on 'invite'");
622 call->error = msi_InvalidMessage;
623 return -1;
624 }
625
626 if (!msg->mvfpsz.exists) {
627 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'"); 603 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'");
628 call->error = msi_InvalidMessage; 604 call->error = msi_InvalidMessage;
629 return -1; 605 return -1;
630 } 606 }
631 607
632 call->peer_capabilities = msg->capabilities.value; 608 call->peer_capabilities = msg->capabilities.value;
633 609 call->peer_vfpsz = ntohs(msg->vfpsz.value);
634 call->peer_mvfsz = ntohs(msg->mvfsz.value);
635 call->peer_mvfpsz = ntohs(msg->mvfpsz.value);
636
637 if (call->peer_mvfsz > call->peer_mvfpsz) {
638 LOGGER_WARNING("Session: %p mvfsz param greater than mvfpsz on 'invite'");
639 call->error = msi_InvalidParam;
640 return -1;
641 }
642 610
643 /* Send response */ 611 /* Send response */
644 response.response.value = resp_starting; 612 response.response.value = resp_starting;
@@ -665,24 +633,14 @@ int handle_recv_invite ( MSICall *call, const MSIMessage *msg )
665 return 0; 633 return 0;
666 } 634 }
667 635
668 636 if (!msg->vfpsz.exists) {
669 if (!msg->mvfsz.exists) {
670 LOGGER_WARNING("Session: %p Invalid mvfsz on 'invite'");
671 call->error = msi_InvalidMessage;
672 return -1;
673 }
674
675 if (!msg->mvfpsz.exists) {
676 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'"); 637 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'");
677 call->error = msi_InvalidMessage; 638 call->error = msi_InvalidMessage;
678 return -1; 639 return -1;
679 } 640 }
680 641
681 call->peer_capabilities = msg->capabilities.value; 642 call->peer_capabilities = msg->capabilities.value;
682 643 call->peer_vfpsz = ntohs(msg->vfpsz.value);
683 call->peer_mvfsz = ntohs(msg->mvfsz.value);
684 call->peer_mvfpsz = ntohs(msg->mvfpsz.value);
685
686 call->state = msi_CallRequested; 644 call->state = msi_CallRequested;
687 645
688 /* Send response */ 646 /* Send response */
@@ -781,31 +739,16 @@ int handle_recv_starting ( MSICall *call, const MSIMessage *msg )
781 return -1; 739 return -1;
782 } 740 }
783 741
784 if (!msg->mvfsz.exists) { 742 if (!msg->vfpsz.exists) {
785 LOGGER_WARNING("Session: %p Invalid mvfsz on 'invite'");
786 call->error = msi_InvalidParam;
787 return -1;
788 }
789
790 if (!msg->mvfpsz.exists) {
791 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'"); 743 LOGGER_WARNING("Session: %p Invalid mvfpsz on 'invite'");
792 call->error = msi_InvalidParam; 744 call->error = msi_InvalidParam;
793 return -1; 745 return -1;
794 } 746 }
795 747
796 call->peer_capabilities = msg->capabilities.value; 748 call->peer_capabilities = msg->capabilities.value;
797 749 call->peer_vfpsz = ntohs(msg->vfpsz.value);
798 call->peer_mvfsz = ntohs(msg->mvfsz.value);
799 call->peer_mvfpsz = ntohs(msg->mvfpsz.value);
800
801
802 if (call->peer_mvfsz > call->peer_mvfpsz) {
803 LOGGER_WARNING("Session: %p mvfsz param greater than mvfpsz on 'invite'");
804 call->error = msi_InvalidParam;
805 return -1;
806 }
807
808 call->state = msi_CallActive; 750 call->state = msi_CallActive;
751
809 invoke_callback(call, msi_OnStart); 752 invoke_callback(call, msi_OnStart);
810 } 753 }
811 /* Otherwise it's a glare case so don't start until 'start' is recved */ 754 /* Otherwise it's a glare case so don't start until 'start' is recved */