8312
|
1 /*
|
|
2 * gaim - Jabber Protocol Plugin
|
|
3 *
|
|
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
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.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 */
|
|
21
|
|
22 #include "internal.h"
|
|
23 #include "prefs.h"
|
|
24
|
|
25 #include "buddy.h"
|
|
26 #include "iq.h"
|
|
27 #include "disco.h"
|
13384
|
28 #include "jabber.h"
|
8312
|
29
|
|
30
|
|
31 struct _jabber_disco_info_cb_data {
|
|
32 gpointer data;
|
|
33 JabberDiscoInfoCallback *callback;
|
|
34 };
|
|
35
|
|
36 #define SUPPORT_FEATURE(x) \
|
|
37 feature = xmlnode_new_child(query, "feature"); \
|
|
38 xmlnode_set_attrib(feature, "var", x);
|
|
39
|
|
40
|
|
41 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
|
|
42 const char *from = xmlnode_get_attrib(packet, "from");
|
|
43 const char *type = xmlnode_get_attrib(packet, "type");
|
|
44
|
|
45 if(!from || !type)
|
|
46 return;
|
|
47
|
|
48 if(!strcmp(type, "get")) {
|
|
49 xmlnode *query, *identity, *feature;
|
13384
|
50 JabberIq *iq;
|
|
51
|
|
52 xmlnode *in_query;
|
|
53 const char *node = NULL;
|
|
54
|
|
55 if((in_query = xmlnode_get_child(packet, "query"))) {
|
|
56 node = xmlnode_get_attrib(in_query, "node");
|
|
57 }
|
|
58
|
|
59
|
|
60 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
|
8312
|
61 "http://jabber.org/protocol/disco#info");
|
|
62
|
|
63 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
|
|
64
|
|
65 xmlnode_set_attrib(iq->node, "to", from);
|
|
66 query = xmlnode_get_child(iq->node, "query");
|
|
67
|
13384
|
68 if(node)
|
|
69 xmlnode_set_attrib(query, "node", node);
|
|
70
|
|
71 if(!node || !strcmp(node, CAPS0115_NODE "#" VERSION)) {
|
|
72
|
|
73 identity = xmlnode_new_child(query, "identity");
|
|
74 xmlnode_set_attrib(identity, "category", "client");
|
|
75 xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console,
|
|
76 * handheld, pc, phone,
|
|
77 * web */
|
8312
|
78
|
13384
|
79 SUPPORT_FEATURE("jabber:iq:last")
|
|
80 SUPPORT_FEATURE("jabber:iq:oob")
|
|
81 SUPPORT_FEATURE("jabber:iq:time")
|
|
82 SUPPORT_FEATURE("jabber:iq:version")
|
|
83 SUPPORT_FEATURE("jabber:x:conference")
|
|
84 SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams")
|
|
85 SUPPORT_FEATURE("http://jabber.org/protocol/disco#info")
|
|
86 SUPPORT_FEATURE("http://jabber.org/protocol/disco#items")
|
8312
|
87 #if 0
|
13384
|
88 SUPPORT_FEATURE("http://jabber.org/protocol/ibb")
|
8312
|
89 #endif
|
13384
|
90 SUPPORT_FEATURE("http://jabber.org/protocol/muc")
|
|
91 SUPPORT_FEATURE("http://jabber.org/protocol/muc#user")
|
|
92 SUPPORT_FEATURE("http://jabber.org/protocol/si")
|
|
93 SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer")
|
|
94 SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
|
|
95 } else {
|
|
96 xmlnode *error, *inf;
|
|
97
|
|
98 /* XXX: gross hack, implement jabber_iq_set_type or something */
|
|
99 xmlnode_set_attrib(iq->node, "type", "error");
|
|
100 iq->type = JABBER_IQ_ERROR;
|
|
101
|
|
102 error = xmlnode_new_child(query, "error");
|
|
103 xmlnode_set_attrib(error, "code", "404");
|
|
104 xmlnode_set_attrib(error, "type", "cancel");
|
|
105 inf = xmlnode_new_child(error, "item-not-found");
|
|
106 xmlnode_set_attrib(inf, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
|
|
107 }
|
8312
|
108
|
|
109 jabber_iq_send(iq);
|
|
110 } else if(!strcmp(type, "result")) {
|
|
111 xmlnode *query = xmlnode_get_child(packet, "query");
|
|
112 xmlnode *child;
|
|
113 JabberID *jid;
|
|
114 JabberBuddy *jb;
|
|
115 JabberBuddyResource *jbr = NULL;
|
|
116 JabberCapabilities capabilities = JABBER_CAP_NONE;
|
|
117 struct _jabber_disco_info_cb_data *jdicd;
|
|
118
|
|
119 if((jid = jabber_id_new(from))) {
|
|
120 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
|
|
121 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
122 jabber_id_free(jid);
|
|
123 }
|
|
124
|
|
125 if(jbr)
|
|
126 capabilities = jbr->capabilities;
|
|
127
|
|
128 for(child = query->child; child; child = child->next) {
|
|
129 if(child->type != XMLNODE_TYPE_TAG)
|
|
130 continue;
|
|
131
|
|
132 if(!strcmp(child->name, "identity")) {
|
|
133 const char *category = xmlnode_get_attrib(child, "category");
|
|
134 const char *type = xmlnode_get_attrib(child, "type");
|
|
135 if(!category || !type)
|
|
136 continue;
|
|
137
|
11675
|
138 if(!strcmp(category, "conference") && !strcmp(type, "text")) {
|
|
139 /* we found a groupchat or MUC server, add it to the list */
|
|
140 /* XXX: actually check for protocol/muc or gc-1.0 support */
|
8312
|
141 js->chat_servers = g_list_append(js->chat_servers, g_strdup(from));
|
11675
|
142 } else if(!strcmp(category, "directory") && !strcmp(type, "user")) {
|
|
143 /* we found a JUD */
|
|
144 js->user_directories = g_list_append(js->user_directories, g_strdup(from));
|
|
145 }
|
8312
|
146
|
|
147 } else if(!strcmp(child->name, "feature")) {
|
|
148 const char *var = xmlnode_get_attrib(child, "var");
|
|
149 if(!var)
|
|
150 continue;
|
|
151
|
|
152 if(!strcmp(var, "http://jabber.org/protocol/si"))
|
|
153 capabilities |= JABBER_CAP_SI;
|
|
154 else if(!strcmp(var, "http://jabber.org/protocol/si/profile/file-transfer"))
|
|
155 capabilities |= JABBER_CAP_SI_FILE_XFER;
|
|
156 else if(!strcmp(var, "http://jabber.org/protocol/bytestreams"))
|
|
157 capabilities |= JABBER_CAP_BYTESTREAMS;
|
11675
|
158 else if(!strcmp(var, "jabber:iq:search"))
|
|
159 capabilities |= JABBER_CAP_IQ_SEARCH;
|
|
160 else if(!strcmp(var, "jabber:iq:register"))
|
|
161 capabilities |= JABBER_CAP_IQ_REGISTER;
|
8312
|
162 }
|
|
163 }
|
|
164
|
|
165 capabilities |= JABBER_CAP_RETRIEVED;
|
|
166
|
|
167 if(jbr)
|
|
168 jbr->capabilities = capabilities;
|
|
169
|
|
170 if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) {
|
|
171 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
172 g_hash_table_remove(js->disco_callbacks, from);
|
|
173 }
|
|
174 } else if(!strcmp(type, "error")) {
|
|
175 JabberID *jid;
|
|
176 JabberBuddy *jb;
|
|
177 JabberBuddyResource *jbr = NULL;
|
|
178 JabberCapabilities capabilities = JABBER_CAP_NONE;
|
|
179 struct _jabber_disco_info_cb_data *jdicd;
|
|
180
|
|
181 if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from)))
|
|
182 return;
|
|
183
|
|
184 if((jid = jabber_id_new(from))) {
|
|
185 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
|
|
186 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
187 jabber_id_free(jid);
|
|
188 }
|
|
189
|
|
190 if(jbr)
|
|
191 capabilities = jbr->capabilities;
|
|
192
|
|
193 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
194 g_hash_table_remove(js->disco_callbacks, from);
|
|
195 }
|
|
196 }
|
|
197
|
|
198 void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) {
|
|
199 const char *from = xmlnode_get_attrib(packet, "from");
|
|
200 const char *type = xmlnode_get_attrib(packet, "type");
|
|
201
|
|
202 if(!strcmp(type, "get")) {
|
|
203 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
|
|
204 "http://jabber.org/protocol/disco#items");
|
|
205
|
|
206 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
|
|
207
|
|
208 xmlnode_set_attrib(iq->node, "to", from);
|
|
209 jabber_iq_send(iq);
|
|
210 }
|
|
211 }
|
|
212
|
|
213 static void
|
|
214 jabber_disco_server_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
215 {
|
|
216 xmlnode *query, *child;
|
|
217 const char *from = xmlnode_get_attrib(packet, "from");
|
|
218 const char *type = xmlnode_get_attrib(packet, "type");
|
|
219
|
|
220 if(!from || !type)
|
|
221 return;
|
|
222
|
|
223 if(strcmp(from, js->user->domain))
|
|
224 return;
|
|
225
|
|
226 if(strcmp(type, "result"))
|
|
227 return;
|
|
228
|
|
229 while(js->chat_servers) {
|
|
230 g_free(js->chat_servers->data);
|
|
231 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers);
|
|
232 }
|
|
233
|
|
234 query = xmlnode_get_child(packet, "query");
|
|
235
|
|
236 for(child = xmlnode_get_child(query, "item"); child;
|
|
237 child = xmlnode_get_next_twin(child)) {
|
|
238 JabberIq *iq;
|
|
239 const char *jid;
|
|
240
|
|
241 if(!(jid = xmlnode_get_attrib(child, "jid")))
|
|
242 continue;
|
|
243
|
|
244 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
245 xmlnode_set_attrib(iq->node, "to", jid);
|
|
246 jabber_iq_send(iq);
|
|
247 }
|
|
248 }
|
|
249
|
|
250 void jabber_disco_items_server(JabberStream *js)
|
|
251 {
|
|
252 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET,
|
|
253 "http://jabber.org/protocol/disco#items");
|
|
254
|
|
255 xmlnode_set_attrib(iq->node, "to", js->user->domain);
|
|
256
|
|
257 jabber_iq_set_callback(iq, jabber_disco_server_result_cb, NULL);
|
|
258 jabber_iq_send(iq);
|
|
259 }
|
|
260
|
|
261 void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data)
|
|
262 {
|
|
263 JabberID *jid;
|
|
264 JabberBuddy *jb;
|
|
265 JabberBuddyResource *jbr = NULL;
|
|
266 struct _jabber_disco_info_cb_data *jdicd;
|
|
267 JabberIq *iq;
|
|
268
|
|
269 if((jid = jabber_id_new(who))) {
|
|
270 if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE)))
|
|
271 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
272 jabber_id_free(jid);
|
|
273 }
|
|
274
|
|
275 if(jbr && jbr->capabilities & JABBER_CAP_RETRIEVED) {
|
|
276 callback(js, who, jbr->capabilities, data);
|
|
277 return;
|
|
278 }
|
|
279
|
|
280 jdicd = g_new0(struct _jabber_disco_info_cb_data, 1);
|
|
281 jdicd->data = data;
|
|
282 jdicd->callback = callback;
|
|
283
|
|
284 g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd);
|
|
285
|
|
286 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
287 xmlnode_set_attrib(iq->node, "to", who);
|
|
288
|
|
289 jabber_iq_send(iq);
|
|
290 }
|
|
291
|
|
292
|