Mon, 24 Sep 2012 13:54:30 -0400
fix a memory leak (I've been in c++ land too long)
adhere to the rule of thumb: if your boolean variable needs 2 lines of comments to explain, you named it badly
| 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; |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
73 | JabberStream *js = purple_connection_get_protocol_data(gc); |
|
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; |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
149 | js = purple_connection_get_protocol_data(gc); |
|
22804
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 | { | |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
157 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7014 | 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; |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
363 | JabberStream *js = purple_connection_get_protocol_data(gc); |
|
28668
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 | { |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
421 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7014 | 422 | JabberChat *chat = jabber_chat_find_by_id(js, id); |
| 7974 | 423 | |
| 7014 | 424 | if(!chat) |
| 425 | return; | |
| 426 | ||
| 7974 | 427 | jabber_chat_part(chat, NULL); |
| 9152 | 428 | |
|
23403
a8704d47889f
Fix the chat-room rejoining bug where the list appears empty.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23302
diff
changeset
|
429 | chat->left = TRUE; |
| 7014 | 430 | } |
| 431 | ||
| 432 | void jabber_chat_destroy(JabberChat *chat) | |
| 433 | { | |
| 434 | JabberStream *js = chat->js; | |
| 435 | char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 436 | ||
|
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
|
437 | g_hash_table_remove(js->chats, room_jid); |
| 7014 | 438 | g_free(room_jid); |
| 8396 | 439 | } |
| 440 | ||
| 441 | void jabber_chat_free(JabberChat *chat) | |
| 442 | { | |
| 443 | if(chat->config_dialog_handle) | |
| 15884 | 444 | purple_request_close(chat->config_dialog_type, chat->config_dialog_handle); |
| 7014 | 445 | |
| 446 | g_free(chat->room); | |
| 447 | g_free(chat->server); | |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
448 | g_free(chat->handle); |
|
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10474
diff
changeset
|
449 | 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
|
450 | g_hash_table_destroy(chat->components); |
| 7014 | 451 | g_free(chat); |
| 452 | } | |
| 453 | ||
| 15884 | 454 | gboolean jabber_chat_find_buddy(PurpleConversation *conv, const char *name) |
| 7014 | 455 | { |
| 15884 | 456 | return purple_conv_chat_find_user(PURPLE_CONV_CHAT(conv), name); |
| 7014 | 457 | } |
| 458 | ||
| 15884 | 459 | char *jabber_chat_buddy_real_name(PurpleConnection *gc, int id, const char *who) |
| 7398 | 460 | { |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
461 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7398 | 462 | 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
|
463 | JabberChatMember *jcm; |
| 7398 | 464 | |
| 465 | chat = jabber_chat_find_by_id(js, id); | |
| 466 | ||
| 467 | if(!chat) | |
| 468 | return NULL; | |
| 469 | ||
|
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
|
470 | 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
|
471 | 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
|
472 | 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
|
473 | |
|
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
|
474 | |
| 7398 | 475 | return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); |
| 476 | } | |
| 7895 | 477 | |
| 7923 | 478 | static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
| 479 | { | |
| 480 | JabberChat *chat = data; | |
| 481 | xmlnode *query; | |
| 482 | JabberIq *iq; | |
| 483 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 484 | ||
| 485 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner"); | |
| 486 | xmlnode_set_attrib(iq->node, "to", to); | |
| 487 | g_free(to); | |
| 488 | ||
| 489 | query = xmlnode_get_child(iq->node, "query"); | |
| 490 | ||
| 491 | xmlnode_insert_child(query, result); | |
| 492 | ||
| 493 | jabber_iq_send(iq); | |
| 494 | } | |
| 495 | ||
|
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
|
496 | 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
|
497 | 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
|
498 | xmlnode *packet, gpointer data) |
| 7923 | 499 | { |
| 500 | xmlnode *query, *x; | |
| 7926 | 501 | char *msg; |
| 7923 | 502 | JabberChat *chat; |
| 503 | JabberID *jid; | |
| 504 | ||
|
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
|
505 | if (!from) |
| 7923 | 506 | return; |
| 507 | ||
|
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
|
508 | if (type == JABBER_IQ_RESULT) { |
| 7923 | 509 | jid = jabber_id_new(from); |
| 510 | ||
| 511 | if(!jid) | |
| 512 | return; | |
| 513 | ||
| 514 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 515 | jabber_id_free(jid); | |
| 516 | ||
| 517 | if(!chat) | |
| 518 | return; | |
| 519 | ||
| 520 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 521 | return; | |
| 522 | ||
| 8135 | 523 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7923 | 524 | const char *xmlns; |
| 13808 | 525 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7923 | 526 | continue; |
| 527 | ||
| 528 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 15884 | 529 | chat->config_dialog_type = PURPLE_REQUEST_FIELDS; |
| 8396 | 530 | chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); |
| 7923 | 531 | return; |
| 532 | } | |
| 533 | } | |
|
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
|
534 | } 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
|
535 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7926 | 536 | |
| 15884 | 537 | purple_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); |
| 7926 | 538 | |
| 8401 | 539 | if(msg) |
| 540 | g_free(msg); | |
| 7926 | 541 | return; |
| 7923 | 542 | } |
| 543 | ||
| 7926 | 544 | msg = g_strdup_printf("Unable to configure room %s", from); |
| 545 | ||
| 15884 | 546 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7926 | 547 | g_free(msg); |
| 7923 | 548 | |
| 549 | } | |
| 550 | ||
| 551 | void jabber_chat_request_room_configure(JabberChat *chat) { | |
| 552 | JabberIq *iq; | |
| 553 | char *room_jid; | |
| 554 | ||
| 7895 | 555 | if(!chat) |
| 556 | return; | |
| 557 | ||
| 8396 | 558 | chat->config_dialog_handle = NULL; |
| 559 | ||
| 7955 | 560 | if(!chat->muc) { |
| 15884 | 561 | purple_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"), |
| 7955 | 562 | _("This room is not capable of being configured")); |
| 563 | return; | |
| 564 | } | |
| 565 | ||
| 10474 | 566 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, |
| 7923 | 567 | "http://jabber.org/protocol/muc#owner"); |
| 568 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 7895 | 569 | |
| 7923 | 570 | xmlnode_set_attrib(iq->node, "to", room_jid); |
| 571 | ||
| 572 | jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL); | |
| 573 | ||
| 574 | jabber_iq_send(iq); | |
| 575 | ||
| 576 | g_free(room_jid); | |
| 7895 | 577 | } |
| 578 | ||
| 579 | void jabber_chat_create_instant_room(JabberChat *chat) { | |
| 580 | JabberIq *iq; | |
| 581 | xmlnode *query, *x; | |
| 582 | char *room_jid; | |
| 583 | ||
| 584 | if(!chat) | |
| 585 | return; | |
| 586 | ||
| 8396 | 587 | chat->config_dialog_handle = NULL; |
| 588 | ||
| 7895 | 589 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, |
| 590 | "http://jabber.org/protocol/muc#owner"); | |
| 591 | query = xmlnode_get_child(iq->node, "query"); | |
| 592 | x = xmlnode_new_child(query, "x"); | |
| 593 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 594 | ||
| 595 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 13808 | 596 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 7895 | 597 | xmlnode_set_attrib(x, "type", "submit"); |
| 598 | ||
| 599 | jabber_iq_send(iq); | |
| 600 | ||
| 601 | g_free(room_jid); | |
| 602 | } | |
| 7955 | 603 | |
|
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
|
604 | 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
|
605 | 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
|
606 | 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
|
607 | xmlnode *packet, gpointer data) |
| 7955 | 608 | { |
|
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
|
609 | 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
|
610 | char *msg = jabber_parse_error(js, packet, NULL); |
| 8401 | 611 | |
| 15884 | 612 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 8401 | 613 | |
| 614 | if(msg) | |
| 615 | g_free(msg); | |
| 616 | return; | |
| 7955 | 617 | } |
| 618 | } | |
| 619 | ||
| 620 | static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 621 | { | |
| 622 | JabberChat *chat = data; | |
| 623 | xmlnode *query; | |
| 624 | JabberIq *iq; | |
| 625 | char *to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 626 | ||
| 627 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | |
| 628 | xmlnode_set_attrib(iq->node, "to", to); | |
| 629 | g_free(to); | |
| 630 | ||
| 631 | query = xmlnode_get_child(iq->node, "query"); | |
| 632 | ||
| 633 | xmlnode_insert_child(query, result); | |
| 634 | ||
| 635 | jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL); | |
| 636 | ||
| 637 | jabber_iq_send(iq); | |
| 638 | } | |
| 639 | ||
|
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
|
640 | 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
|
641 | 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
|
642 | xmlnode *packet, gpointer data) |
| 7955 | 643 | { |
| 644 | xmlnode *query, *x; | |
| 645 | char *msg; | |
| 646 | JabberChat *chat; | |
| 647 | JabberID *jid; | |
| 648 | ||
|
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
|
649 | if (!from) |
| 7955 | 650 | return; |
| 651 | ||
|
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
|
652 | if (type == JABBER_IQ_RESULT) { |
| 7955 | 653 | jid = jabber_id_new(from); |
| 654 | ||
| 655 | if(!jid) | |
| 656 | return; | |
| 657 | ||
| 658 | chat = jabber_chat_find(js, jid->node, jid->domain); | |
| 659 | jabber_id_free(jid); | |
| 660 | ||
| 661 | if(!chat) | |
| 662 | return; | |
| 663 | ||
| 664 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 665 | return; | |
| 666 | ||
| 8135 | 667 | for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7955 | 668 | const char *xmlns; |
| 669 | ||
| 13808 | 670 | if(!(xmlns = xmlnode_get_namespace(x))) |
| 7955 | 671 | continue; |
| 672 | ||
| 673 | if(!strcmp(xmlns, "jabber:x:data")) { | |
| 674 | jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); | |
| 675 | return; | |
| 676 | } | |
| 677 | } | |
|
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
|
678 | } 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
|
679 | char *msg = jabber_parse_error(js, packet, NULL); |
| 7955 | 680 | |
| 15884 | 681 | purple_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); |
| 7955 | 682 | |
| 8401 | 683 | if(msg) |
| 684 | g_free(msg); | |
| 7955 | 685 | return; |
| 686 | } | |
| 687 | ||
| 688 | msg = g_strdup_printf("Unable to configure room %s", from); | |
| 689 | ||
| 15884 | 690 | purple_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg); |
| 7955 | 691 | g_free(msg); |
| 692 | ||
| 693 | } | |
| 694 | ||
| 695 | void jabber_chat_register(JabberChat *chat) | |
| 696 | { | |
| 697 | JabberIq *iq; | |
| 698 | char *room_jid; | |
| 699 | ||
| 700 | if(!chat) | |
| 701 | return; | |
| 702 | ||
| 703 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 704 | ||
| 705 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register"); | |
| 706 | xmlnode_set_attrib(iq->node, "to", room_jid); | |
| 707 | g_free(room_jid); | |
| 708 | ||
| 709 | jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL); | |
| 710 | ||
| 711 | jabber_iq_send(iq); | |
| 712 | } | |
| 713 | ||
| 7971 | 714 | /* merge this with the function below when we get everyone on the same page wrt /commands */ |
| 715 | void jabber_chat_change_topic(JabberChat *chat, const char *topic) | |
| 716 | { | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
717 | JabberMessage *jm; |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
718 | |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
719 | 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
|
720 | 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
|
721 | 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
|
722 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 7955 | 723 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
724 | 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
|
725 | 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
|
726 | else |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
727 | jm->subject = g_strdup(""); |
| 7971 | 728 | |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
729 | 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
|
730 | jabber_message_free(jm); |
| 7971 | 731 | } |
| 732 | ||
| 15884 | 733 | void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic) |
| 7971 | 734 | { |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26687
diff
changeset
|
735 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 7971 | 736 | JabberChat *chat = jabber_chat_find_by_id(js, id); |
| 737 | ||
| 738 | if(!chat) | |
| 739 | return; | |
| 740 | ||
| 741 | jabber_chat_change_topic(chat, topic); | |
| 742 | } | |
| 743 | ||
| 744 | ||
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
745 | gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick) |
| 7972 | 746 | { |
| 747 | xmlnode *presence; | |
| 748 | char *full_jid; | |
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
749 | PurpleAccount *account; |
| 15884 | 750 | PurpleStatus *status; |
| 9954 | 751 | JabberBuddyState state; |
| 14525 | 752 | char *msg; |
| 9954 | 753 | int priority; |
| 7972 | 754 | |
| 755 | if(!chat->muc) { | |
| 15884 | 756 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7972 | 757 | _("Nick changing not supported in non-MUC chatrooms"), |
| 15884 | 758 | 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
|
759 | return FALSE; |
| 7972 | 760 | } |
| 761 | ||
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
762 | 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
|
763 | status = purple_account_get_active_status(account); |
| 9954 | 764 | |
| 15884 | 765 | purple_status_to_jabber(status, &state, &msg, &priority); |
| 9954 | 766 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17007
diff
changeset
|
767 | presence = jabber_presence_create_js(chat->js, state, msg, priority); |
| 7972 | 768 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); |
| 769 | xmlnode_set_attrib(presence, "to", full_jid); | |
| 770 | g_free(full_jid); | |
| 14525 | 771 | g_free(msg); |
| 7972 | 772 | |
| 773 | jabber_send(chat->js, presence); | |
| 774 | xmlnode_free(presence); | |
|
28734
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
775 | |
|
886d6c5e8f9a
jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
Paul Aurich <darkrain42@pidgin.im>
parents:
28703
diff
changeset
|
776 | return TRUE; |
| 7972 | 777 | } |
| 778 | ||
| 7974 | 779 | void jabber_chat_part(JabberChat *chat, const char *msg) |
| 780 | { | |
| 781 | char *room_jid; | |
| 782 | xmlnode *presence; | |
| 7972 | 783 | |
| 8537 | 784 | room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, |
| 785 | chat->handle); | |
| 7974 | 786 | presence = xmlnode_new("presence"); |
| 787 | xmlnode_set_attrib(presence, "to", room_jid); | |
| 788 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 789 | if(msg) { | |
| 790 | xmlnode *status = xmlnode_new_child(presence, "status"); | |
| 791 | xmlnode_insert_data(status, msg, -1); | |
| 792 | } | |
| 793 | 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
|
794 | |
| 7974 | 795 | xmlnode_free(presence); |
| 796 | g_free(room_jid); | |
| 797 | } | |
| 798 | ||
|
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
|
799 | 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
|
800 | 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
|
801 | xmlnode *packet, gpointer data) |
| 8113 | 802 | { |
| 803 | xmlnode *query; | |
| 804 | xmlnode *item; | |
| 7974 | 805 | |
| 8113 | 806 | if(!js->roomlist) |
| 807 | return; | |
| 808 | ||
|
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
|
809 | 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
|
810 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 811 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
812 | _("Error retrieving room list"), err); |
| 15884 | 813 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 814 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 815 | js->roomlist = NULL; |
| 8401 | 816 | g_free(err); |
| 8113 | 817 | return; |
| 818 | } | |
| 819 | ||
| 820 | 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
|
821 | char *err = jabber_parse_error(js, packet, NULL); |
| 15884 | 822 | purple_notify_error(js->gc, _("Error"), |
|
10094
e80a87320835
[gaim-migrate @ 11112]
Mark Doliner <markdoliner@pidgin.im>
parents:
10091
diff
changeset
|
823 | _("Error retrieving room list"), err); |
| 15884 | 824 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 825 | purple_roomlist_unref(js->roomlist); | |
| 8120 | 826 | js->roomlist = NULL; |
| 8401 | 827 | g_free(err); |
| 8113 | 828 | return; |
| 829 | } | |
| 830 | ||
| 8135 | 831 | for(item = xmlnode_get_child(query, "item"); item; |
| 832 | item = xmlnode_get_next_twin(item)) { | |
| 8113 | 833 | const char *name; |
| 15884 | 834 | PurpleRoomlistRoom *room; |
| 8113 | 835 | JabberID *jid; |
| 836 | ||
| 837 | if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) | |
| 838 | continue; | |
| 839 | name = xmlnode_get_attrib(item, "name"); | |
| 840 | ||
| 841 | ||
| 15884 | 842 | room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL); |
| 843 | purple_roomlist_room_add_field(js->roomlist, room, jid->node); | |
| 844 | purple_roomlist_room_add_field(js->roomlist, room, jid->domain); | |
| 845 | purple_roomlist_room_add_field(js->roomlist, room, name ? name : ""); | |
| 846 | purple_roomlist_room_add(js->roomlist, room); | |
| 8113 | 847 | |
| 848 | jabber_id_free(jid); | |
| 849 | } | |
| 15884 | 850 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 851 | purple_roomlist_unref(js->roomlist); | |
| 8113 | 852 | js->roomlist = NULL; |
| 853 | } | |
| 854 | ||
| 10045 | 855 | static void roomlist_cancel_cb(JabberStream *js, const char *server) { |
| 856 | if(js->roomlist) { | |
| 15884 | 857 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 858 | purple_roomlist_unref(js->roomlist); | |
| 10045 | 859 | js->roomlist = NULL; |
| 860 | } | |
| 861 | } | |
| 862 | ||
| 8113 | 863 | static void roomlist_ok_cb(JabberStream *js, const char *server) |
| 864 | { | |
| 865 | JabberIq *iq; | |
| 10045 | 866 | |
| 867 | if(!js->roomlist) | |
| 868 | return; | |
| 8113 | 869 | |
| 870 | if(!server || !*server) { | |
| 15884 | 871 | 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
|
872 | purple_roomlist_set_in_progress(js->roomlist, FALSE); |
| 8113 | 873 | return; |
| 874 | } | |
| 875 | ||
| 15884 | 876 | purple_roomlist_set_in_progress(js->roomlist, TRUE); |
| 10045 | 877 | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
878 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_DISCO_ITEMS); |
| 10045 | 879 | |
| 880 | xmlnode_set_attrib(iq->node, "to", server); | |
| 881 | ||
| 882 | jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL); | |
| 883 | ||
| 884 | jabber_iq_send(iq); | |
| 885 | } | |
| 886 | ||
| 15884 | 887 | char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room) |
| 15185 | 888 | { |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
31511
diff
changeset
|
889 | GList *fields = purple_roomlist_room_get_fields(room); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
31511
diff
changeset
|
890 | return g_strdup_printf("%s@%s", (char*)fields->data, (char*)fields->next->data); |
| 15185 | 891 | } |
| 892 | ||
| 15884 | 893 | PurpleRoomlist *jabber_roomlist_get_list(PurpleConnection *gc) |
| 10045 | 894 | { |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
895 | JabberStream *js = purple_connection_get_protocol_data(gc); |
| 10045 | 896 | GList *fields = NULL; |
| 15884 | 897 | PurpleRoomlistField *f; |
| 10045 | 898 | |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
899 | if(js->roomlist) |
| 15884 | 900 | purple_roomlist_unref(js->roomlist); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
901 | |
| 15884 | 902 | 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
|
903 | |
| 15884 | 904 | 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
|
905 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
906 | |
| 15884 | 907 | 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
|
908 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
909 | |
| 15884 | 910 | 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
|
911 | fields = g_list_append(fields, f); |
|
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
912 | |
| 15884 | 913 | purple_roomlist_set_fields(js->roomlist, fields); |
|
9913
2e773d9ba800
[gaim-migrate @ 10805]
Daniel Atallah <datallah@pidgin.im>
parents:
9770
diff
changeset
|
914 | |
| 8113 | 915 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
916 | purple_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"), |
| 8113 | 917 | _("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
|
918 | js->chat_servers ? js->chat_servers->data : NULL, |
| 8697 | 919 | FALSE, FALSE, NULL, |
| 15884 | 920 | _("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
|
921 | _("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
|
922 | purple_connection_get_account(gc), NULL, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
923 | js); |
| 8113 | 924 | |
| 925 | return js->roomlist; | |
| 926 | } | |
| 927 | ||
| 15884 | 928 | void jabber_roomlist_cancel(PurpleRoomlist *list) |
| 8113 | 929 | { |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
31511
diff
changeset
|
930 | PurpleAccount *account; |
| 15884 | 931 | PurpleConnection *gc; |
| 8113 | 932 | JabberStream *js; |
| 933 | ||
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
31511
diff
changeset
|
934 | account = purple_roomlist_get_account(list); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
31511
diff
changeset
|
935 | gc = purple_account_get_connection(account); |
|
32277
97f16af01a05
Convert jabber prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32218
diff
changeset
|
936 | js = purple_connection_get_protocol_data(gc); |
| 8113 | 937 | |
| 15884 | 938 | purple_roomlist_set_in_progress(list, FALSE); |
| 8113 | 939 | |
| 940 | if (js->roomlist == list) { | |
| 941 | js->roomlist = NULL; | |
| 15884 | 942 | purple_roomlist_unref(list); |
| 8113 | 943 | } |
| 944 | } | |
| 945 | ||
| 9152 | 946 | void jabber_chat_member_free(JabberChatMember *jcm) |
| 947 | { | |
| 948 | g_free(jcm->handle); | |
| 949 | g_free(jcm->jid); | |
| 950 | g_free(jcm); | |
| 951 | } | |
| 952 | ||
| 953 | void jabber_chat_track_handle(JabberChat *chat, const char *handle, | |
| 954 | const char *jid, const char *affiliation, const char *role) | |
| 955 | { | |
| 956 | JabberChatMember *jcm = g_new0(JabberChatMember, 1); | |
| 957 | ||
| 958 | jcm->handle = g_strdup(handle); | |
| 959 | jcm->jid = g_strdup(jid); | |
| 960 | ||
| 961 | g_hash_table_replace(chat->members, jcm->handle, jcm); | |
| 962 | ||
| 963 | /* XXX: keep track of role and affiliation */ | |
| 964 | } | |
| 965 | ||
| 966 | void jabber_chat_remove_handle(JabberChat *chat, const char *handle) | |
| 967 | { | |
| 968 | g_hash_table_remove(chat->members, handle); | |
| 969 | } | |
| 970 | ||
| 971 | gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why) | |
| 972 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
973 | 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
|
974 | 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
|
975 | char *to; |
| 9152 | 976 | JabberIq *iq; |
| 977 | xmlnode *query, *item, *reason; | |
| 978 | ||
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
979 | 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
|
980 | 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
|
981 | 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
|
982 | 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
|
983 | 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
|
984 | else |
| 9152 | 985 | return FALSE; |
| 986 | ||
| 987 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 988 | "http://jabber.org/protocol/muc#admin"); | |
| 989 | ||
| 990 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 991 | xmlnode_set_attrib(iq->node, "to", to); | |
| 992 | g_free(to); | |
| 993 | ||
| 994 | query = xmlnode_get_child(iq->node, "query"); | |
| 995 | 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
|
996 | xmlnode_set_attrib(item, "jid", jid); |
| 9152 | 997 | xmlnode_set_attrib(item, "affiliation", "outcast"); |
| 998 | if(why) { | |
| 999 | reason = xmlnode_new_child(item, "reason"); | |
| 1000 | xmlnode_insert_data(reason, why, -1); | |
| 1001 | } | |
| 1002 | ||
| 1003 | jabber_iq_send(iq); | |
| 1004 | ||
| 1005 | return TRUE; | |
| 1006 | } | |
| 8113 | 1007 | |
| 11393 | 1008 | gboolean jabber_chat_affiliate_user(JabberChat *chat, const char *who, const char *affiliation) |
| 1009 | { | |
|
19854
b7971f8bd19a
Add the ability to affiliate people in an xmpp chat room even if
Mark Doliner <markdoliner@pidgin.im>
parents:
17007
diff
changeset
|
1010 | 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
|
1011 | const char *jid; |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1012 | char *to; |
| 11393 | 1013 | JabberIq *iq; |
| 1014 | xmlnode *query, *item; | |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1015 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1016 | 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
|
1017 | 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
|
1018 | 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
|
1019 | 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
|
1020 | 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
|
1021 | else |
| 11393 | 1022 | return FALSE; |
| 1023 | ||
| 1024 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET, | |
| 1025 | "http://jabber.org/protocol/muc#admin"); | |
| 1026 | ||
| 1027 | to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 1028 | xmlnode_set_attrib(iq->node, "to", to); | |
| 1029 | g_free(to); | |
| 1030 | ||
| 1031 | query = xmlnode_get_child(iq->node, "query"); | |
| 1032 | 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
|
1033 | xmlnode_set_attrib(item, "jid", jid); |
| 11393 | 1034 | xmlnode_set_attrib(item, "affiliation", affiliation); |
| 1035 | ||
| 1036 | jabber_iq_send(iq); | |
| 1037 | ||
| 1038 | return TRUE; | |
| 1039 | } | |
| 8113 | 1040 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1041 | 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
|
1042 | 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
|
1043 | 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
|
1044 | 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
|
1045 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1046 | 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
|
1047 | 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
|
1048 | 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
|
1049 | 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
|
1050 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1051 | 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
|
1052 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1053 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1054 | 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
|
1055 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1056 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1057 | 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
|
1058 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1059 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1060 | 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
|
1061 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1062 | 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
|
1063 | 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
|
1064 | 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
|
1065 | 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
|
1066 | 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
|
1067 | 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
|
1068 | 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
|
1069 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1070 | } else { |
|
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_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
|
1072 | 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
|
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 | |
|
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_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
|
1076 | 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
|
1077 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1078 | 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
|
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 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1081 | 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
|
1082 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1083 | 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
|
1084 | 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
|
1085 | 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
|
1086 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1087 | 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
|
1088 | "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
|
1089 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1090 | 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
|
1091 | 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
|
1092 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1093 | 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
|
1094 | 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
|
1095 | 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
|
1096 | |
|
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_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
|
1098 | 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
|
1099 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1100 | 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
|
1101 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1102 | |
|
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
|
1103 | 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
|
1104 | const char *role, const char *why) |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1105 | { |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1106 | char *to; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1107 | JabberIq *iq; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1108 | xmlnode *query, *item; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1109 | JabberChatMember *jcm; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1110 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1111 | jcm = g_hash_table_lookup(chat->members, who); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1112 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1113 | if (!jcm || !jcm->handle) |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1114 | return FALSE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1115 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1116 | 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
|
1117 | "http://jabber.org/protocol/muc#admin"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1118 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1119 | 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
|
1120 | xmlnode_set_attrib(iq->node, "to", to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1121 | g_free(to); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1122 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1123 | query = xmlnode_get_child(iq->node, "query"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1124 | item = xmlnode_new_child(query, "item"); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1125 | xmlnode_set_attrib(item, "nick", jcm->handle); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1126 | 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
|
1127 | 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
|
1128 | 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
|
1129 | 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
|
1130 | } |
|
13238
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1131 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1132 | jabber_iq_send(iq); |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1133 | |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1134 | return TRUE; |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1135 | } |
|
b98439d90903
[gaim-migrate @ 15603]
Andrej Krivulčík <thefox692@users.sourceforge.net>
parents:
12323
diff
changeset
|
1136 | |
|
27027
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1137 | 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
|
1138 | 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
|
1139 | 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
|
1140 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1141 | 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
|
1142 | 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
|
1143 | 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
|
1144 | 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
|
1145 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1146 | 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
|
1147 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1148 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1149 | 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
|
1150 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1151 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1152 | 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
|
1153 | return; |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1154 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1155 | 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
|
1156 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1157 | 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
|
1158 | 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
|
1159 | 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
|
1160 | 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
|
1161 | 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
|
1162 | 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
|
1163 | 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
|
1164 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1165 | } else { |
|
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_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
|
1167 | 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
|
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 | |
|
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_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
|
1171 | 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
|
1172 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1173 | 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
|
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 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1176 | 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
|
1177 | { |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1178 | 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
|
1179 | 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
|
1180 | 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
|
1181 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1182 | 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
|
1183 | "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
|
1184 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1185 | 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
|
1186 | 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
|
1187 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1188 | 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
|
1189 | 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
|
1190 | 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
|
1191 | |
|
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_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
|
1193 | 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
|
1194 | |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1195 | 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
|
1196 | } |
|
f3129efa65ea
Add ability to list roles/affiliations in a chat via slash-commands and
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
1197 | |
|
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
|
1198 | 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
|
1199 | 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
|
1200 | xmlnode *packet, gpointer data) |
| 10941 | 1201 | { |
| 1202 | 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
|
1203 | #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
|
1204 | 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
|
1205 | #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
|
1206 | int chat_id = GPOINTER_TO_INT(data); |
| 10941 | 1207 | |
|
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
|
1208 | if(!(chat = jabber_chat_find_by_id(js, chat_id))) |
| 10941 | 1209 | return; |
| 1210 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1211 | /* defaults, in case the conference server doesn't |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1212 | * support this request */ |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1213 | chat->xhtml = TRUE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1214 | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
19897
diff
changeset
|
1215 | /* 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
|
1216 | * 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
|
1217 | #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
|
1218 | if (type == JABBER_IQ_ERROR) { |
| 10941 | 1219 | return; |
| 1220 | } | |
| 1221 | ||
| 1222 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1223 | return; | |
| 1224 | ||
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1225 | chat->xhtml = FALSE; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1226 | |
| 10941 | 1227 | for(x = xmlnode_get_child(query, "feature"); x; x = xmlnode_get_next_twin(x)) { |
| 1228 | const char *var = xmlnode_get_attrib(x, "var"); | |
| 1229 | ||
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
1230 | if(var && !strcmp(var, NS_XHTML_IM)) { |
| 10941 | 1231 | chat->xhtml = TRUE; |
| 1232 | } | |
| 1233 | } | |
|
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
|
1234 | #endif |
| 10941 | 1235 | } |
| 1236 | ||
| 1237 | void jabber_chat_disco_traffic(JabberChat *chat) | |
| 1238 | { | |
| 1239 | JabberIq *iq; | |
| 1240 | xmlnode *query; | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1241 | char *room_jid; |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1242 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1243 | room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 10941 | 1244 | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28734
diff
changeset
|
1245 | iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, NS_DISCO_INFO); |
| 10941 | 1246 | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24254
diff
changeset
|
1247 | xmlnode_set_attrib(iq->node, "to", room_jid); |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1248 | |
| 10941 | 1249 | query = xmlnode_get_child(iq->node, "query"); |
| 1250 | ||
| 1251 | xmlnode_set_attrib(query, "node", "http://jabber.org/protocol/muc#traffic"); | |
| 1252 | ||
| 1253 | jabber_iq_set_callback(iq, jabber_chat_disco_traffic_cb, GINT_TO_POINTER(chat->id)); | |
| 1254 | ||
| 1255 | jabber_iq_send(iq); | |
|
11392
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1256 | |
|
fcf358e5a309
[gaim-migrate @ 13621]
Zmitrok <zmitrok@users.sourceforge.net>
parents:
10959
diff
changeset
|
1257 | g_free(room_jid); |
| 10941 | 1258 | } |
| 9152 | 1259 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1260 | 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
|
1261 | 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
|
1262 | 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
|
1263 | 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
|
1264 | } JabberChatCapsData; |
| 9152 | 1265 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1266 | 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
|
1267 | 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
|
1268 | 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
|
1269 | 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
|
1270 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1271 | 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
|
1272 | 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
|
1273 | 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
|
1274 | 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
|
1275 | 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
|
1276 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); |
| 10941 | 1277 | |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1278 | 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
|
1279 | *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
|
1280 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1281 | *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
|
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 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1285 | gboolean |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1286 | 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
|
1287 | 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
|
1288 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1289 | 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
|
1290 | 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
|
1291 | 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
|
1292 | 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
|
1293 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1294 | 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
|
1295 | 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
|
1296 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1297 | 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
|
1298 | 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
|
1299 | 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
|
1300 | 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
|
1301 | |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27110
diff
changeset
|
1302 | 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
|
1303 | 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
|
1304 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1305 | 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
|
1306 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1307 | 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
|
1308 | 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
|
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 | |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1311 | guint |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1312 | 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
|
1313 | { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27027
diff
changeset
|
1314 | 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
|
1315 | } |