2 * Handle <iq> <get> <query> type situations (namespace queries)
4 * Copyright (c) 2007-2014 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.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
22 #include <sys/types.h>
24 #if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
40 #include <libcitadel.h>
43 #include "citserver.h"
46 #include "internet_addressing.h"
48 #include "ctdl_module.h"
49 #include "serv_xmpp.h"
53 * Output a single roster item, for roster queries or pushes
55 void xmpp_roster_item(struct CitContext *cptr)
57 XPrint(HKEY("item"), 0,
58 XCPROPERTY("subscription", "both"),
59 XPROPERTY("jid", cptr->cs_inet_email, strlen(cptr->cs_inet_email)),
60 XPROPERTY("name", cptr->user.fullname, strlen(cptr->user.fullname)),
64 XPrint(HKEY("group"), XCLOSED,
65 XCFGBODY(c_humannode),
72 * Return the results for a "jabber:iq:roster:query"
74 * Since we are not yet managing a roster, we simply return the entire wholist
75 * (minus any entries for this user -- don't tell me about myself)
78 void xmpp_iq_roster_query(void)
80 struct CitContext *cptr;
83 XPUT("<query xmlns=\"jabber:iq:roster\">");
84 cptr = CtdlGetContextArray(&nContexts);
86 for (i=0; i<nContexts; i++) {
87 if (xmpp_is_visible(&cptr[i], CC)) {
88 XMPP_syslog(LOG_DEBUG, "Rosterizing %s\n", cptr[i].user.fullname);
89 xmpp_roster_item(&cptr[i]);
99 * TODO: handle queries on some or all of these namespaces
101 xmpp_query_namespace(purple5b5c1e58, splorph.xand.com, http://jabber.org/protocol/disco#items:query)
102 xmpp_query_namespace(purple5b5c1e59, splorph.xand.com, http://jabber.org/protocol/disco#info:query)
103 xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
107 void xmpp_query_namespace(TheToken_iq *IQ/*char *iq_id, char *iq_from, char *iq_to*/, char *query_xmlns)
109 int supported_namespace = 0;
110 int roster_query = 0;
118 /* We need to know before we begin the response whether this is a supported namespace, so
119 * unfortunately all supported namespaces need to be defined here *and* down below where
123 (!strcasecmp(query_xmlns, "jabber:iq:roster:query"))
124 || (!strcasecmp(query_xmlns, "jabber:iq:auth:query"))
126 supported_namespace = 1;
129 XMPP_syslog(LOG_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", ChrPtr(IQ->id), ChrPtr(IQ->from), ChrPtr(IQ->to), query_xmlns);
132 * Beginning of query result.
134 if (supported_namespace) {
135 TypeStr = Type[0].Key;
139 TypeStr = Type[1].Key;
143 XPrint(HKEY("iq"), 0,
144 XPROPERTY("type", TypeStr, TLen),
145 XSPROPERTY("to", IQ->from),
146 XSPROPERTY("id", IQ->id),
150 * Is this a query we know how to handle?
153 if (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) {
155 xmpp_iq_roster_query();
158 else if (!strcasecmp(query_xmlns, "jabber:iq:auth:query")) {
159 XPUT("<query xmlns=\"jabber:iq:auth\">"
160 "<username/><password/><resource/>"
166 * If we didn't hit any known query namespaces then we should deliver a
167 * "service unavailable" error (see RFC3921 section 2.4 and 11.1.5.4)
171 XMPP_syslog(LOG_DEBUG,
172 "Unknown query namespace '%s' - returning <service-unavailable/>\n",
175 XPUT("<error code=\"503\" type=\"cancel\">"
176 "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
183 /* If we told the client who is on the roster, we also need to tell the client
184 * who is *not* on the roster. (It's down here because we can't do it in the same
185 * stanza; this will be an unsolicited push.)
188 xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster();