Wed, 08 Sep 2004 22:15:23 +0000
[gaim-migrate @ 10903]
i thought I committed these
| 7014 | 1 | /* |
| 2 | * gaim - Jabber Protocol Plugin | |
| 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 | ||
| 23 | #include "debug.h" | |
| 24 | #include "notify.h" | |
| 25 | #include "request.h" | |
| 26 | #include "server.h" | |
| 9954 | 27 | #include "status.h" |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
28 | #include "util.h" |
| 7014 | 29 | |
| 30 | #include "buddy.h" | |
| 31 | #include "chat.h" | |
| 32 | #include "presence.h" | |
| 33 | #include "iq.h" | |
| 34 | #include "jutil.h" | |
| 35 | #include "xmlnode.h" | |
| 36 | ||
| 37 | ||
| 38 | static void chats_send_presence_foreach(gpointer key, gpointer val, | |
| 39 | gpointer user_data) | |
| 40 | { | |
| 41 | JabberChat *chat = val; | |
| 42 | xmlnode *presence = user_data; | |
| 8577 | 43 | char *chat_full_jid; |
| 44 | ||
| 45 | if(!chat->conv) | |
| 46 | return; | |
| 47 | ||
| 48 | chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, | |
| 8401 | 49 | chat->handle); |
| 7014 | 50 | |
| 8401 | 51 | xmlnode_set_attrib(presence, "to", chat_full_jid); |
| 7014 | 52 | jabber_send(chat->js, presence); |
| 8401 | 53 | g_free(chat_full_jid); |
| 7014 | 54 | } |
| 55 | ||
| 9954 | 56 | void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) { |
| 8185 | 57 | char *my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
| 58 | if(gaim_find_buddy(js->gc->account, my_base_jid)) { | |
| 59 | JabberBuddy *jb; | |
| 60 | JabberBuddyResource *jbr; | |
| 61 | if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) { | |
| 9954 | 62 | JabberBuddyState state; |
| 63 | const char *msg; | |
| 64 | int priority; | |
| 65 | ||
| 66 | gaim_status_to_jabber(gstatus, &state, &msg, &priority); | |
| 67 | ||
| 68 | if (state == JABBER_BUDDY_STATE_UNAVAILABLE) { | |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
69 | jabber_buddy_remove_resource(jb, js->user->resource); |
|
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
70 | } else { |
| 9954 | 71 | 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
|
72 | } |
| 9954 | 73 | if((jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 9990 | 74 | gaim_prpl_got_user_status(js->gc->account, my_base_jid, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 75 | } else { |
| 9990 | 76 | gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); |
| 9954 | 77 | } |
| 8185 | 78 | } |
| 79 | } | |
| 80 | g_free(my_base_jid); | |
| 81 | } | |
| 82 | ||
| 7014 | 83 | |
| 9954 | 84 | void jabber_presence_send(GaimConnection *gc, GaimStatus *status) |
| 7014 | 85 | { |
| 86 | JabberStream *js = gc->proto_data; | |
| 87 | xmlnode *presence; | |
| 88 | char *stripped = NULL; | |
| 9954 | 89 | const char *msg; |
| 90 | JabberBuddyState state; | |
| 91 | int priority; | |
| 7014 | 92 | |
| 9954 | 93 | gaim_status_to_jabber(status, &state, &msg, &priority); |
| 94 | ||
| 95 | if(msg) | |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
96 | gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
| 7014 | 97 | |
| 9954 | 98 | presence = jabber_presence_create(state, stripped, priority); |
| 99 | g_free(stripped); | |
| 7014 | 100 | |
| 101 | jabber_send(js, presence); | |
| 102 | g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); | |
| 103 | xmlnode_free(presence); | |
| 8185 | 104 | |
| 9954 | 105 | jabber_presence_fake_to_self(js, status); |
| 106 | ||
| 7014 | 107 | } |
| 108 | ||
| 9954 | 109 | xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
| 7014 | 110 | { |
| 111 | xmlnode *show, *status, *presence; | |
| 9954 | 112 | const char *show_string = NULL; |
| 7014 | 113 | |
| 114 | ||
| 115 | presence = xmlnode_new("presence"); | |
| 116 | ||
| 117 | ||
| 9954 | 118 | if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
| 119 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 120 | else if(state != JABBER_BUDDY_STATE_ONLINE && | |
| 121 | state != JABBER_BUDDY_STATE_UNKNOWN && | |
| 122 | state != JABBER_BUDDY_STATE_ERROR) | |
| 123 | show_string = jabber_buddy_state_get_status_id(state); | |
| 124 | ||
| 125 | if(show_string) { | |
| 126 | show = xmlnode_new_child(presence, "show"); | |
| 127 | xmlnode_insert_data(show, show_string, -1); | |
| 7014 | 128 | } |
| 129 | ||
| 9954 | 130 | if(msg) { |
| 7014 | 131 | status = xmlnode_new_child(presence, "status"); |
| 132 | xmlnode_insert_data(status, msg, -1); | |
| 133 | } | |
| 134 | ||
| 135 | return presence; | |
| 136 | } | |
| 137 | ||
| 138 | struct _jabber_add_permit { | |
| 139 | GaimConnection *gc; | |
| 140 | char *who; | |
| 141 | }; | |
| 142 | ||
| 143 | static void authorize_add_cb(struct _jabber_add_permit *jap) | |
| 144 | { | |
| 145 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 146 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 147 | "subscribed"); | |
| 148 | ||
| 149 | if(!gaim_find_buddy(jap->gc->account, jap->who)) | |
|
7015
bea9111282b3
[gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
150 | gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); |
| 7014 | 151 | } |
| 152 | ||
| 153 | g_free(jap->who); | |
| 154 | g_free(jap); | |
| 155 | } | |
| 156 | ||
| 157 | static void deny_add_cb(struct _jabber_add_permit *jap) | |
| 158 | { | |
| 159 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 160 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 161 | "unsubscribed"); | |
| 162 | } | |
| 163 | ||
| 164 | g_free(jap->who); | |
| 165 | g_free(jap); | |
| 166 | } | |
| 167 | ||
| 168 | void jabber_presence_parse(JabberStream *js, xmlnode *packet) | |
| 169 | { | |
| 170 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 171 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 7944 | 172 | const char *real_jid = NULL; |
| 9152 | 173 | const char *affiliation = NULL; |
| 174 | const char *role = NULL; | |
| 7014 | 175 | char *status = NULL; |
| 176 | int priority = 0; | |
| 177 | JabberID *jid; | |
| 178 | JabberChat *chat; | |
| 179 | JabberBuddy *jb; | |
| 9954 | 180 | JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
181 | GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
182 | gboolean delayed = FALSE; |
| 7014 | 183 | GaimBuddy *b; |
| 184 | char *buddy_name; | |
| 9954 | 185 | JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
| 7014 | 186 | xmlnode *y; |
| 187 | gboolean muc = FALSE; | |
| 188 | ||
| 189 | ||
| 8043 | 190 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 191 | return; | |
| 192 | ||
| 193 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 194 | return; |
| 195 | ||
| 7014 | 196 | if(jb->error_msg) { |
| 197 | g_free(jb->error_msg); | |
| 198 | jb->error_msg = NULL; | |
| 199 | } | |
| 200 | ||
| 7813 | 201 | if(type && !strcmp(type, "error")) { |
| 8401 | 202 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 203 | |
| 9954 | 204 | state = JABBER_BUDDY_STATE_ERROR; |
| 8401 | 205 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 206 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 207 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
| 208 | char *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), from); | |
| 209 | jap->gc = js->gc; | |
| 210 | jap->who = g_strdup(from); | |
| 211 | ||
| 212 | gaim_request_action(js->gc, NULL, msg, NULL, 0, jap, 2, | |
| 213 | _("Authorize"), G_CALLBACK(authorize_add_cb), | |
| 214 | _("Deny"), G_CALLBACK(deny_add_cb)); | |
| 215 | g_free(msg); | |
| 8043 | 216 | jabber_id_free(jid); |
| 7145 | 217 | return; |
| 7813 | 218 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 219 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 220 | jabber_id_free(jid); |
| 7014 | 221 | return; |
| 222 | } else { | |
| 223 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 224 | char *show = xmlnode_get_data(y); | |
| 9954 | 225 | state = jabber_buddy_status_id_get_state(show); |
| 7014 | 226 | g_free(show); |
| 227 | } else { | |
| 9954 | 228 | state = JABBER_BUDDY_STATE_ONLINE; |
| 7014 | 229 | } |
| 230 | } | |
| 231 | ||
| 7310 | 232 | |
| 7014 | 233 | for(y = packet->child; y; y = y->next) { |
| 8135 | 234 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 235 | continue; |
| 236 | ||
| 237 | if(!strcmp(y->name, "status")) { | |
| 7615 | 238 | g_free(status); |
| 7014 | 239 | status = xmlnode_get_data(y); |
| 240 | } else if(!strcmp(y->name, "priority")) { | |
| 241 | char *p = xmlnode_get_data(y); | |
| 242 | if(p) { | |
| 243 | priority = atoi(p); | |
| 244 | g_free(p); | |
| 245 | } | |
| 246 | } else if(!strcmp(y->name, "x")) { | |
| 247 | const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
248 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 249 | /* 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
|
250 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
251 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 252 | xmlnode *z; |
| 253 | ||
| 7014 | 254 | muc = TRUE; |
| 7629 | 255 | if((z = xmlnode_get_child(y, "status"))) { |
| 256 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 257 | if(code && !strcmp(code, "201")) { | |
| 7895 | 258 | chat = jabber_chat_find(js, jid->node, jid->domain); |
| 8396 | 259 | chat->config_dialog_type = GAIM_REQUEST_ACTION; |
| 260 | chat->config_dialog_handle = | |
| 261 | gaim_request_action(js->gc, _("Create New Room"), | |
| 7895 | 262 | _("Create New Room"), |
| 263 | _("You are creating a new room. Would you like to " | |
| 264 | "configure it, or accept the default settings?"), | |
| 265 | 1, chat, 2, _("Configure Room"), | |
| 7923 | 266 | G_CALLBACK(jabber_chat_request_room_configure), |
| 7895 | 267 | _("Accept Defaults"), |
| 268 | G_CALLBACK(jabber_chat_create_instant_room)); | |
| 7629 | 269 | } |
| 270 | } | |
| 7944 | 271 | if((z = xmlnode_get_child(y, "item"))) { |
| 272 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 273 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 274 | role = xmlnode_get_attrib(z, "role"); | |
| 9931 | 275 | if(affiliation != NULL && !strcmp(affiliation, "owner")) |
| 276 | flags |= GAIM_CBFLAGS_FOUNDER; | |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
277 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
278 | if (!strcmp(role, "moderator")) |
| 9931 | 279 | flags |= GAIM_CBFLAGS_OP; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
280 | else if (!strcmp(role, "participant")) |
| 9931 | 281 | flags |= GAIM_CBFLAGS_VOICE; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
282 | } |
| 7944 | 283 | } |
| 7014 | 284 | } |
| 285 | } | |
| 286 | } | |
| 287 | ||
| 288 | ||
| 7322 | 289 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 290 | static int i = 1; |
| 7014 | 291 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 292 | ||
| 9954 | 293 | if(state == JABBER_BUDDY_STATE_ERROR) { |
| 8401 | 294 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 295 | |
| 7321 | 296 | if(chat->conv) { |
| 8401 | 297 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 298 | serv_got_chat_left(js->gc, chat->id); |
| 299 | } else { | |
| 8401 | 300 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 301 | } |
| 8401 | 302 | gaim_notify_error(js->gc, title, title, msg); |
| 303 | g_free(title); | |
| 304 | g_free(msg); | |
| 7014 | 305 | |
| 306 | jabber_chat_destroy(chat); | |
| 7310 | 307 | jabber_id_free(jid); |
| 7615 | 308 | g_free(status); |
| 8182 | 309 | g_free(room_jid); |
| 7014 | 310 | return; |
| 311 | } | |
| 312 | ||
| 313 | ||
| 7813 | 314 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 315 | gboolean nick_change = FALSE; |
| 7973 | 316 | |
| 9152 | 317 | /* If we haven't joined the chat yet, we don't care that someone |
| 318 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 319 | if(!chat->conv) { |
| 9152 | 320 | if(!strcmp(jid->resource, chat->handle)) |
| 321 | jabber_chat_destroy(chat); | |
| 8182 | 322 | jabber_id_free(jid); |
| 323 | g_free(status); | |
| 324 | g_free(room_jid); | |
| 325 | return; | |
| 326 | } | |
| 327 | ||
| 7973 | 328 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 329 | if(chat->muc) { |
| 330 | xmlnode *x; | |
| 8135 | 331 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 332 | const char *xmlns, *nick, *code; |
| 333 | xmlnode *stat, *item; | |
| 334 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
| 335 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
| 336 | continue; | |
| 337 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 338 | continue; | |
| 9152 | 339 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 340 | continue; |
| 9152 | 341 | if(!strcmp(code, "301")) { |
| 342 | /* XXX: we got banned */ | |
| 343 | } else if(!strcmp(code, "303")) { | |
| 344 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 345 | continue; | |
| 346 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 347 | continue; | |
| 348 | nick_change = TRUE; | |
| 349 | if(!strcmp(jid->resource, chat->handle)) { | |
| 350 | g_free(chat->handle); | |
| 351 | chat->handle = g_strdup(nick); | |
| 352 | } | |
| 353 | gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
| 354 | jabber_chat_remove_handle(chat, jid->resource); | |
| 355 | break; | |
| 356 | } else if(!strcmp(code, "307")) { | |
| 357 | /* XXX: we got kicked */ | |
| 358 | } else if(!strcmp(code, "321")) { | |
| 359 | /* XXX: removed due to an affiliation change */ | |
| 360 | } else if(!strcmp(code, "322")) { | |
| 361 | /* XXX: removed because room is now members-only */ | |
| 362 | } else if(!strcmp(code, "332")) { | |
| 363 | /* XXX: removed due to system shutdown */ | |
| 8401 | 364 | } |
| 7972 | 365 | } |
| 366 | } | |
| 367 | if(!nick_change) { | |
| 9152 | 368 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 369 | serv_got_chat_left(js->gc, chat->id); |
| 370 | jabber_chat_destroy(chat); | |
| 371 | } else { | |
| 372 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
| 7974 | 373 | status); |
| 9152 | 374 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 375 | } |
| 7014 | 376 | } |
| 377 | } else { | |
| 8182 | 378 | if(!chat->conv) { |
| 379 | chat->id = i++; | |
| 380 | chat->muc = muc; | |
| 381 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 8401 | 382 | g_free(chat->handle); |
| 383 | chat->handle = g_strdup(jid->resource); | |
| 8182 | 384 | gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), jid->resource); |
| 385 | } | |
| 386 | ||
| 7973 | 387 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 388 | status); | |
| 389 | ||
| 9152 | 390 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 391 | ||
| 7014 | 392 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
393 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
394 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
395 | else |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
396 | gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
397 | flags); |
| 7014 | 398 | } |
| 399 | g_free(room_jid); | |
| 400 | } else { | |
| 9954 | 401 | if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO)) { |
| 7014 | 402 | gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 403 | "got unexpected presence from %s, ignoring\n", from); | |
| 404 | jabber_id_free(jid); | |
| 7615 | 405 | g_free(status); |
| 7014 | 406 | return; |
| 407 | } | |
| 408 | ||
| 7322 | 409 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 410 | jid->node ? "@" : "", jid->domain); | |
| 7014 | 411 | if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
| 412 | jabber_id_free(jid); | |
| 413 | g_free(buddy_name); | |
| 7615 | 414 | g_free(status); |
| 7014 | 415 | return; |
| 416 | } | |
| 417 | ||
| 9954 | 418 | if(state == JABBER_BUDDY_STATE_ERROR || |
| 7813 | 419 | (type && (!strcmp(type, "unavailable") || |
| 420 | !strcmp(type, "unsubscribed")))) { | |
| 8043 | 421 | GaimConversation *conv; |
| 422 | ||
| 7014 | 423 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 424 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 425 | gaim_conversation_set_name(conv, buddy_name); | |
| 426 | ||
| 7395 | 427 | } else { |
| 9954 | 428 | jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
| 429 | state, status); | |
| 7395 | 430 | } |
| 7014 | 431 | |
| 9954 | 432 | if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 433 | if(!jbr || jbr == found_jbr) { | |
| 9990 | 434 | gaim_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(state), "priority", found_jbr->priority, found_jbr->status ? "message" : NULL, found_jbr->status, NULL); |
| 9954 | 435 | } |
| 436 | } else { | |
| 9990 | 437 | gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
| 9954 | 438 | } |
| 7014 | 439 | g_free(buddy_name); |
| 440 | } | |
| 441 | g_free(status); | |
| 442 | jabber_id_free(jid); | |
| 443 | } | |
| 444 | ||
| 445 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 446 | { | |
| 447 | xmlnode *presence = xmlnode_new("presence"); | |
| 448 | ||
| 449 | xmlnode_set_attrib(presence, "to", who); | |
| 450 | xmlnode_set_attrib(presence, "type", type); | |
| 451 | ||
| 452 | jabber_send(js, presence); | |
| 453 | xmlnode_free(presence); | |
| 454 | } | |
| 9954 | 455 | |
| 456 | void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
| 457 | { | |
| 458 | const char *status_id; | |
| 459 | ||
| 460 | if(!status) { | |
| 461 | *state = JABBER_BUDDY_STATE_UNKNOWN; | |
| 462 | *msg = NULL; | |
| 463 | *priority = 0; | |
| 464 | return; | |
| 465 | } | |
| 466 | ||
| 467 | if(state) { | |
| 468 | status_id = gaim_status_get_id(status); | |
| 469 | *state = jabber_buddy_status_id_get_state(status_id); | |
| 470 | } | |
| 471 | ||
| 472 | if(msg) | |
| 473 | *msg = gaim_status_get_attr_string(status, "message"); | |
| 474 | ||
| 475 | if(priority) | |
| 476 | *priority = gaim_status_get_attr_int(status, "priority"); | |
| 477 | ||
| 478 | } |