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