annotate src/protocols/jabber/presence.c @ 12302:1b6167be6e58

[gaim-migrate @ 14606] I think this was leaking committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 03 Dec 2005 17:57:38 +0000
parents af257d8679fe
children e4e47871c373
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
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents: 10646
diff changeset
23 #include "cipher.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "debug.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "notify.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "request.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "server.h"
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
28 #include "status.h"
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7015
diff changeset
29 #include "util.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "buddy.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include "chat.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include "presence.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 #include "iq.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 #include "jutil.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 #include "xmlnode.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 static void chats_send_presence_foreach(gpointer key, gpointer val,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 gpointer user_data)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 JabberChat *chat = val;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 xmlnode *presence = user_data;
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
44 char *chat_full_jid;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
45
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
46 if(!chat->conv)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
47 return;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
48
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8462
diff changeset
49 chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server,
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
50 chat->handle);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
52 xmlnode_set_attrib(presence, "to", chat_full_jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 jabber_send(chat->js, presence);
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
54 g_free(chat_full_jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
57 void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) {
10286
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
58 char *my_base_jid;
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
59
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
60 if(!js->user)
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
61 return;
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
62
ff5e0f059924 [gaim-migrate @ 11460]
Nathan Walp <nwalp@pidgin.im>
parents: 10216
diff changeset
63 my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
8185
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
64 if(gaim_find_buddy(js->gc->account, my_base_jid)) {
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
65 JabberBuddy *jb;
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
66 JabberBuddyResource *jbr;
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
67 if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
68 JabberBuddyState state;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
69 const char *msg;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
70 int priority;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
71
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
72 gaim_status_to_jabber(gstatus, &state, &msg, &priority);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
73
10490
a3a540ed2518 [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 10486
diff changeset
74 if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) {
9744
9a17c90ba190 [gaim-migrate @ 10609]
Luke Schierer <lschiere@pidgin.im>
parents: 9743
diff changeset
75 jabber_buddy_remove_resource(jb, js->user->resource);
9a17c90ba190 [gaim-migrate @ 10609]
Luke Schierer <lschiere@pidgin.im>
parents: 9743
diff changeset
76 } else {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
77 jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg);
9744
9a17c90ba190 [gaim-migrate @ 10609]
Luke Schierer <lschiere@pidgin.im>
parents: 9743
diff changeset
78 }
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
79 if((jbr = jabber_buddy_find_resource(jb, NULL))) {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
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
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
81 } else {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
82 gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
83 }
8185
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
84 }
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
85 }
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
86 g_free(my_base_jid);
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
87 }
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
88
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
90 void jabber_presence_send(GaimAccount *account, GaimStatus *status)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
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
ad9a61894d9b [gaim-migrate @ 13420]
Mark Doliner <mark@kingant.net>
parents: 11183
diff changeset
94 gboolean disconnected;
10755
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
95 int primitive;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
96 xmlnode *presence, *x, *photo;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 char *stripped = NULL;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
98 const char *msg;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
99 JabberBuddyState state;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
100 int priority;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101
10486
84bc372a621e [gaim-migrate @ 11776]
Nathan Walp <nwalp@pidgin.im>
parents: 10382
diff changeset
102 if(!gaim_status_is_active(status))
84bc372a621e [gaim-migrate @ 11776]
Nathan Walp <nwalp@pidgin.im>
parents: 10382
diff changeset
103 return;
84bc372a621e [gaim-migrate @ 11776]
Nathan Walp <nwalp@pidgin.im>
parents: 10382
diff changeset
104
11251
ad9a61894d9b [gaim-migrate @ 13420]
Mark Doliner <mark@kingant.net>
parents: 11183
diff changeset
105 disconnected = gaim_account_is_disconnected(account);
10755
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
106 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status));
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
107
11251
ad9a61894d9b [gaim-migrate @ 13420]
Mark Doliner <mark@kingant.net>
parents: 11183
diff changeset
108 if(disconnected)
10755
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
109 return;
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
110
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
111 gc = gaim_account_get_connection(account);
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
112 js = gc->proto_data;
fffc664d5294 [gaim-migrate @ 12358]
Mark Doliner <mark@kingant.net>
parents: 10738
diff changeset
113
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
114 gaim_status_to_jabber(status, &state, &msg, &priority);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
115
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
119 presence = jabber_presence_create(state, stripped, priority);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
120 g_free(stripped);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
122 if(js->avatar_hash) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
123 x = xmlnode_new_child(presence, "x");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
124 xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
125 photo = xmlnode_new_child(x, "photo");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
126 xmlnode_insert_data(photo, js->avatar_hash, -1);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
127 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
128
12265
f82b6d559ea7 [gaim-migrate @ 14567]
Nathan Walp <nwalp@pidgin.im>
parents: 11872
diff changeset
129 jabber_send(js, presence);
f82b6d559ea7 [gaim-migrate @ 14567]
Nathan Walp <nwalp@pidgin.im>
parents: 11872
diff changeset
130
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 xmlnode_free(presence);
8185
3a229ad2fab0 [gaim-migrate @ 8906]
Nathan Walp <nwalp@pidgin.im>
parents: 8182
diff changeset
133
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
134 jabber_presence_fake_to_self(js, status);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
137 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 {
11568
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
139 xmlnode *show, *status, *presence, *pri;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
140 const char *show_string = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141
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 presence = xmlnode_new("presence");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
146 if(state == JABBER_BUDDY_STATE_UNAVAILABLE)
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
147 xmlnode_set_attrib(presence, "type", "unavailable");
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
148 else if(state != JABBER_BUDDY_STATE_ONLINE &&
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
149 state != JABBER_BUDDY_STATE_UNKNOWN &&
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
150 state != JABBER_BUDDY_STATE_ERROR)
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
151 show_string = jabber_buddy_state_get_status_id(state);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
152
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
153 if(show_string) {
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
154 show = xmlnode_new_child(presence, "show");
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
155 xmlnode_insert_data(show, show_string, -1);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
158 if(msg) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 status = xmlnode_new_child(presence, "status");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 xmlnode_insert_data(status, msg, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162
11568
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
163 if(priority) {
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
164 char *pstr = g_strdup_printf("%d", priority);
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
165 pri = xmlnode_new_child(presence, "priority");
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
166 xmlnode_insert_data(pri, pstr, -1);
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
167 g_free(pstr);
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
168 }
e36f0f9debb5 [gaim-migrate @ 13835]
Nathan Walp <nwalp@pidgin.im>
parents: 11361
diff changeset
169
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 return presence;
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173 struct _jabber_add_permit {
12285
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
174 JabberStream *js;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 GaimConnection *gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 char *who;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177 };
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 static void authorize_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
12285
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
182 GaimBuddy *buddy = NULL;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
183
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 "subscribed");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186
12285
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
187 buddy = gaim_find_buddy(jap->gc->account, jap->who);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
188
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
189 if (buddy) {
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
190 JabberBuddy *jb = NULL;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
191
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
192 jb = jabber_buddy_find(jap->js, jap->who, TRUE);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
193
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
194 if ((jb->subscription & JABBER_SUB_TO) == 0) {
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
195 gaim_account_request_add(jap->gc->account,
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
196 jap->who, NULL,
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
197 NULL, NULL);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
198 } else {
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
199 gaim_account_notify_added(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 }
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
203 } else {
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
204 gaim_account_request_add(jap->gc->account, jap->who,
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
205 NULL, NULL, NULL);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12265
diff changeset
206 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 static void deny_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 "unsubscribed");
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
224 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
225 {
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
226 JabberBuddy *jb = NULL;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
227 GaimBuddy *b = NULL;
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
228 xmlnode *vcard, *photo, *binval;
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
229 char *text;
11137
096020ae09a9 [gaim-migrate @ 13201]
Mark Doliner <mark@kingant.net>
parents: 11127
diff changeset
230 guchar *data;
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
231 gsize size;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
232 const char *from = xmlnode_get_attrib(packet, "from");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
233
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
234 if(!from)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
235 return;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
236
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
237 jb = jabber_buddy_find(js, from, TRUE);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
238
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
239 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
240
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
241 if((vcard = xmlnode_get_child(packet, "vCard")) ||
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
242 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
243 if((photo = xmlnode_get_child(vcard, "PHOTO")) &&
11361
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
244 (( (binval = xmlnode_get_child(photo, "BINVAL")) &&
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
245 (text = xmlnode_get_data(binval))) ||
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
246 (text = xmlnode_get_data(photo)))) {
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
247 data = gaim_base64_decode(text, &size);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
248
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
249 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
250 if((b = gaim_find_buddy(js->gc->account, from))) {
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
251 unsigned char hashval[20];
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
252 char hash[41], *p;
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
253 int i;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
254
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11137
diff changeset
255 gaim_cipher_digest_region("sha1", (guchar *)data, size,
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
256 sizeof(hashval), hashval, NULL);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
257 p = hash;
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
258 for(i=0; i<20; i++, p+=2)
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
259 snprintf(p, 3, "%02x", hashval[i]);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
260 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
261 }
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
262 g_free(text);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
263 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
264 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
265 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
266
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 const char *from = xmlnode_get_attrib(packet, "from");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 const char *type = xmlnode_get_attrib(packet, "type");
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
271 const char *real_jid = NULL;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
272 const char *affiliation = NULL;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
273 const char *role = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 char *status = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 int priority = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 JabberID *jid;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 JabberBuddy *jb;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
279 JabberBuddyResource *jbr = NULL, *found_jbr = NULL;
9554
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
280 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE;
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
281 gboolean delayed = FALSE;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
282 GaimBuddy *b = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 char *buddy_name;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
284 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 xmlnode *y;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 gboolean muc = FALSE;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
287 char *avatar_hash = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
290 if(!(jb = jabber_buddy_find(js, from, TRUE)))
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
291 return;
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
292
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
293 if(!(jid = jabber_id_new(from)))
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7273
diff changeset
294 return;
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7273
diff changeset
295
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 if(jb->error_msg) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 g_free(jb->error_msg);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 jb->error_msg = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
301 if(type && !strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
302 char *msg = jabber_parse_error(js, packet);
7644
4168b8881746 [gaim-migrate @ 8287]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
303
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
304 state = JABBER_BUDDY_STATE_ERROR;
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
305 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence"));
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
306 } else if(type && !strcmp(type, "subscribe")) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1);
10949
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
308 char *msg;
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
309
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
310 msg = g_strdup_printf(_("The user %s wants to add %s to his or "
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
311 "her buddy list."),
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
312 from, gaim_account_get_username(js->gc->account));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 jap->gc = js->gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
317 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE,
10116
9f358a718f38 [gaim-migrate @ 11153]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9990
diff changeset
318 jap, 2,
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 _("Authorize"), G_CALLBACK(authorize_add_cb),
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 _("Deny"), G_CALLBACK(deny_add_cb));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 g_free(msg);
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
322 jabber_id_free(jid);
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7124
diff changeset
323 return;
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
324 } else if(type && !strcmp(type, "subscribed")) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 /* we've been allowed to see their presence, but we don't care */
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
326 jabber_id_free(jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 if((y = xmlnode_get_child(packet, "show"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 char *show = xmlnode_get_data(y);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
340 state = jabber_buddy_status_id_get_state(show);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 g_free(show);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 } else {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
343 state = JABBER_BUDDY_STATE_ONLINE;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7280
diff changeset
347
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 for(y = packet->child; y; y = y->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
349 if(y->type != XMLNODE_TYPE_TAG)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 continue;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 if(!strcmp(y->name, "status")) {
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
353 g_free(status);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 status = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355 } else if(!strcmp(y->name, "priority")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 char *p = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 if(p) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 priority = atoi(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 g_free(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361 } else if(!strcmp(y->name, "x")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
362 const char *xmlns = xmlnode_get_attrib(y, "xmlns");
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
363 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
9847
ab097ff50f5b [gaim-migrate @ 10725]
Nathan Walp <nwalp@pidgin.im>
parents: 9846
diff changeset
364 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
365 delayed = TRUE;
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
366 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
7629
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
367 xmlnode *z;
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
368
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369 muc = TRUE;
7629
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
370 if((z = xmlnode_get_child(y, "status"))) {
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
371 const char *code = xmlnode_get_attrib(z, "code");
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
372 if(code && !strcmp(code, "201")) {
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
373 chat = jabber_chat_find(js, jid->node, jid->domain);
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
374 chat->config_dialog_type = GAIM_REQUEST_ACTION;
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
375 chat->config_dialog_handle =
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
376 gaim_request_action(js->gc, _("Create New Room"),
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
377 _("Create New Room"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
378 _("You are creating a new room. Would you like to "
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
379 "configure it, or accept the default settings?"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
380 1, chat, 2, _("Configure Room"),
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
381 G_CALLBACK(jabber_chat_request_room_configure),
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
382 _("Accept Defaults"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
383 G_CALLBACK(jabber_chat_create_instant_room));
7629
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
384 }
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
385 }
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
386 if((z = xmlnode_get_child(y, "item"))) {
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
387 real_jid = xmlnode_get_attrib(z, "jid");
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
388 affiliation = xmlnode_get_attrib(z, "affiliation");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
389 role = xmlnode_get_attrib(z, "role");
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
390 if(affiliation != NULL && !strcmp(affiliation, "owner"))
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
391 flags |= GAIM_CBFLAGS_FOUNDER;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
392 if (role != NULL) {
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
393 if (!strcmp(role, "moderator"))
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
394 flags |= GAIM_CBFLAGS_OP;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
395 else if (!strcmp(role, "participant"))
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
396 flags |= GAIM_CBFLAGS_VOICE;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
397 }
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
398 }
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
399 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
400 xmlnode *photo = xmlnode_get_child(y, "photo");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
401 if(photo) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
402 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
403 g_free(avatar_hash);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
404 avatar_hash = xmlnode_get_data(photo);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
405 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
407 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
408 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
409
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
410
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7321
diff changeset
411 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) {
8462
5a39fce812f4 [gaim-migrate @ 9192]
Nathan Walp <nwalp@pidgin.im>
parents: 8401
diff changeset
412 static int i = 1;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
413 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
414
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
415 if(state == JABBER_BUDDY_STATE_ERROR) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
416 char *title, *msg = jabber_parse_error(js, packet);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
417
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
418 if(chat->conv) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
419 title = g_strdup_printf(_("Error in chat %s"), from);
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
420 serv_got_chat_left(js->gc, chat->id);
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
421 } else {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
422 title = g_strdup_printf(_("Error joining chat %s"), from);
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
423 }
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
424 gaim_notify_error(js->gc, title, title, msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
425 g_free(title);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
426 g_free(msg);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
427
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
428 jabber_chat_destroy(chat);
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7280
diff changeset
429 jabber_id_free(jid);
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
430 g_free(status);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
431 g_free(room_jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
432 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
433 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
434 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
435 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
436
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
437
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
438 if(type && !strcmp(type, "unavailable")) {
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
439 gboolean nick_change = FALSE;
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
440
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
441 /* If we haven't joined the chat yet, we don't care that someone
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
442 * left, or it was us leaving after we closed the chat */
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
443 if(!chat->conv) {
10558
8bcf7909bec8 [gaim-migrate @ 11936]
Nathan Walp <nwalp@pidgin.im>
parents: 10490
diff changeset
444 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle))
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
445 jabber_chat_destroy(chat);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
446 jabber_id_free(jid);
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
447 g_free(status);
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
448 g_free(room_jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
449 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
450 g_free(avatar_hash);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
451 return;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
452 }
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
453
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
454 jabber_buddy_remove_resource(jb, jid->resource);
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
455 if(chat->muc) {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
456 xmlnode *x;
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
457 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) {
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
458 const char *xmlns, *nick, *code;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
459 xmlnode *stat, *item;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
460 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) ||
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
461 strcmp(xmlns, "http://jabber.org/protocol/muc#user"))
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
462 continue;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
463 if(!(stat = xmlnode_get_child(x, "status")))
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
464 continue;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
465 if(!(code = xmlnode_get_attrib(stat, "code")))
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
466 continue;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
467 if(!strcmp(code, "301")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
468 /* XXX: we got banned */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
469 } else if(!strcmp(code, "303")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
470 if(!(item = xmlnode_get_child(x, "item")))
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
471 continue;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
472 if(!(nick = xmlnode_get_attrib(item, "nick")))
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
473 continue;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
474 nick_change = TRUE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
475 if(!strcmp(jid->resource, chat->handle)) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
476 g_free(chat->handle);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
477 chat->handle = g_strdup(nick);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
478 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
479 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
480 jabber_chat_remove_handle(chat, jid->resource);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
481 break;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
482 } else if(!strcmp(code, "307")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
483 /* XXX: we got kicked */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
484 } else if(!strcmp(code, "321")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
485 /* XXX: removed due to an affiliation change */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
486 } else if(!strcmp(code, "322")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
487 /* XXX: removed because room is now members-only */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
488 } else if(!strcmp(code, "332")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
489 /* XXX: removed due to system shutdown */
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
490 }
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
491 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
492 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
493 if(!nick_change) {
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
494 if(!g_utf8_collate(jid->resource, chat->handle)) {
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
495 serv_got_chat_left(js->gc, chat->id);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
496 jabber_chat_destroy(chat);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
497 } else {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
498 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7973
diff changeset
499 status);
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
500 jabber_chat_remove_handle(chat, jid->resource);
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
501 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
502 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
503 } else {
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
504 if(!chat->conv) {
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
505 chat->id = i++;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
506 chat->muc = muc;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
507 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid);
10722
a14b82fc3a95 [gaim-migrate @ 12322]
Nathan Walp <nwalp@pidgin.im>
parents: 10721
diff changeset
508 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle);
10486
84bc372a621e [gaim-migrate @ 11776]
Nathan Walp <nwalp@pidgin.im>
parents: 10382
diff changeset
509
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
510 jabber_chat_disco_traffic(chat);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
511 }
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
512
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
513 jabber_buddy_track_resource(jb, jid->resource, priority, state,
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
514 status);
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
515
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
516 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
517
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
518 if(!jabber_chat_find_buddy(chat->conv, jid->resource))
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7095
diff changeset
519 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
520 real_jid, flags, !delayed);
9554
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
521 else
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
522 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource,
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
523 flags);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
524 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
525 g_free(room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
526 } else {
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7321
diff changeset
527 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7321
diff changeset
528 jid->node ? "@" : "", jid->domain);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
529 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
530 jabber_id_free(jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
531 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
532 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
533 g_free(buddy_name);
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
534 g_free(status);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
535 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
536 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
537
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
538 if(avatar_hash) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
539 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
540 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
541 JabberIq *iq;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
542 xmlnode *vcard;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
543
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
544 /* XXX this is a crappy way of trying to prevent
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
545 * someone from spamming us with presence packets
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
546 * and causing us to DoS ourselves...what we really
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
547 * need is a queue system that can throttle itself,
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
548 * but i'm too tired to write that right now */
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
549 if(!g_slist_find(js->pending_avatar_requests, jb)) {
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
550
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
551 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
552
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
553 iq = jabber_iq_new(js, JABBER_IQ_GET);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
554 xmlnode_set_attrib(iq->node, "to", buddy_name);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
555 vcard = xmlnode_new_child(iq->node, "vCard");
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
556 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp");
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
557
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
558 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
559 jabber_iq_send(iq);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
560 }
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
561 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
562 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
563
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
564 if(state == JABBER_BUDDY_STATE_ERROR ||
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
565 (type && (!strcmp(type, "unavailable") ||
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
566 !strcmp(type, "unsubscribed")))) {
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
567 GaimConversation *conv;
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
568
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
569 jabber_buddy_remove_resource(jb, jid->resource);
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
570 if((conv = jabber_find_unnormalized_conv(from, js->gc->account)))
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
571 gaim_conversation_set_name(conv, buddy_name);
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
572
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
573 } else {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
574 jbr = jabber_buddy_track_resource(jb, jid->resource, priority,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
575 state, status);
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
576 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
577
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
578 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
579 if(!jbr || jbr == found_jbr) {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
580 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
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
581 }
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
582 } else {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
583 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
584 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
585 g_free(buddy_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
586 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
587 g_free(status);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
588 jabber_id_free(jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
589 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
590 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
591 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
592
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
593 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
594 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
595 xmlnode *presence = xmlnode_new("presence");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
596
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
597 xmlnode_set_attrib(presence, "to", who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
598 xmlnode_set_attrib(presence, "type", type);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
599
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
600 jabber_send(js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
601 xmlnode_free(presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
602 }
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
603
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
604 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority)
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
605 {
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
606 const char *status_id = NULL;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
607
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
608 *state = JABBER_BUDDY_STATE_UNKNOWN;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
609 *msg = NULL;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
610 *priority = 0;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
611
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
612 if(!status) {
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
613 *state = JABBER_BUDDY_STATE_UNAVAILABLE;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
614 } else {
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
615 if(state) {
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
616 status_id = gaim_status_get_id(status);
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
617 *state = jabber_buddy_status_id_get_state(status_id);
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
618 }
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
619
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
620 if(msg)
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
621 *msg = gaim_status_get_attr_string(status, "message");
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
622
11872
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
623 /* if the message is blank, then there really isn't a message */
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
624 if(*msg && !**msg)
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
625 *msg = NULL;
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
626
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
627 if(priority)
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
628 *priority = gaim_status_get_attr_int(status, "priority");
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
629 }
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
630
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
631 }