2 * Handle <iq> <get> <query> type situations (namespace queries)
4 * Copyright (c) 2007-2009 by Art Cancro
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
29 #include <sys/types.h>
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
47 #include <libcitadel.h>
50 #include "citserver.h"
53 #include "internet_addressing.h"
55 #include "ctdl_module.h"
56 #include "serv_xmpp.h"
60 * Output a single roster item, for roster queries or pushes
62 void xmpp_roster_item(struct CitContext *cptr)
64 struct CitContext *CCC=CC;
66 XPrint(HKEY("item"), 0,
67 XCPROPERTY("subscription", "both"),
68 XPROPERTY("jid", CCC->cs_inet_email, strlen(CCC->cs_inet_email)),
69 XPROPERTY("name", cptr->user.fullname, strlen(cptr->user.fullname)),
72 XPrint(HKEY("group"), XCLOSED,
73 XCFGBODY(c_humannode),
80 * Return the results for a "jabber:iq:roster:query"
82 * Since we are not yet managing a roster, we simply return the entire wholist
83 * (minus any entries for this user -- don't tell me about myself)
86 void xmpp_iq_roster_query(void)
88 struct CitContext *cptr;
91 XPUT("<query xmlns=\"jabber:iq:roster\">");
92 cptr = CtdlGetContextArray(&nContexts);
94 for (i=0; i<nContexts; i++) {
95 if (xmpp_is_visible(&cptr[i], CC)) {
96 XMPP_syslog(LOG_DEBUG, "Rosterizing %s\n", cptr[i].user.fullname);
97 xmpp_roster_item(&cptr[i]);
107 * TODO: handle queries on some or all of these namespaces
109 xmpp_query_namespace(purple5b5c1e58, splorph.xand.com, http://jabber.org/protocol/disco#items:query)
110 xmpp_query_namespace(purple5b5c1e59, splorph.xand.com, http://jabber.org/protocol/disco#info:query)
111 xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
115 void xmpp_query_namespace(TheToken_iq *IQ/*char *iq_id, char *iq_from, char *iq_to*/, char *query_xmlns)
117 int supported_namespace = 0;
118 int roster_query = 0;
126 /* We need to know before we begin the response whether this is a supported namespace, so
127 * unfortunately all supported namespaces need to be defined here *and* down below where
131 (!strcasecmp(query_xmlns, "jabber:iq:roster:query"))
132 || (!strcasecmp(query_xmlns, "jabber:iq:auth:query"))
134 supported_namespace = 1;
137 XMPP_syslog(LOG_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", ChrPtr(IQ->id), ChrPtr(IQ->from), ChrPtr(IQ->to), query_xmlns);
140 * Beginning of query result.
142 if (supported_namespace) {
143 TypeStr = Type[0].Key;
147 TypeStr = Type[1].Key;
151 XPrint(HKEY("iq"), 0,
152 XPROPERTY("type", TypeStr, TLen),
153 XSPROPERTY("to", IQ->from),
154 XSPROPERTY("id", IQ->id),
158 * Is this a query we know how to handle?
161 if (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) {
163 xmpp_iq_roster_query();
166 else if (!strcasecmp(query_xmlns, "jabber:iq:auth:query")) {
167 XPUT("<query xmlns=\"jabber:iq:auth\">"
168 "<username/><password/><resource/>"
174 * If we didn't hit any known query namespaces then we should deliver a
175 * "service unavailable" error (see RFC3921 section 2.4 and 11.1.5.4)
179 XMPP_syslog(LOG_DEBUG,
180 "Unknown query namespace '%s' - returning <service-unavailable/>\n",
183 XPUT("<error code=\"503\" type=\"cancel\">"
184 "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
191 /* If we told the client who is on the roster, we also need to tell the client
192 * who is *not* on the roster. (It's down here because we can't do it in the same
193 * stanza; this will be an unsolicited push.)
196 xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster();