Mercurial > pidgin
annotate src/protocols/jabber/chat.c @ 8537:dc818b62379e
[gaim-migrate @ 9276]
jabber fixination
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Wed, 31 Mar 2004 18:37:06 +0000 |
parents | c13a4913a071 |
children | 725413cc9fb9 |
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 |
8537 | 575 room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
576 chat->handle); | |
7974 | 577 presence = xmlnode_new("presence"); |
578 xmlnode_set_attrib(presence, "to", room_jid); | |
579 xmlnode_set_attrib(presence, "type", "unavailable"); | |
580 if(msg) { | |
581 xmlnode *status = xmlnode_new_child(presence, "status"); | |
582 xmlnode_insert_data(status, msg, -1); | |
583 } | |
584 jabber_send(chat->js, presence); | |
585 xmlnode_free(presence); | |
586 g_free(room_jid); | |
587 } | |
588 | |
8113 | 589 static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
590 { | |
591 xmlnode *query; | |
592 xmlnode *item; | |
593 const char *type; | |
7974 | 594 |
8113 | 595 if(!js->roomlist) |
596 return; | |
597 | |
598 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) { | |
8401 | 599 char *err = jabber_parse_error(js,packet); |
600 gaim_notify_error(js->gc, _("Roomlist Error"), | |
601 _("Error retreiving roomlist"), err); | |
8113 | 602 gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
8120 | 603 gaim_roomlist_unref(js->roomlist); |
604 js->roomlist = NULL; | |
8401 | 605 g_free(err); |
8113 | 606 return; |
607 } | |
608 | |
609 if(!(query = xmlnode_get_child(packet, "query"))) { | |
8401 | 610 char *err = jabber_parse_error(js, packet); |
611 gaim_notify_error(js->gc, _("Roomlist Error"), | |
612 _("Error retreiving roomlist"), err); | |
8113 | 613 gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
8120 | 614 gaim_roomlist_unref(js->roomlist); |
615 js->roomlist = NULL; | |
8401 | 616 g_free(err); |
8113 | 617 return; |
618 } | |
619 | |
8135 | 620 for(item = xmlnode_get_child(query, "item"); item; |
621 item = xmlnode_get_next_twin(item)) { | |
8113 | 622 const char *name; |
623 GaimRoomlistRoom *room; | |
624 JabberID *jid; | |
625 | |
626 if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
627 continue; | |
628 name = xmlnode_get_attrib(item, "name"); | |
629 | |
630 | |
631 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); | |
632 gaim_roomlist_room_add_field(js->roomlist, room, jid->node); | |
633 gaim_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
634 gaim_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
635 gaim_roomlist_room_add(js->roomlist, room); | |
636 | |
637 jabber_id_free(jid); | |
638 } | |
639 gaim_roomlist_set_in_progress(js->roomlist, FALSE); | |
640 gaim_roomlist_unref(js->roomlist); | |
641 js->roomlist = NULL; | |
642 } | |
643 | |
644 static void roomlist_ok_cb(JabberStream *js, const char *server) | |
645 { | |
646 JabberIq *iq; | |
647 | |
648 if(!js->roomlist) | |
649 return; | |
650 | |
651 if(!server || !*server) { | |
652 gaim_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL); | |
653 return; | |
654 } | |
655 | |
656 gaim_roomlist_set_in_progress(js->roomlist, TRUE); | |
657 | |
658 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
659 | |
660 xmlnode_set_attrib(iq->node, "to", server); | |
661 | |
662 jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
663 | |
664 jabber_iq_send(iq); | |
665 } | |
666 | |
667 GaimRoomlist *jabber_roomlist_get_list(GaimConnection *gc) | |
668 { | |
669 JabberStream *js = gc->proto_data; | |
670 GList *fields = NULL; | |
671 GaimRoomlistField *f; | |
672 | |
673 if(js->roomlist) | |
674 gaim_roomlist_unref(js->roomlist); | |
675 | |
676 js->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
677 | |
678 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); | |
679 fields = g_list_append(fields, f); | |
680 | |
681 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "server", TRUE); | |
682 fields = g_list_append(fields, f); | |
683 | |
684 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE); | |
685 fields = g_list_append(fields, f); | |
686 | |
687 gaim_roomlist_set_fields(js->roomlist, fields); | |
688 | |
689 gaim_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), | |
690 _("Select a conference server to query"), | |
691 js->chat_servers ? js->chat_servers->data : "conference.jabber.org", | |
692 FALSE, FALSE, _("Find Rooms"), G_CALLBACK(roomlist_ok_cb), _("Cancel"), NULL, js); | |
693 | |
694 return js->roomlist; | |
695 } | |
696 | |
697 void jabber_roomlist_cancel(GaimRoomlist *list) | |
698 { | |
699 GaimConnection *gc; | |
700 JabberStream *js; | |
701 | |
702 gc = gaim_account_get_connection(list->account); | |
703 js = gc->proto_data; | |
704 | |
705 gaim_roomlist_set_in_progress(list, FALSE); | |
706 | |
707 if (js->roomlist == list) { | |
708 js->roomlist = NULL; | |
709 gaim_roomlist_unref(list); | |
710 } | |
711 } | |
712 | |
713 | |
714 |