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