annotate src/protocols/jabber/presence.c @ 11879:20479a2cf911

[gaim-migrate @ 14170] Didn't realize this wasn't saved until I tried quitting emacs. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 28 Oct 2005 23:16:37 +0000
parents ea0f39933003
children f82b6d559ea7
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 jabber_send(js, presence);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
123
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
124 if(js->avatar_hash) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
125 x = xmlnode_new_child(presence, "x");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
126 xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
127 photo = xmlnode_new_child(x, "photo");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
128 xmlnode_insert_data(photo, js->avatar_hash, -1);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
129 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
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 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 GaimConnection *gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 char *who;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 };
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 static void authorize_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
182 "subscribed");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 if(!gaim_find_buddy(jap->gc->account, jap->who))
7015
dece74f05509 [gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
185 gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 static void deny_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 "unsubscribed");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
203 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
204 {
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
205 JabberBuddy *jb = NULL;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
206 GaimBuddy *b = NULL;
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
207 xmlnode *vcard, *photo, *binval;
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
208 char *text;
11137
096020ae09a9 [gaim-migrate @ 13201]
Mark Doliner <mark@kingant.net>
parents: 11127
diff changeset
209 guchar *data;
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
210 gsize size;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
211 const char *from = xmlnode_get_attrib(packet, "from");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
212
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
213 if(!from)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
214 return;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
215
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
216 jb = jabber_buddy_find(js, from, TRUE);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
217
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
218 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
219
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
220 if((vcard = xmlnode_get_child(packet, "vCard")) ||
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
221 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
222 if((photo = xmlnode_get_child(vcard, "PHOTO")) &&
11361
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
223 (( (binval = xmlnode_get_child(photo, "BINVAL")) &&
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
224 (text = xmlnode_get_data(binval))) ||
e4868370c433 [gaim-migrate @ 13585]
Nathan Walp <nwalp@pidgin.im>
parents: 11251
diff changeset
225 (text = xmlnode_get_data(photo)))) {
11127
719779387f96 [gaim-migrate @ 13183]
Mark Doliner <mark@kingant.net>
parents: 11013
diff changeset
226 data = gaim_base64_decode(text, &size);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
227
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
228 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
229 if((b = gaim_find_buddy(js->gc->account, from))) {
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
230 unsigned char hashval[20];
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
231 char hash[41], *p;
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
232 int i;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
233
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11137
diff changeset
234 gaim_cipher_digest_region("sha1", (guchar *)data, size,
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
235 sizeof(hashval), hashval, NULL);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
236 p = hash;
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
237 for(i=0; i<20; i++, p+=2)
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
238 snprintf(p, 3, "%02x", hashval[i]);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
239 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
240 }
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
241 g_free(text);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
242 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
243 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
244 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
245
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 const char *from = xmlnode_get_attrib(packet, "from");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 const char *type = xmlnode_get_attrib(packet, "type");
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
250 const char *real_jid = NULL;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
251 const char *affiliation = NULL;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
252 const char *role = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 char *status = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 int priority = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 JabberID *jid;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 JabberBuddy *jb;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
258 JabberBuddyResource *jbr = NULL, *found_jbr = NULL;
9554
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
259 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE;
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
260 gboolean delayed = FALSE;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
261 GaimBuddy *b = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 char *buddy_name;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
263 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 xmlnode *y;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 gboolean muc = FALSE;
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
266 char *avatar_hash = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
269 if(!(jb = jabber_buddy_find(js, from, TRUE)))
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
270 return;
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
271
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
272 if(!(jid = jabber_id_new(from)))
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7273
diff changeset
273 return;
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7273
diff changeset
274
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 if(jb->error_msg) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 g_free(jb->error_msg);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 jb->error_msg = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
280 if(type && !strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
281 char *msg = jabber_parse_error(js, packet);
7644
4168b8881746 [gaim-migrate @ 8287]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
282
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
283 state = JABBER_BUDDY_STATE_ERROR;
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
284 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
285 } else if(type && !strcmp(type, "subscribe")) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 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
287 char *msg;
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
288
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
289 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
290 "her buddy list."),
1adca5a37fb8 [gaim-migrate @ 12749]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
291 from, gaim_account_get_username(js->gc->account));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 jap->gc = js->gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 jap->who = g_strdup(from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
295 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
296 jap, 2,
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 _("Authorize"), G_CALLBACK(authorize_add_cb),
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 _("Deny"), G_CALLBACK(deny_add_cb));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 g_free(msg);
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
300 jabber_id_free(jid);
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7124
diff changeset
301 return;
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
302 } else if(type && !strcmp(type, "subscribed")) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 /* 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
304 jabber_id_free(jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 if((y = xmlnode_get_child(packet, "show"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 char *show = xmlnode_get_data(y);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
309 state = jabber_buddy_status_id_get_state(show);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 g_free(show);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 } else {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
312 state = JABBER_BUDDY_STATE_ONLINE;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7280
diff changeset
316
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317 for(y = packet->child; y; y = y->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
318 if(y->type != XMLNODE_TYPE_TAG)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 continue;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 if(!strcmp(y->name, "status")) {
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
322 g_free(status);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323 status = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 } else if(!strcmp(y->name, "priority")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 char *p = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 if(p) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 priority = atoi(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 g_free(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 } else if(!strcmp(y->name, "x")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 const char *xmlns = xmlnode_get_attrib(y, "xmlns");
9846
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
332 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
9847
ab097ff50f5b [gaim-migrate @ 10725]
Nathan Walp <nwalp@pidgin.im>
parents: 9846
diff changeset
333 /* 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
334 delayed = TRUE;
c28d5b45624e [gaim-migrate @ 10724]
Mark Doliner <mark@kingant.net>
parents: 9745
diff changeset
335 } 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
336 xmlnode *z;
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
337
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 muc = TRUE;
7629
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
339 if((z = xmlnode_get_child(y, "status"))) {
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
340 const char *code = xmlnode_get_attrib(z, "code");
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
341 if(code && !strcmp(code, "201")) {
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
342 chat = jabber_chat_find(js, jid->node, jid->domain);
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
343 chat->config_dialog_type = GAIM_REQUEST_ACTION;
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
344 chat->config_dialog_handle =
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8297
diff changeset
345 gaim_request_action(js->gc, _("Create New Room"),
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
346 _("Create New Room"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
347 _("You are creating a new room. Would you like to "
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
348 "configure it, or accept the default settings?"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
349 1, chat, 2, _("Configure Room"),
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7895
diff changeset
350 G_CALLBACK(jabber_chat_request_room_configure),
7895
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
351 _("Accept Defaults"),
ddd80ffd3815 [gaim-migrate @ 8555]
Nathan Walp <nwalp@pidgin.im>
parents: 7835
diff changeset
352 G_CALLBACK(jabber_chat_create_instant_room));
7629
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
353 }
778624d3fced [gaim-migrate @ 8253]
Nathan Walp <nwalp@pidgin.im>
parents: 7615
diff changeset
354 }
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
355 if((z = xmlnode_get_child(y, "item"))) {
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
356 real_jid = xmlnode_get_attrib(z, "jid");
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
357 affiliation = xmlnode_get_attrib(z, "affiliation");
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
358 role = xmlnode_get_attrib(z, "role");
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
359 if(affiliation != NULL && !strcmp(affiliation, "owner"))
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
360 flags |= GAIM_CBFLAGS_FOUNDER;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
361 if (role != NULL) {
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
362 if (!strcmp(role, "moderator"))
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
363 flags |= GAIM_CBFLAGS_OP;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
364 else if (!strcmp(role, "participant"))
9931
7101987a49c8 [gaim-migrate @ 10823]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
365 flags |= GAIM_CBFLAGS_VOICE;
9743
bce36da0069a [gaim-migrate @ 10608]
Mark Doliner <mark@kingant.net>
parents: 9559
diff changeset
366 }
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
367 }
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
368 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
369 xmlnode *photo = xmlnode_get_child(y, "photo");
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
370 if(photo) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
371 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
372 g_free(avatar_hash);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
373 avatar_hash = xmlnode_get_data(photo);
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
374 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
375 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
376 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
377 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
378
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
379
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7321
diff changeset
380 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
381 static int i = 1;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
383
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
384 if(state == JABBER_BUDDY_STATE_ERROR) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
385 char *title, *msg = jabber_parse_error(js, packet);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
386
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
387 if(chat->conv) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
388 title = g_strdup_printf(_("Error in chat %s"), from);
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
389 serv_got_chat_left(js->gc, chat->id);
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
390 } else {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
391 title = g_strdup_printf(_("Error joining chat %s"), from);
7321
c41e522028f2 [gaim-migrate @ 7907]
Nathan Walp <nwalp@pidgin.im>
parents: 7320
diff changeset
392 }
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
393 gaim_notify_error(js->gc, title, title, msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
394 g_free(title);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
395 g_free(msg);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
396
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
397 jabber_chat_destroy(chat);
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7280
diff changeset
398 jabber_id_free(jid);
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
399 g_free(status);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
400 g_free(room_jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
401 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
402 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
403 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
404 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
405
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
407 if(type && !strcmp(type, "unavailable")) {
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
408 gboolean nick_change = FALSE;
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
409
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
410 /* 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
411 * 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
412 if(!chat->conv) {
10558
8bcf7909bec8 [gaim-migrate @ 11936]
Nathan Walp <nwalp@pidgin.im>
parents: 10490
diff changeset
413 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle))
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
414 jabber_chat_destroy(chat);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
415 jabber_id_free(jid);
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
416 g_free(status);
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
417 g_free(room_jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
418 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
419 g_free(avatar_hash);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
420 return;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
421 }
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
422
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
423 jabber_buddy_remove_resource(jb, jid->resource);
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
424 if(chat->muc) {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
425 xmlnode *x;
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
426 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
427 const char *xmlns, *nick, *code;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
428 xmlnode *stat, *item;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
429 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) ||
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
430 strcmp(xmlns, "http://jabber.org/protocol/muc#user"))
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
431 continue;
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
432 if(!(stat = xmlnode_get_child(x, "status")))
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
433 continue;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
434 if(!(code = xmlnode_get_attrib(stat, "code")))
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
435 continue;
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
436 if(!strcmp(code, "301")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
437 /* XXX: we got banned */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
438 } else if(!strcmp(code, "303")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
439 if(!(item = xmlnode_get_child(x, "item")))
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
440 continue;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
441 if(!(nick = xmlnode_get_attrib(item, "nick")))
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
442 continue;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
443 nick_change = TRUE;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
444 if(!strcmp(jid->resource, chat->handle)) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
445 g_free(chat->handle);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
446 chat->handle = g_strdup(nick);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
447 }
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
448 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
449 jabber_chat_remove_handle(chat, jid->resource);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
450 break;
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
451 } else if(!strcmp(code, "307")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
452 /* XXX: we got kicked */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
453 } else if(!strcmp(code, "321")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
454 /* XXX: removed due to an affiliation change */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
455 } else if(!strcmp(code, "322")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
456 /* XXX: removed because room is now members-only */
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
457 } else if(!strcmp(code, "332")) {
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
458 /* XXX: removed due to system shutdown */
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8396
diff changeset
459 }
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
460 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
461 }
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
462 if(!nick_change) {
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
463 if(!g_utf8_collate(jid->resource, chat->handle)) {
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
464 serv_got_chat_left(js->gc, chat->id);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
465 jabber_chat_destroy(chat);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
466 } else {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
467 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
468 status);
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
469 jabber_chat_remove_handle(chat, jid->resource);
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7965
diff changeset
470 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
471 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
472 } else {
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
473 if(!chat->conv) {
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
474 chat->id = i++;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
475 chat->muc = muc;
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
476 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
477 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
478
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
479 jabber_chat_disco_traffic(chat);
8182
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
480 }
3e1762ad0f98 [gaim-migrate @ 8901]
Nathan Walp <nwalp@pidgin.im>
parents: 8158
diff changeset
481
7973
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
482 jabber_buddy_track_resource(jb, jid->resource, priority, state,
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
483 status);
aa99b8390092 [gaim-migrate @ 8650]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
484
9152
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
485 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role);
f65be7c97812 [gaim-migrate @ 9936]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
486
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
487 if(!jabber_chat_find_buddy(chat->conv, jid->resource))
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7095
diff changeset
488 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
489 real_jid, flags, !delayed);
9554
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
490 else
8b2451878e26 [gaim-migrate @ 10387]
Luke Schierer <lschiere@pidgin.im>
parents: 9320
diff changeset
491 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
492 flags);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
493 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
494 g_free(room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
495 } else {
10486
84bc372a621e [gaim-migrate @ 11776]
Nathan Walp <nwalp@pidgin.im>
parents: 10382
diff changeset
496 if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
497 gaim_debug(GAIM_DEBUG_INFO, "jabber",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
498 "got unexpected presence from %s, ignoring\n", from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
499 jabber_id_free(jid);
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
500 g_free(status);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
501 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
502 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
503 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
504 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
505
7322
ab828b8c3f22 [gaim-migrate @ 7908]
Nathan Walp <nwalp@pidgin.im>
parents: 7321
diff changeset
506 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
507 jid->node ? "@" : "", jid->domain);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
508 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
509 jabber_id_free(jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
510 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
511 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
512 g_free(buddy_name);
7615
310013ee693e [gaim-migrate @ 8239]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
513 g_free(status);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
514 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
515 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
516
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
517 if(avatar_hash) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
518 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
519 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) {
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
520 JabberIq *iq;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
521 xmlnode *vcard;
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
522
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
523 /* XXX this is a crappy way of trying to prevent
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
524 * someone from spamming us with presence packets
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
525 * and causing us to DoS ourselves...what we really
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
526 * need is a queue system that can throttle itself,
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
527 * but i'm too tired to write that right now */
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
528 if(!g_slist_find(js->pending_avatar_requests, jb)) {
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
529
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
530 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
531
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
532 iq = jabber_iq_new(js, JABBER_IQ_GET);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
533 xmlnode_set_attrib(iq->node, "to", buddy_name);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
534 vcard = xmlnode_new_child(iq->node, "vCard");
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
535 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp");
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
536
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
537 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
538 jabber_iq_send(iq);
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10755
diff changeset
539 }
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
540 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
541 }
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
542
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
543 if(state == JABBER_BUDDY_STATE_ERROR ||
7813
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
544 (type && (!strcmp(type, "unavailable") ||
8bba34c04c9d [gaim-migrate @ 8460]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
545 !strcmp(type, "unsubscribed")))) {
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
546 GaimConversation *conv;
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
547
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
548 jabber_buddy_remove_resource(jb, jid->resource);
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
549 if((conv = jabber_find_unnormalized_conv(from, js->gc->account)))
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
550 gaim_conversation_set_name(conv, buddy_name);
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
551
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
552 } else {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
553 jbr = jabber_buddy_track_resource(jb, jid->resource, priority,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
554 state, status);
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7322
diff changeset
555 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
556
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
557 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
558 if(!jbr || jbr == found_jbr) {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
559 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
560 }
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
561 } else {
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
562 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
563 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
564 g_free(buddy_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
565 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
566 g_free(status);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
567 jabber_id_free(jid);
10189
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
568 if(avatar_hash)
4e7249591251 [gaim-migrate @ 11304]
Nathan Walp <nwalp@pidgin.im>
parents: 10116
diff changeset
569 g_free(avatar_hash);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
570 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
571
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
572 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
573 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
574 xmlnode *presence = xmlnode_new("presence");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
575
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
576 xmlnode_set_attrib(presence, "to", who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
577 xmlnode_set_attrib(presence, "type", type);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
578
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
579 jabber_send(js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
580 xmlnode_free(presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
581 }
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
582
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
583 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
584 {
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
585 const char *status_id = NULL;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
586
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
587 *state = JABBER_BUDDY_STATE_UNKNOWN;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
588 *msg = NULL;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
589 *priority = 0;
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
590
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
591 if(!status) {
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
592 *state = JABBER_BUDDY_STATE_UNAVAILABLE;
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
593 } else {
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
594 if(state) {
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
595 status_id = gaim_status_get_id(status);
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
596 *state = jabber_buddy_status_id_get_state(status_id);
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
597 }
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
598
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
599 if(msg)
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
600 *msg = gaim_status_get_attr_string(status, "message");
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
601
11872
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
602 /* 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
603 if(*msg && !**msg)
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
604 *msg = NULL;
ea0f39933003 [gaim-migrate @ 14163]
Nathan Walp <nwalp@pidgin.im>
parents: 11718
diff changeset
605
10216
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
606 if(priority)
09876d57c520 [gaim-migrate @ 11343]
Nathan Walp <nwalp@pidgin.im>
parents: 10189
diff changeset
607 *priority = gaim_status_get_attr_int(status, "priority");
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
608 }
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
609
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9931
diff changeset
610 }