Mercurial > pidgin
annotate src/protocols/jabber/presence.c @ 14083:08dbb5912709
[gaim-migrate @ 16704]
#if 0 some of the MSN listen-for-connection code for file transfers.
It wasn't being used
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 11 Aug 2006 08:01:16 +0000 |
parents | 6fc412e59214 |
children |
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 { | |
13968 | 185 GaimBuddy *buddy = NULL; |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
186 |
13968 | 187 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
188 "subscribed"); | |
7014 | 189 |
13968 | 190 buddy = gaim_find_buddy(jap->gc->account, jap->who); |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
191 |
13968 | 192 if (buddy) { |
193 JabberBuddy *jb = NULL; | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
194 |
13968 | 195 jb = jabber_buddy_find(jap->js, jap->who, TRUE); |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
196 |
13968 | 197 if ((jb->subscription & JABBER_SUB_TO) == 0) { |
198 gaim_account_request_add(jap->gc->account, | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
199 jap->who, NULL, |
13968 | 200 NULL, NULL); |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
201 } else { |
13968 | 202 gaim_account_notify_added(jap->gc->account, |
203 jap->who, NULL, | |
204 NULL, NULL); | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
205 } |
13968 | 206 } else { |
207 gaim_account_request_add(jap->gc->account, jap->who, | |
208 NULL, NULL, NULL); | |
7014 | 209 } |
210 | |
211 g_free(jap->who); | |
212 g_free(jap); | |
213 } | |
214 | |
215 static void deny_add_cb(struct _jabber_add_permit *jap) | |
216 { | |
13968 | 217 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
218 "unsubscribed"); | |
7014 | 219 |
220 g_free(jap->who); | |
221 g_free(jap); | |
222 } | |
223 | |
10189 | 224 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
225 { | |
10941 | 226 JabberBuddy *jb = NULL; |
10189 | 227 GaimBuddy *b = NULL; |
10941 | 228 xmlnode *vcard, *photo, *binval; |
11127 | 229 char *text; |
11137 | 230 guchar *data; |
11127 | 231 gsize size; |
10189 | 232 const char *from = xmlnode_get_attrib(packet, "from"); |
233 | |
234 if(!from) | |
235 return; | |
236 | |
10941 | 237 jb = jabber_buddy_find(js, from, TRUE); |
238 | |
239 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
240 | |
10189 | 241 if((vcard = xmlnode_get_child(packet, "vCard")) || |
242 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
10941 | 243 if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
11361 | 244 (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
245 (text = xmlnode_get_data(binval))) || | |
246 (text = xmlnode_get_data(photo)))) { | |
11127 | 247 data = gaim_base64_decode(text, &size); |
10189 | 248 |
10941 | 249 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); |
250 if((b = gaim_find_buddy(js->gc->account, from))) { | |
251 unsigned char hashval[20]; | |
252 char hash[41], *p; | |
253 int i; | |
10189 | 254 |
13890 | 255 gaim_cipher_digest_region("sha1", data, size, |
10941 | 256 sizeof(hashval), hashval, NULL); |
257 p = hash; | |
258 for(i=0; i<20; i++, p+=2) | |
259 snprintf(p, 3, "%02x", hashval[i]); | |
260 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
10189 | 261 } |
13890 | 262 g_free(data); |
10941 | 263 g_free(text); |
10189 | 264 } |
265 } | |
266 } | |
267 | |
7014 | 268 void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
269 { | |
270 const char *from = xmlnode_get_attrib(packet, "from"); | |
271 const char *type = xmlnode_get_attrib(packet, "type"); | |
7944 | 272 const char *real_jid = NULL; |
9152 | 273 const char *affiliation = NULL; |
274 const char *role = NULL; | |
7014 | 275 char *status = NULL; |
276 int priority = 0; | |
277 JabberID *jid; | |
278 JabberChat *chat; | |
279 JabberBuddy *jb; | |
9954 | 280 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
9554 | 281 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
9846 | 282 gboolean delayed = FALSE; |
10189 | 283 GaimBuddy *b = NULL; |
7014 | 284 char *buddy_name; |
9954 | 285 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
7014 | 286 xmlnode *y; |
287 gboolean muc = FALSE; | |
10189 | 288 char *avatar_hash = NULL; |
7014 | 289 |
8043 | 290 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
291 return; | |
292 | |
293 if(!(jid = jabber_id_new(from))) | |
7280 | 294 return; |
295 | |
7014 | 296 if(jb->error_msg) { |
297 g_free(jb->error_msg); | |
298 jb->error_msg = NULL; | |
299 } | |
300 | |
7813 | 301 if(type && !strcmp(type, "error")) { |
8401 | 302 char *msg = jabber_parse_error(js, packet); |
7644 | 303 |
9954 | 304 state = JABBER_BUDDY_STATE_ERROR; |
8401 | 305 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
7813 | 306 } else if(type && !strcmp(type, "subscribe")) { |
7014 | 307 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
10949 | 308 char *msg; |
309 | |
310 msg = g_strdup_printf(_("The user %s wants to add %s to his or " | |
311 "her buddy list."), | |
312 from, gaim_account_get_username(js->gc->account)); | |
7014 | 313 jap->gc = js->gc; |
314 jap->who = g_strdup(from); | |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
315 jap->js = js; |
7014 | 316 |
10189 | 317 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
10116 | 318 jap, 2, |
12603
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
12285
diff
changeset
|
319 _("_Authorize"), G_CALLBACK(authorize_add_cb), |
e4e47871c373
[gaim-migrate @ 14938]
Richard Laager <rlaager@wiktel.com>
parents:
12285
diff
changeset
|
320 _("_Deny"), G_CALLBACK(deny_add_cb)); |
7014 | 321 g_free(msg); |
8043 | 322 jabber_id_free(jid); |
7145 | 323 return; |
7813 | 324 } else if(type && !strcmp(type, "subscribed")) { |
7014 | 325 /* we've been allowed to see their presence, but we don't care */ |
8043 | 326 jabber_id_free(jid); |
7014 | 327 return; |
12285
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
328 } else if(type && !strcmp(type, "unsubscribe")) { |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
329 /* 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
|
330 * might be better to add "unsubscribe" to the presence status |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
331 * if lower down, but I'm not sure. */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
332 /* they are unsubscribing from our presence, we don't care */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
333 /* Well, maybe just a little, we might want/need to start |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
334 * acknowledging this (and the others) at some point. */ |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
335 jabber_id_free(jid); |
af257d8679fe
[gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12265
diff
changeset
|
336 return; |
7014 | 337 } else { |
338 if((y = xmlnode_get_child(packet, "show"))) { | |
339 char *show = xmlnode_get_data(y); | |
12683 | 340 state = jabber_buddy_show_get_state(show); |
7014 | 341 g_free(show); |
342 } else { | |
9954 | 343 state = JABBER_BUDDY_STATE_ONLINE; |
7014 | 344 } |
345 } | |
346 | |
7310 | 347 |
7014 | 348 for(y = packet->child; y; y = y->next) { |
8135 | 349 if(y->type != XMLNODE_TYPE_TAG) |
7014 | 350 continue; |
351 | |
352 if(!strcmp(y->name, "status")) { | |
7615 | 353 g_free(status); |
7014 | 354 status = xmlnode_get_data(y); |
355 } else if(!strcmp(y->name, "priority")) { | |
356 char *p = xmlnode_get_data(y); | |
357 if(p) { | |
358 priority = atoi(p); | |
359 g_free(p); | |
360 } | |
361 } else if(!strcmp(y->name, "x")) { | |
13806 | 362 const char *xmlns = xmlnode_get_namespace(y); |
9846 | 363 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
9847 | 364 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
9846 | 365 delayed = TRUE; |
366 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { | |
7629 | 367 xmlnode *z; |
368 | |
7014 | 369 muc = TRUE; |
7629 | 370 if((z = xmlnode_get_child(y, "status"))) { |
371 const char *code = xmlnode_get_attrib(z, "code"); | |
372 if(code && !strcmp(code, "201")) { | |
13444 | 373 if((chat = jabber_chat_find(js, jid->node, jid->domain))) { |
374 chat->config_dialog_type = GAIM_REQUEST_ACTION; | |
375 chat->config_dialog_handle = | |
376 gaim_request_action(js->gc, | |
377 _("Create New Room"), | |
378 _("Create New Room"), | |
379 _("You are creating a new room. Would" | |
380 " you like to configure it, or" | |
381 " accept the default settings?"), | |
382 1, chat, 2, _("_Configure Room"), | |
383 G_CALLBACK(jabber_chat_request_room_configure), | |
384 _("_Accept Defaults"), | |
385 G_CALLBACK(jabber_chat_create_instant_room)); | |
386 } | |
7629 | 387 } |
388 } | |
7944 | 389 if((z = xmlnode_get_child(y, "item"))) { |
390 real_jid = xmlnode_get_attrib(z, "jid"); | |
9152 | 391 affiliation = xmlnode_get_attrib(z, "affiliation"); |
392 role = xmlnode_get_attrib(z, "role"); | |
9931 | 393 if(affiliation != NULL && !strcmp(affiliation, "owner")) |
394 flags |= GAIM_CBFLAGS_FOUNDER; | |
9743 | 395 if (role != NULL) { |
396 if (!strcmp(role, "moderator")) | |
9931 | 397 flags |= GAIM_CBFLAGS_OP; |
9743 | 398 else if (!strcmp(role, "participant")) |
9931 | 399 flags |= GAIM_CBFLAGS_VOICE; |
9743 | 400 } |
7944 | 401 } |
10189 | 402 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
403 xmlnode *photo = xmlnode_get_child(y, "photo"); | |
404 if(photo) { | |
405 if(avatar_hash) | |
406 g_free(avatar_hash); | |
407 avatar_hash = xmlnode_get_data(photo); | |
408 } | |
7014 | 409 } |
410 } | |
411 } | |
412 | |
413 | |
7322 | 414 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
8462 | 415 static int i = 1; |
7014 | 416 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
417 | |
9954 | 418 if(state == JABBER_BUDDY_STATE_ERROR) { |
8401 | 419 char *title, *msg = jabber_parse_error(js, packet); |
7014 | 420 |
7321 | 421 if(chat->conv) { |
8401 | 422 title = g_strdup_printf(_("Error in chat %s"), from); |
7321 | 423 serv_got_chat_left(js->gc, chat->id); |
424 } else { | |
8401 | 425 title = g_strdup_printf(_("Error joining chat %s"), from); |
7321 | 426 } |
8401 | 427 gaim_notify_error(js->gc, title, title, msg); |
428 g_free(title); | |
429 g_free(msg); | |
7014 | 430 |
431 jabber_chat_destroy(chat); | |
7310 | 432 jabber_id_free(jid); |
7615 | 433 g_free(status); |
8182 | 434 g_free(room_jid); |
10189 | 435 if(avatar_hash) |
436 g_free(avatar_hash); | |
7014 | 437 return; |
438 } | |
439 | |
440 | |
7813 | 441 if(type && !strcmp(type, "unavailable")) { |
7972 | 442 gboolean nick_change = FALSE; |
7973 | 443 |
9152 | 444 /* If we haven't joined the chat yet, we don't care that someone |
445 * left, or it was us leaving after we closed the chat */ | |
8182 | 446 if(!chat->conv) { |
10558 | 447 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
9152 | 448 jabber_chat_destroy(chat); |
8182 | 449 jabber_id_free(jid); |
450 g_free(status); | |
451 g_free(room_jid); | |
10189 | 452 if(avatar_hash) |
453 g_free(avatar_hash); | |
8182 | 454 return; |
455 } | |
456 | |
7973 | 457 jabber_buddy_remove_resource(jb, jid->resource); |
7972 | 458 if(chat->muc) { |
459 xmlnode *x; | |
8135 | 460 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
7972 | 461 const char *xmlns, *nick, *code; |
462 xmlnode *stat, *item; | |
13806 | 463 if(!(xmlns = xmlnode_get_namespace(x)) || |
7972 | 464 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) |
465 continue; | |
466 if(!(stat = xmlnode_get_child(x, "status"))) | |
467 continue; | |
9152 | 468 if(!(code = xmlnode_get_attrib(stat, "code"))) |
7972 | 469 continue; |
9152 | 470 if(!strcmp(code, "301")) { |
471 /* XXX: we got banned */ | |
472 } else if(!strcmp(code, "303")) { | |
473 if(!(item = xmlnode_get_child(x, "item"))) | |
474 continue; | |
475 if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
476 continue; | |
477 nick_change = TRUE; | |
478 if(!strcmp(jid->resource, chat->handle)) { | |
479 g_free(chat->handle); | |
480 chat->handle = g_strdup(nick); | |
481 } | |
482 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
483 jabber_chat_remove_handle(chat, jid->resource); | |
484 break; | |
485 } else if(!strcmp(code, "307")) { | |
486 /* XXX: we got kicked */ | |
487 } else if(!strcmp(code, "321")) { | |
488 /* XXX: removed due to an affiliation change */ | |
489 } else if(!strcmp(code, "322")) { | |
490 /* XXX: removed because room is now members-only */ | |
491 } else if(!strcmp(code, "332")) { | |
492 /* XXX: removed due to system shutdown */ | |
8401 | 493 } |
7972 | 494 } |
495 } | |
496 if(!nick_change) { | |
9152 | 497 if(!g_utf8_collate(jid->resource, chat->handle)) { |
7972 | 498 serv_got_chat_left(js->gc, chat->id); |
499 jabber_chat_destroy(chat); | |
500 } else { | |
501 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
7974 | 502 status); |
9152 | 503 jabber_chat_remove_handle(chat, jid->resource); |
7972 | 504 } |
7014 | 505 } |
506 } else { | |
8182 | 507 if(!chat->conv) { |
508 chat->id = i++; | |
509 chat->muc = muc; | |
510 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
10722 | 511 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); |
10486 | 512 |
10941 | 513 jabber_chat_disco_traffic(chat); |
8182 | 514 } |
515 | |
7973 | 516 jabber_buddy_track_resource(jb, jid->resource, priority, state, |
517 status); | |
518 | |
9152 | 519 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
520 | |
7014 | 521 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
522 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
9846 | 523 real_jid, flags, !delayed); |
9554 | 524 else |
525 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
526 flags); | |
7014 | 527 } |
528 g_free(room_jid); | |
529 } else { | |
7322 | 530 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
531 jid->node ? "@" : "", jid->domain); | |
7014 | 532 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
533 jabber_id_free(jid); | |
10189 | 534 if(avatar_hash) |
535 g_free(avatar_hash); | |
7014 | 536 g_free(buddy_name); |
7615 | 537 g_free(status); |
7014 | 538 return; |
539 } | |
540 | |
10189 | 541 if(avatar_hash) { |
542 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
543 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
544 JabberIq *iq; | |
545 xmlnode *vcard; | |
546 | |
10941 | 547 /* XXX this is a crappy way of trying to prevent |
548 * someone from spamming us with presence packets | |
549 * and causing us to DoS ourselves...what we really | |
550 * need is a queue system that can throttle itself, | |
551 * but i'm too tired to write that right now */ | |
552 if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
553 | |
554 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
10189 | 555 |
10941 | 556 iq = jabber_iq_new(js, JABBER_IQ_GET); |
557 xmlnode_set_attrib(iq->node, "to", buddy_name); | |
558 vcard = xmlnode_new_child(iq->node, "vCard"); | |
13806 | 559 xmlnode_set_namespace(vcard, "vcard-temp"); |
10941 | 560 |
561 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
562 jabber_iq_send(iq); | |
563 } | |
10189 | 564 } |
565 } | |
566 | |
9954 | 567 if(state == JABBER_BUDDY_STATE_ERROR || |
7813 | 568 (type && (!strcmp(type, "unavailable") || |
569 !strcmp(type, "unsubscribed")))) { | |
8043 | 570 GaimConversation *conv; |
571 | |
7014 | 572 jabber_buddy_remove_resource(jb, jid->resource); |
8043 | 573 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
574 gaim_conversation_set_name(conv, buddy_name); | |
575 | |
7395 | 576 } else { |
9954 | 577 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
578 state, status); | |
7395 | 579 } |
7014 | 580 |
9954 | 581 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
582 if(!jbr || jbr == found_jbr) { | |
9990 | 583 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 | 584 } |
585 } else { | |
9990 | 586 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
9954 | 587 } |
7014 | 588 g_free(buddy_name); |
589 } | |
590 g_free(status); | |
591 jabber_id_free(jid); | |
10189 | 592 if(avatar_hash) |
593 g_free(avatar_hash); | |
7014 | 594 } |
595 | |
596 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
597 { | |
598 xmlnode *presence = xmlnode_new("presence"); | |
599 | |
600 xmlnode_set_attrib(presence, "to", who); | |
601 xmlnode_set_attrib(presence, "type", type); | |
602 | |
603 jabber_send(js, presence); | |
604 xmlnode_free(presence); | |
605 } | |
9954 | 606 |
607 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
608 { | |
10216 | 609 const char *status_id = NULL; |
610 | |
13442 | 611 if(state) *state = JABBER_BUDDY_STATE_UNKNOWN; |
612 if(msg) *msg = NULL; | |
613 if(priority) *priority = 0; | |
9954 | 614 |
615 if(!status) { | |
13442 | 616 if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
10216 | 617 } else { |
618 if(state) { | |
619 status_id = gaim_status_get_id(status); | |
620 *state = jabber_buddy_status_id_get_state(status_id); | |
621 } | |
622 | |
13496
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
623 if(msg) { |
10216 | 624 *msg = gaim_status_get_attr_string(status, "message"); |
625 | |
13496
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
626 /* 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
|
627 if(*msg && !**msg) |
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
628 *msg = NULL; |
d2aadcdbec6c
[gaim-migrate @ 15872]
Richard Laager <rlaager@wiktel.com>
parents:
13444
diff
changeset
|
629 } |
11872 | 630 |
10216 | 631 if(priority) |
632 *priority = gaim_status_get_attr_int(status, "priority"); | |
9954 | 633 } |
634 } |