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