annotate src/protocols/jabber/presence.c @ 7183:071dee25c48e

[gaim-migrate @ 7751] fix jabber segfault on changing of topic in a chat committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 07 Oct 2003 14:20:48 +0000
parents 0e4894b3e2a6
children 89dc8a119918
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "debug.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "notify.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "request.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "server.h"
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7015
diff changeset
27 #include "util.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "buddy.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "chat.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "presence.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include "iq.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include "jutil.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 #include "xmlnode.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 static void chats_send_presence_foreach(gpointer key, gpointer val,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 gpointer user_data)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 JabberChat *chat = val;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 xmlnode *presence = user_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 char *chat_jid = key;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 xmlnode_set_attrib(presence, "to", chat_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 jabber_send(chat->js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 void jabber_presence_send(GaimConnection *gc, const char *state,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 const char *msg)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 xmlnode *presence;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 char *stripped = NULL;
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 if(msg) {
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7015
diff changeset
57 gaim_markup_html_to_xhtml(msg, NULL, &stripped);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 stripped = g_strdup("");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 gc->away = stripped;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 presence = jabber_presence_create(state, msg);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 jabber_send(js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 xmlnode_free(presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 xmlnode *jabber_presence_create(const char *state, const char *msg)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 xmlnode *show, *status, *presence;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 presence = xmlnode_new("presence");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 if(state) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 const char *show_string = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79 if(!strcmp(state, _("Chatty")))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 show_string = "chat";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 else if(!strcmp(state, _("Away")) ||
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 (msg && !strcmp(state, GAIM_AWAY_CUSTOM)))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 show_string = "away";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 else if(!strcmp(state, _("Extended Away")))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 show_string = "xa";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 else if(!strcmp(state, _("Do Not Disturb")))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 show_string = "dnd";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 else if(!strcmp(state, _("Invisible"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 xmlnode_set_attrib(presence, "type", "invisible");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 if(show_string) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 show = xmlnode_new_child(presence, "show");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 xmlnode_insert_data(show, show_string, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 if(msg && *msg) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 status = xmlnode_new_child(presence, "status");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 xmlnode_insert_data(status, msg, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 return presence;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 struct _jabber_add_permit {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 GaimConnection *gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 char *who;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 };
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 static void authorize_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 "subscribed");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 if(!gaim_find_buddy(jap->gc->account, jap->who))
7015
dece74f05509 [gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
118 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
119 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 static void deny_add_cb(struct _jabber_add_permit *jap)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 if(g_list_find(gaim_connections_get_all(), jap->gc)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 "unsubscribed");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 if(!gaim_find_buddy(jap->gc->account, jap->who))
7015
dece74f05509 [gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
132 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
133 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 g_free(jap->who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 g_free(jap);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 const char *from = xmlnode_get_attrib(packet, "from");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 const char *type = xmlnode_get_attrib(packet, "type");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 char *status = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 int priority = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 JabberID *jid;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 JabberBuddy *jb;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 JabberBuddyResource *jbr;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 GaimBuddy *b;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 char *buddy_name;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 int state = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 xmlnode *y;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 gboolean muc = FALSE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 jb = jabber_buddy_find(js, from, TRUE);
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 if(jb->error_msg) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 g_free(jb->error_msg);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 jb->error_msg = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 }
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 if(type && !strcasecmp(type, "error")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 state = JABBER_STATE_ERROR;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 if((y = xmlnode_get_child(packet, "error")) != NULL) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 char *txt = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 jb->error_msg = g_strdup_printf(_("%s (Code %s)"),
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 txt, xmlnode_get_attrib(y, "code"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 g_free(txt);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 jb->error_msg = g_strdup(_("Unknown Error in 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 } else if(type && !strcasecmp(type, "subscribe")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 char *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 jap->gc = js->gc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 jap->who = g_strdup(from);
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 gaim_request_action(js->gc, NULL, msg, NULL, 0, jap, 2,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 _("Authorize"), G_CALLBACK(authorize_add_cb),
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 _("Deny"), G_CALLBACK(deny_add_cb));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 g_free(msg);
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7124
diff changeset
182 return;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183 } else if(type && (!strcmp(type, "subscribed") ||
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 !strcmp(type, "unsubscribed"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 /* we've been allowed to see their presence, but we don't care */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188 if((y = xmlnode_get_child(packet, "show"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 char *show = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190 if(!show) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 state = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 } else if(!strcasecmp(show, "away")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 state = JABBER_STATE_AWAY;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 } else if(!strcasecmp(show, "chat")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 state = JABBER_STATE_CHAT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 } else if(!strcasecmp(show, "xa")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 state = JABBER_STATE_XA;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 } else if(!strcasecmp(show, "dnd")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 state = JABBER_STATE_DND;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 g_free(show);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 state = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 for(y = packet->child; y; y = y->next) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 if(y->type != NODE_TYPE_TAG)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 continue;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 if(!strcmp(y->name, "status")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 status = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 } else if(!strcmp(y->name, "priority")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 char *p = xmlnode_get_data(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 if(p) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 priority = atoi(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 g_free(p);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 } else if(!strcmp(y->name, "x")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 const char *xmlns = xmlnode_get_attrib(y, "xmlns");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 /* this is where we'd normally get the "op" status of the
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 * user, but since we don't have a good way to show that yet
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 * we'll ignore it */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 muc = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 jid = jabber_id_new(from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 if((chat = jabber_chat_find(js, jid->node, jid->domain))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 static int i = 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 if(state == JABBER_STATE_ERROR) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 const char *code = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 char *text = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 char *buf;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 xmlnode *error = xmlnode_get_child(packet, "error");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 if(error) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 /* I should make my own messages so they can be
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 * translated, but i'm tired */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 code = xmlnode_get_attrib(error, "code");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 text = xmlnode_get_data(error);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 }
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 if(!code)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 code = "";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 if(!text)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 text = g_strdup(_("Unable to join chat"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 buf = g_strdup_printf("Error %s joining chat %s: %s",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 code, from, text);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 gaim_notify_error(js->gc, _("Error"), _("Error"), buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 g_free(text);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 g_free(buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 jabber_chat_destroy(chat);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 if(!chat->conv) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 chat->id = i++;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 chat->muc = muc;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 if(type && !strcasecmp(type, "unavailable")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 if(!strcmp(jid->resource, chat->nick)) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 serv_got_chat_left(js->gc, chat->id);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 jabber_chat_destroy(chat);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 } else {
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7095
diff changeset
275 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 NULL);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 if(!jabber_chat_find_buddy(chat->conv, jid->resource))
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7095
diff changeset
280 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 NULL);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 g_free(room_jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 } else {
7124
be4ca65b3b48 [gaim-migrate @ 7691]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
285 if(state != JABBER_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO)) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 gaim_debug(GAIM_DEBUG_INFO, "jabber",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 "got unexpected presence from %s, ignoring\n", from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 jabber_id_free(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 buddy_name = g_strdup_printf("%s@%s", jid->node, jid->domain);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 jabber_id_free(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 g_free(buddy_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 if(state == JABBER_STATE_ERROR ||
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 (type && !strcasecmp(type, "unavailable")))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 jabber_buddy_remove_resource(jb, jid->resource);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 jabber_buddy_track_resource(jb, jid->resource, priority, state,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304 status);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 jbr = jabber_buddy_find_resource(jb, jid->resource);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 if(jbr)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 serv_got_update(js->gc, buddy_name, 1, 0, b->signon, b->idle,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 jbr->state);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 serv_got_update(js->gc, buddy_name, 0, 0, 0, 0, 0);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 #if 0
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 iq = jabber_iq_new_query(js, JABBER_IQ_GET,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 "http://jabber.org/protocol/disco#items");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 query = xmlnode_get_child(iq->node, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317 xmlnode_set_attrib(query, "node",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 "http://jabber.org/protocol/avatar");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 xmlnode_set_attrib(iq->node, "to", buddy_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 #endif
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323 g_free(buddy_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 g_free(status);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 jabber_id_free(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 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
330 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 xmlnode *presence = xmlnode_new("presence");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 xmlnode_set_attrib(presence, "to", who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 xmlnode_set_attrib(presence, "type", type);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 jabber_send(js, presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 xmlnode_free(presence);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 }