Mon, 25 Jun 2007 02:56:32 +0000
this fixes a bug where:
Resource A comes online, as available
Resource B comes online, as available
Resource A goes away
Resource B goes away, with a lower priority than A
Buddy is still shown as available
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 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 | ||
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
23 | #include "account.h" |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10646
diff
changeset
|
24 | #include "cipher.h" |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
25 | #include "conversation.h" |
| 7014 | 26 | #include "debug.h" |
| 27 | #include "notify.h" | |
| 28 | #include "request.h" | |
| 29 | #include "server.h" | |
| 9954 | 30 | #include "status.h" |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
31 | #include "util.h" |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
32 | #include "xmlnode.h" |
| 7014 | 33 | |
| 34 | #include "buddy.h" | |
| 35 | #include "chat.h" | |
| 36 | #include "presence.h" | |
| 37 | #include "iq.h" | |
| 38 | #include "jutil.h" | |
| 39 | ||
| 40 | ||
| 41 | static void chats_send_presence_foreach(gpointer key, gpointer val, | |
| 42 | gpointer user_data) | |
| 43 | { | |
| 44 | JabberChat *chat = val; | |
| 45 | xmlnode *presence = user_data; | |
| 8577 | 46 | char *chat_full_jid; |
| 47 | ||
| 48 | if(!chat->conv) | |
| 49 | return; | |
| 50 | ||
| 51 | chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, | |
| 8401 | 52 | chat->handle); |
| 7014 | 53 | |
| 8401 | 54 | xmlnode_set_attrib(presence, "to", chat_full_jid); |
| 7014 | 55 | jabber_send(chat->js, presence); |
| 8401 | 56 | g_free(chat_full_jid); |
| 7014 | 57 | } |
| 58 | ||
| 15884 | 59 | void jabber_presence_fake_to_self(JabberStream *js, const PurpleStatus *gstatus) { |
| 10286 | 60 | char *my_base_jid; |
| 61 | ||
| 62 | if(!js->user) | |
| 63 | return; | |
| 64 | ||
| 65 | my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
| 15884 | 66 | if(purple_find_buddy(js->gc->account, my_base_jid)) { |
| 8185 | 67 | JabberBuddy *jb; |
| 68 | JabberBuddyResource *jbr; | |
| 69 | if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) { | |
| 9954 | 70 | JabberBuddyState state; |
| 14525 | 71 | char *msg; |
| 9954 | 72 | int priority; |
| 73 | ||
| 15884 | 74 | purple_status_to_jabber(gstatus, &state, &msg, &priority); |
| 9954 | 75 | |
| 10490 | 76 | if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
77 | jabber_buddy_remove_resource(jb, js->user->resource); |
|
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
78 | } else { |
| 9954 | 79 | jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
80 | } |
| 9954 | 81 | if((jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 15884 | 82 | purple_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 | 83 | } else { |
| 15884 | 84 | purple_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); |
| 9954 | 85 | } |
| 14525 | 86 | |
| 87 | g_free(msg); | |
| 8185 | 88 | } |
| 89 | } | |
| 90 | g_free(my_base_jid); | |
| 91 | } | |
| 92 | ||
| 7014 | 93 | |
| 15884 | 94 | void jabber_presence_send(PurpleAccount *account, PurpleStatus *status) |
| 7014 | 95 | { |
| 15884 | 96 | PurpleConnection *gc = NULL; |
|
10382
32e07712e224
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
97 | JabberStream *js = NULL; |
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
98 | gboolean disconnected; |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
99 | int primitive; |
| 10189 | 100 | xmlnode *presence, *x, *photo; |
| 7014 | 101 | char *stripped = NULL; |
| 9954 | 102 | JabberBuddyState state; |
| 103 | int priority; | |
| 7014 | 104 | |
|
18195
9cd0565f856e
kill some code duplication when sending current presence
Nathan Walp <nwalp@pidgin.im>
parents:
17703
diff
changeset
|
105 | if(NULL == status) { |
|
9cd0565f856e
kill some code duplication when sending current presence
Nathan Walp <nwalp@pidgin.im>
parents:
17703
diff
changeset
|
106 | PurplePresence *gpresence = purple_account_get_presence(account); |
|
9cd0565f856e
kill some code duplication when sending current presence
Nathan Walp <nwalp@pidgin.im>
parents:
17703
diff
changeset
|
107 | status = purple_presence_get_active_status(gpresence); |
|
9cd0565f856e
kill some code duplication when sending current presence
Nathan Walp <nwalp@pidgin.im>
parents:
17703
diff
changeset
|
108 | } |
|
9cd0565f856e
kill some code duplication when sending current presence
Nathan Walp <nwalp@pidgin.im>
parents:
17703
diff
changeset
|
109 | |
| 15884 | 110 | if(!purple_status_is_active(status)) |
| 10486 | 111 | return; |
| 112 | ||
| 15884 | 113 | disconnected = purple_account_is_disconnected(account); |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
114 | |
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
115 | if(disconnected) |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
116 | return; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
117 | |
| 17422 | 118 | primitive = purple_status_type_get_primitive(purple_status_get_type(status)); |
| 119 | ||
| 15884 | 120 | gc = purple_account_get_connection(account); |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
121 | js = gc->proto_data; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
122 | |
|
18226
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
123 | /* we don't want to send presence before we've gotten our roster */ |
|
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
124 | if(!js->roster_parsed) { |
|
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
125 | purple_debug_info("jabber", "attempt to send presence before roster retrieved\n"); |
|
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
126 | return; |
|
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
127 | } |
|
adf83935e838
really and truly enforce the no-presence-before-roster thing
Nathan Walp <nwalp@pidgin.im>
parents:
18195
diff
changeset
|
128 | |
| 15884 | 129 | purple_status_to_jabber(status, &state, &stripped, &priority); |
| 9954 | 130 | |
| 7014 | 131 | |
| 9954 | 132 | presence = jabber_presence_create(state, stripped, priority); |
| 133 | g_free(stripped); | |
| 7014 | 134 | |
| 10189 | 135 | if(js->avatar_hash) { |
| 136 | x = xmlnode_new_child(presence, "x"); | |
| 13808 | 137 | xmlnode_set_namespace(x, "vcard-temp:x:update"); |
| 10189 | 138 | photo = xmlnode_new_child(x, "photo"); |
| 139 | xmlnode_insert_data(photo, js->avatar_hash, -1); | |
| 140 | } | |
| 141 | ||
| 12265 | 142 | jabber_send(js, presence); |
| 143 | ||
| 7014 | 144 | g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
| 145 | xmlnode_free(presence); | |
| 8185 | 146 | |
| 9954 | 147 | jabber_presence_fake_to_self(js, status); |
| 7014 | 148 | } |
| 149 | ||
| 9954 | 150 | xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
| 7014 | 151 | { |
| 13385 | 152 | xmlnode *show, *status, *presence, *pri, *c; |
| 9954 | 153 | const char *show_string = NULL; |
| 7014 | 154 | |
| 155 | presence = xmlnode_new("presence"); | |
| 156 | ||
| 9954 | 157 | if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
| 158 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 159 | else if(state != JABBER_BUDDY_STATE_ONLINE && | |
| 160 | state != JABBER_BUDDY_STATE_UNKNOWN && | |
| 161 | state != JABBER_BUDDY_STATE_ERROR) | |
| 12683 | 162 | show_string = jabber_buddy_state_get_show(state); |
| 9954 | 163 | |
| 164 | if(show_string) { | |
| 165 | show = xmlnode_new_child(presence, "show"); | |
| 166 | xmlnode_insert_data(show, show_string, -1); | |
| 7014 | 167 | } |
| 168 | ||
| 9954 | 169 | if(msg) { |
| 7014 | 170 | status = xmlnode_new_child(presence, "status"); |
| 171 | xmlnode_insert_data(status, msg, -1); | |
| 172 | } | |
| 173 | ||
| 11568 | 174 | if(priority) { |
| 175 | char *pstr = g_strdup_printf("%d", priority); | |
| 176 | pri = xmlnode_new_child(presence, "priority"); | |
| 177 | xmlnode_insert_data(pri, pstr, -1); | |
| 178 | g_free(pstr); | |
| 179 | } | |
| 180 | ||
| 13385 | 181 | /* JEP-0115 */ |
| 182 | c = xmlnode_new_child(presence, "c"); | |
| 13808 | 183 | xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); |
| 13385 | 184 | xmlnode_set_attrib(c, "node", CAPS0115_NODE); |
| 185 | xmlnode_set_attrib(c, "ver", VERSION); | |
| 186 | ||
| 7014 | 187 | return presence; |
| 188 | } | |
| 189 | ||
| 190 | struct _jabber_add_permit { | |
| 15884 | 191 | PurpleConnection *gc; |
| 12285 | 192 | JabberStream *js; |
| 7014 | 193 | char *who; |
| 194 | }; | |
| 195 | ||
| 196 | static void authorize_add_cb(struct _jabber_add_permit *jap) | |
| 197 | { | |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
198 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
199 | "subscribed"); |
| 7014 | 200 | g_free(jap->who); |
| 201 | g_free(jap); | |
| 202 | } | |
| 203 | ||
| 204 | static void deny_add_cb(struct _jabber_add_permit *jap) | |
| 205 | { | |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
206 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
207 | "unsubscribed"); |
| 7014 | 208 | |
| 209 | g_free(jap->who); | |
| 210 | g_free(jap); | |
| 211 | } | |
| 212 | ||
| 10189 | 213 | static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
| 214 | { | |
| 10941 | 215 | JabberBuddy *jb = NULL; |
| 216 | xmlnode *vcard, *photo, *binval; | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
217 | char *text; |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
218 | guchar *data; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
219 | gsize size; |
| 10189 | 220 | const char *from = xmlnode_get_attrib(packet, "from"); |
| 221 | ||
| 222 | if(!from) | |
| 223 | return; | |
| 224 | ||
| 10941 | 225 | jb = jabber_buddy_find(js, from, TRUE); |
| 226 | ||
| 227 | js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
| 228 | ||
| 10189 | 229 | if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 230 | (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 10941 | 231 | if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
| 11361 | 232 | (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
| 233 | (text = xmlnode_get_data(binval))) || | |
| 234 | (text = xmlnode_get_data(photo)))) { | |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
235 | unsigned char hashval[20]; |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
236 | char hash[41], *p; |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
237 | int i; |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
238 | |
| 15884 | 239 | data = purple_base64_decode(text, &size); |
| 10189 | 240 | |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
241 | purple_cipher_digest_region("sha1", data, size, |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
242 | sizeof(hashval), hashval, NULL); |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
243 | p = hash; |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
244 | for(i=0; i<20; i++, p+=2) |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
245 | snprintf(p, 3, "%02x", hashval[i]); |
| 10189 | 246 | |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
247 | purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash); |
| 10941 | 248 | g_free(text); |
| 10189 | 249 | } |
| 250 | } | |
| 251 | } | |
| 252 | ||
| 7014 | 253 | void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
| 254 | { | |
| 255 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 256 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 7944 | 257 | const char *real_jid = NULL; |
| 9152 | 258 | const char *affiliation = NULL; |
| 259 | const char *role = NULL; | |
| 7014 | 260 | char *status = NULL; |
| 261 | int priority = 0; | |
| 262 | JabberID *jid; | |
| 263 | JabberChat *chat; | |
| 264 | JabberBuddy *jb; | |
| 9954 | 265 | JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
| 15884 | 266 | PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
267 | gboolean delayed = FALSE; |
| 15884 | 268 | PurpleBuddy *b = NULL; |
| 7014 | 269 | char *buddy_name; |
| 9954 | 270 | JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
| 7014 | 271 | xmlnode *y; |
| 272 | gboolean muc = FALSE; | |
| 10189 | 273 | char *avatar_hash = NULL; |
| 7014 | 274 | |
| 8043 | 275 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 276 | return; | |
| 277 | ||
| 278 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 279 | return; |
| 280 | ||
| 7014 | 281 | if(jb->error_msg) { |
| 282 | g_free(jb->error_msg); | |
| 283 | jb->error_msg = NULL; | |
| 284 | } | |
| 285 | ||
| 7813 | 286 | if(type && !strcmp(type, "error")) { |
| 8401 | 287 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 288 | |
| 9954 | 289 | state = JABBER_BUDDY_STATE_ERROR; |
| 8401 | 290 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 291 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 292 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
| 15197 | 293 | gboolean onlist = FALSE; |
| 15884 | 294 | PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
| 15197 | 295 | JabberBuddy *jb = NULL; |
|
10949
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
296 | |
| 15197 | 297 | if (buddy) { |
| 298 | jb = jabber_buddy_find(js, from, TRUE); | |
|
16018
0cbbb5b642ce
fix prompting to add a buddy after authorization if they're already on our list
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
299 | if ((jb->subscription & JABBER_SUB_TO)) |
| 15197 | 300 | onlist = TRUE; |
| 301 | } | |
|
16018
0cbbb5b642ce
fix prompting to add a buddy after authorization if they're already on our list
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
302 | |
| 7014 | 303 | jap->gc = js->gc; |
| 304 | jap->who = g_strdup(from); | |
| 12285 | 305 | jap->js = js; |
| 7014 | 306 | |
| 15884 | 307 | purple_account_request_authorization(purple_connection_get_account(js->gc), from, NULL, NULL, NULL, onlist, |
|
16018
0cbbb5b642ce
fix prompting to add a buddy after authorization if they're already on our list
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
308 | G_CALLBACK(authorize_add_cb), G_CALLBACK(deny_add_cb), jap); |
| 8043 | 309 | jabber_id_free(jid); |
| 7145 | 310 | return; |
| 7813 | 311 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 312 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 313 | jabber_id_free(jid); |
| 7014 | 314 | return; |
| 12285 | 315 | } else if(type && !strcmp(type, "unsubscribe")) { |
| 316 | /* XXX I'm not sure this is the right way to handle this, it | |
| 317 | * might be better to add "unsubscribe" to the presence status | |
| 318 | * if lower down, but I'm not sure. */ | |
| 319 | /* they are unsubscribing from our presence, we don't care */ | |
| 320 | /* Well, maybe just a little, we might want/need to start | |
| 321 | * acknowledging this (and the others) at some point. */ | |
| 322 | jabber_id_free(jid); | |
| 323 | return; | |
| 7014 | 324 | } else { |
| 325 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 326 | char *show = xmlnode_get_data(y); | |
| 12683 | 327 | state = jabber_buddy_show_get_state(show); |
| 7014 | 328 | g_free(show); |
| 329 | } else { | |
| 9954 | 330 | state = JABBER_BUDDY_STATE_ONLINE; |
| 7014 | 331 | } |
| 332 | } | |
| 333 | ||
| 7310 | 334 | |
| 7014 | 335 | for(y = packet->child; y; y = y->next) { |
| 8135 | 336 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 337 | continue; |
| 338 | ||
| 339 | if(!strcmp(y->name, "status")) { | |
| 7615 | 340 | g_free(status); |
| 7014 | 341 | status = xmlnode_get_data(y); |
| 342 | } else if(!strcmp(y->name, "priority")) { | |
| 343 | char *p = xmlnode_get_data(y); | |
| 344 | if(p) { | |
| 345 | priority = atoi(p); | |
| 346 | g_free(p); | |
| 347 | } | |
| 348 | } else if(!strcmp(y->name, "x")) { | |
| 13808 | 349 | const char *xmlns = xmlnode_get_namespace(y); |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
350 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 351 | /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
352 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
353 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 354 | xmlnode *z; |
| 355 | ||
| 7014 | 356 | muc = TRUE; |
| 7629 | 357 | if((z = xmlnode_get_child(y, "status"))) { |
| 358 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 359 | if(code && !strcmp(code, "201")) { | |
| 13445 | 360 | if((chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 15884 | 361 | chat->config_dialog_type = PURPLE_REQUEST_ACTION; |
| 13445 | 362 | chat->config_dialog_handle = |
| 15884 | 363 | purple_request_action(js->gc, |
| 13445 | 364 | _("Create New Room"), |
| 365 | _("Create New Room"), | |
| 366 | _("You are creating a new room. Would" | |
| 367 | " you like to configure it, or" | |
| 368 | " accept the default settings?"), | |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16018
diff
changeset
|
369 | /* Default Action */ 1, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16018
diff
changeset
|
370 | purple_connection_get_account(js->gc), NULL, chat->conv, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16018
diff
changeset
|
371 | chat, 2, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16018
diff
changeset
|
372 | _("_Configure Room"), G_CALLBACK(jabber_chat_request_room_configure), |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16018
diff
changeset
|
373 | _("_Accept Defaults"), G_CALLBACK(jabber_chat_create_instant_room)); |
| 13445 | 374 | } |
| 7629 | 375 | } |
| 376 | } | |
| 7944 | 377 | if((z = xmlnode_get_child(y, "item"))) { |
| 378 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 379 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 380 | role = xmlnode_get_attrib(z, "role"); | |
| 9931 | 381 | if(affiliation != NULL && !strcmp(affiliation, "owner")) |
| 15884 | 382 | flags |= PURPLE_CBFLAGS_FOUNDER; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
383 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
384 | if (!strcmp(role, "moderator")) |
| 15884 | 385 | flags |= PURPLE_CBFLAGS_OP; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
386 | else if (!strcmp(role, "participant")) |
| 15884 | 387 | flags |= PURPLE_CBFLAGS_VOICE; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
388 | } |
| 7944 | 389 | } |
| 10189 | 390 | } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
| 391 | xmlnode *photo = xmlnode_get_child(y, "photo"); | |
| 392 | if(photo) { | |
|
17702
15af85f94634
Don't check for null before calling free. I can't help but get rid
Mark Doliner <markdoliner@pidgin.im>
parents:
17683
diff
changeset
|
393 | g_free(avatar_hash); |
| 10189 | 394 | avatar_hash = xmlnode_get_data(photo); |
| 395 | } | |
| 7014 | 396 | } |
| 397 | } | |
| 398 | } | |
| 399 | ||
| 400 | ||
| 7322 | 401 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 402 | static int i = 1; |
| 7014 | 403 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 404 | ||
| 17049 | 405 | if(state == JABBER_BUDDY_STATE_ERROR) { |
| 8401 | 406 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 407 | |
| 7321 | 408 | if(chat->conv) { |
| 8401 | 409 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 410 | serv_got_chat_left(js->gc, chat->id); |
| 411 | } else { | |
| 8401 | 412 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 413 | } |
| 15884 | 414 | purple_notify_error(js->gc, title, title, msg); |
| 8401 | 415 | g_free(title); |
| 416 | g_free(msg); | |
| 7014 | 417 | |
| 418 | jabber_chat_destroy(chat); | |
| 7310 | 419 | jabber_id_free(jid); |
| 7615 | 420 | g_free(status); |
| 8182 | 421 | g_free(room_jid); |
|
17702
15af85f94634
Don't check for null before calling free. I can't help but get rid
Mark Doliner <markdoliner@pidgin.im>
parents:
17683
diff
changeset
|
422 | g_free(avatar_hash); |
| 7014 | 423 | return; |
| 424 | } | |
| 425 | ||
| 426 | ||
| 7813 | 427 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 428 | gboolean nick_change = FALSE; |
| 7973 | 429 | |
| 9152 | 430 | /* If we haven't joined the chat yet, we don't care that someone |
| 431 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 432 | if(!chat->conv) { |
| 10558 | 433 | if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
| 9152 | 434 | jabber_chat_destroy(chat); |
| 8182 | 435 | jabber_id_free(jid); |
| 436 | g_free(status); | |
| 437 | g_free(room_jid); | |
|
17702
15af85f94634
Don't check for null before calling free. I can't help but get rid
Mark Doliner <markdoliner@pidgin.im>
parents:
17683
diff
changeset
|
438 | g_free(avatar_hash); |
| 8182 | 439 | return; |
| 440 | } | |
| 441 | ||
| 7973 | 442 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 443 | if(chat->muc) { |
| 444 | xmlnode *x; | |
| 8135 | 445 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 446 | const char *xmlns, *nick, *code; |
| 447 | xmlnode *stat, *item; | |
| 13808 | 448 | if(!(xmlns = xmlnode_get_namespace(x)) || |
| 7972 | 449 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) |
| 450 | continue; | |
| 451 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 452 | continue; | |
| 9152 | 453 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 454 | continue; |
| 9152 | 455 | if(!strcmp(code, "301")) { |
| 456 | /* XXX: we got banned */ | |
| 457 | } else if(!strcmp(code, "303")) { | |
| 458 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 459 | continue; | |
| 460 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 461 | continue; | |
| 462 | nick_change = TRUE; | |
| 463 | if(!strcmp(jid->resource, chat->handle)) { | |
| 464 | g_free(chat->handle); | |
| 465 | chat->handle = g_strdup(nick); | |
| 466 | } | |
| 15884 | 467 | purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick); |
| 9152 | 468 | jabber_chat_remove_handle(chat, jid->resource); |
| 469 | break; | |
| 470 | } else if(!strcmp(code, "307")) { | |
| 471 | /* XXX: we got kicked */ | |
| 472 | } else if(!strcmp(code, "321")) { | |
| 473 | /* XXX: removed due to an affiliation change */ | |
| 474 | } else if(!strcmp(code, "322")) { | |
| 475 | /* XXX: removed because room is now members-only */ | |
| 476 | } else if(!strcmp(code, "332")) { | |
| 477 | /* XXX: removed due to system shutdown */ | |
| 8401 | 478 | } |
| 7972 | 479 | } |
| 480 | } | |
| 481 | if(!nick_change) { | |
| 9152 | 482 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 483 | serv_got_chat_left(js->gc, chat->id); |
| 484 | jabber_chat_destroy(chat); | |
| 485 | } else { | |
| 15884 | 486 | purple_conv_chat_remove_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
| 7974 | 487 | status); |
| 9152 | 488 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 489 | } |
| 7014 | 490 | } |
| 491 | } else { | |
| 8182 | 492 | if(!chat->conv) { |
| 493 | chat->id = i++; | |
| 494 | chat->muc = muc; | |
| 495 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 15884 | 496 | purple_conv_chat_set_nick(PURPLE_CONV_CHAT(chat->conv), chat->handle); |
| 10486 | 497 | |
| 10941 | 498 | jabber_chat_disco_traffic(chat); |
| 8182 | 499 | } |
| 500 | ||
| 7973 | 501 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 502 | status); | |
| 503 | ||
| 9152 | 504 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 505 | ||
| 7014 | 506 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
| 15884 | 507 | purple_conv_chat_add_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
508 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
509 | else |
| 15884 | 510 | purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
511 | flags); |
| 7014 | 512 | } |
| 513 | g_free(room_jid); | |
| 514 | } else { | |
| 7322 | 515 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 516 | jid->node ? "@" : "", jid->domain); | |
| 15884 | 517 | if((b = purple_find_buddy(js->gc->account, buddy_name)) == NULL) { |
|
18310
dbc5240f6bf5
Fix a crash when you have an IM window open on a jabber account and the
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18226
diff
changeset
|
518 | purple_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%x)\n", |
| 15884 | 519 | buddy_name, purple_account_get_username(js->gc->account), js->gc->account); |
| 7014 | 520 | jabber_id_free(jid); |
| 17703 | 521 | g_free(avatar_hash); |
| 7014 | 522 | g_free(buddy_name); |
| 7615 | 523 | g_free(status); |
| 7014 | 524 | return; |
| 525 | } | |
| 526 | ||
| 10189 | 527 | if(avatar_hash) { |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16018
diff
changeset
|
528 | const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b); |
| 10189 | 529 | if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { |
| 530 | JabberIq *iq; | |
| 531 | xmlnode *vcard; | |
| 532 | ||
| 10941 | 533 | /* XXX this is a crappy way of trying to prevent |
| 534 | * someone from spamming us with presence packets | |
| 535 | * and causing us to DoS ourselves...what we really | |
| 536 | * need is a queue system that can throttle itself, | |
| 537 | * but i'm too tired to write that right now */ | |
| 538 | if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
| 539 | ||
| 540 | js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
| 10189 | 541 | |
| 10941 | 542 | iq = jabber_iq_new(js, JABBER_IQ_GET); |
| 543 | xmlnode_set_attrib(iq->node, "to", buddy_name); | |
| 544 | vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 13808 | 545 | xmlnode_set_namespace(vcard, "vcard-temp"); |
| 10941 | 546 | |
| 547 | jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
| 548 | jabber_iq_send(iq); | |
| 549 | } | |
| 10189 | 550 | } |
| 551 | } | |
| 552 | ||
| 9954 | 553 | if(state == JABBER_BUDDY_STATE_ERROR || |
| 7813 | 554 | (type && (!strcmp(type, "unavailable") || |
| 555 | !strcmp(type, "unsubscribed")))) { | |
| 15884 | 556 | PurpleConversation *conv; |
| 8043 | 557 | |
| 7014 | 558 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 559 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 15884 | 560 | purple_conversation_set_name(conv, buddy_name); |
| 8043 | 561 | |
| 7395 | 562 | } else { |
| 9954 | 563 | jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
| 564 | state, status); | |
| 7395 | 565 | } |
| 7014 | 566 | |
| 9954 | 567 | if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 18330 | 568 | purple_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 | 569 | } else { |
| 15884 | 570 | purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
| 9954 | 571 | } |
| 7014 | 572 | g_free(buddy_name); |
| 573 | } | |
| 574 | g_free(status); | |
| 575 | jabber_id_free(jid); | |
|
17702
15af85f94634
Don't check for null before calling free. I can't help but get rid
Mark Doliner <markdoliner@pidgin.im>
parents:
17683
diff
changeset
|
576 | g_free(avatar_hash); |
| 7014 | 577 | } |
| 578 | ||
| 579 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 580 | { | |
| 581 | xmlnode *presence = xmlnode_new("presence"); | |
| 582 | ||
| 583 | xmlnode_set_attrib(presence, "to", who); | |
| 584 | xmlnode_set_attrib(presence, "type", type); | |
| 585 | ||
| 586 | jabber_send(js, presence); | |
| 587 | xmlnode_free(presence); | |
| 588 | } | |
| 9954 | 589 | |
| 15884 | 590 | void purple_status_to_jabber(const PurpleStatus *status, JabberBuddyState *state, char **msg, int *priority) |
| 9954 | 591 | { |
| 10216 | 592 | const char *status_id = NULL; |
| 14525 | 593 | const char *formatted_msg = NULL; |
| 10216 | 594 | |
| 13443 | 595 | if(state) *state = JABBER_BUDDY_STATE_UNKNOWN; |
| 596 | if(msg) *msg = NULL; | |
| 597 | if(priority) *priority = 0; | |
| 9954 | 598 | |
| 599 | if(!status) { | |
| 13443 | 600 | if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
| 10216 | 601 | } else { |
| 602 | if(state) { | |
| 15884 | 603 | status_id = purple_status_get_id(status); |
| 10216 | 604 | *state = jabber_buddy_status_id_get_state(status_id); |
| 605 | } | |
| 606 | ||
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
607 | if(msg) { |
| 15884 | 608 | formatted_msg = purple_status_get_attr_string(status, "message"); |
| 10216 | 609 | |
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
610 | /* if the message is blank, then there really isn't a message */ |
| 14525 | 611 | if(formatted_msg && !*formatted_msg) |
| 612 | formatted_msg = NULL; | |
| 613 | ||
| 614 | if(formatted_msg) | |
| 17683 | 615 | *msg = purple_markup_strip_html(formatted_msg); |
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
616 | } |
| 11872 | 617 | |
| 10216 | 618 | if(priority) |
| 15884 | 619 | *priority = purple_status_get_attr_int(status, "priority"); |
| 9954 | 620 | } |
| 621 | } |