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