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