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