Mercurial > pidgin
comparison libpurple/protocols/msn/slplink.c @ 30857:1ded0bc5c911
Split msn_slplink_process_msg in three smaller functions.
author | masca@cpw.pidgin.im |
---|---|
date | Wed, 28 Jul 2010 20:35:28 +0000 |
parents | 9f41998d4fcc |
children | 2d00d29a45fd |
comparison
equal
deleted
inserted
replaced
30856:9f41998d4fcc | 30857:1ded0bc5c911 |
---|---|
457 } | 457 } |
458 | 458 |
459 return NULL; | 459 return NULL; |
460 } | 460 } |
461 | 461 |
462 static MsnSlpMessage * | |
463 init_first_msg(MsnSlpLink *slplink, MsnP2PHeader *header) | |
464 { | |
465 MsnSlpMessage *slpmsg; | |
466 | |
467 slpmsg = msn_slpmsg_new(slplink); | |
468 slpmsg->id = header->id; | |
469 slpmsg->header->session_id = header->session_id; | |
470 slpmsg->size = header->total_size; | |
471 slpmsg->flags = header->flags; | |
472 | |
473 if (slpmsg->header->session_id) | |
474 { | |
475 slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->header->session_id); | |
476 if (slpmsg->slpcall != NULL) | |
477 { | |
478 if (slpmsg->flags == P2P_MSN_OBJ_DATA || | |
479 slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) || | |
480 slpmsg->flags == P2P_FILE_DATA) | |
481 { | |
482 PurpleXfer *xfer = slpmsg->slpcall->xfer; | |
483 if (xfer != NULL) | |
484 { | |
485 slpmsg->ft = TRUE; | |
486 slpmsg->slpcall->xfer_msg = slpmsg; | |
487 | |
488 purple_xfer_ref(xfer); | |
489 purple_xfer_start(xfer, -1, NULL, 0); | |
490 | |
491 if (xfer->data == NULL) { | |
492 purple_xfer_unref(xfer); | |
493 msn_slpmsg_destroy(slpmsg); | |
494 g_return_val_if_reached(NULL); | |
495 } else { | |
496 purple_xfer_unref(xfer); | |
497 } | |
498 } | |
499 } | |
500 } | |
501 } | |
502 if (!slpmsg->ft && slpmsg->size) | |
503 { | |
504 slpmsg->buffer = g_try_malloc(slpmsg->size); | |
505 if (slpmsg->buffer == NULL) | |
506 { | |
507 purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); | |
508 msn_slpmsg_destroy(slpmsg); | |
509 return NULL; | |
510 } | |
511 } | |
512 | |
513 return slpmsg; | |
514 } | |
515 | |
516 static void | |
517 process_complete_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg, MsnP2PHeader *header) | |
518 { | |
519 MsnSlpCall *slpcall; | |
520 | |
521 slpcall = msn_slp_process_msg(slplink, slpmsg); | |
522 | |
523 if (slpcall == NULL) { | |
524 msn_slpmsg_destroy(slpmsg); | |
525 return; | |
526 } | |
527 | |
528 purple_debug_info("msn", "msn_slplink_process_msg: slpmsg complete\n"); | |
529 | |
530 if (/* !slpcall->wasted && */ slpmsg->flags == 0x100) | |
531 { | |
532 #if 0 | |
533 MsnDirectConn *directconn; | |
534 | |
535 directconn = slplink->directconn; | |
536 if (!directconn->acked) | |
537 msn_directconn_send_handshake(directconn); | |
538 #endif | |
539 } | |
540 else if (slpmsg->flags == P2P_NO_FLAG || slpmsg->flags == P2P_WML2009_COMP || | |
541 slpmsg->flags == P2P_MSN_OBJ_DATA || | |
542 slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) || | |
543 slpmsg->flags == P2P_FILE_DATA) | |
544 { | |
545 /* Release all the messages and send the ACK */ | |
546 | |
547 if (slpcall->wait_for_socket) { | |
548 /* | |
549 * Save ack for later because we have to send | |
550 * a 200 OK message to the previous direct connect | |
551 * invitation before ACK but the listening socket isn't | |
552 * created yet. | |
553 */ | |
554 purple_debug_info("msn", "msn_slplink_process_msg: save ACK\n"); | |
555 | |
556 slpcall->slplink->dc->prev_ack = msn_slplink_create_ack(slplink, header); | |
557 } else if (!slpcall->wasted) { | |
558 purple_debug_info("msn", "msn_slplink_process_msg: send ACK\n"); | |
559 | |
560 msn_slplink_send_ack(slplink, header); | |
561 msn_slplink_send_queued_slpmsgs(slplink); | |
562 } | |
563 } | |
564 | |
565 msn_slpmsg_destroy(slpmsg); | |
566 | |
567 if (!slpcall->wait_for_socket && slpcall->wasted) | |
568 msn_slpcall_destroy(slpcall); | |
569 } | |
570 | |
462 void | 571 void |
463 msn_slplink_process_msg(MsnSlpLink *slplink, MsnP2PHeader *header, const char *data, gsize len) | 572 msn_slplink_process_msg(MsnSlpLink *slplink, MsnP2PHeader *header, const char *data, gsize len) |
464 { | 573 { |
465 MsnSlpMessage *slpmsg; | 574 MsnSlpMessage *slpmsg; |
466 guint64 offset; | 575 guint64 offset; |
475 } | 584 } |
476 | 585 |
477 offset = header->offset; | 586 offset = header->offset; |
478 | 587 |
479 if (offset == 0) | 588 if (offset == 0) |
480 { | 589 slpmsg = init_first_msg(slplink, header); |
481 slpmsg = msn_slpmsg_new(slplink); | 590 else { |
482 slpmsg->id = header->id; | |
483 slpmsg->header->session_id = header->session_id; | |
484 slpmsg->size = header->total_size; | |
485 slpmsg->flags = header->flags; | |
486 | |
487 if (slpmsg->header->session_id) | |
488 { | |
489 slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->header->session_id); | |
490 if (slpmsg->slpcall != NULL) | |
491 { | |
492 if (slpmsg->flags == P2P_MSN_OBJ_DATA || | |
493 slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) || | |
494 slpmsg->flags == P2P_FILE_DATA) | |
495 { | |
496 PurpleXfer *xfer = slpmsg->slpcall->xfer; | |
497 if (xfer != NULL) | |
498 { | |
499 slpmsg->ft = TRUE; | |
500 slpmsg->slpcall->xfer_msg = slpmsg; | |
501 | |
502 purple_xfer_ref(xfer); | |
503 purple_xfer_start(xfer, -1, NULL, 0); | |
504 | |
505 if (xfer->data == NULL) { | |
506 purple_xfer_unref(xfer); | |
507 msn_slpmsg_destroy(slpmsg); | |
508 g_return_if_reached(); | |
509 } else { | |
510 purple_xfer_unref(xfer); | |
511 } | |
512 } | |
513 } | |
514 } | |
515 } | |
516 if (!slpmsg->ft && slpmsg->size) | |
517 { | |
518 slpmsg->buffer = g_try_malloc(slpmsg->size); | |
519 if (slpmsg->buffer == NULL) | |
520 { | |
521 purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); | |
522 msn_slpmsg_destroy(slpmsg); | |
523 return; | |
524 } | |
525 } | |
526 } | |
527 else | |
528 { | |
529 slpmsg = msn_slplink_message_find(slplink, header->session_id, header->id); | 591 slpmsg = msn_slplink_message_find(slplink, header->session_id, header->id); |
530 if (slpmsg == NULL) | 592 if (slpmsg == NULL) |
531 { | 593 { |
532 /* Probably the transfer was canceled */ | 594 /* Probably the transfer was canceled */ |
533 purple_debug_error("msn", "Couldn't find slpmsg\n"); | 595 purple_debug_error("msn", "Couldn't find slpmsg\n"); |
572 #if 0 | 634 #if 0 |
573 if (slpmsg->buffer == NULL) | 635 if (slpmsg->buffer == NULL) |
574 return; | 636 return; |
575 #endif | 637 #endif |
576 | 638 |
639 /* All the pieces of the slpmsg have been received */ | |
577 if (header->offset + header->length >= header->total_size) | 640 if (header->offset + header->length >= header->total_size) |
578 { | 641 process_complete_msg(slplink, slpmsg, header); |
579 /* All the pieces of the slpmsg have been received */ | |
580 MsnSlpCall *slpcall; | |
581 | |
582 slpcall = msn_slp_process_msg(slplink, slpmsg); | |
583 | |
584 if (slpcall == NULL) { | |
585 msn_slpmsg_destroy(slpmsg); | |
586 return; | |
587 } | |
588 | |
589 purple_debug_info("msn", "msn_slplink_process_msg: slpmsg complete\n"); | |
590 | |
591 if (/* !slpcall->wasted && */ slpmsg->flags == 0x100) | |
592 { | |
593 #if 0 | |
594 MsnDirectConn *directconn; | |
595 | |
596 directconn = slplink->directconn; | |
597 if (!directconn->acked) | |
598 msn_directconn_send_handshake(directconn); | |
599 #endif | |
600 } | |
601 else if (slpmsg->flags == P2P_NO_FLAG || slpmsg->flags == P2P_WML2009_COMP || | |
602 slpmsg->flags == P2P_MSN_OBJ_DATA || | |
603 slpmsg->flags == (P2P_WML2009_COMP | P2P_MSN_OBJ_DATA) || | |
604 slpmsg->flags == P2P_FILE_DATA) | |
605 { | |
606 /* Release all the messages and send the ACK */ | |
607 | |
608 if (slpcall->wait_for_socket) { | |
609 /* | |
610 * Save ack for later because we have to send | |
611 * a 200 OK message to the previous direct connect | |
612 * invitation before ACK but the listening socket isn't | |
613 * created yet. | |
614 */ | |
615 purple_debug_info("msn", "msn_slplink_process_msg: save ACK\n"); | |
616 | |
617 slpcall->slplink->dc->prev_ack = msn_slplink_create_ack(slplink, header); | |
618 } else if (!slpcall->wasted) { | |
619 purple_debug_info("msn", "msn_slplink_process_msg: send ACK\n"); | |
620 | |
621 msn_slplink_send_ack(slplink, header); | |
622 msn_slplink_send_queued_slpmsgs(slplink); | |
623 } | |
624 } | |
625 | |
626 msn_slpmsg_destroy(slpmsg); | |
627 | |
628 if (!slpcall->wait_for_socket && slpcall->wasted) | |
629 msn_slpcall_destroy(slpcall); | |
630 } | |
631 } | 642 } |
632 | 643 |
633 void | 644 void |
634 msn_slplink_request_object(MsnSlpLink *slplink, | 645 msn_slplink_request_object(MsnSlpLink *slplink, |
635 const char *info, | 646 const char *info, |