7014
|
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 #include "internal.h"
|
|
22 #include "debug.h"
|
9713
|
23 #include "prpl.h" /* for proto_chat_entry */
|
7310
|
24 #include "notify.h"
|
8113
|
25 #include "request.h"
|
|
26 #include "roomlist.h"
|
7971
|
27 #include "util.h"
|
7014
|
28
|
|
29 #include "chat.h"
|
7895
|
30 #include "iq.h"
|
7014
|
31 #include "message.h"
|
7073
|
32 #include "presence.h"
|
7923
|
33 #include "xdata.h"
|
7014
|
34
|
|
35 GList *jabber_chat_info(GaimConnection *gc)
|
|
36 {
|
|
37 GList *m = NULL;
|
|
38 struct proto_chat_entry *pce;
|
|
39 JabberStream *js = gc->proto_data;
|
|
40
|
|
41 pce = g_new0(struct proto_chat_entry, 1);
|
7841
|
42 pce->label = _("_Room:");
|
7014
|
43 pce->identifier = "room";
|
|
44 m = g_list_append(m, pce);
|
|
45
|
|
46 pce = g_new0(struct proto_chat_entry, 1);
|
7841
|
47 pce->label = _("_Server:");
|
7014
|
48 pce->identifier = "server";
|
8043
|
49 pce->def = js->chat_servers ? js->chat_servers->data : "conference.jabber.org";
|
7014
|
50 m = g_list_append(m, pce);
|
|
51
|
|
52 pce = g_new0(struct proto_chat_entry, 1);
|
7841
|
53 pce->label = _("_Handle:");
|
7014
|
54 pce->identifier = "handle";
|
|
55 pce->def = js->user->node;
|
|
56 m = g_list_append(m, pce);
|
|
57
|
|
58 pce = g_new0(struct proto_chat_entry, 1);
|
7841
|
59 pce->label = _("_Password:");
|
7014
|
60 pce->identifier = "password";
|
|
61 pce->secret = TRUE;
|
|
62 m = g_list_append(m, pce);
|
|
63
|
|
64 return m;
|
|
65 }
|
|
66
|
|
67 JabberChat *jabber_chat_find(JabberStream *js, const char *room,
|
|
68 const char *server)
|
|
69 {
|
|
70 JabberChat *chat;
|
|
71 char *room_jid;
|
|
72
|
|
73 room_jid = g_strdup_printf("%s@%s", room, server);
|
|
74
|
7322
|
75 chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid));
|
7014
|
76 g_free(room_jid);
|
|
77
|
|
78 return chat;
|
|
79 }
|
|
80
|
|
81 struct _find_by_id_data {
|
|
82 int id;
|
|
83 JabberChat *chat;
|
|
84 };
|
|
85
|
|
86 void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data)
|
|
87 {
|
|
88 JabberChat *chat = value;
|
|
89 struct _find_by_id_data *fbid = user_data;
|
|
90
|
|
91 if(chat->id == fbid->id)
|
|
92 fbid->chat = chat;
|
|
93 }
|
|
94
|
|
95 JabberChat *jabber_chat_find_by_id(JabberStream *js, int id)
|
|
96 {
|
|
97 JabberChat *chat;
|
|
98 struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1);
|
7073
|
99 fbid->id = id;
|
7014
|
100 g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid);
|
|
101 chat = fbid->chat;
|
|
102 g_free(fbid);
|
|
103 return chat;
|
|
104 }
|
|
105
|
9130
|
106 JabberChat *jabber_chat_find_by_conv(GaimConversation *conv)
|
|
107 {
|
|
108 GaimAccount *account = gaim_conversation_get_account(conv);
|
|
109 GaimConnection *gc = gaim_account_get_connection(account);
|
|
110 JabberStream *js = gc->proto_data;
|
|
111 int id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
|
|
112
|
|
113 return jabber_chat_find_by_id(js, id);
|
|
114 }
|
|
115
|
7014
|
116 void jabber_chat_invite(GaimConnection *gc, int id, const char *msg,
|
|
117 const char *name)
|
|
118 {
|
|
119 JabberStream *js = gc->proto_data;
|
|
120 JabberChat *chat;
|
|
121 xmlnode *message, *body, *x, *invite;
|
|
122 char *room_jid;
|
|
123
|
|
124 chat = jabber_chat_find_by_id(js, id);
|
|
125 if(!chat)
|
|
126 return;
|
|
127
|
|
128 message = xmlnode_new("message");
|
|
129
|
|
130 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
131
|
|
132 if(chat->muc) {
|
|
133 xmlnode_set_attrib(message, "to", room_jid);
|
|
134 x = xmlnode_new_child(message, "x");
|
|
135 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc#user");
|
|
136 invite = xmlnode_new_child(x, "invite");
|
|
137 xmlnode_set_attrib(invite, "to", name);
|
|
138 body = xmlnode_new_child(invite, "reason");
|
|
139 xmlnode_insert_data(body, msg, -1);
|
|
140 } else {
|
|
141 xmlnode_set_attrib(message, "to", name);
|
|
142 body = xmlnode_new_child(message, "body");
|
|
143 xmlnode_insert_data(body, msg, -1);
|
|
144 x = xmlnode_new_child(message, "x");
|
|
145 xmlnode_set_attrib(x, "jid", room_jid);
|
|
146 xmlnode_set_attrib(x, "xmlns", "jabber:x:conference");
|
|
147 }
|
|
148
|
|
149 jabber_send(js, message);
|
|
150 xmlnode_free(message);
|
|
151 g_free(room_jid);
|
|
152 }
|
|
153
|
9152
|
154 void jabber_chat_member_free(JabberChatMember *jcm);
|
|
155
|
7014
|
156 void jabber_chat_join(GaimConnection *gc, GHashTable *data)
|
|
157 {
|
|
158 JabberChat *chat;
|
|
159 char *room, *server, *handle, *passwd;
|
|
160 xmlnode *presence, *x;
|
7262
|
161 char *tmp, *room_jid, *full_jid;
|
7014
|
162 JabberStream *js = gc->proto_data;
|
|
163
|
|
164 room = g_hash_table_lookup(data, "room");
|
|
165 server = g_hash_table_lookup(data, "server");
|
|
166 handle = g_hash_table_lookup(data, "handle");
|
|
167 passwd = g_hash_table_lookup(data, "password");
|
|
168
|
8113
|
169 if(!room || !server)
|
7014
|
170 return;
|
|
171
|
8113
|
172 if(!handle)
|
|
173 handle = js->user->node;
|
|
174
|
7310
|
175 if(!jabber_nodeprep_validate(room)) {
|
|
176 char *buf = g_strdup_printf(_("%s is not a valid room name"), room);
|
|
177 gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"),
|
|
178 buf);
|
|
179 g_free(buf);
|
|
180 return;
|
|
181 } else if(!jabber_nameprep_validate(server)) {
|
|
182 char *buf = g_strdup_printf(_("%s is not a valid server name"), server);
|
|
183 gaim_notify_error(gc, _("Invalid Server Name"),
|
|
184 _("Invalid Server Name"), buf);
|
|
185 g_free(buf);
|
|
186 return;
|
|
187 } else if(!jabber_resourceprep_validate(handle)) {
|
|
188 char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle);
|
|
189 gaim_notify_error(gc, _("Invalid Room Handle"),
|
|
190 _("Invalid Room Handle"), buf);
|
|
191 }
|
|
192
|
7014
|
193 if(jabber_chat_find(js, room, server))
|
|
194 return;
|
|
195
|
7262
|
196 tmp = g_strdup_printf("%s@%s", room, server);
|
7322
|
197 room_jid = g_strdup(jabber_normalize(NULL, tmp));
|
7262
|
198 g_free(tmp);
|
7014
|
199
|
|
200 chat = g_new0(JabberChat, 1);
|
|
201 chat->js = gc->proto_data;
|
|
202
|
|
203 chat->room = g_strdup(room);
|
|
204 chat->server = g_strdup(server);
|
8400
|
205 chat->handle = g_strdup(handle);
|
7014
|
206
|
9152
|
207 chat->members = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
|
|
208 (GDestroyNotify)jabber_chat_member_free);
|
|
209
|
7014
|
210 g_hash_table_insert(js->chats, room_jid, chat);
|
|
211
|
7073
|
212 presence = jabber_presence_create(gc->away_state, gc->away);
|
7014
|
213 full_jid = g_strdup_printf("%s/%s", room_jid, handle);
|
|
214 xmlnode_set_attrib(presence, "to", full_jid);
|
|
215 g_free(full_jid);
|
|
216
|
|
217 x = xmlnode_new_child(presence, "x");
|
|
218 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc");
|
|
219
|
|
220 if(passwd && *passwd) {
|
|
221 xmlnode *password = xmlnode_new_child(x, "password");
|
|
222 xmlnode_insert_data(password, passwd, -1);
|
|
223 }
|
|
224
|
|
225 jabber_send(js, presence);
|
|
226 xmlnode_free(presence);
|
|
227 }
|
|
228
|
|
229 void jabber_chat_leave(GaimConnection *gc, int id)
|
|
230 {
|
|
231 JabberStream *js = gc->proto_data;
|
|
232 JabberChat *chat = jabber_chat_find_by_id(js, id);
|
7974
|
233
|
7014
|
234
|
|
235 if(!chat)
|
|
236 return;
|
|
237
|
7974
|
238 jabber_chat_part(chat, NULL);
|
9152
|
239
|
|
240 chat->conv = NULL;
|
7014
|
241 }
|
|
242
|
|
243 void jabber_chat_destroy(JabberChat *chat)
|
|
244 {
|
|
245 JabberStream *js = chat->js;
|
|
246 char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
247
|
7322
|
248 g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid));
|
7014
|
249 g_free(room_jid);
|
8396
|
250 }
|
|
251
|
|
252 void jabber_chat_free(JabberChat *chat)
|
|
253 {
|
|
254 if(chat->config_dialog_handle)
|
|
255 gaim_request_close(chat->config_dialog_type, chat->config_dialog_handle);
|
7014
|
256
|
|
257 g_free(chat->room);
|
|
258 g_free(chat->server);
|
|
259 g_free(chat);
|
|
260 }
|
|
261
|
|
262 gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name)
|
|
263 {
|
9554
|
264 return gaim_conv_chat_find_user(GAIM_CONV_CHAT(conv), name);
|
7014
|
265 }
|
|
266
|
7398
|
267 char *jabber_chat_buddy_real_name(GaimConnection *gc, int id, const char *who)
|
|
268 {
|
|
269 JabberStream *js = gc->proto_data;
|
|
270 JabberChat *chat;
|
|
271
|
|
272 chat = jabber_chat_find_by_id(js, id);
|
|
273
|
|
274 if(!chat)
|
|
275 return NULL;
|
|
276
|
|
277 return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who);
|
|
278 }
|
7895
|
279
|
7923
|
280 static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
|
|
281 {
|
|
282 JabberChat *chat = data;
|
|
283 xmlnode *query;
|
|
284 JabberIq *iq;
|
|
285 char *to = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
286
|
|
287 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner");
|
|
288 xmlnode_set_attrib(iq->node, "to", to);
|
|
289 g_free(to);
|
|
290
|
|
291 query = xmlnode_get_child(iq->node, "query");
|
|
292
|
|
293 xmlnode_insert_child(query, result);
|
|
294
|
|
295 jabber_iq_send(iq);
|
|
296 }
|
|
297
|
|
298 static void jabber_chat_room_configure_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
299 {
|
|
300 xmlnode *query, *x;
|
|
301 const char *type = xmlnode_get_attrib(packet, "type");
|
|
302 const char *from = xmlnode_get_attrib(packet, "from");
|
7926
|
303 char *msg;
|
7923
|
304 JabberChat *chat;
|
|
305 JabberID *jid;
|
|
306
|
|
307 if(!type || !from)
|
|
308 return;
|
|
309
|
|
310
|
7926
|
311
|
7923
|
312 if(!strcmp(type, "result")) {
|
|
313 jid = jabber_id_new(from);
|
|
314
|
|
315 if(!jid)
|
|
316 return;
|
|
317
|
|
318 chat = jabber_chat_find(js, jid->node, jid->domain);
|
|
319 jabber_id_free(jid);
|
|
320
|
|
321 if(!chat)
|
|
322 return;
|
|
323
|
|
324 if(!(query = xmlnode_get_child(packet, "query")))
|
|
325 return;
|
|
326
|
8135
|
327 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) {
|
7923
|
328 const char *xmlns;
|
|
329 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
|
|
330 continue;
|
|
331
|
|
332 if(!strcmp(xmlns, "jabber:x:data")) {
|
8396
|
333 chat->config_dialog_type = GAIM_REQUEST_FIELDS;
|
|
334 chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat);
|
7923
|
335 return;
|
|
336 }
|
|
337 }
|
7926
|
338 } else if(!strcmp(type, "error")) {
|
8401
|
339 char *msg = jabber_parse_error(js, packet);
|
7926
|
340
|
|
341 gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg);
|
|
342
|
8401
|
343 if(msg)
|
|
344 g_free(msg);
|
7926
|
345 return;
|
7923
|
346 }
|
|
347
|
7926
|
348 msg = g_strdup_printf("Unable to configure room %s", from);
|
|
349
|
|
350 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg);
|
|
351 g_free(msg);
|
7923
|
352
|
|
353 }
|
|
354
|
|
355 void jabber_chat_request_room_configure(JabberChat *chat) {
|
|
356 JabberIq *iq;
|
|
357 xmlnode *query;
|
|
358 char *room_jid;
|
|
359
|
7895
|
360 if(!chat)
|
|
361 return;
|
|
362
|
8396
|
363 chat->config_dialog_handle = NULL;
|
|
364
|
7955
|
365 if(!chat->muc) {
|
|
366 gaim_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"),
|
|
367 _("This room is not capable of being configured"));
|
|
368 return;
|
|
369 }
|
|
370
|
7923
|
371 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
|
|
372 "http://jabber.org/protocol/muc#owner");
|
|
373 query = xmlnode_get_child(iq->node, "query");
|
|
374 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
|
7895
|
375
|
7923
|
376 xmlnode_set_attrib(iq->node, "to", room_jid);
|
|
377
|
|
378 jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL);
|
|
379
|
|
380 jabber_iq_send(iq);
|
|
381
|
|
382 g_free(room_jid);
|
7895
|
383 }
|
|
384
|
|
385 void jabber_chat_create_instant_room(JabberChat *chat) {
|
|
386 JabberIq *iq;
|
|
387 xmlnode *query, *x;
|
|
388 char *room_jid;
|
|
389
|
|
390 if(!chat)
|
|
391 return;
|
|
392
|
8396
|
393 chat->config_dialog_handle = NULL;
|
|
394
|
7895
|
395 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
|
|
396 "http://jabber.org/protocol/muc#owner");
|
|
397 query = xmlnode_get_child(iq->node, "query");
|
|
398 x = xmlnode_new_child(query, "x");
|
|
399 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
400
|
|
401 xmlnode_set_attrib(iq->node, "to", room_jid);
|
|
402 xmlnode_set_attrib(x, "xmlns", "jabber:x:data");
|
|
403 xmlnode_set_attrib(x, "type", "submit");
|
|
404
|
|
405 jabber_iq_send(iq);
|
|
406
|
|
407 g_free(room_jid);
|
|
408 }
|
7955
|
409
|
|
410 static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
411 {
|
|
412 const char *type = xmlnode_get_attrib(packet, "type");
|
|
413
|
|
414 if(type && !strcmp(type, "error")) {
|
8401
|
415 char *msg = jabber_parse_error(js, packet);
|
|
416
|
|
417 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
|
|
418
|
|
419 if(msg)
|
|
420 g_free(msg);
|
|
421 return;
|
7955
|
422 }
|
|
423 }
|
|
424
|
|
425 static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
|
|
426 {
|
|
427 JabberChat *chat = data;
|
|
428 xmlnode *query;
|
|
429 JabberIq *iq;
|
|
430 char *to = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
431
|
|
432 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
|
|
433 xmlnode_set_attrib(iq->node, "to", to);
|
|
434 g_free(to);
|
|
435
|
|
436 query = xmlnode_get_child(iq->node, "query");
|
|
437
|
|
438 xmlnode_insert_child(query, result);
|
|
439
|
|
440 jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL);
|
|
441
|
|
442 jabber_iq_send(iq);
|
|
443 }
|
|
444
|
|
445 static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
446 {
|
|
447 xmlnode *query, *x;
|
|
448 const char *type = xmlnode_get_attrib(packet, "type");
|
|
449 const char *from = xmlnode_get_attrib(packet, "from");
|
|
450 char *msg;
|
|
451 JabberChat *chat;
|
|
452 JabberID *jid;
|
|
453
|
|
454 if(!type || !from)
|
|
455 return;
|
|
456
|
|
457 if(!strcmp(type, "result")) {
|
|
458 jid = jabber_id_new(from);
|
|
459
|
|
460 if(!jid)
|
|
461 return;
|
|
462
|
|
463 chat = jabber_chat_find(js, jid->node, jid->domain);
|
|
464 jabber_id_free(jid);
|
|
465
|
|
466 if(!chat)
|
|
467 return;
|
|
468
|
|
469 if(!(query = xmlnode_get_child(packet, "query")))
|
|
470 return;
|
|
471
|
8135
|
472 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) {
|
7955
|
473 const char *xmlns;
|
|
474
|
|
475 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
|
|
476 continue;
|
|
477
|
|
478 if(!strcmp(xmlns, "jabber:x:data")) {
|
|
479 jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat);
|
|
480 return;
|
|
481 }
|
|
482 }
|
|
483 } else if(!strcmp(type, "error")) {
|
8401
|
484 char *msg = jabber_parse_error(js, packet);
|
7955
|
485
|
|
486 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
|
|
487
|
8401
|
488 if(msg)
|
|
489 g_free(msg);
|
7955
|
490 return;
|
|
491 }
|
|
492
|
|
493 msg = g_strdup_printf("Unable to configure room %s", from);
|
|
494
|
|
495 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg);
|
|
496 g_free(msg);
|
|
497
|
|
498 }
|
|
499
|
|
500 void jabber_chat_register(JabberChat *chat)
|
|
501 {
|
|
502 JabberIq *iq;
|
|
503 char *room_jid;
|
|
504
|
|
505 if(!chat)
|
|
506 return;
|
|
507
|
|
508 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
509
|
|
510 iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register");
|
|
511 xmlnode_set_attrib(iq->node, "to", room_jid);
|
|
512 g_free(room_jid);
|
|
513
|
|
514 jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL);
|
|
515
|
|
516 jabber_iq_send(iq);
|
|
517 }
|
|
518
|
7971
|
519 /* merge this with the function below when we get everyone on the same page wrt /commands */
|
|
520 void jabber_chat_change_topic(JabberChat *chat, const char *topic)
|
|
521 {
|
|
522 if(topic && *topic) {
|
|
523 JabberMessage *jm;
|
|
524 jm = g_new0(JabberMessage, 1);
|
|
525 jm->js = chat->js;
|
|
526 jm->type = JABBER_MESSAGE_GROUPCHAT;
|
|
527 jm->subject = gaim_markup_strip_html(topic);
|
|
528 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
529 jabber_message_send(jm);
|
|
530 jabber_message_free(jm);
|
|
531 } else {
|
|
532 const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv));
|
|
533 char *buf;
|
7955
|
534
|
7971
|
535 if(cur)
|
8261
|
536 buf = g_strdup_printf(_("current topic is: %s"), cur);
|
7971
|
537 else
|
|
538 buf = g_strdup(_("No topic is set"));
|
|
539 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf,
|
|
540 GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
541 g_free(buf);
|
|
542 }
|
|
543
|
|
544 }
|
|
545
|
|
546 void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic)
|
|
547 {
|
|
548 JabberStream *js = gc->proto_data;
|
|
549 JabberChat *chat = jabber_chat_find_by_id(js, id);
|
|
550
|
|
551 if(!chat)
|
|
552 return;
|
|
553
|
|
554 jabber_chat_change_topic(chat, topic);
|
|
555 }
|
|
556
|
|
557
|
7972
|
558 void jabber_chat_change_nick(JabberChat *chat, const char *nick)
|
|
559 {
|
|
560 xmlnode *presence;
|
|
561 char *full_jid;
|
|
562
|
|
563 if(!chat->muc) {
|
|
564 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "",
|
|
565 _("Nick changing not supported in non-MUC chatrooms"),
|
|
566 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
567 return;
|
|
568 }
|
|
569
|
|
570 presence = jabber_presence_create(chat->js->gc->away_state, chat->js->gc->away);
|
|
571 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick);
|
|
572 xmlnode_set_attrib(presence, "to", full_jid);
|
|
573 g_free(full_jid);
|
|
574
|
|
575 jabber_send(chat->js, presence);
|
|
576 xmlnode_free(presence);
|
|
577 }
|
|
578
|
7974
|
579 void jabber_chat_part(JabberChat *chat, const char *msg)
|
|
580 {
|
|
581 char *room_jid;
|
|
582 xmlnode *presence;
|
7972
|
583
|
8537
|
584 room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server,
|
|
585 chat->handle);
|
7974
|
586 presence = xmlnode_new("presence");
|
|
587 xmlnode_set_attrib(presence, "to", room_jid);
|
|
588 xmlnode_set_attrib(presence, "type", "unavailable");
|
|
589 if(msg) {
|
|
590 xmlnode *status = xmlnode_new_child(presence, "status");
|
|
591 xmlnode_insert_data(status, msg, -1);
|
|
592 }
|
|
593 jabber_send(chat->js, presence);
|
|
594 xmlnode_free(presence);
|
|
595 g_free(room_jid);
|
|
596 }
|
|
597
|
8113
|
598 static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
599 {
|
|
600 xmlnode *query;
|
|
601 xmlnode *item;
|
|
602 const char *type;
|
7974
|
603
|
8113
|
604 if(!js->roomlist)
|
|
605 return;
|
|
606
|
|
607 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) {
|
8401
|
608 char *err = jabber_parse_error(js,packet);
|
|
609 gaim_notify_error(js->gc, _("Roomlist Error"),
|
|
610 _("Error retreiving roomlist"), err);
|
8113
|
611 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
|
8120
|
612 gaim_roomlist_unref(js->roomlist);
|
|
613 js->roomlist = NULL;
|
8401
|
614 g_free(err);
|
8113
|
615 return;
|
|
616 }
|
|
617
|
|
618 if(!(query = xmlnode_get_child(packet, "query"))) {
|
8401
|
619 char *err = jabber_parse_error(js, packet);
|
|
620 gaim_notify_error(js->gc, _("Roomlist Error"),
|
|
621 _("Error retreiving roomlist"), err);
|
8113
|
622 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
|
8120
|
623 gaim_roomlist_unref(js->roomlist);
|
|
624 js->roomlist = NULL;
|
8401
|
625 g_free(err);
|
8113
|
626 return;
|
|
627 }
|
|
628
|
8135
|
629 for(item = xmlnode_get_child(query, "item"); item;
|
|
630 item = xmlnode_get_next_twin(item)) {
|
8113
|
631 const char *name;
|
|
632 GaimRoomlistRoom *room;
|
|
633 JabberID *jid;
|
|
634
|
|
635 if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid"))))
|
|
636 continue;
|
|
637 name = xmlnode_get_attrib(item, "name");
|
|
638
|
|
639
|
|
640 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL);
|
|
641 gaim_roomlist_room_add_field(js->roomlist, room, jid->node);
|
|
642 gaim_roomlist_room_add_field(js->roomlist, room, jid->domain);
|
|
643 gaim_roomlist_room_add_field(js->roomlist, room, name ? name : "");
|
|
644 gaim_roomlist_room_add(js->roomlist, room);
|
|
645
|
|
646 jabber_id_free(jid);
|
|
647 }
|
|
648 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
|
|
649 gaim_roomlist_unref(js->roomlist);
|
|
650 js->roomlist = NULL;
|
|
651 }
|
|
652
|
|
653 static void roomlist_ok_cb(JabberStream *js, const char *server)
|
|
654 {
|
|
655 JabberIq *iq;
|
|
656
|
|
657 if(!js->roomlist)
|
|
658 return;
|
|
659
|
|
660 if(!server || !*server) {
|
|
661 gaim_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL);
|
|
662 return;
|
|
663 }
|
|
664
|
|
665 gaim_roomlist_set_in_progress(js->roomlist, TRUE);
|
|
666
|
|
667 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items");
|
|
668
|
|
669 xmlnode_set_attrib(iq->node, "to", server);
|
|
670
|
|
671 jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL);
|
|
672
|
|
673 jabber_iq_send(iq);
|
|
674 }
|
|
675
|
|
676 GaimRoomlist *jabber_roomlist_get_list(GaimConnection *gc)
|
|
677 {
|
|
678 JabberStream *js = gc->proto_data;
|
|
679 GList *fields = NULL;
|
|
680 GaimRoomlistField *f;
|
|
681
|
|
682 if(js->roomlist)
|
|
683 gaim_roomlist_unref(js->roomlist);
|
|
684
|
|
685 js->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));
|
|
686
|
|
687 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE);
|
|
688 fields = g_list_append(fields, f);
|
|
689
|
|
690 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "server", TRUE);
|
|
691 fields = g_list_append(fields, f);
|
|
692
|
|
693 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE);
|
|
694 fields = g_list_append(fields, f);
|
|
695
|
|
696 gaim_roomlist_set_fields(js->roomlist, fields);
|
|
697
|
|
698 gaim_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"),
|
|
699 _("Select a conference server to query"),
|
|
700 js->chat_servers ? js->chat_servers->data : "conference.jabber.org",
|
8697
|
701 FALSE, FALSE, NULL,
|
|
702 _("Find Rooms"), G_CALLBACK(roomlist_ok_cb), _("Cancel"), NULL, js);
|
8113
|
703
|
|
704 return js->roomlist;
|
|
705 }
|
|
706
|
|
707 void jabber_roomlist_cancel(GaimRoomlist *list)
|
|
708 {
|
|
709 GaimConnection *gc;
|
|
710 JabberStream *js;
|
|
711
|
|
712 gc = gaim_account_get_connection(list->account);
|
|
713 js = gc->proto_data;
|
|
714
|
|
715 gaim_roomlist_set_in_progress(list, FALSE);
|
|
716
|
|
717 if (js->roomlist == list) {
|
|
718 js->roomlist = NULL;
|
|
719 gaim_roomlist_unref(list);
|
|
720 }
|
|
721 }
|
|
722
|
9152
|
723 void jabber_chat_member_free(JabberChatMember *jcm)
|
|
724 {
|
|
725 g_free(jcm->handle);
|
|
726 g_free(jcm->jid);
|
|
727 g_free(jcm);
|
|
728 }
|
|
729
|
|
730 void jabber_chat_track_handle(JabberChat *chat, const char *handle,
|
|
731 const char *jid, const char *affiliation, const char *role)
|
|
732 {
|
|
733 JabberChatMember *jcm = g_new0(JabberChatMember, 1);
|
|
734
|
|
735 jcm->handle = g_strdup(handle);
|
|
736 jcm->jid = g_strdup(jid);
|
|
737
|
|
738 g_hash_table_replace(chat->members, jcm->handle, jcm);
|
|
739
|
|
740 /* XXX: keep track of role and affiliation */
|
|
741 }
|
|
742
|
|
743 void jabber_chat_remove_handle(JabberChat *chat, const char *handle)
|
|
744 {
|
|
745 g_hash_table_remove(chat->members, handle);
|
|
746 }
|
|
747
|
|
748 gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why)
|
|
749 {
|
|
750 JabberIq *iq;
|
|
751 JabberChatMember *jcm = g_hash_table_lookup(chat->members, who);
|
|
752 char *to;
|
|
753 xmlnode *query, *item, *reason;
|
|
754
|
|
755 if(!jcm || !jcm->jid)
|
|
756 return FALSE;
|
|
757
|
|
758 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
|
|
759 "http://jabber.org/protocol/muc#admin");
|
|
760
|
|
761 to = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
762 xmlnode_set_attrib(iq->node, "to", to);
|
|
763 g_free(to);
|
|
764
|
|
765 query = xmlnode_get_child(iq->node, "query");
|
|
766 item = xmlnode_new_child(query, "item");
|
|
767 xmlnode_set_attrib(item, "jid", jcm->jid);
|
|
768 xmlnode_set_attrib(item, "affiliation", "outcast");
|
|
769 if(why) {
|
|
770 reason = xmlnode_new_child(item, "reason");
|
|
771 xmlnode_insert_data(reason, why, -1);
|
|
772 }
|
|
773
|
|
774 jabber_iq_send(iq);
|
|
775
|
|
776 return TRUE;
|
|
777 }
|
8113
|
778
|
|
779
|
9152
|
780 gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why)
|
|
781 {
|
|
782 JabberIq *iq;
|
|
783 JabberChatMember *jcm = g_hash_table_lookup(chat->members, who);
|
|
784 char *to;
|
|
785 xmlnode *query, *item, *reason;
|
|
786
|
|
787 if(!jcm || !jcm->jid)
|
|
788 return FALSE;
|
|
789
|
|
790 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
|
|
791 "http://jabber.org/protocol/muc#admin");
|
|
792
|
|
793 to = g_strdup_printf("%s@%s", chat->room, chat->server);
|
|
794 xmlnode_set_attrib(iq->node, "to", to);
|
|
795 g_free(to);
|
|
796
|
|
797 query = xmlnode_get_child(iq->node, "query");
|
|
798 item = xmlnode_new_child(query, "item");
|
|
799 xmlnode_set_attrib(item, "jid", jcm->jid);
|
|
800 xmlnode_set_attrib(item, "role", "none");
|
|
801 if(why) {
|
|
802 reason = xmlnode_new_child(item, "reason");
|
|
803 xmlnode_insert_data(reason, why, -1);
|
|
804 }
|
|
805
|
|
806 jabber_iq_send(iq);
|
|
807
|
|
808 return TRUE;
|
|
809 }
|
|
810
|
|
811
|
|
812
|