Sun, 10 Jun 2007 15:58:23 +0000
Two questions:
1. XMPP <status> messages inside <presence> broadcasts should be
plaintext and not HTML, right?
2. 'stripped = purple_markup_strip_html(str)' is basically the same as
'purple_markup_html_to_xhtml(str, NULL, &stripped)', right?
This fixes a bug Emily found where setting an XMPP status message with
an embedded link would drop the link completely. For example, in
Pidgin you set your away message and insert a link so that the message
body is <a href="http://www.example.com/">Example</a>. When we set
this message for an XMPP account it just strips the HTML and sets the
message to "Example". This change causes the message to be
"Example (http://www.example.com/)". It's the same thing we do when
displaying links in tooltips in the blist.
| 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 | |
| 9954 | 121 | presence = jabber_presence_create(state, stripped, priority); |
| 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 | { |
| 13385 | 141 | xmlnode *show, *status, *presence, *pri, *c; |
| 9954 | 142 | const char *show_string = NULL; |
| 7014 | 143 | |
| 144 | presence = xmlnode_new("presence"); | |
| 145 | ||
| 9954 | 146 | if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
| 147 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 148 | else if(state != JABBER_BUDDY_STATE_ONLINE && | |
| 149 | state != JABBER_BUDDY_STATE_UNKNOWN && | |
| 150 | state != JABBER_BUDDY_STATE_ERROR) | |
| 12683 | 151 | show_string = jabber_buddy_state_get_show(state); |
| 9954 | 152 | |
| 153 | if(show_string) { | |
| 154 | show = xmlnode_new_child(presence, "show"); | |
| 155 | xmlnode_insert_data(show, show_string, -1); | |
| 7014 | 156 | } |
| 157 | ||
| 9954 | 158 | if(msg) { |
| 7014 | 159 | status = xmlnode_new_child(presence, "status"); |
| 160 | xmlnode_insert_data(status, msg, -1); | |
| 161 | } | |
| 162 | ||
| 11568 | 163 | if(priority) { |
| 164 | char *pstr = g_strdup_printf("%d", priority); | |
| 165 | pri = xmlnode_new_child(presence, "priority"); | |
| 166 | xmlnode_insert_data(pri, pstr, -1); | |
| 167 | g_free(pstr); | |
| 168 | } | |
| 169 | ||
| 13385 | 170 | /* JEP-0115 */ |
| 171 | c = xmlnode_new_child(presence, "c"); | |
| 13808 | 172 | xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); |
| 13385 | 173 | xmlnode_set_attrib(c, "node", CAPS0115_NODE); |
| 174 | xmlnode_set_attrib(c, "ver", VERSION); | |
| 175 | ||
| 7014 | 176 | return presence; |
| 177 | } | |
| 178 | ||
| 179 | struct _jabber_add_permit { | |
| 15884 | 180 | PurpleConnection *gc; |
| 12285 | 181 | JabberStream *js; |
| 7014 | 182 | char *who; |
| 183 | }; | |
| 184 | ||
| 185 | static void authorize_add_cb(struct _jabber_add_permit *jap) | |
| 186 | { | |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
187 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
188 | "subscribed"); |
| 7014 | 189 | g_free(jap->who); |
| 190 | g_free(jap); | |
| 191 | } | |
| 192 | ||
| 193 | static void deny_add_cb(struct _jabber_add_permit *jap) | |
| 194 | { | |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
195 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13952
diff
changeset
|
196 | "unsubscribed"); |
| 7014 | 197 | |
| 198 | g_free(jap->who); | |
| 199 | g_free(jap); | |
| 200 | } | |
| 201 | ||
| 10189 | 202 | static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
| 203 | { | |
| 10941 | 204 | JabberBuddy *jb = NULL; |
| 205 | xmlnode *vcard, *photo, *binval; | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
206 | char *text; |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
207 | guchar *data; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
208 | gsize size; |
| 10189 | 209 | const char *from = xmlnode_get_attrib(packet, "from"); |
| 210 | ||
| 211 | if(!from) | |
| 212 | return; | |
| 213 | ||
| 10941 | 214 | jb = jabber_buddy_find(js, from, TRUE); |
| 215 | ||
| 216 | js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
| 217 | ||
| 10189 | 218 | if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 219 | (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 10941 | 220 | if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
| 11361 | 221 | (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
| 222 | (text = xmlnode_get_data(binval))) || | |
| 223 | (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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | |
| 15884 | 228 | data = purple_base64_decode(text, &size); |
| 10189 | 229 | |
|
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
|
230 | 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
|
231 | 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
|
232 | 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
|
233 | 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
|
234 | snprintf(p, 3, "%02x", hashval[i]); |
| 10189 | 235 | |
|
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
|
236 | purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash); |
| 10941 | 237 | g_free(text); |
| 10189 | 238 | } |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 7014 | 242 | void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
| 243 | { | |
| 244 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 245 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 7944 | 246 | const char *real_jid = NULL; |
| 9152 | 247 | const char *affiliation = NULL; |
| 248 | const char *role = NULL; | |
| 7014 | 249 | char *status = NULL; |
| 250 | int priority = 0; | |
| 251 | JabberID *jid; | |
| 252 | JabberChat *chat; | |
| 253 | JabberBuddy *jb; | |
| 9954 | 254 | JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
| 15884 | 255 | PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
256 | gboolean delayed = FALSE; |
| 15884 | 257 | PurpleBuddy *b = NULL; |
| 7014 | 258 | char *buddy_name; |
| 9954 | 259 | JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
| 7014 | 260 | xmlnode *y; |
| 261 | gboolean muc = FALSE; | |
| 10189 | 262 | char *avatar_hash = NULL; |
| 7014 | 263 | |
| 8043 | 264 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 265 | return; | |
| 266 | ||
| 267 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 268 | return; |
| 269 | ||
| 7014 | 270 | if(jb->error_msg) { |
| 271 | g_free(jb->error_msg); | |
| 272 | jb->error_msg = NULL; | |
| 273 | } | |
| 274 | ||
| 7813 | 275 | if(type && !strcmp(type, "error")) { |
| 8401 | 276 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 277 | |
| 9954 | 278 | state = JABBER_BUDDY_STATE_ERROR; |
| 8401 | 279 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 280 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 281 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
| 15197 | 282 | gboolean onlist = FALSE; |
| 15884 | 283 | PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
| 15197 | 284 | JabberBuddy *jb = NULL; |
|
10949
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
285 | |
| 15197 | 286 | if (buddy) { |
| 287 | 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
|
288 | if ((jb->subscription & JABBER_SUB_TO)) |
| 15197 | 289 | onlist = TRUE; |
| 290 | } | |
|
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
|
291 | |
| 7014 | 292 | jap->gc = js->gc; |
| 293 | jap->who = g_strdup(from); | |
| 12285 | 294 | jap->js = js; |
| 7014 | 295 | |
| 15884 | 296 | 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
|
297 | G_CALLBACK(authorize_add_cb), G_CALLBACK(deny_add_cb), jap); |
| 8043 | 298 | jabber_id_free(jid); |
| 7145 | 299 | return; |
| 7813 | 300 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 301 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 302 | jabber_id_free(jid); |
| 7014 | 303 | return; |
| 12285 | 304 | } else if(type && !strcmp(type, "unsubscribe")) { |
| 305 | /* XXX I'm not sure this is the right way to handle this, it | |
| 306 | * might be better to add "unsubscribe" to the presence status | |
| 307 | * if lower down, but I'm not sure. */ | |
| 308 | /* they are unsubscribing from our presence, we don't care */ | |
| 309 | /* Well, maybe just a little, we might want/need to start | |
| 310 | * acknowledging this (and the others) at some point. */ | |
| 311 | jabber_id_free(jid); | |
| 312 | return; | |
| 7014 | 313 | } else { |
| 314 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 315 | char *show = xmlnode_get_data(y); | |
| 12683 | 316 | state = jabber_buddy_show_get_state(show); |
| 7014 | 317 | g_free(show); |
| 318 | } else { | |
| 9954 | 319 | state = JABBER_BUDDY_STATE_ONLINE; |
| 7014 | 320 | } |
| 321 | } | |
| 322 | ||
| 7310 | 323 | |
| 7014 | 324 | for(y = packet->child; y; y = y->next) { |
| 8135 | 325 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 326 | continue; |
| 327 | ||
| 328 | if(!strcmp(y->name, "status")) { | |
| 7615 | 329 | g_free(status); |
| 7014 | 330 | status = xmlnode_get_data(y); |
| 331 | } else if(!strcmp(y->name, "priority")) { | |
| 332 | char *p = xmlnode_get_data(y); | |
| 333 | if(p) { | |
| 334 | priority = atoi(p); | |
| 335 | g_free(p); | |
| 336 | } | |
| 337 | } else if(!strcmp(y->name, "x")) { | |
| 13808 | 338 | const char *xmlns = xmlnode_get_namespace(y); |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
339 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 340 | /* 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
|
341 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
342 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 343 | xmlnode *z; |
| 344 | ||
| 7014 | 345 | muc = TRUE; |
| 7629 | 346 | if((z = xmlnode_get_child(y, "status"))) { |
| 347 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 348 | if(code && !strcmp(code, "201")) { | |
| 13445 | 349 | if((chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 15884 | 350 | chat->config_dialog_type = PURPLE_REQUEST_ACTION; |
| 13445 | 351 | chat->config_dialog_handle = |
| 15884 | 352 | purple_request_action(js->gc, |
| 13445 | 353 | _("Create New Room"), |
| 354 | _("Create New Room"), | |
| 355 | _("You are creating a new room. Would" | |
| 356 | " you like to configure it, or" | |
| 357 | " 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
|
358 | /* 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
|
359 | 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
|
360 | 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
|
361 | _("_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
|
362 | _("_Accept Defaults"), G_CALLBACK(jabber_chat_create_instant_room)); |
| 13445 | 363 | } |
| 7629 | 364 | } |
| 365 | } | |
| 7944 | 366 | if((z = xmlnode_get_child(y, "item"))) { |
| 367 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 368 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 369 | role = xmlnode_get_attrib(z, "role"); | |
| 9931 | 370 | if(affiliation != NULL && !strcmp(affiliation, "owner")) |
| 15884 | 371 | flags |= PURPLE_CBFLAGS_FOUNDER; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
372 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
373 | if (!strcmp(role, "moderator")) |
| 15884 | 374 | flags |= PURPLE_CBFLAGS_OP; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
375 | else if (!strcmp(role, "participant")) |
| 15884 | 376 | flags |= PURPLE_CBFLAGS_VOICE; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
377 | } |
| 7944 | 378 | } |
| 10189 | 379 | } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
| 380 | xmlnode *photo = xmlnode_get_child(y, "photo"); | |
| 381 | if(photo) { | |
| 382 | if(avatar_hash) | |
| 383 | g_free(avatar_hash); | |
| 384 | avatar_hash = xmlnode_get_data(photo); | |
| 385 | } | |
| 7014 | 386 | } |
| 387 | } | |
| 388 | } | |
| 389 | ||
| 390 | ||
| 7322 | 391 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 392 | static int i = 1; |
| 7014 | 393 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 394 | ||
| 17049 | 395 | if(state == JABBER_BUDDY_STATE_ERROR) { |
| 8401 | 396 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 397 | |
| 7321 | 398 | if(chat->conv) { |
| 8401 | 399 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 400 | serv_got_chat_left(js->gc, chat->id); |
| 401 | } else { | |
| 8401 | 402 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 403 | } |
| 15884 | 404 | purple_notify_error(js->gc, title, title, msg); |
| 8401 | 405 | g_free(title); |
| 406 | g_free(msg); | |
| 7014 | 407 | |
| 408 | jabber_chat_destroy(chat); | |
| 7310 | 409 | jabber_id_free(jid); |
| 7615 | 410 | g_free(status); |
| 8182 | 411 | g_free(room_jid); |
| 10189 | 412 | if(avatar_hash) |
| 413 | g_free(avatar_hash); | |
| 7014 | 414 | return; |
| 415 | } | |
| 416 | ||
| 417 | ||
| 7813 | 418 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 419 | gboolean nick_change = FALSE; |
| 7973 | 420 | |
| 9152 | 421 | /* If we haven't joined the chat yet, we don't care that someone |
| 422 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 423 | if(!chat->conv) { |
| 10558 | 424 | if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
| 9152 | 425 | jabber_chat_destroy(chat); |
| 8182 | 426 | jabber_id_free(jid); |
| 427 | g_free(status); | |
| 428 | g_free(room_jid); | |
| 10189 | 429 | if(avatar_hash) |
| 430 | g_free(avatar_hash); | |
| 8182 | 431 | return; |
| 432 | } | |
| 433 | ||
| 7973 | 434 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 435 | if(chat->muc) { |
| 436 | xmlnode *x; | |
| 8135 | 437 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 438 | const char *xmlns, *nick, *code; |
| 439 | xmlnode *stat, *item; | |
| 13808 | 440 | if(!(xmlns = xmlnode_get_namespace(x)) || |
| 7972 | 441 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) |
| 442 | continue; | |
| 443 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 444 | continue; | |
| 9152 | 445 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 446 | continue; |
| 9152 | 447 | if(!strcmp(code, "301")) { |
| 448 | /* XXX: we got banned */ | |
| 449 | } else if(!strcmp(code, "303")) { | |
| 450 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 451 | continue; | |
| 452 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 453 | continue; | |
| 454 | nick_change = TRUE; | |
| 455 | if(!strcmp(jid->resource, chat->handle)) { | |
| 456 | g_free(chat->handle); | |
| 457 | chat->handle = g_strdup(nick); | |
| 458 | } | |
| 15884 | 459 | purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick); |
| 9152 | 460 | jabber_chat_remove_handle(chat, jid->resource); |
| 461 | break; | |
| 462 | } else if(!strcmp(code, "307")) { | |
| 463 | /* XXX: we got kicked */ | |
| 464 | } else if(!strcmp(code, "321")) { | |
| 465 | /* XXX: removed due to an affiliation change */ | |
| 466 | } else if(!strcmp(code, "322")) { | |
| 467 | /* XXX: removed because room is now members-only */ | |
| 468 | } else if(!strcmp(code, "332")) { | |
| 469 | /* XXX: removed due to system shutdown */ | |
| 8401 | 470 | } |
| 7972 | 471 | } |
| 472 | } | |
| 473 | if(!nick_change) { | |
| 9152 | 474 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 475 | serv_got_chat_left(js->gc, chat->id); |
| 476 | jabber_chat_destroy(chat); | |
| 477 | } else { | |
| 15884 | 478 | purple_conv_chat_remove_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
| 7974 | 479 | status); |
| 9152 | 480 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 481 | } |
| 7014 | 482 | } |
| 483 | } else { | |
| 8182 | 484 | if(!chat->conv) { |
| 485 | chat->id = i++; | |
| 486 | chat->muc = muc; | |
| 487 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 15884 | 488 | purple_conv_chat_set_nick(PURPLE_CONV_CHAT(chat->conv), chat->handle); |
| 10486 | 489 | |
| 10941 | 490 | jabber_chat_disco_traffic(chat); |
| 8182 | 491 | } |
| 492 | ||
| 7973 | 493 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 494 | status); | |
| 495 | ||
| 9152 | 496 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 497 | ||
| 7014 | 498 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
| 15884 | 499 | 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
|
500 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
501 | else |
| 15884 | 502 | 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
|
503 | flags); |
| 7014 | 504 | } |
| 505 | g_free(room_jid); | |
| 506 | } else { | |
| 7322 | 507 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 508 | jid->node ? "@" : "", jid->domain); | |
| 15884 | 509 | if((b = purple_find_buddy(js->gc->account, buddy_name)) == NULL) { |
| 510 | purple_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%x)", | |
| 511 | buddy_name, purple_account_get_username(js->gc->account), js->gc->account); | |
| 7014 | 512 | jabber_id_free(jid); |
| 10189 | 513 | if(avatar_hash) |
| 514 | g_free(avatar_hash); | |
| 7014 | 515 | g_free(buddy_name); |
| 7615 | 516 | g_free(status); |
| 7014 | 517 | return; |
| 518 | } | |
| 519 | ||
| 10189 | 520 | 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
|
521 | const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b); |
| 10189 | 522 | if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { |
| 523 | JabberIq *iq; | |
| 524 | xmlnode *vcard; | |
| 525 | ||
| 10941 | 526 | /* XXX this is a crappy way of trying to prevent |
| 527 | * someone from spamming us with presence packets | |
| 528 | * and causing us to DoS ourselves...what we really | |
| 529 | * need is a queue system that can throttle itself, | |
| 530 | * but i'm too tired to write that right now */ | |
| 531 | if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
| 532 | ||
| 533 | js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
| 10189 | 534 | |
| 10941 | 535 | iq = jabber_iq_new(js, JABBER_IQ_GET); |
| 536 | xmlnode_set_attrib(iq->node, "to", buddy_name); | |
| 537 | vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 13808 | 538 | xmlnode_set_namespace(vcard, "vcard-temp"); |
| 10941 | 539 | |
| 540 | jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
| 541 | jabber_iq_send(iq); | |
| 542 | } | |
| 10189 | 543 | } |
| 544 | } | |
| 545 | ||
| 9954 | 546 | if(state == JABBER_BUDDY_STATE_ERROR || |
| 7813 | 547 | (type && (!strcmp(type, "unavailable") || |
| 548 | !strcmp(type, "unsubscribed")))) { | |
| 15884 | 549 | PurpleConversation *conv; |
| 8043 | 550 | |
| 7014 | 551 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 552 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 15884 | 553 | purple_conversation_set_name(conv, buddy_name); |
| 8043 | 554 | |
| 7395 | 555 | } else { |
| 9954 | 556 | jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
| 557 | state, status); | |
| 7395 | 558 | } |
| 7014 | 559 | |
| 9954 | 560 | if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 561 | if(!jbr || jbr == found_jbr) { | |
| 15884 | 562 | 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 | 563 | } |
| 564 | } else { | |
| 15884 | 565 | purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
| 9954 | 566 | } |
| 7014 | 567 | g_free(buddy_name); |
| 568 | } | |
| 569 | g_free(status); | |
| 570 | jabber_id_free(jid); | |
| 10189 | 571 | if(avatar_hash) |
| 572 | g_free(avatar_hash); | |
| 7014 | 573 | } |
| 574 | ||
| 575 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 576 | { | |
| 577 | xmlnode *presence = xmlnode_new("presence"); | |
| 578 | ||
| 579 | xmlnode_set_attrib(presence, "to", who); | |
| 580 | xmlnode_set_attrib(presence, "type", type); | |
| 581 | ||
| 582 | jabber_send(js, presence); | |
| 583 | xmlnode_free(presence); | |
| 584 | } | |
| 9954 | 585 | |
| 15884 | 586 | void purple_status_to_jabber(const PurpleStatus *status, JabberBuddyState *state, char **msg, int *priority) |
| 9954 | 587 | { |
| 10216 | 588 | const char *status_id = NULL; |
| 14525 | 589 | const char *formatted_msg = NULL; |
| 10216 | 590 | |
| 13443 | 591 | if(state) *state = JABBER_BUDDY_STATE_UNKNOWN; |
| 592 | if(msg) *msg = NULL; | |
| 593 | if(priority) *priority = 0; | |
| 9954 | 594 | |
| 595 | if(!status) { | |
| 13443 | 596 | if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
| 10216 | 597 | } else { |
| 598 | if(state) { | |
| 15884 | 599 | status_id = purple_status_get_id(status); |
| 10216 | 600 | *state = jabber_buddy_status_id_get_state(status_id); |
| 601 | } | |
| 602 | ||
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
603 | if(msg) { |
| 15884 | 604 | formatted_msg = purple_status_get_attr_string(status, "message"); |
| 10216 | 605 | |
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
606 | /* if the message is blank, then there really isn't a message */ |
| 14525 | 607 | if(formatted_msg && !*formatted_msg) |
| 608 | formatted_msg = NULL; | |
| 609 | ||
| 610 | if(formatted_msg) | |
| 17683 | 611 | *msg = purple_markup_strip_html(formatted_msg); |
|
13497
07fc0a9826b8
[gaim-migrate @ 15872]
Richard Laager <rlaager@pidgin.im>
parents:
13445
diff
changeset
|
612 | } |
| 11872 | 613 | |
| 10216 | 614 | if(priority) |
| 15884 | 615 | *priority = purple_status_get_attr_int(status, "priority"); |
| 9954 | 616 | } |
| 617 | } |