diff options
Diffstat (limited to 'src/com/isode')
15 files changed, 167 insertions, 11 deletions
diff --git a/src/com/isode/stroke/base/SafeByteArray.java b/src/com/isode/stroke/base/SafeByteArray.java index af43261..d6f817a 100644 --- a/src/com/isode/stroke/base/SafeByteArray.java +++ b/src/com/isode/stroke/base/SafeByteArray.java @@ -12,6 +12,10 @@ import com.isode.stroke.base.ByteArray; */ public class SafeByteArray extends ByteArray { + public SafeByteArray() { + + } + public SafeByteArray(String s) { super(s); } diff --git a/src/com/isode/stroke/elements/AuthChallenge.java b/src/com/isode/stroke/elements/AuthChallenge.java index 552af13..d83c19e 100644 --- a/src/com/isode/stroke/elements/AuthChallenge.java +++ b/src/com/isode/stroke/elements/AuthChallenge.java @@ -13,7 +13,7 @@ import com.isode.stroke.base.ByteArray; public class AuthChallenge implements Element { //FIXME: parser/serialiser public AuthChallenge() { - value_ = new ByteArray(); + } public AuthChallenge(ByteArray value) { diff --git a/src/com/isode/stroke/elements/AuthRequest.java b/src/com/isode/stroke/elements/AuthRequest.java index 291d31d..97ac8a0 100644 --- a/src/com/isode/stroke/elements/AuthRequest.java +++ b/src/com/isode/stroke/elements/AuthRequest.java @@ -41,6 +41,6 @@ public class AuthRequest implements Element { public void setMechanism(String mechanism) { mechanism_ = mechanism; } - private String mechanism_; - private ByteArray message_ = new ByteArray(); -} + private String mechanism_ = ""; + private ByteArray message_; +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/ErrorPayload.java b/src/com/isode/stroke/elements/ErrorPayload.java index 42e9c61..103115c 100644 --- a/src/com/isode/stroke/elements/ErrorPayload.java +++ b/src/com/isode/stroke/elements/ErrorPayload.java @@ -15,7 +15,7 @@ package com.isode.stroke.elements; public class ErrorPayload extends Payload { private Condition condition_; private Type type_; - private String text_; + private String text_ = ""; private Payload payload_; public enum Type { Cancel, Continue, Modify, Auth, Wait }; diff --git a/src/com/isode/stroke/elements/JingleFileTransferHash.java b/src/com/isode/stroke/elements/JingleFileTransferHash.java index b018549..4c22da5 100644 --- a/src/com/isode/stroke/elements/JingleFileTransferHash.java +++ b/src/com/isode/stroke/elements/JingleFileTransferHash.java @@ -23,7 +23,7 @@ import com.isode.stroke.base.NotNull; public class JingleFileTransferHash extends Payload { - private JingleFileTransferFileInfo fileInfo_; + private JingleFileTransferFileInfo fileInfo_ = new JingleFileTransferFileInfo(); /** * Default Constructor. diff --git a/src/com/isode/stroke/elements/PubSubEvent.java b/src/com/isode/stroke/elements/PubSubEvent.java new file mode 100644 index 0000000..6d5e3d2 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEvent.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2013 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.ContainerPayload; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEvent extends ContainerPayload<PubSubEventPayload> { + +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/StreamFeatures.java b/src/com/isode/stroke/elements/StreamFeatures.java index 39ebb04..db38dd2 100644 --- a/src/com/isode/stroke/elements/StreamFeatures.java +++ b/src/com/isode/stroke/elements/StreamFeatures.java @@ -73,6 +73,14 @@ public class StreamFeatures implements Element { return !authenticationMechanisms_.isEmpty(); } + public String getAuthenticationHostname() { + return authenticationHostname_; + } + + public void setAuthenticationHostname(String authenticationHostname) { + authenticationHostname_ = authenticationHostname; + } + public boolean hasStreamManagement() { return hasStreamManagement_; } @@ -106,4 +114,5 @@ public class StreamFeatures implements Element { private boolean hasSession_; private boolean hasStreamManagement_; private boolean hasRosterVersioning_; + private String authenticationHostname_; } diff --git a/src/com/isode/stroke/parser/EnumParser.java b/src/com/isode/stroke/parser/EnumParser.java new file mode 100644 index 0000000..2d35c79 --- /dev/null +++ b/src/com/isode/stroke/parser/EnumParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser; + +import java.util.Map; +import java.util.HashMap; + +public class EnumParser<T> { + + private Map<String, T> values = new HashMap<String, T>(); + + public EnumParser() { + + } + + public EnumParser addValue(T value, String text) { + values.put(text, value); + return this; + } + + public T parse(String value) { + if(values.containsKey(value)) { + return values.get(value); + } else { + return null; + } + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/parser/StreamFeaturesParser.java b/src/com/isode/stroke/parser/StreamFeaturesParser.java index 5c98268..ee4f9dc 100644 --- a/src/com/isode/stroke/parser/StreamFeaturesParser.java +++ b/src/com/isode/stroke/parser/StreamFeaturesParser.java @@ -31,6 +31,8 @@ class StreamFeaturesParser extends GenericElementParser<StreamFeatures> { inMechanisms_ = true; } else if (element.equals("compression") && ns.equals("http://jabber.org/features/compress")) { inCompression_ = true; + } else if (element.equals("ver") && ns.equals("urn:xmpp:features:rosterver")) { + getElementGeneric().setHasRosterVersioning(); } } else if (currentDepth_ == 2) { if (inCompression_ && element.equals("method")) { @@ -39,6 +41,9 @@ class StreamFeaturesParser extends GenericElementParser<StreamFeatures> { } else if (inMechanisms_ && element.equals("mechanism")) { inMechanism_ = true; currentText_ = ""; + } else if (inMechanisms_ && element.equals("hostname") && ns.equals("urn:xmpp:domain-based-name:1")) { + inAuthenticationHostname_ = true; + currentText_ = ""; } } ++currentDepth_; @@ -57,6 +62,9 @@ class StreamFeaturesParser extends GenericElementParser<StreamFeatures> { } else if (inMechanism_) { getElementGeneric().addAuthenticationMechanism(currentText_); inMechanism_ = false; + } else if (inAuthenticationHostname_) { + getElementGeneric().setAuthenticationHostname(currentText_); + inAuthenticationHostname_ = false; } } } @@ -71,4 +79,5 @@ class StreamFeaturesParser extends GenericElementParser<StreamFeatures> { private boolean inMechanism_ = false; private boolean inCompression_ = false; private boolean inCompressionMethod_ = false; + private boolean inAuthenticationHostname_ = false; } diff --git a/src/com/isode/stroke/serializer/AuthRequestSerializer.java b/src/com/isode/stroke/serializer/AuthRequestSerializer.java index 2eaed47..318eab8 100644 --- a/src/com/isode/stroke/serializer/AuthRequestSerializer.java +++ b/src/com/isode/stroke/serializer/AuthRequestSerializer.java @@ -35,4 +35,4 @@ class AuthRequestSerializer extends GenericElementSerializer<AuthRequest> { return "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"" + authRequest.getMechanism() + "\">" + value + "</auth>"; } -} +}
\ No newline at end of file diff --git a/src/com/isode/stroke/serializer/AuthResponseSerializer.java b/src/com/isode/stroke/serializer/AuthResponseSerializer.java index 8deb9b8..97bf91a 100644 --- a/src/com/isode/stroke/serializer/AuthResponseSerializer.java +++ b/src/com/isode/stroke/serializer/AuthResponseSerializer.java @@ -25,7 +25,7 @@ class AuthResponseSerializer extends GenericElementSerializer<AuthResponse> { ByteArray message = authResponse.getValue(); if (message != null) { if (message.isEmpty()) { - value = "="; + value = ""; } else { value = Base64.encode(message); } diff --git a/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java b/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java new file mode 100644 index 0000000..b5eb598 --- /dev/null +++ b/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010-2014 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.serializer; + +import com.isode.stroke.serializer.GenericElementSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLTextNode; +import com.isode.stroke.elements.StreamFeatures; +import com.isode.stroke.elements.Element; + +public class StreamFeaturesSerializer extends GenericElementSerializer<StreamFeatures> { + + public StreamFeaturesSerializer() { + super(StreamFeatures.class); + } + + public String serialize(Element element) { + StreamFeatures streamFeatures = (StreamFeatures)(element); + + XMLElement streamFeaturesElement = new XMLElement("stream:features"); + if (streamFeatures.hasStartTLS()) { + streamFeaturesElement.addNode(new XMLElement("starttls", "urn:ietf:params:xml:ns:xmpp-tls")); + } + if (!streamFeatures.getCompressionMethods().isEmpty()) { + XMLElement compressionElement = new XMLElement("compression", "http://jabber.org/features/compress"); + for(String method : streamFeatures.getCompressionMethods()) { + XMLElement methodElement = new XMLElement("method"); + methodElement.addNode(new XMLTextNode(method)); + compressionElement.addNode(methodElement); + } + streamFeaturesElement.addNode(compressionElement); + } + if (!streamFeatures.getAuthenticationMechanisms().isEmpty()) { + XMLElement mechanismsElement = new XMLElement("mechanisms", "urn:ietf:params:xml:ns:xmpp-sasl"); + for(String mechanism : streamFeatures.getAuthenticationMechanisms()) { + XMLElement mechanismElement = new XMLElement("mechanism"); + mechanismElement.addNode(new XMLTextNode(mechanism)); + mechanismsElement.addNode(mechanismElement); + } + streamFeaturesElement.addNode(mechanismsElement); + } + if (streamFeatures.hasResourceBind()) { + streamFeaturesElement.addNode(new XMLElement("bind", "urn:ietf:params:xml:ns:xmpp-bind")); + } + if (streamFeatures.hasSession()) { + streamFeaturesElement.addNode(new XMLElement("session", "urn:ietf:params:xml:ns:xmpp-session")); + } + if (streamFeatures.hasStreamManagement()) { + streamFeaturesElement.addNode(new XMLElement("sm", "urn:xmpp:sm:2")); + } + if (streamFeatures.hasRosterVersioning()) { + streamFeaturesElement.addNode(new XMLElement("ver", "urn:xmpp:features:rosterver")); + } + return streamFeaturesElement.serialize(); + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java index f54f38f..38e1eba 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java @@ -25,7 +25,8 @@ public class DelaySerializer extends GenericPayloadSerializer<Delay> { if (delay.getFrom() != null && delay.getFrom().isValid()) { delayElement.setAttribute("from", delay.getFrom().toString()); } - delayElement.setAttribute("stamp", DateTime.dateToString(delay.getStamp())); + if(delay.getStamp() != null) + delayElement.setAttribute("stamp", DateTime.dateToString(delay.getStamp())); return delayElement.serialize(); } } diff --git a/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java index 33d064d..47373f8 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java @@ -12,11 +12,16 @@ package com.isode.stroke.serializer.payloadserializers; import com.isode.stroke.elements.ErrorPayload; import com.isode.stroke.serializer.GenericPayloadSerializer; import com.isode.stroke.serializer.xml.XMLTextNode; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.PayloadSerializer; class ErrorSerializer extends GenericPayloadSerializer<ErrorPayload> { - public ErrorSerializer() { + private PayloadSerializerCollection serializers; + + public ErrorSerializer(PayloadSerializerCollection serializers) { super(ErrorPayload.class); + this.serializers = serializers; } @Override @@ -63,6 +68,13 @@ class ErrorSerializer extends GenericPayloadSerializer<ErrorPayload> { result += "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">" + textNode.serialize() + "</text>"; } + if (error.getPayload() != null) { + PayloadSerializer serializer = serializers.getPayloadSerializer(error.getPayload()); + if (serializer != null) { + result += serializer.serialize(error.getPayload()); + } + } + result += "</error>"; return result; } diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index 001d126..ac093c0 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -26,7 +26,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection addSerializer(new CarbonsReceivedSerializer(this)); addSerializer(new CarbonsSentSerializer(this)); addSerializer(new PrioritySerializer()); - addSerializer(new ErrorSerializer()); + addSerializer(new ErrorSerializer(this)); addSerializer(new InBandRegistrationPayloadSerializer()); addSerializer(new IBBSerializer()); addSerializer(new JingleIBBTransportPayloadSerializer()); |