Mercurial > pidgin
annotate src/protocols/jabber/chat.c @ 9130:933a19e3a6b3
[gaim-migrate @ 9908]
This puts the core in charge of irc-style /commands, which is way cool. Tim did most of the work, I've just been keeping it in sync with CVS, and slowly adding more commands to jabber.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 30 May 2004 19:34:21 +0000 |
parents | 725413cc9fb9 |
children | f65be7c97812 |
rev | line source |
---|---|
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" | |
23 #include "multi.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 | |
154 void jabber_chat_join(GaimConnection *gc, GHashTable *data) | |
155 { | |
156 JabberChat *chat; | |
157 char *room, *server, *handle, *passwd; | |
158 xmlnode *presence, *x; | |
7262 | 159 char *tmp, *room_jid, *full_jid; |
7014 | 160 JabberStream *js = gc->proto_data; |
161 | |
162 room = g_hash_table_lookup(data, "room"); | |
163 server = g_hash_table_lookup(data, "server"); | |
164 handle = g_hash_table_lookup(data, "handle"); | |
165 passwd = g_hash_table_lookup(data, "password"); | |
166 | |
8113 | 167 if(!room || !server) |
7014 | 168 return; |
169 | |
8113 | 170 if(!handle) |
171 handle = js->user->node; | |
172 | |
7310 | 173 if(!jabber_nodeprep_validate(room)) { |
174 char *buf = g_strdup_printf(_("%s is not a valid room name"), room); | |
175 gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), | |
176 buf); | |
177 g_free(buf); | |
178 return; | |
179 } else if(!jabber_nameprep_validate(server)) { | |
180 char *buf = g_strdup_printf(_("%s is not a valid server name"), server); | |
181 gaim_notify_error(gc, _("Invalid Server Name"), | |
182 _("Invalid Server Name"), buf); | |
183 g_free(buf); | |
184 return; | |
185 } else if(!jabber_resourceprep_validate(handle)) { | |
186 char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); | |
187 gaim_notify_error(gc, _("Invalid Room Handle"), | |
188 _("Invalid Room Handle"), buf); | |
189 } | |
190 | |
7014 | 191 if(jabber_chat_find(js, room, server)) |
192 return; | |
193 | |
7262 | 194 tmp = g_strdup_printf("%s@%s", room, server); |
7322 | 195 room_jid = g_strdup(jabber_normalize(NULL, tmp)); |
7262 | 196 g_free(tmp); |
7014 | 197 |
198 chat = g_new0(JabberChat, 1); | |
199 chat->js = gc->proto_data; | |
200 | |
201 chat->room = g_strdup(room); | |
202 chat->server = g_strdup(server); | |
8400 | 203 chat->handle = g_strdup(handle); |
7014 | 204 |
205 g_hash_table_insert(js->chats, room_jid, chat); | |
206 | |
7073 | 207 presence = jabber_presence_create(gc->away_state, gc->away); |
7014 | 208 full_jid = g_strdup_printf("%s/%s", room_jid, handle); |
209 xmlnode_set_attrib(presence, "to", full_jid); | |
210 g_free(full_jid); | |
211 | |
212 x = xmlnode_new_child(presence, "x"); | |
213 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc"); | |
214 | |
215 if(passwd && *passwd) { | |
216 xmlnode *password = xmlnode_new_child(x, "password"); | |
217 xmlnode_insert_data(password, passwd, -1); | |
218 } | |
219 | |
220 jabber_send(js, presence); | |
221 xmlnode_free(presence); | |
222 } | |
223 | |
224 void jabber_chat_leave(GaimConnection *gc, int id) | |
225 { | |
226 JabberStream *js = gc->proto_data; | |
227 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
7974 | 228 |
7014 | 229 |
230 if(!chat) | |
231 return; | |
232 | |
7974 | 233 jabber_chat_part(chat, NULL); |
7014 | 234 } |
235 | |
236 void jabber_chat_destroy(JabberChat *chat) | |
237 { | |
238 JabberStream *js = chat->js; | |
239 char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
240 | |
7322 | 241 g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); |
7014 | 242 g_free(room_jid); |
8396 | 243 } |
244 | |
245 void jabber_chat_free(JabberChat *chat) | |
246 { | |
247 if(chat->config_dialog_handle) | |
248 gaim_request_close(chat->config_dialog_type, chat->config_dialog_handle); | |
7014 | 249 |
250 g_free(chat->room); | |
251 g_free(chat->server); | |
252 g_free(chat); | |
253 } | |
254 | |
255 gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name) | |
256 { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7073
diff
changeset
|
257 GList *m = gaim_conv_chat_get_users(GAIM_CONV_CHAT(conv)); |
7014 | 258 |
259 while(m) { | |
260 if(!strcmp(m->data, name)) | |
261 return TRUE; | |
262 m = m->next; | |
263 } | |
264 | |
265 return FALSE; | |
266 } | |
267 | |
7398 | 268 char *jabber_chat_buddy_real_name(GaimConnection *gc, int id, const char *who) |
269 { | |
270 JabberStream *js = gc->proto_data; | |
271 JabberChat *chat; | |
272 | |
273 chat = jabber_chat_find_by_id(js, id); | |
274 | |
275 if(!chat) | |
276 return NULL; | |
277 | |
278 return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); | |
279 } | |
7895 | 280 |
7923 | 281 static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
282 { | |
283 JabberChat *chat = data; | |
284 xmlnode *query; | |
285 JabberIq *iq; | |
286 char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
287 | |
288 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
289 xmlnode_set_attrib(iq->node, "to", to); | |
290 g_free(to); | |
291 | |
292 query = xmlnode_get_child(iq->node, "query"); | |
293 | |
294 xmlnode_insert_child(query, result); | |
295 | |
296 jabber_iq_send(iq); | |
297 } | |
298 | |
299 static void jabber_chat_room_configure_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
300 { | |
301 xmlnode *query, *x; | |
302 const char *type = xmlnode_get_attrib(packet, "type"); | |
303 const char *from = xmlnode_get_attrib(packet, "from"); | |
7926 | 304 char *msg; |
7923 | 305 JabberChat *chat; |
306 JabberID *jid; | |
307 | |
308 if(!type || !from) | |
309 return; | |
310 | |
311 | |
7926 | 312 |
7923 | 313 if(!strcmp(type, "result")) { |
314 jid = jabber_id_new(from); | |
315 | |
316 if(!jid) | |
317 return; | |
318 | |
319 chat = jabber_chat_find(js, jid->node, jid->domain); | |
320 jabber_id_free(jid); | |
321 | |
322 if(!chat) | |
323 return; | |
324 | |
325 if(!(query = xmlnode_get_child(packet, "query"))) | |
326 return; | |
327 | |
8135 | 328 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
7923 | 329 const char *xmlns; |
330 if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) | |
331 continue; | |
332 | |
333 if(!strcmp(xmlns, "jabber:x:data")) { | |
8396 | 334 chat->config_dialog_type = GAIM_REQUEST_FIELDS; |
335 chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); | |
7923 | 336 return; |
337 } | |
338 } | |
7926 | 339 } else if(!strcmp(type, "error")) { |
8401 | 340 char *msg = jabber_parse_error(js, packet); |
7926 | 341 |
342 gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); | |
343 | |
8401 | 344 if(msg) |
345 g_free(msg); | |
7926 | 346 return; |
7923 | 347 } |
348 | |
7926 | 349 msg = g_strdup_printf("Unable to configure room %s", from); |
350 | |
351 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); | |
352 g_free(msg); | |
7923 | 353 |
354 } | |
355 | |
356 void jabber_chat_request_room_configure(JabberChat *chat) { | |
357 JabberIq *iq; | |
358 xmlnode *query; | |
359 char *room_jid; | |
360 | |
7895 | 361 if(!chat) |
362 return; | |
363 | |
8396 | 364 chat->config_dialog_handle = NULL; |
365 | |
7955 | 366 if(!chat->muc) { |
367 gaim_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), | |
368 _("This room is not capable of being configured")); | |
369 return; | |
370 } | |
371 | |
7923 | 372 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
373 "http://jabber.org/protocol/muc#owner"); | |
374 query = xmlnode_get_child(iq->node, "query"); | |
375 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
7895 | 376 |
7923 | 377 xmlnode_set_attrib(iq->node, "to", room_jid); |
378 | |
379 jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
380 | |
381 jabber_iq_send(iq); | |
382 | |
383 g_free(room_jid); | |
7895 | 384 } |
385 | |
386 void jabber_chat_create_instant_room(JabberChat *chat) { | |
387 JabberIq *iq; | |
388 xmlnode *query, *x; | |
389 char *room_jid; | |
390 | |
391 if(!chat) | |
392 return; | |
393 | |
8396 | 394 chat->config_dialog_handle = NULL; |
395 | |
7895 | 396 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
397 "http://jabber.org/protocol/muc#owner"); | |
398 query = xmlnode_get_child(iq->node, "query"); | |
399 x = xmlnode_new_child(query, "x"); | |
400 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
401 | |
402 xmlnode_set_attrib(iq->node, "to", room_jid); | |
403 xmlnode_set_attrib(x, "xmlns", "jabber:x:data"); | |
404 xmlnode_set_attrib(x, "type", "submit"); | |
405 | |
406 jabber_iq_send(iq); | |
407 | |
408 g_free(room_jid); | |
409 } | |
7955 | 410 |
411 static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
412 { | |
413 const char *type = xmlnode_get_attrib(packet, "type"); | |
414 | |
415 if(type && !strcmp(type, "error")) { | |
8401 | 416 char *msg = jabber_parse_error(js, packet); |
417 | |
418 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); | |
419 | |
420 if(msg) | |
421 g_free(msg); | |
422 return; | |
7955 | 423 } |
424 } | |
425 | |
426 static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
427 { | |
428 JabberChat *chat = data; | |
429 xmlnode *query; | |
430 JabberIq *iq; | |
431 char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
432 | |
433 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
434 xmlnode_set_attrib(iq->node, "to", to); | |
435 g_free(to); | |
436 | |
437 query = xmlnode_get_child(iq->node, "query"); | |
438 | |
439 xmlnode_insert_child(query, result); | |
440 | |
441 jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
442 | |
443 jabber_iq_send(iq); | |
444 } | |
445 | |
446 static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
447 { | |
448 xmlnode *query, *x; | |
449 const char *type = xmlnode_get_attrib(packet, "type"); | |
450 const char *from = xmlnode_get_attrib(packet, "from"); | |
451 char *msg; | |
452 JabberChat *chat; | |
453 JabberID *jid; | |
454 | |
455 if(!type || !from) | |
456 return; | |
457 | |
458 if(!strcmp(type, "result")) { | |
459 jid = jabber_id_new(from); | |
460 | |
461 if(!jid) | |
462 return; | |
463 | |
464 chat = jabber_chat_find(js, jid->node, jid->domain); | |
465 jabber_id_free(jid); | |
466 | |
467 if(!chat) | |
468 return; | |
469 | |
470 if(!(query = xmlnode_get_child(packet, "query"))) | |
471 return; | |
472 | |
8135 | 473 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
7955 | 474 const char *xmlns; |
475 | |
476 if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) | |
477 continue; | |
478 | |
479 if(!strcmp(xmlns, "jabber:x:data")) { | |
480 jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
481 return; | |
482 } | |
483 } | |
484 } else if(!strcmp(type, "error")) { | |
8401 | 485 char *msg = jabber_parse_error(js, packet); |
7955 | 486 |
487 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); | |
488 | |
8401 | 489 if(msg) |
490 g_free(msg); | |
7955 | 491 return; |
492 } | |
493 | |
494 msg = g_strdup_printf("Unable to configure room %s", from); | |
495 | |
496 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); | |
497 g_free(msg); | |
498 | |
499 } | |
500 | |
501 void jabber_chat_register(JabberChat *chat) | |
502 { | |
503 JabberIq *iq; | |
504 char *room_jid; | |
505 | |
506 if(!chat) | |
507 return; | |
508 | |
509 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
510 | |
511 iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
512 xmlnode_set_attrib(iq->node, "to", room_jid); | |
513 g_free(room_jid); | |
514 | |
515 jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
516 | |
517 jabber_iq_send(iq); | |
518 } | |
519 | |
7971 | 520 /* merge this with the function below when we get everyone on the same page wrt /commands */ |
521 void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
522 { | |
523 if(topic && *topic) { | |
524 JabberMessage *jm; | |
525 jm = g_new0(JabberMessage, 1); | |
526 jm->js = chat->js; | |
527 jm->type = JABBER_MESSAGE_GROUPCHAT; | |
528 jm->subject = gaim_markup_strip_html(topic); | |
529 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
530 jabber_message_send(jm); | |
531 jabber_message_free(jm); | |
532 } else { | |
533 const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv)); | |
534 char *buf; | |
7955 | 535 |
7971 | 536 if(cur) |
8261 | 537 buf = g_strdup_printf(_("current topic is: %s"), cur); |
7971 | 538 else |
539 buf = g_strdup(_("No topic is set")); | |
540 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf, | |
541 GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL)); | |
542 g_free(buf); | |
543 } | |
544 | |
545 } | |
546 | |
547 void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic) | |
548 { | |
549 JabberStream *js = gc->proto_data; | |
550 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
551 | |
552 if(!chat) | |
553 return; | |
554 | |
555 jabber_chat_change_topic(chat, topic); | |
556 } | |
557 | |
558 | |
7972 | 559 void jabber_chat_change_nick(JabberChat *chat, const char *nick) |
560 { | |
561 xmlnode *presence; | |
562 char *full_jid; | |
563 | |
564 if(!chat->muc) { | |
565 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", | |
566 _("Nick changing not supported in non-MUC chatrooms"), | |
567 GAIM_MESSAGE_SYSTEM, time(NULL)); | |
568 return; | |
569 } | |
570 | |
571 presence = jabber_presence_create(chat->js->gc->away_state, chat->js->gc->away); | |
572 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); | |
573 xmlnode_set_attrib(presence, "to", full_jid); | |
574 g_free(full_jid); | |
575 | |
576 jabber_send(chat->js, presence); | |
577 xmlnode_free(presence); | |
578 } | |
579 | |
7974 | 580 void jabber_chat_part(JabberChat *chat, const char *msg) |
581 { | |
582 char *room_jid; | |
583 xmlnode *presence; | |
7972 | 584 |
8537 | 585 room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
586 chat->handle); | |
7974 | 587 presence = xmlnode_new("presence"); |
588 xmlnode_set_attrib(presence, "to", room_jid); | |
589 xmlnode_set_attrib(presence, "type", "unavailable"); | |
590 if(msg) { | |
591 xmlnode *status = xmlnode_new_child(presence, "status"); | |
592 xmlnode_insert_data(status, msg, -1); | |
593 } | |
594 jabber_send(chat->js, presence); | |
595 xmlnode_free(presence); | |
596 g_free(room_jid); | |
597 } | |
598 | |
8113 | 599 static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
600 { | |
601 xmlnode *query; | |
602 xmlnode *item; | |
603 const char *type; | |
7974 | 604 |
8113 | 605 if(!js->roomlist) |
606 return; | |
607 | |
608 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) { | |
8401 | 609 char *err = jabber_parse_error(js,packet); |
610 gaim_notify_error(js->gc, _("Roomlist Error"), | |
611 _("Error retreiving roomlist"), err); | |
8113 | 612 gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
8120 | 613 gaim_roomlist_unref(js->roomlist); |
614 js->roomlist = NULL; | |
8401 | 615 g_free(err); |
8113 | 616 return; |
617 } | |
618 | |
619 if(!(query = xmlnode_get_child(packet, "query"))) { | |
8401 | 620 char *err = jabber_parse_error(js, packet); |
621 gaim_notify_error(js->gc, _("Roomlist Error"), | |
622 _("Error retreiving roomlist"), err); | |
8113 | 623 gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
8120 | 624 gaim_roomlist_unref(js->roomlist); |
625 js->roomlist = NULL; | |
8401 | 626 g_free(err); |
8113 | 627 return; |
628 } | |
629 | |
8135 | 630 for(item = xmlnode_get_child(query, "item"); item; |
631 item = xmlnode_get_next_twin(item)) { | |
8113 | 632 const char *name; |
633 GaimRoomlistRoom *room; | |
634 JabberID *jid; | |
635 | |
636 if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
637 continue; | |
638 name = xmlnode_get_attrib(item, "name"); | |
639 | |
640 | |
641 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); | |
642 gaim_roomlist_room_add_field(js->roomlist, room, jid->node); | |
643 gaim_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
644 gaim_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
645 gaim_roomlist_room_add(js->roomlist, room); | |
646 | |
647 jabber_id_free(jid); | |
648 } | |
649 gaim_roomlist_set_in_progress(js->roomlist, FALSE); | |
650 gaim_roomlist_unref(js->roomlist); | |
651 js->roomlist = NULL; | |
652 } | |
653 | |
654 static void roomlist_ok_cb(JabberStream *js, const char *server) | |
655 { | |
656 JabberIq *iq; | |
657 | |
658 if(!js->roomlist) | |
659 return; | |
660 | |
661 if(!server || !*server) { | |
662 gaim_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL); | |
663 return; | |
664 } | |
665 | |
666 gaim_roomlist_set_in_progress(js->roomlist, TRUE); | |
667 | |
668 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
669 | |
670 xmlnode_set_attrib(iq->node, "to", server); | |
671 | |
672 jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
673 | |
674 jabber_iq_send(iq); | |
675 } | |
676 | |
677 GaimRoomlist *jabber_roomlist_get_list(GaimConnection *gc) | |
678 { | |
679 JabberStream *js = gc->proto_data; | |
680 GList *fields = NULL; | |
681 GaimRoomlistField *f; | |
682 | |
683 if(js->roomlist) | |
684 gaim_roomlist_unref(js->roomlist); | |
685 | |
686 js->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
687 | |
688 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); | |
689 fields = g_list_append(fields, f); | |
690 | |
691 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "server", TRUE); | |
692 fields = g_list_append(fields, f); | |
693 | |
694 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE); | |
695 fields = g_list_append(fields, f); | |
696 | |
697 gaim_roomlist_set_fields(js->roomlist, fields); | |
698 | |
699 gaim_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), | |
700 _("Select a conference server to query"), | |
701 js->chat_servers ? js->chat_servers->data : "conference.jabber.org", | |
8697 | 702 FALSE, FALSE, NULL, |
703 _("Find Rooms"), G_CALLBACK(roomlist_ok_cb), _("Cancel"), NULL, js); | |
8113 | 704 |
705 return js->roomlist; | |
706 } | |
707 | |
708 void jabber_roomlist_cancel(GaimRoomlist *list) | |
709 { | |
710 GaimConnection *gc; | |
711 JabberStream *js; | |
712 | |
713 gc = gaim_account_get_connection(list->account); | |
714 js = gc->proto_data; | |
715 | |
716 gaim_roomlist_set_in_progress(list, FALSE); | |
717 | |
718 if (js->roomlist == list) { | |
719 js->roomlist = NULL; | |
720 gaim_roomlist_unref(list); | |
721 } | |
722 } | |
723 | |
724 | |
725 |