comparison libpurple/protocols/msn/oim.c @ 23499:7b03d95902d4

References #4382, fixes receiving too many offline messages committer: Ka-Hing Cheung <khc@hxbc.us>
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 12 Jan 2008 23:32:00 +0000
parents bca58b00afab
children d756a0477c06
comparison
equal deleted inserted replaced
23498:bca58b00afab 23499:7b03d95902d4
39 MsnOim *oim; 39 MsnOim *oim;
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_oim_post_single_get_msg(MsnOim *oim, char *msgid); 45 static void msn_oim_post_single_get_msg(MsnOim *oim, char *msgid);
45 static MsnOimSendReq *msn_oim_new_send_req(const char *from_member, 46 static MsnOimSendReq *msn_oim_new_send_req(const char *from_member,
46 const char *friendname, 47 const char *friendname,
47 const char* to_member, 48 const char* to_member,
48 const char *msg); 49 const char *msg);
107 g_free(req->friendname); 108 g_free(req->friendname);
108 g_free(req->to_member); 109 g_free(req->to_member);
109 g_free(req->oim_msg); 110 g_free(req->oim_msg);
110 111
111 g_free(req); 112 g_free(req);
113 }
114
115 /****************************************
116 * OIM GetMetadata request
117 * **************************************/
118 static void
119 msn_oim_get_metadata_cb(MsnSoapMessage *request, MsnSoapMessage *response,
120 gpointer data)
121 {
122 MsnOim *oim = data;
123
124 if (response) {
125 msn_parse_oim_xml(oim,
126 xmlnode_get_child(response->xml, "Body/GetMetadataResponse/MD"));
127 }
128 }
129
130 /* Post to get the OIM Metadata */
131 static void
132 msn_oim_get_metadata(MsnOim *oim)
133 {
134 char *soap_body;
135 GHashTable *token;
136 const char *msn_t;
137 const char *msn_p;
138
139 token = msn_nexus_get_token(oim->session->nexus, MSN_AUTH_MESSENGER_WEB);
140 g_return_if_fail(token != NULL);
141
142 msn_t = g_hash_table_lookup(token, "t");
143 msn_p = g_hash_table_lookup(token, "p");
144
145 g_return_if_fail(msn_t != NULL);
146 g_return_if_fail(msn_p != NULL);
147
148 soap_body = g_strdup_printf(MSN_OIM_GET_METADATA_TEMPLATE, msn_t, msn_p);
149
150 msn_soap_message_send(oim->session,
151 msn_soap_message_new(MSN_OIM_GET_METADATA_ACTION,
152 xmlnode_from_str(soap_body, -1)),
153 MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
154 msn_oim_get_metadata_cb, oim);
155
156 g_free(soap_body);
112 } 157 }
113 158
114 /**************************************** 159 /****************************************
115 * OIM send SOAP request 160 * OIM send SOAP request
116 * **************************************/ 161 * **************************************/
474 * and post it to the soap server to get the Offline Message 519 * and post it to the soap server to get the Offline Message
475 * */ 520 * */
476 void 521 void
477 msn_parse_oim_msg(MsnOim *oim,const char *xmlmsg) 522 msn_parse_oim_msg(MsnOim *oim,const char *xmlmsg)
478 { 523 {
479 xmlnode *node, *mNode; 524 xmlnode *node;
525
526 purple_debug_info("MSNP14:OIM", "%s\n", xmlmsg);
527
528 if (!strcmp(xmlmsg, "too-large")) {
529 /* Too many OIM's to send via NS, so we need to request them via SOAP. */
530 msn_oim_get_metadata(oim);
531 } else {
532 node = xmlnode_from_str(xmlmsg, -1);
533 msn_parse_oim_xml(oim, node);
534 xmlnode_free(node);
535 }
536 }
537
538 static void
539 msn_parse_oim_xml(MsnOim *oim, xmlnode *node)
540 {
541 xmlnode *mNode;
480 xmlnode *iu_node; 542 xmlnode *iu_node;
481 MsnSession *session = oim->session; 543 MsnSession *session = oim->session;
482 544
483 purple_debug_info("MSNP14:OIM", "%s\n", xmlmsg); 545 g_return_if_fail(node != NULL);
484 546
485 node = xmlnode_from_str(xmlmsg, -1);
486 if (strcmp(node->name, "MD") != 0) { 547 if (strcmp(node->name, "MD") != 0) {
548 char *xmlmsg = xmlnode_to_str(node, NULL);
487 purple_debug_info("msnoim", "WTF is this? %s\n", xmlmsg); 549 purple_debug_info("msnoim", "WTF is this? %s\n", xmlmsg);
488 xmlnode_free(node); 550 g_free(xmlmsg);
489 return; 551 return;
490 } 552 }
491 553
492 iu_node = xmlnode_get_child(node, "E/IU"); 554 iu_node = xmlnode_get_child(node, "E/IU");
493 555
534 g_free(passport); 596 g_free(passport);
535 g_free(msgid); 597 g_free(msgid);
536 g_free(rtime); 598 g_free(rtime);
537 g_free(nickname); 599 g_free(nickname);
538 } 600 }
539
540 xmlnode_free(node);
541 } 601 }
542 602
543 /*Post to get the Offline Instant Message*/ 603 /*Post to get the Offline Instant Message*/
544 static void 604 static void
545 msn_oim_post_single_get_msg(MsnOim *oim, char *msgid) 605 msn_oim_post_single_get_msg(MsnOim *oim, char *msgid)