Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/oim.c @ 23728:3c0e7b05714e
Fix a leak when requesting OIM's. Also removed some unnecessary
prototypes from oim.c while I was there.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 03 Aug 2008 23:55:06 +0000 |
parents | 860e5e210fc9 |
children | 1385d79ef68f |
comparison
equal
deleted
inserted
replaced
23685:58bb7fc244e4 | 23728:3c0e7b05714e |
---|---|
40 char *msg_id; | 40 char *msg_id; |
41 } MsnOimRecvData; | 41 } MsnOimRecvData; |
42 | 42 |
43 /*Local Function Prototype*/ | 43 /*Local Function Prototype*/ |
44 static void msn_parse_oim_xml(MsnOim *oim, xmlnode *node); | 44 static void msn_parse_oim_xml(MsnOim *oim, xmlnode *node); |
45 static void msn_oim_post_single_get_msg(MsnOim *oim, char *msgid); | |
46 static MsnOimSendReq *msn_oim_new_send_req(const char *from_member, | |
47 const char *friendname, | |
48 const char* to_member, | |
49 const char *msg); | |
50 static void msn_oim_free_send_req(MsnOimSendReq *req); | 45 static void msn_oim_free_send_req(MsnOimSendReq *req); |
51 static void msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str); | 46 static void msn_oim_recv_data_free(MsnOimRecvData *data); |
52 static char *msn_oim_msg_to_str(MsnOim *oim, const char *body); | 47 static void msn_oim_post_single_get_msg(MsnOim *oim, MsnOimRecvData *data); |
53 | 48 |
54 /*new a OIM object*/ | 49 /*new a OIM object*/ |
55 MsnOim * | 50 MsnOim * |
56 msn_oim_new(MsnSession *session) | 51 msn_oim_new(MsnSession *session) |
57 { | 52 { |
75 | 70 |
76 purple_debug_info("msn", "destroy the OIM %p\n", oim); | 71 purple_debug_info("msn", "destroy the OIM %p\n", oim); |
77 g_free(oim->run_id); | 72 g_free(oim->run_id); |
78 g_free(oim->challenge); | 73 g_free(oim->challenge); |
79 | 74 |
80 while((request = g_queue_pop_head(oim->send_queue)) != NULL){ | 75 while ((request = g_queue_pop_head(oim->send_queue)) != NULL) |
81 msn_oim_free_send_req(request); | 76 msn_oim_free_send_req(request); |
82 } | |
83 | |
84 g_queue_free(oim->send_queue); | 77 g_queue_free(oim->send_queue); |
85 g_list_free(oim->oim_list); | 78 |
79 while (oim->oim_list != NULL) | |
80 msn_oim_recv_data_free((MsnOimRecvData *)oim->oim_list->data); | |
86 | 81 |
87 g_free(oim); | 82 g_free(oim); |
88 } | 83 } |
89 | 84 |
90 static MsnOimSendReq * | 85 static MsnOimSendReq * |
110 g_free(req->friendname); | 105 g_free(req->friendname); |
111 g_free(req->to_member); | 106 g_free(req->to_member); |
112 g_free(req->oim_msg); | 107 g_free(req->oim_msg); |
113 | 108 |
114 g_free(req); | 109 g_free(req); |
110 } | |
111 | |
112 static MsnOimRecvData * | |
113 msn_oim_recv_data_new(MsnOim *oim, char *msg_id) | |
114 { | |
115 MsnOimRecvData *data; | |
116 | |
117 data = g_new0(MsnOimRecvData, 1); | |
118 data->oim = oim; | |
119 data->msg_id = msg_id; | |
120 | |
121 oim->oim_list = g_list_append(oim->oim_list, data); | |
122 | |
123 return data; | |
124 } | |
125 | |
126 /* Probably only good for g_list_find_custom */ | |
127 static gint | |
128 msn_recv_data_equal(MsnOimRecvData *a, const char *msg_id) | |
129 { | |
130 return strcmp(a->msg_id, msg_id); | |
131 } | |
132 | |
133 static void | |
134 msn_oim_recv_data_free(MsnOimRecvData *data) | |
135 { | |
136 data->oim->oim_list = g_list_remove(data->oim->oim_list, data); | |
137 g_free(data->msg_id); | |
138 | |
139 g_free(data); | |
115 } | 140 } |
116 | 141 |
117 /**************************************** | 142 /**************************************** |
118 * Manage OIM Tokens | 143 * Manage OIM Tokens |
119 ****************************************/ | 144 ****************************************/ |
463 msn_oim_delete_read_cb(MsnSoapMessage *request, MsnSoapMessage *response, | 488 msn_oim_delete_read_cb(MsnSoapMessage *request, MsnSoapMessage *response, |
464 gpointer data) | 489 gpointer data) |
465 { | 490 { |
466 MsnOimRecvData *rdata = data; | 491 MsnOimRecvData *rdata = data; |
467 | 492 |
468 if (response && xmlnode_get_child(response->xml, "Body/Fault") == NULL) { | 493 if (response && xmlnode_get_child(response->xml, "Body/Fault") == NULL) |
469 purple_debug_info("msn", "Delete OIM success\n"); | 494 purple_debug_info("msn", "Delete OIM success\n"); |
470 rdata->oim->oim_list = g_list_remove(rdata->oim->oim_list, | 495 else |
471 rdata->msg_id); | |
472 g_free(rdata->msg_id); | |
473 } else { | |
474 purple_debug_info("msn", "Delete OIM failed\n"); | 496 purple_debug_info("msn", "Delete OIM failed\n"); |
475 } | 497 |
476 | 498 msn_oim_recv_data_free(rdata); |
477 g_free(rdata); | |
478 } | 499 } |
479 | 500 |
480 /*Post to get the Offline Instant Message*/ | 501 /*Post to get the Offline Instant Message*/ |
481 static void | 502 static void |
482 msn_oim_post_delete_msg(MsnOimRecvData *rdata) | 503 msn_oim_post_delete_msg(MsnOimRecvData *rdata) |
643 g_free(msg_str); | 664 g_free(msg_str); |
644 } else { | 665 } else { |
645 char *str = xmlnode_to_str(response->xml, NULL); | 666 char *str = xmlnode_to_str(response->xml, NULL); |
646 purple_debug_info("msn", "Unknown OIM response: %s\n", str); | 667 purple_debug_info("msn", "Unknown OIM response: %s\n", str); |
647 g_free(str); | 668 g_free(str); |
669 msn_oim_recv_data_free(rdata); | |
648 } | 670 } |
649 } else { | 671 } else { |
650 purple_debug_info("msn", "Failed to get OIM\n"); | 672 purple_debug_info("msn", "Failed to get OIM\n"); |
651 } | 673 msn_oim_recv_data_free(rdata); |
674 } | |
675 | |
652 } | 676 } |
653 | 677 |
654 /* parse the oim XML data | 678 /* parse the oim XML data |
655 * and post it to the soap server to get the Offline Message | 679 * and post it to the soap server to get the Offline Message |
656 * */ | 680 * */ |
721 if (rt_node != NULL) { | 745 if (rt_node != NULL) { |
722 rtime = xmlnode_get_data(rt_node); | 746 rtime = xmlnode_get_data(rt_node); |
723 } | 747 } |
724 /* purple_debug_info("msn", "E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */ | 748 /* purple_debug_info("msn", "E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */ |
725 | 749 |
726 if (!g_list_find_custom(oim->oim_list, msgid, (GCompareFunc)strcmp)) { | 750 if (!g_list_find_custom(oim->oim_list, msgid, (GCompareFunc)msn_recv_data_equal)) { |
727 oim->oim_list = g_list_append(oim->oim_list, msgid); | 751 MsnOimRecvData *data = msn_oim_recv_data_new(oim, msgid); |
728 msn_oim_post_single_get_msg(oim, msgid); | 752 msn_oim_post_single_get_msg(oim, data); |
729 msgid = NULL; | 753 msgid = NULL; |
730 } | 754 } |
731 | 755 |
732 g_free(passport); | 756 g_free(passport); |
733 g_free(msgid); | 757 g_free(msgid); |
736 } | 760 } |
737 } | 761 } |
738 | 762 |
739 /*Post to get the Offline Instant Message*/ | 763 /*Post to get the Offline Instant Message*/ |
740 static void | 764 static void |
741 msn_oim_post_single_get_msg(MsnOim *oim, char *msgid) | 765 msn_oim_post_single_get_msg(MsnOim *oim, MsnOimRecvData *data) |
742 { | 766 { |
743 char *soap_body; | 767 char *soap_body; |
744 MsnOimRecvData *data = g_new0(MsnOimRecvData, 1); | |
745 | 768 |
746 purple_debug_info("msn", "Get single OIM Message\n"); | 769 purple_debug_info("msn", "Get single OIM Message\n"); |
747 | 770 |
748 data->oim = oim; | 771 soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE, data->msg_id); |
749 data->msg_id = msgid; | |
750 | |
751 soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE, msgid); | |
752 | 772 |
753 msn_oim_make_request(oim, FALSE, MSN_OIM_GET_SOAP_ACTION, MSN_OIM_RETRIEVE_HOST, | 773 msn_oim_make_request(oim, FALSE, MSN_OIM_GET_SOAP_ACTION, MSN_OIM_RETRIEVE_HOST, |
754 MSN_OIM_RETRIEVE_URL, xmlnode_from_str(soap_body, -1), msn_oim_get_read_cb, | 774 MSN_OIM_RETRIEVE_URL, xmlnode_from_str(soap_body, -1), msn_oim_get_read_cb, |
755 data); | 775 data); |
756 | 776 |
757 g_free(soap_body); | 777 g_free(soap_body); |
758 } | 778 } |
779 |