libical, expat, and libsieve are now *required*.
[citadel.git] / citadel / modules / jabber / serv_xmpp.c
index 00c08bd893facb95666de2247975a6e892f83f08..3b448fbf491eec93ea7b9e8755ef9ca6a664ddcb 100644 (file)
@@ -33,6 +33,7 @@
 #include <limits.h>
 #include <ctype.h>
 #include <libcitadel.h>
+#include <expat.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -46,9 +47,6 @@
 #include "internet_addressing.h"
 #include "md5.h"
 #include "ctdl_module.h"
-
-#ifdef HAVE_EXPAT
-#include <expat.h>
 #include "serv_xmpp.h"
 
 struct xmpp_event *xmpp_queue = NULL;
@@ -89,8 +87,8 @@ void xmpp_stream_start(void *data, const char *supplied_el, const char **attr)
                /* If we're not logged in yet, offer SASL as our feature set */
                xmpp_output_auth_mechs();
 
-               /* Also offer non-SASL authentication 
-               cprintf("<auth xmlns=\"http://jabber.org/features/iq-auth\"/>"); */
+               /* Also offer non-SASL authentication */
+               cprintf("<auth xmlns=\"http://jabber.org/features/iq-auth\"/>");
        }
 
        /* Offer binding and sessions as part of our feature set */
@@ -193,6 +191,23 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                if (XMPP->chardata_len > 0) {
                        safestrncpy(XMPP->iq_client_resource, XMPP->chardata,
                                sizeof XMPP->iq_client_resource);
+                       striplt(XMPP->iq_client_resource);
+               }
+       }
+
+       if (!strcasecmp(el, "username")) {              /* NON SASL ONLY */
+               if (XMPP->chardata_len > 0) {
+                       safestrncpy(XMPP->iq_client_username, XMPP->chardata,
+                               sizeof XMPP->iq_client_username);
+                       striplt(XMPP->iq_client_username);
+               }
+       }
+
+       if (!strcasecmp(el, "password")) {              /* NON SASL ONLY */
+               if (XMPP->chardata_len > 0) {
+                       safestrncpy(XMPP->iq_client_password, XMPP->chardata,
+                               sizeof XMPP->iq_client_password);
+                       striplt(XMPP->iq_client_password);
                }
        }
 
@@ -220,6 +235,22 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                        }
                }
 
+               /*
+                * Non SASL authentication
+                */
+               else if (
+                       (!strcasecmp(XMPP->iq_type, "set"))
+                       && (!strcasecmp(XMPP->iq_query_xmlns, "jabber:iq:auth:query"))
+                       ) {
+
+                       jabber_non_sasl_authenticate(
+                               XMPP->iq_id,
+                               XMPP->iq_client_username,
+                               XMPP->iq_client_password,
+                               XMPP->iq_client_resource
+                       );
+               }       
+
                /*
                 * If this <iq> stanza was a "bind" attempt, process it ...
                 */
@@ -442,11 +473,8 @@ void xmpp_logout_hook(void) {
 
 const char *CitadelServiceXMPP="XMPP";
 
-#endif /* HAVE_EXPAT */
-
 CTDL_MODULE_INIT(jabber)
 {
-#ifdef HAVE_EXPAT
        if (!threading) {
                CtdlRegisterServiceHook(config.c_xmpp_c2s_port,
                                        NULL,
@@ -459,9 +487,6 @@ CTDL_MODULE_INIT(jabber)
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT);
                 CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH);
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH);
-       #else
-               lprintf(CTDL_INFO, "This server is missing the Expat XML parser.  Jabber service will be disabled.\n");
-#endif
        }
 
        /* return our Subversion id for the Log */