Wed, 10 Oct 2007 23:20:18 +0000
propagate from branch 'im.pidgin.pidgin' (head 5c9b034ab8cd309736e4832072c0ce69b75d0a55)
to branch 'org.maemo.garage.pidgin.pidgin.request-with-ui-hint' (head a1a29d2f9231932dfaff30e8ca5da694f5e3f5f7)
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19854
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 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 | |
| 15884 | 35 | GList *jabber_chat_info(PurpleConnection *gc) |
| 7014 | 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"; |
| 10959 | 43 | pce->required = TRUE; |
| 7014 | 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"; |
| 10959 | 49 | pce->required = TRUE; |
| 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"; |
| 10959 | 55 | pce->required = TRUE; |
| 7014 | 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 | ||
| 15884 | 67 | GHashTable *jabber_chat_info_defaults(PurpleConnection *gc, const char *chat_name) |
|
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 | GHashTable *defaults; |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
70 | JabberStream *js = gc->proto_data; |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
71 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
72 | 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
|
73 | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
74 | g_hash_table_insert(defaults, "handle", g_strdup(js->user->node)); |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
75 | |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
76 | if (js->chat_servers) |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
77 | 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
|
78 | |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
79 | if (chat_name != NULL) { |
| 9760 | 80 | JabberID *jid = jabber_id_new(chat_name); |
| 81 | if(jid) { | |
| 82 | g_hash_table_insert(defaults, "room", g_strdup(jid->node)); | |
| 83 | if(jid->domain) | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
84 | g_hash_table_replace(defaults, "server", g_strdup(jid->domain)); |
| 15185 | 85 | if(jid->resource) |
| 86 | g_hash_table_replace(defaults, "handle", g_strdup(jid->resource)); | |
| 9760 | 87 | jabber_id_free(jid); |
| 88 | } | |
|
9754
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 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
91 | return defaults; |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
92 | } |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
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
f52908fb23b0
[gaim-migrate @ 14627]
Richard Laager <rlaager@pidgin.im>
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 | ||
| 15884 | 136 | JabberChat *jabber_chat_find_by_conv(PurpleConversation *conv) |
| 9130 | 137 | { |
| 15884 | 138 | PurpleAccount *account = purple_conversation_get_account(conv); |
| 139 | PurpleConnection *gc = purple_account_get_connection(account); | |
| 9130 | 140 | JabberStream *js = gc->proto_data; |
| 15884 | 141 | int id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)); |
| 9130 | 142 | |
| 143 | return jabber_chat_find_by_id(js, id); | |
| 144 | } | |
| 145 | ||
| 15884 | 146 | void jabber_chat_invite(PurpleConnection *gc, int id, const char *msg, |
| 7014 | 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"); | |
| 13808 | 165 | xmlnode_set_namespace(x, "http://jabber.org/protocol/muc#user"); |
| 7014 | 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); | |
| 13808 | 176 | xmlnode_set_namespace(x, "jabber:x:conference"); |
| 7014 | 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
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
186 | char *jabber_get_chat_name(GHashTable *data) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
187 | char *room, *server, *chat_name = NULL; |
|
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 | room = g_hash_table_lookup(data, "room"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
190 | server = g_hash_table_lookup(data, "server"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
191 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
192 | if (room && server) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
193 | chat_name = g_strdup_printf("%s@%s", room, server); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
194 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
195 | return chat_name; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
196 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
197 | |
| 15884 | 198 | void jabber_chat_join(PurpleConnection *gc, GHashTable *data) |
| 7014 | 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; |
| 15884 | 205 | PurplePresence *gpresence; |
| 206 | PurpleStatus *status; | |
| 9954 | 207 | JabberBuddyState state; |
| 14525 | 208 | char *msg; |
| 9954 | 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); | |
| 15884 | 224 | purple_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), |
| 7310 | 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); | |
| 15884 | 230 | purple_notify_error(gc, _("Invalid Server Name"), |
| 7310 | 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); | |
| 15884 | 236 | purple_notify_error(gc, _("Invalid Room Handle"), |
| 7310 | 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 | ||
| 15884 | 259 | gpresence = purple_account_get_presence(gc->account); |
| 260 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 261 | |
| 15884 | 262 | purple_status_to_jabber(status, &state, &msg, &priority); |
| 9954 | 263 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17007
diff
changeset
|
264 | presence = jabber_presence_create_js(js, 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); | |
| 14525 | 268 | g_free(msg); |
| 7014 | 269 | |
| 270 | x = xmlnode_new_child(presence, "x"); | |
| 13808 | 271 | xmlnode_set_namespace(x, "http://jabber.org/protocol/muc"); |
| 7014 | 272 | |
| 273 | if(passwd && *passwd) { | |
| 274 | xmlnode *password = xmlnode_new_child(x, "password"); | |
| 275 | xmlnode_insert_data(password, passwd, -1); | |
| 276 | } | |
| 277 | ||
| 278 | jabber_send(js, presence); | |
| 279 | xmlnode_free(presence); | |
| 280 | } | |
| 281 | ||
| 15884 | 282 | void jabber_chat_leave(PurpleConnection *gc, int id) |
| 7014 | 283 | { |
| 284 | JabberStream *js = gc->proto_data; | |
| 285 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 7974 | 286 | |
| 7014 | 287 | |
| 288 | if(!chat) | |
| 289 | return; | |
| 290 | ||
| 7974 | 291 | jabber_chat_part(chat, NULL); |
| 9152 | 292 | |
| 293 | chat->conv = NULL; | |
| 7014 | 294 | } |
| 295 | ||
| 296 | void jabber_chat_destroy(JabberChat *chat) | |
| 297 | { | |
| 298 | JabberStream *js = chat->js; | |
| 299 | char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 300 | ||
| 7322 | 301 | g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 302 | g_free(room_jid); |
| 8396 | 303 | } |
| 304 | ||
| 305 | void jabber_chat_free(JabberChat *chat) | |
| 306 | { | |
| 307 | if(chat->config_dialog_handle) | |
| 15884 | 308 | purple_request_close(chat->config_dialog_type, chat->config_dialog_handle); |
| 7014 | 309 | |
| 310 | g_free(chat->room); | |
| 311 | g_free(chat->server); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
312 | g_free(chat->handle); |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
313 | g_hash_table_destroy(chat->members); |
| 7014 | 314 | g_free(chat); |
| 315 | } | |
| 316 | ||
| 15884 | 317 | gboolean jabber_chat_find_buddy(PurpleConversation *conv, const char *name) |
| 7014 | 318 | { |
| 15884 | 319 | return purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), name); |
| 7014 | 320 | } |
| 321 | ||
| 15884 | 322 | char *jabber_chat_buddy_real_name(PurpleConnection *gc, int id, const char *who) |
| 7398 | 323 | { |
| 324 | JabberStream *js = gc->proto_data; | |
| 325 | JabberChat *chat; | |
| 326 | ||
| 327 | chat = jabber_chat_find_by_id(js, id); | |
| 328 | ||
| 329 | if(!chat) | |
| 330 | return NULL; | |
| 331 | ||
| 332 | return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); | |
| 333 | } | |
| 7895 | 334 | |
| 7923 | 335 | static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
| 336 | { | |
| 337 | JabberChat *chat = data; | |
| 338 | xmlnode *query; | |
| 339 | JabberIq *iq; | |
| 340 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 341 | ||
| 342 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
| 343 | xmlnode_set_attrib(iq->node, "to", to); | |
| 344 | g_free(to); | |
| 345 | ||
| 346 | query = xmlnode_get_child(iq->node, "query"); | |
| 347 | ||
| 348 | xmlnode_insert_child(query, result); | |
| 349 | ||
| 350 | jabber_iq_send(iq); | |
| 351 | } | |
| 352 | ||
| 353 | static void jabber_chat_room_configure_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 354 | { | |
| 355 | xmlnode *query, *x; | |
| 356 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 357 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 7926 | 358 | char *msg; |
| 7923 | 359 | JabberChat *chat; |
| 360 | JabberID *jid; | |
| 361 | ||
| 362 | if(!type || !from) | |
| 363 | return; | |
| 364 | ||
| 365 | ||
| 7926 | 366 | |
| 7923 | 367 | if(!strcmp(type, "result")) { |
| 368 | jid = jabber_id_new(from); | |
| 369 | ||
| 370 | if(!jid) | |
| 371 | return; | |
| 372 | ||
| 373 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 374 | jabber_id_free(jid); | |
| 375 | ||
| 376 | if(!chat) | |
| 377 | return; | |
| 378 | ||
| 379 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 380 | return; | |
| 381 | ||
| 8135 | 382 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7923 | 383 | const char *xmlns; |
| 13808 | 384 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7923 | 385 | continue; |
| 386 | ||
| 387 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 15884 | 388 | chat->config_dialog_type = PURPLE_REQUEST_FIELDS; |
| 8396 | 389 | chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); |
| 7923 | 390 | return; |
| 391 | } | |
| 392 | } | |
| 7926 | 393 | } else if(!strcmp(type, "error")) { |
| 8401 | 394 | char *msg = jabber_parse_error(js, packet); |
| 7926 | 395 | |
| 15884 | 396 | purple_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); |
| 7926 | 397 | |
| 8401 | 398 | if(msg) |
| 399 | g_free(msg); | |
| 7926 | 400 | return; |
| 7923 | 401 | } |
| 402 | ||
| 7926 | 403 | msg = g_strdup_printf("Unable to configure room %s", from); |
| 404 | ||
| 15884 | 405 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7926 | 406 | g_free(msg); |
| 7923 | 407 | |
| 408 | } | |
| 409 | ||
| 410 | void jabber_chat_request_room_configure(JabberChat *chat) { | |
| 411 | JabberIq *iq; | |
| 412 | char *room_jid; | |
| 413 | ||
| 7895 | 414 | if(!chat) |
| 415 | return; | |
| 416 | ||
| 8396 | 417 | chat->config_dialog_handle = NULL; |
| 418 | ||
| 7955 | 419 | if(!chat->muc) { |
| 15884 | 420 | purple_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), |
| 7955 | 421 | _("This room is not capable of being configured")); |
| 422 | return; | |
| 423 | } | |
| 424 | ||
| 10474 | 425 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
| 7923 | 426 | "http://jabber.org/protocol/muc#owner"); |
| 427 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 7895 | 428 | |
| 7923 | 429 | xmlnode_set_attrib(iq->node, "to", room_jid); |
| 430 | ||
| 431 | jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
| 432 | ||
| 433 | jabber_iq_send(iq); | |
| 434 | ||
| 435 | g_free(room_jid); | |
| 7895 | 436 | } |
| 437 | ||
| 438 | void jabber_chat_create_instant_room(JabberChat *chat) { | |
| 439 | JabberIq *iq; | |
| 440 | xmlnode *query, *x; | |
| 441 | char *room_jid; | |
| 442 | ||
| 443 | if(!chat) | |
| 444 | return; | |
| 445 | ||
| 8396 | 446 | chat->config_dialog_handle = NULL; |
| 447 | ||
| 7895 | 448 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
| 449 | "http://jabber.org/protocol/muc#owner"); | |
| 450 | query = xmlnode_get_child(iq->node, "query"); | |
| 451 | x = xmlnode_new_child(query, "x"); | |
| 452 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 453 | ||
| 454 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 13808 | 455 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 7895 | 456 | xmlnode_set_attrib(x, "type", "submit"); |
| 457 | ||
| 458 | jabber_iq_send(iq); | |
| 459 | ||
| 460 | g_free(room_jid); | |
| 461 | } | |
| 7955 | 462 | |
| 463 | static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 464 | { | |
| 465 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 466 | ||
| 467 | if(type && !strcmp(type, "error")) { | |
| 8401 | 468 | char *msg = jabber_parse_error(js, packet); |
| 469 | ||
| 15884 | 470 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 8401 | 471 | |
| 472 | if(msg) | |
| 473 | g_free(msg); | |
| 474 | return; | |
| 7955 | 475 | } |
| 476 | } | |
| 477 | ||
| 478 | static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 479 | { | |
| 480 | JabberChat *chat = data; | |
| 481 | xmlnode *query; | |
| 482 | JabberIq *iq; | |
| 483 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 484 | ||
| 485 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
| 486 | xmlnode_set_attrib(iq->node, "to", to); | |
| 487 | g_free(to); | |
| 488 | ||
| 489 | query = xmlnode_get_child(iq->node, "query"); | |
| 490 | ||
| 491 | xmlnode_insert_child(query, result); | |
| 492 | ||
| 493 | jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
| 494 | ||
| 495 | jabber_iq_send(iq); | |
| 496 | } | |
| 497 | ||
| 498 | static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 499 | { | |
| 500 | xmlnode *query, *x; | |
| 501 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 502 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 503 | char *msg; | |
| 504 | JabberChat *chat; | |
| 505 | JabberID *jid; | |
| 506 | ||
| 507 | if(!type || !from) | |
| 508 | return; | |
| 509 | ||
| 510 | if(!strcmp(type, "result")) { | |
| 511 | jid = jabber_id_new(from); | |
| 512 | ||
| 513 | if(!jid) | |
| 514 | return; | |
| 515 | ||
| 516 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 517 | jabber_id_free(jid); | |
| 518 | ||
| 519 | if(!chat) | |
| 520 | return; | |
| 521 | ||
| 522 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 523 | return; | |
| 524 | ||
| 8135 | 525 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7955 | 526 | const char *xmlns; |
| 527 | ||
| 13808 | 528 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7955 | 529 | continue; |
| 530 | ||
| 531 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 532 | jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
| 533 | return; | |
| 534 | } | |
| 535 | } | |
| 536 | } else if(!strcmp(type, "error")) { | |
| 8401 | 537 | char *msg = jabber_parse_error(js, packet); |
| 7955 | 538 | |
| 15884 | 539 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 7955 | 540 | |
| 8401 | 541 | if(msg) |
| 542 | g_free(msg); | |
| 7955 | 543 | return; |
| 544 | } | |
| 545 | ||
| 546 | msg = g_strdup_printf("Unable to configure room %s", from); | |
| 547 | ||
| 15884 | 548 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7955 | 549 | g_free(msg); |
| 550 | ||
| 551 | } | |
| 552 | ||
| 553 | void jabber_chat_register(JabberChat *chat) | |
| 554 | { | |
| 555 | JabberIq *iq; | |
| 556 | char *room_jid; | |
| 557 | ||
| 558 | if(!chat) | |
| 559 | return; | |
| 560 | ||
| 561 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 562 | ||
| 563 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
| 564 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 565 | g_free(room_jid); | |
| 566 | ||
| 567 | jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
| 568 | ||
| 569 | jabber_iq_send(iq); | |
| 570 | } | |
| 571 | ||
| 7971 | 572 | /* merge this with the function below when we get everyone on the same page wrt /commands */ |
| 573 | void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
| 574 | { | |
| 575 | if(topic && *topic) { | |
| 576 | JabberMessage *jm; | |
| 577 | jm = g_new0(JabberMessage, 1); | |
| 578 | jm->js = chat->js; | |
| 579 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 15884 | 580 | jm->subject = purple_markup_strip_html(topic); |
| 7971 | 581 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 582 | jabber_message_send(jm); | |
| 583 | jabber_message_free(jm); | |
| 584 | } else { | |
| 15884 | 585 | const char *cur = purple_conv_chat_get_topic(PURPLE_CONV_CHAT(chat->conv)); |
| 9762 | 586 | char *buf, *tmp, *tmp2; |
| 7955 | 587 | |
| 9762 | 588 | if(cur) { |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
589 | tmp = g_markup_escape_text(cur, -1); |
| 15884 | 590 | tmp2 = purple_markup_linkify(tmp); |
| 9762 | 591 | buf = g_strdup_printf(_("current topic is: %s"), tmp2); |
| 592 | g_free(tmp); | |
| 593 | g_free(tmp2); | |
| 594 | } else | |
| 7971 | 595 | buf = g_strdup(_("No topic is set")); |
| 15884 | 596 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf, |
| 597 | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
| 7971 | 598 | g_free(buf); |
| 599 | } | |
| 600 | ||
| 601 | } | |
| 602 | ||
| 15884 | 603 | void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic) |
| 7971 | 604 | { |
| 605 | JabberStream *js = gc->proto_data; | |
| 606 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 607 | ||
| 608 | if(!chat) | |
| 609 | return; | |
| 610 | ||
| 611 | jabber_chat_change_topic(chat, topic); | |
| 612 | } | |
| 613 | ||
| 614 | ||
| 7972 | 615 | void jabber_chat_change_nick(JabberChat *chat, const char *nick) |
| 616 | { | |
| 617 | xmlnode *presence; | |
| 618 | char *full_jid; | |
| 15884 | 619 | PurplePresence *gpresence; |
| 620 | PurpleStatus *status; | |
| 9954 | 621 | JabberBuddyState state; |
| 14525 | 622 | char *msg; |
| 9954 | 623 | int priority; |
| 7972 | 624 | |
| 625 | if(!chat->muc) { | |
| 15884 | 626 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7972 | 627 | _("Nick changing not supported in non-MUC chatrooms"), |
| 15884 | 628 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 7972 | 629 | return; |
| 630 | } | |
| 631 | ||
| 15884 | 632 | gpresence = purple_account_get_presence(chat->js->gc->account); |
| 633 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 634 | |
| 15884 | 635 | purple_status_to_jabber(status, &state, &msg, &priority); |
| 9954 | 636 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17007
diff
changeset
|
637 | presence = jabber_presence_create_js(chat->js, state, msg, priority); |
| 7972 | 638 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); |
| 639 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 640 | g_free(full_jid); | |
| 14525 | 641 | g_free(msg); |
| 7972 | 642 | |
| 643 | jabber_send(chat->js, presence); | |
| 644 | xmlnode_free(presence); | |
| 645 | } | |
| 646 | ||
| 7974 | 647 | void jabber_chat_part(JabberChat *chat, const char *msg) |
| 648 | { | |
| 649 | char *room_jid; | |
| 650 | xmlnode *presence; | |
| 7972 | 651 | |
| 8537 | 652 | room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
| 653 | chat->handle); | |
| 7974 | 654 | presence = xmlnode_new("presence"); |
| 655 | xmlnode_set_attrib(presence, "to", room_jid); | |
| 656 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 657 | if(msg) { | |
| 658 | xmlnode *status = xmlnode_new_child(presence, "status"); | |
| 659 | xmlnode_insert_data(status, msg, -1); | |
| 660 | } | |
| 661 | jabber_send(chat->js, presence); | |
| 662 | xmlnode_free(presence); | |
| 663 | g_free(room_jid); | |
| 664 | } | |
| 665 | ||
| 8113 | 666 | static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 667 | { | |
| 668 | xmlnode *query; | |
| 669 | xmlnode *item; | |
| 670 | const char *type; | |
| 7974 | 671 | |
| 8113 | 672 | if(!js->roomlist) |
| 673 | return; | |
| 674 | ||
| 675 | if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) { | |
| 8401 | 676 | char *err = jabber_parse_error(js,packet); |
| 15884 | 677 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
678 | _("Error retrieving room list"), err); |
| 15884 | 679 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 680 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 681 | js->roomlist = NULL; |
| 8401 | 682 | g_free(err); |
| 8113 | 683 | return; |
| 684 | } | |
| 685 | ||
| 686 | if(!(query = xmlnode_get_child(packet, "query"))) { | |
| 8401 | 687 | char *err = jabber_parse_error(js, packet); |
| 15884 | 688 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
689 | _("Error retrieving room list"), err); |
| 15884 | 690 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 691 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 692 | js->roomlist = NULL; |
| 8401 | 693 | g_free(err); |
| 8113 | 694 | return; |
| 695 | } | |
| 696 | ||
| 8135 | 697 | for(item = xmlnode_get_child(query, "item"); item; |
| 698 | item = xmlnode_get_next_twin(item)) { | |
| 8113 | 699 | const char *name; |
| 15884 | 700 | PurpleRoomlistRoom *room; |
| 8113 | 701 | JabberID *jid; |
| 702 | ||
| 703 | if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
| 704 | continue; | |
| 705 | name = xmlnode_get_attrib(item, "name"); | |
| 706 | ||
| 707 | ||
| 15884 | 708 | room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); |
| 709 | purple_roomlist_room_add_field(js->roomlist, room, jid->node); | |
| 710 | purple_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
| 711 | purple_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
| 712 | purple_roomlist_room_add(js->roomlist, room); | |
| 8113 | 713 | |
| 714 | jabber_id_free(jid); | |
| 715 | } | |
| 15884 | 716 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 717 | purple_roomlist_unref(js->roomlist); | |
| 8113 | 718 | js->roomlist = NULL; |
| 719 | } | |
| 720 | ||
| 10045 | 721 | static void roomlist_cancel_cb(JabberStream *js, const char *server) { |
| 722 | if(js->roomlist) { | |
| 15884 | 723 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 724 | purple_roomlist_unref(js->roomlist); | |
| 10045 | 725 | js->roomlist = NULL; |
| 726 | } | |
| 727 | } | |
| 728 | ||
| 8113 | 729 | static void roomlist_ok_cb(JabberStream *js, const char *server) |
| 730 | { | |
| 731 | JabberIq *iq; | |
| 10045 | 732 | |
| 733 | if(!js->roomlist) | |
| 734 | return; | |
| 8113 | 735 | |
| 736 | if(!server || !*server) { | |
| 15884 | 737 | purple_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL); |
| 8113 | 738 | return; |
| 739 | } | |
| 740 | ||
| 15884 | 741 | purple_roomlist_set_in_progress(js->roomlist, TRUE); |
| 10045 | 742 | |
| 743 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
| 744 | ||
| 745 | xmlnode_set_attrib(iq->node, "to", server); | |
| 746 | ||
| 747 | jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
| 748 | ||
| 749 | jabber_iq_send(iq); | |
| 750 | } | |
| 751 | ||
| 15884 | 752 | char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room) |
| 15185 | 753 | { |
| 754 | ||
| 755 | return g_strdup_printf("%s@%s", (char*)room->fields->data, (char*)room->fields->next->data); | |
| 756 | } | |
| 757 | ||
| 15884 | 758 | PurpleRoomlist *jabber_roomlist_get_list(PurpleConnection *gc) |
| 10045 | 759 | { |
| 760 | JabberStream *js = gc->proto_data; | |
| 761 | GList *fields = NULL; | |
| 15884 | 762 | PurpleRoomlistField *f; |
| 10045 | 763 | |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
764 | if(js->roomlist) |
| 15884 | 765 | purple_roomlist_unref(js->roomlist); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
766 | |
| 15884 | 767 | js->roomlist = purple_roomlist_new(purple_connection_get_account(js->gc)); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
768 | |
| 15884 | 769 | f = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, "", "room", TRUE); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
770 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
771 | |
| 15884 | 772 | f = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, "", "server", TRUE); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
773 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
774 | |
| 15884 | 775 | f = purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
776 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
777 | |
| 15884 | 778 | purple_roomlist_set_fields(js->roomlist, fields); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
779 | |
| 8113 | 780 | |
|
20685
039aef89faf6
Updated hinting to be less invasive
Gabriel Schulhof <nix@go-nix.ca>
parents:
19997
diff
changeset
|
781 | purple_request_input_with_hint(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), |
| 8113 | 782 | _("Select a conference server to query"), |
|
17007
66c0fa6e5e2a
Removes 'jabber.org' defaults from XMPP. I think we had agreed this was a good idea.
Sean Egan <seanegan@pidgin.im>
parents:
16490
diff
changeset
|
783 | js->chat_servers ? js->chat_servers->data : NULL, |
| 8697 | 784 | FALSE, FALSE, NULL, |
| 15884 | 785 | _("Find Rooms"), PURPLE_CALLBACK(roomlist_ok_cb), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
786 | _("Cancel"), PURPLE_CALLBACK(roomlist_cancel_cb), |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
787 | purple_connection_get_account(gc), NULL, NULL, |
|
19259
a8adc0b18ee2
Added hints to jabber chat.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
17007
diff
changeset
|
788 | "chat", js); |
| 8113 | 789 | |
| 790 | return js->roomlist; | |
| 791 | } | |
| 792 | ||
| 15884 | 793 | void jabber_roomlist_cancel(PurpleRoomlist *list) |
| 8113 | 794 | { |
| 15884 | 795 | PurpleConnection *gc; |
| 8113 | 796 | JabberStream *js; |
| 797 | ||
| 15884 | 798 | gc = purple_account_get_connection(list->account); |
| 8113 | 799 | js = gc->proto_data; |
| 800 | ||
| 15884 | 801 | purple_roomlist_set_in_progress(list, FALSE); |
| 8113 | 802 | |
| 803 | if (js->roomlist == list) { | |
| 804 | js->roomlist = NULL; | |
| 15884 | 805 | purple_roomlist_unref(list); |
| 8113 | 806 | } |
| 807 | } | |
| 808 | ||
| 9152 | 809 | void jabber_chat_member_free(JabberChatMember *jcm) |
| 810 | { | |
| 811 | g_free(jcm->handle); | |
| 812 | g_free(jcm->jid); | |
| 813 | g_free(jcm); | |
| 814 | } | |
| 815 | ||
| 816 | void jabber_chat_track_handle(JabberChat *chat, const char *handle, | |
| 817 | const char *jid, const char *affiliation, const char *role) | |
| 818 | { | |
| 819 | JabberChatMember *jcm = g_new0(JabberChatMember, 1); | |
| 820 | ||
| 821 | jcm->handle = g_strdup(handle); | |
| 822 | jcm->jid = g_strdup(jid); | |
| 823 | ||
| 824 | g_hash_table_replace(chat->members, jcm->handle, jcm); | |
| 825 | ||
| 826 | /* XXX: keep track of role and affiliation */ | |
| 827 | } | |
| 828 | ||
| 829 | void jabber_chat_remove_handle(JabberChat *chat, const char *handle) | |
| 830 | { | |
| 831 | g_hash_table_remove(chat->members, handle); | |
| 832 | } | |
| 833 | ||
| 834 | gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why) | |
| 835 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
836 | JabberChatMember *jcm; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
837 | const char *jid; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
838 | char *to; |
| 9152 | 839 | JabberIq *iq; |
| 840 | xmlnode *query, *item, *reason; | |
| 841 | ||
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
842 | jcm = g_hash_table_lookup(chat->members, who); |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
843 | if (jcm && jcm->jid) |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
844 | jid = jcm->jid; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
845 | else if (g_utf8_strchr(who, -1, '@') != NULL) |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
846 | jid = who; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
847 | else |
| 9152 | 848 | return FALSE; |
| 849 | ||
| 850 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 851 | "http://jabber.org/protocol/muc#admin"); | |
| 852 | ||
| 853 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 854 | xmlnode_set_attrib(iq->node, "to", to); | |
| 855 | g_free(to); | |
| 856 | ||
| 857 | query = xmlnode_get_child(iq->node, "query"); | |
| 858 | item = xmlnode_new_child(query, "item"); | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
859 | xmlnode_set_attrib(item, "jid", jid); |
| 9152 | 860 | xmlnode_set_attrib(item, "affiliation", "outcast"); |
| 861 | if(why) { | |
| 862 | reason = xmlnode_new_child(item, "reason"); | |
| 863 | xmlnode_insert_data(reason, why, -1); | |
| 864 | } | |
| 865 | ||
| 866 | jabber_iq_send(iq); | |
| 867 | ||
| 868 | return TRUE; | |
| 869 | } | |
| 8113 | 870 | |
| 11393 | 871 | gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation) |
| 872 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
873 | JabberChatMember *jcm; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
874 | const char *jid; |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
875 | char *to; |
| 11393 | 876 | JabberIq *iq; |
| 877 | xmlnode *query, *item; | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
878 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
879 | jcm = g_hash_table_lookup(chat->members, who); |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
880 | if (jcm && jcm->jid) |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
881 | jid = jcm->jid; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
882 | else if (g_utf8_strchr(who, -1, '@') != NULL) |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
883 | jid = who; |
|
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
884 | else |
| 11393 | 885 | return FALSE; |
| 886 | ||
| 887 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 888 | "http://jabber.org/protocol/muc#admin"); | |
| 889 | ||
| 890 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 891 | xmlnode_set_attrib(iq->node, "to", to); | |
| 892 | g_free(to); | |
| 893 | ||
| 894 | query = xmlnode_get_child(iq->node, "query"); | |
| 895 | item = xmlnode_new_child(query, "item"); | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
896 | xmlnode_set_attrib(item, "jid", jid); |
| 11393 | 897 | xmlnode_set_attrib(item, "affiliation", affiliation); |
| 898 | ||
| 899 | jabber_iq_send(iq); | |
| 900 | ||
| 901 | return TRUE; | |
| 902 | } | |
| 8113 | 903 | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
904 | gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role) |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
905 | { |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
906 | char *to; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
907 | JabberIq *iq; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
908 | xmlnode *query, *item; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
909 | JabberChatMember *jcm; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
910 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
911 | jcm = g_hash_table_lookup(chat->members, who); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
912 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
913 | if (!jcm || !jcm->handle) |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
914 | return FALSE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
915 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
916 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
917 | "http://jabber.org/protocol/muc#admin"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
918 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
919 | to = g_strdup_printf("%s@%s", chat->room, chat->server); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
920 | xmlnode_set_attrib(iq->node, "to", to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
921 | g_free(to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
922 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
923 | query = xmlnode_get_child(iq->node, "query"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
924 | item = xmlnode_new_child(query, "item"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
925 | xmlnode_set_attrib(item, "nick", jcm->handle); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
926 | xmlnode_set_attrib(item, "role", role); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
927 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
928 | jabber_iq_send(iq); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
929 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
930 | return TRUE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
931 | } |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
932 | |
| 9152 | 933 | gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why) |
| 934 | { | |
| 935 | JabberIq *iq; | |
| 936 | JabberChatMember *jcm = g_hash_table_lookup(chat->members, who); | |
| 937 | char *to; | |
| 938 | xmlnode *query, *item, *reason; | |
| 939 | ||
| 940 | if(!jcm || !jcm->jid) | |
| 941 | return FALSE; | |
| 942 | ||
| 943 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 944 | "http://jabber.org/protocol/muc#admin"); | |
| 945 | ||
| 946 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 947 | xmlnode_set_attrib(iq->node, "to", to); | |
| 948 | g_free(to); | |
| 949 | ||
| 950 | query = xmlnode_get_child(iq->node, "query"); | |
| 951 | item = xmlnode_new_child(query, "item"); | |
| 952 | xmlnode_set_attrib(item, "jid", jcm->jid); | |
| 953 | xmlnode_set_attrib(item, "role", "none"); | |
| 954 | if(why) { | |
| 955 | reason = xmlnode_new_child(item, "reason"); | |
| 956 | xmlnode_insert_data(reason, why, -1); | |
| 957 | } | |
| 958 | ||
| 959 | jabber_iq_send(iq); | |
| 960 | ||
| 961 | return TRUE; | |
| 962 | } | |
| 963 | ||
| 10941 | 964 | static void jabber_chat_disco_traffic_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 965 | { | |
| 966 | JabberChat *chat; | |
|
20927
65bb21157e8f
Fully comment out some disabled code to prevent CID 180.
Daniel Atallah <datallah@pidgin.im>
parents:
19897
diff
changeset
|
967 | /*xmlnode *query;*/ |
| 10941 | 968 | int id = GPOINTER_TO_INT(data); |
| 969 | ||
| 970 | if(!(chat = jabber_chat_find_by_id(js, id))) | |
| 971 | return; | |
| 972 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
973 | /* defaults, in case the conference server doesn't |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
974 | * support this request */ |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
975 | chat->xhtml = TRUE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
976 | |
|
20927
65bb21157e8f
Fully comment out some disabled code to prevent CID 180.
Daniel Atallah <datallah@pidgin.im>
parents:
19897
diff
changeset
|
977 | /* disabling this until more MUC servers support |
|
65bb21157e8f
Fully comment out some disabled code to prevent CID 180.
Daniel Atallah <datallah@pidgin.im>
parents:
19897
diff
changeset
|
978 | * announcing this |
|
13713
1ae8790174a4
[gaim-migrate @ 16115]
Richard Laager <rlaager@pidgin.im>
parents:
13238
diff
changeset
|
979 | if(xmlnode_get_child(packet, "error")) { |
| 10941 | 980 | return; |
| 981 | } | |
| 982 | ||
| 983 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 984 | return; | |
| 985 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
986 | chat->xhtml = FALSE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
987 | |
| 10941 | 988 | for(x = xmlnode_get_child(query, "feature"); x; x = xmlnode_get_next_twin(x)) { |
| 989 | const char *var = xmlnode_get_attrib(x, "var"); | |
| 990 | ||
| 991 | if(var && !strcmp(var, "http://jabber.org/protocol/xhtml-im")) { | |
| 992 | chat->xhtml = TRUE; | |
| 993 | } | |
| 994 | } | |
| 15157 | 995 | */ |
| 10941 | 996 | } |
| 997 | ||
| 998 | void jabber_chat_disco_traffic(JabberChat *chat) | |
| 999 | { | |
| 1000 | JabberIq *iq; | |
| 1001 | xmlnode *query; | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1002 | char *room_jid; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1003 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1004 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 10941 | 1005 | |
| 1006 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, | |
| 1007 | "http://jabber.org/protocol/disco#info"); | |
| 1008 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1009 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1010 | |
| 10941 | 1011 | query = xmlnode_get_child(iq->node, "query"); |
| 1012 | ||
| 1013 | xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/muc#traffic"); | |
| 1014 | ||
| 1015 | jabber_iq_set_callback(iq, jabber_chat_disco_traffic_cb, GINT_TO_POINTER(chat->id)); | |
| 1016 | ||
| 1017 | jabber_iq_send(iq); | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1018 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1019 | g_free(room_jid); |
| 10941 | 1020 | } |
| 9152 | 1021 | |
| 1022 | ||
| 10941 | 1023 |