You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by be...@apache.org on 2008/06/24 23:27:19 UTC
svn commit: r671350 -
/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
Author: berndf
Date: Tue Jun 24 14:27:19 2008
New Revision: 671350
URL: http://svn.apache.org/viewvc?rev=671350&view=rev
Log:
[vysper] simplify presence handling (LABS-133)
Modified:
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java?rev=671350&r1=671349&r2=671350&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java Tue Jun 24 14:27:19 2008
@@ -64,81 +64,43 @@
boolean hasFrom = verifier.attributePresent("from");
boolean hasTo = verifier.attributePresent("to");
- boolean hasType = verifier.attributePresent("type");
boolean isOutbound = !hasFrom && hasTo && !sessionContext.isServerToServer();
PresenceStanzaType type = presenceStanza.getPresenceType();
+ boolean available = PresenceStanzaType.isAvailable(type);
- if (!hasTo && !hasType) {
- ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
- boolean isPresenceUpdate = resourceState != null && resourceState == ResourceState.AVAILABLE;
+ if (available) {
+ if (!hasTo && available) {
+ ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
+
+ boolean isPresenceUpdate = resourceState != null && resourceState == ResourceState.AVAILABLE;
- // TODO in case of !isPresenceUpdate, should we check for resourceState != ResourceState.INTERESTED ?
- // RFC3921bis-04#4.2.2 Initial Presence
- // RFC3921bis-04#4.4.2 Initial Presence
+ // TODO in case of !isPresenceUpdate, should we check for resourceState != ResourceState.INTERESTED ?
+ // RFC3921bis-04#4.2.2 Initial Presence
+ // RFC3921bis-04#4.4.2 Initial Presence
- handleOutboundPresence(presenceStanza, isPresenceUpdate, sessionContext, registry, initiatingEntity, rosterManager);
-
- } else if (isOutbound && hasType) {
- // 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 ERROR:
- throw new RuntimeException("not implemented yet");
-
- case PROBE:
- throw new RuntimeException("not implemented yet");
-
- default:
- throw new RuntimeException("unhandled case " + type.value());
- }
-
- } else if (hasFrom && hasTo && !hasType) {
- // RFC3921bis-04#4.2.3
- handleInboundInitialPresence(presenceStanza, sessionContext, registry);
-
- } else if (hasFrom && hasTo && hasType) {
-
- switch (type) {
-
- case ERROR:
- throw new RuntimeException("not implemented yet");
-
- case PROBE:
- handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
-
- case UNAVAILABLE:
- throw new RuntimeException("not implemented yet");
-
- default:
- throw new RuntimeException("unhandled case " + type.value());
+ handleOutboundPresence(presenceStanza, isPresenceUpdate, sessionContext, registry, initiatingEntity, rosterManager);
+ } else if (!isOutbound) {
+ // RFC3921bis-04#4.2.3
+ handleInboundInitialPresence(presenceStanza, sessionContext, registry);
+ } else {
+ throw new RuntimeException("unhandled presence available case");
}
-
- } else if (hasFrom && hasTo) {
- throw new RuntimeException("unhandled direct presence stanza");
- } else if (hasType && type == UNAVAILABLE) {
+ } else if (type == UNAVAILABLE) {
handleInboundUnavailable(presenceStanza, sessionContext);
+ } else if (type == PROBE) {
+ handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
+ } else if (type == ERROR) {
+ throw new RuntimeException("not implemented yet");
} else {
- System.err.println("unhandled presence case");
+ throw new RuntimeException("unhandled presence case");
}
return null;
}
- private void handleOutboundPresenceUpdate(PresenceStanza stanza, SessionContext sessionContext,
- ResourceRegistry registry, Entity initiatingEntity) {
- updateResourcePriority(registry, initiatingEntity, stanza.getPrioritySafe());
- System.out.println("C: has updated his presence");
- }
-
private void handleInboundUnavailable(PresenceStanza presenceStanza, SessionContext sessionContext) {
ResourceRegistry registry = sessionContext.getServerRuntimeContext().getResourceRegistry();
@@ -189,6 +151,7 @@
}
if (!presenceUpdate) registry.setResourceState(user.getResource(), ResourceState.AVAILABLE);
+ updateResourcePriority(registry, sessionContext.getInitiatingEntity(), stanza.getPrioritySafe());
List<Entity> contacts = new ArrayList<Entity>();
@@ -237,7 +200,6 @@
@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
private void handleInboundInitialPresence(PresenceStanza stanza,
SessionContext sessionContext, ResourceRegistry registry) {
- updateResourcePriority(registry, sessionContext.getInitiatingEntity(), stanza.getPrioritySafe());
Entity user = stanza.getTo();
List<String> resources = registry.getAvailableResources(user);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org