]> code.citadel.org Git - citadel.git/commitdiff
* Implemented XEP-0199: XMPP Ping ... see http://xmpp.org/extensions/xep-0199.html...
authorArt Cancro <ajc@citadel.org>
Sun, 21 Feb 2010 06:30:08 +0000 (06:30 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 21 Feb 2010 06:30:08 +0000 (06:30 +0000)
citadel/modules/jabber/serv_xmpp.c
citadel/modules/jabber/serv_xmpp.h

index a2532a3516e8c0a242664419d99508052bd2c3b2..7f37e5acdbdbfc660131861fbfe777f83d0d419f 100644 (file)
@@ -2,21 +2,21 @@
  * $Id$ 
  *
  * XMPP (Jabber) service for the Citadel system
- * Copyright (c) 2007-2009 by Art Cancro
+ * Copyright (c) 2007-2010 by Art Cancro
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "sysdep.h"
@@ -238,11 +238,30 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                                                XMPP->iq_to, XMPP->iq_query_xmlns);
                        }
 
+                       /*
+                        * ping ( http://xmpp.org/extensions/xep-0199.html )
+                        */
+                       else if (XMPP->ping_requested) {
+                               cprintf("<iq type=\"result\" ");
+                               if (!IsEmptyStr(XMPP->iq_from)) {
+                                       cprintf("to=\"%s\" ", XMPP->iq_from);
+                               }
+                               if (!IsEmptyStr(XMPP->iq_to)) {
+                                       cprintf("from=\"%s\" ", XMPP->iq_to);
+                               }
+                               cprintf("id=\"%s\"/>", XMPP->iq_id);
+                       }
+
                        /*
                         * Unknown queries ... return the XML equivalent of a blank stare
                         */
                        else {
-                               cprintf("<iq type=\"result\" id=\"%s\">", XMPP->iq_id);
+                               CtdlLogPrintf(CTDL_DEBUG, "Unknown query; <service-unavailable/>\n");
+                               cprintf("<iq type=\"error\" id=\"%s\">", XMPP->iq_id);
+                               cprintf("<error code=\"503\" type=\"cancel\">"
+                                       "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
+                                       "</error>"
+                               );
                                cprintf("</iq>");
                        }
                }
@@ -310,6 +329,7 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                XMPP->iq_session = 0;
                XMPP->iq_query_xmlns[0] = 0;
                XMPP->bind_requested = 0;
+               XMPP->ping_requested = 0;
        }
 
        else if (!strcasecmp(el, "auth")) {
@@ -363,6 +383,10 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
 #endif
        }
 
+       else if (!strcasecmp(el, "ping")) {
+               XMPP->ping_requested = 1;
+       }
+
        XMPP->chardata_len = 0;
        if (XMPP->chardata_alloc > 0) {
                XMPP->chardata[0] = 0;
index ed93ff25cb9b6db49801ed403e4a8a1fe7803697..f7d9e1452e2bfd48f6ab2adf3efaa9fc66d7d600 100644 (file)
@@ -44,6 +44,7 @@ struct citxmpp {                      /* Information about the current session */
        int html_tag_level;             /* <html> tag nesting level */
 
        int bind_requested;             /* In this stanza, client is asking server to bind a resource. */
+       int ping_requested;             /* In this stanza, client is pinging the server. */
 };
 
 #define XMPP ((struct citxmpp *)CC->session_specific_data)