Mercurial > pidgin
comparison libpurple/protocols/msn/oim.c @ 24729:1385d79ef68f
Clean up msn_oim_report_to_user to avoid extra g_strdup's and call strchr
instead of strstr.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Mon, 15 Dec 2008 00:49:35 +0000 |
parents | 3c0e7b05714e |
children | 34258af32335 |
comparison
equal
deleted
inserted
replaced
24728:c09a647fd538 | 24729:1385d79ef68f |
---|---|
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; | |
598 gsize body_len; | 600 gsize body_len; |
599 char **tokens; | 601 char **tokens; |
600 char *start,*end; | 602 char *start, *end; |
601 int has_nick = 0; | 603 char *passport; |
602 char *passport_str, *passport; | |
603 time_t stamp; | 604 time_t stamp; |
604 | 605 |
605 message = msn_message_new(MSN_MSG_UNKNOWN); | 606 message = msn_message_new(MSN_MSG_UNKNOWN); |
606 | 607 |
607 msn_message_parse_payload(message, msg_str, strlen(msg_str), | 608 msn_message_parse_payload(message, msg_str, strlen(msg_str), |
608 MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); | 609 MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); |
609 purple_debug_info("msn", "oim body:{%s}\n", message->body); | 610 purple_debug_info("msn", "oim body:{%s}\n", message->body); |
610 decode_msg = (char *)purple_base64_decode(message->body,&body_len); | 611 decode_msg = (char *)purple_base64_decode(message->body, &body_len); |
611 date = (char *)g_hash_table_lookup(message->attr_table, "Date"); | 612 date = msn_message_get_attr(message, "Date"); |
612 from = (char *)g_hash_table_lookup(message->attr_table, "From"); | 613 from = msn_message_get_attr(message, "From"); |
613 if (strstr(from," ")) { | 614 |
614 has_nick = 1; | 615 tokens = g_strsplit(from, " ", 2); |
615 } | 616 if (tokens[1] != NULL) |
616 if (has_nick) { | 617 from = (const char *)tokens[1]; |
617 tokens = g_strsplit(from , " " , 2); | 618 |
618 passport_str = g_strdup(tokens[1]); | 619 start = strchr(from, '<') + 1; |
619 purple_debug_info("msn", "oim Date:{%s},nickname:{%s},tokens[1]:{%s} passport{%s}\n", | 620 end = strchr(from, '>'); |
620 date, tokens[0], tokens[1], passport_str); | 621 passport = g_strndup(start, end - start); |
621 g_strfreev(tokens); | 622 purple_debug_info("msn", "oim Date:{%s},passport{%s},tokens[0]:{%s}\n", |
622 } else { | 623 date, passport, tokens[0]); |
623 passport_str = g_strdup(from); | |
624 purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", | |
625 date, passport_str); | |
626 } | |
627 start = strstr(passport_str,"<"); | |
628 start += 1; | |
629 end = strstr(passport_str,">"); | |
630 passport = g_strndup(start,end - start); | |
631 g_free(passport_str); | |
632 purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", date, passport); | |
633 | 624 |
634 stamp = msn_oim_parse_timestamp(date); | 625 stamp = msn_oim_parse_timestamp(date); |
635 | 626 |
636 serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0, | 627 serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0, |
637 stamp); | 628 stamp); |
638 | 629 |
639 /*Now get the oim message ID from the oim_list. | 630 /*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 | 631 * and append to read list to prepare for deleting the Offline Message when sign out |
641 */ | 632 */ |
642 msn_oim_post_delete_msg(rdata); | 633 msn_oim_post_delete_msg(rdata); |
643 | 634 |
635 g_strfreev(tokens); | |
644 g_free(passport); | 636 g_free(passport); |
645 g_free(decode_msg); | 637 g_free(decode_msg); |
646 } | 638 } |
647 | 639 |
648 /* Parse the XML data, | 640 /* Parse the XML data, |