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