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