src/protocols/jabber/presence.c

changeset 9152
ff7aaa305cbd
parent 8577
64f25a17f8e4
child 9320
570c11e35c4a
equal deleted inserted replaced
9151:deba164a360e 9152:ff7aaa305cbd
188 void jabber_presence_parse(JabberStream *js, xmlnode *packet) 188 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
189 { 189 {
190 const char *from = xmlnode_get_attrib(packet, "from"); 190 const char *from = xmlnode_get_attrib(packet, "from");
191 const char *type = xmlnode_get_attrib(packet, "type"); 191 const char *type = xmlnode_get_attrib(packet, "type");
192 const char *real_jid = NULL; 192 const char *real_jid = NULL;
193 const char *affiliation = NULL;
194 const char *role = NULL;
193 char *status = NULL; 195 char *status = NULL;
194 int priority = 0; 196 int priority = 0;
195 JabberID *jid; 197 JabberID *jid;
196 JabberChat *chat; 198 JabberChat *chat;
197 JabberBuddy *jb; 199 JabberBuddy *jb;
284 G_CALLBACK(jabber_chat_create_instant_room)); 286 G_CALLBACK(jabber_chat_create_instant_room));
285 } 287 }
286 } 288 }
287 if((z = xmlnode_get_child(y, "item"))) { 289 if((z = xmlnode_get_child(y, "item"))) {
288 real_jid = xmlnode_get_attrib(z, "jid"); 290 real_jid = xmlnode_get_attrib(z, "jid");
291 affiliation = xmlnode_get_attrib(z, "affiliation");
292 role = xmlnode_get_attrib(z, "role");
289 } 293 }
290 } 294 }
291 } 295 }
292 } 296 }
293 297
318 322
319 323
320 if(type && !strcmp(type, "unavailable")) { 324 if(type && !strcmp(type, "unavailable")) {
321 gboolean nick_change = FALSE; 325 gboolean nick_change = FALSE;
322 326
323 /* If we haven't joined the chat yet, we don't care that someone left */ 327 /* If we haven't joined the chat yet, we don't care that someone
328 * left, or it was us leaving after we closed the chat */
324 if(!chat->conv) { 329 if(!chat->conv) {
330 if(!strcmp(jid->resource, chat->handle))
331 jabber_chat_destroy(chat);
325 jabber_id_free(jid); 332 jabber_id_free(jid);
326 g_free(status); 333 g_free(status);
327 g_free(room_jid); 334 g_free(room_jid);
328 return; 335 return;
329 } 336 }
337 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || 344 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) ||
338 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) 345 strcmp(xmlns, "http://jabber.org/protocol/muc#user"))
339 continue; 346 continue;
340 if(!(stat = xmlnode_get_child(x, "status"))) 347 if(!(stat = xmlnode_get_child(x, "status")))
341 continue; 348 continue;
342 if(!(code = xmlnode_get_attrib(stat, "code")) || strcmp(code, "303")) 349 if(!(code = xmlnode_get_attrib(stat, "code")))
343 continue; 350 continue;
344 if(!(item = xmlnode_get_child(x, "item"))) 351 if(!strcmp(code, "301")) {
345 continue; 352 /* XXX: we got banned */
346 if(!(nick = xmlnode_get_attrib(item, "nick"))) 353 } else if(!strcmp(code, "303")) {
347 continue; 354 if(!(item = xmlnode_get_child(x, "item")))
348 nick_change = TRUE; 355 continue;
349 if(!strcmp(jid->resource, chat->handle)) { 356 if(!(nick = xmlnode_get_attrib(item, "nick")))
350 g_free(chat->handle); 357 continue;
351 chat->handle = g_strdup(nick); 358 nick_change = TRUE;
359 if(!strcmp(jid->resource, chat->handle)) {
360 g_free(chat->handle);
361 chat->handle = g_strdup(nick);
362 }
363 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick);
364 jabber_chat_remove_handle(chat, jid->resource);
365 break;
366 } else if(!strcmp(code, "307")) {
367 /* XXX: we got kicked */
368 } else if(!strcmp(code, "321")) {
369 /* XXX: removed due to an affiliation change */
370 } else if(!strcmp(code, "322")) {
371 /* XXX: removed because room is now members-only */
372 } else if(!strcmp(code, "332")) {
373 /* XXX: removed due to system shutdown */
352 } 374 }
353 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick);
354 break;
355 } 375 }
356 } 376 }
357 if(!nick_change) { 377 if(!nick_change) {
358 if(!g_utf8_collate(jid->resource, gaim_conv_chat_get_nick(GAIM_CONV_CHAT(chat->conv)))) { 378 if(!g_utf8_collate(jid->resource, chat->handle)) {
359 serv_got_chat_left(js->gc, chat->id); 379 serv_got_chat_left(js->gc, chat->id);
360 jabber_chat_destroy(chat); 380 jabber_chat_destroy(chat);
361 } else { 381 } else {
362 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, 382 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
363 status); 383 status);
384 jabber_chat_remove_handle(chat, jid->resource);
364 } 385 }
365 } 386 }
366 } else { 387 } else {
367 if(!chat->conv) { 388 if(!chat->conv) {
368 chat->id = i++; 389 chat->id = i++;
374 } 395 }
375 396
376 jabber_buddy_track_resource(jb, jid->resource, priority, state, 397 jabber_buddy_track_resource(jb, jid->resource, priority, state,
377 status); 398 status);
378 399
400 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role);
401
379 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) 402 if(!jabber_chat_find_buddy(chat->conv, jid->resource))
380 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, 403 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
381 real_jid); 404 real_jid);
382 } 405 }
383 g_free(room_jid); 406 g_free(room_jid);

mercurial