Mercurial > pidgin
comparison libpurple/protocols/msn/oim.c @ 25237:401f548e3544
propagate from branch 'im.pidgin.pidgin' (head df6eba32e5b6b34d7483cbfb7e9f2e4c836ac35f)
to branch 'org.darkrain42.pidgin.buddy-add' (head 6831808999a270f8c1a128c7430a73d3dc0bfae2)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 21 Dec 2008 18:32:37 +0000 |
parents | fbd1a82247ba |
children | 955bfda56492 |
comparison
equal
deleted
inserted
replaced
25172:125cac3e24ee | 25237:401f548e3544 |
---|---|
592 /*Post the Offline Instant Message to User Conversation*/ | 592 /*Post the Offline Instant Message to User Conversation*/ |
593 static void | 593 static void |
594 msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str) | 594 msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str) |
595 { | 595 { |
596 MsnMessage *message; | 596 MsnMessage *message; |
597 char *date,*from,*decode_msg; | 597 const char *date; |
598 const char *from; | |
599 char *decode_msg = NULL; | |
598 gsize body_len; | 600 gsize body_len; |
599 char **tokens; | 601 char **tokens; |
600 char *start,*end; | 602 char *passport = NULL; |
601 int has_nick = 0; | |
602 char *passport_str, *passport; | |
603 time_t stamp; | 603 time_t stamp; |
604 | 604 |
605 message = msn_message_new(MSN_MSG_UNKNOWN); | 605 message = msn_message_new(MSN_MSG_UNKNOWN); |
606 | 606 |
607 msn_message_parse_payload(message, msg_str, strlen(msg_str), | 607 msn_message_parse_payload(message, msg_str, strlen(msg_str), |
608 MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); | 608 MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); |
609 purple_debug_info("msn", "oim body:{%s}\n", message->body); | 609 purple_debug_info("msn", "oim body:{%s}\n", message->body); |
610 decode_msg = (char *)purple_base64_decode(message->body,&body_len); | 610 |
611 date = (char *)g_hash_table_lookup(message->attr_table, "Date"); | 611 if (!strcmp(msn_message_get_attr(message, "X-OIMProxy"), "MOSMS")) { |
612 from = (char *)g_hash_table_lookup(message->attr_table, "From"); | 612 char *boundary; |
613 if (strstr(from," ")) { | 613 char **part; |
614 has_nick = 1; | 614 |
615 } | 615 from = msn_message_get_attr(message, "X-OIM-originatingSource"); |
616 if (has_nick) { | 616 |
617 tokens = g_strsplit(from , " " , 2); | 617 /* Match number to user's mobile number, FROM is a phone number |
618 passport_str = g_strdup(tokens[1]); | 618 if the other side pages you using your phone number */ |
619 purple_debug_info("msn", "oim Date:{%s},nickname:{%s},tokens[1]:{%s} passport{%s}\n", | 619 if (!strncmp(from, "tel:+", 5)) { |
620 date, tokens[0], tokens[1], passport_str); | 620 MsnUser *user = msn_userlist_find_user_with_mobile_phone( |
621 rdata->oim->session->userlist, from + 4); | |
622 | |
623 if (user && user->passport) | |
624 passport = g_strdup(user->passport); | |
625 } | |
626 if (passport == NULL) | |
627 passport = g_strdup(from); | |
628 | |
629 boundary = g_strdup_printf("--%s" MSG_OIM_LINE_DEM, | |
630 msn_message_get_attr(message, "boundary")); | |
631 tokens = g_strsplit(message->body, boundary, 0); | |
632 | |
633 /* tokens+1 to skip the "This is a multipart message..." text */ | |
634 for (part = tokens+1; *part != NULL; part++) { | |
635 MsnMessage *multipart; | |
636 const char *type; | |
637 multipart = msn_message_new(MSN_MSG_UNKNOWN); | |
638 msn_message_parse_payload(multipart, *part, strlen(*part), | |
639 MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); | |
640 | |
641 type = msn_message_get_content_type(multipart); | |
642 if (type && !strcmp(type, "text/plain")) { | |
643 decode_msg = (char *)purple_base64_decode(multipart->body, &body_len); | |
644 msn_message_destroy(multipart); | |
645 break; | |
646 } | |
647 msn_message_destroy(multipart); | |
648 } | |
649 | |
621 g_strfreev(tokens); | 650 g_strfreev(tokens); |
651 g_free(boundary); | |
652 | |
653 if (decode_msg == NULL) { | |
654 purple_debug_error("msn", "Couldn't find text/plain OIM message.\n"); | |
655 g_free(passport); | |
656 return; | |
657 } | |
622 } else { | 658 } else { |
623 passport_str = g_strdup(from); | 659 char *start, *end; |
624 purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", | 660 |
625 date, passport_str); | 661 from = msn_message_get_attr(message, "From"); |
626 } | 662 decode_msg = (char *)purple_base64_decode(message->body, &body_len); |
627 start = strstr(passport_str,"<"); | 663 |
628 start += 1; | 664 tokens = g_strsplit(from, " ", 2); |
629 end = strstr(passport_str,">"); | 665 if (tokens[1] != NULL) |
630 passport = g_strndup(start,end - start); | 666 from = (const char *)tokens[1]; |
631 g_free(passport_str); | 667 |
632 purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", date, passport); | 668 start = strchr(from, '<') + 1; |
633 | 669 end = strchr(from, '>'); |
670 passport = g_strndup(start, end - start); | |
671 | |
672 g_strfreev(tokens); | |
673 } | |
674 | |
675 date = msn_message_get_attr(message, "Date"); | |
634 stamp = msn_oim_parse_timestamp(date); | 676 stamp = msn_oim_parse_timestamp(date); |
677 purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", | |
678 date, passport); | |
635 | 679 |
636 serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0, | 680 serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0, |
637 stamp); | 681 stamp); |
638 | 682 |
639 /*Now get the oim message ID from the oim_list. | 683 /*Now get the oim message ID from the oim_list. |
640 * and append to read list to prepare for deleting the Offline Message when sign out | 684 * and append to read list to prepare for deleting the Offline Message when sign out |
641 */ | 685 */ |
642 msn_oim_post_delete_msg(rdata); | 686 msn_oim_post_delete_msg(rdata); |