Mercurial > hg
comparison mcabber/src/jab_iq.c @ 698:60522cf6d325
Propagate context to IQ callback functions
It will allow to deal with timeouts and errors more easily.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 12 Feb 2006 11:06:26 +0100 |
parents | d3511f846d47 |
children | ee03b56b93ee |
comparison
equal
deleted
inserted
replaced
697:f75972271c1f | 698:60522cf6d325 |
---|---|
100 return i; | 100 return i; |
101 } | 101 } |
102 return NULL; | 102 return NULL; |
103 } | 103 } |
104 | 104 |
105 // iqs_callback(iqid, xml_result) | 105 // iqs_callback(iqid, xml_result, iqcontext) |
106 // Callback processing for the iqid message. | 106 // Callback processing for the iqid message. |
107 // If we've received an answer, xml_result should point to the xmldata packet. | 107 // If we've received an answer, xml_result should point to the xmldata packet. |
108 // If this is a timeout, xml_result should be NULL. | 108 // If this is a timeout, xml_result should be NULL. |
109 // Return 0 in case of success, -1 if the iqid hasn't been found. | 109 // Return 0 in case of success, -1 if the iqid hasn't been found. |
110 int iqs_callback(const char *iqid, xmlnode xml_result) | 110 int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext) |
111 { | 111 { |
112 iqs *i; | 112 iqs *i; |
113 | 113 |
114 i = iqs_find(iqid); | 114 i = iqs_find(iqid); |
115 if (!i) return -1; | 115 if (!i) return -1; |
116 | 116 |
117 // IQ processing | 117 // IQ processing |
118 // Note: If xml_result is NULL, this is a timeout | 118 // Note: If xml_result is NULL, this is a timeout |
119 if (i->callback) | 119 if (i->callback) |
120 (*i->callback)(i, xml_result); | 120 (*i->callback)(i, xml_result, iqcontext); |
121 | 121 |
122 iqs_del(iqid); | 122 iqs_del(iqid); |
123 return 0; | 123 return 0; |
124 } | 124 } |
125 | 125 |
133 | 133 |
134 for (p = iqs_list; p; p = g_slist_next(p)) { | 134 for (p = iqs_list; p; p = g_slist_next(p)) { |
135 i = p->data; | 135 i = p->data; |
136 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || | 136 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || |
137 (i->ts_expire && now_t > i->ts_expire)) { | 137 (i->ts_expire && now_t > i->ts_expire)) { |
138 iqs_callback(i->id, NULL); | 138 iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT); |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 void jb_iqs_display_list(void) | 143 void jb_iqs_display_list(void) |
239 update_roster = TRUE; | 239 update_roster = TRUE; |
240 if (need_refresh) | 240 if (need_refresh) |
241 scr_ShowBuddyWindow(); | 241 scr_ShowBuddyWindow(); |
242 } | 242 } |
243 | 243 |
244 void iqscallback_version(iqs *iqp, xmlnode xml_result) | 244 void iqscallback_version(iqs *iqp, xmlnode xml_result, guint iqcontext) |
245 { | 245 { |
246 xmlnode ansqry; | 246 xmlnode ansqry; |
247 char *p, *p_noutf8; | 247 char *p, *p_noutf8; |
248 | 248 |
249 // xml_result is null for timeouts and errors | 249 // Leave now if we cannot process xml_result |
250 if (!xml_result) return; | 250 if (!xml_result || iqcontext) return; |
251 | 251 |
252 ansqry = xmlnode_get_tag(xml_result, "query"); | 252 ansqry = xmlnode_get_tag(xml_result, "query"); |
253 if (!ansqry) { | 253 if (!ansqry) { |
254 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!"); | 254 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!"); |
255 return; | 255 return; |
302 if (utf8_jid) g_free(utf8_jid); | 302 if (utf8_jid) g_free(utf8_jid); |
303 iqn->callback = &iqscallback_version; | 303 iqn->callback = &iqscallback_version; |
304 jab_send(jc, iqn->xmldata); | 304 jab_send(jc, iqn->xmldata); |
305 } | 305 } |
306 | 306 |
307 void iqscallback_time(iqs *iqp, xmlnode xml_result) | 307 void iqscallback_time(iqs *iqp, xmlnode xml_result, guint iqcontext) |
308 { | 308 { |
309 xmlnode ansqry; | 309 xmlnode ansqry; |
310 char *p, *p_noutf8; | 310 char *p, *p_noutf8; |
311 | 311 |
312 // xml_result is null for timeouts and errors | 312 // Leave now if we cannot process xml_result |
313 if (!xml_result) return; | 313 if (!xml_result || iqcontext) return; |
314 | 314 |
315 ansqry = xmlnode_get_tag(xml_result, "query"); | 315 ansqry = xmlnode_get_tag(xml_result, "query"); |
316 if (!ansqry) { | 316 if (!ansqry) { |
317 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!"); | 317 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!"); |
318 return; | 318 return; |
399 if (!id) { | 399 if (!id) { |
400 scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored."); | 400 scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored."); |
401 return; | 401 return; |
402 } | 402 } |
403 | 403 |
404 if (!iqs_callback(id, xmldata)) | 404 if (!iqs_callback(id, xmldata, IQS_CONTEXT_RESULT)) |
405 return; | 405 return; |
406 | 406 |
407 /* | 407 /* |
408 if (!strcmp(id, "VCARDreq")) { | 408 if (!strcmp(id, "VCARDreq")) { |
409 x = xmlnode_get_firstchild(xmldata); | 409 x = xmlnode_get_firstchild(xmldata); |
610 handle_iq_set(conn, from, xmldata); | 610 handle_iq_set(conn, from, xmldata); |
611 } else if (!strcmp(type, TMSG_ERROR)) { | 611 } else if (!strcmp(type, TMSG_ERROR)) { |
612 xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR); | 612 xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR); |
613 if (x) | 613 if (x) |
614 display_server_error(x); | 614 display_server_error(x); |
615 iqs_callback(xmlnode_get_attrib(xmldata, "id"), NULL); | 615 iqs_callback(xmlnode_get_attrib(xmldata, "id"), NULL, IQS_CONTEXT_ERROR); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ | 619 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |