Add support for XEP-360: Nonzas

SMACK-682
This commit is contained in:
Florian Schmaus 2015-07-14 22:41:33 +02:00
parent 734695c80e
commit 710948c8f7
20 changed files with 126 additions and 86 deletions

View File

@ -9,6 +9,13 @@ for many of the protocol extensions.
This manual provides details about each of the "smackx" extensions, including
what it is, how to use it, and some simple example code.
Currently supported XEPs of Smack (all subprojects)
---------------------------------------------------
| Name | XEP | Description |
|---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| Nonzas | [XEP-0360](http://xmpp.org/extensions/xep-0360.html) | Defines the term "Nonza", describing every top level stream element that is not a Stanza. |
Currently supported XEPs of smack-tcp
-------------------------------------
@ -17,8 +24,8 @@ Currently supported XEPs of smack-tcp
| [Stream Management](streammanagement.md) | [XEP-0198](http://xmpp.org/extensions/xep-0198.html) | Allows active management of an XML Stream between two XMPP entities (stanza acknowledgement, stream resumption). |
Smack Extensions and currently supported XEPs by Smack (smack-extensions)
-------------------------------------------------------------------------
Smack Extensions and currently supported XEPs of smack-extensions
-----------------------------------------------------------------
| Name | XEP | Description |
|---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
@ -63,8 +70,8 @@ Smack Extensions and currently supported XEPs by Smack (smack-extensions)
| [Jive Properties](properties.md) | n/a | TODO |
Experimental Smack Extensions and currently supported XEPs by Smack (smack-experimental)
----------------------------------------------------------------------------------------
Experimental Smack Extensions and currently supported XEPs of smack-experimental
--------------------------------------------------------------------------------
| Name | XEP | Description |
|---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
@ -75,8 +82,8 @@ Experimental Smack Extensions and currently supported XEPs by Smack (smack-exper
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
Legacy Smack Extensions and currently supported XEPs by Smack (smack-legacy)
----------------------------------------------------------------------------
Legacy Smack Extensions and currently supported XEPs of smack-legacy
--------------------------------------------------------------------
If a XEP becomes 'Deprecated' or 'Obsolete' the code will be moved to the *smack-legacy* subproject.

View File

@ -36,7 +36,7 @@ import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Success;
@ -222,7 +222,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
}
@Override
public void send(PlainStreamElement element) throws NotConnectedException {
public void sendNonza(Nonza element) throws NotConnectedException {
if (done) {
throw new NotConnectedException();
}

View File

@ -68,7 +68,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
@ -340,7 +340,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected abstract void sendStanzaInternal(Stanza packet) throws NotConnectedException, InterruptedException;
@Override
public abstract void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;
public abstract void sendNonza(Nonza element) throws NotConnectedException, InterruptedException;
@Override
public abstract boolean isUsingCompression();

View File

@ -24,7 +24,7 @@ import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
public class SynchronizationPoint<E extends Exception> {
@ -79,8 +79,8 @@ public class SynchronizationPoint<E extends Exception> {
if (request instanceof Stanza) {
connection.sendStanza((Stanza) request);
}
else if (request instanceof PlainStreamElement){
connection.send((PlainStreamElement) request);
else if (request instanceof Nonza){
connection.sendNonza((Nonza) request);
} else {
throw new IllegalStateException("Unsupported element type");
}
@ -102,7 +102,7 @@ public class SynchronizationPoint<E extends Exception> {
* @throws NoResponseException if no response was received.
* @throws NotConnectedException if the connection is not connected.
*/
public void sendAndWaitForResponseOrThrow(PlainStreamElement request) throws E, NoResponseException,
public void sendAndWaitForResponseOrThrow(Nonza request) throws E, NoResponseException,
NotConnectedException, InterruptedException {
sendAndWaitForResponse(request);
switch (state) {

View File

@ -25,7 +25,7 @@ import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;
@ -186,18 +186,18 @@ public interface XMPPConnection {
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException;
/**
* Send a PlainStreamElement.
* Send a Nonza.
* <p>
* <b>This method is not meant for end-user usage!</b> It allows sending plain stream elements, which should not be
* done by a user manually. <b>Doing so may result in a unstable or unusable connection.</b> Certain Smack APIs use
* this method to send plain stream elements.
* </p>
*
* @param element
* @param nonza the Nonza to send.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;
public void sendNonza(Nonza nonza) throws NotConnectedException, InterruptedException;
/**
* Adds a connection listener to this connection that will be notified when

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,11 +19,11 @@ package org.jivesoftware.smack.compress.packet;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
public class Compress extends FullStreamElement {
public class Compress implements Nonza {
public static final String ELEMENT = "compress";
public static final String NAMESPACE = "http://jabber.org/protocol/compress";

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,9 +16,9 @@
*/
package org.jivesoftware.smack.compress.packet;
import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.Nonza;
public final class Compressed extends FullStreamElement {
public final class Compressed implements Nonza {
public static final String ELEMENT = "compressed";
public static final String NAMESPACE = Compress.NAMESPACE;

View File

@ -1,28 +0,0 @@
/**
*
* Copyright © 2014 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.packet;
/**
* Base class for Stream elements. Everything that is not a stanza (RFC 6120 8.), ie. message,
* presence and iq, should sublcass this class instead of {@link Stanza}.
*
* @author Florian Schmaus
*/
public abstract class FullStreamElement implements PlainStreamElement, ExtensionElement {
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,7 @@
package org.jivesoftware.smack.packet;
/**
* Plain stream elements, ie. everything that is <b>not a stanza</b> as defined
* A Nonza, i.e everything that is <b>not a stanza</b> as defined
* RFC 6120 8. Stanzas are {@link Message}, {@link Presence} and {@link IQ}.
* Everything else should sublcass this class instead of {@link Stanza}.
* <p>
@ -26,9 +26,10 @@ package org.jivesoftware.smack.packet;
* example plain stream elements don't count into the stanza count of XEP-198
* Stream Management.
* </p>
*
*
* @author Florian Schmaus
* @see <a href="http://xmpp.org/extensions/xep-0360.html">XEP-0360: Nonzas (are not Stanzas)</a>
*/
public interface PlainStreamElement extends TopLevelStreamElement {
public interface Nonza extends TopLevelStreamElement, ExtensionElement {
}

View File

@ -18,7 +18,7 @@ package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.util.XmlStringBuilder;
public class StartTls extends FullStreamElement {
public class StartTls implements Nonza {
public static final String ELEMENT = "starttls";
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-tls";

View File

@ -97,7 +97,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Gaston Dombiak
*/
public class StreamError extends AbstractError implements PlainStreamElement {
public class StreamError extends AbstractError implements Nonza {
public static final String ELEMENT = "stream:error";
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-streams";
@ -197,4 +197,14 @@ public class StreamError extends AbstractError implements PlainStreamElement {
return condition;
}
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}

View File

@ -23,7 +23,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* The stream open <b>tag</b>.
*/
public class StreamOpen extends FullStreamElement {
public class StreamOpen implements Nonza {
public static final String ELEMENT = "stream:stream";

View File

@ -19,7 +19,7 @@ package org.jivesoftware.smack.packet;
/**
* A XMPP top level stream element. This is either a stanza ({@link Stanza}) or
* just a plain stream element ({@link PlainStreamElement}).
* just a plain stream element ({@link Nonza}).
*/
public interface TopLevelStreamElement extends Element {

View File

@ -213,7 +213,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
authenticationText = "=";
}
// Send the authentication to the server
connection.send(new AuthMechanism(getName(), authenticationText));
connection.sendNonza(new AuthMechanism(getName(), authenticationText));
}
/**
@ -252,7 +252,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
}
// Send the authentication to the server
connection.send(responseStanza);
connection.sendNonza(responseStanza);
}
/**

View File

@ -19,7 +19,7 @@ package org.jivesoftware.smack.sasl.packet;
import java.util.Map;
import org.jivesoftware.smack.packet.AbstractError;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.sasl.SASLError;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
@ -31,7 +31,7 @@ public class SaslStreamElements {
/**
* Initiating SASL authentication by select a mechanism.
*/
public static class AuthMechanism implements PlainStreamElement {
public static class AuthMechanism implements Nonza {
public static final String ELEMENT = "auth";
private final String mechanism;
@ -59,12 +59,22 @@ public class SaslStreamElements {
public String getAuthenticationText() {
return authenticationText;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}
/**
* A SASL challenge stream element.
*/
public static class Challenge implements PlainStreamElement {
public static class Challenge implements Nonza {
public static final String ELEMENT = "challenge";
private final String data;
@ -81,12 +91,22 @@ public class SaslStreamElements {
xml.closeElement(ELEMENT);
return xml;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}
/**
* A SASL response stream element.
*/
public static class Response implements PlainStreamElement {
public static class Response implements Nonza {
public static final String ELEMENT = "response";
private final String authenticationText;
@ -111,12 +131,22 @@ public class SaslStreamElements {
public String getAuthenticationText() {
return authenticationText;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}
/**
* A SASL success stream element.
*/
public static class Success implements PlainStreamElement {
public static class Success implements Nonza {
public static final String ELEMENT = "success";
final private String data;
@ -148,13 +178,23 @@ public class SaslStreamElements {
xml.closeElement(ELEMENT);
return xml;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}
/**
* A SASL failure stream element, also called "SASL Error".
* @see <a href="http://xmpp.org/rfcs/rfc6120.html#sasl-errors">RFC 6120 6.5 SASL Errors</a>
*/
public static class SASLFailure extends AbstractError implements PlainStreamElement {
public static class SASLFailure extends AbstractError implements Nonza {
public static final String ELEMENT = "failure";
private final SASLError saslError;
@ -209,5 +249,15 @@ public class SaslStreamElements {
public String toString() {
return toXML().toString();
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String getElementName() {
return ELEMENT;
}
}
}

View File

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.JidTestUtil;
@ -124,7 +124,7 @@ public class DummyConnection extends AbstractXMPPConnection {
}
@Override
public void send(PlainStreamElement element) {
public void sendNonza(Nonza element) {
queue.add(element);
}

View File

@ -30,12 +30,12 @@ public class ClientStateIndicationManager {
public static void active(XMPPConnection connection) throws NotConnectedException, InterruptedException {
throwIaeIfNotSupported(connection);
connection.send(ClientStateIndication.Active.INSTANCE);
connection.sendNonza(ClientStateIndication.Active.INSTANCE);
}
public static void inactive(XMPPConnection connection) throws NotConnectedException, InterruptedException {
throwIaeIfNotSupported(connection);
connection.send(ClientStateIndication.Inactive.INSTANCE);
connection.sendNonza(ClientStateIndication.Inactive.INSTANCE);
}
public static boolean isSupported(XMPPConnection connection) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
*/
package org.jivesoftware.smackx.csi.packet;
import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.ExtensionElement;
/**
@ -27,7 +27,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
public class ClientStateIndication {
public static final String NAMESPACE = "urn:xmpp:csi:0";
public static final class Active extends FullStreamElement {
public static final class Active implements Nonza {
public static final Active INSTANCE = new Active();
public static final String ELEMENT = "active";
@ -50,7 +50,7 @@ public class ClientStateIndication {
}
}
public static final class Inactive extends FullStreamElement {
public static final class Inactive implements Nonza {
public static final Inactive INSTANCE = new Inactive();
public static final String ELEMENT = "inactive";

View File

@ -16,7 +16,7 @@
*/
package org.jivesoftware.smack.sm.packet;
import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -50,7 +50,7 @@ public class StreamManagement {
}
}
private static abstract class AbstractEnable extends FullStreamElement {
private static abstract class AbstractEnable implements Nonza {
/**
* Preferred maximum resumption time in seconds (optional).
@ -186,7 +186,7 @@ public class StreamManagement {
}
}
public static class Failed extends FullStreamElement {
public static class Failed implements Nonza {
public static final String ELEMENT = "failed";
private XMPPError.Condition condition;
@ -229,7 +229,7 @@ public class StreamManagement {
}
private static abstract class AbstractResume extends FullStreamElement {
private static abstract class AbstractResume implements Nonza {
private final long handledCount;
private final String previd;
@ -288,7 +288,7 @@ public class StreamManagement {
}
}
public static class AckAnswer extends FullStreamElement {
public static class AckAnswer implements Nonza {
public static final String ELEMENT = "a";
private final long handledCount;
@ -320,7 +320,7 @@ public class StreamManagement {
}
}
public static final class AckRequest extends FullStreamElement {
public static final class AckRequest implements Nonza {
public static final String ELEMENT = "r";
public static final AckRequest INSTANCE = new AckRequest();

View File

@ -66,7 +66,7 @@ import org.jivesoftware.smack.sm.packet.StreamManagement.Resumed;
import org.jivesoftware.smack.sm.packet.StreamManagement.StreamManagementFeature;
import org.jivesoftware.smack.sm.predicates.Predicate;
import org.jivesoftware.smack.sm.provider.ParseStreamManagement;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.ArrayBlockingQueueWithShutdown;
import org.jivesoftware.smack.util.Async;
@ -511,7 +511,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
}
@Override
public void send(PlainStreamElement element) throws NotConnectedException, InterruptedException {
public void sendNonza(Nonza element) throws NotConnectedException, InterruptedException {
packetWriter.sendStreamElement(element);
}
@ -847,7 +847,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
}
if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
send(new StartTls());
sendNonza(new StartTls());
}
}
// If TLS is required but the server doesn't offer it, disconnect
@ -886,7 +886,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
from = XmppStringUtils.completeJidFrom(localpart, to);
}
String id = getStreamId();
send(new StreamOpen(to, from, id));
sendNonza(new StreamOpen(to, from, id));
try {
packetReader.parser = PacketParserUtils.newXmppParser(reader);
}