labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r602786 - in /labs/vysper/src: main/config/ main/java/org/apache/vysper/mina/ main/java/org/apache/vysper/xmpp/applicationdomains/sasl/ main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/ main/java/org/apache/vysper/xmpp/appli...
Date Mon, 10 Dec 2007 06:30:31 GMT
Author: berndf
Date: Sun Dec  9 22:30:20 2007
New Revision: 602786

URL: http://svn.apache.org/viewvc?rev=602786&view=rev
Log:
[vysper] support logical stream re-opening
render namespaces and fix bug of non-rendered plain text elements 
removed unused stanzaWriter field
first steps towards SASL authentification

Added:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLFailureType.java
      - copied, changed from r572898, labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaErrorType.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLStanzaDictionary.java
      - copied, changed from r597307, labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/AuthHandler.java
      - copied, changed from r601223, labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/handler/StartTLSHandler.java
Modified:
    labs/vysper/src/main/config/spring-config.xml
    labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
    labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerFeatures.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/NamespaceAttribute.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/Renderer.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElementVerifier.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java

Modified: labs/vysper/src/main/config/spring-config.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/spring-config.xml?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (original)
+++ labs/vysper/src/main/config/spring-config.xml Sun Dec  9 22:30:20 2007
@@ -53,6 +53,7 @@
             <list>
                 <bean class="org.apache.vysper.xmpp.applicationdomains.base.BaseStreamStanzaDictionary"/>
                 <bean class="org.apache.vysper.xmpp.applicationdomains.starttls.StartTLSStanzaDictionary"/>
+                <!--<bean class="org.apache.vysper.xmpp.applicationdomains.sasl.SASLStanzaDictionary"/>-->
             </list>
         </constructor-arg>
         <property name="tlsContextFactory" ref="tlsContextFactory" />

Modified: labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java Sun Dec
 9 22:30:20 2007
@@ -51,6 +51,10 @@
         switchToTLS = true;
     }
 
