comparison libpurple/protocols/jabber/presence.c @ 27363:eff7db4db632

Various minor changes to jabber_presence_parse. No functionality changes. This will spit out a few more warnings and refuse to handle a presence with a non-standard type. There is no actual 'available' type, so don't bother checking for it in the last chunk in presence.c
author Paul Aurich <paul@darkrain42.org>
date Mon, 06 Jul 2009 00:45:54 +0000
parents c4196cd47602
children 735e58197140
comparison
equal deleted inserted replaced
27362:c4196cd47602 27363:eff7db4db632
484 gboolean signal_return; 484 gboolean signal_return;
485 485
486 from = xmlnode_get_attrib(packet, "from"); 486 from = xmlnode_get_attrib(packet, "from");
487 type = xmlnode_get_attrib(packet, "type"); 487 type = xmlnode_get_attrib(packet, "type");
488 488
489 if(!(jb = jabber_buddy_find(js, from, TRUE))) 489 jb = jabber_buddy_find(js, from, TRUE);
490 return; 490 g_return_if_fail(jb != NULL);
491 491
492 signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(jabber_plugin, 492 signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(jabber_plugin,
493 "jabber-receiving-presence", js->gc, type, from, packet)); 493 "jabber-receiving-presence", js->gc, type, from, packet));
494 if (signal_return) 494 if (signal_return)
495 return; 495 return;
496 496
497 if(!(jid = jabber_id_new(from))) 497 jid = jabber_id_new(from);
498 return; 498 if (jid == NULL) {
499 purple_debug_error("jabber", "Ignoring presence with malformed 'from' "
500 "JID: %s\n", from);
501 return;
502 }
499 503
500 if(jb->error_msg) { 504 if(jb->error_msg) {
501 g_free(jb->error_msg); 505 g_free(jb->error_msg);
502 jb->error_msg = NULL; 506 jb->error_msg = NULL;
503 } 507 }
504 508
505 if(type && !strcmp(type, "error")) { 509 if (type == NULL) {
510 xmlnode *show;
511 char *show_data = NULL;
512
513 state = JABBER_BUDDY_STATE_ONLINE;
514
515 show = xmlnode_get_child(packet, "show");
516 if (show) {
517 show_data = xmlnode_get_data(show);
518 if (show_data) {
519 state = jabber_buddy_show_get_state(show_data);
520 g_free(show_data);
521 } else
522 purple_debug_warning("jabber", "<show/> present on presence, "
523 "but no contents!\n");
524 }
525 } else if (g_str_equal(type, "error")) {
506 char *msg = jabber_parse_error(js, packet, NULL); 526 char *msg = jabber_parse_error(js, packet, NULL);
507 527
508 state = JABBER_BUDDY_STATE_ERROR; 528 state = JABBER_BUDDY_STATE_ERROR;
509 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); 529 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence"));
510 } else if(type && !strcmp(type, "subscribe")) { 530 } else if (g_str_equal(type, "subscribe")) {
511 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); 531 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1);
512 gboolean onlist = FALSE; 532 gboolean onlist = FALSE;
513 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); 533 PurpleAccount *account;
534 PurpleBuddy *buddy;
514 JabberBuddy *jb = NULL; 535 JabberBuddy *jb = NULL;
515 xmlnode *nick; 536 xmlnode *nick;
516 537
538 account = purple_connection_get_account(js->gc);
539 buddy = purple_find_buddy(account, from);
517 nick = xmlnode_get_child_with_namespace(packet, "nick", "http://jabber.org/protocol/nick"); 540 nick = xmlnode_get_child_with_namespace(packet, "nick", "http://jabber.org/protocol/nick");
518 if (nick) 541 if (nick)
519 nickname = xmlnode_get_data(nick); 542 nickname = xmlnode_get_data(nick);
520 543
521 if (buddy) { 544 if (buddy) {
526 549
527 jap->gc = js->gc; 550 jap->gc = js->gc;
528 jap->who = g_strdup(from); 551 jap->who = g_strdup(from);
529 jap->js = js; 552 jap->js = js;
530 553
531 purple_account_request_authorization(purple_connection_get_account(js->gc), from, NULL, nickname, NULL, onlist, 554 purple_account_request_authorization(account, from, NULL, nickname,
532 authorize_add_cb, deny_add_cb, jap); 555 NULL, onlist, authorize_add_cb, deny_add_cb, jap);
556
533 g_free(nickname); 557 g_free(nickname);
534 jabber_id_free(jid); 558 jabber_id_free(jid);
535 return; 559 return;
536 } else if(type && !strcmp(type, "subscribed")) { 560 } else if (g_str_equal(type, "subscribed")) {
537 /* we've been allowed to see their presence, but we don't care */ 561 /* we've been allowed to see their presence, but we don't care */
538 jabber_id_free(jid); 562 jabber_id_free(jid);
539 return; 563 return;
540 } else if(type && !strcmp(type, "unsubscribe")) { 564 } else if (g_str_equal(type, "unsubscribe")) {
541 /* XXX I'm not sure this is the right way to handle this, it 565 /* XXX I'm not sure this is the right way to handle this, it
542 * might be better to add "unsubscribe" to the presence status 566 * might be better to add "unsubscribe" to the presence status
543 * if lower down, but I'm not sure. */ 567 * if lower down, but I'm not sure. */
544 /* they are unsubscribing from our presence, we don't care */ 568 /* they are unsubscribing from our presence, we don't care */
545 /* Well, maybe just a little, we might want/need to start 569 /* Well, maybe just a little, we might want/need to start
546 * acknowledging this (and the others) at some point. */ 570 * acknowledging this (and the others) at some point. */
547 jabber_id_free(jid); 571 jabber_id_free(jid);
548 return; 572 return;
549 } else { 573 } else {
550 if((y = xmlnode_get_child(packet, "show"))) { 574 purple_debug_warning("jabber", "Ignoring presence with invalid type "
551 char *show = xmlnode_get_data(y); 575 "'%s'\n", type);
552 state = jabber_buddy_show_get_state(show); 576 jabber_id_free(jid);
553 g_free(show); 577 return;
554 } else {
555 state = JABBER_BUDDY_STATE_ONLINE;
556 }
557 } 578 }
558 579
559 580
560 for(y = packet->child; y; y = y->next) { 581 for(y = packet->child; y; y = y->next) {
561 const char *xmlns; 582 const char *xmlns;
686 g_free(nickname); 707 g_free(nickname);
687 return; 708 return;
688 } 709 }
689 710
690 711
691 if(type && !strcmp(type, "unavailable")) { 712 if (type && g_str_equal(type, "unavailable")) {
692 gboolean nick_change = FALSE; 713 gboolean nick_change = FALSE;
693 gboolean kick = FALSE; 714 gboolean kick = FALSE;
694 gboolean is_our_resource = FALSE; /* Is the presence about us? */ 715 gboolean is_our_resource = FALSE; /* Is the presence about us? */
695 716
696 /* If the chat nick is invalid, we haven't yet joined, or we've 717 /* If the chat nick is invalid, we haven't yet joined, or we've
885 } 906 }
886 } 907 }
887 } 908 }
888 909
889 if(state == JABBER_BUDDY_STATE_ERROR || 910 if(state == JABBER_BUDDY_STATE_ERROR ||
890 (type && (!strcmp(type, "unavailable") || 911 (type && (g_str_equal(type, "unavailable") ||
891 !strcmp(type, "unsubscribed")))) { 912 g_str_equal(type, "unsubscribed")))) {
892 PurpleConversation *conv; 913 PurpleConversation *conv;
893 914
894 jabber_buddy_remove_resource(jb, jid->resource); 915 jabber_buddy_remove_resource(jb, jid->resource);
895 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) 916 if((conv = jabber_find_unnormalized_conv(from, js->gc->account)))
896 purple_conversation_set_name(conv, buddy_name); 917 purple_conversation_set_name(conv, buddy_name);
915 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); 936 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
916 } 937 }
917 g_free(buddy_name); 938 g_free(buddy_name);
918 } 939 }
919 940
920 if (caps && (!type || g_str_equal(type, "available"))) { 941 if (caps && !type) {
921 /* handle Entity Capabilities (XEP-0115) */ 942 /* handle Entity Capabilities (XEP-0115) */
922 const char *node = xmlnode_get_attrib(caps, "node"); 943 const char *node = xmlnode_get_attrib(caps, "node");
923 const char *ver = xmlnode_get_attrib(caps, "ver"); 944 const char *ver = xmlnode_get_attrib(caps, "ver");
924 const char *hash = xmlnode_get_attrib(caps, "hash"); 945 const char *hash = xmlnode_get_attrib(caps, "hash");
925 const char *ext = xmlnode_get_attrib(caps, "ext"); 946 const char *ext = xmlnode_get_attrib(caps, "ext");