diff mcabber/src/jab_iq.c @ 686:98de2d166a11

Use the new IQ system for authentication
author Mikael Berthe <mikael@lilotux.net>
date Mon, 06 Feb 2006 21:06:19 +0100
parents f033345d1315
children 426145046b93
line wrap: on
line diff
--- a/mcabber/src/jab_iq.c	Mon Feb 06 20:04:58 2006 +0100
+++ b/mcabber/src/jab_iq.c	Mon Feb 06 21:06:19 2006 +0100
@@ -33,8 +33,6 @@
 #include "settings.h"
 
 
-int s_id; // XXX
-
 static GSList *iqs_list;
 
 
@@ -230,6 +228,28 @@
     scr_ShowBuddyWindow();
 }
 
+void iqscallback_auth(iqs *iqp, xmlnode xml_result)
+{
+  if (jstate == STATE_GETAUTH) {
+    iqs *iqn;
+
+    if (xml_result) {
+      xmlnode x = xmlnode_get_tag(xml_result, "query");
+      if (x && !xmlnode_get_tag(x, "digest"))
+        jc->sid = 0;
+    }
+
+    iqn = iqs_new(JPACKET__SET, NS_AUTH, "auth", IQS_DEFAULT_TIMEOUT);
+    iqn->callback = &iqscallback_auth;
+    jab_auth_mcabber(jc, iqn->xmldata);
+    jab_send(jc, iqn->xmldata);
+    jstate = STATE_SENDAUTH;
+  } else if (jstate == STATE_SENDAUTH) {
+    request_roster();
+    jstate = STATE_LOGGED;
+  }
+}
+
 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata)
 {
   xmlnode x;
@@ -242,22 +262,6 @@
     return;
   }
 
-  if (atoi(id) == s_id) {  // Authentication  XXX
-    if (jstate == STATE_GETAUTH) {
-      if ((x = xmlnode_get_tag(xmldata, "query")) != NULL)
-        if (!xmlnode_get_tag(x, "digest")) {
-          jc->sid = 0;
-        }
-
-      s_id = atoi(jab_auth(jc));
-      jstate = STATE_SENDAUTH;
-    } else if (jstate == STATE_SENDAUTH) {
-      request_roster();
-      jstate = STATE_LOGGED;
-    }
-    return;
-  }
-
   if (!iqs_callback(id, xmldata))
     return;