+    public void setIsReopeningXMLStream() {
+        openingStanzaWritten = false;
+    }
+
     public void write(Stanza stanza) {
 
         if (switchToTLS) {

Modified: labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java Sun Dec  9
22:30:20 2007
@@ -62,7 +62,9 @@
             protocolWorker.processTLSEstablished(session, stateHolder);
             return;
         } else if (message == SSLFilter.SESSION_UNSECURED) {
-            throw new IllegalStateException("server must close session!"); // TODO
+            // TODO
+            return;
+//            throw new IllegalStateException("server must close session!"); 
         }
 
         throw new IllegalArgumentException("xmpp handler only accepts Stanza-typed messages");

Copied: labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLFailureType.java
(from r572898, labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaErrorType.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLFailureType.java?p2=labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLFailureType.java&p1=labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaErrorType.java&r1=572898&r2=602786&rev=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaErrorType.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLFailureType.java
Sun Dec  9 22:30:20 2007
@@ -15,21 +15,28 @@
  * permissions and limitations under the License.                      *
  ***********************************************************************/
 
-package org.apache.vysper.xmpp.stanza;
+package org.apache.vysper.xmpp.applicationdomains.sasl;
 
 /**
+ * see also RFC3920/7.5
  */
-public enum StanzaErrorType {
+public enum SASLFailureType {
 
-    CANCEL("cancel"), // do not retry (the error is unrecoverable) 
-    CONTINUE("continue"), // proceed (the condition was only a warning)
-    MODIFY("modify"), // retry after changing the data sent
-    AUTH("auth"), // retry after providing credentials
-    WAIT("wait"); // retry after waiting (the error is temporary)
+    ABORTED("aborted"), // sent as ACK in reply to <abort/>  
+    INCORRECT_ENCODING("incorrect-encoding"), // BASE64 or other encoding is incorrect 
+    INVALID_AUTHZID("invalid-authzid"), // RFC 3920: "authzid provided by the initiating
entity is invalid, 
+                                        // either because it is incorrectly formatted or
because the initiating 
+                                        // entity does not have permissions to authorize
that ID"
+    INVALID_MECHANISM("invalid-mechanism"), // this mechanism is not supported by the server

+    MALFORMED_REQUEST("malformed-request"), // request is malformed 
+    MECHANISMS_TOO_WEAK("mechanisms-too-weak"), // RFC 3920: "The mechanism requested by
the initiating entity is 
+                                                // weaker than server policy permits for
that initiating entity" 
+    NOT_AUTHORIZED("not-authorized"), // sent credentials could not be positively verified

+    TEMPORARY_AUTH_FAILURE("temporary-auth-failure"); // try again later! 
 
     private final String value;
 
-    StanzaErrorType(String value) {
+    SASLFailureType(String value) {
         this.value = value;
     }
 
@@ -37,4 +44,4 @@
         return value;
     }
 
-}
+}
\ No newline at end of file

Copied: labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLStanzaDictionary.java
(from r597307, labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLStanzaDictionary.java?p2=labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLStanzaDictionary.java&p1=labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java&r1=597307&r2=602786&rev=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/SASLStanzaDictionary.java
Sun Dec  9 22:30:20 2007
@@ -15,21 +15,21 @@
  * permissions and limitations under the License.                      *
  ***********************************************************************/
 
-package org.apache.vysper.xmpp.applicationdomains.starttls;
+package org.apache.vysper.xmpp.applicationdomains.sasl;
 
-import org.apache.vysper.xmpp.applicationdomains.starttls.handler.StartTLSHandler;
+import org.apache.vysper.xmpp.applicationdomains.sasl.handler.AuthHandler;
 import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 
 /**
- * handler for base stanzas from RFC3920 (xmpp core)<br/>
- * they are: stream, message, presence, iq
+ * handler for authorization stanzas from RFC3920 (xmpp core)<br/>
+ * they are: auth, challenge, abort, aborted, failure, sucess, response
  */
-public class StartTLSStanzaDictionary extends NamespaceHandlerDictionary {
+public class SASLStanzaDictionary extends NamespaceHandlerDictionary {
 
-    public StartTLSStanzaDictionary() {
-        super(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_TLS);
-        register(new StartTLSHandler());
+    public SASLStanzaDictionary() {
+        super(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL);
+        register(new AuthHandler());
         seal();
     }
 }

Copied: labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/AuthHandler.java
(from r601223, labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/handler/StartTLSHandler.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/AuthHandler.java?p2=labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/AuthHandler.java&p1=labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/handler/StartTLSHandler.java&r1=601223&r2=602786&rev=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/handler/StartTLSHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/sasl/handler/AuthHandler.java
Sun Dec  9 22:30:20 2007
@@ -15,7 +15,7 @@
  * permissions and limitations under the License.                      *
  ***********************************************************************/
 
-package org.apache.vysper.xmpp.applicationdomains.starttls.handler;
+package org.apache.vysper.xmpp.applicationdomains.sasl.handler;
 
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
@@ -28,12 +28,13 @@
 import org.apache.vysper.xmpp.server.response.ServerResponses;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.xmlfragment.XMLElementVerifier;
+import org.apache.vysper.xmpp.applicationdomains.sasl.SASLFailureType;
 
 /**
  */
-public class StartTLSHandler implements StanzaHandler {
+public class AuthHandler implements StanzaHandler {
     public String getName() {
-        return "starttls";
+        return "auth";
     }
 
     public boolean verify(Stanza stanza) {
@@ -44,15 +45,16 @@
 
     public ResponseStanzaContainer execute(Stanza stanza, SessionContext sessionContext,
SessionStateHolder sessionStateHolder) {
         XMLElementVerifier xmlElementVerifier = stanza.getVerifier();
-        boolean tlsNamespace = xmlElementVerifier.namespacePresent(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_TLS);
+        boolean saslNamespace = xmlElementVerifier.namespacePresent(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL);
 
-        if (!tlsNamespace) {
-            return respondTLSFailure();
+        if (!saslNamespace) {
+            return respondSASLFailure();
         }
-        if (sessionStateHolder.getState() != SessionState.STARTED) {
-            return respondTLSFailure();
+        if (sessionStateHolder.getState() != SessionState.ENCRYPTED) {
+            return respondSASLFailure();
         }
-        
+
+        // TODO implement logic below!
         Stanza responseStanza = new ServerResponses().getTLSProceed();
 
         // if all is correct, go to next phase
@@ -63,7 +65,7 @@
         return new ResponseStanzaContainerImpl(responseStanza);
     }
 
-    private ResponseStanzaContainer respondTLSFailure() {
-        return new ResponseStanzaContainerImpl(ServerErrorResponses.getInstance().getTLSFailure());
+    private ResponseStanzaContainer respondSASLFailure() {
+        return new ResponseStanzaContainerImpl(ServerErrorResponses.getInstance().getSASLFailure(SASLFailureType.MALFORMED_REQUEST));
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/starttls/StartTLSStanzaDictionary.java
Sun Dec  9 22:30:20 2007
@@ -22,8 +22,8 @@
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 
 /**
- * handler for base stanzas from RFC3920 (xmpp core)<br/>
- * they are: stream, message, presence, iq
+ * handler for stream securing (TLS) stanzas from RFC3920 (xmpp core)<br/>
+ * they are: starttls, failure, proceed 
  */
 public class StartTLSStanzaDictionary extends NamespaceHandlerDictionary {
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java Sun Dec
 9 22:30:20 2007
@@ -125,6 +125,7 @@
             return;
         }
         sessionStateHolder.setState(SessionState.ENCRYPTED);
+        sessionContext.setIsReopeningXMLStream();
     }
 
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java Sun
Dec  9 22:30:20 2007
@@ -29,7 +29,6 @@
     protected ServerRuntimeContext serverRuntimeContext;
     protected String sessionId;
     protected String xmlLang;
-    protected StanzaWriter stanzaWriter;
     protected SessionStateHolder sessionStateHolder;
     protected Entity serverEntity;
     private Entity initiatingEntity;
@@ -88,13 +87,9 @@
         xmlLang = languageCode;
     }
 
-    public StanzaWriter getResponseWriter() {
-        return stanzaWriter;
-    }
-
     public void endSession() {
+        StanzaWriter stanzaWriter = getResponseWriter();
         stanzaWriter.close();
-        stanzaWriter = null;
         sessionStateHolder.setState(SessionState.CLOSED);
         // TODO close underlying transport (TCP socket)
     }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerFeatures.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerFeatures.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerFeatures.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerFeatures.java Sun Dec  9
22:30:20 2007
@@ -16,12 +16,16 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.server;
 
+import java.util.List;
+import java.util.ArrayList;
+
 /**
  * switch configuration of optional server features 
  */
 public class ServerFeatures {
 
     private boolean startTLSRequired = true;
+    private List<String> authenticationMethods = new ArrayList<String>();
 
     public ServerFeatures() {
         // default constructor

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java Sun Dec  9
22:30:20 2007
@@ -62,4 +62,11 @@
      * signals the underlying transport to handle TLS handshake
      */
     void switchToTLS();
+
+    /**
+     * this method signals that from now on a new <stream:stream>... xml stream begins.
+     * this is used at the very beginning of the session, then again after encryption and
after
+     * authentication. see RFC3920.7.5.7 and RFC3920.6.2
+     */
+    void setIsReopeningXMLStream();
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
Sun Dec  9 22:30:20 2007
@@ -17,12 +17,13 @@
 
 package org.apache.vysper.xmpp.server.response;
 
-import org.apache.vysper.xmpp.stanza.StanzaErrorCondition;
-import org.apache.vysper.xmpp.stanza.StanzaErrorType;
+import org.apache.vysper.xmpp.applicationdomains.sasl.SASLFailureType;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.protocol.StreamErrorCondition;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.stanza.StanzaErrorCondition;
+import org.apache.vysper.xmpp.stanza.StanzaErrorType;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
 import org.apache.vysper.xmpp.xmlfragment.XMLElement;
 
@@ -139,5 +140,13 @@
         stanzaBuilder.addNamespaceAttribute(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_TLS);
         return stanzaBuilder.getFinalStanza();
     }
-    
+
+    public Stanza getSASLFailure(SASLFailureType failureType) {
+        StanzaBuilder stanzaBuilder = new StanzaBuilder("failure");
+        stanzaBuilder.addNamespaceAttribute(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL);
+        if (failureType != null) {
+            stanzaBuilder.startInnerElement(failureType.toString()).endInnerElement();
+        }
+        return stanzaBuilder.getFinalStanza();
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerResponses.java
Sun Dec  9 22:30:20 2007
@@ -78,6 +78,7 @@
 
         stanzaBuilder.startInnerElement("mechanisms")
             .addNamespaceAttribute(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL)
+            .startInnerElement("mechanism").addText("ANONYMOUS").endInnerElement()
             .startInnerElement("mechanism").addText("EXTERNAL").endInnerElement()
             .startInnerElement("mechanism").addText("DIGEST-MD5").endInnerElement()
             .startInnerElement("mechanism").addText("PLAIN").endInnerElement()

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/writer/DenseStanzaLogRenderer.java Sun
Dec  9 22:30:20 2007
@@ -47,6 +47,8 @@
                 renderError(stringBuilder, stanza, firstInnerElement);
             } else if ("presence".equals(outerName)) {
                 renderPresence(stringBuilder, stanza, firstInnerElement);
+            } else if ("auth".equals(outerName)) {
+                renderAuth(stringBuilder, stanza, firstInnerElement);
             }
 
             return stringBuilder.toString();
@@ -55,10 +57,21 @@
         }
     }
 
+    private static void renderAuth(StringBuilder stringBuilder, XMLElement stanza, XMLElement
firstInnerElement) {
+        renderAttribute(stringBuilder, stanza, "mechanism");
+    }
+
     private static void renderStreamStart(StringBuilder stringBuilder, XMLElement stanza,
XMLElement firstInnerElement) {
         try {
             XMLElement features = stanza.getSingleInnerElementsNamed("features");
             if (features != null) {
+                XMLElement starttls = features.getSingleInnerElementsNamed("starttls");
+                if (starttls != null) {
+                    stringBuilder.append(ELEMENT_SEPARATOR);
+                    stringBuilder.append("starttls");
+                    XMLElement required = starttls.getSingleInnerElementsNamed("required");
+                    if (required != null) stringBuilder.append("[required]");
+                }
                 XMLElement mechanisms = features.getSingleInnerElementsNamed("mechanisms");
                 if (mechanisms != null) {
                     stringBuilder.append(ELEMENT_SEPARATOR);

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
Sun Dec  9 22:30:20 2007
@@ -46,18 +46,23 @@
     
     public boolean isBalanced(List<XMLParticle> particles) throws DecodingException
{
 
+        // stack, where opened elements are pushed and closing are pulled
         Stack<XMLParticle> openedElements = new Stack<XMLParticle>();
         
         for (XMLParticle particle : particles) {
             if (particle.isSpecialElement()) {
-                continue;
+                continue; // special elements do not have nested elements 
             } else if (particle.isOpeningOnlyElement()) {
                 openedElements.push(particle);
             } else if (particle.isText()) {
-                continue;
+                continue; // text does not have nested elements 
             } else if (particle.isOpeningElement()) {
+                // is also closing (because opening-only are already handled),
+                // so don't push them 
                 continue;
             } else if (particle.isClosingElement()) {
+                // TODO handle </stream:stream> here as a special case
+                if (openedElements.isEmpty()) return false; // not balanced, because no matching
opener on stack
                 if (!openedElements.peek().getElementName().equals(particle.getElementName()))
{
                     throw new IllegalStateException();
                 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/NamespaceAttribute.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/NamespaceAttribute.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/NamespaceAttribute.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/NamespaceAttribute.java Sun
Dec  9 22:30:20 2007
@@ -24,13 +24,13 @@
     public static final String DEFAULT_NAMESPACE = "";
 
     public static final String XMLNS = "xmlns";
-    public static final String XMLNS_COLON = "xmlns:";
+    public static final String XMLNS_AND_COLON = "xmlns:";
 
     public NamespaceAttribute(String value) {
         super(XMLNS, value);
     }
 
     public NamespaceAttribute(String nsPrefix, String value) {
-        super(XMLNS_COLON + nsPrefix, value);
+        super(XMLNS_AND_COLON + nsPrefix, value);
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/Renderer.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/Renderer.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/Renderer.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/Renderer.java Sun Dec  9
22:30:20 2007
@@ -18,8 +18,7 @@
 package org.apache.vysper.xmpp.xmlfragment;
 
 /**
- * TODO support namespaces
- * TODO force "stream" for "http://etherx.jabber.org/streams"
+ * TODO support namespaces (inherited from outer/inheriting for inner elements)
  */
 public class Renderer {
 
@@ -27,6 +26,7 @@
     private StringBuffer openElementBuffer = new StringBuffer();
     private StringBuffer elementContentBuffer = new StringBuffer();
     private StringBuffer closeElementBuffer = new StringBuffer();
+    private static final String COLON = ":";
 
     public Renderer(XMLElement element) {
         this.topElement = element;
@@ -52,8 +52,10 @@
 
     private void renderXMLElement(XMLElement element, StringBuffer openElementBuffer, StringBuffer
elementContentBuffer, StringBuffer closeElementBuffer) {
         String name = element.getName();
+        String namespace = element.getNamespace();
 
-        openElementBuffer.append("<").append(name);
+        openElementBuffer.append("<");
+        renderElementName(openElementBuffer, element, namespace, name);
         for (Attribute attribute : element.getAttributes()) {
             openElementBuffer.append(" ");
             renderAttribute(openElementBuffer, attribute);
@@ -62,12 +64,29 @@
 
         for (XMLFragment xmlFragment : element.getInnerFragments()) {
             if (xmlFragment instanceof XMLElement) renderXMLElement((XMLElement) xmlFragment,
elementContentBuffer, elementContentBuffer, elementContentBuffer);
-            else if (xmlFragment instanceof XMLText) ((XMLText) xmlFragment).getText();
-            else throw new UnsupportedOperationException("cannot render XML fragement of
type " + xmlFragment.getClass().getName());
+            else if (xmlFragment instanceof XMLText) {
+                elementContentBuffer.append(((XMLText) xmlFragment).getText());
+            } else {
+                throw new UnsupportedOperationException("cannot render XML fragement of type
" + xmlFragment.getClass().getName());
+            }
         }
 
-        closeElementBuffer.append("</").append(name).append(">");
+        closeElementBuffer.append("</");
+        renderElementName(closeElementBuffer, element, namespace, name);
+        closeElementBuffer.append(">");
 
+    }
+
+    private void renderElementName(StringBuffer buffer, XMLElement element, String namespace,
String name) {
+        // if the element has a namespace prefix, retrieves the prefix from the defining
attribute 
+        if (namespace != null) {
+            String namespaceIdentifier = element.getVerifier().getNamespaceIdentifier(namespace);
+            if (namespaceIdentifier != null) {
+                buffer.append(namespaceIdentifier).append(COLON);
+            }
+        }
+
+        buffer.append(name);
     }
 
     private void renderAttribute(StringBuffer buffer, Attribute attribute) {

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElement.java Sun Dec 
9 22:30:20 2007
@@ -30,7 +30,15 @@
 public class XMLElement implements XMLFragment {
 
     private String name;
+
+    /**
+     * example element: <a:b xmlns:a="http://ns.org" >
+     * element's namespace. the prefix for the element name is taken from the corresponding
attribute.
+     * if the namespace is 'http://ns.org', then element name b is prefixed with a.
+     * NOTE: the namespace value must NOT be "b"!  
+     */
     private String namespace;
+    
     private List<Attribute> attributes;
     private List<XMLFragment> innerFragments;
     protected XMLElementVerifier xmlElementVerifier;

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElementVerifier.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElementVerifier.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElementVerifier.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/XMLElementVerifier.java Sun
Dec  9 22:30:20 2007
@@ -76,9 +76,24 @@
         return false; // not present
     }
 
+    /**
+     * example for "http://myNS.org/anything", this method returns "myNS" for 
+     * element <test xmlns:myNS="http://myNS.org/anything" />
+     * @return the identifier for the given namespace definition
+     */
+    public String getNamespaceIdentifier(String namespace) {
+        for (Attribute attribute : element.getAttributes()) {
+            if (attribute.getValue().equals(namespace) 
+                && attribute.getName().startsWith(NamespaceAttribute.XMLNS_AND_COLON))
{
+                return attribute.getName().substring(NamespaceAttribute.XMLNS_AND_COLON.length());
+            }
+        }
+        return null;
+    } 
+    
     private boolean isNamespaceAttribute(Attribute attribute) {
         return (attribute.getName().equalsIgnoreCase(NamespaceAttribute.XMLNS)
-                 || attribute.getName().startsWith(NamespaceAttribute.XMLNS_COLON));
+                 || attribute.getName().startsWith(NamespaceAttribute.XMLNS_AND_COLON));
     }
 
     public String getUniqueXMLNSValue() {

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java?rev=602786&r1=602785&r2=602786&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java Sun Dec
 9 22:30:20 2007
@@ -31,6 +31,7 @@
     private Stanza recordedResponse = null;
     private boolean closed = false;
     private boolean switchToTLSCalled;
+    private boolean isReopeningXMLStream;
 
     public TestSessionContext(SessionStateHolder sessionStateHolder) {
         this(new DefaultServerRuntimeContext(new EntityImpl(null, "test", null), new RecordingStanzaRelay()),
sessionStateHolder);
@@ -40,7 +41,6 @@
         super(serverRuntimeContext, sessionStateHolder);
         sessionId = serverRuntimeContext.getNextSessionId();
         xmlLang = "de";
-        stanzaWriter = this;
     }
 
     public Stanza getRecordedResponse() {
@@ -48,7 +48,6 @@
     }
 
     public void close() {
-        stanzaWriter = null;
         closed = true;
     }
 
@@ -64,8 +63,16 @@
         this.sessionStateHolder.setState(sessionState);
     }
 
+    public StanzaWriter getResponseWriter() {
+        return this;
+    }
+
     public void switchToTLS() {
         switchToTLSCalled = true;
+    }
+
+    public void setIsReopeningXMLStream() {
+        isReopeningXMLStream = true;
     }
 
     public boolean isSwitchToTLSCalled() {



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


Mime
View raw message