]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/jabber/serv_xmpp.c
Define an XMPP queue...
[citadel.git] / citadel / modules / jabber / serv_xmpp.c
index 27c4f6a6015c9d8466d4da8736eec41849adb4c7..66a32097ca740fd982df1bccda496ef3fda9aa52 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id:  
+ * $Id$ 
  *
  * XMPP (Jabber) service for the Citadel system
  * Copyright (c) 2007 by Art Cancro
@@ -51,6 +51,7 @@
 #include <expat.h>
 #include "serv_xmpp.h"
 
+struct xmpp_event *xmpp_queue = NULL;
 
 /* We have just received a <stream> tag from the client, so send them ours */
 
@@ -78,19 +79,19 @@ void xmpp_stream_start(void *data, const char *supplied_el, const char **attr)
        /* The features of this stream are... */
        cprintf("<stream:features>");
 
-       /* Binding... */
-       cprintf("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>");
-
-       /* Sessions... */
-       cprintf("<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>");
-
-       /* SASL (but only if we're not already logged in; this is important!) ... */
        if (!CC->logged_in) {
+               /* If we're not logged in yet, offer SASL as our feature set */
                xmpp_output_auth_mechs();
        }
+       else {
+               /* If we've logged in, now offer binding and sessions as our feature set */
+               cprintf("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>");
+               cprintf("<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>");
+       }
 
-       /* ...and the ability to close XML tags using angle brackets.  We should patent this. */
        cprintf("</stream:features>");
+
+       CC->is_async = 1;               /* XMPP sessions are inherently async-capable */
 }
 
 
@@ -202,10 +203,16 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
 
                        /* Generate the "full JID" of the client resource */
 
+                       // snprintf(XMPP->client_jid, sizeof XMPP->client_jid,
+                       //      "%d@%s/%s",
+                       //      CC->cs_pid,
+                       //      config.c_fqdn,
+                       //      XMPP->iq_client_resource
+                       //);
+
                        snprintf(XMPP->client_jid, sizeof XMPP->client_jid,
-                               "%d@%s/%s",
-                               CC->cs_pid,
-                               config.c_fqdn,
+                               "%s/%s",
+                               CC->cs_inet_email,
                                XMPP->iq_client_resource
                        );
 
@@ -252,6 +259,14 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                XMPP->iq_session = 1;
        }
 
+       else if (!strcasecmp(el, "presence")) {
+
+               /* Respond to a <presence> update by firing back with presence information
+                * on the entire wholist.  Check this assumption, it's probably wrong.
+                */
+               jabber_wholist_presence_dump();
+       }
+
        XMPP->chardata_len = 0;
        if (XMPP->chardata_alloc > 0) {
                XMPP->chardata[0] = 0;
@@ -342,6 +357,28 @@ void xmpp_command_loop(void) {
        XML_Parse(XMPP->xp, cmdbuf, 1, 0);
 }
 
+
+/*
+ * Async loop for XMPP sessions (handles the transmission of unsolicited stanzas)
+ */
+void xmpp_async_loop(void) {
+       jabber_output_incoming_messages();
+}
+
+
+/*
+ * Login hook for XMPP sessions
+ */
+void xmpp_login_hook(void) {
+
+       // we need to somehow alert all xmpp sessions that we are here
+       // and do a roster push followed by a presence push
+
+       lprintf(CTDL_DEBUG, "LOGIN HOOOOOOOOOOOOOKK!!!\n");
+
+}
+
+
 const char *CitadelServiceXMPP="XMPP";
 
 #endif /* HAVE_EXPAT */
@@ -350,19 +387,20 @@ CTDL_MODULE_INIT(jabber)
 {
 #ifdef HAVE_EXPAT
        if (!threading) {
-               /* CtdlRegisterServiceHook(config.c_xmpp_port,          FIXME   */
-               CtdlRegisterServiceHook(5222,
+               CtdlRegisterServiceHook(5222,                   /* FIXME change to config.c_xmpp_port */
                                        NULL,
                                        xmpp_greeting,
                                        xmpp_command_loop,
-                                       NULL,
+                                       xmpp_async_loop,
                                        CitadelServiceXMPP);
                CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP);
+                CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN);
+
        #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 */
-       return "$Id$";
+       return "$Id$";
 }