in server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java [84:144]
/* package */Stanza executeCorePresence(ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
SessionContext sessionContext, PresenceStanza presenceStanza, RosterManager rosterManager,
StanzaBroker stanzaBroker) {
// do not handle other cases of presence
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 = sessionContext == null ? null : sessionContext.getInitiatingEntity();
XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
// check if presence reception is turned off either globally or locally
if (!serverRuntimeContext.getServerFeatures().isRelayingPresence() || (sessionContext != null
&& sessionContext.getAttribute(SessionContext.SESSION_ATTRIBUTE_PRESENCE_STANZA_NO_RECEIVE) != null)) {
return null;
}
PresenceStanzaType type = presenceStanza.getPresenceType();
boolean available = PresenceStanzaType.isAvailable(type);
if (isOutboundStanza) {
Entity user = XMPPCoreStanzaHandler.extractUniqueSenderJID(presenceStanza, sessionContext);
if (user == null) {
return ServerErrorResponses.getStanzaError(StanzaErrorCondition.UNKNOWN_SENDER, presenceStanza,
StanzaErrorType.MODIFY, "sender info insufficient: no from", null, null);
}
if (available) {
return handleOutboundAvailable(presenceStanza, serverRuntimeContext, sessionContext, rosterManager,
user, registry, stanzaBroker);
} else if (type == UNAVAILABLE) {
return handleOutboundUnavailable(presenceStanza, sessionContext, rosterManager, user, registry,
stanzaBroker);
} else if (type == PROBE) {
return handleOutboundPresenceProbe(presenceStanza, serverRuntimeContext, sessionContext, registry);
} else if (type == ERROR) {
throw new RuntimeException("not implemented yet");
} else {
throw new RuntimeException("unhandled outbound presence case " + type.value());
}
} else /* inbound */ {
if (available) {
return handleInboundAvailable(presenceStanza, serverRuntimeContext, sessionContext, registry);
} else if (type == UNAVAILABLE) {
return handleInboundUnavailable(presenceStanza, serverRuntimeContext, sessionContext, registry);
} else if (type == PROBE) {
return handleInboundPresenceProbe(presenceStanza, sessionContext, rosterManager, stanzaBroker);
} else if (type == ERROR) {
return handleInboundPresenceError(presenceStanza, serverRuntimeContext, sessionContext, registry);
} else {
throw new RuntimeException("unhandled inbound presence case " + type.value());
}
}
}