Wed, 01 Sep 2004 01:07:42 +0000
[gaim-migrate @ 10819]
" Currently, the "loggedin" parameter of
serv_got_update() is of type int and used as a boolean.
I updated it and all references to be gboolean.
I also noticed that "presence" in
gaim_blist_update_buddy_presence() is also a really
boolean. of whether or not the buddy is currently
online. There seemed to be some confusion,
particularly in the silc plugin which tried to use a
GaimBuddyPresenceState (coincidentally (or perhaps not)
GAIM_BUDDY_OFFLINE and GAIM_BUDDY_ONLINE work as FALSE
and TRUE respectively). The value passed to
gaim_blist_update_buddy_presence() doesn't directly
become the buddy presence state and this patch helps
avoid confusion in this respect." --Daniel Atallah
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))) |
|
9927
7ae7d2accb3e
[gaim-migrate @ 10819]
Daniel Atallah <datallah@pidgin.im>
parents:
9847
diff
changeset
|
80 | serv_got_update(js->gc, my_base_jid, TRUE, 0, 0, 0, jbr->state); |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
81 | else |
|
9927
7ae7d2accb3e
[gaim-migrate @ 10819]
Daniel Atallah <datallah@pidgin.im>
parents:
9847
diff
changeset
|
82 | serv_got_update(js->gc, my_base_jid, FALSE, 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; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
210 | gboolean delayed = FALSE; |
| 7014 | 211 | GaimBuddy *b; |
| 212 | char *buddy_name; | |
| 213 | int state = 0; | |
| 214 | xmlnode *y; | |
| 215 | gboolean muc = FALSE; | |
| 216 | ||
| 217 | ||
| 8043 | 218 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 219 | return; | |
| 220 | ||
| 221 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 222 | return; |
| 223 | ||
| 7014 | 224 | if(jb->error_msg) { |
| 225 | g_free(jb->error_msg); | |
| 226 | jb->error_msg = NULL; | |
| 227 | } | |
| 228 | ||
| 7813 | 229 | if(type && !strcmp(type, "error")) { |
| 8401 | 230 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 231 | |
| 7014 | 232 | state = JABBER_STATE_ERROR; |
| 8401 | 233 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 234 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 235 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
| 236 | char *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), from); | |
| 237 | jap->gc = js->gc; | |
| 238 | jap->who = g_strdup(from); | |
| 239 | ||
| 240 | gaim_request_action(js->gc, NULL, msg, NULL, 0, jap, 2, | |
| 241 | _("Authorize"), G_CALLBACK(authorize_add_cb), | |
| 242 | _("Deny"), G_CALLBACK(deny_add_cb)); | |
| 243 | g_free(msg); | |
| 8043 | 244 | jabber_id_free(jid); |
| 7145 | 245 | return; |
| 7813 | 246 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 247 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 248 | jabber_id_free(jid); |
| 7014 | 249 | return; |
| 250 | } else { | |
| 251 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 252 | char *show = xmlnode_get_data(y); | |
| 8185 | 253 | state = show_to_state(show); |
| 7014 | 254 | g_free(show); |
| 255 | } else { | |
| 256 | state = 0; | |
| 257 | } | |
| 258 | } | |
| 259 | ||
| 7310 | 260 | |
| 7014 | 261 | for(y = packet->child; y; y = y->next) { |
| 8135 | 262 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 263 | continue; |
| 264 | ||
| 265 | if(!strcmp(y->name, "status")) { | |
| 7615 | 266 | g_free(status); |
| 7014 | 267 | status = xmlnode_get_data(y); |
| 268 | } else if(!strcmp(y->name, "priority")) { | |
| 269 | char *p = xmlnode_get_data(y); | |
| 270 | if(p) { | |
| 271 | priority = atoi(p); | |
| 272 | g_free(p); | |
| 273 | } | |
| 274 | } else if(!strcmp(y->name, "x")) { | |
| 275 | const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
276 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 277 | /* 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
|
278 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
279 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 280 | xmlnode *z; |
| 281 | ||
| 7014 | 282 | muc = TRUE; |
| 7629 | 283 | if((z = xmlnode_get_child(y, "status"))) { |
| 284 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 285 | if(code && !strcmp(code, "201")) { | |
| 7895 | 286 | chat = jabber_chat_find(js, jid->node, jid->domain); |
| 8396 | 287 | chat->config_dialog_type = GAIM_REQUEST_ACTION; |
| 288 | chat->config_dialog_handle = | |
| 289 | gaim_request_action(js->gc, _("Create New Room"), | |
| 7895 | 290 | _("Create New Room"), |
| 291 | _("You are creating a new room. Would you like to " | |
| 292 | "configure it, or accept the default settings?"), | |
| 293 | 1, chat, 2, _("Configure Room"), | |
| 7923 | 294 | G_CALLBACK(jabber_chat_request_room_configure), |
| 7895 | 295 | _("Accept Defaults"), |
| 296 | G_CALLBACK(jabber_chat_create_instant_room)); | |
| 7629 | 297 | } |
| 298 | } | |
| 7944 | 299 | if((z = xmlnode_get_child(y, "item"))) { |
| 300 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 301 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 302 | role = xmlnode_get_attrib(z, "role"); | |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
303 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
304 | if (!strcmp(role, "moderator")) |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
305 | flags = GAIM_CBFLAGS_OP; |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
306 | else if (!strcmp(role, "participant")) |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
307 | flags = GAIM_CBFLAGS_VOICE; |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
308 | } |
| 7944 | 309 | } |
| 7014 | 310 | } |
| 311 | } | |
| 312 | } | |
| 313 | ||
| 314 | ||
| 7322 | 315 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 316 | static int i = 1; |
| 7014 | 317 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 318 | ||
| 319 | if(state == JABBER_STATE_ERROR) { | |
| 8401 | 320 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 321 | |
| 7321 | 322 | if(chat->conv) { |
| 8401 | 323 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 324 | serv_got_chat_left(js->gc, chat->id); |
| 325 | } else { | |
| 8401 | 326 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 327 | } |
| 8401 | 328 | gaim_notify_error(js->gc, title, title, msg); |
| 329 | g_free(title); | |
| 330 | g_free(msg); | |
| 7014 | 331 | |
| 332 | jabber_chat_destroy(chat); | |
| 7310 | 333 | jabber_id_free(jid); |
| 7615 | 334 | g_free(status); |
| 8182 | 335 | g_free(room_jid); |
| 7014 | 336 | return; |
| 337 | } | |
| 338 | ||
| 339 | ||
| 7813 | 340 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 341 | gboolean nick_change = FALSE; |
| 7973 | 342 | |
| 9152 | 343 | /* If we haven't joined the chat yet, we don't care that someone |
| 344 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 345 | if(!chat->conv) { |
| 9152 | 346 | if(!strcmp(jid->resource, chat->handle)) |
| 347 | jabber_chat_destroy(chat); | |
| 8182 | 348 | jabber_id_free(jid); |
| 349 | g_free(status); | |
| 350 | g_free(room_jid); | |
| 351 | return; | |
| 352 | } | |
| 353 | ||
| 7973 | 354 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 355 | if(chat->muc) { |
| 356 | xmlnode *x; | |
| 8135 | 357 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 358 | const char *xmlns, *nick, *code; |
| 359 | xmlnode *stat, *item; | |
| 360 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
| 361 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
| 362 | continue; | |
| 363 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 364 | continue; | |
| 9152 | 365 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 366 | continue; |
| 9152 | 367 | if(!strcmp(code, "301")) { |
| 368 | /* XXX: we got banned */ | |
| 369 | } else if(!strcmp(code, "303")) { | |
| 370 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 371 | continue; | |
| 372 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 373 | continue; | |
| 374 | nick_change = TRUE; | |
| 375 | if(!strcmp(jid->resource, chat->handle)) { | |
| 376 | g_free(chat->handle); | |
| 377 | chat->handle = g_strdup(nick); | |
| 378 | } | |
| 379 | gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
| 380 | jabber_chat_remove_handle(chat, jid->resource); | |
| 381 | break; | |
| 382 | } else if(!strcmp(code, "307")) { | |
| 383 | /* XXX: we got kicked */ | |
| 384 | } else if(!strcmp(code, "321")) { | |
| 385 | /* XXX: removed due to an affiliation change */ | |
| 386 | } else if(!strcmp(code, "322")) { | |
| 387 | /* XXX: removed because room is now members-only */ | |
| 388 | } else if(!strcmp(code, "332")) { | |
| 389 | /* XXX: removed due to system shutdown */ | |
| 8401 | 390 | } |
| 7972 | 391 | } |
| 392 | } | |
| 393 | if(!nick_change) { | |
| 9152 | 394 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 395 | serv_got_chat_left(js->gc, chat->id); |
| 396 | jabber_chat_destroy(chat); | |
| 397 | } else { | |
| 398 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
| 7974 | 399 | status); |
| 9152 | 400 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 401 | } |
| 7014 | 402 | } |
| 403 | } else { | |
| 8182 | 404 | if(!chat->conv) { |
| 405 | chat->id = i++; | |
| 406 | chat->muc = muc; | |
| 407 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 8401 | 408 | g_free(chat->handle); |
| 409 | chat->handle = g_strdup(jid->resource); | |
| 8182 | 410 | gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), jid->resource); |
| 411 | } | |
| 412 | ||
| 7973 | 413 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 414 | status); | |
| 415 | ||
| 9152 | 416 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 417 | ||
| 7014 | 418 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
419 | 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
|
420 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
421 | else |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
422 | 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
|
423 | flags); |
| 7014 | 424 | } |
| 425 | g_free(room_jid); | |
| 426 | } else { | |
| 7124 | 427 | if(state != JABBER_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO)) { |
| 7014 | 428 | gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 429 | "got unexpected presence from %s, ignoring\n", from); | |
| 430 | jabber_id_free(jid); | |
| 7615 | 431 | g_free(status); |
| 7014 | 432 | return; |
| 433 | } | |
| 434 | ||
| 7322 | 435 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 436 | jid->node ? "@" : "", jid->domain); | |
| 7014 | 437 | if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
| 438 | jabber_id_free(jid); | |
| 439 | g_free(buddy_name); | |
| 7615 | 440 | g_free(status); |
| 7014 | 441 | return; |
| 442 | } | |
| 443 | ||
| 444 | if(state == JABBER_STATE_ERROR || | |
| 7813 | 445 | (type && (!strcmp(type, "unavailable") || |
| 446 | !strcmp(type, "unsubscribed")))) { | |
| 8043 | 447 | GaimConversation *conv; |
| 448 | ||
| 7014 | 449 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 450 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 451 | gaim_conversation_set_name(conv, buddy_name); | |
| 452 | ||
| 7395 | 453 | } else { |
| 7014 | 454 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 455 | status); | |
| 7395 | 456 | } |
| 7014 | 457 | |
| 7835 | 458 | if((jbr = jabber_buddy_find_resource(jb, NULL))) |
|
9927
7ae7d2accb3e
[gaim-migrate @ 10819]
Daniel Atallah <datallah@pidgin.im>
parents:
9847
diff
changeset
|
459 | serv_got_update(js->gc, buddy_name, TRUE, 0, b->signon, b->idle, |
| 7014 | 460 | jbr->state); |
| 461 | else | |
|
9927
7ae7d2accb3e
[gaim-migrate @ 10819]
Daniel Atallah <datallah@pidgin.im>
parents:
9847
diff
changeset
|
462 | serv_got_update(js->gc, buddy_name, FALSE, 0, 0, 0, 0); |
| 7014 | 463 | |
| 464 | g_free(buddy_name); | |
| 465 | } | |
| 466 | g_free(status); | |
| 467 | jabber_id_free(jid); | |
| 468 | } | |
| 469 | ||
| 470 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 471 | { | |
| 472 | xmlnode *presence = xmlnode_new("presence"); | |
| 473 | ||
| 474 | xmlnode_set_attrib(presence, "to", who); | |
| 475 | xmlnode_set_attrib(presence, "type", type); | |
| 476 | ||
| 477 | jabber_send(js, presence); | |
| 478 | xmlnode_free(presence); | |
| 479 | } |