// error if the from attribute is not present.
Entity initiatingEntity = sessionContext == null ? null : 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, serverRuntimeContext, sessionContext, registry,
rosterManager);
break;
case SUBSCRIBED:
// RFC3921bis-04#3.1.5
// user approves subscription to requesting contact
handleOutboundSubscriptionApproval(stampedStanza, serverRuntimeContext, sessionContext, registry,
rosterManager);
break;
case UNSUBSCRIBE:
// RFC3921bis-04#3.3.2
// user removes subscription from contact
handleOutboundUnsubscription(stampedStanza, serverRuntimeContext, sessionContext, registry,
rosterManager);
break;
case UNSUBSCRIBED:
// RFC3921bis-04#3.2.2
// user approves unsubscription of contact
handleOutboundSubscriptionCancellation(stampedStanza, serverRuntimeContext, sessionContext, registry,
rosterManager);
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, serverRuntimeContext, sessionContext, registry,
rosterManager);
case SUBSCRIBED:
// RFC3921bis-04#3.1.6
// contact approves user's subsription request
return handleInboundSubscriptionApproval(presenceStanza, serverRuntimeContext, sessionContext,
registry, rosterManager);
case UNSUBSCRIBE:
// RFC3921bis-04#3.3.3
// contact unsubscribes
handleInboundUnsubscription(presenceStanza, serverRuntimeContext, sessionContext, registry,
rosterManager);
return null;
case UNSUBSCRIBED:
// RFC3921bis-04#3.2.3
// contact denies subsription
handleInboundSubscriptionCancellation(presenceStanza, serverRuntimeContext, sessionContext, registry,
rosterManager);
return null;
default:
throw new RuntimeException("unhandled case " + type.value());
}
}
return null;
}