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
|
|
109 /* we found a groupchat or MUC server, add it to the list */
|
|
110 /* XXX: actually check for protocol/muc or gc-1.0 support */
|
|
111 if(!strcmp(category, "conference") && !strcmp(type, "text"))
|
|
112 js->chat_servers = g_list_append(js->chat_servers, g_strdup(from));
|
|
113
|
|
114 } else if(!strcmp(child->name, "feature")) {
|
|
115 const char *var = xmlnode_get_attrib(child, "var");
|
|
116 if(!var)
|
|
117 continue;
|
|
118
|
|
119 if(!strcmp(var, "http://jabber.org/protocol/si"))
|
|
120 capabilities |= JABBER_CAP_SI;
|
|
121 else if(!strcmp(var, "http://jabber.org/protocol/si/profile/file-transfer"))
|
|
122 capabilities |= JABBER_CAP_SI_FILE_XFER;
|
|
123 else if(!strcmp(var, "http://jabber.org/protocol/bytestreams"))
|
|
124 capabilities |= JABBER_CAP_BYTESTREAMS;
|
|
125 }
|
|
126 }
|
|
127
|
|
128 capabilities |= JABBER_CAP_RETRIEVED;
|
|
129
|
|
130 if(jbr)
|
|
131 jbr->capabilities = capabilities;
|
|
132
|
|
133 if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) {
|
|
134 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
135 g_hash_table_remove(js->disco_callbacks, from);
|
|
136 }
|
|
137 } else if(!strcmp(type, "error")) {
|
|
138 JabberID *jid;
|
|
139 JabberBuddy *jb;
|
|
140 JabberBuddyResource *jbr = NULL;
|
|
141 JabberCapabilities capabilities = JABBER_CAP_NONE;
|
|
142 struct _jabber_disco_info_cb_data *jdicd;
|
|
143
|
|
144 if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from)))
|
|
145 return;
|
|
146
|
|
147 if((jid = jabber_id_new(from))) {
|
|
148 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
|
|
149 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
150 jabber_id_free(jid);
|
|
151 }
|
|
152
|
|
153 if(jbr)
|
|
154 capabilities = jbr->capabilities;
|
|
155
|
|
156 jdicd->callback(js, from, capabilities, jdicd->data);
|
|
157 g_hash_table_remove(js->disco_callbacks, from);
|
|
158 }
|
|
159 }
|
|
160
|
|
161 void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) {
|
|
162 const char *from = xmlnode_get_attrib(packet, "from");
|
|
163 const char *type = xmlnode_get_attrib(packet, "type");
|
|
164
|
|
165 if(!strcmp(type, "get")) {
|
|
166 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
|
|
167 "http://jabber.org/protocol/disco#items");
|
|
168
|
|
169 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
|
|
170
|
|
171 xmlnode_set_attrib(iq->node, "to", from);
|
|
172 jabber_iq_send(iq);
|
|
173 }
|
|
174 }
|
|
175
|
|
176 static void
|
|
177 jabber_disco_server_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
178 {
|
|
179 xmlnode *query, *child;
|
|
180 const char *from = xmlnode_get_attrib(packet, "from");
|
|
181 const char *type = xmlnode_get_attrib(packet, "type");
|
|
182
|
|
183 if(!from || !type)
|
|
184 return;
|
|
185
|
|
186 if(strcmp(from, js->user->domain))
|
|
187 return;
|
|
188
|
|
189 if(strcmp(type, "result"))
|
|
190 return;
|
|
191
|
|
192 while(js->chat_servers) {
|
|
193 g_free(js->chat_servers->data);
|
|
194 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers);
|
|
195 }
|
|
196
|
|
197 query = xmlnode_get_child(packet, "query");
|
|
198
|
|
199 for(child = xmlnode_get_child(query, "item"); child;
|
|
200 child = xmlnode_get_next_twin(child)) {
|
|
201 JabberIq *iq;
|
|
202 const char *jid;
|
|
203
|
|
204 if(!(jid = xmlnode_get_attrib(child, "jid")))
|
|
205 continue;
|
|
206
|
|
207 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
208 xmlnode_set_attrib(iq->node, "to", jid);
|
|
209 jabber_iq_send(iq);
|
|
210 }
|
|
211 }
|
|
212
|
|
213 void jabber_disco_items_server(JabberStream *js)
|
|
214 {
|
|
215 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET,
|
|
216 "http://jabber.org/protocol/disco#items");
|
|
217
|
|
218 xmlnode_set_attrib(iq->node, "to", js->user->domain);
|
|
219
|
|
220 jabber_iq_set_callback(iq, jabber_disco_server_result_cb, NULL);
|
|
221 jabber_iq_send(iq);
|
|
222 }
|
|
223
|
|
224 void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data)
|
|
225 {
|
|
226 JabberID *jid;
|
|
227 JabberBuddy *jb;
|
|
228 JabberBuddyResource *jbr = NULL;
|
|
229 struct _jabber_disco_info_cb_data *jdicd;
|
|
230 JabberIq *iq;
|
|
231
|
|
232 if((jid = jabber_id_new(who))) {
|
|
233 if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE)))
|
|
234 jbr = jabber_buddy_find_resource(jb, jid->resource);
|
|
235 jabber_id_free(jid);
|
|
236 }
|
|
237
|
|
238 if(jbr && jbr->capabilities & JABBER_CAP_RETRIEVED) {
|
|
239 callback(js, who, jbr->capabilities, data);
|
|
240 return;
|
|
241 }
|
|
242
|
|
243 jdicd = g_new0(struct _jabber_disco_info_cb_data, 1);
|
|
244 jdicd->data = data;
|
|
245 jdicd->callback = callback;
|
|
246
|
|
247 g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd);
|
|
248
|
|
249 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
|
|
250 xmlnode_set_attrib(iq->node, "to", who);
|
|
251
|
|
252 jabber_iq_send(iq);
|
|
253 }
|
|
254
|
|
255
|