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"
|
|
28
|
|
29
|
|
30 struct _jabber_disco_info_cb_data {
|
|
31 gpointer data;
|
|
32 JabberDiscoInfoCallback *callback;
|
|
33 };
|
|
34
|
|
35 #define SUPPORT_FEATURE(x) \
|
|
36 feature = xmlnode_new_child(query, "feature"); \
|
|
37 xmlnode_set_attrib(feature, "var", x);
|
|
38
|
|
39
|
|
40 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
|
|
41 const char *from = xmlnode_get_attrib(packet, "from");
|
|
42 const char *type = xmlnode_get_attrib(packet, "type");
|
|
43
|
|
44 if(!from || !type)
|
|
45 return;
|
|
46
|
|
47 if(!strcmp(type, "get")) {
|
|
48 xmlnode *query, *identity, *feature;
|
|
49 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
|
|
50 "http://jabber.org/protocol/disco#info");
|
|
51
|
|
52 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
|
|
53
|
|
54 xmlnode_set_attrib(iq->node, "to", from);
|
|
55 query = xmlnode_get_child(iq->node, "query");
|
|
56
|
|
57 identity = xmlnode_new_child(query, "identity");
|
|
58 xmlnode_set_attrib(identity, "category", "client");
|
|
59 xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console,
|
|
60 * handheld, pc, phone,
|
|
61 * web */
|
|
62
|
|
63 SUPPORT_FEATURE("jabber:iq:last")
|
|
64 SUPPORT_FEATURE("jabber:iq:oob")
|
|
65 SUPPORT_FEATURE("jabber:iq:time")
|
|
66 SUPPORT_FEATURE("jabber:iq:version")
|
|
67 SUPPORT_FEATURE("jabber:x:conference")
|
|
68 SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams")
|
|
69 SUPPORT_FEATURE("http://jabber.org/protocol/disco#info")
|
|
70 SUPPORT_FEATURE("http://jabber.org/protocol/disco#items")
|
|
71 #if 0
|
|
72 SUPPORT_FEATURE("http://jabber.org/protocol/ibb")
|
|
73 #endif
|
|
74 SUPPORT_FEATURE("http://jabber.org/protocol/muc")
|
|
75 SUPPORT_FEATURE("http://jabber.org/protocol/muc#user")
|
|
76 SUPPORT_FEATURE("http://jabber.org/protocol/si")
|
|
77 SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer")
|
|
78 SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
|
|
79
|
|
80 jabber_iq_send(iq);
|
|
81 } else if(!strcmp(type, "result")) {
|
|
82 xmlnode *query = xmlnode_get_child(packet, "query");
|
|
83 xmlnode *child;
|
|
84 JabberID *jid;
|
|
85 JabberBuddy *jb;
|
|
86 JabberBuddyResource *jbr = NULL;
|
|
87 JabberCapabilities capabilities = JABBER_CAP_NONE;
|
|
88 struct _jabber_disco_info_cb_data *jdicd;
|
|
89
|
|
90 if((jid = jabber_id_new(from))) {
|
|
91 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
|
|
92 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
93 jabber_id_free(jid);
|
|
94 }
|
|
95
|
|
96 if(jbr)
|
|
97 capabilities = jbr->capabilities;
|
|
98
|
|
99 for(child = query->child; child; child = child->next) {
|
|
100 if(child->type != XMLNODE_TYPE_TAG)
|
|
101 continue;
|
|
102
|
|
103 if(!strcmp(child->name, "identity")) {
|
|
104 const char *category = xmlnode_get_attrib(child, "category");
|
|
105 const char *type = xmlnode_get_attrib(child, "type");
|
|
106 if(!category || !type)
|
|
107 continue;
|
|
108
|
11675
|
109 if(!strcmp(category, "conference") && !strcmp(type, "text")) {
|
|
110 /* we found a groupchat or MUC server, add it to the list */
|
|
111 /* XXX: actually check for protocol/muc or gc-1.0 support */
|
8312
|
112 js->chat_servers = g_list_append(js->chat_servers, g_strdup(from));
|
11675
|
113 } else if(!strcmp(category, "directory") && !strcmp(type, "user")) {
|
|
114 /* we found a JUD */
|
|
115 js->user_directories = g_list_append(js->user_directories, g_strdup(from));
|
|
116 }
|
8312
|
117
|
|
118 } else if(!strcmp(child->name, "feature")) {
|
|
119 const char *var = xmlnode_get_attrib(child, "var");
|
|
120 if(!var)
|
|
121 continue;
|
|
122
|
|
123 if(!strcmp(var, "http://jabber.org/protocol/si"))
|
|
124 capabilities |= JABBER_CAP_SI;
|
|
125 else if(!strcmp(var, "http://jabber.org/protocol/si/profile/file-transfer"))
|
|
126 capabilities |= JABBER_CAP_SI_FILE_XFER;
|
|
127 else if(!strcmp(var, "http://jabber.org/protocol/bytestreams"))
|
|
128 capabilities |= JABBER_CAP_BYTESTREAMS;
|
11675
|
129 else if(!strcmp(var, "jabber:iq:search"))
|
|
130 capabilities |= JABBER_CAP_IQ_SEARCH;
|
|
131 else if(!strcmp(var, "jabber:iq:register"))
|
|
132 capabilities |= JABBER_CAP_IQ_REGISTER;
|
8312
|
133 }
|
|
134 }
|
|
135
|
|
136 capabilities |= JABBER_CAP_RETRIEVED;
|
|
137
|
|
138 if(jbr)
|
|
139 jbr->capabilities = capabilities;
|
|
140
|
|
141 if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) {
|
|
142 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
143 g_hash_table_remove(js->disco_callbacks, from);
|
|
144 }
|
|
145 } else if(!strcmp(type, "error")) {
|
|
146 JabberID *jid;
|
|
147 JabberBuddy *jb;
|
|
148 JabberBuddyResource *jbr = NULL;
|
|
149 JabberCapabilities capabilities = JABBER_CAP_NONE;
|
|
150 struct _jabber_disco_info_cb_data *jdicd;
|
|
151
|
|
152 if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from)))
|
|
153 return;
|
|
154
|
|
155 if((jid = jabber_id_new(from))) {
|
|
156 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
|
|
157 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
158 jabber_id_free(jid);
|
|
159 }
|
|
160
|
|
161 if(jbr)
|
|
162 capabilities = jbr->capabilities;
|
|
163
|
|
164 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
165 g_hash_table_remove(js->disco_callbacks, from);
|
|
166 }
|
|
167 }
|
|
168
|
|
169 void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) {
|
|
170 const char *from = xmlnode_get_attrib(packet, "from");
|
|
171 const char *type = xmlnode_get_attrib(packet, "type");
|
|
172
|
|
173 if(!strcmp(type, "get")) {
|
|
174 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
|
|
175 "http://jabber.org/protocol/disco#items");
|
|
176
|
|
177 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
|
|
178
|
|
179 xmlnode_set_attrib(iq->node, "to", from);
|
|
180 jabber_iq_send(iq);
|
|
181 }
|
|
182 }
|
|
183
|
|
184 static void
|
|
185 jabber_disco_server_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
186 {
|
|
187 xmlnode *query, *child;
|
|
188 const char *from = xmlnode_get_attrib(packet, "from");
|
|
189 const char *type = xmlnode_get_attrib(packet, "type");
|
|
190
|
|
191 if(!from || !type)
|
|
192 return;
|
|
193
|
|
194 if(strcmp(from, js->user->domain))
|
|
195 return;
|
|
196
|
|
197 if(strcmp(type, "result"))
|
|
198 return;
|
|
199
|
|
200 while(js->chat_servers) {
|
|
201 g_free(js->chat_servers->data);
|
|
202 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers);
|
|
203 }
|
|
204
|
|
205 query = xmlnode_get_child(packet, "query");
|
|
206
|
|
207 for(child = xmlnode_get_child(query, "item"); child;
|
|
208 child = xmlnode_get_next_twin(child)) {
|
|
209 JabberIq *iq;
|
|
210 const char *jid;
|
|
211
|
|
212 if(!(jid = xmlnode_get_attrib(child, "jid")))
|
|
213 continue;
|
|
214
|
|
215 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
216 xmlnode_set_attrib(iq->node, "to", jid);
|
|
217 jabber_iq_send(iq);
|
|
218 }
|
|
219 }
|
|
220
|
|
221 void jabber_disco_items_server(JabberStream *js)
|
|
222 {
|
|
223 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET,
|
|
224 "http://jabber.org/protocol/disco#items");
|
|
225
|
|
226 xmlnode_set_attrib(iq->node, "to", js->user->domain);
|
|
227
|
|
228 jabber_iq_set_callback(iq, jabber_disco_server_result_cb, NULL);
|
|
229 jabber_iq_send(iq);
|
|
230 }
|
|
231
|
|
232 void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data)
|
|
233 {
|
|
234 JabberID *jid;
|
|
235 JabberBuddy *jb;
|
|
236 JabberBuddyResource *jbr = NULL;
|
|
237 struct _jabber_disco_info_cb_data *jdicd;
|
|
238 JabberIq *iq;
|
|
239
|
|
240 if((jid = jabber_id_new(who))) {
|
|
241 if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE)))
|
|
242 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
243 jabber_id_free(jid);
|
|
244 }
|
|
245
|
|
246 if(jbr && jbr->capabilities & JABBER_CAP_RETRIEVED) {
|
|
247 callback(js, who, jbr->capabilities, data);
|
|
248 return;
|
|
249 }
|
|
250
|
|
251 jdicd = g_new0(struct _jabber_disco_info_cb_data, 1);
|
|
252 jdicd->data = data;
|
|
253 jdicd->callback = callback;
|
|
254
|
|
255 g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd);
|
|
256
|
|
257 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
258 xmlnode_set_attrib(iq->node, "to", who);
|
|
259
|
|
260 jabber_iq_send(iq);
|
|
261 }
|
|
262
|
|
263
|