Propagate context to IQ callback functions
It will allow to deal with timeouts and errors more easily.
--- 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);
}
}
--- a/mcabber/src/jab_priv.h Sat Feb 11 16:06:29 2006 +0100
+++ b/mcabber/src/jab_priv.h Sun Feb 12 11:06:26 2006 +0100
@@ -23,6 +23,11 @@
#define IQS_DEFAULT_TIMEOUT 40
#define IQS_MAX_TIMEOUT 600
+#define IQS_CONTEXT_RESULT 0 /* Normal result should be zero */
+#define IQS_CONTEXT_TIMEOUT 1
+#define IQS_CONTEXT_ERROR 2
+
+
typedef struct {
char *id;
time_t ts_create;
@@ -42,7 +47,7 @@
void display_server_error(xmlnode x);
iqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t timeout);
int iqs_del(const char *iqid);
-int iqs_callback(const char *iqid, xmlnode xml_anwser);
+int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext);
void iqs_check_timeout(void);
void iqscallback_auth(iqs *iqp, xmlnode xml_result);
void request_version(const char *fulljid);