}
break;
case out_subscribe:
case out_unsubscribe:
if (pres_type == PresenceType.out_subscribe) {
SubscriptionType current_subscription =
roster_util.getBuddySubscription(session, packet.getElemTo());
if (current_subscription == null) {
roster_util.addBuddy(session, packet.getElemTo(), null, null);
} // end of if (current_subscription == null)
}
subscr_changed = roster_util.updateBuddySubscription(session, pres_type,
packet.getElemTo());
if (subscr_changed) {
roster_util.updateBuddyChange(session, results,
roster_util.getBuddyItem(session, packet.getElemTo()));
} // end of if (subscr_changed)
// According to RFC-3921 I must forward all these kind presence
// requests, it allows to resynchronize
// subscriptions in case of synchronization loss
forwardPresence(results, packet, session.getUserId());
break;
case out_subscribed:
case out_unsubscribed:
forwardPresence(results, packet, session.getUserId());
subscr_changed = roster_util.updateBuddySubscription(session, pres_type,
packet.getElemTo());
if (subscr_changed) {
roster_util.updateBuddyChange(session, results,
roster_util.getBuddyItem(session, packet.getElemTo()));
if (pres_type == PresenceType.out_subscribed) {
Element presence = (Element)session.getSessionData(PRESENCE_KEY);
if (presence != null) {
sendPresence(null, packet.getElemTo(), session.getJID(),
results, presence);
} else {
sendPresence(StanzaType.available, packet.getElemTo(),
session.getJID(), results, null);
}
} else {
sendPresence(StanzaType.unavailable, packet.getElemTo(),
session.getJID(), results, null);
}
} // end of if (subscr_changed)
break;
case in_initial:
if (packet.getElemFrom() == null) {
// That really happened already. It looks like a bug in tigase
// let's try to catch it here....
log.warning("Initial presence without from attribute set: "
+ packet.toString());
return;
}
// If other users are in 'to' or 'both' contacts, broadcast
// their preseces to all active resources
if (roster_util.isSubscribedTo(session, packet.getElemFrom())
|| (DynamicRoster.getBuddyItem(session, settings,
packet.getElemFrom()) != null)) {
updatePresenceChange(packet.getElement(), session, results);
} else {
// The code below looks like a bug to me.
// If the buddy is nt subscribed I should ignore all presences
// states from him. Commenting this out for now....
// Well, it is not a bug and it is intentional.
// All presences received from MUC come from not subscribed buddies
// therefore it seems presences from unknown buddy should be passed out
Element elem = packet.getElement().clone();
Packet result = new Packet(elem);
result.setTo(session.getConnectionId());
result.setFrom(packet.getTo());
results.offer(result);
}
break;
case in_subscribe:
// If the buddy is already subscribed then auto-reply with sybscribed
// presence stanza.
if (roster_util.isSubscribedFrom(session, packet.getElemFrom())) {
sendPresence(StanzaType.subscribed, packet.getElemFrom(),
session.getJID(), results, null);
} else {
SubscriptionType curr_sub =
roster_util.getBuddySubscription(session, packet.getElemFrom());
if (curr_sub == null) {
curr_sub = SubscriptionType.none;
roster_util.addBuddy(session, packet.getElemFrom(), null, null);
} // end of if (curr_sub == null)
roster_util.updateBuddySubscription(session, pres_type,
packet.getElemFrom());
updatePresenceChange(packet.getElement(), session, results);
} // end of else
break;
case in_unsubscribe:
subscr_changed = roster_util.updateBuddySubscription(session, pres_type,
packet.getElemFrom());
if (subscr_changed) {
// No longer needed according to RFC-3921-bis5
//sendPresence(StanzaType.unsubscribed, packet.getElemFrom(),
// session.getJID(), results, null);
//updatePresenceChange(packet.getElement(), session, results);
roster_util.updateBuddyChange(session, results,
roster_util.getBuddyItem(session, packet.getElemFrom()));
}
break;
case in_subscribed: {
SubscriptionType curr_sub =
roster_util.getBuddySubscription(session, packet.getElemFrom());
if (curr_sub == null) {
curr_sub = SubscriptionType.none;
roster_util.addBuddy(session, packet.getElemFrom(), null, null);
} // end of if (curr_sub == null)
subscr_changed = roster_util.updateBuddySubscription(session, pres_type,
packet.getElemFrom());
if (subscr_changed) {
//updatePresenceChange(packet.getElement(), session, results);
roster_util.updateBuddyChange(session, results,
roster_util.getBuddyItem(session, packet.getElemFrom()));
}
}
break;
case in_unsubscribed: {
SubscriptionType curr_sub =
roster_util.getBuddySubscription(session, packet.getElemFrom());
if (curr_sub != null) {
subscr_changed = roster_util.updateBuddySubscription(session, pres_type,
packet.getElemFrom());
if (subscr_changed) {
// No longer needed according to RFC-3921-bis5
//updatePresenceChange(packet.getElement(), session, results);
roster_util.updateBuddyChange(session, results,
roster_util.getBuddyItem(session, packet.getElemFrom()));
}
}
}
break;
case in_probe:
SubscriptionType buddy_subscr = null;
if (DynamicRoster.getBuddyItem(session, settings,
packet.getElemFrom()) != null) {
buddy_subscr = SubscriptionType.both;
} else {
buddy_subscr =