Mon, 12 Sep 2005 18:52:53 +0000
[gaim-migrate @ 13781]
these variables were now essentially unused, but they didn't cause
warnings because of the line snprint line.
| 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 | ||
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10646
diff
changeset
|
23 | #include "cipher.h" |
| 7014 | 24 | #include "debug.h" |
| 25 | #include "notify.h" | |
| 26 | #include "request.h" | |
| 27 | #include "server.h" | |
| 9954 | 28 | #include "status.h" |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
29 | #include "util.h" |
| 7014 | 30 | |
| 31 | #include "buddy.h" | |
| 32 | #include "chat.h" | |
| 33 | #include "presence.h" | |
| 34 | #include "iq.h" | |
| 35 | #include "jutil.h" | |
| 36 | #include "xmlnode.h" | |
| 37 | ||
| 38 | ||
| 39 | static void chats_send_presence_foreach(gpointer key, gpointer val, | |
| 40 | gpointer user_data) | |
| 41 | { | |
| 42 | JabberChat *chat = val; | |
| 43 | xmlnode *presence = user_data; | |
| 8577 | 44 | char *chat_full_jid; |
| 45 | ||
| 46 | if(!chat->conv) | |
| 47 | return; | |
| 48 | ||
| 49 | chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, | |
| 8401 | 50 | chat->handle); |
| 7014 | 51 | |
| 8401 | 52 | xmlnode_set_attrib(presence, "to", chat_full_jid); |
| 7014 | 53 | jabber_send(chat->js, presence); |
| 8401 | 54 | g_free(chat_full_jid); |
| 7014 | 55 | } |
| 56 | ||
| 9954 | 57 | void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) { |
| 10286 | 58 | char *my_base_jid; |
| 59 | ||
| 60 | if(!js->user) | |
| 61 | return; | |
| 62 | ||
| 63 | my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
| 8185 | 64 | if(gaim_find_buddy(js->gc->account, my_base_jid)) { |
| 65 | JabberBuddy *jb; | |
| 66 | JabberBuddyResource *jbr; | |
| 67 | if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) { | |
| 9954 | 68 | JabberBuddyState state; |
| 69 | const char *msg; | |
| 70 | int priority; | |
| 71 | ||
| 72 | gaim_status_to_jabber(gstatus, &state, &msg, &priority); | |
| 73 | ||
| 10490 | 74 | if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { |
|
9744
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 { |
| 9954 | 77 | 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
|
78 | } |
| 9954 | 79 | if((jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 9990 | 80 | 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 | 81 | } else { |
| 9990 | 82 | gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); |
| 9954 | 83 | } |
| 8185 | 84 | } |
| 85 | } | |
| 86 | g_free(my_base_jid); | |
| 87 | } | |
| 88 | ||
| 7014 | 89 | |
| 10216 | 90 | void jabber_presence_send(GaimAccount *account, GaimStatus *status) |
| 7014 | 91 | { |
|
10382
32e07712e224
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
92 | GaimConnection *gc = NULL; |
|
32e07712e224
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
93 | JabberStream *js = NULL; |
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
94 | gboolean disconnected; |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
95 | int primitive; |
| 10189 | 96 | xmlnode *presence, *x, *photo; |
| 7014 | 97 | char *stripped = NULL; |
| 9954 | 98 | const char *msg; |
| 99 | JabberBuddyState state; | |
| 100 | int priority; | |
| 7014 | 101 | |
| 10486 | 102 | if(!gaim_status_is_active(status)) |
| 103 | return; | |
| 104 | ||
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
105 | disconnected = gaim_account_is_disconnected(account); |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
106 | primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
107 | |
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
108 | if(primitive != GAIM_STATUS_OFFLINE && disconnected) { |
|
10738
63ca8277c234
[gaim-migrate @ 12340]
Mark Doliner <markdoliner@pidgin.im>
parents:
10722
diff
changeset
|
109 | gaim_account_connect(account); |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
110 | } |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
111 | |
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
112 | if(disconnected) |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
113 | return; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
114 | |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
115 | gc = gaim_account_get_connection(account); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
116 | js = gc->proto_data; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
117 | |
| 9954 | 118 | gaim_status_to_jabber(status, &state, &msg, &priority); |
| 119 | ||
| 120 | if(msg) | |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
121 | gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
| 7014 | 122 | |
| 9954 | 123 | presence = jabber_presence_create(state, stripped, priority); |
| 124 | g_free(stripped); | |
| 7014 | 125 | |
| 126 | jabber_send(js, presence); | |
| 10189 | 127 | |
| 128 | if(js->avatar_hash) { | |
| 129 | x = xmlnode_new_child(presence, "x"); | |
| 130 | xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update"); | |
| 131 | photo = xmlnode_new_child(x, "photo"); | |
| 132 | xmlnode_insert_data(photo, js->avatar_hash, -1); | |
| 133 | } | |
| 134 | ||
| 7014 | 135 | g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
| 136 | xmlnode_free(presence); | |
| 8185 | 137 | |
| 9954 | 138 | jabber_presence_fake_to_self(js, status); |
| 139 | ||
|
11251
e38d86958a63
[gaim-migrate @ 13420]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11183
diff
changeset
|
140 | if(primitive == GAIM_STATUS_OFFLINE && !disconnected) { |
| 11013 | 141 | gaim_account_disconnect(account); |
| 142 | } | |
| 7014 | 143 | } |
| 144 | ||
| 9954 | 145 | xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
| 7014 | 146 | { |
| 147 | xmlnode *show, *status, *presence; | |
| 9954 | 148 | const char *show_string = NULL; |
| 7014 | 149 | |
| 150 | ||
| 151 | presence = xmlnode_new("presence"); | |
| 152 | ||
| 153 | ||
| 9954 | 154 | if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
| 155 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 156 | else if(state != JABBER_BUDDY_STATE_ONLINE && | |
| 157 | state != JABBER_BUDDY_STATE_UNKNOWN && | |
| 158 | state != JABBER_BUDDY_STATE_ERROR) | |
| 159 | show_string = jabber_buddy_state_get_status_id(state); | |
| 160 | ||
| 161 | if(show_string) { | |
| 162 | show = xmlnode_new_child(presence, "show"); | |
| 163 | xmlnode_insert_data(show, show_string, -1); | |
| 7014 | 164 | } |
| 165 | ||
| 9954 | 166 | if(msg) { |
| 7014 | 167 | status = xmlnode_new_child(presence, "status"); |
| 168 | xmlnode_insert_data(status, msg, -1); | |
| 169 | } | |
| 170 | ||
| 171 | return presence; | |
| 172 | } | |
| 173 | ||
| 174 | struct _jabber_add_permit { | |
| 175 | GaimConnection *gc; | |
| 176 | char *who; | |
| 177 | }; | |
| 178 | ||
| 179 | static void authorize_add_cb(struct _jabber_add_permit *jap) | |
| 180 | { | |
| 181 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 182 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 183 | "subscribed"); | |
| 184 | ||
| 185 | if(!gaim_find_buddy(jap->gc->account, jap->who)) | |
|
7015
bea9111282b3
[gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
186 | gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); |
| 7014 | 187 | } |
| 188 | ||
| 189 | g_free(jap->who); | |
| 190 | g_free(jap); | |
| 191 | } | |
| 192 | ||
| 193 | static void deny_add_cb(struct _jabber_add_permit *jap) | |
| 194 | { | |
| 195 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 196 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 197 | "unsubscribed"); | |
| 198 | } | |
| 199 | ||
| 200 | g_free(jap->who); | |
| 201 | g_free(jap); | |
| 202 | } | |
| 203 | ||
| 10189 | 204 | static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
| 205 | { | |
| 10941 | 206 | JabberBuddy *jb = NULL; |
| 10189 | 207 | GaimBuddy *b = NULL; |
| 10941 | 208 | xmlnode *vcard, *photo, *binval; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
209 | char *text; |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
210 | guchar *data; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
211 | gsize size; |
| 10189 | 212 | const char *from = xmlnode_get_attrib(packet, "from"); |
| 213 | ||
| 214 | if(!from) | |
| 215 | return; | |
| 216 | ||
| 10941 | 217 | jb = jabber_buddy_find(js, from, TRUE); |
| 218 | ||
| 219 | js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
| 220 | ||
| 10189 | 221 | if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 222 | (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 10941 | 223 | if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
| 11361 | 224 | (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
| 225 | (text = xmlnode_get_data(binval))) || | |
| 226 | (text = xmlnode_get_data(photo)))) { | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
11013
diff
changeset
|
227 | data = gaim_base64_decode(text, &size); |
| 10189 | 228 | |
| 10941 | 229 | gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); |
| 230 | if((b = gaim_find_buddy(js->gc->account, from))) { | |
| 231 | unsigned char hashval[20]; | |
| 232 | char hash[41], *p; | |
| 233 | int i; | |
| 10189 | 234 | |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11137
diff
changeset
|
235 | gaim_cipher_digest_region("sha1", (guchar *)data, size, |
| 10941 | 236 | sizeof(hashval), hashval, NULL); |
| 237 | p = hash; | |
| 238 | for(i=0; i<20; i++, p+=2) | |
| 239 | snprintf(p, 3, "%02x", hashval[i]); | |
| 240 | gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
| 10189 | 241 | } |
| 10941 | 242 | g_free(text); |
| 10189 | 243 | } |
| 244 | } | |
| 245 | } | |
| 246 | ||
| 7014 | 247 | void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
| 248 | { | |
| 249 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 250 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 7944 | 251 | const char *real_jid = NULL; |
| 9152 | 252 | const char *affiliation = NULL; |
| 253 | const char *role = NULL; | |
| 7014 | 254 | char *status = NULL; |
| 255 | int priority = 0; | |
| 256 | JabberID *jid; | |
| 257 | JabberChat *chat; | |
| 258 | JabberBuddy *jb; | |
| 9954 | 259 | JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
260 | GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
261 | gboolean delayed = FALSE; |
| 10189 | 262 | GaimBuddy *b = NULL; |
| 7014 | 263 | char *buddy_name; |
| 9954 | 264 | JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
| 7014 | 265 | xmlnode *y; |
| 266 | gboolean muc = FALSE; | |
| 10189 | 267 | char *avatar_hash = NULL; |
| 7014 | 268 | |
| 269 | ||
| 8043 | 270 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 271 | return; | |
| 272 | ||
| 273 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 274 | return; |
| 275 | ||
| 7014 | 276 | if(jb->error_msg) { |
| 277 | g_free(jb->error_msg); | |
| 278 | jb->error_msg = NULL; | |
| 279 | } | |
| 280 | ||
| 7813 | 281 | if(type && !strcmp(type, "error")) { |
| 8401 | 282 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 283 | |
| 9954 | 284 | state = JABBER_BUDDY_STATE_ERROR; |
| 8401 | 285 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 286 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 287 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
|
10949
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
288 | char *msg; |
|
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
289 | |
|
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
290 | msg = g_strdup_printf(_("The user %s wants to add %s to his or " |
|
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
291 | "her buddy list."), |
|
b2949f5fc512
[gaim-migrate @ 12749]
Evan Schoenberg <evands@pidgin.im>
parents:
10941
diff
changeset
|
292 | from, gaim_account_get_username(js->gc->account)); |
| 7014 | 293 | jap->gc = js->gc; |
| 294 | jap->who = g_strdup(from); | |
| 295 | ||
| 10189 | 296 | gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
|
10116
054b064145a1
[gaim-migrate @ 11153]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9990
diff
changeset
|
297 | jap, 2, |
| 7014 | 298 | _("Authorize"), G_CALLBACK(authorize_add_cb), |
| 299 | _("Deny"), G_CALLBACK(deny_add_cb)); | |
| 300 | g_free(msg); | |
| 8043 | 301 | jabber_id_free(jid); |
| 7145 | 302 | return; |
| 7813 | 303 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 304 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 305 | jabber_id_free(jid); |
| 7014 | 306 | return; |
| 307 | } else { | |
| 308 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 309 | char *show = xmlnode_get_data(y); | |
| 9954 | 310 | state = jabber_buddy_status_id_get_state(show); |
| 7014 | 311 | g_free(show); |
| 312 | } else { | |
| 9954 | 313 | state = JABBER_BUDDY_STATE_ONLINE; |
| 7014 | 314 | } |
| 315 | } | |
| 316 | ||
| 7310 | 317 | |
| 7014 | 318 | for(y = packet->child; y; y = y->next) { |
| 8135 | 319 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 320 | continue; |
| 321 | ||
| 322 | if(!strcmp(y->name, "status")) { | |
| 7615 | 323 | g_free(status); |
| 7014 | 324 | status = xmlnode_get_data(y); |
| 325 | } else if(!strcmp(y->name, "priority")) { | |
| 326 | char *p = xmlnode_get_data(y); | |
| 327 | if(p) { | |
| 328 | priority = atoi(p); | |
| 329 | g_free(p); | |
| 330 | } | |
| 331 | } else if(!strcmp(y->name, "x")) { | |
| 332 | const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
333 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 334 | /* 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
|
335 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
336 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 337 | xmlnode *z; |
| 338 | ||
| 7014 | 339 | muc = TRUE; |
| 7629 | 340 | if((z = xmlnode_get_child(y, "status"))) { |
| 341 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 342 | if(code && !strcmp(code, "201")) { | |
| 7895 | 343 | chat = jabber_chat_find(js, jid->node, jid->domain); |
| 8396 | 344 | chat->config_dialog_type = GAIM_REQUEST_ACTION; |
| 345 | chat->config_dialog_handle = | |
| 346 | gaim_request_action(js->gc, _("Create New Room"), | |
| 7895 | 347 | _("Create New Room"), |
| 348 | _("You are creating a new room. Would you like to " | |
| 349 | "configure it, or accept the default settings?"), | |
| 350 | 1, chat, 2, _("Configure Room"), | |
| 7923 | 351 | G_CALLBACK(jabber_chat_request_room_configure), |
| 7895 | 352 | _("Accept Defaults"), |
| 353 | G_CALLBACK(jabber_chat_create_instant_room)); | |
| 7629 | 354 | } |
| 355 | } | |
| 7944 | 356 | if((z = xmlnode_get_child(y, "item"))) { |
| 357 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 358 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 359 | role = xmlnode_get_attrib(z, "role"); | |
| 9931 | 360 | if(affiliation != NULL && !strcmp(affiliation, "owner")) |
| 361 | flags |= GAIM_CBFLAGS_FOUNDER; | |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
362 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
363 | if (!strcmp(role, "moderator")) |
| 9931 | 364 | flags |= GAIM_CBFLAGS_OP; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
365 | else if (!strcmp(role, "participant")) |
| 9931 | 366 | flags |= GAIM_CBFLAGS_VOICE; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
367 | } |
| 7944 | 368 | } |
| 10189 | 369 | } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
| 370 | xmlnode *photo = xmlnode_get_child(y, "photo"); | |
| 371 | if(photo) { | |
| 372 | if(avatar_hash) | |
| 373 | g_free(avatar_hash); | |
| 374 | avatar_hash = xmlnode_get_data(photo); | |
| 375 | } | |
| 7014 | 376 | } |
| 377 | } | |
| 378 | } | |
| 379 | ||
| 380 | ||
| 7322 | 381 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 382 | static int i = 1; |
| 7014 | 383 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 384 | ||
| 9954 | 385 | if(state == JABBER_BUDDY_STATE_ERROR) { |
| 8401 | 386 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 387 | |
| 7321 | 388 | if(chat->conv) { |
| 8401 | 389 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 390 | serv_got_chat_left(js->gc, chat->id); |
| 391 | } else { | |
| 8401 | 392 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 393 | } |
| 8401 | 394 | gaim_notify_error(js->gc, title, title, msg); |
| 395 | g_free(title); | |
| 396 | g_free(msg); | |
| 7014 | 397 | |
| 398 | jabber_chat_destroy(chat); | |
| 7310 | 399 | jabber_id_free(jid); |
| 7615 | 400 | g_free(status); |
| 8182 | 401 | g_free(room_jid); |
| 10189 | 402 | if(avatar_hash) |
| 403 | g_free(avatar_hash); | |
| 7014 | 404 | return; |
| 405 | } | |
| 406 | ||
| 407 | ||
| 7813 | 408 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 409 | gboolean nick_change = FALSE; |
| 7973 | 410 | |
| 9152 | 411 | /* If we haven't joined the chat yet, we don't care that someone |
| 412 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 413 | if(!chat->conv) { |
| 10558 | 414 | if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
| 9152 | 415 | jabber_chat_destroy(chat); |
| 8182 | 416 | jabber_id_free(jid); |
| 417 | g_free(status); | |
| 418 | g_free(room_jid); | |
| 10189 | 419 | if(avatar_hash) |
| 420 | g_free(avatar_hash); | |
| 8182 | 421 | return; |
| 422 | } | |
| 423 | ||
| 7973 | 424 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 425 | if(chat->muc) { |
| 426 | xmlnode *x; | |
| 8135 | 427 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 428 | const char *xmlns, *nick, *code; |
| 429 | xmlnode *stat, *item; | |
| 430 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
| 431 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
| 432 | continue; | |
| 433 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 434 | continue; | |
| 9152 | 435 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 436 | continue; |
| 9152 | 437 | if(!strcmp(code, "301")) { |
| 438 | /* XXX: we got banned */ | |
| 439 | } else if(!strcmp(code, "303")) { | |
| 440 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 441 | continue; | |
| 442 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 443 | continue; | |
| 444 | nick_change = TRUE; | |
| 445 | if(!strcmp(jid->resource, chat->handle)) { | |
| 446 | g_free(chat->handle); | |
| 447 | chat->handle = g_strdup(nick); | |
| 448 | } | |
| 449 | gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
| 450 | jabber_chat_remove_handle(chat, jid->resource); | |
| 451 | break; | |
| 452 | } else if(!strcmp(code, "307")) { | |
| 453 | /* XXX: we got kicked */ | |
| 454 | } else if(!strcmp(code, "321")) { | |
| 455 | /* XXX: removed due to an affiliation change */ | |
| 456 | } else if(!strcmp(code, "322")) { | |
| 457 | /* XXX: removed because room is now members-only */ | |
| 458 | } else if(!strcmp(code, "332")) { | |
| 459 | /* XXX: removed due to system shutdown */ | |
| 8401 | 460 | } |
| 7972 | 461 | } |
| 462 | } | |
| 463 | if(!nick_change) { | |
| 9152 | 464 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 465 | serv_got_chat_left(js->gc, chat->id); |
| 466 | jabber_chat_destroy(chat); | |
| 467 | } else { | |
| 468 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
| 7974 | 469 | status); |
| 9152 | 470 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 471 | } |
| 7014 | 472 | } |
| 473 | } else { | |
| 8182 | 474 | if(!chat->conv) { |
| 475 | chat->id = i++; | |
| 476 | chat->muc = muc; | |
| 477 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 10722 | 478 | gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); |
| 10486 | 479 | |
| 10941 | 480 | jabber_chat_disco_traffic(chat); |
| 8182 | 481 | } |
| 482 | ||
| 7973 | 483 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 484 | status); | |
| 485 | ||
| 9152 | 486 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 487 | ||
| 7014 | 488 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
489 | 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
|
490 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
491 | else |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
492 | 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
|
493 | flags); |
| 7014 | 494 | } |
| 495 | g_free(room_jid); | |
| 496 | } else { | |
| 10486 | 497 | if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) { |
| 7014 | 498 | gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 499 | "got unexpected presence from %s, ignoring\n", from); | |
| 500 | jabber_id_free(jid); | |
| 7615 | 501 | g_free(status); |
| 10189 | 502 | if(avatar_hash) |
| 503 | g_free(avatar_hash); | |
| 7014 | 504 | return; |
| 505 | } | |
| 506 | ||
| 7322 | 507 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 508 | jid->node ? "@" : "", jid->domain); | |
| 7014 | 509 | if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
| 510 | jabber_id_free(jid); | |
| 10189 | 511 | if(avatar_hash) |
| 512 | g_free(avatar_hash); | |
| 7014 | 513 | g_free(buddy_name); |
| 7615 | 514 | g_free(status); |
| 7014 | 515 | return; |
| 516 | } | |
| 517 | ||
| 10189 | 518 | if(avatar_hash) { |
| 519 | const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
| 520 | if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
| 521 | JabberIq *iq; | |
| 522 | xmlnode *vcard; | |
| 523 | ||
| 10941 | 524 | /* XXX this is a crappy way of trying to prevent |
| 525 | * someone from spamming us with presence packets | |
| 526 | * and causing us to DoS ourselves...what we really | |
| 527 | * need is a queue system that can throttle itself, | |
| 528 | * but i'm too tired to write that right now */ | |
| 529 | if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
| 530 | ||
| 531 | js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
| 10189 | 532 | |
| 10941 | 533 | iq = jabber_iq_new(js, JABBER_IQ_GET); |
| 534 | xmlnode_set_attrib(iq->node, "to", buddy_name); | |
| 535 | vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 536 | xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 537 | ||
| 538 | jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
| 539 | jabber_iq_send(iq); | |
| 540 | } | |
| 10189 | 541 | } |
| 542 | } | |
| 543 | ||
| 9954 | 544 | if(state == JABBER_BUDDY_STATE_ERROR || |
| 7813 | 545 | (type && (!strcmp(type, "unavailable") || |
| 546 | !strcmp(type, "unsubscribed")))) { | |
| 8043 | 547 | GaimConversation *conv; |
| 548 | ||
| 7014 | 549 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 550 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 551 | gaim_conversation_set_name(conv, buddy_name); | |
| 552 | ||
| 7395 | 553 | } else { |
| 9954 | 554 | jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
| 555 | state, status); | |
| 7395 | 556 | } |
| 7014 | 557 | |
| 9954 | 558 | if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 559 | if(!jbr || jbr == found_jbr) { | |
| 9990 | 560 | 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 | 561 | } |
| 562 | } else { | |
| 9990 | 563 | gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
| 9954 | 564 | } |
| 7014 | 565 | g_free(buddy_name); |
| 566 | } | |
| 567 | g_free(status); | |
| 568 | jabber_id_free(jid); | |
| 10189 | 569 | if(avatar_hash) |
| 570 | g_free(avatar_hash); | |
| 7014 | 571 | } |
| 572 | ||
| 573 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 574 | { | |
| 575 | xmlnode *presence = xmlnode_new("presence"); | |
| 576 | ||
| 577 | xmlnode_set_attrib(presence, "to", who); | |
| 578 | xmlnode_set_attrib(presence, "type", type); | |
| 579 | ||
| 580 | jabber_send(js, presence); | |
| 581 | xmlnode_free(presence); | |
| 582 | } | |
| 9954 | 583 | |
| 584 | void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
| 585 | { | |
| 10216 | 586 | const char *status_id = NULL; |
| 587 | ||
| 588 | *state = JABBER_BUDDY_STATE_UNKNOWN; | |
| 589 | *msg = NULL; | |
| 590 | *priority = 0; | |
| 9954 | 591 | |
| 592 | if(!status) { | |
| 10216 | 593 | *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
| 594 | } else { | |
| 595 | if(state) { | |
| 596 | status_id = gaim_status_get_id(status); | |
| 597 | *state = jabber_buddy_status_id_get_state(status_id); | |
| 598 | } | |
| 599 | ||
| 600 | if(msg) | |
| 601 | *msg = gaim_status_get_attr_string(status, "message"); | |
| 602 | ||
| 603 | if(priority) | |
| 604 | *priority = gaim_status_get_attr_int(status, "priority"); | |
| 9954 | 605 | } |
| 606 | ||
| 607 | } |