Tue, 11 Jan 2005 17:25:06 +0000
[gaim-migrate @ 11796]
Lots of things here:
- Several memory leak fixes
- A few invalid memory access fixes
- Fix a yahoo crash going idle when away
- Fix Add user in chats to actually fill in the screenname
- Add gaim_account_{get,set}_enabled to perl
- Fix command priorities (fixes /me in IRC)
- Fix MSN notification server transfer to be quiet about it
- Fix MSN blist sync if user has insane friendly name
- Make the docklet less crash-happy if it fails to embed in 3 seconds
- Only probe for native plugins with the correct file extension
- 1 typo fix :)
... and quite possibly something else I forgot.
| 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
bb37562302a1
[gaim-migrate @ 10574]
Mark Doliner <markdoliner@pidgin.im>
parents:
9554
diff
changeset
|
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
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
41 | pce->label = _("_Room:"); |
| 7014 | 42 | pce->identifier = "room"; |
| 43 | m = g_list_append(m, pce); | |
| 44 | ||
| 45 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
46 | pce->label = _("_Server:"); |
| 7014 | 47 | pce->identifier = "server"; |
| 48 | m = g_list_append(m, pce); | |
| 49 | ||
| 50 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
51 | pce->label = _("_Handle:"); |
| 7014 | 52 | pce->identifier = "handle"; |
| 53 | m = g_list_append(m, pce); | |
| 54 | ||
| 55 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
56 | pce->label = _("_Password:"); |
| 7014 | 57 | pce->identifier = "password"; |
| 58 | pce->secret = TRUE; | |
| 59 | m = g_list_append(m, pce); | |
| 60 | ||
| 61 | return m; | |
| 62 | } | |
| 63 | ||
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
64 | GHashTable *jabber_chat_info_defaults(GaimConnection *gc, const char *chat_name) |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
65 | { |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
66 | GHashTable *defaults; |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
67 | JabberStream *js = gc->proto_data; |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
68 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
69 | defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
70 | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
71 | g_hash_table_insert(defaults, "handle", g_strdup(js->user->node)); |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
72 | |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
73 | if (js->chat_servers) |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
74 | g_hash_table_insert(defaults, "server", g_strdup(js->chat_servers->data)); |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
75 | else |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
76 | g_hash_table_insert(defaults, "server", g_strdup("conference.jabber.org")); |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
77 | |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
78 | if (chat_name != NULL) { |
| 9760 | 79 | JabberID *jid = jabber_id_new(chat_name); |
| 80 | if(jid) { | |
| 81 | g_hash_table_insert(defaults, "room", g_strdup(jid->node)); | |
| 82 | if(jid->domain) | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
83 | g_hash_table_replace(defaults, "server", g_strdup(jid->domain)); |
| 9760 | 84 | jabber_id_free(jid); |
| 85 | } | |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
86 | } |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
87 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
88 | return defaults; |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
89 | } |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
90 | |
| 7014 | 91 | JabberChat *jabber_chat_find(JabberStream *js, const char *room, |
| 92 | const char *server) | |
| 93 | { | |
| 94 | JabberChat *chat; | |
| 95 | char *room_jid; | |
| 96 | ||
| 97 | room_jid = g_strdup_printf("%s@%s", room, server); | |
| 98 | ||
| 7322 | 99 | chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 100 | g_free(room_jid); |
| 101 | ||
| 102 | return chat; | |
| 103 | } | |
| 104 | ||
| 105 | struct _find_by_id_data { | |
| 106 | int id; | |
| 107 | JabberChat *chat; | |
| 108 | }; | |
| 109 | ||
| 110 | void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data) | |
| 111 | { | |
| 112 | JabberChat *chat = value; | |
| 113 | struct _find_by_id_data *fbid = user_data; | |
| 114 | ||
| 115 | if(chat->id == fbid->id) | |
| 116 | fbid->chat = chat; | |
| 117 | } | |
| 118 | ||
| 119 | JabberChat *jabber_chat_find_by_id(JabberStream *js, int id) | |
| 120 | { | |
| 121 | JabberChat *chat; | |
| 122 | struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1); | |
| 7073 | 123 | fbid->id = id; |
| 7014 | 124 | g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid); |
| 125 | chat = fbid->chat; | |
| 126 | g_free(fbid); | |
| 127 | return chat; | |
| 128 | } | |
| 129 | ||
| 9130 | 130 | JabberChat *jabber_chat_find_by_conv(GaimConversation *conv) |
| 131 | { | |
| 132 | GaimAccount *account = gaim_conversation_get_account(conv); | |
| 133 | GaimConnection *gc = gaim_account_get_connection(account); | |
| 134 | JabberStream *js = gc->proto_data; | |
| 135 | int id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)); | |
| 136 | ||
| 137 | return jabber_chat_find_by_id(js, id); | |
| 138 | } | |
| 139 | ||
| 7014 | 140 | void jabber_chat_invite(GaimConnection *gc, int id, const char *msg, |
| 141 | const char *name) | |
| 142 | { | |
| 143 | JabberStream *js = gc->proto_data; | |
| 144 | JabberChat *chat; | |
| 145 | xmlnode *message, *body, *x, *invite; | |
| 146 | char *room_jid; | |
| 147 | ||
| 148 | chat = jabber_chat_find_by_id(js, id); | |
| 149 | if(!chat) | |
| 150 | return; | |
| 151 | ||
| 152 | message = xmlnode_new("message"); | |
| 153 | ||
| 154 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 155 | ||
| 156 | if(chat->muc) { | |
| 157 | xmlnode_set_attrib(message, "to", room_jid); | |
| 158 | x = xmlnode_new_child(message, "x"); | |
| 159 | xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc#user"); | |
| 160 | invite = xmlnode_new_child(x, "invite"); | |
| 161 | xmlnode_set_attrib(invite, "to", name); | |
| 162 | body = xmlnode_new_child(invite, "reason"); | |
| 163 | xmlnode_insert_data(body, msg, -1); | |
| 164 | } else { | |
| 165 | xmlnode_set_attrib(message, "to", name); | |
| 166 | body = xmlnode_new_child(message, "body"); | |
| 167 | xmlnode_insert_data(body, msg, -1); | |
| 168 | x = xmlnode_new_child(message, "x"); | |
| 169 | xmlnode_set_attrib(x, "jid", room_jid); | |
| 170 | xmlnode_set_attrib(x, "xmlns", "jabber:x:conference"); | |
| 171 | } | |
| 172 | ||
| 173 | jabber_send(js, message); | |
| 174 | xmlnode_free(message); | |
| 175 | g_free(room_jid); | |
| 176 | } | |
| 177 | ||
| 9152 | 178 | void jabber_chat_member_free(JabberChatMember *jcm); |
| 179 | ||
|
9917
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
180 | char *jabber_get_chat_name(GHashTable *data) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
181 | char *room, *server, *chat_name = NULL; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
182 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
183 | room = g_hash_table_lookup(data, "room"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
184 | server = g_hash_table_lookup(data, "server"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
185 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
186 | if (room && server) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
187 | chat_name = g_strdup_printf("%s@%s", room, server); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
188 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
189 | return chat_name; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
190 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
191 | |
| 7014 | 192 | void jabber_chat_join(GaimConnection *gc, GHashTable *data) |
| 193 | { | |
| 194 | JabberChat *chat; | |
| 195 | char *room, *server, *handle, *passwd; | |
| 196 | xmlnode *presence, *x; | |
| 7262 | 197 | char *tmp, *room_jid, *full_jid; |
| 7014 | 198 | JabberStream *js = gc->proto_data; |
| 9954 | 199 | GaimPresence *gpresence; |
| 200 | GaimStatus *status; | |
| 201 | JabberBuddyState state; | |
| 202 | const char *msg; | |
| 203 | int priority; | |
| 7014 | 204 | |
| 205 | room = g_hash_table_lookup(data, "room"); | |
| 206 | server = g_hash_table_lookup(data, "server"); | |
| 207 | handle = g_hash_table_lookup(data, "handle"); | |
| 208 | passwd = g_hash_table_lookup(data, "password"); | |
| 209 | ||
| 8113 | 210 | if(!room || !server) |
| 7014 | 211 | return; |
| 212 | ||
| 8113 | 213 | if(!handle) |
| 214 | handle = js->user->node; | |
| 215 | ||
| 7310 | 216 | if(!jabber_nodeprep_validate(room)) { |
| 217 | char *buf = g_strdup_printf(_("%s is not a valid room name"), room); | |
| 218 | gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), | |
| 219 | buf); | |
| 220 | g_free(buf); | |
| 221 | return; | |
| 222 | } else if(!jabber_nameprep_validate(server)) { | |
| 223 | char *buf = g_strdup_printf(_("%s is not a valid server name"), server); | |
| 224 | gaim_notify_error(gc, _("Invalid Server Name"), | |
| 225 | _("Invalid Server Name"), buf); | |
| 226 | g_free(buf); | |
| 227 | return; | |
| 228 | } else if(!jabber_resourceprep_validate(handle)) { | |
| 229 | char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); | |
| 230 | gaim_notify_error(gc, _("Invalid Room Handle"), | |
| 231 | _("Invalid Room Handle"), buf); | |
| 232 | } | |
| 233 | ||
| 7014 | 234 | if(jabber_chat_find(js, room, server)) |
| 235 | return; | |
| 236 | ||
| 7262 | 237 | tmp = g_strdup_printf("%s@%s", room, server); |
| 7322 | 238 | room_jid = g_strdup(jabber_normalize(NULL, tmp)); |
| 7262 | 239 | g_free(tmp); |
| 7014 | 240 | |
| 241 | chat = g_new0(JabberChat, 1); | |
| 242 | chat->js = gc->proto_data; | |
| 243 | ||
| 244 | chat->room = g_strdup(room); | |
| 245 | chat->server = g_strdup(server); | |
| 8400 | 246 | chat->handle = g_strdup(handle); |
| 7014 | 247 | |
| 9152 | 248 | chat->members = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, |
| 249 | (GDestroyNotify)jabber_chat_member_free); | |
| 250 | ||
| 7014 | 251 | g_hash_table_insert(js->chats, room_jid, chat); |
| 252 | ||
| 9954 | 253 | gpresence = gaim_account_get_presence(gc->account); |
| 254 | status = gaim_presence_get_active_status(gpresence); | |
| 255 | ||
| 256 | gaim_status_to_jabber(status, &state, &msg, &priority); | |
| 257 | ||
| 258 | presence = jabber_presence_create(state, msg, priority); | |
| 7014 | 259 | full_jid = g_strdup_printf("%s/%s", room_jid, handle); |
| 260 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 261 | g_free(full_jid); | |
| 262 | ||
| 263 | x = xmlnode_new_child(presence, "x"); | |
| 264 | xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc"); | |
| 265 | ||
| 266 | if(passwd && *passwd) { | |
| 267 | xmlnode *password = xmlnode_new_child(x, "password"); | |
| 268 | xmlnode_insert_data(password, passwd, -1); | |
| 269 | } | |
| 270 | ||
| 271 | jabber_send(js, presence); | |
| 272 | xmlnode_free(presence); | |
| 273 | } | |
| 274 | ||
| 275 | void jabber_chat_leave(GaimConnection *gc, int id) | |
| 276 | { | |
| 277 | JabberStream *js = gc->proto_data; | |
| 278 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 7974 | 279 | |
| 7014 | 280 | |
| 281 | if(!chat) | |
| 282 | return; | |
| 283 | ||
| 7974 | 284 | jabber_chat_part(chat, NULL); |
| 9152 | 285 | |
| 286 | chat->conv = NULL; | |
| 7014 | 287 | } |
| 288 | ||
| 289 | void jabber_chat_destroy(JabberChat *chat) | |
| 290 | { | |
| 291 | JabberStream *js = chat->js; | |
| 292 | char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 293 | ||
| 7322 | 294 | g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 295 | g_free(room_jid); |
| 8396 | 296 | } |
| 297 | ||
| 298 | void jabber_chat_free(JabberChat *chat) | |
| 299 | { | |
| 300 | if(chat->config_dialog_handle) | |
| 301 | gaim_request_close(chat->config_dialog_type, chat->config_dialog_handle); | |
| 7014 | 302 | |
| 303 | g_free(chat->room); | |
| 304 | g_free(chat->server); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
305 | g_free(chat->handle); |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
306 | g_hash_table_destroy(chat->members); |
| 7014 | 307 | g_free(chat); |
| 308 | } | |
| 309 | ||
| 310 | gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name) | |
| 311 | { | |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9152
diff
changeset
|
312 | return gaim_conv_chat_find_user(GAIM_CONV_CHAT(conv), name); |
| 7014 | 313 | } |
| 314 | ||
| 7398 | 315 | char *jabber_chat_buddy_real_name(GaimConnection *gc, int id, const char *who) |
| 316 | { | |
| 317 | JabberStream *js = gc->proto_data; | |
| 318 | JabberChat *chat; | |
| 319 | ||
| 320 | chat = jabber_chat_find_by_id(js, id); | |
| 321 | ||
| 322 | if(!chat) | |
| 323 | return NULL; | |
| 324 | ||
| 325 | return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); | |
| 326 | } | |
| 7895 | 327 | |
| 7923 | 328 | static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
| 329 | { | |
| 330 | JabberChat *chat = data; | |
| 331 | xmlnode *query; | |
| 332 | JabberIq *iq; | |
| 333 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 334 | ||
| 335 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
| 336 | xmlnode_set_attrib(iq->node, "to", to); | |
| 337 | g_free(to); | |
| 338 | ||
| 339 | query = xmlnode_get_child(iq->node, "query"); | |
| 340 | ||
| 341 | xmlnode_insert_child(query, result); | |
| 342 | ||
| 343 | jabber_iq_send(iq); | |
| 344 | } | |
| 345 | ||
| 346 | static void jabber_chat_room_configure_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 347 | { | |
| 348 | xmlnode *query, *x; | |
| 349 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 350 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 7926 | 351 | char *msg; |
| 7923 | 352 | JabberChat *chat; |
| 353 | JabberID *jid; | |
| 354 | ||
| 355 | if(!type || !from) | |
| 356 | return; | |
| 357 | ||
| 358 | ||
| 7926 | 359 | |
| 7923 | 360 | if(!strcmp(type, "result")) { |
| 361 | jid = jabber_id_new(from); | |
| 362 | ||
| 363 | if(!jid) | |
| 364 | return; | |
| 365 | ||
| 366 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 367 | jabber_id_free(jid); | |
| 368 | ||
| 369 | if(!chat) | |
| 370 | return; | |
| 371 | ||
| 372 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 373 | return; | |
| 374 | ||
| 8135 | 375 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7923 | 376 | const char *xmlns; |
| 377 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) | |
| 378 | continue; | |
| 379 | ||
| 380 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 8396 | 381 | chat->config_dialog_type = GAIM_REQUEST_FIELDS; |
| 382 | chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); | |
| 7923 | 383 | return; |
| 384 | } | |
| 385 | } | |
| 7926 | 386 | } else if(!strcmp(type, "error")) { |
| 8401 | 387 | char *msg = jabber_parse_error(js, packet); |
| 7926 | 388 | |
| 389 | gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); | |
| 390 | ||
| 8401 | 391 | if(msg) |
| 392 | g_free(msg); | |
| 7926 | 393 | return; |
| 7923 | 394 | } |
| 395 | ||
| 7926 | 396 | msg = g_strdup_printf("Unable to configure room %s", from); |
| 397 | ||
| 398 | gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); | |
| 399 | g_free(msg); | |
| 7923 | 400 | |
| 401 | } | |
| 402 | ||
| 403 | void jabber_chat_request_room_configure(JabberChat *chat) { | |
| 404 | JabberIq *iq; | |
| 405 | xmlnode *query; | |
| 406 | char *room_jid; | |
| 407 | ||
| 7895 | 408 | if(!chat) |
| 409 | return; | |
| 410 | ||
| 8396 | 411 | chat->config_dialog_handle = NULL; |
| 412 | ||
| 7955 | 413 | if(!chat->muc) { |
| 414 | gaim_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), | |
| 415 | _("This room is not capable of being configured")); | |
| 416 | return; | |
| 417 | } | |
| 418 | ||
| 10474 | 419 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
| 7923 | 420 | "http://jabber.org/protocol/muc#owner"); |
| 421 | query = xmlnode_get_child(iq->node, "query"); | |
| 422 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 7895 | 423 | |
| 7923 | 424 | xmlnode_set_attrib(iq->node, "to", room_jid); |
| 425 | ||
| 426 | jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
| 427 | ||
| 428 | jabber_iq_send(iq); | |
| 429 | ||
| 430 | g_free(room_jid); | |
| 7895 | 431 | } |
| 432 | ||
| 433 | void jabber_chat_create_instant_room(JabberChat *chat) { | |
| 434 | JabberIq *iq; | |
| 435 | xmlnode *query, *x; | |
| 436 | char *room_jid; | |
| 437 | ||
| 438 | if(!chat) | |
| 439 | return; | |
| 440 | ||
| 8396 | 441 | chat->config_dialog_handle = NULL; |
| 442 | ||
| 7895 | 443 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
| 444 | "http://jabber.org/protocol/muc#owner"); | |
| 445 | query = xmlnode_get_child(iq->node, "query"); | |
| 446 | x = xmlnode_new_child(query, "x"); | |
| 447 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 448 | ||
| 449 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 450 | xmlnode_set_attrib(x, "xmlns", "jabber:x:data"); | |
| 451 | xmlnode_set_attrib(x, "type", "submit"); | |
| 452 | ||
| 453 | jabber_iq_send(iq); | |
| 454 | ||
| 455 | g_free(room_jid); | |
| 456 | } | |
| 7955 | 457 | |
| 458 | static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 459 | { | |
| 460 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 461 | ||
| 462 | if(type && !strcmp(type, "error")) { | |
| 8401 | 463 | char *msg = jabber_parse_error(js, packet); |
| 464 | ||
| 465 | gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); | |
| 466 | ||
| 467 | if(msg) | |
| 468 | g_free(msg); | |
| 469 | return; | |
| 7955 | 470 | } |
| 471 | } | |
| 472 | ||
| 473 | static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 474 | { | |
| 475 | JabberChat *chat = data; | |
| 476 | xmlnode *query; | |
| 477 | JabberIq *iq; | |
| 478 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 479 | ||
| 480 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
| 481 | xmlnode_set_attrib(iq->node, "to", to); | |
| 482 | g_free(to); | |
| 483 | ||
| 484 | query = xmlnode_get_child(iq->node, "query"); | |
| 485 | ||
| 486 | xmlnode_insert_child(query, result); | |
| 487 | ||
| 488 | jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
| 489 | ||
| 490 | jabber_iq_send(iq); | |
| 491 | } | |
| 492 | ||
| 493 | static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 494 | { | |
| 495 | xmlnode *query, *x; | |
| 496 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 497 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 498 | char *msg; | |
| 499 | JabberChat *chat; | |
| 500 | JabberID *jid; | |
| 501 | ||
| 502 | if(!type || !from) | |
| 503 | return; | |
| 504 | ||
| 505 | if(!strcmp(type, "result")) { | |
| 506 | jid = jabber_id_new(from); | |
| 507 | ||
| 508 | if(!jid) | |
| 509 | return; | |
| 510 | ||
| 511 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 512 | jabber_id_free(jid); | |
| 513 | ||
| 514 | if(!chat) | |
| 515 | return; | |
| 516 | ||
| 517 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 518 | return; | |
| 519 | ||
| 8135 | 520 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7955 | 521 | const char *xmlns; |
| 522 | ||
| 523 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) | |
| 524 | continue; | |
| 525 | ||
| 526 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 527 | jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
| 528 | return; | |
| 529 | } | |
| 530 | } | |
| 531 | } else if(!strcmp(type, "error")) { | |
| 8401 | 532 | char *msg = jabber_parse_error(js, packet); |
| 7955 | 533 | |
| 534 | gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); | |
| 535 | ||
| 8401 | 536 | if(msg) |
| 537 | g_free(msg); | |
| 7955 | 538 | return; |
| 539 | } | |
| 540 | ||
| 541 | msg = g_strdup_printf("Unable to configure room %s", from); | |
| 542 | ||
| 543 | gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); | |
| 544 | g_free(msg); | |
| 545 | ||
| 546 | } | |
| 547 | ||
| 548 | void jabber_chat_register(JabberChat *chat) | |
| 549 | { | |
| 550 | JabberIq *iq; | |
| 551 | char *room_jid; | |
| 552 | ||
| 553 | if(!chat) | |
| 554 | return; | |
| 555 | ||
| 556 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 557 | ||
| 558 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
| 559 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 560 | g_free(room_jid); | |
| 561 | ||
| 562 | jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
| 563 | ||
| 564 | jabber_iq_send(iq); | |
| 565 | } | |
| 566 | ||
| 7971 | 567 | /* merge this with the function below when we get everyone on the same page wrt /commands */ |
| 568 | void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
| 569 | { | |
| 570 | if(topic && *topic) { | |
| 571 | JabberMessage *jm; | |
| 572 | jm = g_new0(JabberMessage, 1); | |
| 573 | jm->js = chat->js; | |
| 574 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 575 | jm->subject = gaim_markup_strip_html(topic); | |
| 576 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 577 | jabber_message_send(jm); | |
| 578 | jabber_message_free(jm); | |
| 579 | } else { | |
| 580 | const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv)); | |
| 9762 | 581 | char *buf, *tmp, *tmp2; |
| 7955 | 582 | |
| 9762 | 583 | if(cur) { |
| 584 | tmp = gaim_escape_html(cur); | |
| 585 | tmp2 = gaim_markup_linkify(tmp); | |
| 586 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); | |
| 587 | g_free(tmp); | |
| 588 | g_free(tmp2); | |
| 589 | } else | |
| 7971 | 590 | buf = g_strdup(_("No topic is set")); |
| 591 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf, | |
| 592 | GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL)); | |
| 593 | g_free(buf); | |
| 594 | } | |
| 595 | ||
| 596 | } | |
| 597 | ||
| 598 | void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic) | |
| 599 | { | |
| 600 | JabberStream *js = gc->proto_data; | |
| 601 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 602 | ||
| 603 | if(!chat) | |
| 604 | return; | |
| 605 | ||
| 606 | jabber_chat_change_topic(chat, topic); | |
| 607 | } | |
| 608 | ||
| 609 | ||
| 7972 | 610 | void jabber_chat_change_nick(JabberChat *chat, const char *nick) |
| 611 | { | |
| 612 | xmlnode *presence; | |
| 613 | char *full_jid; | |
| 9954 | 614 | GaimPresence *gpresence; |
| 615 | GaimStatus *status; | |
| 616 | JabberBuddyState state; | |
| 617 | const char *msg; | |
| 618 | int priority; | |
| 7972 | 619 | |
| 620 | if(!chat->muc) { | |
| 621 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", | |
| 622 | _("Nick changing not supported in non-MUC chatrooms"), | |
| 623 | GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 624 | return; | |
| 625 | } | |
| 626 | ||
| 9954 | 627 | gpresence = gaim_account_get_presence(chat->js->gc->account); |
| 628 | status = gaim_presence_get_active_status(gpresence); | |
| 629 | ||
| 630 | gaim_status_to_jabber(status, &state, &msg, &priority); | |
| 631 | ||
| 632 | presence = jabber_presence_create(state, msg, priority); | |
| 7972 | 633 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); |
| 634 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 635 | g_free(full_jid); | |
| 636 | ||
| 637 | jabber_send(chat->js, presence); | |
| 638 | xmlnode_free(presence); | |
| 639 | } | |
| 640 | ||
| 7974 | 641 | void jabber_chat_part(JabberChat *chat, const char *msg) |
| 642 | { | |
| 643 | char *room_jid; | |
| 644 | xmlnode *presence; | |
| 7972 | 645 | |
| 8537 | 646 | room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
| 647 | chat->handle); | |
| 7974 | 648 | presence = xmlnode_new("presence"); |
| 649 | xmlnode_set_attrib(presence, "to", room_jid); | |
| 650 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 651 | if(msg) { | |
| 652 | xmlnode *status = xmlnode_new_child(presence, "status"); | |
| 653 | xmlnode_insert_data(status, msg, -1); | |
| 654 | } | |
| 655 | jabber_send(chat->js, presence); | |
| 656 | xmlnode_free(presence); | |
| 657 | g_free(room_jid); | |
| 658 | } | |
| 659 | ||
| 8113 | 660 | static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 661 | { | |
| 662 | xmlnode *query; | |
| 663 | xmlnode *item; | |
| 664 | const char *type; | |
| 7974 | 665 | |
| 8113 | 666 | if(!js->roomlist) |
| 667 | return; | |
| 668 | ||
| 669 | if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) { | |
| 8401 | 670 | char *err = jabber_parse_error(js,packet); |
|
10091
aca1c1e0feda
[gaim-migrate @ 11107]
Mark Doliner <markdoliner@pidgin.im>
parents:
10045
diff
changeset
|
671 | gaim_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
672 | _("Error retrieving room list"), err); |
| 8113 | 673 | gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
| 8120 | 674 | gaim_roomlist_unref(js->roomlist); |
| 675 | js->roomlist = NULL; | |
| 8401 | 676 | g_free(err); |
| 8113 | 677 | return; |
| 678 | } | |
| 679 | ||
| 680 | if(!(query = xmlnode_get_child(packet, "query"))) { | |
| 8401 | 681 | char *err = jabber_parse_error(js, packet); |
|
10091
aca1c1e0feda
[gaim-migrate @ 11107]
Mark Doliner <markdoliner@pidgin.im>
parents:
10045
diff
changeset
|
682 | gaim_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
683 | _("Error retrieving room list"), err); |
| 8113 | 684 | gaim_roomlist_set_in_progress(js->roomlist, FALSE); |
| 8120 | 685 | gaim_roomlist_unref(js->roomlist); |
| 686 | js->roomlist = NULL; | |
| 8401 | 687 | g_free(err); |
| 8113 | 688 | return; |
| 689 | } | |
| 690 | ||
| 8135 | 691 | for(item = xmlnode_get_child(query, "item"); item; |
| 692 | item = xmlnode_get_next_twin(item)) { | |
| 8113 | 693 | const char *name; |
| 694 | GaimRoomlistRoom *room; | |
| 695 | JabberID *jid; | |
| 696 | ||
| 697 | if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
| 698 | continue; | |
| 699 | name = xmlnode_get_attrib(item, "name"); | |
| 700 | ||
| 701 | ||
| 702 | room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); | |
| 703 | gaim_roomlist_room_add_field(js->roomlist, room, jid->node); | |
| 704 | gaim_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
| 705 | gaim_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
| 706 | gaim_roomlist_room_add(js->roomlist, room); | |
| 707 | ||
| 708 | jabber_id_free(jid); | |
| 709 | } | |
| 710 | gaim_roomlist_set_in_progress(js->roomlist, FALSE); | |
| 711 | gaim_roomlist_unref(js->roomlist); | |
| 712 | js->roomlist = NULL; | |
| 713 | } | |
| 714 | ||
| 10045 | 715 | static void roomlist_cancel_cb(JabberStream *js, const char *server) { |
| 716 | if(js->roomlist) { | |
| 717 | gaim_roomlist_set_in_progress(js->roomlist, FALSE); | |
| 718 | gaim_roomlist_unref(js->roomlist); | |
| 719 | js->roomlist = NULL; | |
| 720 | } | |
| 721 | } | |
| 722 | ||
| 8113 | 723 | static void roomlist_ok_cb(JabberStream *js, const char *server) |
| 724 | { | |
| 725 | JabberIq *iq; | |
| 10045 | 726 | |
| 727 | if(!js->roomlist) | |
| 728 | return; | |
| 8113 | 729 | |
| 730 | if(!server || !*server) { | |
| 731 | gaim_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL); | |
| 732 | return; | |
| 733 | } | |
| 734 | ||
| 10045 | 735 | gaim_roomlist_set_in_progress(js->roomlist, TRUE); |
| 736 | ||
| 737 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
| 738 | ||
| 739 | xmlnode_set_attrib(iq->node, "to", server); | |
| 740 | ||
| 741 | jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
| 742 | ||
| 743 | jabber_iq_send(iq); | |
| 744 | } | |
| 745 | ||
| 746 | GaimRoomlist *jabber_roomlist_get_list(GaimConnection *gc) | |
| 747 | { | |
| 748 | JabberStream *js = gc->proto_data; | |
| 749 | GList *fields = NULL; | |
| 750 | GaimRoomlistField *f; | |
| 751 | ||
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
752 | if(js->roomlist) |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
753 | gaim_roomlist_unref(js->roomlist); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
754 | |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
755 | js->roomlist = gaim_roomlist_new(gaim_connection_get_account(js->gc)); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
756 | |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
757 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
758 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
759 | |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
760 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "server", TRUE); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
761 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
762 | |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
763 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
764 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
765 | |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
766 | gaim_roomlist_set_fields(js->roomlist, fields); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
767 | |
| 8113 | 768 | |
| 769 | gaim_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), | |
| 770 | _("Select a conference server to query"), | |
| 771 | js->chat_servers ? js->chat_servers->data : "conference.jabber.org", | |
| 8697 | 772 | FALSE, FALSE, NULL, |
| 10045 | 773 | _("Find Rooms"), GAIM_CALLBACK(roomlist_ok_cb), |
| 774 | _("Cancel"), GAIM_CALLBACK(roomlist_cancel_cb), js); | |
| 8113 | 775 | |
| 776 | return js->roomlist; | |
| 777 | } | |
| 778 | ||
| 779 | void jabber_roomlist_cancel(GaimRoomlist *list) | |
| 780 | { | |
| 781 | GaimConnection *gc; | |
| 782 | JabberStream *js; | |
| 783 | ||
| 784 | gc = gaim_account_get_connection(list->account); | |
| 785 | js = gc->proto_data; | |
| 786 | ||
| 787 | gaim_roomlist_set_in_progress(list, FALSE); | |
| 788 | ||
| 789 | if (js->roomlist == list) { | |
| 790 | js->roomlist = NULL; | |
| 791 | gaim_roomlist_unref(list); | |
| 792 | } | |
| 793 | } | |
| 794 | ||
| 9152 | 795 | void jabber_chat_member_free(JabberChatMember *jcm) |
| 796 | { | |
| 797 | g_free(jcm->handle); | |
| 798 | g_free(jcm->jid); | |
| 799 | g_free(jcm); | |
| 800 | } | |
| 801 | ||
| 802 | void jabber_chat_track_handle(JabberChat *chat, const char *handle, | |
| 803 | const char *jid, const char *affiliation, const char *role) | |
| 804 | { | |
| 805 | JabberChatMember *jcm = g_new0(JabberChatMember, 1); | |
| 806 | ||
| 807 | jcm->handle = g_strdup(handle); | |
| 808 | jcm->jid = g_strdup(jid); | |
| 809 | ||
| 810 | g_hash_table_replace(chat->members, jcm->handle, jcm); | |
| 811 | ||
| 812 | /* XXX: keep track of role and affiliation */ | |
| 813 | } | |
| 814 | ||
| 815 | void jabber_chat_remove_handle(JabberChat *chat, const char *handle) | |
| 816 | { | |
| 817 | g_hash_table_remove(chat->members, handle); | |
| 818 | } | |
| 819 | ||
| 820 | gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why) | |
| 821 | { | |
| 822 | JabberIq *iq; | |
| 823 | JabberChatMember *jcm = g_hash_table_lookup(chat->members, who); | |
| 824 | char *to; | |
| 825 | xmlnode *query, *item, *reason; | |
| 826 | ||
| 827 | if(!jcm || !jcm->jid) | |
| 828 | return FALSE; | |
| 829 | ||
| 830 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 831 | "http://jabber.org/protocol/muc#admin"); | |
| 832 | ||
| 833 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 834 | xmlnode_set_attrib(iq->node, "to", to); | |
| 835 | g_free(to); | |
| 836 | ||
| 837 | query = xmlnode_get_child(iq->node, "query"); | |
| 838 | item = xmlnode_new_child(query, "item"); | |
| 839 | xmlnode_set_attrib(item, "jid", jcm->jid); | |
| 840 | xmlnode_set_attrib(item, "affiliation", "outcast"); | |
| 841 | if(why) { | |
| 842 | reason = xmlnode_new_child(item, "reason"); | |
| 843 | xmlnode_insert_data(reason, why, -1); | |
| 844 | } | |
| 845 | ||
| 846 | jabber_iq_send(iq); | |
| 847 | ||
| 848 | return TRUE; | |
| 849 | } | |
| 8113 | 850 | |
| 851 | ||
| 9152 | 852 | gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why) |
| 853 | { | |
| 854 | JabberIq *iq; | |
| 855 | JabberChatMember *jcm = g_hash_table_lookup(chat->members, who); | |
| 856 | char *to; | |
| 857 | xmlnode *query, *item, *reason; | |
| 858 | ||
| 859 | if(!jcm || !jcm->jid) | |
| 860 | return FALSE; | |
| 861 | ||
| 862 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 863 | "http://jabber.org/protocol/muc#admin"); | |
| 864 | ||
| 865 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 866 | xmlnode_set_attrib(iq->node, "to", to); | |
| 867 | g_free(to); | |
| 868 | ||
| 869 | query = xmlnode_get_child(iq->node, "query"); | |
| 870 | item = xmlnode_new_child(query, "item"); | |
| 871 | xmlnode_set_attrib(item, "jid", jcm->jid); | |
| 872 | xmlnode_set_attrib(item, "role", "none"); | |
| 873 | if(why) { | |
| 874 | reason = xmlnode_new_child(item, "reason"); | |
| 875 | xmlnode_insert_data(reason, why, -1); | |
| 876 | } | |
| 877 | ||
| 878 | jabber_iq_send(iq); | |
| 879 | ||
| 880 | return TRUE; | |
| 881 | } | |
| 882 | ||
| 883 | ||
| 884 |