diff 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
line wrap: on
line diff
--- a/mcabber/src/jab_iq.c	Sat Feb 11 16:06:29 2006 +0100
+++ b/mcabber/src/jab_iq.c	Sun Feb 12 11:06:26 2006 +0100
@@ -102,12 +102,12 @@
   return NULL;
 }
 
-//  iqs_callback(iqid, xml_result)
+//  iqs_callback(iqid, xml_result, iqcontext)
 // Callback processing for the iqid message.
 // If we've received an answer, xml_result should point to the xmldata packet.
 // If this is a timeout, xml_result should be NULL.
 // Return 0 in case of success, -1 if the iqid hasn't been found.
-int iqs_callback(const char *iqid, xmlnode xml_result)
+int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext)
 {
   iqs *i;
 
@@ -117,7 +117,7 @@
   // IQ processing
   // Note: If xml_result is NULL, this is a timeout
   if (i->callback)
-    (*i->callback)(i, xml_result);
+    (*i->callback)(i, xml_result, iqcontext);
 
   iqs_del(iqid);
   return 0;
@@ -135,7 +135,7 @@
     i = p->data;
     if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) ||
         (i->ts_expire && now_t > i->ts_expire)) {
-      iqs_callback(i->id, NULL);
+      iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT);
     }
   }
 }
@@ -241,13 +241,13 @@
     scr_ShowBuddyWindow();
 }
 
-void iqscallback_version(iqs *iqp, xmlnode xml_result)
+void iqscallback_version(iqs *iqp, xmlnode xml_result, guint iqcontext)
 {
   xmlnode ansqry;
   char *p, *p_noutf8;
 
-  // xml_result is null for timeouts and errors
-  if (!xml_result) return;
+  // Leave now if we cannot process xml_result
+  if (!xml_result || iqcontext) return;
 
   ansqry = xmlnode_get_tag(xml_result, "query");
   if (!ansqry) {
@@ -304,13 +304,13 @@
   jab_send(jc, iqn->xmldata);
 }
 
-void iqscallback_time(iqs *iqp, xmlnode xml_result)
+void iqscallback_time(iqs *iqp, xmlnode xml_result, guint iqcontext)
 {
   xmlnode ansqry;
   char *p, *p_noutf8;
 
-  // xml_result is null for timeouts and errors
-  if (!xml_result) return;
+  // Leave now if we cannot process xml_result
+  if (!xml_result || iqcontext) return;
 
   ansqry = xmlnode_get_tag(xml_result, "query");
   if (!ansqry) {
@@ -401,7 +401,7 @@
     return;
   }
 
-  if (!iqs_callback(id, xmldata))
+  if (!iqs_callback(id, xmldata, IQS_CONTEXT_RESULT))
     return;
 
   /*
@@ -612,7 +612,7 @@
     xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR);
     if (x)
       display_server_error(x);
-    iqs_callback(xmlnode_get_attrib(xmldata, "id"), NULL);
+    iqs_callback(xmlnode_get_attrib(xmldata, "id"), NULL, IQS_CONTEXT_ERROR);
   }
 }