1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 01:29:38 +02:00

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

@ -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);
}