Sun, 22 Nov 2009 21:13:20 +0000
Documented chat API. References #10605
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
|
28322
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28158
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28158
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28158
diff
changeset
|
6 | * source distribution. |
| 7014 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * 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
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 21 | * |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | #include "debug.h" | |
|
9713
bb37562302a1
[gaim-migrate @ 10574]
Mark Doliner <markdoliner@pidgin.im>
parents:
9554
diff
changeset
|
25 | #include "prpl.h" /* for proto_chat_entry */ |
| 7310 | 26 | #include "notify.h" |
| 8113 | 27 | #include "request.h" |
| 28 | #include "roomlist.h" | |
| 7971 | 29 | #include "util.h" |
| 7014 | 30 | |
| 31 | #include "chat.h" | |
| 7895 | 32 | #include "iq.h" |
| 7014 | 33 | #include "message.h" |
| 7073 | 34 | #include "presence.h" |
| 7923 | 35 | #include "xdata.h" |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23403
diff
changeset
|
36 | #include "data.h" |
| 7014 | 37 | |
| 15884 | 38 | GList *jabber_chat_info(PurpleConnection *gc) |
| 7014 | 39 | { |
| 40 | GList *m = NULL; | |
| 41 | struct proto_chat_entry *pce; | |
| 42 | ||
| 43 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
44 | pce->label = _("_Room:"); |
| 7014 | 45 | pce->identifier = "room"; |
| 10959 | 46 | pce->required = TRUE; |
| 7014 | 47 | m = g_list_append(m, pce); |
| 48 | ||
| 49 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
50 | pce->label = _("_Server:"); |
| 7014 | 51 | pce->identifier = "server"; |
| 10959 | 52 | pce->required = TRUE; |
| 7014 | 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 = _("_Handle:"); |
| 7014 | 57 | pce->identifier = "handle"; |
| 10959 | 58 | pce->required = TRUE; |
| 7014 | 59 | m = g_list_append(m, pce); |
| 60 | ||
| 61 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7400
diff
changeset
|
62 | pce->label = _("_Password:"); |
| 7014 | 63 | pce->identifier = "password"; |
| 64 | pce->secret = TRUE; | |
| 65 | m = g_list_append(m, pce); | |
| 66 | ||
| 67 | return m; | |
| 68 | } | |
| 69 | ||
| 15884 | 70 | 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
|
71 | { |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
72 | GHashTable *defaults; |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
73 | JabberStream *js = gc->proto_data; |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
74 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
75 | 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
|
76 | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
77 | g_hash_table_insert(defaults, "handle", g_strdup(js->user->node)); |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
78 | |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
79 | if (js->chat_servers) |
|
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
80 | 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
|
81 | |
|
9754
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
82 | if (chat_name != NULL) { |
| 9760 | 83 | JabberID *jid = jabber_id_new(chat_name); |
| 84 | if(jid) { | |
| 85 | g_hash_table_insert(defaults, "room", g_strdup(jid->node)); | |
| 86 | if(jid->domain) | |
|
9770
d61fe8dcb6d9
[gaim-migrate @ 10638]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9762
diff
changeset
|
87 | g_hash_table_replace(defaults, "server", g_strdup(jid->domain)); |
| 15185 | 88 | if(jid->resource) |
| 89 | g_hash_table_replace(defaults, "handle", g_strdup(jid->resource)); | |
| 9760 | 90 | jabber_id_free(jid); |
| 91 | } | |
|
9754
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 | |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
94 | return defaults; |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
95 | } |
|
3a17eee239b2
[gaim-migrate @ 10621]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9713
diff
changeset
|
96 | |
| 7014 | 97 | JabberChat *jabber_chat_find(JabberStream *js, const char *room, |
| 98 | const char *server) | |
| 99 | { | |
| 10607 | 100 | JabberChat *chat = NULL; |
| 7014 | 101 | |
|
28584
1226297d1ba9
jabber: Don't crash when adding a buddy without a node (no '@'). Closes #10261.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
102 | g_return_val_if_fail(room != NULL, NULL); |
|
1226297d1ba9
jabber: Don't crash when adding a buddy without a node (no '@'). Closes #10261.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
103 | g_return_val_if_fail(server != NULL, NULL); |
|
1226297d1ba9
jabber: Don't crash when adding a buddy without a node (no '@'). Closes #10261.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
104 | |
| 10607 | 105 | if(NULL != js->chats) |
| 106 | { | |
|
23130
7193be04646f
Close up scope of a variable, I'm just cleaning up my tree some.
Etan Reisner <deryni@pidgin.im>
parents:
22919
diff
changeset
|
107 | char *room_jid = g_strdup_printf("%s@%s", room, server); |
| 7014 | 108 | |
| 10607 | 109 | chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid)); |
| 110 | g_free(room_jid); | |
| 111 | } | |
| 7014 | 112 | |
| 113 | return chat; | |
| 114 | } | |
| 115 | ||
| 116 | struct _find_by_id_data { | |
| 117 | int id; | |
| 118 | JabberChat *chat; | |
| 119 | }; | |
| 120 | ||
|
12323
f52908fb23b0
[gaim-migrate @ 14627]
Richard Laager <rlaager@pidgin.im>
parents:
11393
diff
changeset
|
121 | static void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data) |
| 7014 | 122 | { |
| 123 | JabberChat *chat = value; | |
| 124 | struct _find_by_id_data *fbid = user_data; | |
| 125 | ||
| 126 | if(chat->id == fbid->id) | |
| 127 | fbid->chat = chat; | |
| 128 | } | |
| 129 | ||
| 130 | JabberChat *jabber_chat_find_by_id(JabberStream *js, int id) | |
| 131 | { | |
| 132 | JabberChat *chat; | |
| 133 | struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1); | |
| 7073 | 134 | fbid->id = id; |
| 7014 | 135 | g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid); |
| 136 | chat = fbid->chat; | |
| 137 | g_free(fbid); | |
| 138 | return chat; | |
| 139 | } | |
| 140 | ||
| 15884 | 141 | JabberChat *jabber_chat_find_by_conv(PurpleConversation *conv) |
| 9130 | 142 | { |
| 15884 | 143 | PurpleAccount *account = purple_conversation_get_account(conv); |
| 144 | PurpleConnection *gc = purple_account_get_connection(account); | |
|
22804
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
145 | JabberStream *js; |
|
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
146 | int id; |
|
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
147 | if (!gc) |
|
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
148 | return NULL; |
|
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
149 | js = gc->proto_data; |
|
3a3bc5f12e52
Do not crash from commands in a disconnected chat. Fixes #5208
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
150 | id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)); |
| 9130 | 151 | return jabber_chat_find_by_id(js, id); |
| 152 | } | |
| 153 | ||
| 15884 | 154 | void jabber_chat_invite(PurpleConnection *gc, int id, const char *msg, |
| 7014 | 155 | const char *name) |
| 156 | { | |
| 157 | JabberStream *js = gc->proto_data; | |
| 158 | JabberChat *chat; | |
| 159 | xmlnode *message, *body, *x, *invite; | |
| 160 | char *room_jid; | |
| 161 | ||
| 162 | chat = jabber_chat_find_by_id(js, id); | |
| 163 | if(!chat) | |
| 164 | return; | |
| 165 | ||
| 166 | message = xmlnode_new("message"); | |
| 167 | ||
| 168 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 169 | ||
| 170 | if(chat->muc) { | |
| 171 | xmlnode_set_attrib(message, "to", room_jid); | |
| 172 | x = xmlnode_new_child(message, "x"); | |
| 13808 | 173 | xmlnode_set_namespace(x, "http://jabber.org/protocol/muc#user"); |
| 7014 | 174 | invite = xmlnode_new_child(x, "invite"); |
| 175 | xmlnode_set_attrib(invite, "to", name); | |
| 176 | body = xmlnode_new_child(invite, "reason"); | |
| 177 | xmlnode_insert_data(body, msg, -1); | |
| 178 | } else { | |
| 179 | xmlnode_set_attrib(message, "to", name); | |
| 180 | body = xmlnode_new_child(message, "body"); | |
| 181 | xmlnode_insert_data(body, msg, -1); | |
| 182 | x = xmlnode_new_child(message, "x"); | |
| 183 | xmlnode_set_attrib(x, "jid", room_jid); | |
| 13808 | 184 | xmlnode_set_namespace(x, "jabber:x:conference"); |
| 7014 | 185 | } |
| 186 | ||
| 187 | jabber_send(js, message); | |
| 188 | xmlnode_free(message); | |
| 189 | g_free(room_jid); | |
| 190 | } | |
| 191 | ||
| 9152 | 192 | void jabber_chat_member_free(JabberChatMember *jcm); |
| 193 | ||
|
9917
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
194 | char *jabber_get_chat_name(GHashTable *data) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
195 | char *room, *server, *chat_name = NULL; |
|
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 | room = g_hash_table_lookup(data, "room"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
198 | server = g_hash_table_lookup(data, "server"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
199 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
200 | if (room && server) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
201 | chat_name = g_strdup_printf("%s@%s", room, server); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
202 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
203 | return chat_name; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
204 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
205 | |
|
23273
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
206 | static void insert_in_hash_table(gpointer key, gpointer value, gpointer user_data) |
|
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
207 | { |
|
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
208 | GHashTable *hash_table = (GHashTable *)user_data; |
|
23275
c8599f5dac4c
The key and value need to be g_stdup()'d before adding to the hash table
Evan Schoenberg <evands@pidgin.im>
parents:
23273
diff
changeset
|
209 | g_hash_table_insert(hash_table, g_strdup(key), g_strdup(value)); |
|
23273
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
210 | } |
|
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
211 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
212 | static JabberChat *jabber_chat_new(JabberStream *js, const char *room, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
213 | const char *server, const char *handle, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
214 | const char *password, GHashTable *data) |
| 7014 | 215 | { |
| 216 | JabberChat *chat; | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
217 | char *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
218 | |
|
28677
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
219 | if (jabber_chat_find(js, room, server) != NULL) |
|
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
220 | return NULL; |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
221 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
222 | chat = g_new0(JabberChat, 1); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
223 | chat->js = js; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
224 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
225 | chat->room = g_strdup(room); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
226 | chat->server = g_strdup(server); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
227 | chat->handle = g_strdup(handle); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
228 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
229 | /* Copy the data hash table to chat->components */ |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
230 | chat->components = g_hash_table_new_full(g_str_hash, g_str_equal, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
231 | g_free, g_free); |
|
28669
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
232 | if (data == NULL) { |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
233 | g_hash_table_insert(chat->components, g_strdup("handle"), g_strdup(handle)); |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
234 | g_hash_table_insert(chat->components, g_strdup("room"), g_strdup(room)); |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
235 | g_hash_table_insert(chat->components, g_strdup("server"), g_strdup(server)); |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
236 | /* g_hash_table_insert(chat->components, g_strdup("password"), g_strdup(server)); */ |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
237 | } else { |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
238 | g_hash_table_foreach(data, insert_in_hash_table, chat->components); |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
239 | } |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
240 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
241 | chat->members = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
242 | (GDestroyNotify)jabber_chat_member_free); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
243 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
244 | jid = g_strdup_printf("%s@%s", room, server); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
245 | g_hash_table_insert(js->chats, jid, chat); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
246 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
247 | return chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
248 | } |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
249 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
250 | JabberChat *jabber_join_chat(JabberStream *js, const char *room, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
251 | const char *server, const char *handle, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
252 | const char *password, GHashTable *data) |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
253 | { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
254 | JabberChat *chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
255 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
256 | PurpleConnection *gc; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
257 | PurpleAccount *account; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
258 | PurpleStatus *status; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
259 | |
| 7014 | 260 | xmlnode *presence, *x; |
| 9954 | 261 | JabberBuddyState state; |
| 14525 | 262 | char *msg; |
| 9954 | 263 | int priority; |
| 7014 | 264 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
265 | char *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
266 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
267 | chat = jabber_chat_new(js, room, server, handle, password, data); |
|
28677
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
268 | if (chat == NULL) |
|
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
269 | return NULL; |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
270 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
271 | gc = js->gc; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
272 | account = purple_connection_get_account(gc); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
273 | status = purple_account_get_active_status(account); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
274 | purple_status_to_jabber(status, &state, &msg, &priority); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
275 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
276 | presence = jabber_presence_create_js(js, state, msg, priority); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
277 | g_free(msg); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
278 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
279 | jid = g_strdup_printf("%s@%s/%s", room, server, handle); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
280 | xmlnode_set_attrib(presence, "to", jid); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
281 | g_free(jid); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
282 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
283 | x = xmlnode_new_child(presence, "x"); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
284 | xmlnode_set_namespace(x, "http://jabber.org/protocol/muc"); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
285 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
286 | if (password && *password) { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
287 | xmlnode *p = xmlnode_new_child(x, "password"); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
288 | xmlnode_insert_data(p, password, -1); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
289 | } |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
290 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
291 | jabber_send(js, presence); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
292 | xmlnode_free(presence); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
293 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
294 | return chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
295 | } |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
296 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
297 | void jabber_chat_join(PurpleConnection *gc, GHashTable *data) |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
298 | { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
299 | char *room, *server, *handle, *passwd; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
300 | JabberID *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
301 | JabberStream *js = gc->proto_data; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
302 | char *tmp; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
303 | |
| 7014 | 304 | room = g_hash_table_lookup(data, "room"); |
| 305 | server = g_hash_table_lookup(data, "server"); | |
| 306 | handle = g_hash_table_lookup(data, "handle"); | |
| 307 | passwd = g_hash_table_lookup(data, "password"); | |
| 308 | ||
| 8113 | 309 | if(!room || !server) |
| 7014 | 310 | return; |
| 311 | ||
| 8113 | 312 | if(!handle) |
| 313 | handle = js->user->node; | |
| 314 | ||
| 7310 | 315 | if(!jabber_nodeprep_validate(room)) { |
| 316 | char *buf = g_strdup_printf(_("%s is not a valid room name"), room); | |
| 15884 | 317 | purple_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), |
| 7310 | 318 | buf); |
|
23270
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
319 | purple_serv_got_join_chat_failed(gc, data); |
| 7310 | 320 | g_free(buf); |
| 321 | return; | |
|
27728
03b2a20ba465
Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
322 | } else if(!jabber_domain_validate(server)) { |
| 7310 | 323 | char *buf = g_strdup_printf(_("%s is not a valid server name"), server); |
| 15884 | 324 | purple_notify_error(gc, _("Invalid Server Name"), |
| 7310 | 325 | _("Invalid Server Name"), buf); |
|
23270
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
326 | purple_serv_got_join_chat_failed(gc, data); |
| 7310 | 327 | g_free(buf); |
| 328 | return; | |
| 329 | } else if(!jabber_resourceprep_validate(handle)) { | |
| 330 | char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); | |
| 15884 | 331 | purple_notify_error(gc, _("Invalid Room Handle"), |
| 7310 | 332 | _("Invalid Room Handle"), buf); |
|
23270
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
333 | purple_serv_got_join_chat_failed(gc, data); |
|
22902
560976846e56
Fix a small memory leak when failing to join a jabber conference
Mark Doliner <markdoliner@pidgin.im>
parents:
22804
diff
changeset
|
334 | g_free(buf); |
|
560976846e56
Fix a small memory leak when failing to join a jabber conference
Mark Doliner <markdoliner@pidgin.im>
parents:
22804
diff
changeset
|
335 | return; |
| 7310 | 336 | } |
| 337 | ||
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
338 | /* Normalize the room and server parameters */ |
|
23270
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
339 | tmp = g_strdup_printf("%s@%s", room, server); |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
340 | jid = jabber_id_new(tmp); |
|
23270
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
341 | g_free(tmp); |
|
2b7db16e721a
As discussed on the devel list, purple_serv_got_join_chat_failed() and the
Evan Schoenberg <evands@pidgin.im>
parents:
22920
diff
changeset
|
342 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
343 | if (jid == NULL) { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
344 | /* TODO: Error message */ |
| 7014 | 345 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
346 | g_return_if_reached(); |
| 7014 | 347 | } |
| 348 | ||
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
349 | /* |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
350 | * Now that we've done all that nice core-interface stuff, let's join |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
351 | * this room! |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
352 | */ |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
353 | jabber_join_chat(js, jid->node, jid->domain, handle, passwd, data); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
354 | jabber_id_free(jid); |
| 7014 | 355 | } |
| 356 | ||
| 15884 | 357 | void jabber_chat_leave(PurpleConnection *gc, int id) |
| 7014 | 358 | { |
| 359 | JabberStream *js = gc->proto_data; | |
| 360 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 7974 | 361 | |
| 7014 | 362 | |
| 363 | if(!chat) | |
| 364 | return; | |
| 365 | ||
| 7974 | 366 | jabber_chat_part(chat, NULL); |
| 9152 | 367 | |
|
23403
a8704d47889f
Fix the chat-room rejoining bug where the list appears empty.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23302
diff
changeset
|
368 | chat->left = TRUE; |
| 7014 | 369 | } |
| 370 | ||
| 371 | void jabber_chat_destroy(JabberChat *chat) | |
| 372 | { | |
| 373 | JabberStream *js = chat->js; | |
| 374 | char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 375 | ||
| 7322 | 376 | g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 377 | g_free(room_jid); |
| 8396 | 378 | } |
| 379 | ||
| 380 | void jabber_chat_free(JabberChat *chat) | |
| 381 | { | |
| 382 | if(chat->config_dialog_handle) | |
| 15884 | 383 | purple_request_close(chat->config_dialog_type, chat->config_dialog_handle); |
| 7014 | 384 | |
| 385 | g_free(chat->room); | |
| 386 | g_free(chat->server); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
387 | g_free(chat->handle); |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
388 | g_hash_table_destroy(chat->members); |
|
23273
c42eae02c76e
g_hash_table_ref() / g_hash_table_unref() were added in too recent a glib version per Mark. Copy data to chat->components rather than using those.
Evan Schoenberg <evands@pidgin.im>
parents:
23270
diff
changeset
|
389 | g_hash_table_destroy(chat->components); |
| 7014 | 390 | g_free(chat); |
| 391 | } | |
| 392 | ||
| 15884 | 393 | gboolean jabber_chat_find_buddy(PurpleConversation *conv, const char *name) |
| 7014 | 394 | { |
| 15884 | 395 | return purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), name); |
| 7014 | 396 | } |
| 397 | ||
| 15884 | 398 | char *jabber_chat_buddy_real_name(PurpleConnection *gc, int id, const char *who) |
| 7398 | 399 | { |
| 400 | JabberStream *js = gc->proto_data; | |
| 401 | JabberChat *chat; | |
|
23499
3d18632e27a3
Return the real JID (if available) from the xmpp get_cb_real_name function.
Daniel Atallah <datallah@pidgin.im>
parents:
23403
diff
changeset
|
402 | JabberChatMember *jcm; |
| 7398 | 403 | |
| 404 | chat = jabber_chat_find_by_id(js, id); | |
| 405 | ||
| 406 | if(!chat) | |
| 407 | return NULL; | |
| 408 | ||
|
23499
3d18632e27a3
Return the real JID (if available) from the xmpp get_cb_real_name function.
Daniel Atallah <datallah@pidgin.im>
parents:
23403
diff
changeset
|
409 | jcm = g_hash_table_lookup(chat->members, who); |
|
3d18632e27a3
Return the real JID (if available) from the xmpp get_cb_real_name function.
Daniel Atallah <datallah@pidgin.im>
parents:
23403
diff
changeset
|
410 | if (jcm != NULL && jcm->jid) |
|
3d18632e27a3
Return the real JID (if available) from the xmpp get_cb_real_name function.
Daniel Atallah <datallah@pidgin.im>
parents:
23403
diff
changeset
|
411 | return g_strdup(jcm->jid); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
412 | |
|
23499
3d18632e27a3
Return the real JID (if available) from the xmpp get_cb_real_name function.
Daniel Atallah <datallah@pidgin.im>
parents:
23403
diff
changeset
|
413 | |
| 7398 | 414 | return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); |
| 415 | } | |
| 7895 | 416 | |
| 7923 | 417 | static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
| 418 | { | |
| 419 | JabberChat *chat = data; | |
| 420 | xmlnode *query; | |
| 421 | JabberIq *iq; | |
| 422 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 423 | ||
| 424 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
| 425 | xmlnode_set_attrib(iq->node, "to", to); | |
| 426 | g_free(to); | |
| 427 | ||
| 428 | query = xmlnode_get_child(iq->node, "query"); | |
| 429 | ||
| 430 | xmlnode_insert_child(query, result); | |
| 431 | ||
| 432 | jabber_iq_send(iq); | |
| 433 | } | |
| 434 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
435 | static void jabber_chat_room_configure_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
436 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
437 | xmlnode *packet, gpointer data) |
| 7923 | 438 | { |
| 439 | xmlnode *query, *x; | |
| 7926 | 440 | char *msg; |
| 7923 | 441 | JabberChat *chat; |
| 442 | JabberID *jid; | |
| 443 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
444 | if (!from) |
| 7923 | 445 | return; |
| 446 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
447 | if (type == JABBER_IQ_RESULT) { |
| 7923 | 448 | jid = jabber_id_new(from); |
| 449 | ||
| 450 | if(!jid) | |
| 451 | return; | |
| 452 | ||
| 453 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 454 | jabber_id_free(jid); | |
| 455 | ||
| 456 | if(!chat) | |
| 457 | return; | |
| 458 | ||
| 459 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 460 | return; | |
| 461 | ||
| 8135 | 462 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7923 | 463 | const char *xmlns; |
| 13808 | 464 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7923 | 465 | continue; |
| 466 | ||
| 467 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 15884 | 468 | chat->config_dialog_type = PURPLE_REQUEST_FIELDS; |
| 8396 | 469 | chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); |
| 7923 | 470 | return; |
| 471 | } | |
| 472 | } | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
473 | } else if (type == JABBER_IQ_ERROR) { |
|
21150
bedd1215fb5e
Stop jabber setting wants_to_die itself. This involved plumbing disconnection
Will Thompson <resiak@pidgin.im>
parents:
19897
diff
changeset
|
474 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7926 | 475 | |
| 15884 | 476 | purple_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); |
| 7926 | 477 | |
| 8401 | 478 | if(msg) |
| 479 | g_free(msg); | |
| 7926 | 480 | return; |
| 7923 | 481 | } |
| 482 | ||
| 7926 | 483 | msg = g_strdup_printf("Unable to configure room %s", from); |
| 484 | ||
| 15884 | 485 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7926 | 486 | g_free(msg); |
| 7923 | 487 | |
| 488 | } | |
| 489 | ||
| 490 | void jabber_chat_request_room_configure(JabberChat *chat) { | |
| 491 | JabberIq *iq; | |
| 492 | char *room_jid; | |
| 493 | ||
| 7895 | 494 | if(!chat) |
| 495 | return; | |
| 496 | ||
| 8396 | 497 | chat->config_dialog_handle = NULL; |
| 498 | ||
| 7955 | 499 | if(!chat->muc) { |
| 15884 | 500 | purple_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), |
| 7955 | 501 | _("This room is not capable of being configured")); |
| 502 | return; | |
| 503 | } | |
| 504 | ||
| 10474 | 505 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
| 7923 | 506 | "http://jabber.org/protocol/muc#owner"); |
| 507 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 7895 | 508 | |
| 7923 | 509 | xmlnode_set_attrib(iq->node, "to", room_jid); |
| 510 | ||
| 511 | jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
| 512 | ||
| 513 | jabber_iq_send(iq); | |
| 514 | ||
| 515 | g_free(room_jid); | |
| 7895 | 516 | } |
| 517 | ||
| 518 | void jabber_chat_create_instant_room(JabberChat *chat) { | |
| 519 | JabberIq *iq; | |
| 520 | xmlnode *query, *x; | |
| 521 | char *room_jid; | |
| 522 | ||
| 523 | if(!chat) | |
| 524 | return; | |
| 525 | ||
| 8396 | 526 | chat->config_dialog_handle = NULL; |
| 527 | ||
| 7895 | 528 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
| 529 | "http://jabber.org/protocol/muc#owner"); | |
| 530 | query = xmlnode_get_child(iq->node, "query"); | |
| 531 | x = xmlnode_new_child(query, "x"); | |
| 532 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 533 | ||
| 534 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 13808 | 535 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 7895 | 536 | xmlnode_set_attrib(x, "type", "submit"); |
| 537 | ||
| 538 | jabber_iq_send(iq); | |
| 539 | ||
| 540 | g_free(room_jid); | |
| 541 | } | |
| 7955 | 542 | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
543 | static void |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
544 | jabber_chat_register_x_data_result_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
545 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
546 | xmlnode *packet, gpointer data) |
| 7955 | 547 | { |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
548 | if (type == JABBER_IQ_ERROR) { |
|
21150
bedd1215fb5e
Stop jabber setting wants_to_die itself. This involved plumbing disconnection
Will Thompson <resiak@pidgin.im>
parents:
19897
diff
changeset
|
549 | char *msg = jabber_parse_error(js, packet, NULL); |
| 8401 | 550 | |
| 15884 | 551 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 8401 | 552 | |
| 553 | if(msg) | |
| 554 | g_free(msg); | |
| 555 | return; | |
| 7955 | 556 | } |
| 557 | } | |
| 558 | ||
| 559 | static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 560 | { | |
| 561 | JabberChat *chat = data; | |
| 562 | xmlnode *query; | |
| 563 | JabberIq *iq; | |
| 564 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 565 | ||
| 566 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
| 567 | xmlnode_set_attrib(iq->node, "to", to); | |
| 568 | g_free(to); | |
| 569 | ||
| 570 | query = xmlnode_get_child(iq->node, "query"); | |
| 571 | ||
| 572 | xmlnode_insert_child(query, result); | |
| 573 | ||
| 574 | jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
| 575 | ||
| 576 | jabber_iq_send(iq); | |
| 577 | } | |
| 578 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
579 | static void jabber_chat_register_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
580 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
581 | xmlnode *packet, gpointer data) |
| 7955 | 582 | { |
| 583 | xmlnode *query, *x; | |
| 584 | char *msg; | |
| 585 | JabberChat *chat; | |
| 586 | JabberID *jid; | |
| 587 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
588 | if (!from) |
| 7955 | 589 | return; |
| 590 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
591 | if (type == JABBER_IQ_RESULT) { |
| 7955 | 592 | jid = jabber_id_new(from); |
| 593 | ||
| 594 | if(!jid) | |
| 595 | return; | |
| 596 | ||
| 597 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 598 | jabber_id_free(jid); | |
| 599 | ||
| 600 | if(!chat) | |
| 601 | return; | |
| 602 | ||
| 603 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 604 | return; | |
| 605 | ||
| 8135 | 606 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7955 | 607 | const char *xmlns; |
| 608 | ||
| 13808 | 609 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7955 | 610 | continue; |
| 611 | ||
| 612 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 613 | jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
| 614 | return; | |
| 615 | } | |
| 616 | } | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
617 | } else if (type == JABBER_IQ_ERROR) { |
|
21150
bedd1215fb5e
Stop jabber setting wants_to_die itself. This involved plumbing disconnection
Will Thompson <resiak@pidgin.im>
parents:
19897
diff
changeset
|
618 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7955 | 619 | |
| 15884 | 620 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 7955 | 621 | |
| 8401 | 622 | if(msg) |
| 623 | g_free(msg); | |
| 7955 | 624 | return; |
| 625 | } | |
| 626 | ||
| 627 | msg = g_strdup_printf("Unable to configure room %s", from); | |
| 628 | ||
| 15884 | 629 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7955 | 630 | g_free(msg); |
| 631 | ||
| 632 | } | |
| 633 | ||
| 634 | void jabber_chat_register(JabberChat *chat) | |
| 635 | { | |
| 636 | JabberIq *iq; | |
| 637 | char *room_jid; | |
| 638 | ||
| 639 | if(!chat) | |
| 640 | return; | |
| 641 | ||
| 642 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 643 | ||
| 644 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
| 645 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 646 | g_free(room_jid); | |
| 647 | ||
| 648 | jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
| 649 | ||
| 650 | jabber_iq_send(iq); | |
| 651 | } | |
| 652 | ||
| 7971 | 653 | /* merge this with the function below when we get everyone on the same page wrt /commands */ |
| 654 | void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
| 655 | { | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
656 | JabberMessage *jm; |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
657 | |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
658 | jm = g_new0(JabberMessage, 1); |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
659 | jm->js = chat->js; |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
660 | jm->type = JABBER_MESSAGE_GROUPCHAT; |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
661 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 7955 | 662 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
663 | if (topic && *topic) |
|
28130
a29344f04ec9
Set XMPP chat topic when it contains a < followed by a character. Closes #5712.
Paul Aurich <darkrain42@pidgin.im>
parents:
27728
diff
changeset
|
664 | jm->subject = g_strdup(topic); |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
665 | else |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
666 | jm->subject = g_strdup(""); |
| 7971 | 667 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
668 | jabber_message_send(jm); |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
669 | jabber_message_free(jm); |
| 7971 | 670 | } |
| 671 | ||
| 15884 | 672 | void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic) |
| 7971 | 673 | { |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
674 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7971 | 675 | JabberChat *chat = jabber_chat_find_by_id(js, id); |
| 676 | ||
| 677 | if(!chat) | |
| 678 | return; | |
| 679 | ||
| 680 | jabber_chat_change_topic(chat, topic); | |
| 681 | } | |
| 682 | ||
| 683 | ||
| 7972 | 684 | void jabber_chat_change_nick(JabberChat *chat, const char *nick) |
| 685 | { | |
| 686 | xmlnode *presence; | |
| 687 | char *full_jid; | |
| 15884 | 688 | PurplePresence *gpresence; |
| 689 | PurpleStatus *status; | |
| 9954 | 690 | JabberBuddyState state; |
| 14525 | 691 | char *msg; |
| 9954 | 692 | int priority; |
| 7972 | 693 | |
| 694 | if(!chat->muc) { | |
| 15884 | 695 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7972 | 696 | _("Nick changing not supported in non-MUC chatrooms"), |
| 15884 | 697 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 7972 | 698 | return; |
| 699 | } | |
| 700 | ||
| 15884 | 701 | gpresence = purple_account_get_presence(chat->js->gc->account); |
| 702 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 703 | |
| 15884 | 704 | purple_status_to_jabber(status, &state, &msg, &priority); |
| 9954 | 705 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17007
diff
changeset
|
706 | presence = jabber_presence_create_js(chat->js, state, msg, priority); |
| 7972 | 707 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); |
| 708 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 709 | g_free(full_jid); | |
| 14525 | 710 | g_free(msg); |
| 7972 | 711 | |
| 712 | jabber_send(chat->js, presence); | |
| 713 | xmlnode_free(presence); | |
| 714 | } | |
| 715 | ||
| 7974 | 716 | void jabber_chat_part(JabberChat *chat, const char *msg) |
| 717 | { | |
| 718 | char *room_jid; | |
| 719 | xmlnode *presence; | |
| 7972 | 720 | |
| 8537 | 721 | room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
| 722 | chat->handle); | |
| 7974 | 723 | presence = xmlnode_new("presence"); |
| 724 | xmlnode_set_attrib(presence, "to", room_jid); | |
| 725 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 726 | if(msg) { | |
| 727 | xmlnode *status = xmlnode_new_child(presence, "status"); | |
| 728 | xmlnode_insert_data(status, msg, -1); | |
| 729 | } | |
| 730 | jabber_send(chat->js, presence); | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
731 | |
| 7974 | 732 | xmlnode_free(presence); |
| 733 | g_free(room_jid); | |
| 734 | } | |
| 735 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
736 | static void roomlist_disco_result_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
737 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
738 | xmlnode *packet, gpointer data) |
| 8113 | 739 | { |
| 740 | xmlnode *query; | |
| 741 | xmlnode *item; | |
| 7974 | 742 | |
| 8113 | 743 | if(!js->roomlist) |
| 744 | return; | |
| 745 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
746 | if (type == JABBER_IQ_ERROR) { |
|
21150
bedd1215fb5e
Stop jabber setting wants_to_die itself. This involved plumbing disconnection
Will Thompson <resiak@pidgin.im>
parents:
19897
diff
changeset
|
747 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 748 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
749 | _("Error retrieving room list"), err); |
| 15884 | 750 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 751 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 752 | js->roomlist = NULL; |
| 8401 | 753 | g_free(err); |
| 8113 | 754 | return; |
| 755 | } | |
| 756 | ||
| 757 | if(!(query = xmlnode_get_child(packet, "query"))) { | |
|
21150
bedd1215fb5e
Stop jabber setting wants_to_die itself. This involved plumbing disconnection
Will Thompson <resiak@pidgin.im>
parents:
19897
diff
changeset
|
758 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 759 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
760 | _("Error retrieving room list"), err); |
| 15884 | 761 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 762 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 763 | js->roomlist = NULL; |
| 8401 | 764 | g_free(err); |
| 8113 | 765 | return; |
| 766 | } | |
| 767 | ||
| 8135 | 768 | for(item = xmlnode_get_child(query, "item"); item; |
| 769 | item = xmlnode_get_next_twin(item)) { | |
| 8113 | 770 | const char *name; |
| 15884 | 771 | PurpleRoomlistRoom *room; |
| 8113 | 772 | JabberID *jid; |
| 773 | ||
| 774 | if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
| 775 | continue; | |
| 776 | name = xmlnode_get_attrib(item, "name"); | |
| 777 | ||
| 778 | ||
| 15884 | 779 | room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); |
| 780 | purple_roomlist_room_add_field(js->roomlist, room, jid->node); | |
| 781 | purple_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
| 782 | purple_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
| 783 | purple_roomlist_room_add(js->roomlist, room); | |
| 8113 | 784 | |
| 785 | jabber_id_free(jid); | |
| 786 | } | |
| 15884 | 787 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 788 | purple_roomlist_unref(js->roomlist); | |
| 8113 | 789 | js->roomlist = NULL; |
| 790 | } | |
| 791 | ||
| 10045 | 792 | static void roomlist_cancel_cb(JabberStream *js, const char *server) { |
| 793 | if(js->roomlist) { | |
| 15884 | 794 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 795 | purple_roomlist_unref(js->roomlist); | |
| 10045 | 796 | js->roomlist = NULL; |
| 797 | } | |
| 798 | } | |
| 799 | ||
| 8113 | 800 | static void roomlist_ok_cb(JabberStream *js, const char *server) |
| 801 | { | |
| 802 | JabberIq *iq; | |
| 10045 | 803 | |
| 804 | if(!js->roomlist) | |
| 805 | return; | |
| 8113 | 806 | |
| 807 | if(!server || !*server) { | |
| 15884 | 808 | purple_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL); |
|
28158
0ec0690c2741
jabber: Fix "Invalid Server" breaking roomlist dialog. Closes #8143.
Paul Aurich <darkrain42@pidgin.im>
parents:
28130
diff
changeset
|
809 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 8113 | 810 | return; |
| 811 | } | |
| 812 | ||
| 15884 | 813 | purple_roomlist_set_in_progress(js->roomlist, TRUE); |
| 10045 | 814 | |
| 815 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
| 816 | ||
| 817 | xmlnode_set_attrib(iq->node, "to", server); | |
| 818 | ||
| 819 | jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
| 820 | ||
| 821 | jabber_iq_send(iq); | |
| 822 | } | |
| 823 | ||
| 15884 | 824 | char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room) |
| 15185 | 825 | { |
| 826 | ||
| 827 | return g_strdup_printf("%s@%s", (char*)room->fields->data, (char*)room->fields->next->data); | |
| 828 | } | |
| 829 | ||
| 15884 | 830 | PurpleRoomlist *jabber_roomlist_get_list(PurpleConnection *gc) |
| 10045 | 831 | { |
| 832 | JabberStream *js = gc->proto_data; | |
| 833 | GList *fields = NULL; | |
| 15884 | 834 | PurpleRoomlistField *f; |
| 10045 | 835 | |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
836 | if(js->roomlist) |
| 15884 | 837 | purple_roomlist_unref(js->roomlist); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
838 | |
| 15884 | 839 | 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
|
840 | |
| 15884 | 841 | 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
|
842 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
843 | |
| 15884 | 844 | 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
|
845 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
846 | |
| 15884 | 847 | 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
|
848 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
849 | |
| 15884 | 850 | purple_roomlist_set_fields(js->roomlist, fields); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
851 | |
| 8113 | 852 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
853 | purple_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), |
| 8113 | 854 | _("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
|
855 | js->chat_servers ? js->chat_servers->data : NULL, |
| 8697 | 856 | FALSE, FALSE, NULL, |
| 15884 | 857 | _("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
|
858 | _("Cancel"), PURPLE_CALLBACK(roomlist_cancel_cb), |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
859 | purple_connection_get_account(gc), NULL, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
860 | js); |
| 8113 | 861 | |
| 862 | return js->roomlist; | |
| 863 | } | |
| 864 | ||
| 15884 | 865 | void jabber_roomlist_cancel(PurpleRoomlist *list) |
| 8113 | 866 | { |
| 15884 | 867 | PurpleConnection *gc; |
| 8113 | 868 | JabberStream *js; |
| 869 | ||
| 15884 | 870 | gc = purple_account_get_connection(list->account); |
| 8113 | 871 | js = gc->proto_data; |
| 872 | ||
| 15884 | 873 | purple_roomlist_set_in_progress(list, FALSE); |
| 8113 | 874 | |
| 875 | if (js->roomlist == list) { | |
| 876 | js->roomlist = NULL; | |
| 15884 | 877 | purple_roomlist_unref(list); |
| 8113 | 878 | } |
| 879 | } | |
| 880 | ||
| 9152 | 881 | void jabber_chat_member_free(JabberChatMember *jcm) |
| 882 | { | |
| 883 | g_free(jcm->handle); | |
| 884 | g_free(jcm->jid); | |
| 885 | g_free(jcm); | |
| 886 | } | |
| 887 | ||
| 888 | void jabber_chat_track_handle(JabberChat *chat, const char *handle, | |
| 889 | const char *jid, const char *affiliation, const char *role) | |
| 890 | { | |
| 891 | JabberChatMember *jcm = g_new0(JabberChatMember, 1); | |
| 892 | ||
| 893 | jcm->handle = g_strdup(handle); | |
| 894 | jcm->jid = g_strdup(jid); | |
| 895 | ||
| 896 | g_hash_table_replace(chat->members, jcm->handle, jcm); | |
| 897 | ||
| 898 | /* XXX: keep track of role and affiliation */ | |
| 899 | } | |
| 900 | ||
| 901 | void jabber_chat_remove_handle(JabberChat *chat, const char *handle) | |
| 902 | { | |
| 903 | g_hash_table_remove(chat->members, handle); | |
| 904 | } | |
| 905 | ||
| 906 | gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why) | |
| 907 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
908 | 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
|
909 | 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
|
910 | char *to; |
| 9152 | 911 | JabberIq *iq; |
| 912 | xmlnode *query, *item, *reason; | |
| 913 | ||
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
914 | 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
|
915 | 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
|
916 | 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
|
917 | 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
|
918 | 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
|
919 | else |
| 9152 | 920 | return FALSE; |
| 921 | ||
| 922 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 923 | "http://jabber.org/protocol/muc#admin"); | |
| 924 | ||
| 925 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 926 | xmlnode_set_attrib(iq->node, "to", to); | |
| 927 | g_free(to); | |
| 928 | ||
| 929 | query = xmlnode_get_child(iq->node, "query"); | |
| 930 | 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
|
931 | xmlnode_set_attrib(item, "jid", jid); |
| 9152 | 932 | xmlnode_set_attrib(item, "affiliation", "outcast"); |
| 933 | if(why) { | |
| 934 | reason = xmlnode_new_child(item, "reason"); | |
| 935 | xmlnode_insert_data(reason, why, -1); | |
| 936 | } | |
| 937 | ||
| 938 | jabber_iq_send(iq); | |
| 939 | ||
| 940 | return TRUE; | |
| 941 | } | |
| 8113 | 942 | |
| 11393 | 943 | gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation) |
| 944 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
945 | 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
|
946 | const char *jid; |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
947 | char *to; |
| 11393 | 948 | JabberIq *iq; |
| 949 | xmlnode *query, *item; | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
950 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
951 | 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
|
952 | 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
|
953 | 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
|
954 | 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
|
955 | 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
|
956 | else |
| 11393 | 957 | return FALSE; |
| 958 | ||
| 959 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 960 | "http://jabber.org/protocol/muc#admin"); | |
| 961 | ||
| 962 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 963 | xmlnode_set_attrib(iq->node, "to", to); | |
| 964 | g_free(to); | |
| 965 | ||
| 966 | query = xmlnode_get_child(iq->node, "query"); | |
| 967 | 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
|
968 | xmlnode_set_attrib(item, "jid", jid); |
| 11393 | 969 | xmlnode_set_attrib(item, "affiliation", affiliation); |
| 970 | ||
| 971 | jabber_iq_send(iq); | |
| 972 | ||
| 973 | return TRUE; | |
| 974 | } | |
| 8113 | 975 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
976 | static void |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
977 | jabber_chat_affiliation_list_cb(JabberStream *js, const char *from, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
978 | JabberIqType type, const char *id, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
979 | xmlnode *packet, gpointer data) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
980 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
981 | JabberChat *chat; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
982 | xmlnode *query, *item; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
983 | int chat_id = GPOINTER_TO_INT(data); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
984 | GString *buf; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
985 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
986 | if(!(chat = jabber_chat_find_by_id(js, chat_id))) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
987 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
988 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
989 | if (type == JABBER_IQ_ERROR) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
990 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
991 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
992 | if(!(query = xmlnode_get_child(packet, "query"))) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
993 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
994 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
995 | buf = g_string_new(_("Affiliations:")); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
996 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
997 | item = xmlnode_get_child(query, "item"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
998 | if (item) { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
999 | for( ; item; item = xmlnode_get_next_twin(item)) { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1000 | const char *jid = xmlnode_get_attrib(item, "jid"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1001 | const char *affiliation = xmlnode_get_attrib(item, "affiliation"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1002 | if (jid && affiliation) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1003 | g_string_append_printf(buf, "\n%s %s", jid, affiliation); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1004 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1005 | } else { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1006 | buf = g_string_append_c(buf, '\n'); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1007 | buf = g_string_append_len(buf, _("No users found"), -1); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1008 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1009 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1010 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1011 | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1012 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1013 | g_string_free(buf, TRUE); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1014 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1015 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1016 | gboolean jabber_chat_affiliation_list(JabberChat *chat, const char *affiliation) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1017 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1018 | JabberIq *iq; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1019 | char *room_jid; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1020 | xmlnode *query, *item; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1021 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1022 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1023 | "http://jabber.org/protocol/muc#admin"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1024 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1025 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1026 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1027 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1028 | query = xmlnode_get_child(iq->node, "query"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1029 | item = xmlnode_new_child(query, "item"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1030 | xmlnode_set_attrib(item, "affiliation", affiliation); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1031 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1032 | jabber_iq_set_callback(iq, jabber_chat_affiliation_list_cb, GINT_TO_POINTER(chat->id)); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1033 | jabber_iq_send(iq); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1034 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1035 | return TRUE; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1036 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1037 | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1038 | 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
|
1039 | { |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1040 | char *to; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1041 | JabberIq *iq; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1042 | xmlnode *query, *item; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1043 | JabberChatMember *jcm; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1044 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1045 | jcm = g_hash_table_lookup(chat->members, who); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1046 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1047 | if (!jcm || !jcm->handle) |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1048 | return FALSE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1049 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1050 | 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
|
1051 | "http://jabber.org/protocol/muc#admin"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1052 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1053 | 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
|
1054 | xmlnode_set_attrib(iq->node, "to", to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1055 | g_free(to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1056 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1057 | query = xmlnode_get_child(iq->node, "query"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1058 | item = xmlnode_new_child(query, "item"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1059 | xmlnode_set_attrib(item, "nick", jcm->handle); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1060 | xmlnode_set_attrib(item, "role", role); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1061 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1062 | jabber_iq_send(iq); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1063 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1064 | return TRUE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1065 | } |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1066 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1067 | static void jabber_chat_role_list_cb(JabberStream *js, const char *from, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1068 | JabberIqType type, const char *id, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1069 | xmlnode *packet, gpointer data) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1070 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1071 | JabberChat *chat; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1072 | xmlnode *query, *item; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1073 | int chat_id = GPOINTER_TO_INT(data); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1074 | GString *buf; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1075 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1076 | if(!(chat = jabber_chat_find_by_id(js, chat_id))) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1077 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1078 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1079 | if (type == JABBER_IQ_ERROR) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1080 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1081 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1082 | if(!(query = xmlnode_get_child(packet, "query"))) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1083 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1084 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1085 | buf = g_string_new(_("Roles:")); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1086 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1087 | item = xmlnode_get_child(query, "item"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1088 | if (item) { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1089 | for( ; item; item = xmlnode_get_next_twin(item)) { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1090 | const char *jid = xmlnode_get_attrib(item, "jid"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1091 | const char *role = xmlnode_get_attrib(item, "role"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1092 | if (jid && role) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1093 | g_string_append_printf(buf, "\n%s %s", jid, role); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1094 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1095 | } else { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1096 | buf = g_string_append_c(buf, '\n'); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1097 | buf = g_string_append_len(buf, _("No users found"), -1); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1098 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1099 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1100 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1101 | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1102 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1103 | g_string_free(buf, TRUE); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1104 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1105 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1106 | gboolean jabber_chat_role_list(JabberChat *chat, const char *role) |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1107 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1108 | JabberIq *iq; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1109 | char *room_jid; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1110 | xmlnode *query, *item; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1111 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1112 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1113 | "http://jabber.org/protocol/muc#admin"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1114 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1115 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1116 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1117 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1118 | query = xmlnode_get_child(iq->node, "query"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1119 | item = xmlnode_new_child(query, "item"); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1120 | xmlnode_set_attrib(item, "role", role); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1121 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1122 | jabber_iq_set_callback(iq, jabber_chat_role_list_cb, GINT_TO_POINTER(chat->id)); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1123 | jabber_iq_send(iq); |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1124 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1125 | return TRUE; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1126 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1127 | |
| 9152 | 1128 | gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why) |
| 1129 | { | |
| 1130 | JabberIq *iq; | |
| 1131 | JabberChatMember *jcm = g_hash_table_lookup(chat->members, who); | |
| 1132 | char *to; | |
| 1133 | xmlnode *query, *item, *reason; | |
| 1134 | ||
| 1135 | if(!jcm || !jcm->jid) | |
| 1136 | return FALSE; | |
| 1137 | ||
| 1138 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 1139 | "http://jabber.org/protocol/muc#admin"); | |
| 1140 | ||
| 1141 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 1142 | xmlnode_set_attrib(iq->node, "to", to); | |
| 1143 | g_free(to); | |
| 1144 | ||
| 1145 | query = xmlnode_get_child(iq->node, "query"); | |
| 1146 | item = xmlnode_new_child(query, "item"); | |
| 1147 | xmlnode_set_attrib(item, "jid", jcm->jid); | |
| 1148 | xmlnode_set_attrib(item, "role", "none"); | |
| 1149 | if(why) { | |
| 1150 | reason = xmlnode_new_child(item, "reason"); | |
| 1151 | xmlnode_insert_data(reason, why, -1); | |
| 1152 | } | |
| 1153 | ||
| 1154 | jabber_iq_send(iq); | |
| 1155 | ||
| 1156 | return TRUE; | |
| 1157 | } | |
| 1158 | ||
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1159 | static void jabber_chat_disco_traffic_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1160 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1161 | xmlnode *packet, gpointer data) |
| 10941 | 1162 | { |
| 1163 | JabberChat *chat; | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1164 | #if 0 |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1165 | xmlnode *query, *x; |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1166 | #endif |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1167 | int chat_id = GPOINTER_TO_INT(data); |
| 10941 | 1168 | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1169 | if(!(chat = jabber_chat_find_by_id(js, chat_id))) |
| 10941 | 1170 | return; |
| 1171 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1172 | /* defaults, in case the conference server doesn't |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1173 | * support this request */ |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1174 | chat->xhtml = TRUE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1175 | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
19897
diff
changeset
|
1176 | /* disabling this until more MUC servers support |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1177 | * announcing this */ |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1178 | #if 0 |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1179 | if (type == JABBER_IQ_ERROR) { |
| 10941 | 1180 | return; |
| 1181 | } | |
| 1182 | ||
| 1183 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1184 | return; | |
| 1185 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1186 | chat->xhtml = FALSE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1187 | |
| 10941 | 1188 | for(x = xmlnode_get_child(query, "feature"); x; x = xmlnode_get_next_twin(x)) { |
| 1189 | const char *var = xmlnode_get_attrib(x, "var"); | |
| 1190 | ||
| 1191 | if(var && !strcmp(var, "http://jabber.org/protocol/xhtml-im")) { | |
| 1192 | chat->xhtml = TRUE; | |
| 1193 | } | |
| 1194 | } | |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
1195 | #endif |
| 10941 | 1196 | } |
| 1197 | ||
| 1198 | void jabber_chat_disco_traffic(JabberChat *chat) | |
| 1199 | { | |
| 1200 | JabberIq *iq; | |
| 1201 | xmlnode *query; | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1202 | char *room_jid; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1203 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1204 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 10941 | 1205 | |
| 1206 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, | |
| 1207 | "http://jabber.org/protocol/disco#info"); | |
| 1208 | ||
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
1209 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1210 | |
| 10941 | 1211 | query = xmlnode_get_child(iq->node, "query"); |
| 1212 | ||
| 1213 | xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/muc#traffic"); | |
| 1214 | ||
| 1215 | jabber_iq_set_callback(iq, jabber_chat_disco_traffic_cb, GINT_TO_POINTER(chat->id)); | |
| 1216 | ||
| 1217 | jabber_iq_send(iq); | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1218 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1219 | g_free(room_jid); |
| 10941 | 1220 | } |
| 9152 | 1221 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1222 | typedef struct { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1223 | const gchar *cap; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1224 | gboolean *all_support; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1225 | JabberBuddy *jb; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1226 | } JabberChatCapsData; |
| 9152 | 1227 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1228 | static void |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1229 | jabber_chat_all_participants_have_capability_foreach(gpointer key, |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1230 | gpointer value, |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1231 | gpointer user_data) |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1232 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1233 | const gchar *cap = ((JabberChatCapsData *) user_data)->cap; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1234 | gboolean *all_support = ((JabberChatCapsData *) user_data)->all_support; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1235 | JabberBuddy *jb = ((JabberChatCapsData *) user_data)->jb; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1236 | JabberChatMember *member = (JabberChatMember *) value; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1237 | const gchar *resource = member->handle; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1238 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); |
| 10941 | 1239 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1240 | if (jbr) { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1241 | *all_support &= jabber_resource_has_capability(jbr, cap); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1242 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1243 | *all_support = FALSE; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1244 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1245 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1246 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1247 | gboolean |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1248 | jabber_chat_all_participants_have_capability(const JabberChat *chat, |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1249 | const gchar *cap) |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1250 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1251 | gchar *chat_jid = NULL; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1252 | JabberBuddy *jb = NULL; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1253 | gboolean all_support = TRUE; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1254 | JabberChatCapsData data; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1255 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1256 | chat_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1257 | jb = jabber_buddy_find(chat->js, chat_jid, FALSE); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1258 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1259 | if (jb) { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1260 | data.cap = cap; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1261 | data.all_support = &all_support; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1262 | data.jb = jb; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1263 | |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27110
diff
changeset
|
1264 | g_hash_table_foreach(chat->members, |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1265 | jabber_chat_all_participants_have_capability_foreach, &data); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1266 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1267 | all_support = FALSE; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1268 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1269 | g_free(chat_jid); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1270 | return all_support; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1271 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1272 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1273 | guint |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1274 | jabber_chat_get_num_participants(const JabberChat *chat) |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1275 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1276 | return g_hash_table_size(chat->members); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1277 | } |