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