Strip leading and trailing whitespace from instant messages before sending them to...
[citadel.git] / citadel / modules / jabber / xmpp_query_namespace.c
1 /*
2  * $Id$ 
3  *
4  * Handle <iq> <get> <query> type situations (namespace queries)
5  *
6  * Copyright (c) 2007 by Art Cancro
7  * This code is released under the terms of the GNU General Public License.
8  *
9  */
10
11 #include "sysdep.h"
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <pwd.h>
18 #include <errno.h>
19 #include <sys/types.h>
20
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
23 # include <time.h>
24 #else
25 # if HAVE_SYS_TIME_H
26 #  include <sys/time.h>
27 # else
28 #  include <time.h>
29 # endif
30 #endif
31
32 #include <sys/wait.h>
33 #include <string.h>
34 #include <limits.h>
35 #include <ctype.h>
36 #include <libcitadel.h>
37 #include "citadel.h"
38 #include "server.h"
39 #include "citserver.h"
40 #include "support.h"
41 #include "config.h"
42 #include "internet_addressing.h"
43 #include "md5.h"
44 #include "ctdl_module.h"
45
46 #ifdef HAVE_EXPAT
47 #include <expat.h>
48 #include "serv_xmpp.h"
49
50
51 /* 
52  * Return the results for a "jabber:iq:roster:query"
53  *
54  * Since we are not yet managing a roster, we simply return the entire wholist
55  * (minus any entries for this user -- don't tell me about myself)
56  *
57  */
58 void jabber_iq_roster_query(void)
59 {
60         struct CitContext *cptr;
61         int aide = (CC->user.axlevel >= 6);
62
63         cprintf("<query xmlns=\"jabber:iq:roster\">");
64
65         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
66
67                 if (
68                    (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
69                    && (cptr->user.usernum != CC->user.usernum)
70                    ) {
71                         cprintf("<item jid=\"%s\" name=\"%s\" subscription=\"both\">",
72                                 cptr->cs_inet_email,
73                                 cptr->user.fullname
74                         );
75                         cprintf("<group>%s</group>", config.c_humannode);
76                         cprintf("</item>");
77                 }
78         }
79
80         cprintf("</query>");
81 }
82
83
84 /*
85  * TODO: handle queries on some or all of these namespaces
86  *
87 xmpp_query_namespace(purple5b5c1e58, splorph.xand.com, http://jabber.org/protocol/disco#items:query)
88 xmpp_query_namespace(purple5b5c1e59, splorph.xand.com, http://jabber.org/protocol/disco#info:query)
89 xmpp_query_namespace(purple5b5c1e5a, , vcard-temp:query)
90  *
91  */
92
93 void xmpp_query_namespace(char *iq_id, char *iq_from, char *iq_to, char *query_xmlns) {
94
95         lprintf(CTDL_DEBUG, "xmpp_query_namespace(%s, %s, %s, %s)\n", iq_id, iq_from, iq_to, query_xmlns);
96
97         /*
98          * Beginning of query result.
99          */
100         cprintf("<iq type=\"result\" ");
101         if (!IsEmptyStr(iq_from)) {
102                 cprintf("to=\"%s\" ", iq_from);
103         }
104         cprintf("id=\"%s\">", iq_id);
105
106         /*
107          * Is this a query we know how to handle?
108          */
109         if (!strcasecmp(query_xmlns, "jabber:iq:roster:query")) {
110                 jabber_iq_roster_query();
111         }
112
113         /*
114          * End of query result.  If we didn't hit any known namespaces then we will
115          * have simply delivered an empty result stanza, which should be ok.
116          */
117         cprintf("</iq>");
118
119 }
120
121 #endif  /* HAVE_EXPAT */