You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by gs...@apache.org on 2008/05/03 00:56:40 UTC
svn commit: r652942 -
/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
Author: gseitz
Date: Fri May 2 15:56:40 2008
New Revision: 652942
URL: http://svn.apache.org/viewvc?rev=652942&view=rev
Log:
[vysper] only take resources for current session into account
relaxed checks for attributes
Modified:
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java?rev=652942&r1=652941&r2=652942&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java Fri May 2 15:56:40 2008
@@ -34,7 +34,7 @@
import org.apache.vysper.xmpp.stanza.Stanza;
import org.apache.vysper.xmpp.stanza.StanzaBuilder;
import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
-import org.apache.vysper.xmpp.xmlfragment.XMLElementVerifier;
+import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
/**
* handling presence stanzas
@@ -55,16 +55,18 @@
// or in case of multiple resources, use the from attribute or return an
// error if the from attribute is not present.
Entity initiatingEntity = sessionContext.getInitiatingEntity();
- XMLElementVerifier verifier = stanza.getVerifier();
+ XMPPCoreStanzaVerifier verifier = stanza.getCoreVerifier();
- int nrOfAttributes = stanza.getAttributes().size();
- if ((nrOfAttributes == 0 || verifier.onlyAttributesPresent("from"))
- && verifier.subElementsPresentExact(0)) {
+ boolean hasFrom = verifier.attributePresent("from");
+ boolean hasTo = verifier.attributePresent("to");
+ boolean hasType = verifier.attributePresent("type");
+
+ if (!hasTo && !hasType) {
// RFC3921bis-04#4.2.2 Initial Presence
handleOutboundInitialPresence(stanza, sessionContext,
initiatingEntity);
- } else if (verifier.onlyAttributesPresent("type", "to")
- && sessionContext.isServerToServer() == false) {
+ } else if (hasType && hasTo && !hasFrom
+ && !sessionContext.isServerToServer()) {
// this is an outbound subscription
// request/approval/cancellation/unsubscription
// stamp it with the bare JID of the user
@@ -88,10 +90,10 @@
handleOutboundSubscriptionCancellation(stampedStanza,
sessionContext);
}
- } else if (verifier.onlyAttributesPresent("from", "to")) {
+ } else if (hasFrom && hasTo && !hasType) {
// RFC3921bis-04#4.2.3
handleInboundInitialPresence(stanza, sessionContext);
- } else if (verifier.onlyAttributesPresent("type", "to", "from")) {
+ } else if (hasFrom && hasTo && hasType) {
String type = stanza.getType();
if ("subscribe".equals(type)) {
// RFC3921bis-04#3.1.3
@@ -106,11 +108,39 @@
// RFC3921bis-04#3.3.3
handleInboundUnsubscription(stanza, sessionContext);
} else if ("probe".equals(type)) {
-
+ handleInboundPresenceProbe(stanza, sessionContext);
}
- } else if (verifier.allAttributesPresent("from", "to")) {
+ } else if (hasFrom && hasTo) {
+
+ }
+
+ return null;
+ }
+
+ @SpecCompliant(spec = "RFC3921bis-04", section = "4.3.2")
+ private XMPPCoreStanza handleInboundPresenceProbe(XMPPCoreStanza stanza,
+ SessionContext sessionContext) {
+ Entity contact = stanza.getFrom();
+ Entity user = stanza.getTo();
+
+ // TODO: check whether user actually exists on the server
+ // TODO: check whether contact is in roster other than 'From', 'From
+ // +
+ // Pending Out' or 'Both'
+ if (false) {
+ return buildPresenceStanza(user.getBareJID(), contact.getBareJID(),
+ "unsubscribed");
+ }
+ List<String> resources = sessionContext.getServerRuntimeContext()
+ .getResourceRegistry().getAvailableResources(user);
+ for (String resource : resources) {
+ Entity userResource = new EntityImpl(user, resource);
+ XMPPCoreStanza presence = null;
+ // TODO: get last presence stanza sent from the user and relay it to
+ // the contact
+ relayStanza(contact, presence, sessionContext);
}
return null;
@@ -354,7 +384,8 @@
SessionContext sessionContext, Entity initiatingEntity) {
ResourceRegistry registry = sessionContext.getServerRuntimeContext()
.getResourceRegistry();
- List<String> resourceIDs = registry.getBoundResources(initiatingEntity);
+
+ List<String> resourceIDs = registry.getResourcesForSession(sessionContext);
Entity user;
if (resourceIDs.size() == 1) {
user = new EntityImpl(initiatingEntity, resourceIDs.get(0));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org