in server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java [71:173]
/* package */Stanza executeCorePresence(ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
SessionContext sessionContext, PresenceStanza presenceStanza, RosterManager rosterManager,
StanzaBroker stanzaBroker) {
if (!isSubscriptionType(presenceStanza.getPresenceType())) {
throw new RuntimeException(
"case not handled in availability handler" + presenceStanza.getPresenceType().value());
}
// TODO: either use the resource associated with the session
// (initiatingEntity)
// or in case of multiple resources, use the from attribute or return an
// error if the from attribute is not present.
Entity initiatingEntity = null;
if (sessionContext != null) {
if (sessionContext.isServerToServer()) {
initiatingEntity = presenceStanza.getFrom();
} else {
initiatingEntity = sessionContext.getInitiatingEntity();
}
}
XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
PresenceStanzaType type = presenceStanza.getPresenceType();
if (isOutboundStanza) {
// this is an outbound subscription
// request/approval/cancellation/unsubscription
// stamp it with the bare JID of the user
Entity user = initiatingEntity;
PresenceStanza stampedStanza = buildPresenceStanza(user.getBareJID(), presenceStanza.getTo().getBareJID(),
presenceStanza.getPresenceType(), null);
switch (type) {
case SUBSCRIBE:
// RFC3921bis-04#3.1.2
// user requests subsription to contact
handleOutboundSubscriptionRequest(stampedStanza, sessionContext, registry, rosterManager, stanzaBroker);
break;
case SUBSCRIBED:
// RFC3921bis-04#3.1.5
// user approves subscription to requesting contact
handleOutboundSubscriptionApproval(stampedStanza, sessionContext, registry, rosterManager,
stanzaBroker);
break;
case UNSUBSCRIBE:
// RFC3921bis-04#3.3.2
// user removes subscription from contact
handleOutboundUnsubscription(stampedStanza, sessionContext, registry, rosterManager, stanzaBroker);
break;
case UNSUBSCRIBED:
// RFC3921bis-04#3.2.2
// user approves unsubscription of contact
handleOutboundSubscriptionCancellation(stampedStanza, sessionContext, registry, rosterManager,
stanzaBroker);
break;
default:
throw new RuntimeException("unhandled case " + type.value());
}
} else /* inbound */ {
switch (type) {
case SUBSCRIBE:
// RFC3921bis-04#3.1.3
// contact requests subscription to user
return handleInboundSubscriptionRequest(presenceStanza, sessionContext, rosterManager, stanzaBroker);
case SUBSCRIBED:
// RFC3921bis-04#3.1.6
// contact approves user's subsription request
return handleInboundSubscriptionApproval(presenceStanza, sessionContext, registry, rosterManager,
stanzaBroker);
case UNSUBSCRIBE:
// RFC3921bis-04#3.3.3
// contact unsubscribes
handleInboundUnsubscription(presenceStanza, serverRuntimeContext, sessionContext, registry,
rosterManager, stanzaBroker);
return null;
case UNSUBSCRIBED:
// RFC3921bis-04#3.2.3
// contact denies subsription
handleInboundSubscriptionCancellation(presenceStanza, sessionContext, registry, rosterManager,
stanzaBroker);
return null;
default:
throw new RuntimeException("unhandled case " + type.value());
}
}
return null;
}