Mercurial > pidgin
annotate src/protocols/jabber/presence.c @ 13806:25e63008d3bb
[gaim-migrate @ 16229]
Use libxml2 for XML parsing, if available. The biggest benefit from this is actual support for XML namespaces. This fixes a handful of Google Talk integration problems, including typing notifications and buddy icons.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 08 Jun 2006 01:03:51 +0000 |
parents | d2aadcdbec6c |
children | 2bac009eaa0c |
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 | |
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10646
diff
changeset
|
23 #include "cipher.h" |
7014 | 24 #include "debug.h" |
25 #include "notify.h" | |
26 #include "request.h" | |
27 #include "server.h" | |
9954 | 28 #include "status.h" |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
29 #include "util.h" |
7014 | 30 |
31 #include "buddy.h" | |
32 #include "chat.h" | |
33 #include "presence.h" | |
34 #include "iq.h" | |
35 #include "jutil.h" | |
36 #include "xmlnode.h" | |
37 | |
38 | |
39 static void chats_send_presence_foreach(gpointer key, gpointer val, | |
40 gpointer user_data) | |
41 { | |
42 JabberChat *chat = val; | |
43 xmlnode *presence = user_data; | |
8577 | 44 char *chat_full_jid; |
45 | |
46 if(!chat->conv) | |
47 return; | |
48 | |
49 chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, | |
8401 | 50 chat->handle); |
7014 | 51 |
8401 | 52 xmlnode_set_attrib(presence, "to", chat_full_jid); |
7014 | 53 jabber_send(chat->js, presence); |
8401 | 54 g_free(chat_full_jid); |
7014 | 55 } |
56 | |
9954 | 57 void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) { |
10286 | 58 char *my_base_jid; |
59 | |
60 if(!js->user) | |
61 return; | |
62 | |
63 my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
8185 | 64 if(gaim_find_buddy(js->gc->account, my_base_jid)) { |
65 JabberBuddy *jb; | |
66 JabberBuddyResource *jbr; | |
67 if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) { | |
9954 | 68 JabberBuddyState state; |
69 const char *msg; | |
70 int priority; | |
71 | |
72 gaim_status_to_jabber(gstatus, &state, &msg, &priority); | |
73 | |
10490 | 74 if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { |
9744 | 75 jabber_buddy_remove_resource(jb, js->user->resource); |
76 } else { | |
9954 | 77 jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); |
9744 | 78 } |
9954 | 79 if((jbr = jabber_buddy_find_resource(jb, NULL))) { |
9990 | 80 gaim_prpl_got_user_status(js->gc->account, my_base_jid, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
9954 | 81 } else { |
9990 | 82 gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); |
9954 | 83 } |
8185 | 84 } |
85 } | |
86 g_free(my_base_jid); | |
87 } | |
88 | |
7014 | 89 |
10216 | 90 void jabber_presence_send(GaimAccount *account, GaimStatus *status) |
7014 | 91 { |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
92 GaimConnection *gc = NULL; |
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
93 JabberStream *js = NULL; |
11251 | 94 gboolean disconnected; |
10755 | 95 int primitive; |
10189 | 96 xmlnode *presence, *x, *photo; |
7014 | 97 char *stripped = NULL; |
9954 | 98 const char *msg; |
99 JabberBuddyState state; | |
100 int priority; | |
7014 | 101 |
10486 | 102 if(!gaim_status_is_active(status)) |
103 return; | |
104 | |
11251 | 105 disconnected = gaim_account_is_disconnected(account); |
10755 | 106 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
107 | |
11251 | 108 if(disconnected) |
10755 | 109 return; |
110 | |
111 gc = gaim_account_get_connection(account); | |
112 js = gc->proto_data; | |
113 | |
9954 | 114 gaim_status_to_jabber(status, &state, &msg, &priority); |
115 | |
116 if(msg) | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
117 gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
7014 | 118 |
9954 | 119 presence = jabber_presence_create(state, stripped, priority); |
120 g_free(stripped); | |
7014 | 121 |
10189 | 122 if(js->avatar_hash) { |
123 x = xmlnode_new_child(presence, "x"); | |
13806 | 124 xmlnode_set_namespace(x, "vcard-temp:x:update"); |
10189 | 125 photo = xmlnode_new_child(x, "photo"); |
126 xmlnode_insert_data(photo, js->avatar_hash, -1); | |
127 } | |
128 | |
12265 | 129 jabber_send(js, presence); |
130 | |
7014 | 131 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
132 xmlnode_free(presence); | |
8185 | 133 |
9954 | 134 jabber_presence_fake_to_self(js, status); |
7014 | 135 } |
136 | |
9954 | 137 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
7014 | 138 { |
13384 | 139 xmlnode *show, *status, *presence, *pri, *c; |
9954 | 140 const char *show_string = NULL; |
7014 | 141 |
142 presence = xmlnode_new("presence"); | |
143 | |
9954 | 144 if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
145 xmlnode_set_attrib(presence, "type", "unavailable"); | |
146 else if(state != JABBER_BUDDY_STATE_ONLINE && | |
147 state != JABBER_BUDDY_STATE_UNKNOWN && | |
148 state != JABBER_BUDDY_STATE_ERROR) | |
12683 | 149 show_string = jabber_buddy_state_get_show(state); |
9954 | 150 |
151 if(show_string) { | |
152 show = xmlnode_new_child(presence, "show"); | |
153 xmlnode_insert_data(show, show_string, -1); | |
7014 | 154 } |
155 | |
9954 | 156 if(msg) { |
7014 | 157 status = xmlnode_new_child(presence, "status"); |
158 xmlnode_insert_data(status, msg, -1); | |
159 } | |
160 | |
11568 | 161 if(priority) { |
162 char *pstr = g_strdup_printf("%d", priority); | |
163 pri = xmlnode_new_child(presence, "priority"); | |
164 xmlnode_insert_data(pri, pstr, -1); | |
165 g_free(pstr); | |
166 } | |
167 | |
13384 | 168 /* JEP-0115 */ |
169 c = xmlnode_new_child(presence, "c"); | |
13806 | 170 xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); |
13384 | 171 xmlnode_set_attrib(c, "node", CAPS0115_NODE); |
172 xmlnode_set_attrib(c, "ver", VERSION); | |
173 | |
7014 | 174 return presence; |
175 } | |
176 | |
177 struct _jabber_add_permit { | |
13213
371f353f7d99
[gaim-migrate @ 15577]
Evan Schoenberg <evan.s@dreskin.net>
parents:
12683
diff
changeset
|
178 GaimConnection *gc; |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
179 JabberStream *js; |
7014 | 180 char *who; |
181 }; | |
182 | |
183 static void authorize_add_cb(struct _jabber_add_permit *jap) | |
184 { | |
185 if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
186 GaimBuddy *buddy = NULL; |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
187 |
7014 | 188 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
189 "subscribed"); | |
190 | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
191 buddy = gaim_find_buddy(jap->gc->account, jap->who); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
192 |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
193 if (buddy) { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
194 JabberBuddy *jb = NULL; |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
195 |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
196 jb = jabber_buddy_find(jap->js, jap->who, TRUE); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
197 |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
198 if ((jb->subscription & JABBER_SUB_TO) == 0) { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
199 gaim_account_request_add(jap->gc->account, |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
200 jap->who, NULL, |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
201 NULL, NULL); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
202 } else { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
203 gaim_account_notify_added(jap->gc->account, |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
204 jap->who, NULL, |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
205 NULL, NULL); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
206 } |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
207 } else { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
208 gaim_account_request_add(jap->gc->account, jap->who, |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
209 NULL, NULL, NULL); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
210 } |
7014 | 211 } |
212 | |
213 g_free(jap->who); | |
214 g_free(jap); | |
215 } | |
216 | |
217 static void deny_add_cb(struct _jabber_add_permit *jap) | |
218 { | |
219 if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
220 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
221 "unsubscribed"); | |
222 } | |
223 | |
224 g_free(jap->who); | |
225 g_free(jap); | |
226 } | |
227 | |
10189 | 228 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
229 { | |
10941 | 230 JabberBuddy *jb = NULL; |
10189 | 231 GaimBuddy *b = NULL; |
10941 | 232 xmlnode *vcard, *photo, *binval; |
11127 | 233 char *text; |
11137 | 234 guchar *data; |
11127 | 235 gsize size; |
10189 | 236 const char *from = xmlnode_get_attrib(packet, "from"); |
237 | |
238 if(!from) | |
239 return; | |
240 | |
10941 | 241 jb = jabber_buddy_find(js, from, TRUE); |
242 | |
243 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
244 | |
10189 | 245 if((vcard = xmlnode_get_child(packet, "vCard")) || |
246 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
10941 | 247 if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
11361 | 248 (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
249 (text = xmlnode_get_data(binval))) || | |
250 (text = xmlnode_get_data(photo)))) { | |
11127 | 251 data = gaim_base64_decode(text, &size); |
10189 | 252 |
10941 | 253 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); |
254 if((b = gaim_find_buddy(js->gc->account, from))) { | |
255 unsigned char hashval[20]; | |
256 char hash[41], *p; | |
257 int i; | |
10189 | 258 |
11183 | 259 gaim_cipher_digest_region("sha1", (guchar *)data, size, |
10941 | 260 sizeof(hashval), hashval, NULL); |
261 p = hash; | |
262 for(i=0; i<20; i++, p+=2) | |
263 snprintf(p, 3, "%02x", hashval[i]); | |
264 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
10189 | 265 } |
10941 | 266 g_free(text); |
10189 | 267 } |
268 } | |
269 } | |
270 | |
7014 | 271 void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
272 { | |
273 const char *from = xmlnode_get_attrib(packet, "from"); | |
274 const char *type = xmlnode_get_attrib(packet, "type"); | |
7944 | 275 const char *real_jid = NULL; |
9152 | 276 const char *affiliation = NULL; |
277 const char *role = NULL; | |
7014 | 278 char *status = NULL; |
279 int priority = 0; | |
280 JabberID *jid; | |
281 JabberChat *chat; | |
282 JabberBuddy *jb; | |
9954 | 283 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
9554 | 284 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
9846 | 285 gboolean delayed = FALSE; |
10189 | 286 GaimBuddy *b = NULL; |
7014 | 287 char *buddy_name; |
9954 | 288 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
7014 | 289 xmlnode *y; |
290 gboolean muc = FALSE; | |
10189 | 291 char *avatar_hash = NULL; |
7014 | 292 |
8043 | 293 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
294 return; | |
295 | |
296 if(!(jid = jabber_id_new(from))) | |
7280 | 297 return; |
298 | |
7014 | 299 if(jb->error_msg) { |
300 g_free(jb->error_msg); | |
301 jb->error_msg = NULL; | |
302 } | |
303 | |
7813 | 304 if(type && !strcmp(type, "error")) { |
8401 | 305 char *msg = jabber_parse_error(js, packet); |
7644 | 306 |
9954 | 307 state = JABBER_BUDDY_STATE_ERROR; |
8401 | 308 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
7813 | 309 } else if(type && !strcmp(type, "subscribe")) { |
7014 | 310 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
10949 | 311 char *msg; |
312 | |
313 msg = g_strdup_printf(_("The user %s wants to add %s to his or " | |
314 "her buddy list."), | |
315 from, gaim_account_get_username(js->gc->account)); | |
7014 | 316 jap->gc = js->gc; |
317 jap->who = g_strdup(from); | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
318 jap->js = js; |
7014 | 319 |
10189 | 320 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
10116 | 321 jap, 2, |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
12285
diff
changeset
|
322 _("_Authorize"), G_CALLBACK(authorize_add_cb), |
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
12285
diff
changeset
|
323 _("_Deny"), G_CALLBACK(deny_add_cb)); |
7014 | 324 g_free(msg); |
8043 | 325 jabber_id_free(jid); |
7145 | 326 return; |
7813 | 327 } else if(type && !strcmp(type, "subscribed")) { |
7014 | 328 /* we've been allowed to see their presence, but we don't care */ |
8043 | 329 jabber_id_free(jid); |
7014 | 330 return; |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
331 } else if(type && !strcmp(type, "unsubscribe")) { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
332 /* XXX I'm not sure this is the right way to handle this, it |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
333 * might be better to add "unsubscribe" to the presence status |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
334 * if lower down, but I'm not sure. */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
335 /* they are unsubscribing from our presence, we don't care */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
336 /* Well, maybe just a little, we might want/need to start |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
337 * acknowledging this (and the others) at some point. */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
338 jabber_id_free(jid); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
339 return; |
7014 | 340 } else { |
341 if((y = xmlnode_get_child(packet, "show"))) { | |
342 char *show = xmlnode_get_data(y); | |
12683 | 343 state = jabber_buddy_show_get_state(show); |
7014 | 344 g_free(show); |
345 } else { | |
9954 | 346 state = JABBER_BUDDY_STATE_ONLINE; |
7014 | 347 } |
348 } | |
349 | |
7310 | 350 |
7014 | 351 for(y = packet->child; y; y = y->next) { |
8135 | 352 if(y->type != XMLNODE_TYPE_TAG) |
7014 | 353 continue; |
354 | |
355 if(!strcmp(y->name, "status")) { | |
7615 | 356 g_free(status); |
7014 | 357 status = xmlnode_get_data(y); |
358 } else if(!strcmp(y->name, "priority")) { | |
359 char *p = xmlnode_get_data(y); | |
360 if(p) { | |
361 priority = atoi(p); | |
362 g_free(p); | |
363 } | |
364 } else if(!strcmp(y->name, "x")) { | |
13806 | 365 const char *xmlns = xmlnode_get_namespace(y); |
9846 | 366 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
9847 | 367 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
9846 | 368 delayed = TRUE; |
369 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { | |
7629 | 370 xmlnode *z; |
371 | |
7014 | 372 muc = TRUE; |
7629 | 373 if((z = xmlnode_get_child(y, "status"))) { |
374 const char *code = xmlnode_get_attrib(z, "code"); | |
375 if(code && !strcmp(code, "201")) { | |
13444 | 376 if((chat = jabber_chat_find(js, jid->node, jid->domain))) { |
377 chat->config_dialog_type = GAIM_REQUEST_ACTION; | |
378 chat->config_dialog_handle = | |
379 gaim_request_action(js->gc, | |
380 _("Create New Room"), | |
381 _("Create New Room"), | |
382 _("You are creating a new room. Would" | |
383 " you like to configure it, or" | |
384 " accept the default settings?"), | |
385 1, chat, 2, _("_Configure Room"), | |
386 G_CALLBACK(jabber_chat_request_room_configure), | |
387 _("_Accept Defaults"), | |
388 G_CALLBACK(jabber_chat_create_instant_room)); | |
389 } | |
7629 | 390 } |
391 } | |
7944 | 392 if((z = xmlnode_get_child(y, "item"))) { |
393 real_jid = xmlnode_get_attrib(z, "jid"); | |
9152 | 394 affiliation = xmlnode_get_attrib(z, "affiliation"); |
395 role = xmlnode_get_attrib(z, "role"); | |
9931 | 396 if(affiliation != NULL && !strcmp(affiliation, "owner")) |
397 flags |= GAIM_CBFLAGS_FOUNDER; | |
9743 | 398 if (role != NULL) { |
399 if (!strcmp(role, "moderator")) | |
9931 | 400 flags |= GAIM_CBFLAGS_OP; |
9743 | 401 else if (!strcmp(role, "participant")) |
9931 | 402 flags |= GAIM_CBFLAGS_VOICE; |
9743 | 403 } |
7944 | 404 } |
10189 | 405 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
406 xmlnode *photo = xmlnode_get_child(y, "photo"); | |
407 if(photo) { | |
408 if(avatar_hash) | |
409 g_free(avatar_hash); | |
410 avatar_hash = xmlnode_get_data(photo); | |
411 } | |
7014 | 412 } |
413 } | |
414 } | |
415 | |
416 | |
7322 | 417 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
8462 | 418 static int i = 1; |
7014 | 419 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
420 | |
9954 | 421 if(state == JABBER_BUDDY_STATE_ERROR) { |
8401 | 422 char *title, *msg = jabber_parse_error(js, packet); |
7014 | 423 |
7321 | 424 if(chat->conv) { |
8401 | 425 title = g_strdup_printf(_("Error in chat %s"), from); |
7321 | 426 serv_got_chat_left(js->gc, chat->id); |
427 } else { | |
8401 | 428 title = g_strdup_printf(_("Error joining chat %s"), from); |
7321 | 429 } |
8401 | 430 gaim_notify_error(js->gc, title, title, msg); |
431 g_free(title); | |
432 g_free(msg); | |
7014 | 433 |
434 jabber_chat_destroy(chat); | |
7310 | 435 jabber_id_free(jid); |
7615 | 436 g_free(status); |
8182 | 437 g_free(room_jid); |
10189 | 438 if(avatar_hash) |
439 g_free(avatar_hash); | |
7014 | 440 return; |
441 } | |
442 | |
443 | |
7813 | 444 if(type && !strcmp(type, "unavailable")) { |
7972 | 445 gboolean nick_change = FALSE; |
7973 | 446 |
9152 | 447 /* If we haven't joined the chat yet, we don't care that someone |
448 * left, or it was us leaving after we closed the chat */ | |
8182 | 449 if(!chat->conv) { |
10558 | 450 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
9152 | 451 jabber_chat_destroy(chat); |
8182 | 452 jabber_id_free(jid); |
453 g_free(status); | |
454 g_free(room_jid); | |
10189 | 455 if(avatar_hash) |
456 g_free(avatar_hash); | |
8182 | 457 return; |
458 } | |
459 | |
7973 | 460 jabber_buddy_remove_resource(jb, jid->resource); |
7972 | 461 if(chat->muc) { |
462 xmlnode *x; | |
8135 | 463 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
7972 | 464 const char *xmlns, *nick, *code; |
465 xmlnode *stat, *item; | |
13806 | 466 if(!(xmlns = xmlnode_get_namespace(x)) || |
7972 | 467 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) |
468 continue; | |
469 if(!(stat = xmlnode_get_child(x, "status"))) | |
470 continue; | |
9152 | 471 if(!(code = xmlnode_get_attrib(stat, "code"))) |
7972 | 472 continue; |
9152 | 473 if(!strcmp(code, "301")) { |
474 /* XXX: we got banned */ | |
475 } else if(!strcmp(code, "303")) { | |
476 if(!(item = xmlnode_get_child(x, "item"))) | |
477 continue; | |
478 if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
479 continue; | |
480 nick_change = TRUE; | |
481 if(!strcmp(jid->resource, chat->handle)) { | |
482 g_free(chat->handle); | |
483 chat->handle = g_strdup(nick); | |
484 } | |
485 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
486 jabber_chat_remove_handle(chat, jid->resource); | |
487 break; | |
488 } else if(!strcmp(code, "307")) { | |
489 /* XXX: we got kicked */ | |
490 } else if(!strcmp(code, "321")) { | |
491 /* XXX: removed due to an affiliation change */ | |
492 } else if(!strcmp(code, "322")) { | |
493 /* XXX: removed because room is now members-only */ | |
494 } else if(!strcmp(code, "332")) { | |
495 /* XXX: removed due to system shutdown */ | |
8401 | 496 } |
7972 | 497 } |
498 } | |
499 if(!nick_change) { | |
9152 | 500 if(!g_utf8_collate(jid->resource, chat->handle)) { |
7972 | 501 serv_got_chat_left(js->gc, chat->id); |
502 jabber_chat_destroy(chat); | |
503 } else { | |
504 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
7974 | 505 status); |
9152 | 506 jabber_chat_remove_handle(chat, jid->resource); |
7972 | 507 } |
7014 | 508 } |
509 } else { | |
8182 | 510 if(!chat->conv) { |
511 chat->id = i++; | |
512 chat->muc = muc; | |
513 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
10722 | 514 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); |
10486 | 515 |
10941 | 516 jabber_chat_disco_traffic(chat); |
8182 | 517 } |
518 | |
7973 | 519 jabber_buddy_track_resource(jb, jid->resource, priority, state, |
520 status); | |
521 | |
9152 | 522 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
523 | |
7014 | 524 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
525 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
9846 | 526 real_jid, flags, !delayed); |
9554 | 527 else |
528 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
529 flags); | |
7014 | 530 } |
531 g_free(room_jid); | |
532 } else { | |
7322 | 533 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
534 jid->node ? "@" : "", jid->domain); | |
7014 | 535 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
536 jabber_id_free(jid); | |
10189 | 537 if(avatar_hash) |
538 g_free(avatar_hash); | |
7014 | 539 g_free(buddy_name); |
7615 | 540 g_free(status); |
7014 | 541 return; |
542 } | |
543 | |
10189 | 544 if(avatar_hash) { |
545 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
546 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
547 JabberIq *iq; | |
548 xmlnode *vcard; | |
549 | |
10941 | 550 /* XXX this is a crappy way of trying to prevent |
551 * someone from spamming us with presence packets | |
552 * and causing us to DoS ourselves...what we really | |
553 * need is a queue system that can throttle itself, | |
554 * but i'm too tired to write that right now */ | |
555 if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
556 | |
557 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
10189 | 558 |
10941 | 559 iq = jabber_iq_new(js, JABBER_IQ_GET); |
560 xmlnode_set_attrib(iq->node, "to", buddy_name); | |
561 vcard = xmlnode_new_child(iq->node, "vCard"); | |
13806 | 562 xmlnode_set_namespace(vcard, "vcard-temp"); |
10941 | 563 |
564 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
565 jabber_iq_send(iq); | |
566 } | |
10189 | 567 } |
568 } | |
569 | |
9954 | 570 if(state == JABBER_BUDDY_STATE_ERROR || |
7813 | 571 (type && (!strcmp(type, "unavailable") || |
572 !strcmp(type, "unsubscribed")))) { | |
8043 | 573 GaimConversation *conv; |
574 | |
7014 | 575 jabber_buddy_remove_resource(jb, jid->resource); |
8043 | 576 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
577 gaim_conversation_set_name(conv, buddy_name); | |
578 | |
7395 | 579 } else { |
9954 | 580 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
581 state, status); | |
7395 | 582 } |
7014 | 583 |
9954 | 584 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
585 if(!jbr || jbr == found_jbr) { | |
9990 | 586 gaim_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(state), "priority", found_jbr->priority, found_jbr->status ? "message" : NULL, found_jbr->status, NULL); |
9954 | 587 } |
588 } else { | |
9990 | 589 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
9954 | 590 } |
7014 | 591 g_free(buddy_name); |
592 } | |
593 g_free(status); | |
594 jabber_id_free(jid); | |
10189 | 595 if(avatar_hash) |
596 g_free(avatar_hash); | |
7014 | 597 } |
598 | |
599 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
600 { | |
601 xmlnode *presence = xmlnode_new("presence"); | |
602 | |
603 xmlnode_set_attrib(presence, "to", who); | |
604 xmlnode_set_attrib(presence, "type", type); | |
605 | |
606 jabber_send(js, presence); | |
607 xmlnode_free(presence); | |
608 } | |
9954 | 609 |
610 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
611 { | |
10216 | 612 const char *status_id = NULL; |
613 | |
13442 | 614 if(state) *state = JABBER_BUDDY_STATE_UNKNOWN; |
615 if(msg) *msg = NULL; | |
616 if(priority) *priority = 0; | |
9954 | 617 |
618 if(!status) { | |
13442 | 619 if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
10216 | 620 } else { |
621 if(state) { | |
622 status_id = gaim_status_get_id(status); | |
623 *state = jabber_buddy_status_id_get_state(status_id); | |
624 } | |
625 | |
13496
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
626 if(msg) { |
10216 | 627 *msg = gaim_status_get_attr_string(status, "message"); |
628 | |
13496
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
629 /* if the message is blank, then there really isn't a message */ |
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
630 if(*msg && !**msg) |
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
631 *msg = NULL; |
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
632 } |
11872 | 633 |
10216 | 634 if(priority) |
635 *priority = gaim_status_get_attr_int(status, "priority"); | |
9954 | 636 } |
637 } |