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