4 * Handle <iq> <get> <query> type situations (namespace queries)
6 * Copyright (c) 2007-2009 by Art Cancro
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
33 #if TIME_WITH_SYS_TIME
34 # include <sys/time.h>
38 # include <sys/time.h>
49 #include <libcitadel.h>
52 #include "citserver.h"
55 #include "internet_addressing.h"
57 #include "ctdl_module.h"
58 #include "serv_xmpp.h"
62 * Output a single roster item, for roster queries or pushes
64 void xmpp_roster_item(struct CitContext *cptr) {
65 cprintf("<item jid=\"%s\" name=\"%s\" subscription=\"both\">",
69 cprintf("<group>%s</group>", config.c_humannode);
74 * Return the results for a "jabber:iq:roster:query"
76 * Since we are not yet managing a roster, we simply return the entire wholist
77 * (minus any entries for this user -- don't tell me about myself)
80 void xmpp_iq_roster_query(void)
82 struct CitContext *cptr;
85 cprintf("<query xmlns=\"jabber:iq:roster\">");
86 cptr = CtdlGetContextArray(&nContexts);
88 for (i=0; i<nContexts; i++) {
89 if (xmpp_is_visible(&cptr[i], CC)) {
90 CtdlLogPrintf(CTDL_DEBUG, "Rosterizing %s\n", cptr[i].user.fullname);
91 xmpp_roster_item(&cptr[i]);
101 * TODO: handle queries on some or all of these namespaces
103 xmpp_query_namespace(purple5b5c1e58, splorph.xand.com, http://jabber.org/protocol/disco#items:query)
104 xmpp_query_namespace(purple5b5c1e59, splorph.xand.com, http://jabber.org/protocol/disco#info:query)
105 xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
109 void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_xmlns)
111 int supported_namespace = 0;
112 int roster_query = 0;
114 /* We need to know before we begin the response whether this is a supported namespace, so
115 * unfortunately all supported namespaces need to be defined here *and* down below where
119 (!strcasecmp(query_xmlns, "jabber:iq:roster:query"))
120 || (!strcasecmp(query_xmlns, "jabber:iq:auth:query"))
122 supported_namespace = 1;
125 CtdlLogPrintf(CTDL_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", iq_id, iq_from, iq_to, query_xmlns);
128 * Beginning of query result.
130 if (supported_namespace) {
131 cprintf("<iq type=\"result\" ");
134 cprintf("<iq type=\"error\" ");
136 if (!IsEmptyStr(iq_from)) {
137 cprintf("to=\"%s\" ", iq_from);
139 cprintf("id=\"%s\">", iq_id);
142 * Is this a query we know how to handle?
145 if (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) {
147 xmpp_iq_roster_query();
150 else if (!strcasecmp(query_xmlns, "jabber:iq:auth:query")) {
151 cprintf("<query xmlns=\"jabber:iq:auth\">"
152 "<username/><password/><resource/>"
158 * If we didn't hit any known query namespaces then we should deliver a
159 * "service unavailable" error (see RFC3921 section 2.4 and 11.1.5.4)
163 CtdlLogPrintf(CTDL_DEBUG,
164 "Unknown query namespace '%s' - returning <service-unavailable/>\n",
167 cprintf("<error code=\"503\" type=\"cancel\">"
168 "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
175 /* If we told the client who is on the roster, we also need to tell the client
176 * who is *not* on the roster. (It's down here because we can't do it in the same
177 * stanza; this will be an unsolicited push.)
180 xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster();