annotate src/protocols/jabber/chat.c @ 9760:cee4e4cae56a

[gaim-migrate @ 10628] better way to split a jid committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 15 Aug 2004 23:24:14 +0000
parents 4a8bf81b82ae
children 3f97624e7753
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 #include "debug.h"
9713
db62420a53a2 [gaim-migrate @ 10574]
Mark Doliner <mark@kingant.net>
parents: 9554
diff changeset
23 #include "prpl.h" /* for proto_chat_entry */
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
24 #include "notify.h"
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
25 #include "request.h"
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
26 #include "roomlist.h"
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
27 #include "util.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "chat.h"
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
30 #include "iq.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "message.h"
7073
82e980962926 [gaim-migrate @ 7638]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
32 #include "presence.h"
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
33 #include "xdata.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 GList *jabber_chat_info(GaimConnection *gc)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 GList *m = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 struct proto_chat_entry *pce;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 pce = g_new0(struct proto_chat_entry, 1);
7841
0555e59dfba9 [gaim-migrate @ 8494]
Mark Doliner <mark@kingant.net>
parents: 7400
diff changeset
42 pce->label = _("_Room:");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 pce->identifier = "room";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 m = g_list_append(m, pce);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 pce = g_new0(struct proto_chat_entry, 1);
7841
0555e59dfba9 [gaim-migrate @ 8494]
Mark Doliner <mark@kingant.net>
parents: 7400
diff changeset
47 pce->label = _("_Server:");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 pce->identifier = "server";
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
49 pce->def = js->chat_servers ? js->chat_servers->data : "conference.jabber.org";
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 m = g_list_append(m, pce);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 pce = g_new0(struct proto_chat_entry, 1);
7841
0555e59dfba9 [gaim-migrate @ 8494]
Mark Doliner <mark@kingant.net>
parents: 7400
diff changeset
53 pce->label = _("_Handle:");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 pce->identifier = "handle";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 pce->def = js->user->node;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 m = g_list_append(m, pce);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 pce = g_new0(struct proto_chat_entry, 1);
7841
0555e59dfba9 [gaim-migrate @ 8494]
Mark Doliner <mark@kingant.net>
parents: 7400
diff changeset
59 pce->label = _("_Password:");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 pce->identifier = "password";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 pce->secret = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 m = g_list_append(m, pce);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 return m;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66
9754
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
67 GHashTable *jabber_chat_info_defaults(GaimConnection *gc, const char *chat_name)
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
68 {
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
69 GHashTable *defaults;
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
70
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
71 defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
72
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
73 if (chat_name != NULL) {
9760
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
74 JabberID *jid = jabber_id_new(chat_name);
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
75 if(jid) {
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
76 g_hash_table_insert(defaults, "room", g_strdup(jid->node));
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
77 if(jid->domain)
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
78 g_hash_table_insert(defaults, "server", g_strdup(jid->domain));
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
79 jabber_id_free(jid);
cee4e4cae56a [gaim-migrate @ 10628]
Nathan Walp <nwalp@pidgin.im>
parents: 9754
diff changeset
80 }
9754
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
81 }
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
82
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
83 return defaults;
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
84 }
4a8bf81b82ae [gaim-migrate @ 10621]
Luke Schierer <lschiere@pidgin.im>
parents: 9713
diff changeset
85
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 JabberChat *jabber_chat_find(JabberStream *js, const char *room,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 const char *server)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 char *room_jid;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 room_jid = g_strdup_printf("%s@%s", room, server);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
94 chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 g_free(room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 return chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 struct _find_by_id_data {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 int id;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 };
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 JabberChat *chat = value;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 struct _find_by_id_data *fbid = user_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 if(chat->id == fbid->id)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 fbid->chat = chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 JabberChat *jabber_chat_find_by_id(JabberStream *js, int id)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1);
7073
82e980962926 [gaim-migrate @ 7638]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
118 fbid->id = id;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 chat = fbid->chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 g_free(fbid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 return chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
125 JabberChat *jabber_chat_find_by_conv(GaimConversation *conv)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
126 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
127 GaimAccount *account = gaim_conversation_get_account(conv);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
128 GaimConnection *gc = gaim_account_get_connection(account);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
129 JabberStream *js = gc->proto_data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
130 int id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
131
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
132 return jabber_chat_find_by_id(js, id);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
133 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8697
diff changeset
134
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 void jabber_chat_invite(GaimConnection *gc, int id, const char *msg,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 const char *name)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 xmlnode *message, *body, *x, *invite;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 char *room_jid;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 chat = jabber_chat_find_by_id(js, id);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 if(!chat)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 message = xmlnode_new("message");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 if(chat->muc) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 xmlnode_set_attrib(message, "to", room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 x = xmlnode_new_child(message, "x");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc#user");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 invite = xmlnode_new_child(x, "invite");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 xmlnode_set_attrib(invite, "to", name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 body = xmlnode_new_child(invite, "reason");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 xmlnode_insert_data(body, msg, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 xmlnode_set_attrib(message, "to", name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 body = xmlnode_new_child(message, "body");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 xmlnode_insert_data(body, msg, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 x = xmlnode_new_child(message, "x");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 xmlnode_set_attrib(x, "jid", room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 xmlnode_set_attrib(x, "xmlns", "jabber:x:conference");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 jabber_send(js, message);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 xmlnode_free(message);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 g_free(room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
173 void jabber_chat_member_free(JabberChatMember *jcm);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
174
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 void jabber_chat_join(GaimConnection *gc, GHashTable *data)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178 char *room, *server, *handle, *passwd;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 xmlnode *presence, *x;
7262
85fcaff1505d [gaim-migrate @ 7839]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
180 char *tmp, *room_jid, *full_jid;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
182
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183 room = g_hash_table_lookup(data, "room");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 server = g_hash_table_lookup(data, "server");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 handle = g_hash_table_lookup(data, "handle");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 passwd = g_hash_table_lookup(data, "password");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
188 if(!room || !server)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
191 if(!handle)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
192 handle = js->user->node;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
193
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
194 if(!jabber_nodeprep_validate(room)) {
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
195 char *buf = g_strdup_printf(_("%s is not a valid room name"), room);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
196 gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"),
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
197 buf);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
198 g_free(buf);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
199 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
200 } else if(!jabber_nameprep_validate(server)) {
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
201 char *buf = g_strdup_printf(_("%s is not a valid server name"), server);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
202 gaim_notify_error(gc, _("Invalid Server Name"),
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
203 _("Invalid Server Name"), buf);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
204 g_free(buf);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
205 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
206 } else if(!jabber_resourceprep_validate(handle)) {
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
207 char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
208 gaim_notify_error(gc, _("Invalid Room Handle"),
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
209 _("Invalid Room Handle"), buf);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
210 }
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7294
diff changeset
211
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 if(jabber_chat_find(js, room, server))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214
7262
85fcaff1505d [gaim-migrate @ 7839]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
215 tmp = g_strdup_printf("%s@%s", room, server);
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
216 room_jid = g_strdup(jabber_normalize(NULL, tmp));
7262
85fcaff1505d [gaim-migrate @ 7839]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
217 g_free(tmp);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 chat = g_new0(JabberChat, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 chat->js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 chat->room = g_strdup(room);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 chat->server = g_strdup(server);
8400
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
224 chat->handle = g_strdup(handle);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
226 chat->members = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
227 (GDestroyNotify)jabber_chat_member_free);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
228
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 g_hash_table_insert(js->chats, room_jid, chat);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230
7073
82e980962926 [gaim-migrate @ 7638]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
231 presence = jabber_presence_create(gc->away_state, gc->away);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 full_jid = g_strdup_printf("%s/%s", room_jid, handle);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 xmlnode_set_attrib(presence, "to", full_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 g_free(full_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 x = xmlnode_new_child(presence, "x");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 if(passwd && *passwd) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 xmlnode *password = xmlnode_new_child(x, "password");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 xmlnode_insert_data(password, passwd, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 jabber_send(js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 xmlnode_free(presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 void jabber_chat_leave(GaimConnection *gc, int id)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 JabberChat *chat = jabber_chat_find_by_id(js, id);
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
252
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 if(!chat)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
257 jabber_chat_part(chat, NULL);
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
258
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
259 chat->conv = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 void jabber_chat_destroy(JabberChat *chat)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 JabberStream *js = chat->js;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
267 g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 g_free(room_jid);
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
269 }
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
270
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
271 void jabber_chat_free(JabberChat *chat)
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
272 {
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
273 if(chat->config_dialog_handle)
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
274 gaim_request_close(chat->config_dialog_type, chat->config_dialog_handle);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 g_free(chat->room);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 g_free(chat->server);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 g_free(chat);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 {
9554
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9152
diff changeset
283 return gaim_conv_chat_find_user(GAIM_CONV_CHAT(conv), name);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285
7398
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
286 char *jabber_chat_buddy_real_name(GaimConnection *gc, int id, const char *who)
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
287 {
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
288 JabberStream *js = gc->proto_data;
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
289 JabberChat *chat;
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
290
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
291 chat = jabber_chat_find_by_id(js, id);
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
292
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
293 if(!chat)
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
294 return NULL;
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
295
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
296 return g_strdup_printf("%s@%s/%s", chat->room, chat->server, who);
d60e1629ffde [gaim-migrate @ 7994]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
297 }
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
298
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
299 static void jabber_chat_room_configure_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
300 {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
301 JabberChat *chat = data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
302 xmlnode *query;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
303 JabberIq *iq;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
304 char *to = g_strdup_printf("%s@%s", chat->room, chat->server);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
305
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
306 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "http://jabber.org/protocol/muc#owner");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
307 xmlnode_set_attrib(iq->node, "to", to);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
308 g_free(to);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
309
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
310 query = xmlnode_get_child(iq->node, "query");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
311
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
312 xmlnode_insert_child(query, result);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
313
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
314 jabber_iq_send(iq);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
315 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
316
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
317 static void jabber_chat_room_configure_cb(JabberStream *js, xmlnode *packet, gpointer data)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
318 {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
319 xmlnode *query, *x;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
320 const char *type = xmlnode_get_attrib(packet, "type");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
321 const char *from = xmlnode_get_attrib(packet, "from");
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
322 char *msg;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
323 JabberChat *chat;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
324 JabberID *jid;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
325
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
326 if(!type || !from)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
327 return;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
328
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
329
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
330
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
331 if(!strcmp(type, "result")) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
332 jid = jabber_id_new(from);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
333
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
334 if(!jid)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
335 return;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
336
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
337 chat = jabber_chat_find(js, jid->node, jid->domain);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
338 jabber_id_free(jid);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
339
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
340 if(!chat)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
341 return;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
342
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
343 if(!(query = xmlnode_get_child(packet, "query")))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
344 return;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
345
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
346 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) {
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
347 const char *xmlns;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
348 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
349 continue;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
350
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
351 if(!strcmp(xmlns, "jabber:x:data")) {
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
352 chat->config_dialog_type = GAIM_REQUEST_FIELDS;
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
353 chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
354 return;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
355 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
356 }
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
357 } else if(!strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
358 char *msg = jabber_parse_error(js, packet);
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
359
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
360 gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg);
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
361
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
362 if(msg)
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
363 g_free(msg);
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
364 return;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
365 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
366
7926
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
367 msg = g_strdup_printf("Unable to configure room %s", from);
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
368
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
369 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg);
68900f9cb540 [gaim-migrate @ 8597]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
370 g_free(msg);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
371
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
372 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
373
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
374 void jabber_chat_request_room_configure(JabberChat *chat) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
375 JabberIq *iq;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
376 xmlnode *query;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
377 char *room_jid;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
378
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
379 if(!chat)
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
380 return;
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
381
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
382 chat->config_dialog_handle = NULL;
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
383
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
384 if(!chat->muc) {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
385 gaim_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"),
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
386 _("This room is not capable of being configured"));
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
387 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
388 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
389
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
390 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
391 "http://jabber.org/protocol/muc#owner");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
392 query = xmlnode_get_child(iq->node, "query");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
393 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
394
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
395 xmlnode_set_attrib(iq->node, "to", room_jid);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
396
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
397 jabber_iq_set_callback(iq, jabber_chat_room_configure_cb, NULL);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
398
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
399 jabber_iq_send(iq);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
400
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
401 g_free(room_jid);
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
402 }
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
403
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
404 void jabber_chat_create_instant_room(JabberChat *chat) {
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
405 JabberIq *iq;
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
406 xmlnode *query, *x;
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
407 char *room_jid;
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
408
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
409 if(!chat)
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
410 return;
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
411
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
412 chat->config_dialog_handle = NULL;
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8261
diff changeset
413
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
414 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
415 "http://jabber.org/protocol/muc#owner");
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
416 query = xmlnode_get_child(iq->node, "query");
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
417 x = xmlnode_new_child(query, "x");
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
418 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
419
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
420 xmlnode_set_attrib(iq->node, "to", room_jid);
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
421 xmlnode_set_attrib(x, "xmlns", "jabber:x:data");
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
422 xmlnode_set_attrib(x, "type", "submit");
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
423
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
424 jabber_iq_send(iq);
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
425
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
426 g_free(room_jid);
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7841
diff changeset
427 }
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
428
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
429 static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
430 {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
431 const char *type = xmlnode_get_attrib(packet, "type");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
432
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
433 if(type && !strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
434 char *msg = jabber_parse_error(js, packet);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
435
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
436 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
437
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
438 if(msg)
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
439 g_free(msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
440 return;
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
441 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
442 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
443
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
444 static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
445 {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
446 JabberChat *chat = data;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
447 xmlnode *query;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
448 JabberIq *iq;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
449 char *to = g_strdup_printf("%s@%s", chat->room, chat->server);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
450
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
451 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
452 xmlnode_set_attrib(iq->node, "to", to);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
453 g_free(to);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
454
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
455 query = xmlnode_get_child(iq->node, "query");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
456
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
457 xmlnode_insert_child(query, result);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
458
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
459 jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
460
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
461 jabber_iq_send(iq);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
462 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
463
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
464 static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
465 {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
466 xmlnode *query, *x;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
467 const char *type = xmlnode_get_attrib(packet, "type");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
468 const char *from = xmlnode_get_attrib(packet, "from");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
469 char *msg;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
470 JabberChat *chat;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
471 JabberID *jid;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
472
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
473 if(!type || !from)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
474 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
475
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
476 if(!strcmp(type, "result")) {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
477 jid = jabber_id_new(from);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
478
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
479 if(!jid)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
480 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
481
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
482 chat = jabber_chat_find(js, jid->node, jid->domain);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
483 jabber_id_free(jid);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
484
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
485 if(!chat)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
486 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
487
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
488 if(!(query = xmlnode_get_child(packet, "query")))
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
489 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
490
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
491 for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) {
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
492 const char *xmlns;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
493
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
494 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
495 continue;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
496
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
497 if(!strcmp(xmlns, "jabber:x:data")) {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
498 jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
499 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
500 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
501 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
502 } else if(!strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
503 char *msg = jabber_parse_error(js, packet);
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
504
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
505 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
506
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
507 if(msg)
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
508 g_free(msg);
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
509 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
510 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
511
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
512 msg = g_strdup_printf("Unable to configure room %s", from);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
513
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
514 gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
515 g_free(msg);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
516
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
517 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
518
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
519 void jabber_chat_register(JabberChat *chat)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
520 {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
521 JabberIq *iq;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
522 char *room_jid;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
523
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
524 if(!chat)
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
525 return;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
526
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
527 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
528
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
529 iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register");
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
530 xmlnode_set_attrib(iq->node, "to", room_jid);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
531 g_free(room_jid);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
532
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
533 jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
534
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
535 jabber_iq_send(iq);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
536 }
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
537
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
538 /* merge this with the function below when we get everyone on the same page wrt /commands */
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
539 void jabber_chat_change_topic(JabberChat *chat, const char *topic)
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
540 {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
541 if(topic && *topic) {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
542 JabberMessage *jm;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
543 jm = g_new0(JabberMessage, 1);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
544 jm->js = chat->js;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
545 jm->type = JABBER_MESSAGE_GROUPCHAT;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
546 jm->subject = gaim_markup_strip_html(topic);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
547 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
548 jabber_message_send(jm);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
549 jabber_message_free(jm);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
550 } else {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
551 const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv));
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
552 char *buf;
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7926
diff changeset
553
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
554 if(cur)
8261
7b57c3bd9db6 [gaim-migrate @ 8984]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
555 buf = g_strdup_printf(_("current topic is: %s"), cur);
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
556 else
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
557 buf = g_strdup(_("No topic is set"));
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
558 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf,
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
559 GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL));
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
560 g_free(buf);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
561 }
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
562
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
563 }
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
564
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
565 void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic)
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
566 {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
567 JabberStream *js = gc->proto_data;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
568 JabberChat *chat = jabber_chat_find_by_id(js, id);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
569
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
570 if(!chat)
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
571 return;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
572
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
573 jabber_chat_change_topic(chat, topic);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
574 }
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
575
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
576
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
577 void jabber_chat_change_nick(JabberChat *chat, const char *nick)
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
578 {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
579 xmlnode *presence;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
580 char *full_jid;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
581
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
582 if(!chat->muc) {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
583 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "",
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
584 _("Nick changing not supported in non-MUC chatrooms"),
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
585 GAIM_MESSAGE_SYSTEM, time(NULL));
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
586 return;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
587 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
588
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
589 presence = jabber_presence_create(chat->js->gc->away_state, chat->js->gc->away);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
590 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
591 xmlnode_set_attrib(presence, "to", full_jid);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
592 g_free(full_jid);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
593
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
594 jabber_send(chat->js, presence);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
595 xmlnode_free(presence);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
596 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
597
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
598 void jabber_chat_part(JabberChat *chat, const char *msg)
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
599 {
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
600 char *room_jid;
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
601 xmlnode *presence;
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
602
8537
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8401
diff changeset
603 room_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server,
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8401
diff changeset
604 chat->handle);
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
605 presence = xmlnode_new("presence");
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
606 xmlnode_set_attrib(presence, "to", room_jid);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
607 xmlnode_set_attrib(presence, "type", "unavailable");
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
608 if(msg) {
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
609 xmlnode *status = xmlnode_new_child(presence, "status");
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
610 xmlnode_insert_data(status, msg, -1);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
611 }
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
612 jabber_send(chat->js, presence);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
613 xmlnode_free(presence);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
614 g_free(room_jid);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
615 }
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
616
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
617 static void roomlist_disco_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
618 {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
619 xmlnode *query;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
620 xmlnode *item;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
621 const char *type;
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
622
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
623 if(!js->roomlist)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
624 return;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
625
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
626 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
627 char *err = jabber_parse_error(js,packet);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
628 gaim_notify_error(js->gc, _("Roomlist Error"),
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
629 _("Error retreiving roomlist"), err);
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
630 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
8120
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8113
diff changeset
631 gaim_roomlist_unref(js->roomlist);
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8113
diff changeset
632 js->roomlist = NULL;
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
633 g_free(err);
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
634 return;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
635 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
636
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
637 if(!(query = xmlnode_get_child(packet, "query"))) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
638 char *err = jabber_parse_error(js, packet);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
639 gaim_notify_error(js->gc, _("Roomlist Error"),
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
640 _("Error retreiving roomlist"), err);
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
641 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
8120
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8113
diff changeset
642 gaim_roomlist_unref(js->roomlist);
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8113
diff changeset
643 js->roomlist = NULL;
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
644 g_free(err);
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
645 return;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
646 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
647
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
648 for(item = xmlnode_get_child(query, "item"); item;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
649 item = xmlnode_get_next_twin(item)) {
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
650 const char *name;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
651 GaimRoomlistRoom *room;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
652 JabberID *jid;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
653
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
654 if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid"))))
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
655 continue;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
656 name = xmlnode_get_attrib(item, "name");
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
657
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
658
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
659 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, jid->node, NULL);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
660 gaim_roomlist_room_add_field(js->roomlist, room, jid->node);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
661 gaim_roomlist_room_add_field(js->roomlist, room, jid->domain);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
662 gaim_roomlist_room_add_field(js->roomlist, room, name ? name : "");
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
663 gaim_roomlist_room_add(js->roomlist, room);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
664
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
665 jabber_id_free(jid);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
666 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
667 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
668 gaim_roomlist_unref(js->roomlist);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
669 js->roomlist = NULL;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
670 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
671
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
672 static void roomlist_ok_cb(JabberStream *js, const char *server)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
673 {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
674 JabberIq *iq;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
675
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
676 if(!js->roomlist)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
677 return;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
678
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
679 if(!server || !*server) {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
680 gaim_notify_error(js->gc, _("Invalid Server"), _("Invalid Server"), NULL);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
681 return;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
682 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
683
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
684 gaim_roomlist_set_in_progress(js->roomlist, TRUE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
685
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
686 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items");
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
687
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
688 xmlnode_set_attrib(iq->node, "to", server);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
689
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
690 jabber_iq_set_callback(iq, roomlist_disco_result_cb, NULL);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
691
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
692 jabber_iq_send(iq);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
693 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
694
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
695 GaimRoomlist *jabber_roomlist_get_list(GaimConnection *gc)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
696 {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
697 JabberStream *js = gc->proto_data;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
698 GList *fields = NULL;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
699 GaimRoomlistField *f;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
700
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
701 if(js->roomlist)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
702 gaim_roomlist_unref(js->roomlist);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
703
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
704 js->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
705
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
706 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
707 fields = g_list_append(fields, f);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
708
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
709 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "server", TRUE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
710 fields = g_list_append(fields, f);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
711
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
712 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Description"), "description", FALSE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
713 fields = g_list_append(fields, f);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
714
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
715 gaim_roomlist_set_fields(js->roomlist, fields);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
716
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
717 gaim_request_input(gc, _("Enter a Conference Server"), _("Enter a Conference Server"),
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
718 _("Select a conference server to query"),
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
719 js->chat_servers ? js->chat_servers->data : "conference.jabber.org",
8697
725413cc9fb9 [gaim-migrate @ 9450]
Mark Doliner <mark@kingant.net>
parents: 8537
diff changeset
720 FALSE, FALSE, NULL,
725413cc9fb9 [gaim-migrate @ 9450]
Mark Doliner <mark@kingant.net>
parents: 8537
diff changeset
721 _("Find Rooms"), G_CALLBACK(roomlist_ok_cb), _("Cancel"), NULL, js);
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
722
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
723 return js->roomlist;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
724 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
725
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
726 void jabber_roomlist_cancel(GaimRoomlist *list)
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
727 {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
728 GaimConnection *gc;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
729 JabberStream *js;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
730
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
731 gc = gaim_account_get_connection(list->account);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
732 js = gc->proto_data;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
733
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
734 gaim_roomlist_set_in_progress(list, FALSE);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
735
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
736 if (js->roomlist == list) {
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
737 js->roomlist = NULL;
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
738 gaim_roomlist_unref(list);
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
739 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
740 }
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
741
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
742 void jabber_chat_member_free(JabberChatMember *jcm)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
743 {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
744 g_free(jcm->handle);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
745 g_free(jcm->jid);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
746 g_free(jcm);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
747 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
748
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
749 void jabber_chat_track_handle(JabberChat *chat, const char *handle,
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
750 const char *jid, const char *affiliation, const char *role)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
751 {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
752 JabberChatMember *jcm = g_new0(JabberChatMember, 1);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
753
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
754 jcm->handle = g_strdup(handle);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
755 jcm->jid = g_strdup(jid);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
756
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
757 g_hash_table_replace(chat->members, jcm->handle, jcm);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
758
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
759 /* XXX: keep track of role and affiliation */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
760 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
761
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
762 void jabber_chat_remove_handle(JabberChat *chat, const char *handle)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
763 {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
764 g_hash_table_remove(chat->members, handle);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
765 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
766
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
767 gboolean jabber_chat_ban_user(JabberChat *chat, const char *who, const char *why)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
768 {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
769 JabberIq *iq;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
770 JabberChatMember *jcm = g_hash_table_lookup(chat->members, who);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
771 char *to;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
772 xmlnode *query, *item, *reason;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
773
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
774 if(!jcm || !jcm->jid)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
775 return FALSE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
776
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
777 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
778 "http://jabber.org/protocol/muc#admin");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
779
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
780 to = g_strdup_printf("%s@%s", chat->room, chat->server);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
781 xmlnode_set_attrib(iq->node, "to", to);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
782 g_free(to);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
783
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
784 query = xmlnode_get_child(iq->node, "query");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
785 item = xmlnode_new_child(query, "item");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
786 xmlnode_set_attrib(item, "jid", jcm->jid);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
787 xmlnode_set_attrib(item, "affiliation", "outcast");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
788 if(why) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
789 reason = xmlnode_new_child(item, "reason");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
790 xmlnode_insert_data(reason, why, -1);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
791 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
792
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
793 jabber_iq_send(iq);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
794
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
795 return TRUE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
796 }
8113
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
797
d60272410bd5 [gaim-migrate @ 8817]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
798
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
799 gboolean jabber_chat_kick_user(JabberChat *chat, const char *who, const char *why)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
800 {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
801 JabberIq *iq;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
802 JabberChatMember *jcm = g_hash_table_lookup(chat->members, who);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
803 char *to;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
804 xmlnode *query, *item, *reason;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
805
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
806 if(!jcm || !jcm->jid)
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
807 return FALSE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
808
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
809 iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
810 "http://jabber.org/protocol/muc#admin");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
811
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
812 to = g_strdup_printf("%s@%s", chat->room, chat->server);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
813 xmlnode_set_attrib(iq->node, "to", to);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
814 g_free(to);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
815
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
816 query = xmlnode_get_child(iq->node, "query");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
817 item = xmlnode_new_child(query, "item");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
818 xmlnode_set_attrib(item, "jid", jcm->jid);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
819 xmlnode_set_attrib(item, "role", "none");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
820 if(why) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
821 reason = xmlnode_new_child(item, "reason");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
822 xmlnode_insert_data(reason, why, -1);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
823 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
824
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
825 jabber_iq_send(iq);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
826
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
827 return TRUE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
828 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
829
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
830
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
831