Sun, 06 Mar 2011 23:03:47 +0000
jabber: Support for requesting limited history when joining a MUC.
Patch from xnyhps, with some minor corrections by me.
Fixes #10986.
Refs #a14219.
| 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 | |
|
28687
9de3f49f3b30
jabber: Remove useless jabber_normalize calls now that the data in the hash table
Paul Aurich <darkrain42@pidgin.im>
parents:
28677
diff
changeset
|
109 | chat = g_hash_table_lookup(js->chats, room_jid); |
| 10607 | 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); | |
|
30581
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
176 | if (msg) { |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
177 | body = xmlnode_new_child(invite, "reason"); |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
178 | xmlnode_insert_data(body, msg, -1); |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
179 | } |
| 7014 | 180 | } else { |
| 181 | xmlnode_set_attrib(message, "to", name); | |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
182 | /* |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
183 | * Putting the reason into the body was an 'undocumented protocol, |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
184 | * ...not part of "groupchat 1.0"'. |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
185 | * http://xmpp.org/extensions/attic/jep-0045-1.16.html#invite |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
186 | * |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
187 | * Left here for compatibility. |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
188 | */ |
|
30581
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
189 | if (msg) { |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
190 | body = xmlnode_new_child(message, "body"); |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
191 | xmlnode_insert_data(body, msg, -1); |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
192 | } |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
193 | |
| 7014 | 194 | x = xmlnode_new_child(message, "x"); |
| 195 | xmlnode_set_attrib(x, "jid", room_jid); | |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
196 | |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28687
diff
changeset
|
197 | /* The better place for it! XEP-0249 style. */ |
|
30581
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
198 | if (msg) |
|
c63679097d60
jabber: Avoid an assertion warning
Paul Aurich <darkrain42@pidgin.im>
parents:
29400
diff
changeset
|
199 | xmlnode_set_attrib(x, "reason", msg); |
| 13808 | 200 | xmlnode_set_namespace(x, "jabber:x:conference"); |
| 7014 | 201 | } |
| 202 | ||
| 203 | jabber_send(js, message); | |
| 204 | xmlnode_free(message); | |
| 205 | g_free(room_jid); | |
| 206 | } | |
| 207 | ||
| 9152 | 208 | void jabber_chat_member_free(JabberChatMember *jcm); |
| 209 | ||
|
9917
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
210 | char *jabber_get_chat_name(GHashTable *data) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
211 | char *room, *server, *chat_name = NULL; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
212 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
213 | room = g_hash_table_lookup(data, "room"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
214 | server = g_hash_table_lookup(data, "server"); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
215 | |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
216 | if (room && server) { |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
217 | chat_name = g_strdup_printf("%s@%s", room, server); |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
218 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
219 | return chat_name; |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
220 | } |
|
2fbb3c9fab2b
[gaim-migrate @ 10809]
Daniel Atallah <datallah@pidgin.im>
parents:
9913
diff
changeset
|
221 | |
|
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
|
222 | 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
|
223 | { |
|
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
|
224 | 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
|
225 | 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
|
226 | } |
|
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
|
227 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
228 | 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
|
229 | const char *server, const char *handle, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
230 | const char *password, GHashTable *data) |
| 7014 | 231 | { |
| 232 | JabberChat *chat; | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
233 | char *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
234 | |
|
28677
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
235 | 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
|
236 | return NULL; |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
237 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
238 | chat = g_new0(JabberChat, 1); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
239 | chat->js = js; |
|
31442
fd16ffae2043
jabber: Treat the presence storm on joining a room as not new arrivals.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
30581
diff
changeset
|
240 | chat->joined = 0; |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
241 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
242 | chat->room = g_strdup(room); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
243 | chat->server = g_strdup(server); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
244 | chat->handle = g_strdup(handle); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
245 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
246 | /* Copy the data hash table to chat->components */ |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
247 | 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
|
248 | 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
|
249 | if (data == NULL) { |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
250 | 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
|
251 | 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
|
252 | 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
|
253 | /* 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
|
254 | } else { |
|
f67839ca0064
jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents:
28668
diff
changeset
|
255 | 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
|
256 | } |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
257 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
258 | 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
|
259 | (GDestroyNotify)jabber_chat_member_free); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
260 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
261 | jid = g_strdup_printf("%s@%s", room, server); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
262 | g_hash_table_insert(js->chats, jid, chat); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
263 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
264 | return chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
265 | } |
|
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 | 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
|
268 | const char *server, const char *handle, |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
269 | const char *password, GHashTable *data) |
|
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 | JabberChat *chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
272 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
273 | PurpleConnection *gc; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
274 | PurpleAccount *account; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
275 | PurpleStatus *status; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
276 | |
| 7014 | 277 | xmlnode *presence, *x; |
| 9954 | 278 | JabberBuddyState state; |
| 14525 | 279 | char *msg; |
| 9954 | 280 | int priority; |
| 7014 | 281 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
282 | char *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
283 | |
|
31511
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
284 | char *history_maxchars; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
285 | char *history_maxstanzas; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
286 | char *history_seconds; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
287 | char *history_since; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
288 | |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
289 | struct tm history_since_datetime; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
290 | const char *history_since_string = NULL; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
291 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
292 | 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
|
293 | if (chat == NULL) |
|
5615313acca3
jabber: Reduce these from assertions to checks.
Paul Aurich <darkrain42@pidgin.im>
parents:
28669
diff
changeset
|
294 | return NULL; |
|
28668
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 | gc = js->gc; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
297 | account = purple_connection_get_account(gc); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
298 | status = purple_account_get_active_status(account); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
299 | purple_status_to_jabber(status, &state, &msg, &priority); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
300 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
301 | 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
|
302 | g_free(msg); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
303 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
304 | 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
|
305 | xmlnode_set_attrib(presence, "to", jid); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
306 | g_free(jid); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
307 | |
|
31511
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
308 | history_maxchars = g_hash_table_lookup(data, "history_maxchars"); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
309 | history_maxstanzas = g_hash_table_lookup(data, "history_maxstanzas"); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
310 | history_seconds = g_hash_table_lookup(data, "history_seconds"); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
311 | history_since = g_hash_table_lookup(data, "history_since"); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
312 | |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
313 | if (history_since) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
314 | if (purple_str_to_time(history_since, TRUE, &history_since_datetime, NULL, NULL) != 0) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
315 | history_since_string = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", &history_since_datetime); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
316 | } else { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
317 | history_since_string = NULL; |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
318 | |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
319 | purple_debug_error("jabber", "Invalid date format for history_since" |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
320 | " while requesting history: %s", history_since); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
321 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
322 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
323 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
324 | x = xmlnode_new_child(presence, "x"); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
325 | 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
|
326 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
327 | if (password && *password) { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
328 | xmlnode *p = xmlnode_new_child(x, "password"); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
329 | xmlnode_insert_data(p, password, -1); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
330 | } |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
331 | |
|
31511
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
332 | if ((history_maxchars && *history_maxchars) |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
333 | || (history_maxstanzas && *history_maxstanzas) |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
334 | || (history_seconds && *history_seconds) |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
335 | || (history_since_string && *history_since_string)) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
336 | |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
337 | xmlnode *history = xmlnode_new_child(x, "history"); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
338 | |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
339 | if (history_maxchars && *history_maxchars) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
340 | xmlnode_set_attrib(history, "maxchars", history_maxchars); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
341 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
342 | if (history_maxstanzas && *history_maxstanzas) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
343 | xmlnode_set_attrib(history, "maxstanzas", history_maxstanzas); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
344 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
345 | if (history_seconds && *history_seconds) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
346 | xmlnode_set_attrib(history, "seconds", history_seconds); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
347 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
348 | if (history_since_string && *history_since_string) { |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
349 | xmlnode_set_attrib(history, "since", history_since_string); |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
350 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
351 | } |
|
541a49389b3a
jabber: Support for requesting limited history when joining a MUC.
Paul Aurich <darkrain42@pidgin.im>
parents:
31442
diff
changeset
|
352 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
353 | jabber_send(js, presence); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
354 | xmlnode_free(presence); |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
355 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
356 | return chat; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
357 | } |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
358 | |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
359 | void jabber_chat_join(PurpleConnection *gc, GHashTable *data) |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
360 | { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
361 | char *room, *server, *handle, *passwd; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
362 | JabberID *jid; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
363 | JabberStream *js = gc->proto_data; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
364 | char *tmp; |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
365 | |
| 7014 | 366 | room = g_hash_table_lookup(data, "room"); |
| 367 | server = g_hash_table_lookup(data, "server"); | |
| 368 | handle = g_hash_table_lookup(data, "handle"); | |
| 369 | passwd = g_hash_table_lookup(data, "password"); | |
| 370 | ||
| 8113 | 371 | if(!room || !server) |
| 7014 | 372 | return; |
| 373 | ||
| 8113 | 374 | if(!handle) |
| 375 | handle = js->user->node; | |
| 376 | ||
| 7310 | 377 | if(!jabber_nodeprep_validate(room)) { |
| 378 | char *buf = g_strdup_printf(_("%s is not a valid room name"), room); | |
| 15884 | 379 | purple_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), |
| 7310 | 380 | 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
|
381 | purple_serv_got_join_chat_failed(gc, data); |
| 7310 | 382 | g_free(buf); |
| 383 | return; | |
|
27728
03b2a20ba465
Validate IPv6 identifiers in the domain portion of a JID.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
384 | } else if(!jabber_domain_validate(server)) { |
| 7310 | 385 | char *buf = g_strdup_printf(_("%s is not a valid server name"), server); |
| 15884 | 386 | purple_notify_error(gc, _("Invalid Server Name"), |
| 7310 | 387 | _("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
|
388 | purple_serv_got_join_chat_failed(gc, data); |
| 7310 | 389 | g_free(buf); |
| 390 | return; | |
| 391 | } else if(!jabber_resourceprep_validate(handle)) { | |
| 392 | char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); | |
| 15884 | 393 | purple_notify_error(gc, _("Invalid Room Handle"), |
| 7310 | 394 | _("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
|
395 | 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
|
396 | 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
|
397 | return; |
| 7310 | 398 | } |
| 399 | ||
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
400 | /* 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
|
401 | 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
|
402 | 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
|
403 | 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
|
404 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
405 | if (jid == NULL) { |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
406 | /* TODO: Error message */ |
| 7014 | 407 | |
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
408 | g_return_if_reached(); |
| 7014 | 409 | } |
| 410 | ||
|
28668
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
411 | /* |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
412 | * 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
|
413 | * this room! |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
414 | */ |
|
2f7479b4d0c0
jabber: Refactor the chat-joining code
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
415 | 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
|
416 | jabber_id_free(jid); |
| 7014 | 417 | } |
| 418 | ||
| 15884 | 419 | void jabber_chat_leave(PurpleConnection *gc, int id) |
| 7014 | 420 | { |
| 421 | JabberStream *js = gc->proto_data; | |
| 422 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 7974 | 423 | |
| 7014 | 424 | |
| 425 | if(!chat) | |
| 426 | return; | |
| 427 | ||
| 7974 | 428 | jabber_chat_part(chat, NULL); |
| 9152 | 429 | |
|
23403
a8704d47889f
Fix the chat-room rejoining bug where the list appears empty.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23302
diff
changeset
|
430 | chat->left = TRUE; |
| 7014 | 431 | } |
| 432 | ||
| 433 | void jabber_chat_destroy(JabberChat *chat) | |
| 434 | { | |
| 435 | JabberStream *js = chat->js; | |
| 436 | char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 437 | ||
|
28687
9de3f49f3b30
jabber: Remove useless jabber_normalize calls now that the data in the hash table
Paul Aurich <darkrain42@pidgin.im>
parents:
28677
diff
changeset
|
438 | g_hash_table_remove(js->chats, room_jid); |
| 7014 | 439 | g_free(room_jid); |
| 8396 | 440 | } |
| 441 | ||
| 442 | void jabber_chat_free(JabberChat *chat) | |
| 443 | { | |
| 444 | if(chat->config_dialog_handle) | |
| 15884 | 445 | purple_request_close(chat->config_dialog_type, chat->config_dialog_handle); |
| 7014 | 446 | |
| 447 | g_free(chat->room); | |
| 448 | g_free(chat->server); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
449 | g_free(chat->handle); |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
450 | 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
|
451 | g_hash_table_destroy(chat->components); |
| 7014 | 452 | g_free(chat); |
| 453 | } | |
| 454 | ||
| 15884 | 455 | gboolean jabber_chat_find_buddy(PurpleConversation *conv, const char *name) |
| 7014 | 456 | { |
| 15884 | 457 | return purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), name); |
| 7014 | 458 | } |
| 459 | ||
| 15884 | 460 | char *jabber_chat_buddy_real_name(PurpleConnection *gc, int id, const char *who) |
| 7398 | 461 | { |
| 462 | JabberStream *js = gc->proto_data; | |
| 463 | 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
|
464 | JabberChatMember *jcm; |
| 7398 | 465 | |
| 466 | chat = jabber_chat_find_by_id(js, id); | |
| 467 | ||
| 468 | if(!chat) | |
| 469 | return NULL; | |
| 470 | ||
|
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
|
471 | 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
|
472 | 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
|
473 | 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
|
474 | |
|
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
|
475 | |
| 7398 | 476 | return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); |
| 477 | } | |
| 7895 | 478 | |
| 7923 | 479 | static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
| 480 | { | |
| 481 | JabberChat *chat = data; | |
| 482 | xmlnode *query; | |
| 483 | JabberIq *iq; | |
| 484 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 485 | ||
| 486 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
| 487 | xmlnode_set_attrib(iq->node, "to", to); | |
| 488 | g_free(to); | |
| 489 | ||
| 490 | query = xmlnode_get_child(iq->node, "query"); | |
| 491 | ||
| 492 | xmlnode_insert_child(query, result); | |
| 493 | ||
| 494 | jabber_iq_send(iq); | |
| 495 | } | |
| 496 | ||
|
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
|
497 | 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
|
498 | 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
|
499 | xmlnode *packet, gpointer data) |
| 7923 | 500 | { |
| 501 | xmlnode *query, *x; | |
| 7926 | 502 | char *msg; |
| 7923 | 503 | JabberChat *chat; |
| 504 | JabberID *jid; | |
| 505 | ||
|
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
|
506 | if (!from) |
| 7923 | 507 | return; |
| 508 | ||
|
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
|
509 | if (type == JABBER_IQ_RESULT) { |
| 7923 | 510 | jid = jabber_id_new(from); |
| 511 | ||
| 512 | if(!jid) | |
| 513 | return; | |
| 514 | ||
| 515 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 516 | jabber_id_free(jid); | |
| 517 | ||
| 518 | if(!chat) | |
| 519 | return; | |
| 520 | ||
| 521 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 522 | return; | |
| 523 | ||
| 8135 | 524 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7923 | 525 | const char *xmlns; |
| 13808 | 526 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7923 | 527 | continue; |
| 528 | ||
| 529 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 15884 | 530 | chat->config_dialog_type = PURPLE_REQUEST_FIELDS; |
| 8396 | 531 | chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); |
| 7923 | 532 | return; |
| 533 | } | |
| 534 | } | |
|
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
|
535 | } 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
|
536 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7926 | 537 | |
| 15884 | 538 | purple_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); |
| 7926 | 539 | |
| 8401 | 540 | if(msg) |
| 541 | g_free(msg); | |
| 7926 | 542 | return; |
| 7923 | 543 | } |
| 544 | ||
| 7926 | 545 | msg = g_strdup_printf("Unable to configure room %s", from); |
| 546 | ||
| 15884 | 547 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7926 | 548 | g_free(msg); |
| 7923 | 549 | |
| 550 | } | |
| 551 | ||
| 552 | void jabber_chat_request_room_configure(JabberChat *chat) { | |
| 553 | JabberIq *iq; | |
| 554 | char *room_jid; | |
| 555 | ||
| 7895 | 556 | if(!chat) |
| 557 | return; | |
| 558 | ||
| 8396 | 559 | chat->config_dialog_handle = NULL; |
| 560 | ||
| 7955 | 561 | if(!chat->muc) { |
| 15884 | 562 | purple_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), |
| 7955 | 563 | _("This room is not capable of being configured")); |
| 564 | return; | |
| 565 | } | |
| 566 | ||
| 10474 | 567 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
| 7923 | 568 | "http://jabber.org/protocol/muc#owner"); |
| 569 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 7895 | 570 | |
| 7923 | 571 | xmlnode_set_attrib(iq->node, "to", room_jid); |
| 572 | ||
| 573 | jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
| 574 | ||
| 575 | jabber_iq_send(iq); | |
| 576 | ||
| 577 | g_free(room_jid); | |
| 7895 | 578 | } |
| 579 | ||
| 580 | void jabber_chat_create_instant_room(JabberChat *chat) { | |
| 581 | JabberIq *iq; | |
| 582 | xmlnode *query, *x; | |
| 583 | char *room_jid; | |
| 584 | ||
| 585 | if(!chat) | |
| 586 | return; | |
| 587 | ||
| 8396 | 588 | chat->config_dialog_handle = NULL; |
| 589 | ||
| 7895 | 590 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
| 591 | "http://jabber.org/protocol/muc#owner"); | |
| 592 | query = xmlnode_get_child(iq->node, "query"); | |
| 593 | x = xmlnode_new_child(query, "x"); | |
| 594 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 595 | ||
| 596 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 13808 | 597 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 7895 | 598 | xmlnode_set_attrib(x, "type", "submit"); |
| 599 | ||
| 600 | jabber_iq_send(iq); | |
| 601 | ||
| 602 | g_free(room_jid); | |
| 603 | } | |
| 7955 | 604 | |
|
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
|
605 | 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
|
606 | 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
|
607 | 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
|
608 | xmlnode *packet, gpointer data) |
| 7955 | 609 | { |
|
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
|
610 | 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
|
611 | char *msg = jabber_parse_error(js, packet, NULL); |
| 8401 | 612 | |
| 15884 | 613 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 8401 | 614 | |
| 615 | if(msg) | |
| 616 | g_free(msg); | |
| 617 | return; | |
| 7955 | 618 | } |
| 619 | } | |
| 620 | ||
| 621 | static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 622 | { | |
| 623 | JabberChat *chat = data; | |
| 624 | xmlnode *query; | |
| 625 | JabberIq *iq; | |
| 626 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 627 | ||
| 628 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
| 629 | xmlnode_set_attrib(iq->node, "to", to); | |
| 630 | g_free(to); | |
| 631 | ||
| 632 | query = xmlnode_get_child(iq->node, "query"); | |
| 633 | ||
| 634 | xmlnode_insert_child(query, result); | |
| 635 | ||
| 636 | jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
| 637 | ||
| 638 | jabber_iq_send(iq); | |
| 639 | } | |
| 640 | ||
|
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
|
641 | 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
|
642 | 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
|
643 | xmlnode *packet, gpointer data) |
| 7955 | 644 | { |
| 645 | xmlnode *query, *x; | |
| 646 | char *msg; | |
| 647 | JabberChat *chat; | |
| 648 | JabberID *jid; | |
| 649 | ||
|
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
|
650 | if (!from) |
| 7955 | 651 | return; |
| 652 | ||
|
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
|
653 | if (type == JABBER_IQ_RESULT) { |
| 7955 | 654 | jid = jabber_id_new(from); |
| 655 | ||
| 656 | if(!jid) | |
| 657 | return; | |
| 658 | ||
| 659 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 660 | jabber_id_free(jid); | |
| 661 | ||
| 662 | if(!chat) | |
| 663 | return; | |
| 664 | ||
| 665 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 666 | return; | |
| 667 | ||
| 8135 | 668 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7955 | 669 | const char *xmlns; |
| 670 | ||
| 13808 | 671 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7955 | 672 | continue; |
| 673 | ||
| 674 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 675 | jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
| 676 | return; | |
| 677 | } | |
| 678 | } | |
|
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
|
679 | } 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
|
680 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7955 | 681 | |
| 15884 | 682 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 7955 | 683 | |
| 8401 | 684 | if(msg) |
| 685 | g_free(msg); | |
| 7955 | 686 | return; |
| 687 | } | |
| 688 | ||
| 689 | msg = g_strdup_printf("Unable to configure room %s", from); | |
| 690 | ||
| 15884 | 691 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7955 | 692 | g_free(msg); |
| 693 | ||
| 694 | } | |
| 695 | ||
| 696 | void jabber_chat_register(JabberChat *chat) | |
| 697 | { | |
| 698 | JabberIq *iq; | |
| 699 | char *room_jid; | |
| 700 | ||
| 701 | if(!chat) | |
| 702 | return; | |
| 703 | ||
| 704 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 705 | ||
| 706 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
| 707 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 708 | g_free(room_jid); | |
| 709 | ||
| 710 | jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
| 711 | ||
| 712 | jabber_iq_send(iq); | |
| 713 | } | |
| 714 | ||
| 7971 | 715 | /* merge this with the function below when we get everyone on the same page wrt /commands */ |
| 716 | void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
| 717 | { | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
718 | JabberMessage *jm; |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
719 | |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
720 | 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
|
721 | 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
|
722 | 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
|
723 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 7955 | 724 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
725 | 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
|
726 | 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
|
727 | else |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
728 | jm->subject = g_strdup(""); |
| 7971 | 729 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
730 | 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
|
731 | jabber_message_free(jm); |
| 7971 | 732 | } |
| 733 | ||
| 15884 | 734 | void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic) |
| 7971 | 735 | { |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
736 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7971 | 737 | JabberChat *chat = jabber_chat_find_by_id(js, id); |
| 738 | ||
| 739 | if(!chat) | |
| 740 | return; | |
| 741 | ||
| 742 | jabber_chat_change_topic(chat, topic); | |
| 743 | } | |
| 744 | ||
| 745 | ||
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
746 | gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick) |
| 7972 | 747 | { |
| 748 | xmlnode *presence; | |
| 749 | char *full_jid; | |
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
750 | PurpleAccount *account; |
| 15884 | 751 | PurpleStatus *status; |
| 9954 | 752 | JabberBuddyState state; |
| 14525 | 753 | char *msg; |
| 9954 | 754 | int priority; |
| 7972 | 755 | |
| 756 | if(!chat->muc) { | |
| 15884 | 757 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7972 | 758 | _("Nick changing not supported in non-MUC chatrooms"), |
| 15884 | 759 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
760 | return FALSE; |
| 7972 | 761 | } |
| 762 | ||
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
763 | account = purple_connection_get_account(chat->js->gc); |
|
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
764 | status = purple_account_get_active_status(account); |
| 9954 | 765 | |
| 15884 | 766 | purple_status_to_jabber(status, &state, &msg, &priority); |
| 9954 | 767 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17007
diff
changeset
|
768 | presence = jabber_presence_create_js(chat->js, state, msg, priority); |
| 7972 | 769 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); |
| 770 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 771 | g_free(full_jid); | |
| 14525 | 772 | g_free(msg); |
| 7972 | 773 | |
| 774 | jabber_send(chat->js, presence); | |
| 775 | xmlnode_free(presence); | |
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
776 | |
|
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
777 | return TRUE; |
| 7972 | 778 | } |
| 779 | ||
| 7974 | 780 | void jabber_chat_part(JabberChat *chat, const char *msg) |
| 781 | { | |
| 782 | char *room_jid; | |
| 783 | xmlnode *presence; | |
| 7972 | 784 | |
| 8537 | 785 | room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
| 786 | chat->handle); | |
| 7974 | 787 | presence = xmlnode_new("presence"); |
| 788 | xmlnode_set_attrib(presence, "to", room_jid); | |
| 789 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 790 | if(msg) { | |
| 791 | xmlnode *status = xmlnode_new_child(presence, "status"); | |
| 792 | xmlnode_insert_data(status, msg, -1); | |
| 793 | } | |
| 794 | 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
|
795 | |
| 7974 | 796 | xmlnode_free(presence); |
| 797 | g_free(room_jid); | |
| 798 | } | |
| 799 | ||
|
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
|
800 | 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
|
801 | 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
|
802 | xmlnode *packet, gpointer data) |
| 8113 | 803 | { |
| 804 | xmlnode *query; | |
| 805 | xmlnode *item; | |
| 7974 | 806 | |
| 8113 | 807 | if(!js->roomlist) |
| 808 | return; | |
| 809 | ||
|
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
|
810 | 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
|
811 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 812 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
813 | _("Error retrieving room list"), err); |
| 15884 | 814 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 815 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 816 | js->roomlist = NULL; |
| 8401 | 817 | g_free(err); |
| 8113 | 818 | return; |
| 819 | } | |
| 820 | ||
| 821 | 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
|
822 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 823 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
824 | _("Error retrieving room list"), err); |
| 15884 | 825 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 826 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 827 | js->roomlist = NULL; |
| 8401 | 828 | g_free(err); |
| 8113 | 829 | return; |
| 830 | } | |
| 831 | ||
| 8135 | 832 | for(item = xmlnode_get_child(query, "item"); item; |
| 833 | item = xmlnode_get_next_twin(item)) { | |
| 8113 | 834 | const char *name; |
| 15884 | 835 | PurpleRoomlistRoom *room; |
| 8113 | 836 | JabberID *jid; |
| 837 | ||
| 838 | if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
| 839 | continue; | |
| 840 | name = xmlnode_get_attrib(item, "name"); | |
| 841 | ||
| 842 | ||
| 15884 | 843 | room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); |
| 844 | purple_roomlist_room_add_field(js->roomlist, room, jid->node); | |
| 845 | purple_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
| 846 | purple_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
| 847 | purple_roomlist_room_add(js->roomlist, room); | |
| 8113 | 848 | |
| 849 | jabber_id_free(jid); | |
| 850 | } | |
| 15884 | 851 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 852 | purple_roomlist_unref(js->roomlist); | |
| 8113 | 853 | js->roomlist = NULL; |
| 854 | } | |
| 855 | ||
| 10045 | 856 | static void roomlist_cancel_cb(JabberStream *js, const char *server) { |
| 857 | if(js->roomlist) { | |
| 15884 | 858 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 859 | purple_roomlist_unref(js->roomlist); | |
| 10045 | 860 | js->roomlist = NULL; |
| 861 | } | |
| 862 | } | |
| 863 | ||
| 8113 | 864 | static void roomlist_ok_cb(JabberStream *js, const char *server) |
| 865 | { | |
| 866 | JabberIq *iq; | |
| 10045 | 867 | |
| 868 | if(!js->roomlist) | |
| 869 | return; | |
| 8113 | 870 | |
| 871 | if(!server || !*server) { | |
| 15884 | 872 | 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
|
873 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 8113 | 874 | return; |
| 875 | } | |
| 876 | ||
| 15884 | 877 | purple_roomlist_set_in_progress(js->roomlist, TRUE); |
| 10045 | 878 | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
879 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_DISCO_ITEMS); |
| 10045 | 880 | |
| 881 | xmlnode_set_attrib(iq->node, "to", server); | |
| 882 | ||
| 883 | jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
| 884 | ||
| 885 | jabber_iq_send(iq); | |
| 886 | } | |
| 887 | ||
| 15884 | 888 | char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room) |
| 15185 | 889 | { |
| 890 | ||
| 891 | return g_strdup_printf("%s@%s", (char*)room->fields->data, (char*)room->fields->next->data); | |
| 892 | } | |
| 893 | ||
| 15884 | 894 | PurpleRoomlist *jabber_roomlist_get_list(PurpleConnection *gc) |
| 10045 | 895 | { |
| 896 | JabberStream *js = gc->proto_data; | |
| 897 | GList *fields = NULL; | |
| 15884 | 898 | PurpleRoomlistField *f; |
| 10045 | 899 | |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
900 | if(js->roomlist) |
| 15884 | 901 | purple_roomlist_unref(js->roomlist); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
902 | |
| 15884 | 903 | 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
|
904 | |
| 15884 | 905 | 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
|
906 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
907 | |
| 15884 | 908 | 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
|
909 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
910 | |
| 15884 | 911 | 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
|
912 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
913 | |
| 15884 | 914 | purple_roomlist_set_fields(js->roomlist, fields); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
915 | |
| 8113 | 916 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
917 | purple_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), |
| 8113 | 918 | _("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
|
919 | js->chat_servers ? js->chat_servers->data : NULL, |
| 8697 | 920 | FALSE, FALSE, NULL, |
| 15884 | 921 | _("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
|
922 | _("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
|
923 | purple_connection_get_account(gc), NULL, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
924 | js); |
| 8113 | 925 | |
| 926 | return js->roomlist; | |
| 927 | } | |
| 928 | ||
| 15884 | 929 | void jabber_roomlist_cancel(PurpleRoomlist *list) |
| 8113 | 930 | { |
| 15884 | 931 | PurpleConnection *gc; |
| 8113 | 932 | JabberStream *js; |
| 933 | ||
| 15884 | 934 | gc = purple_account_get_connection(list->account); |
| 8113 | 935 | js = gc->proto_data; |
| 936 | ||
| 15884 | 937 | purple_roomlist_set_in_progress(list, FALSE); |
| 8113 | 938 | |
| 939 | if (js->roomlist == list) { | |
| 940 | js->roomlist = NULL; | |
| 15884 | 941 | purple_roomlist_unref(list); |
| 8113 | 942 | } |
| 943 | } | |
| 944 | ||
| 9152 | 945 | void jabber_chat_member_free(JabberChatMember *jcm) |
| 946 | { | |
| 947 | g_free(jcm->handle); | |
| 948 | g_free(jcm->jid); | |
| 949 | g_free(jcm); | |
| 950 | } | |
| 951 | ||
| 952 | void jabber_chat_track_handle(JabberChat *chat, const char *handle, | |
| 953 | const char *jid, const char *affiliation, const char *role) | |
| 954 | { | |
| 955 | JabberChatMember *jcm = g_new0(JabberChatMember, 1); | |
| 956 | ||
| 957 | jcm->handle = g_strdup(handle); | |
| 958 | jcm->jid = g_strdup(jid); | |
| 959 | ||
| 960 | g_hash_table_replace(chat->members, jcm->handle, jcm); | |
| 961 | ||
| 962 | /* XXX: keep track of role and affiliation */ | |
| 963 | } | |
| 964 | ||
| 965 | void jabber_chat_remove_handle(JabberChat *chat, const char *handle) | |
| 966 | { | |
| 967 | g_hash_table_remove(chat->members, handle); | |
| 968 | } | |
| 969 | ||
| 970 | gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why) | |
| 971 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
972 | 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
|
973 | 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
|
974 | char *to; |
| 9152 | 975 | JabberIq *iq; |
| 976 | xmlnode *query, *item, *reason; | |
| 977 | ||
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
978 | 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
|
979 | 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
|
980 | jid = jcm->jid; |
|
29059
8225f2507058
strchr() is safe when searching for an ASCII character in UTF8 strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
28984
diff
changeset
|
981 | else if (strchr(who, '@') != NULL) |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
982 | 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
|
983 | else |
| 9152 | 984 | return FALSE; |
| 985 | ||
| 986 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 987 | "http://jabber.org/protocol/muc#admin"); | |
| 988 | ||
| 989 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 990 | xmlnode_set_attrib(iq->node, "to", to); | |
| 991 | g_free(to); | |
| 992 | ||
| 993 | query = xmlnode_get_child(iq->node, "query"); | |
| 994 | 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
|
995 | xmlnode_set_attrib(item, "jid", jid); |
| 9152 | 996 | xmlnode_set_attrib(item, "affiliation", "outcast"); |
| 997 | if(why) { | |
| 998 | reason = xmlnode_new_child(item, "reason"); | |
| 999 | xmlnode_insert_data(reason, why, -1); | |
| 1000 | } | |
| 1001 | ||
| 1002 | jabber_iq_send(iq); | |
| 1003 | ||
| 1004 | return TRUE; | |
| 1005 | } | |
| 8113 | 1006 | |
| 11393 | 1007 | gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation) |
| 1008 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
1009 | 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
|
1010 | const char *jid; |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1011 | char *to; |
| 11393 | 1012 | JabberIq *iq; |
| 1013 | xmlnode *query, *item; | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1014 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1015 | 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
|
1016 | 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
|
1017 | jid = jcm->jid; |
|
29059
8225f2507058
strchr() is safe when searching for an ASCII character in UTF8 strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
28984
diff
changeset
|
1018 | else if (strchr(who, '@') != NULL) |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
1019 | 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
|
1020 | else |
| 11393 | 1021 | return FALSE; |
| 1022 | ||
| 1023 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 1024 | "http://jabber.org/protocol/muc#admin"); | |
| 1025 | ||
| 1026 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 1027 | xmlnode_set_attrib(iq->node, "to", to); | |
| 1028 | g_free(to); | |
| 1029 | ||
| 1030 | query = xmlnode_get_child(iq->node, "query"); | |
| 1031 | 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
|
1032 | xmlnode_set_attrib(item, "jid", jid); |
| 11393 | 1033 | xmlnode_set_attrib(item, "affiliation", affiliation); |
| 1034 | ||
| 1035 | jabber_iq_send(iq); | |
| 1036 | ||
| 1037 | return TRUE; | |
| 1038 | } | |
| 8113 | 1039 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1040 | 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
|
1041 | 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
|
1042 | 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
|
1043 | 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
|
1044 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1045 | 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
|
1046 | 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
|
1047 | 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
|
1048 | 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
|
1049 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1050 | 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
|
1051 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1052 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1053 | 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
|
1054 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1055 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1056 | 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
|
1057 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1058 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1059 | 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
|
1060 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1061 | 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
|
1062 | 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
|
1063 | 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
|
1064 | 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
|
1065 | 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
|
1066 | 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
|
1067 | 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
|
1068 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1069 | } else { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1070 | 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
|
1071 | 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
|
1072 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1073 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1074 | 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
|
1075 | 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
|
1076 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1077 | 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
|
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 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1080 | 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
|
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 | 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
|
1083 | 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
|
1084 | 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
|
1085 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1086 | 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
|
1087 | "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
|
1088 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1089 | 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
|
1090 | 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
|
1091 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1092 | 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
|
1093 | 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
|
1094 | 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
|
1095 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1096 | 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
|
1097 | 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
|
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 | 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
|
1100 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1101 | |
|
29400
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1102 | gboolean jabber_chat_role_user(JabberChat *chat, const char *who, |
|
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1103 | const char *role, const char *why) |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1104 | { |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1105 | char *to; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1106 | JabberIq *iq; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1107 | xmlnode *query, *item; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1108 | JabberChatMember *jcm; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1109 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1110 | jcm = g_hash_table_lookup(chat->members, who); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1111 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1112 | if (!jcm || !jcm->handle) |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1113 | return FALSE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1114 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1115 | 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
|
1116 | "http://jabber.org/protocol/muc#admin"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1117 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1118 | 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
|
1119 | xmlnode_set_attrib(iq->node, "to", to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1120 | g_free(to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1121 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1122 | query = xmlnode_get_child(iq->node, "query"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1123 | item = xmlnode_new_child(query, "item"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1124 | xmlnode_set_attrib(item, "nick", jcm->handle); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1125 | xmlnode_set_attrib(item, "role", role); |
|
29400
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1126 | if (why) { |
|
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1127 | xmlnode *reason = xmlnode_new_child(item, "reason"); |
|
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1128 | xmlnode_insert_data(reason, why, -1); |
|
8d8ad40c9c7d
jabber: Kick by in-room nick, not JID. Reduces code, but is still in-spec (and seems to be the preferred method)
Paul Aurich <darkrain42@pidgin.im>
parents:
29059
diff
changeset
|
1129 | } |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1130 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1131 | jabber_iq_send(iq); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1132 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1133 | return TRUE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1134 | } |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1135 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1136 | 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
|
1137 | 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
|
1138 | 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
|
1139 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1140 | 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
|
1141 | 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
|
1142 | 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
|
1143 | 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
|
1144 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1145 | 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
|
1146 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1147 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1148 | 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
|
1149 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1150 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1151 | 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
|
1152 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1153 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1154 | 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
|
1155 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1156 | 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
|
1157 | 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
|
1158 | 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
|
1159 | 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
|
1160 | 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
|
1161 | 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
|
1162 | 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
|
1163 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1164 | } else { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1165 | 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
|
1166 | 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
|
1167 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1168 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1169 | 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
|
1170 | 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
|
1171 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1172 | 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
|
1173 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1174 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1175 | 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
|
1176 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1177 | 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
|
1178 | 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
|
1179 | 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
|
1180 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1181 | 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
|
1182 | "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
|
1183 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1184 | 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
|
1185 | 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
|
1186 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1187 | 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
|
1188 | 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
|
1189 | 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
|
1190 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1191 | 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
|
1192 | 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
|
1193 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1194 | 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
|
1195 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1196 | |
|
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
|
1197 | 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
|
1198 | 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
|
1199 | xmlnode *packet, gpointer data) |
| 10941 | 1200 | { |
| 1201 | 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
|
1202 | #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
|
1203 | 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
|
1204 | #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
|
1205 | int chat_id = GPOINTER_TO_INT(data); |
| 10941 | 1206 | |
|
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
|
1207 | if(!(chat = jabber_chat_find_by_id(js, chat_id))) |
| 10941 | 1208 | return; |
| 1209 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1210 | /* defaults, in case the conference server doesn't |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1211 | * support this request */ |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1212 | chat->xhtml = TRUE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1213 | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
19897
diff
changeset
|
1214 | /* 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
|
1215 | * 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
|
1216 | #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
|
1217 | if (type == JABBER_IQ_ERROR) { |
| 10941 | 1218 | return; |
| 1219 | } | |
| 1220 | ||
| 1221 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1222 | return; | |
| 1223 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1224 | chat->xhtml = FALSE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1225 | |
| 10941 | 1226 | for(x = xmlnode_get_child(query, "feature"); x; x = xmlnode_get_next_twin(x)) { |
| 1227 | const char *var = xmlnode_get_attrib(x, "var"); | |
| 1228 | ||
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
1229 | if(var && !strcmp(var, NS_XHTML_IM)) { |
| 10941 | 1230 | chat->xhtml = TRUE; |
| 1231 | } | |
| 1232 | } | |
|
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
|
1233 | #endif |
| 10941 | 1234 | } |
| 1235 | ||
| 1236 | void jabber_chat_disco_traffic(JabberChat *chat) | |
| 1237 | { | |
| 1238 | JabberIq *iq; | |
| 1239 | xmlnode *query; | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1240 | char *room_jid; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1241 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1242 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 10941 | 1243 | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
1244 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, NS_DISCO_INFO); |
| 10941 | 1245 | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
1246 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1247 | |
| 10941 | 1248 | query = xmlnode_get_child(iq->node, "query"); |
| 1249 | ||
| 1250 | xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/muc#traffic"); | |
| 1251 | ||
| 1252 | jabber_iq_set_callback(iq, jabber_chat_disco_traffic_cb, GINT_TO_POINTER(chat->id)); | |
| 1253 | ||
| 1254 | jabber_iq_send(iq); | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1255 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1256 | g_free(room_jid); |
| 10941 | 1257 | } |
| 9152 | 1258 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1259 | 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
|
1260 | 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
|
1261 | 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
|
1262 | 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
|
1263 | } JabberChatCapsData; |
| 9152 | 1264 | |
|
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 | 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
|
1266 | 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
|
1267 | 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
|
1268 | 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
|
1269 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1270 | 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
|
1271 | 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
|
1272 | 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
|
1273 | 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
|
1274 | 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
|
1275 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); |
| 10941 | 1276 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1277 | 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
|
1278 | *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
|
1279 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1280 | *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
|
1281 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1282 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1283 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1284 | gboolean |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1285 | 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
|
1286 | 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
|
1287 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1288 | 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
|
1289 | 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
|
1290 | 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
|
1291 | 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
|
1292 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1293 | 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
|
1294 | 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
|
1295 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1296 | 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
|
1297 | 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
|
1298 | 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
|
1299 | 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
|
1300 | |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27110
diff
changeset
|
1301 | 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
|
1302 | 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
|
1303 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1304 | 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
|
1305 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1306 | 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
|
1307 | 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
|
1308 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1309 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1310 | guint |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1311 | 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
|
1312 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1313 | 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
|
1314 | } |