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/10/18 22:42:17 UTC

svn commit: r705922 - in /labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler: PresenceAvailabilityHandler.java PresenceSubscriptionHandler.java

Author: berndf
Date: Sat Oct 18 13:42:17 2008
New Revision: 705922

URL: http://svn.apache.org/viewvc?rev=705922&view=rev
Log:
[vysper] presence subscription workflow between two clients works now.

Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.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=705922&r1=705921&r2=705922&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 Sat Oct 18 13:42:17 2008
@@ -69,7 +69,6 @@
         PresenceStanzaType type = presenceStanza.getPresenceType();
         boolean available = PresenceStanzaType.isAvailable(type);
 
-
         if (available) {
             if (!hasTo && available) {
                 ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
@@ -102,7 +101,11 @@
     }
 
     private PresenceStanza handleInboundUnavailable(PresenceStanza presenceStanza, SessionContext sessionContext, ResourceRegistry registry) {
-        System.out.println(presenceStanza.getFrom().getFullQualifiedName() +  " has become unavailable");
+        String unavailableContact = "UNKNOWN";
+        if (presenceStanza != null && presenceStanza.getFrom() != null) {
+            unavailableContact = presenceStanza.getFrom().getFullQualifiedName();
+        }
+        System.out.println(unavailableContact + " has become unavailable");
 
         return presenceStanza;
     }
@@ -200,6 +203,12 @@
 	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
 	private PresenceStanza handleInboundInitialPresence(PresenceStanza stanza,
                                            SessionContext sessionContext, ResourceRegistry registry) {
+
+        // TODO ?check if user has blocked contact?
+
+        // write inbound stanza to the user
+        sessionContext.getResponseWriter().write(stanza);
+
         System.out.println(stanza.getFrom().getFullQualifiedName() +  " has become available");
 
         return stanza;

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java?rev=705922&r1=705921&r2=705922&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java Sat Oct 18 13:42:17 2008
@@ -451,7 +451,7 @@
             throw new RuntimeException(e);
         }
         
-        RosterSubscriptionMutator.Result result = RosterSubscriptionMutator.getInstance().add(rosterItem, TO);
+        RosterSubscriptionMutator.Result result = RosterSubscriptionMutator.getInstance().add(rosterItem, FROM);
 
         if (result != OK) {
             // TODO
@@ -563,25 +563,34 @@
 	protected Stanza handleInboundSubscriptionApproval(PresenceStanza stanza,
                                                     SessionContext sessionContext, ResourceRegistry registry, RosterManager rosterManager) {
 
-		// TODO: check if contact is in users roster with
-		// subscription="from||none" && ask="subscribe"
-		if (true /* condition is met */) {
+        Entity contact = stanza.getFrom();
+        Entity user = stanza.getTo();
+
+        Entity userBareJid = user.getBareJID();
+
+        RosterItem rosterItem;
+        try {
+            rosterItem = getExistingOrNewRosterItem(rosterManager, userBareJid, contact);
+        } catch (RosterException e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+
+        RosterSubscriptionMutator.Result result = RosterSubscriptionMutator.getInstance().add(rosterItem, TO);
+
+		if (result == OK || result == ALREADY_SET) {
 
             // write inbound stanza to the user 
             sessionContext.getResponseWriter().write(stanza);
 
             // send roster push to all interested resources
             // TODO do this only once, since inbound is multiplexed on DeliveringInboundStanzaRelay level already 
-			Entity user = stanza.getTo();
-			Entity contact = stanza.getFrom();
 			List<String> resources = registry.getInterestedResources(user);
 			for (String resource : resources) {
 				Entity userResource = new EntityImpl(user, resource);
-				Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), 
-                        contact.getBareJID(), TO, null /*TODO ask? */);
+				Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), rosterItem);
                 sessionContext.getResponseWriter().write(push);
 			}
-            
 		} else {
 			// silently drop the stanza
 		}
@@ -767,42 +776,36 @@
 		ServerRuntimeContext serverRuntimeContext = sessionContext.getServerRuntimeContext();
 		StanzaRelay stanzaRelay = serverRuntimeContext.getStanzaRelay();
 
-		// relay the stanza to the contact (via the contact's server)
-		try {
-			stanzaRelay.relay(stanza.getTo(), stanza, new IgnoreFailureStrategy());
-		} catch (DeliveryException e) {
-			e.printStackTrace();
-		}
-
 		Entity user = stanza.getFrom();
 		Entity contact = stanza.getTo();
 
         // TODO schedule a observer which can re-send the request
 
-        Roster roster = null;
+        RosterItem rosterItem = null;
         try {
-            roster = rosterManager.retrieve(user);
+            rosterItem = getExistingOrNewRosterItem(rosterManager, user.getBareJID(), contact.getBareJID());
         } catch (RosterException e) {
-            // TODO send internal server error or something like that
             e.printStackTrace();
-            return;
+            throw new RuntimeException(e);
         }
 
-        RosterItem contactItem = roster.getEntry(contact);
-        if (contactItem == null) {
-            contactItem = new RosterItem(contact, NONE);
+        RosterSubscriptionMutator.Result result = RosterSubscriptionMutator.getInstance().add(rosterItem, ASK_SUBSCRIBE);
+        if (result != OK) {
+            return;
         }
 
-        RosterSubscriptionMutator.Result result = RosterSubscriptionMutator.getInstance().add(contactItem, ASK_SUBSCRIBE);
-        if (result != OK) {
-            
+        // relay the stanza to the contact (via the contact's server)
+        try {
+            stanzaRelay.relay(stanza.getTo(), stanza, new IgnoreFailureStrategy());
+        } catch (DeliveryException e) {
+            e.printStackTrace();
         }
 
         // send roster push to all of the user's interested resources
 		List<String> resources = registry.getInterestedResources(user);
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
-			Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), contactItem);
+			Stanza push = buildRosterPushStanza(userResource, sessionContext.nextSequenceValue(), rosterItem);
             try {
                 stanzaRelay.relay(userResource, push, new IgnoreFailureStrategy());
 			} catch (DeliveryException e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org