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