Mercurial > pidgin
annotate src/protocols/jabber/chat.c @ 7262:85fcaff1505d
[gaim-migrate @ 7839]
put normalizing back in the realm of sanity (what was I thinking?) and fix
jabber chat case sensitivity (as well as a few other things)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 14 Oct 2003 16:44:36 +0000 |
parents | bf630f7dfdcd |
children | 89e211509d02 |
rev | line source |
---|---|
7014 | 1 /* |
2 * gaim - Jabber Protocol Plugin | |
3 * | |
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 #include "internal.h" | |
22 #include "debug.h" | |
23 #include "multi.h" /* for proto_chat_entry */ | |
24 | |
25 #include "chat.h" | |
26 #include "message.h" | |
7073 | 27 #include "presence.h" |
7014 | 28 |
29 GList *jabber_chat_info(GaimConnection *gc) | |
30 { | |
31 GList *m = NULL; | |
32 struct proto_chat_entry *pce; | |
33 JabberStream *js = gc->proto_data; | |
34 | |
35 pce = g_new0(struct proto_chat_entry, 1); | |
36 pce->label = _("Room:"); | |
37 pce->identifier = "room"; | |
38 m = g_list_append(m, pce); | |
39 | |
40 /* we're gonna default to a conference server I know is true, until | |
41 * I can figure out how to disco for a chat server */ | |
42 pce = g_new0(struct proto_chat_entry, 1); | |
43 pce->label = _("Server:"); | |
44 pce->identifier = "server"; | |
45 pce->def = "conference.jabber.org"; | |
46 m = g_list_append(m, pce); | |
47 | |
48 pce = g_new0(struct proto_chat_entry, 1); | |
49 pce->label = _("Handle:"); | |
50 pce->identifier = "handle"; | |
51 pce->def = js->user->node; | |
52 m = g_list_append(m, pce); | |
53 | |
54 pce = g_new0(struct proto_chat_entry, 1); | |
55 pce->label = _("Password:"); | |
56 pce->identifier = "password"; | |
57 pce->secret = TRUE; | |
58 m = g_list_append(m, pce); | |
59 | |
60 return m; | |
61 } | |
62 | |
63 JabberChat *jabber_chat_find(JabberStream *js, const char *room, | |
64 const char *server) | |
65 { | |
66 JabberChat *chat; | |
67 char *room_jid; | |
68 | |
69 room_jid = g_strdup_printf("%s@%s", room, server); | |
70 | |
7262 | 71 chat = g_hash_table_lookup(js->chats, jabber_normalize(room_jid)); |
7014 | 72 g_free(room_jid); |
73 | |
74 return chat; | |
75 } | |
76 | |
77 struct _find_by_id_data { | |
78 int id; | |
79 JabberChat *chat; | |
80 }; | |
81 | |
82 void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data) | |
83 { | |
84 JabberChat *chat = value; | |
85 struct _find_by_id_data *fbid = user_data; | |
86 | |
87 if(chat->id == fbid->id) | |
88 fbid->chat = chat; | |
89 } | |
90 | |
91 JabberChat *jabber_chat_find_by_id(JabberStream *js, int id) | |
92 { | |
93 JabberChat *chat; | |
94 struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1); | |
7073 | 95 fbid->id = id; |
7014 | 96 g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid); |
97 chat = fbid->chat; | |
98 g_free(fbid); | |
99 return chat; | |
100 } | |
101 | |
102 void jabber_chat_invite(GaimConnection *gc, int id, const char *msg, | |
103 const char *name) | |
104 { | |
105 JabberStream *js = gc->proto_data; | |
106 JabberChat *chat; | |
107 xmlnode *message, *body, *x, *invite; | |
108 char *room_jid; | |
109 | |
110 chat = jabber_chat_find_by_id(js, id); | |
111 if(!chat) | |
112 return; | |
113 | |
114 message = xmlnode_new("message"); | |
115 | |
116 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
117 | |
118 if(chat->muc) { | |
119 xmlnode_set_attrib(message, "to", room_jid); | |
120 x = xmlnode_new_child(message, "x"); | |
121 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc#user"); | |
122 invite = xmlnode_new_child(x, "invite"); | |
123 xmlnode_set_attrib(invite, "to", name); | |
124 body = xmlnode_new_child(invite, "reason"); | |
125 xmlnode_insert_data(body, msg, -1); | |
126 } else { | |
127 xmlnode_set_attrib(message, "to", name); | |
128 body = xmlnode_new_child(message, "body"); | |
129 xmlnode_insert_data(body, msg, -1); | |
130 x = xmlnode_new_child(message, "x"); | |
131 xmlnode_set_attrib(x, "jid", room_jid); | |
132 xmlnode_set_attrib(x, "xmlns", "jabber:x:conference"); | |
133 } | |
134 | |
135 jabber_send(js, message); | |
136 xmlnode_free(message); | |
137 g_free(room_jid); | |
138 } | |
139 | |
140 void jabber_chat_whisper(GaimConnection *gc, int id, const char *who, | |
141 const char *message) | |
142 { | |
143 JabberStream *js = gc->proto_data; | |
144 JabberChat *chat; | |
145 char *full_jid; | |
146 | |
147 chat = jabber_chat_find_by_id(js, id); | |
148 | |
149 /* TODO: we get real Jabber IDs from MUC sometimes, we need to cache | |
150 * them eventually */ | |
151 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); | |
152 | |
153 jabber_message_send_im(gc, full_jid, message, 0); | |
154 | |
155 g_free(full_jid); | |
156 } | |
157 | |
158 void jabber_chat_join(GaimConnection *gc, GHashTable *data) | |
159 { | |
160 JabberChat *chat; | |
161 char *room, *server, *handle, *passwd; | |
162 xmlnode *presence, *x; | |
7262 | 163 char *tmp, *room_jid, *full_jid; |
7014 | 164 JabberStream *js = gc->proto_data; |
165 | |
166 room = g_hash_table_lookup(data, "room"); | |
167 server = g_hash_table_lookup(data, "server"); | |
168 handle = g_hash_table_lookup(data, "handle"); | |
169 passwd = g_hash_table_lookup(data, "password"); | |
170 | |
171 if(!room || !server || !handle) | |
172 return; | |
173 | |
174 if(jabber_chat_find(js, room, server)) | |
175 return; | |
176 | |
7262 | 177 tmp = g_strdup_printf("%s@%s", room, server); |
178 room_jid = g_strdup(jabber_normalize(tmp)); | |
179 g_free(tmp); | |
7014 | 180 |
181 chat = g_new0(JabberChat, 1); | |
182 chat->js = gc->proto_data; | |
183 | |
184 chat->room = g_strdup(room); | |
185 chat->server = g_strdup(server); | |
186 chat->nick = g_strdup(handle); | |
187 | |
188 g_hash_table_insert(js->chats, room_jid, chat); | |
189 | |
7073 | 190 presence = jabber_presence_create(gc->away_state, gc->away); |
7014 | 191 full_jid = g_strdup_printf("%s/%s", room_jid, handle); |
192 xmlnode_set_attrib(presence, "to", full_jid); | |
193 g_free(full_jid); | |
194 | |
195 x = xmlnode_new_child(presence, "x"); | |
196 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc"); | |
197 | |
198 if(passwd && *passwd) { | |
199 xmlnode *password = xmlnode_new_child(x, "password"); | |
200 xmlnode_insert_data(password, passwd, -1); | |
201 } | |
202 | |
203 jabber_send(js, presence); | |
204 xmlnode_free(presence); | |
205 } | |
206 | |
207 void jabber_chat_leave(GaimConnection *gc, int id) | |
208 { | |
209 JabberStream *js = gc->proto_data; | |
210 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
211 char *room_jid; | |
212 xmlnode *presence; | |
213 | |
214 if(!chat) | |
215 return; | |
216 | |
217 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
218 gaim_debug(GAIM_DEBUG_INFO, "jabber", "%s is leaving chat %s\n", | |
219 chat->nick, room_jid); | |
220 presence = xmlnode_new("presence"); | |
221 xmlnode_set_attrib(presence, "to", room_jid); | |
222 xmlnode_set_attrib(presence, "type", "unavailable"); | |
223 jabber_send(js, presence); | |
224 xmlnode_free(presence); | |
225 } | |
226 | |
227 void jabber_chat_destroy(JabberChat *chat) | |
228 { | |
229 JabberStream *js = chat->js; | |
230 char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
231 | |
7262 | 232 g_hash_table_remove(js->chats, jabber_normalize(room_jid)); |
7014 | 233 g_free(room_jid); |
234 | |
235 g_free(chat->room); | |
236 g_free(chat->server); | |
237 g_free(chat->nick); | |
238 g_free(chat); | |
239 } | |
240 | |
241 gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name) | |
242 { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7073
diff
changeset
|
243 GList *m = gaim_conv_chat_get_users(GAIM_CONV_CHAT(conv)); |
7014 | 244 |
245 while(m) { | |
246 if(!strcmp(m->data, name)) | |
247 return TRUE; | |
248 m = m->next; | |
249 } | |
250 | |
251 return FALSE; | |
252 } | |
253 |