summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-17 07:33:03 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-18 20:18:56 (GMT)
commitf9c7be7adde21ab29b5e268a726506bb06510ead (patch)
treeb1e2f276c7015eb74e955b856bdf944c8f4f4041
parent4addb6419080db814094ab501d69111adffeb5be (diff)
downloadstroke-f9c7be7adde21ab29b5e268a726506bb06510ead.zip
stroke-f9c7be7adde21ab29b5e268a726506bb06510ead.tar.bz2
Adds Jingle Elements.
Adds: JinglePayload, its Parser and Serializer and JingleReasonParser. JingleContentPayload Element, its Parser and Serializer. JingleDesciption Element. JingleFileTransferDescription Element, its Parser and Serializer. JingleFileTransferFileInfo Element, its Parser and Serializer. JingleFileTransferHash Element, its Parser and Serializer. JingleIBBTransportPayload Element, its Parser and Serializer. JingleS5BTransportPayload Element, its Parser and Serializer. JingleTransportPayload Element and HashElement. Updates HostAddress access specifier for getInetAddress(). License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for: JingleParser JingleContentPayload Parser and Serializer. JingleFileTransferHash Parser and Serializer. JingleFileTranferFileInfo Parser and Serializer. JingleFileTransferDescription Parser and Serializer. JingleIBBTransportPayload Parser and Serializer. JingleS5BTransportPayload Parser and Serializer. All tests passes. Change-Id: Ife1b7fef00efc57d8d0d4290f3280327439abbb6
-rw-r--r--src/com/isode/stroke/elements/HashElement.java61
-rw-r--r--src/com/isode/stroke/elements/JingleContentPayload.java137
-rw-r--r--src/com/isode/stroke/elements/JingleDescription.java20
-rw-r--r--src/com/isode/stroke/elements/JingleFileTransferDescription.java43
-rw-r--r--src/com/isode/stroke/elements/JingleFileTransferFileInfo.java222
-rw-r--r--src/com/isode/stroke/elements/JingleFileTransferHash.java49
-rw-r--r--src/com/isode/stroke/elements/JingleIBBTransportPayload.java62
-rw-r--r--src/com/isode/stroke/elements/JinglePayload.java265
-rw-r--r--src/com/isode/stroke/elements/JingleS5BTransportPayload.java172
-rw-r--r--src/com/isode/stroke/elements/JingleTransportPayload.java35
-rw-r--r--src/com/isode/stroke/network/HostAddress.java2
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java8
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParser.java119
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserFactory.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParser.java88
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserFactory.java56
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParser.java111
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParser.java82
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParser.java63
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleParser.java174
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleParserFactory.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleReasonParser.java119
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParser.java176
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java6
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializer.java96
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializer.java41
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializer.java71
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializer.java48
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializer.java37
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JinglePayloadSerializer.java158
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializer.java98
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java90
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java79
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java65
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java79
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java34
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java649
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java50
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java189
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java66
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java57
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java65
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java32
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java55
44 files changed, 4230 insertions, 1 deletions
diff --git a/src/com/isode/stroke/elements/HashElement.java b/src/com/isode/stroke/elements/HashElement.java
new file mode 100644
index 0000000..8c85c53
--- /dev/null
+++ b/src/com/isode/stroke/elements/HashElement.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 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.elements;
+
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.ByteArray;
+
+public class HashElement {
+
+ private String algorithm_ = "";
+ private ByteArray hash_;
+
+ public HashElement(String algorithm, ByteArray hash) {
+ algorithm_ = algorithm;
+ hash_ = hash;
+ }
+
+ /**
+ * @param algorithm, Not Null.
+ * @param hash, Not Null.
+ */
+ public void setHashValue(String algorithm, ByteArray hash) {
+ NotNull.exceptIfNull(algorithm, "algorithm");
+ NotNull.exceptIfNull(hash, "hash");
+ algorithm_ = algorithm;
+ hash_ = hash;
+ }
+
+ /**
+ * @return algorithm, Not Null.
+ */
+ public String getAlgorithm() {
+ return algorithm_;
+ }
+
+ /**
+ * @return hash, Not Null.
+ */
+ public ByteArray getHashValue() {
+ return hash_;
+ }
+
+ public boolean equals(Object other) {
+
+ if ((!(other instanceof HashElement)) || other == null) {
+ return false;
+ }
+
+ HashElement guest = (HashElement) other;
+ return (algorithm_.equals(guest.algorithm_)) && (hash_.equals(guest.hash_));
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleContentPayload.java b/src/com/isode/stroke/elements/JingleContentPayload.java
new file mode 100644
index 0000000..423a499
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleContentPayload.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2011 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.base.NotNull;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.JingleDescription;
+import com.isode.stroke.elements.JingleTransportPayload;
+import java.util.Vector;
+
+public class JingleContentPayload extends Payload {
+
+ public enum Creator {
+ UnknownCreator,
+ InitiatorCreator,
+ ResponderCreator
+ };
+
+ /*public enum Senders {
+ NoSenders,
+ InitiatorSender,
+ ResponderSender,
+ BothSenders,
+ };*/
+
+ private Creator creator;
+ private String name = "";
+ //private Senders senders;
+ private Vector<JingleDescription> descriptions = new Vector<JingleDescription>();
+ private Vector<JingleTransportPayload> transports = new Vector<JingleTransportPayload>();
+
+ /**
+ * Default Constructor.
+ */
+ public JingleContentPayload() {
+ this.creator = Creator.UnknownCreator;
+ }
+
+ /**
+ * @return creator, Not Null.
+ */
+ public Creator getCreator() {
+ return creator;
+ }
+
+ /**
+ * @param creator, Not Null.
+ */
+ public void setCreator(Creator creator) {
+ NotNull.exceptIfNull(creator, "creator");
+ this.creator = creator;
+ }
+
+ /**
+ * @return name, Not Null.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name, Not Null.
+ */
+ public void setName(String name) {
+ NotNull.exceptIfNull(name, "name");
+ this.name = name;
+ }
+
+ /**
+ * @return descriptions, Not Null.
+ */
+ public Vector<JingleDescription> getDescriptions() {
+ return descriptions;
+ }
+
+ /**
+ * @param description, Not Null.
+ */
+ public void addDescription(JingleDescription description) {
+ NotNull.exceptIfNull(description, "description");
+ descriptions.add(description);
+ }
+
+ /**
+ * @return transports, Not Null.
+ */
+ public Vector<JingleTransportPayload> getTransports() {
+ return transports;
+ }
+
+ /**
+ * @param transport, Not Null.
+ */
+ public void addTransport(JingleTransportPayload transport) {
+ NotNull.exceptIfNull(transport, "transport");
+ transports.add(transport);
+ }
+
+ /**
+ * Get the description of the given type.
+ * @param <T> type.
+ * @param type, not null.
+ * @return description of given type.
+ */
+ public <T extends Payload> T getDescription(T type) {
+ for (JingleDescription description : descriptions) {
+ if (description.getClass().isAssignableFrom(type.getClass())) {
+ return (T)description;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the transport of the given type.
+ * @param <T> type.
+ * @param type, not null.
+ * @return transport of given type.
+ */
+ public <T extends Payload> T getTransport(T type) {
+ for (JingleTransportPayload transport : transports) {
+ if (transport.getClass().isAssignableFrom(type.getClass())) {
+ return (T)transport;
+ }
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleDescription.java b/src/com/isode/stroke/elements/JingleDescription.java
new file mode 100644
index 0000000..5f454c2
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleDescription.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2011 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.base.NotNull;
+import com.isode.stroke.elements.Payload;
+
+public class JingleDescription extends Payload {
+
+
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleFileTransferDescription.java b/src/com/isode/stroke/elements/JingleFileTransferDescription.java
new file mode 100644
index 0000000..e883b37
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleFileTransferDescription.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011-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.elements;
+
+import com.isode.stroke.elements.JingleDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferDescription extends JingleDescription {
+
+ private JingleFileTransferFileInfo fileInfo_;
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferDescription() {
+
+ }
+
+ /**
+ * @param fileInfo, Not Null.
+ */
+ public void setFileInfo(JingleFileTransferFileInfo fileInfo) {
+ NotNull.exceptIfNull(fileInfo, "fileInfo");
+ fileInfo_ = fileInfo;
+ }
+
+ /**
+ * @return fileInfo, Not Null.
+ */
+ public JingleFileTransferFileInfo getFileInfo() {
+ return fileInfo_;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleFileTransferFileInfo.java b/src/com/isode/stroke/elements/JingleFileTransferFileInfo.java
new file mode 100644
index 0000000..100afd9
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleFileTransferFileInfo.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 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.elements;
+
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.ByteArray;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @brief This class represents the file info used in XEP-0234.
+ */
+public class JingleFileTransferFileInfo extends Payload {
+
+ private String name_ = "";
+ private String description_ = "";
+ private String mediaType_ = "";
+ private long size_;
+ private Date date_;
+ private boolean supportsRangeRequests_;
+ private long rangeOffset_;
+ private Map<String, ByteArray> hashes_ = new HashMap<String, ByteArray>();
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferFileInfo() {
+ this("", "", 0, new Date(0L));
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param name, NotNull.
+ */
+ public JingleFileTransferFileInfo(String name) {
+ this(name, "", 0, new Date(0L));
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param name, NotNull.
+ * @param description, NotNull.
+ */
+ public JingleFileTransferFileInfo(String name, String description) {
+ this(name, description, 0, new Date(0L));
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param name, NotNull.
+ * @param description, NotNull.
+ * @param size.
+ */
+ public JingleFileTransferFileInfo(String name, String description, long size) {
+ this(name, description, size, new Date(0L));
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param name, NotNull.
+ * @param description, NotNull.
+ * @param size.
+ * @param date, NotNull.
+ */
+ public JingleFileTransferFileInfo(String name, String description, long size, Date date) {
+ NotNull.exceptIfNull(name, "name");
+ NotNull.exceptIfNull(description, "description");
+ NotNull.exceptIfNull(date, "date");
+ this.name_ = name;
+ this.description_ = description;
+ this.size_ = size;
+ this.date_ = date;
+ this.supportsRangeRequests_ = false;
+ this.rangeOffset_ = 0;
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ /**
+ * @param name, NotNull.
+ */
+ public void setName(String name) {
+ NotNull.exceptIfNull(name, "name");
+ name_ = name;;
+ }
+
+ /**
+ * @return name, NotNull.
+ */
+ public String getName() {
+ return name_;
+ }
+
+ /**
+ * @param description, NotNull.
+ */
+ public void setDescription(String description) {
+ NotNull.exceptIfNull(description, "description");
+ description_ = description;
+ }
+
+ /**
+ * @return description, NotNull.
+ */
+ public String getDescription() {
+ return description_;
+ }
+
+ /**
+ * @param mediaType, NotNull.
+ */
+ public void setMediaType(String mediaType) {
+ NotNull.exceptIfNull(mediaType, "mediaType");
+ mediaType_ = mediaType;
+ }
+
+ /**
+ * @return mediaType, NotNull.
+ */
+ public String getMediaType() {
+ return mediaType_;
+ }
+
+ /**
+ * @param size.
+ */
+ public void setSize(long size) {
+ size_ = size;
+ }
+
+ /**
+ * @return size.
+ */
+ public long getSize() {
+ return size_;
+ }
+
+ /**
+ * @param date, NotNull.
+ */
+ public void setDate(Date date) {
+ NotNull.exceptIfNull(date, "date");
+ date_ = date;
+ }
+
+ /**
+ * @return date, NotNull.
+ */
+ public Date getDate() {
+ return date_;
+ }
+
+ /**
+ * @param supportsRangeRequests_.
+ */
+ public void setSupportsRangeRequests(boolean supportsIt) {
+ supportsRangeRequests_ = supportsIt;
+ }
+
+ /**
+ * @return supportsRangeRequests_.
+ */
+ public boolean getSupportsRangeRequests() {
+ return supportsRangeRequests_;
+ }
+
+ /**
+ * @param offset.
+ */
+ public void setRangeOffset(long offset) {
+ supportsRangeRequests_ = true;
+ rangeOffset_ = offset;
+ }
+
+ /**
+ * @return offset.
+ */
+ public long getRangeOffset() {
+ return rangeOffset_;
+ }
+
+ /**
+ * @param hash, NotNull.
+ */
+ public void addHash(HashElement hash) {
+ NotNull.exceptIfNull(hash, "hash");
+ hashes_.put(hash.getAlgorithm(), hash.getHashValue());
+ }
+
+ /**
+ * @return hashes map.
+ */
+ public Map<String, ByteArray> getHashes() {
+ return hashes_;
+ }
+
+ /**
+ * @param algorithm, NotNull.
+ * @return ByteArray, can be null.
+ */
+ public ByteArray getHash(String algorithm) {
+ NotNull.exceptIfNull(algorithm, "algorithm");
+ ByteArray ret = null;
+ if(hashes_.containsKey(algorithm)) {
+ ret = new ByteArray(hashes_.get(algorithm));
+ }
+ return ret;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleFileTransferHash.java b/src/com/isode/stroke/elements/JingleFileTransferHash.java
new file mode 100644
index 0000000..b018549
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleFileTransferHash.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 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.elements;
+
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.JingleDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferHash extends Payload {
+
+ private JingleFileTransferFileInfo fileInfo_;
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferHash() {
+
+ }
+
+ /**
+ * @param fileInfo, NotNull.
+ */
+ public void setFileInfo(JingleFileTransferFileInfo fileInfo) {
+ NotNull.exceptIfNull(fileInfo, "fileInfo");
+ fileInfo_ = fileInfo;
+ }
+
+ /**
+ * @return fileInfo, NotNull.
+ */
+ public JingleFileTransferFileInfo getFileInfo() {
+ return fileInfo_;
+ }
+}
diff --git a/src/com/isode/stroke/elements/JingleIBBTransportPayload.java b/src/com/isode/stroke/elements/JingleIBBTransportPayload.java
new file mode 100644
index 0000000..677bef3
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleIBBTransportPayload.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011-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.elements;
+
+import com.isode.stroke.elements.JingleTransportPayload;
+import com.isode.stroke.base.NotNull;
+
+public class JingleIBBTransportPayload extends JingleTransportPayload {
+
+ public enum StanzaType {
+ IQStanza,
+ MessageStanza
+ };
+
+ private Integer blockSize;
+ private StanzaType stanzaType;
+
+ /**
+ * Default Constructor.
+ */
+ public JingleIBBTransportPayload() {
+ this.stanzaType = StanzaType.IQStanza;
+ }
+
+ /**
+ * @param stanzaType, NotNull.
+ */
+ public void setStanzaType(StanzaType stanzaType) {
+ NotNull.exceptIfNull(stanzaType, "stanzaType");
+ this.stanzaType = stanzaType;
+ }
+
+ /**
+ * @return stanzaType, NotNull.
+ */
+ public StanzaType getStanzaType() {
+ return stanzaType;
+ }
+
+ /**
+ * @return blockSize.
+ */
+ public Integer getBlockSize() {
+ return blockSize;
+ }
+
+ /**
+ * @param blockSize.
+ */
+ public void setBlockSize(Integer blockSize) {
+ this.blockSize = blockSize;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JinglePayload.java b/src/com/isode/stroke/elements/JinglePayload.java
new file mode 100644
index 0000000..c90e802
--- /dev/null
+++ b/src/com/isode/stroke/elements/JinglePayload.java
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2011-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.elements;
+
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.jid.JID;
+import java.util.Vector;
+
+public class JinglePayload extends Payload {
+
+ public static class Reason extends Payload {
+
+ public enum Type {
+ UnknownType,
+ AlternativeSession,
+ Busy,
+ Cancel,
+ ConnectivityError,
+ Decline,
+ Expired,
+ FailedApplication,
+ FailedTransport,
+ GeneralError,
+ Gone,
+ IncompatibleParameters,
+ MediaError,
+ SecurityError,
+ Success,
+ Timeout,
+ UnsupportedApplications,
+ UnsupportedTransports
+ };
+
+ public Type type;
+ public String text = "";
+
+ public Reason() {
+ this(Type.UnknownType, "");
+ }
+
+ public Reason(Type type) {
+ this(type, "");
+ }
+
+ public Reason(Type type, String text) {
+ NotNull.exceptIfNull(type, "type");
+ NotNull.exceptIfNull(text, "text");
+ this.type = type;
+ this.text = text;
+ }
+
+ /**
+ * @return Type, NotNull.
+ */
+ public Type getType() {
+ return this.type;
+ }
+
+ /**
+ * @param Type, NotNull.
+ */
+ public void setType(Type type) {
+ NotNull.exceptIfNull(type, "type");
+ this.type = type;
+ }
+
+ /**
+ * @return Text, NotNull.
+ */
+ public String getText() {
+ return this.text;
+ }
+
+ /**
+ * @param Text, NotNull.
+ */
+ public void setText(String text) {
+ NotNull.exceptIfNull(text, "text");
+ this.text = text;
+ }
+ }
+
+ public enum Action {
+ UnknownAction,
+ ContentAccept,
+ ContentAdd,
+ ContentModify,
+ ContentReject,
+ ContentRemove,
+ DescriptionInfo,
+ SecurityInfo,
+ SessionAccept,
+ SessionInfo,
+ SessionInitiate,
+ SessionTerminate,
+ TransportAccept,
+ TransportInfo,
+ TransportReject,
+ TransportReplace
+ };
+
+ private Action action;
+ private JID initiator = new JID();
+ private JID responder = new JID();
+ private String sessionID = "";
+ private Vector<Payload> payloads = new Vector<Payload>();
+ private Reason reason = null;
+
+ public JinglePayload() {
+ this(Action.SessionTerminate, "");
+ }
+
+ public JinglePayload(Action action, String sessionID) {
+ NotNull.exceptIfNull(action, "action");
+ NotNull.exceptIfNull(sessionID, "sessionID");
+ this.action = action;
+ this.sessionID = sessionID;
+ }
+
+ /**
+ * @param action, NotNull.
+ */
+ public void setAction(Action action) {
+ NotNull.exceptIfNull(action, "action");
+ this.action = action;
+ }
+
+ /**
+ * @return action, NotNull.
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * @param initiator, NotNull.
+ */
+ public void setInitiator(JID initiator) {
+ NotNull.exceptIfNull(initiator, "initiator");
+ this.initiator = initiator;
+ }
+
+ /**
+ * @return initiator, NotNull.
+ */
+ public JID getInitiator() {
+ return initiator;
+ }
+
+ /**
+ * @param responder, NotNull.
+ */
+ public void setResponder(JID responder) {
+ NotNull.exceptIfNull(responder, "responder");
+ this.responder = responder;
+ }
+
+ /**
+ * @return responder, NotNull.
+ */
+ public JID getResponder() {
+ return responder;
+ }
+
+ /**
+ * @param sessionID, NotNull.
+ */
+ public void setSessionID(String id) {
+ NotNull.exceptIfNull(id, "sessionID");
+ sessionID = id;
+ }
+
+ /**
+ * @return sessionID, NotNull.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * @param content.
+ */
+ public void addContent(JingleContentPayload content) {
+ this.payloads.add(content);
+ }
+
+ /**
+ * @param payload.
+ */
+ public void addPayload(Payload payload) {
+ this.payloads.add(payload);
+ }
+
+ /**
+ * @return payloads, of type JingleContentPayload.
+ */
+ public Vector<JingleContentPayload> getContents() {
+ return getPayloads(new JingleContentPayload());
+ }
+
+ /**
+ * @return payloads.
+ */
+ public Vector<Payload> getPayloads() {
+ return payloads;
+ }
+
+ /**
+ * Get the payload of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return payload of given type, can be null
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Payload> T getPayload(T type) {
+ for (Payload payload : payloads) {
+ if (payload.getClass().isAssignableFrom(type.getClass())) {
+ return (T)payload;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the payloads of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return list of payloads of given type, not null but can be empty
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Payload> Vector<T> getPayloads(T type) {
+ Vector<T> matched_payloads = new Vector<T>();
+ for (Payload payload : payloads) {
+ if (payload.getClass().isAssignableFrom(type.getClass())) {
+ matched_payloads.add((T)payload);
+ }
+ }
+ return matched_payloads;
+ }
+
+ /**
+ * @param reason.
+ */
+ public void setReason(Reason reason) {
+ this.reason = reason;
+ }
+
+ /**
+ * @return reason.
+ */
+ public Reason getReason() {
+ return reason;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleS5BTransportPayload.java b/src/com/isode/stroke/elements/JingleS5BTransportPayload.java
new file mode 100644
index 0000000..e9ee67f
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleS5BTransportPayload.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2011-2015 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.JingleTransportPayload;
+import com.isode.stroke.elements.Bytestreams;
+import com.isode.stroke.network.HostAddressPort;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.base.NotNull;
+import java.util.Vector;
+
+public class JingleS5BTransportPayload extends JingleTransportPayload {
+
+ public enum Mode {
+ TCPMode, // default case
+ UDPMode
+ };
+
+ public static class Candidate {
+
+ public enum Type {
+ DirectType, // default case
+ AssistedType,
+ TunnelType,
+ ProxyType
+ };
+
+ public String cid = "";
+ public JID jid = new JID();
+ public HostAddressPort hostPort;
+ public int priority;
+ public Type type;
+
+ public Candidate() {
+ this.priority = 0;
+ this.type = Type.DirectType;
+ }
+ }
+
+ public class CompareCandidate {
+ public boolean compareTo(JingleS5BTransportPayload.Candidate c1, JingleS5BTransportPayload.Candidate c2) {
+ return (c1.priority < c2.priority);
+ }
+ }
+
+ private Mode mode;
+ private Vector<Candidate> candidates = new Vector<Candidate>();
+
+ private String candidateUsedCID = "";
+ private String activatedCID = "";
+ private String dstAddr = "";
+ private boolean candidateError;
+ private boolean proxyError;
+
+ public JingleS5BTransportPayload() {
+ this.mode = Mode.TCPMode;
+ this.candidateError = false;
+ this.proxyError = false;
+ }
+
+ /**
+ * @return mode, Not Null.
+ */
+ public Mode getMode() {
+ return mode;
+ }
+
+ /**
+ * @param mode, Not Null.
+ */
+ public void setMode(Mode mode) {
+ NotNull.exceptIfNull(mode, "mode");
+ this.mode = mode;
+ }
+
+ /**
+ * @return candidates, Not Null.
+ */
+ public Vector<Candidate> getCandidates() {
+ return candidates;
+ }
+
+ /**
+ * @param candidate, NotNull.
+ */
+ public void addCandidate(Candidate candidate) {
+ NotNull.exceptIfNull(candidate, "candidate");
+ candidates.add(candidate);
+ }
+
+ /**
+ * @param cid, NotNull.
+ */
+ public void setCandidateUsed(String cid) {
+ NotNull.exceptIfNull(cid, "cid");
+ candidateUsedCID = cid;
+ }
+
+ /**
+ * @return candidateUsedCID, Not Null.
+ */
+ public String getCandidateUsed() {
+ return candidateUsedCID;
+ }
+
+ /**
+ * @param cid, NotNull.
+ */
+ public void setActivated(String cid) {
+ NotNull.exceptIfNull(cid, "cid");
+ activatedCID = cid;
+ }
+
+ /**
+ * @return activatedCID, Not Null.
+ */
+ public String getActivated() {
+ return activatedCID;
+ }
+
+ /**
+ * @param addr, NotNull.
+ */
+ public void setDstAddr(String addr) {
+ NotNull.exceptIfNull(addr, "addr");
+ dstAddr = addr;
+ }
+
+ /**
+ * @return dstAddr, Not Null.
+ */
+ public String getDstAddr() {
+ return dstAddr;
+ }
+
+ /**
+ * @param candidateError.
+ */
+ public void setCandidateError(boolean hasError) {
+ candidateError = hasError;
+ }
+
+ /**
+ * @return candidateError.
+ */
+ public boolean hasCandidateError() {
+ return candidateError;
+ }
+
+ /**
+ * @param proxyError.
+ */
+ public void setProxyError(boolean hasError) {
+ proxyError = hasError;
+ }
+
+ /**
+ * @return proxyError.
+ */
+ public boolean hasProxyError() {
+ return proxyError;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/JingleTransportPayload.java b/src/com/isode/stroke/elements/JingleTransportPayload.java
new file mode 100644
index 0000000..a474eae
--- /dev/null
+++ b/src/com/isode/stroke/elements/JingleTransportPayload.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 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.base.NotNull;
+import com.isode.stroke.elements.Payload;
+
+public class JingleTransportPayload extends Payload {
+
+ private String sessionID = "";
+
+ /**
+ * @param Id, Not Null.
+ */
+ public void setSessionID(String id) {
+ NotNull.exceptIfNull(id, "id");
+ sessionID = id;
+ }
+
+ /**
+ * @return Id, Not Null.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/network/HostAddress.java b/src/com/isode/stroke/network/HostAddress.java
index 7145fb3..c1b3600 100644
--- a/src/com/isode/stroke/network/HostAddress.java
+++ b/src/com/isode/stroke/network/HostAddress.java
@@ -53,7 +53,7 @@ public class HostAddress {
return address_ != null;
}
- InetAddress getInetAddress() {
+ public InetAddress getInetAddress() {
return address_;
}
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index 84a0b43..08d9f28 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -21,6 +21,14 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new GenericPayloadParserFactory<LastParser>("query", "jabber:iq:last", LastParser.class));
addFactory(new GenericPayloadParserFactory<BodyParser>("body", BodyParser.class));
addFactory(new GenericPayloadParserFactory<SubjectParser>("subject", SubjectParser.class));
+ addFactory(new JingleParserFactory(this));
+ addFactory(new GenericPayloadParserFactory<JingleReasonParser>("reason", "urn:xmpp:jingle:1", JingleReasonParser.class));
+ addFactory(new GenericPayloadParserFactory<JingleFileTransferFileInfoParser>("file", "", JingleFileTransferFileInfoParser.class));
+ addFactory(new JingleFileTransferDescriptionParserFactory(this));
+ addFactory(new GenericPayloadParserFactory<JingleFileTransferHashParser>("checksum", "urn:xmpp:jingle:apps:file-transfer:4", JingleFileTransferHashParser.class));
+ addFactory(new GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser>("transport", "urn:xmpp:jingle:transports:ibb:1", JingleIBBTransportMethodPayloadParser.class));
+ addFactory(new GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser>("transport", "urn:xmpp:jingle:transports:s5b:1", JingleS5BTransportMethodPayloadParser.class));
+ addFactory(new JingleContentPayloadParserFactory(this));
//addFactory(new GenericPayloadParserFactory<PriorityParser>("priority", PriorityParser.class));
addFactory(new ErrorParserFactory(this));
addFactory(new SoftwareVersionParserFactory());
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParser.java
new file mode 100644
index 0000000..5f114c2
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParser.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleTransportPayload;
+import com.isode.stroke.elements.JingleDescription;
+import com.isode.stroke.base.NotNull;
+
+public class JingleContentPayloadParser extends GenericPayloadParser<JingleContentPayload> {
+
+ private PayloadParserFactoryCollection factories;
+ private int level;
+ private PayloadParser currentPayloadParser;
+
+ public JingleContentPayloadParser(PayloadParserFactoryCollection factories) {
+ super(new JingleContentPayload());
+ this.factories = factories;
+ this.level = 0;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes, NotNull.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(attributes, "attributes");
+ if (level == 0) {
+ String creator = "";
+ if(attributes.getAttributeValue("creator") != null) {
+ creator = attributes.getAttributeValue("creator");
+ } else {
+ creator = "";
+ }
+ if (creator.equals("initiator")) {
+ getPayloadInternal().setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ } else if (creator.equals("responder")) {
+ getPayloadInternal().setCreator(JingleContentPayload.Creator.ResponderCreator);
+ } else {
+ getPayloadInternal().setCreator(JingleContentPayload.Creator.UnknownCreator);
+ }
+ if(attributes.getAttributeValue("name") != null) {
+ getPayloadInternal().setName(attributes.getAttributeValue("name"));
+ } else {
+ getPayloadInternal().setName("");
+ }
+ }
+
+ if (level == 1) {
+ PayloadParserFactory payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes);
+ if (payloadParserFactory != null) {
+ currentPayloadParser = payloadParserFactory.createPayloadParser();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleStartElement(element, ns, attributes);
+ }
+
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+
+ if (currentPayloadParser != null) {
+ if (level >= 1) {
+ currentPayloadParser.handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if(currentPayloadParser.getPayload() instanceof JingleTransportPayload) {
+ JingleTransportPayload transport = (JingleTransportPayload)(currentPayloadParser.getPayload());
+ if (transport != null) {
+ getPayloadInternal().addTransport(transport);
+ }
+ }
+ if(currentPayloadParser.getPayload() instanceof JingleDescription) {
+ JingleDescription description = (JingleDescription)(currentPayloadParser.getPayload());
+ if (description != null) {
+ getPayloadInternal().addDescription(description);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ if (level > 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserFactory.java b/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserFactory.java
new file mode 100644
index 0000000..d31303e
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserFactory.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParserFactory;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.payloadparsers.JingleContentPayloadParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.base.NotNull;
+
+public class JingleContentPayloadParserFactory implements PayloadParserFactory {
+
+ private PayloadParserFactoryCollection factories;
+
+ /**
+ * JingleContentPayloadParserFactory();
+ */
+ public JingleContentPayloadParserFactory(PayloadParserFactoryCollection factories) {
+ this.factories = factories;
+ }
+
+ /**
+ * @param attributes.
+ * @param element, Not Null.
+ * @param attributes, Not NUll.
+ */
+ public boolean canParse(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(attributes, "attributes");
+ return element.equals("content") && ns.equals("urn:xmpp:jingle:1");
+ }
+
+ /**
+ * @return PayloadParser()
+ */
+ public PayloadParser createPayloadParser() {
+ return new JingleContentPayloadParser(factories);
+ }
+}
+
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParser.java
new file mode 100644
index 0000000..1b74fa9
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParser.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 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.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferDescriptionParser extends GenericPayloadParser<JingleFileTransferDescription> {
+
+ private PayloadParserFactoryCollection factories;
+ private int level = 0;
+ private PayloadParser currentPayloadParser;
+
+ public JingleFileTransferDescriptionParser(PayloadParserFactoryCollection factories) {
+ super(new JingleFileTransferDescription());
+ this.factories = factories;
+ this.level = 0;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ if (level == 1) {
+ PayloadParserFactory payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes);
+ if (payloadParserFactory != null) {
+ currentPayloadParser = payloadParserFactory.createPayloadParser();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleStartElement(element, ns, attributes);
+ }
+ ++level;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleEndElement(element, ns);
+ }
+
+ if (level == 0) {
+ JingleFileTransferFileInfo info = (JingleFileTransferFileInfo)(currentPayloadParser.getPayload());
+ if (info != null) {
+ getPayloadInternal().setFileInfo(info);
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserFactory.java b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserFactory.java
new file mode 100644
index 0000000..ec884ec
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserFactory.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 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.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParserFactory;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferDescriptionParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferDescriptionParserFactory implements PayloadParserFactory {
+
+ private PayloadParserFactoryCollection factories;
+
+ /**
+ * JingleFileTransferDescriptionParserFactory();
+ */
+ public JingleFileTransferDescriptionParserFactory(PayloadParserFactoryCollection factories) {
+ this.factories = factories;
+ }
+
+ /**
+ * @param attributes.
+ * @param element, Not Null.
+ * @param attributes, Not NUll.
+ */
+ public boolean canParse(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(ns, "ns");
+ return element.equals("description") && ns.equals("urn:xmpp:jingle:apps:file-transfer:4");
+ }
+
+ /**
+ * @return PayloadParser()
+ */
+ public PayloadParser createPayloadParser() {
+ return new JingleFileTransferDescriptionParser(factories);
+ }
+}
+
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParser.java
new file mode 100644
index 0000000..edb40f4
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParser.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 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.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.stringcodecs.Base64;
+
+public class JingleFileTransferFileInfoParser extends GenericPayloadParser<JingleFileTransferFileInfo> {
+
+ private int level = 0;
+ private String charData = "";
+ private String hashAlg = "";
+ private Long rangeOffset = null;
+
+ public JingleFileTransferFileInfoParser() {
+ super(new JingleFileTransferFileInfo());
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ charData = "";
+ if (element.equals("hash")) {
+ if(attributes.getAttributeValue("algo") != null) {
+ hashAlg = attributes.getAttributeValue("algo");
+ } else {
+ hashAlg = "";
+ }
+ }
+ else if (element.equals("range")) {
+ if(attributes.getAttributeValue("offset") != null) {
+ try {
+ rangeOffset = Long.parseLong(attributes.getAttributeValue("offset"));
+ }
+ catch(NumberFormatException e) {
+ rangeOffset = null;
+ }
+ } else {
+ rangeOffset = null;
+ }
+ }
+
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ NotNull.exceptIfNull(element, "element");
+ --level;
+ if (level == 1) {
+ if (element.equals("date")) {
+ getPayloadInternal().setDate(DateTime.stringToDate(charData));
+ }
+ else if (element.equals("desc")) {
+ getPayloadInternal().setDescription(charData);
+ }
+ else if (element.equals("media-type")) {
+ getPayloadInternal().setMediaType(charData);
+ }
+ else if (element.equals("name")) {
+ getPayloadInternal().setName(charData);
+ }
+ else if (element.equals("size")) {
+ getPayloadInternal().setSize(Long.parseLong(charData));
+ }
+ else if (element.equals("range")) {
+ getPayloadInternal().setSupportsRangeRequests(true);
+ if (rangeOffset != null) {
+ getPayloadInternal().setRangeOffset(rangeOffset.longValue());
+ } else {
+ getPayloadInternal().setRangeOffset(0L);
+ }
+ }
+ else if (element.equals("hash")) {
+ getPayloadInternal().addHash(new HashElement(hashAlg, Base64.decode(charData)));
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ charData += data;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParser.java
new file mode 100644
index 0000000..89d6817
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParser.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 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.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferHashParser extends GenericPayloadParser<JingleFileTransferHash> {
+
+ private int level = 0;
+ private PayloadParser currentPayloadParser;
+
+ public JingleFileTransferHashParser() {
+ super(new JingleFileTransferHash());
+ this.level = 0;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ if (level == 1 && element.equals("file")) {
+ currentPayloadParser = new JingleFileTransferFileInfoParser();
+ }
+
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleStartElement(element, ns, attributes);
+ }
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ JingleFileTransferFileInfo info = (JingleFileTransferFileInfo)(currentPayloadParser.getPayload());
+ if (info != null) {
+ getPayloadInternal().setFileInfo(info);
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParser.java
new file mode 100644
index 0000000..1883903
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParser.java
@@ -0,0 +1,63 @@
+/*
+ * 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.base.NotNull;
+
+public class JingleIBBTransportMethodPayloadParser extends GenericPayloadParser<JingleIBBTransportPayload> {
+
+ private int level = 0;
+
+ public JingleIBBTransportMethodPayloadParser() {
+ super(new JingleIBBTransportPayload());
+ this.level = 0;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ try {
+ String blockSize = attributes.getAttributeValue("block-size");
+ if (blockSize != null) {
+ getPayloadInternal().setBlockSize(Integer.parseInt(blockSize));
+ }
+ }
+ catch (NumberFormatException e) {
+
+ }
+ if(attributes.getAttributeValue("sid") != null) {
+ getPayloadInternal().setSessionID(attributes.getAttributeValue("sid"));
+ } else {
+ getPayloadInternal().setSessionID("");
+ }
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleParser.java
new file mode 100644
index 0000000..1778b02
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleParser.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.jid.JID;
+
+public class JingleParser extends GenericPayloadParser<JinglePayload> {
+
+ private PayloadParserFactoryCollection factories;
+ private int level = 0;
+ private PayloadParser currentPayloadParser;
+
+ public JingleParser(PayloadParserFactoryCollection factories) {
+ super(new JinglePayload());
+ this.factories = factories;
+ this.level = 0;
+ }
+
+ private JinglePayload.Action stringToAction(String str) {
+ if (str.equals("content-accept")) {
+ return JinglePayload.Action.ContentAccept;
+ } else if (str.equals("content-add")) {
+ return JinglePayload.Action.ContentAdd;
+ } else if (str.equals("content-modify")) {
+ return JinglePayload.Action.ContentModify;
+ } else if (str.equals("content-reject")) {
+ return JinglePayload.Action.ContentReject;
+ } else if (str.equals("content-remove")) {
+ return JinglePayload.Action.ContentRemove;
+ } else if (str.equals("description-info")) {
+ return JinglePayload.Action.DescriptionInfo;
+ } else if (str.equals("security-info")) {
+ return JinglePayload.Action.SecurityInfo;
+ } else if (str.equals("session-accept")) {
+ return JinglePayload.Action.SessionAccept;
+ } else if (str.equals("session-info")) {
+ return JinglePayload.Action.SessionInfo;
+ } else if (str.equals("session-initiate")) {
+ return JinglePayload.Action.SessionInitiate;
+ } else if (str.equals("session-terminate")) {
+ return JinglePayload.Action.SessionTerminate;
+ } else if (str.equals("transport-accept")) {
+ return JinglePayload.Action.TransportAccept;
+ } else if (str.equals("transport-info")) {
+ return JinglePayload.Action.TransportInfo;
+ } else if (str.equals("transport-reject")) {
+ return JinglePayload.Action.TransportReject;
+ } else if (str.equals("transport-replace")) {
+ return JinglePayload.Action.TransportReplace;
+ } else {
+ return JinglePayload.Action.UnknownAction;
+ }
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(attributes, "attributes");
+ if (level == 0) {
+ // <jingle > tag
+ JinglePayload payload = getPayloadInternal();
+ if (attributes.getAttributeValue("action") != null) {
+ payload.setAction(stringToAction(attributes.getAttributeValue("action")));
+ } else {
+ payload.setAction(stringToAction(""));
+ }
+
+ if(attributes.getAttributeValue("initiator") != null) {
+ payload.setInitiator(new JID(attributes.getAttributeValue("initiator")));
+ } else {
+ payload.setInitiator(new JID(""));
+ }
+
+ if(attributes.getAttributeValue("responder") != null) {
+ payload.setResponder(new JID(attributes.getAttributeValue("responder")));
+ } else {
+ payload.setResponder(new JID(""));
+ }
+
+ if (attributes.getAttributeValue("sid") != null) {
+ payload.setSessionID(attributes.getAttributeValue("sid"));
+ } else {
+ payload.setSessionID("");
+ }
+ }
+
+ if (level == 1) {
+ PayloadParserFactory payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes);
+ if (payloadParserFactory != null) {
+ currentPayloadParser = payloadParserFactory.createPayloadParser();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleStartElement(element, ns, attributes);
+ }
+
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ if (currentPayloadParser != null) {
+ if (level >= 1) {
+ currentPayloadParser.handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if(currentPayloadParser.getPayload() instanceof JinglePayload.Reason) {
+ JinglePayload.Reason reason = (JinglePayload.Reason)(currentPayloadParser.getPayload());
+ if (reason != null) {
+ getPayloadInternal().setReason(reason);
+ }
+ }
+
+ if(currentPayloadParser.getPayload() instanceof JingleContentPayload) {
+ JingleContentPayload payload = (JingleContentPayload)(currentPayloadParser.getPayload());
+ if (payload != null) {
+ getPayloadInternal().addContent(payload);
+ }
+ }
+
+ if(currentPayloadParser.getPayload() instanceof JingleFileTransferHash) {
+ JingleFileTransferHash hash = (JingleFileTransferHash)(currentPayloadParser.getPayload());
+ if (hash != null) {
+ getPayloadInternal().addPayload(hash);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ if (level > 1 && currentPayloadParser != null) {
+ currentPayloadParser.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleParserFactory.java b/src/com/isode/stroke/parser/payloadparsers/JingleParserFactory.java
new file mode 100644
index 0000000..3a6c2e9
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleParserFactory.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParserFactory;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.payloadparsers.JingleParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.base.NotNull;
+
+public class JingleParserFactory implements PayloadParserFactory {
+
+ private PayloadParserFactoryCollection factories;
+
+ /**
+ * JingleParserFactory();
+ */
+ public JingleParserFactory(PayloadParserFactoryCollection factories) {
+ this.factories = factories;
+ }
+
+ /**
+ * @param attributes.
+ * @param element, Not Null.
+ * @param attributes, Not NUll.
+ */
+ public boolean canParse(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(ns, "ns");
+ return element.equals("jingle") && ns.equals("urn:xmpp:jingle:1");
+ }
+
+ /**
+ * @return PayloadParser()
+ */
+ public PayloadParser createPayloadParser() {
+ return new JingleParser(factories);
+ }
+}
+
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleReasonParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleReasonParser.java
new file mode 100644
index 0000000..5651c64
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleReasonParser.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.jid.JID;
+
+public class JingleReasonParser extends GenericPayloadParser<JinglePayload.Reason> {
+
+ private int level;
+ private boolean parseText;
+ private String text = "";
+
+ public JingleReasonParser() {
+ super(new JinglePayload.Reason());
+ this.level = 0;
+ this.parseText = false;
+ }
+
+ private JinglePayload.Reason.Type stringToReasonType(String type) {
+ if (type.equals("alternative-session")) {
+ return JinglePayload.Reason.Type.AlternativeSession;
+ } else if (type.equals("busy")) {
+ return JinglePayload.Reason.Type.Busy;
+ } else if (type.equals("cancel")) {
+ return JinglePayload.Reason.Type.Cancel;
+ } else if (type.equals("connectivity-error")) {
+ return JinglePayload.Reason.Type.ConnectivityError;
+ } else if (type.equals("decline")) {
+ return JinglePayload.Reason.Type.Decline;
+ } else if (type.equals("expired")) {
+ return JinglePayload.Reason.Type.Expired;
+ } else if (type.equals("failed-application")) {
+ return JinglePayload.Reason.Type.FailedApplication;
+ } else if (type.equals("failed-transport")) {
+ return JinglePayload.Reason.Type.FailedTransport;
+ } else if (type.equals("general-error")) {
+ return JinglePayload.Reason.Type.GeneralError;
+ } else if (type.equals("gone")) {
+ return JinglePayload.Reason.Type.Gone;
+ } else if (type.equals("incompatible-parameters")) {
+ return JinglePayload.Reason.Type.IncompatibleParameters;
+ } else if (type.equals("media-error")) {
+ return JinglePayload.Reason.Type.MediaError;
+ } else if (type.equals("security-error")) {
+ return JinglePayload.Reason.Type.SecurityError;
+ } else if (type.equals("success")) {
+ return JinglePayload.Reason.Type.Success;
+ } else if (type.equals("timeout")) {
+ return JinglePayload.Reason.Type.Timeout;
+ } else if (type.equals("unsupported-applications")) {
+ return JinglePayload.Reason.Type.UnsupportedApplications;
+ } else if (type.equals("unsupported-transports")) {
+ return JinglePayload.Reason.Type.UnsupportedTransports;
+ } else {
+ return JinglePayload.Reason.Type.UnknownType;
+ }
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ if (level == 1) {
+ if (element.equals("text")) {
+ parseText = true;
+ } else {
+ // reason type
+ getPayloadInternal().type = stringToReasonType(element);
+ }
+ }
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ if (element.equals("text")) {
+ parseText = false;
+ getPayloadInternal().text = text;
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ if (parseText) {
+ text += data;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParser.java b/src/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParser.java
new file mode 100644
index 0000000..d4a1ae4
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParser.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+* Copyright (c) 2014-2015 Isode Limited.
+* All rights reserved.v3.
+* 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.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.network.HostAddressPort;
+import com.isode.stroke.network.HostAddress;
+import java.util.logging.Logger;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleS5BTransportMethodPayloadParser extends GenericPayloadParser<JingleS5BTransportPayload> {
+
+ private int level = 0;
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
+
+ public JingleS5BTransportMethodPayloadParser() {
+ super(new JingleS5BTransportPayload());
+ this.level = 0;
+ }
+
+ private JingleS5BTransportPayload.Candidate.Type stringToType(String str) {
+ if (str.equals("direct")) {
+ return JingleS5BTransportPayload.Candidate.Type.DirectType;
+ } else if (str.equals("assisted")) {
+ return JingleS5BTransportPayload.Candidate.Type.AssistedType;
+ } else if (str.equals("tunnel")) {
+ return JingleS5BTransportPayload.Candidate.Type.TunnelType;
+ } else if (str.equals("proxy")) {
+ return JingleS5BTransportPayload.Candidate.Type.ProxyType;
+ } else {
+ logger_.warning("Unknown candidate type; falling back to default!");
+ return JingleS5BTransportPayload.Candidate.Type.DirectType;
+ }
+ }
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+
+ if (level == 0) {
+ if(attributes.getAttributeValue("sid") != null) {
+ getPayloadInternal().setSessionID(attributes.getAttributeValue("sid"));
+ } else {
+ getPayloadInternal().setSessionID("");
+ }
+
+ String mode = "";
+ if(attributes.getAttributeValue("mode") != null) {
+ mode = attributes.getAttributeValue("mode");
+ } else {
+ mode = "tcp";
+ }
+
+ if (mode.equals("tcp")) {
+ getPayloadInternal().setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ } else if(mode.equals("udp")) {
+ getPayloadInternal().setMode(JingleS5BTransportPayload.Mode.UDPMode);
+ } else {
+ logger_.warning("Unknown S5B mode; falling back to default!");
+ getPayloadInternal().setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ }
+
+ if(attributes.getAttributeValue("dstaddr") != null) {
+ getPayloadInternal().setDstAddr(attributes.getAttributeValue("dstaddr"));
+ } else {
+ getPayloadInternal().setDstAddr("");
+ }
+
+ } else if (level == 1) {
+ if (element.equals("candidate")) {
+ JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate();
+ candidate.cid = "";
+ if(attributes.getAttributeValue("cid") != null) {
+ candidate.cid = attributes.getAttributeValue("cid");
+ }
+
+ int port = -1;
+ try {
+ if(attributes.getAttributeValue("port") != null) {
+ port = Integer.parseInt(attributes.getAttributeValue("port"));
+ }
+ } catch (NumberFormatException e) {
+
+ }
+
+ try {
+ candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("")), port);
+ if(attributes.getAttributeValue("host") != null) {
+ candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName(attributes.getAttributeValue("host"))), port);
+ }
+ } catch (UnknownHostException e) {
+
+ }
+
+ candidate.jid = new JID("");
+ if(attributes.getAttributeValue("jid") != null) {
+ candidate.jid = new JID(attributes.getAttributeValue("jid"));
+ }
+
+ int priority = -1;
+ try {
+ if(attributes.getAttributeValue("priority") != null) {
+ priority = Integer.parseInt(attributes.getAttributeValue("priority"));
+ }
+ } catch (NumberFormatException e) {
+
+ }
+ candidate.priority = priority;
+
+ candidate.type = stringToType("direct");
+ if(attributes.getAttributeValue("type") != null) {
+ candidate.type = stringToType(attributes.getAttributeValue("type"));
+ }
+ getPayloadInternal().addCandidate(candidate);
+
+ } else if (element.equals("candidate-used")) {
+ if(attributes.getAttributeValue("cid") != null) {
+ getPayloadInternal().setCandidateUsed(attributes.getAttributeValue("cid"));
+ } else {
+ getPayloadInternal().setCandidateUsed("");
+ }
+ } else if (element.equals("candidate-error")) {
+ getPayloadInternal().setCandidateError(true);
+ } else if (element.equals("activated")) {
+ if(attributes.getAttributeValue("cid") != null) {
+ getPayloadInternal().setActivated(attributes.getAttributeValue("cid"));
+ } else {
+ getPayloadInternal().setActivated("");
+ }
+ } else if (element.equals("proxy-error")) {
+ getPayloadInternal().setProxyError(true);
+ }
+ }
+
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
index d8f90c3..8c1f14b 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -24,6 +24,12 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new ErrorSerializer());
addSerializer(new InBandRegistrationPayloadSerializer());
addSerializer(new IBBSerializer());
+ addSerializer(new JingleIBBTransportPayloadSerializer());
+ addSerializer(new JingleS5BTransportPayloadSerializer());
+ addSerializer(new JingleFileTransferFileInfoSerializer());
+ addSerializer(new JingleFileTransferDescriptionSerializer());
+ addSerializer(new JingleFileTransferHashSerializer());
+ addSerializer(new JingleContentPayloadSerializer());
addSerializer(new RosterSerializer());
addSerializer(new MUCPayloadSerializer());
addSerializer(new MUCDestroyPayloadSerializer());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializer.java
new file mode 100644
index 0000000..b295807
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializer.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 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.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLNode;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleTransportPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleDescription;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferDescriptionSerializer;
+import com.isode.stroke.serializer.payloadserializers.JingleIBBTransportPayloadSerializer;
+import com.isode.stroke.serializer.payloadserializers.JingleS5BTransportPayloadSerializer;
+import java.util.logging.Logger;
+
+public class JingleContentPayloadSerializer extends GenericPayloadSerializer<JingleContentPayload> {
+
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
+
+ public JingleContentPayloadSerializer() {
+ super(JingleContentPayload.class);
+ }
+
+ private String creatorToString(JingleContentPayload.Creator creator) {
+ switch(creator) {
+ case InitiatorCreator:
+ return "initiator";
+ case ResponderCreator:
+ return "responder";
+ case UnknownCreator:
+ logger_.warning("Serializing unknown creator value.");
+ return "ERROR ERROR ERROR";
+ }
+ assert(false);
+ return "";
+ }
+
+ public String serializePayload(JingleContentPayload payload) {
+
+ XMLElement payloadXML = new XMLElement("content");
+ payloadXML.setAttribute("creator", creatorToString(payload.getCreator()));
+ payloadXML.setAttribute("name", payload.getName());
+
+ if (!payload.getDescriptions().isEmpty()) {
+ // JingleFileTransferDescription
+ JingleFileTransferDescriptionSerializer ftSerializer = new JingleFileTransferDescriptionSerializer();
+ JingleFileTransferDescription filetransfer;
+
+ for(JingleDescription desc : payload.getDescriptions()) {
+ if(desc instanceof JingleFileTransferDescription) {
+ filetransfer = (JingleFileTransferDescription)(desc);
+ payloadXML.addNode(new XMLRawTextNode(ftSerializer.serializePayload(filetransfer)));
+ }
+ }
+ }
+
+ if (!payload.getTransports().isEmpty()) {
+ // JingleIBBTransportPayload
+ JingleIBBTransportPayloadSerializer ibbSerializer = new JingleIBBTransportPayloadSerializer();
+ JingleIBBTransportPayload ibb;
+
+ // JingleS5BTransportPayload
+ JingleS5BTransportPayloadSerializer s5bSerializer = new JingleS5BTransportPayloadSerializer();
+ JingleS5BTransportPayload s5b;
+
+ for(JingleTransportPayload transport: payload.getTransports()) {
+ if(transport instanceof JingleIBBTransportPayload) {
+ ibb = (JingleIBBTransportPayload)(transport);
+ payloadXML.addNode(new XMLRawTextNode(ibbSerializer.serializePayload(ibb)));
+ } else if (transport instanceof JingleS5BTransportPayload) {
+ s5b = (JingleS5BTransportPayload)(transport);
+ payloadXML.addNode(new XMLRawTextNode(s5bSerializer.serializePayload(s5b)));
+ }
+ }
+ }
+ return payloadXML.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializer.java
new file mode 100644
index 0000000..5bc14b8
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializer.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadserializers;
+
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferFileInfoSerializer;
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferDescriptionSerializer extends GenericPayloadSerializer<JingleFileTransferDescription> {
+
+ public JingleFileTransferDescriptionSerializer() {
+ super(JingleFileTransferDescription.class);
+ }
+
+ public String serializePayload(JingleFileTransferDescription payload) {
+ XMLElement description = new XMLElement("description", "urn:xmpp:jingle:apps:file-transfer:4");
+
+ JingleFileTransferFileInfoSerializer fileInfoSerializer = new JingleFileTransferFileInfoSerializer();
+ XMLRawTextNode fileInfoXML = new XMLRawTextNode(fileInfoSerializer.serialize((JingleFileTransferFileInfo)(payload.getFileInfo())));
+ description.addNode(fileInfoXML);
+ return description.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializer.java
new file mode 100644
index 0000000..a9ae722
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializer.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 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.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.stringcodecs.Base64;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Date;
+
+public class JingleFileTransferFileInfoSerializer extends GenericPayloadSerializer<JingleFileTransferFileInfo> {
+
+ public JingleFileTransferFileInfoSerializer() {
+ super(JingleFileTransferFileInfo.class);
+ }
+
+ public String serializePayload(JingleFileTransferFileInfo fileInfo) {
+ XMLElement fileElement = new XMLElement("file", "");
+
+ if (fileInfo.getDate().getTime() != 0L) {
+ fileElement.addNode(new XMLElement("date", "", DateTime.dateToString(fileInfo.getDate())));
+ }
+
+ if (fileInfo.getDescription().length() != 0) {
+ fileElement.addNode(new XMLElement("desc", "", fileInfo.getDescription()));
+ }
+
+ if (fileInfo.getMediaType().length() != 0) {
+ fileElement.addNode(new XMLElement("media-type", "", fileInfo.getMediaType()));
+ }
+
+ if (fileInfo.getName().length() != 0) {
+ fileElement.addNode(new XMLElement("name", "", fileInfo.getName()));
+ }
+
+ if (fileInfo.getSupportsRangeRequests()) {
+ XMLElement range = new XMLElement("range");
+ if (fileInfo.getRangeOffset() != 0) {
+ range.setAttribute("offset", Long.toString(fileInfo.getRangeOffset()));
+ }
+ fileElement.addNode(range);
+ }
+
+ if (fileInfo.getSize() > 0) {
+ fileElement.addNode(new XMLElement("size", "", Long.toString(fileInfo.getSize())));
+ }
+
+ for (Map.Entry<String, ByteArray> entry : fileInfo.getHashes().entrySet()) {
+ XMLElement hash = new XMLElement("hash", "urn:xmpp:hashes:1", Base64.encode(entry.getValue()));
+ hash.setAttribute("algo", entry.getKey());
+ fileElement.addNode(hash);
+ }
+
+ return fileElement.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializer.java
new file mode 100644
index 0000000..73a3fd6
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializer.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadserializers;
+
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferFileInfoSerializer;
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.base.NotNull;
+
+public class JingleFileTransferHashSerializer extends GenericPayloadSerializer<JingleFileTransferHash> {
+
+ public JingleFileTransferHashSerializer() {
+ super(JingleFileTransferHash.class);
+ }
+
+ public String serializePayload(JingleFileTransferHash payload) {
+ // code for version urn:xmpp:jingle:apps:file-transfer:2
+ //XMLElement hash("hash", "urn:xmpp:jingle:apps:file-transfer:info:2", payload->getHash());
+
+ // code for version urn:xmpp:jingle:apps:file-transfer:4
+ XMLElement checksum = new XMLElement("checksum", "urn:xmpp:jingle:apps:file-transfer:4");
+
+ JingleFileTransferFileInfoSerializer fileSerializer = new JingleFileTransferFileInfoSerializer();
+
+ XMLRawTextNode file = new XMLRawTextNode(fileSerializer.serialize((JingleFileTransferFileInfo)(payload.getFileInfo())));
+
+ checksum.addNode(file);
+
+ return checksum.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializer.java
new file mode 100644
index 0000000..3633ba9
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializer.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt 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.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.base.NotNull;
+
+public class JingleIBBTransportPayloadSerializer extends GenericPayloadSerializer<JingleIBBTransportPayload> {
+
+ public JingleIBBTransportPayloadSerializer() {
+ super(JingleIBBTransportPayload.class);
+ }
+
+ public String serializePayload(JingleIBBTransportPayload payload) {
+ XMLElement payloadXML = new XMLElement("transport", "urn:xmpp:jingle:transports:ibb:1");
+ if (payload.getBlockSize() > 0) {
+ payloadXML.setAttribute("block-size", Integer.toString(payload.getBlockSize()));
+ }
+ payloadXML.setAttribute("sid", payload.getSessionID());
+
+ return payloadXML.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JinglePayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JinglePayloadSerializer.java
new file mode 100644
index 0000000..a529f5b
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JinglePayloadSerializer.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadserializers;
+
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferHashSerializer;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.PayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.base.NotNull;
+import java.util.Vector;
+import java.util.logging.Logger;
+
+public class JinglePayloadSerializer extends GenericPayloadSerializer<JinglePayload> {
+
+ private PayloadSerializerCollection serializers;
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
+
+ public JinglePayloadSerializer(PayloadSerializerCollection serializers) {
+ super(JinglePayload.class);
+ this.serializers = serializers;
+ }
+
+ private String actionToString(JinglePayload.Action action) {
+ switch(action) {
+ case ContentAccept:
+ return "content-accept";
+ case ContentAdd:
+ return "content-add";
+ case ContentModify:
+ return "content-modify";
+ case ContentReject:
+ return "content-reject";
+ case ContentRemove:
+ return "content-remove";
+ case DescriptionInfo:
+ return "description-info";
+ case SecurityInfo:
+ return "security-info";
+ case SessionAccept:
+ return "session-accept";
+ case SessionInfo:
+ return "session-info";
+ case SessionInitiate:
+ return "session-initiate";
+ case SessionTerminate:
+ return "session-terminate";
+ case TransportAccept:
+ return "transport-accept";
+ case TransportInfo:
+ return "transport-info";
+ case TransportReject:
+ return "transport-reject";
+ case TransportReplace:
+ return "transport-replace";
+ case UnknownAction:
+ logger_.warning("Serializing unknown action value.\n");
+ return "";
+ }
+ assert(false);
+ return "";
+ }
+
+ private String reasonTypeToString(JinglePayload.Reason.Type type) {
+ switch(type) {
+ case UnknownType:
+ logger_.warning("Unknown jingle reason type!\n");
+ return "";
+ case AlternativeSession:
+ return "alternative-session";
+ case Busy:
+ return "busy";
+ case Cancel:
+ return "cancel";
+ case ConnectivityError:
+ return "connectivity-error";
+ case Decline:
+ return "decline";
+ case Expired:
+ return "expired";
+ case FailedApplication:
+ return "failed-application";
+ case FailedTransport:
+ return "failed-transport";
+ case GeneralError:
+ return "general-error";
+ case Gone:
+ return "gone";
+ case IncompatibleParameters:
+ return "incompatible-parameters";
+ case MediaError:
+ return "media-error";
+ case SecurityError:
+ return "security-error";
+ case Success:
+ return "success";
+ case Timeout:
+ return "timeout";
+ case UnsupportedApplications:
+ return "unsupported-applications";
+ case UnsupportedTransports:
+ return "unsupported-transports";
+ }
+ assert(false);
+ return "";
+ }
+
+ public String serializePayload(JinglePayload payload) {
+ XMLElement jinglePayload = new XMLElement("jingle", "urn:xmpp:jingle:1");
+ jinglePayload.setAttribute("action", actionToString(payload.getAction()));
+ jinglePayload.setAttribute("initiator", payload.getInitiator().toString());
+ jinglePayload.setAttribute("sid", payload.getSessionID());
+
+ Vector<Payload> payloads = payload.getPayloads();
+ if (!payloads.isEmpty()) {
+ for(Payload subPayload : payloads) {
+ PayloadSerializer serializer = serializers.getPayloadSerializer(subPayload);
+ if (serializer != null) {
+ jinglePayload.addNode(new XMLRawTextNode(serializer.serialize(subPayload)));
+ }
+ }
+ }
+
+ if (payload.getReason() != null) {
+ XMLElement reason = new XMLElement("reason");
+ reason.addNode(new XMLElement(reasonTypeToString(payload.getReason().type)));
+ if (payload.getReason().text.length() != 0) {
+ reason.addNode(new XMLElement("desc", "", payload.getReason().text));
+ }
+ jinglePayload.addNode(reason);
+ }
+
+ return jinglePayload.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializer.java
new file mode 100644
index 0000000..f6cc205
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializer.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLNode;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+
+public class JingleS5BTransportPayloadSerializer extends GenericPayloadSerializer<JingleS5BTransportPayload> {
+
+ public JingleS5BTransportPayloadSerializer() {
+ super(JingleS5BTransportPayload.class);
+ }
+
+ private String modeToString(JingleS5BTransportPayload.Mode mode) {
+ switch(mode) {
+ case TCPMode:
+ return "tcp";
+ case UDPMode:
+ return "udp";
+ }
+ assert(false);
+ return "";
+ }
+
+ private String typeToString(JingleS5BTransportPayload.Candidate.Type type) {
+ switch(type) {
+ case AssistedType:
+ return "assisted";
+ case DirectType:
+ return "direct";
+ case ProxyType:
+ return "proxy";
+ case TunnelType:
+ return "tunnel";
+ }
+ assert(false);
+ return "";
+ }
+
+ public String serializePayload(JingleS5BTransportPayload payload) {
+
+ XMLElement payloadXML = new XMLElement("transport", "urn:xmpp:jingle:transports:s5b:1");
+ payloadXML.setAttribute("sid", payload.getSessionID());
+ payloadXML.setAttribute("mode", modeToString(payload.getMode()));
+ if (payload.getDstAddr().length() != 0) {
+ payloadXML.setAttribute("dstaddr", payload.getDstAddr());
+ }
+
+ for(JingleS5BTransportPayload.Candidate candidate : payload.getCandidates()) {
+ XMLElement candidateXML = new XMLElement("candidate");
+ candidateXML.setAttribute("cid", candidate.cid);
+ candidateXML.setAttribute("host", candidate.hostPort.getAddress().toString());
+ candidateXML.setAttribute("jid", candidate.jid.toString());
+ candidateXML.setAttribute("port", Integer.toString(candidate.hostPort.getPort()));
+ candidateXML.setAttribute("priority", Integer.toString(candidate.priority));
+ candidateXML.setAttribute("type", typeToString(candidate.type));
+ payloadXML.addNode(candidateXML);
+ }
+
+ if (payload.hasCandidateError()) {
+ payloadXML.addNode(new XMLElement("candidate-error"));
+ }
+ if (payload.hasProxyError()) {
+ payloadXML.addNode(new XMLElement("proxy-error"));
+ }
+
+ if (payload.getActivated().length() != 0) {
+ XMLElement activatedXML = new XMLElement("activated");
+ activatedXML.setAttribute("cid", payload.getActivated());
+ payloadXML.addNode(activatedXML);
+ }
+ if (payload.getCandidateUsed().length() != 0) {
+ XMLElement candusedXML = new XMLElement("candidate-used");
+ candusedXML.setAttribute("cid", payload.getCandidateUsed());
+ payloadXML.addNode(candusedXML);
+ }
+
+ return payloadXML.serialize();
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java
new file mode 100644
index 0000000..3498287
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.jid.JID;
+import java.util.Date;
+import java.util.TimeZone;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class JingleContentPayloadParserTest {
+
+ public JingleContentPayloadParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<content xmlns=\"urn:xmpp:jingle:1\" creator=\"initiator\" name=\"Erin\"><description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" +
+ "<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>" +
+ "</description><transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" +
+ "<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/><proxy-error/>" +
+ "<activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport></content>"));
+
+ JingleContentPayload content = (JingleContentPayload)parser.getPayload();
+
+ assertEquals (JingleContentPayload.Creator.InitiatorCreator, content.getCreator());
+ assertEquals ("Erin", content.getName());
+
+
+ assertEquals(1, content.getDescriptions().size());
+ JingleFileTransferDescription description = content.getDescription(new JingleFileTransferDescription());
+ assertNotNull(description);
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+
+ assertEquals(2, content.getTransports().size());
+ JingleIBBTransportPayload jingleIBBTransportPayload = content.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(jingleIBBTransportPayload);
+ assertEquals(Integer.valueOf(4), jingleIBBTransportPayload.getBlockSize());
+ assertEquals("546-45", jingleIBBTransportPayload.getSessionID());
+
+ JingleS5BTransportPayload jingleS5BTransportPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(jingleS5BTransportPayload);
+ assertEquals (JingleS5BTransportPayload.Mode.TCPMode, jingleS5BTransportPayload.getMode());
+ assertEquals ("Candidate", jingleS5BTransportPayload.getCandidateUsed());
+ assertEquals ("Activity", jingleS5BTransportPayload.getActivated());
+ assertEquals ("UK", jingleS5BTransportPayload.getDstAddr());
+ assertEquals (false, jingleS5BTransportPayload.hasCandidateError());
+ assertEquals (true, jingleS5BTransportPayload.hasProxyError());
+
+ assertEquals(1, jingleS5BTransportPayload.getCandidates().size());
+ JingleS5BTransportPayload.Candidate candidate = jingleS5BTransportPayload.getCandidates().get(0);
+ assertEquals("cid", candidate.cid);
+ assertEquals(new JID("blas@nal.vx"), candidate.jid);
+ assertEquals("/173.194.36.112", candidate.hostPort.getAddress().getInetAddress().toString());
+ assertEquals(4, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java
new file mode 100644
index 0000000..765af5c
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferDescriptionParser;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferDescriptionParserTest {
+
+ public JingleFileTransferDescriptionParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc>" +
+ "<media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>"));
+
+ JingleFileTransferDescription description = (JingleFileTransferDescription)parser.getPayload();
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>"));
+
+
+ JingleFileTransferDescription description = (JingleFileTransferDescription)parser.getPayload();
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java
new file mode 100644
index 0000000..5225a6d
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferFileInfoParserTest {
+
+ public JingleFileTransferFileInfoParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>"));
+
+ JingleFileTransferFileInfo fileInfo = (JingleFileTransferFileInfo)parser.getPayload();
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>"));
+
+ JingleFileTransferFileInfo fileInfo = (JingleFileTransferFileInfo)parser.getPayload();
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java
new file mode 100644
index 0000000..8dc8a6c
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferHashParser;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferHashParserTest {
+
+ public JingleFileTransferHashParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc>" +
+ "<media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>"));
+
+ JingleFileTransferHash hash = (JingleFileTransferHash)parser.getPayload();
+ assertNotNull(hash);
+
+ JingleFileTransferFileInfo fileInfo = hash.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>"));
+
+
+ JingleFileTransferHash hash = (JingleFileTransferHash)parser.getPayload();
+ assertNotNull(hash);
+
+ JingleFileTransferFileInfo fileInfo = hash.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java
new file mode 100644
index 0000000..46d9529
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.parser.payloadparsers.JingleIBBTransportMethodPayloadParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class JingleIBBTransportMethodPayloadParserTest {
+
+ public JingleIBBTransportMethodPayloadParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>"));
+
+ JingleIBBTransportPayload payload = (JingleIBBTransportPayload)parser.getPayload();
+ assertEquals(Integer.valueOf(4), payload.getBlockSize());
+ assertEquals("546-45", payload.getSessionID());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java
new file mode 100644
index 0000000..ec7f044
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java
@@ -0,0 +1,649 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.stringcodecs.Base64;
+import java.util.Vector;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import com.isode.stroke.network.HostAddress;
+import com.isode.stroke.network.HostAddressPort;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleParserTest {
+
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
+
+ public JingleParserTest() {
+
+ }
+
+ @Test
+ public void testParse_Xep0166_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason>\n" +
+ " <success/>\n" +
+ " </reason>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ }
+
+ //http://xmpp.org/extensions/xep-0166.html#example-8
+ @Test
+ public void testParse_Xep0166_Example8() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason>\n" +
+ " <success/>\n" +
+ " <text>Sorry, gotta go!</text>\n" +
+ " </reason>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ assertEquals("Sorry, gotta go!", jingle.getReason().text);
+ }
+
+ // IBB Transport Method Examples
+
+ // http://xmpp.org/extensions/xep-0261.html#example-1
+ @Test
+ public void testParse_Xep0261_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='4096'\n" +
+ " sid='ch3d9s71'/>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+ assertEquals(1, payload.getTransports().size());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(4096), transportPayload.getBlockSize());
+ assertEquals("ch3d9s71", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-1
+ @Test
+ public void testParse_Xep0261_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " responder='juliet@capulet.lit/balcony'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='2048'\n" +
+ " sid='ch3d9s71'/>\n" +
+ " </content>\n" +
+ " </jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals(new JID("juliet@capulet.lit/balcony"), jingle.getResponder());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+ assertEquals(1, payload.getTransports().size());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(2048), transportPayload.getBlockSize());
+ assertEquals("ch3d9s71", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-9
+ @Test
+ public void testParse_Xep0261_Example9() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='transport-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='2048'\n" +
+ " sid='bt8a71h6'/>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.TransportInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(2048), transportPayload.getBlockSize());
+ assertEquals("bt8a71h6", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-13
+ @Test
+ public void testParse_Xep0261_Example13() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason><success/></reason>\n" +
+ " </jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ }
+
+ // Jingle File Transfer Examples
+
+ // http://xmpp.org/extensions/xep-0234.html#example-1
+ @Test
+ public void testParse_Xep0234_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='851ba2'>\n" +
+ "<content creator='initiator' name='a-file-offer'>\n" +
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ "<file>\n" +
+ "<date>1969-07-21T02:56:15Z</date>\n" +
+ "<desc>This is a test. If this were a real file...</desc>\n" +
+ "<media-type>text/plain</media-type>\n" +
+ "<name>test.txt</name>\n" +
+ "<range/>\n" +
+ "<size>1022</size>\n" +
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ "</file>\n" +
+ "</description>\n" +
+ "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ "<candidate cid='hft54dqy'\n" +
+ " host='192.168.4.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5086'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ "<candidate cid='hutr46fe'\n" +
+ " host='24.24.24.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5087'\n" +
+ " priority='8258636'\n" +
+ " type='direct'/>\n" +
+ "</transport>\n" +
+ "</content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("851ba2", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleFileTransferDescription description = contents.get(0).getDescription(new JingleFileTransferDescription());
+
+ assertNotNull(description);
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertEquals("test.txt", fileInfo.getName());
+ assertEquals("sha-1", fileInfo.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(fileInfo.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(1022L, fileInfo.getSize());
+ assertEquals("This is a test. If this were a real file...", fileInfo.getDescription());
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"), fileInfo.getDate());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-3
+ @Test
+ public void testParse_Xep0234_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='851ba2'>\n" +
+ "<content creator='initiator' name='a-file-offer'>\n" +
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ "<file>\n" +
+ "<date>1969-07-21T02:56:15Z</date>\n" +
+ "<desc>This is a test. If this were a real file...</desc>\n" +
+ "<media-type>text/plain</media-type>\n" +
+ "<name>test.txt</name>\n" +
+ "<range/>\n" +
+ "<size>1022</size>\n" +
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ "</file>\n" +
+ "</description>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("851ba2", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleFileTransferDescription description = contents.get(0).getDescription(new JingleFileTransferDescription());
+
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertEquals("test.txt", fileInfo.getName());
+ assertEquals("sha-1", fileInfo.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(fileInfo.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(1022L, fileInfo.getSize());
+ assertEquals("This is a test. If this were a real file...", fileInfo.getDescription());
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"), fileInfo.getDate());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-5
+ @Test
+ public void testParse_Xep0234_Example5() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='transport-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate-used cid='hr65dqyd'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.TransportInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleS5BTransportPayload transport = contents.get(0).getTransport(new JingleS5BTransportPayload());
+ assertNotNull(transport);
+
+ assertEquals("vj3hs98y", transport.getSessionID());
+ assertEquals("hr65dqyd", transport.getCandidateUsed());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-8
+ @Test
+ public void testParse_Xep0234_Example8() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ " <file>\n" +
+ " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ " </file>\n" +
+ " </checksum>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleFileTransferHash hash = jingle.getPayload(new JingleFileTransferHash());
+ assertNotNull(hash);
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(hash.getFileInfo().getHash("sha-1")));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-10
+ @Test
+ public void testParse_Xep0234_Example10() {
+ logger_.setLevel(Level.FINE);
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='uj3b2'>\n" +
+ " <content creator='initiator' name='a-file-request'>\n" +
+ " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ " <file>\n" +
+ " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ " <range offset='270336'/>\n" +
+ " </file>\n" +
+ " </description>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='xig361fj'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("uj3b2", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleFileTransferFileInfo file = content.getDescription(new JingleFileTransferDescription()).getFileInfo();
+ assertEquals("sha-1", file.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(file.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(270336L, file.getRangeOffset());
+ assertEquals(true, file.getSupportsRangeRequests());
+ }
+
+ // http://xmpp.org/extensions/xep-0260.html#example-1
+ @Test
+ public void testParse_Xep0260_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='hft54dqy'\n" +
+ " host='192.168.4.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5086'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hutr46fe'\n" +
+ " host='24.24.24.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5087'\n" +
+ " priority='8258636'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleS5BTransportPayload s5bPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(s5bPayload);
+
+ assertEquals("vj3hs98y", s5bPayload.getSessionID());
+ assertEquals(JingleS5BTransportPayload.Mode.TCPMode, s5bPayload.getMode());
+ assertEquals(false, s5bPayload.hasCandidateError());
+ assertEquals(false, s5bPayload.hasProxyError());
+ assertEquals("", s5bPayload.getActivated());
+ assertEquals("", s5bPayload.getCandidateUsed());
+ assertEquals(2, s5bPayload.getCandidates().size());
+
+ try {
+ JingleS5BTransportPayload.Candidate candidate;
+ candidate = s5bPayload.getCandidates().get(0);
+ assertEquals("hft54dqy", candidate.cid);
+ assertEquals(new JID("romeo@montague.lit/orchard"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("192.168.4.1")), 5086), candidate.hostPort);
+ assertEquals(8257636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(1);
+ assertEquals("hutr46fe", candidate.cid);
+ assertEquals(new JID("romeo@montague.lit/orchard"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("24.24.24.1")), 5087), candidate.hostPort);
+ assertEquals(8258636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+ } catch (UnknownHostException e) {
+
+ }
+ }
+
+ // http://xmpp.org/extensions/xep-0260.html#example-3
+ @Test
+ public void testParse_Xep0260_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleS5BTransportPayload s5bPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(s5bPayload);
+
+ assertEquals("vj3hs98y", s5bPayload.getSessionID());
+ assertEquals(JingleS5BTransportPayload.Mode.TCPMode, s5bPayload.getMode());
+ assertEquals("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba", s5bPayload.getDstAddr());
+ assertEquals(false, s5bPayload.hasCandidateError());
+ assertEquals(false, s5bPayload.hasProxyError());
+ assertEquals("", s5bPayload.getActivated());
+ assertEquals("", s5bPayload.getCandidateUsed());
+ assertEquals(3, s5bPayload.getCandidates().size());
+
+ try {
+ JingleS5BTransportPayload.Candidate candidate;
+ candidate = s5bPayload.getCandidates().get(0);
+ assertEquals("ht567dq", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("192.169.1.10")), 6539), candidate.hostPort);
+ assertEquals(8257636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(1);
+ assertEquals("hr65dqyd", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("134.102.201.180")), 16453), candidate.hostPort);
+ assertEquals(7929856, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(2);
+ assertEquals("grt654q2", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("2001:638:708:30c9:219:d1ff:fea4:a17d")), 6539), candidate.hostPort);
+ assertEquals(8257606, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+ } catch (UnknownHostException e) {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java
new file mode 100644
index 0000000..ac9e03f
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleTransportPayload;
+import com.isode.stroke.parser.payloadparsers.JingleS5BTransportMethodPayloadParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+
+public class JingleS5BTransportMethodPayloadParserTest {
+
+ public JingleS5BTransportMethodPayloadParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/>" +
+ "<proxy-error/><activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport>"));
+
+ JingleS5BTransportPayload payload = (JingleS5BTransportPayload)parser.getPayload();
+ assertEquals (JingleS5BTransportPayload.Mode.TCPMode, payload.getMode());
+ assertEquals ("Candidate", payload.getCandidateUsed());
+ assertEquals ("Activity", payload.getActivated());
+ assertEquals ("UK", payload.getDstAddr());
+ assertEquals (false, payload.hasCandidateError());
+ assertEquals (true, payload.hasProxyError());
+
+ assertEquals(1, payload.getCandidates().size());
+ JingleS5BTransportPayload.Candidate candidate = payload.getCandidates().get(0);
+ assertEquals("cid", candidate.cid);
+ assertEquals(new JID("blas@nal.vx"), candidate.jid);
+ assertEquals("/173.194.36.112", candidate.hostPort.getAddress().getInetAddress().toString());
+ assertEquals(4, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java
new file mode 100644
index 0000000..686ad7e
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java
@@ -0,0 +1,189 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.network.HostAddress;
+import com.isode.stroke.network.HostAddressPort;
+import java.util.Date;
+import java.util.TimeZone;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleContentPayloadSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleContentPayloadSerializerTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testSerialize() {
+ JingleContentPayloadSerializer testling = new JingleContentPayloadSerializer();
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("Erin");
+
+ JingleFileTransferDescription description = new JingleFileTransferDescription();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.setSize(513L);
+ fileInfo.setDate(new Date(1434056150620L));
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(566L);
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ description.setFileInfo(fileInfo);
+ content.addDescription(description);
+
+ JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload();
+ jingleIBBTransportPayload.setBlockSize(4);
+ jingleIBBTransportPayload.setSessionID("546-45");
+ content.addTransport(jingleIBBTransportPayload);
+
+ JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload();
+ jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate();
+ candidate.cid = "cid";
+ candidate.jid = new JID("blas@nal.vx");
+ try {
+ candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112")));
+ } catch (UnknownHostException e) {
+
+ }
+ candidate.priority = 4;
+ candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType;
+ jingleS5BTransportPayload.addCandidate(candidate);
+ jingleS5BTransportPayload.setCandidateUsed("Candidate");
+ jingleS5BTransportPayload.setActivated("Activity");
+ jingleS5BTransportPayload.setDstAddr("UK");
+ jingleS5BTransportPayload.setCandidateError(false);
+ jingleS5BTransportPayload.setProxyError(true);
+ content.addTransport(jingleS5BTransportPayload);
+
+ String expectedResult = "<content creator=\"initiator\" name=\"Erin\"><description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" +
+ "<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>" +
+ "</description><transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" +
+ "<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/><proxy-error/>" +
+ "<activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport></content>";
+ assertEquals(expectedResult, testling.serialize(content));
+ }
+
+ @Test
+ public void testSerialize_MultiplePayloads() {
+ JingleContentPayloadSerializer testling = new JingleContentPayloadSerializer();
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("Erin");
+
+ JingleFileTransferDescription description = new JingleFileTransferDescription();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.setSize(513L);
+ fileInfo.setDate(new Date(1434056150620L));
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(566L);
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ description.setFileInfo(fileInfo);
+ content.addDescription(description);
+
+ JingleFileTransferDescription description2 = new JingleFileTransferDescription();
+ JingleFileTransferFileInfo fileInfo2 = new JingleFileTransferFileInfo();
+ fileInfo2.setName("Newton");
+ fileInfo2.setDescription("It is bad.");
+ fileInfo2.setMediaType("MediaJPG");
+ fileInfo2.setSize(556L);
+ fileInfo2.setSupportsRangeRequests(false);
+ fileInfo2.addHash(new HashElement("SHA-1", new ByteArray()));
+ description2.setFileInfo(fileInfo2);
+ content.addDescription(description2);
+
+ JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload();
+ jingleIBBTransportPayload.setBlockSize(4);
+ jingleIBBTransportPayload.setSessionID("546-45");
+ content.addTransport(jingleIBBTransportPayload);
+
+
+ JingleIBBTransportPayload jingleIBBTransportPayload2 = new JingleIBBTransportPayload();
+ jingleIBBTransportPayload2.setBlockSize(43);
+ jingleIBBTransportPayload2.setSessionID("546-452");
+ content.addTransport(jingleIBBTransportPayload2);
+
+ JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload();
+ jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate();
+ candidate.cid = "cid";
+ candidate.jid = new JID("blas@nal.vx");
+ try {
+ candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112")));
+ } catch (UnknownHostException e) {
+
+ }
+ candidate.priority = 4;
+ candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType;
+ jingleS5BTransportPayload.addCandidate(candidate);
+ jingleS5BTransportPayload.setCandidateUsed("Candidate");
+ jingleS5BTransportPayload.setActivated("Activity");
+ jingleS5BTransportPayload.setDstAddr("UK");
+ jingleS5BTransportPayload.setCandidateError(false);
+ jingleS5BTransportPayload.setProxyError(true);
+ content.addTransport(jingleS5BTransportPayload);
+
+ JingleS5BTransportPayload jingleS5BTransportPayload2 = new JingleS5BTransportPayload();
+ jingleS5BTransportPayload2.setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ JingleS5BTransportPayload.Candidate candidate2 = new JingleS5BTransportPayload.Candidate();
+ candidate2.cid = "cid";
+ candidate2.jid = new JID("blas@nal.vx");
+ try {
+ candidate2.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112")));
+ } catch (UnknownHostException e) {
+
+ }
+ candidate2.priority = 4;
+ candidate2.type = JingleS5BTransportPayload.Candidate.Type.AssistedType;
+ jingleS5BTransportPayload2.addCandidate(candidate2);
+ jingleS5BTransportPayload2.setCandidateUsed("Candy");
+ jingleS5BTransportPayload2.setActivated("Active");
+ jingleS5BTransportPayload2.setDstAddr("USA");
+ jingleS5BTransportPayload2.setCandidateError(true);
+ jingleS5BTransportPayload2.setProxyError(false);
+ content.addTransport(jingleS5BTransportPayload2);
+
+ String expectedResult = "<content creator=\"initiator\" name=\"Erin\"><description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file>" +
+ "<date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type><name>Isaac</name>" +
+ "<range offset=\"566\"/><size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>" +
+ "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is bad.</desc><media-type>MediaJPG</media-type>" +
+ "<name>Newton</name><size>556</size><hash algo=\"SHA-1\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>" +
+ "<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" +
+ "<transport block-size=\"43\" sid=\"546-452\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" +
+ "<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/><proxy-error/>" +
+ "<activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport>" +
+ "<transport dstaddr=\"USA\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/><candidate-error/>" +
+ "<activated cid=\"Active\"/><candidate-used cid=\"Candy\"/></transport></content>";
+ assertEquals(expectedResult, testling.serialize(content));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java
new file mode 100644
index 0000000..720aa65
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferDescriptionSerializer;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class JingleFileTransferDescriptionSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferDescriptionSerializerTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testSerialize_FileInfo_withAllVariables() {
+ JingleFileTransferDescriptionSerializer testling = new JingleFileTransferDescriptionSerializer();
+ JingleFileTransferDescription description = new JingleFileTransferDescription();
+
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.setSize(513L);
+ fileInfo.setDate(new Date(1434056150620L));
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(566L);
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+
+ description.setFileInfo(fileInfo);
+ String expectedResult = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date>" +
+ "<desc>It is good.</desc><media-type>MediaAAC</media-type><name>Isaac</name><range offset=\"566\"/>" +
+ "<size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>";
+ assertEquals(expectedResult, testling.serialize(description));
+ }
+
+ @Test
+ public void testSerialize_FileInfo_withSomeVariables() {
+ JingleFileTransferDescriptionSerializer testling = new JingleFileTransferDescriptionSerializer();
+ JingleFileTransferDescription description = new JingleFileTransferDescription();
+
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ description.setFileInfo(fileInfo);
+ String expectedResult = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>";
+ assertEquals(expectedResult, testling.serialize(description));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java
new file mode 100644
index 0000000..69e5606
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferFileInfoSerializer;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.ByteArray;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class JingleFileTransferFileInfoSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferFileInfoSerializerTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testSerialize_withAllVariables() {
+ JingleFileTransferFileInfoSerializer testling = new JingleFileTransferFileInfoSerializer();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.setSize(513L);
+ fileInfo.setDate(new Date(1434056150620L));
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(566L);
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ String expectedResult = "<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>";
+ assertEquals(expectedResult, testling.serialize(fileInfo));
+ }
+
+ @Test
+ public void testSerialize_withSomeVariables() {
+ JingleFileTransferFileInfoSerializer testling = new JingleFileTransferFileInfoSerializer();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ String expectedResult = "<file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>";
+ assertEquals(expectedResult, testling.serialize(fileInfo));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java
new file mode 100644
index 0000000..96410bf
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferHashSerializer;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.Date;
+
+public class JingleFileTransferHashSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleFileTransferHashSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize_FileInfo_withAllVariables() {
+ JingleFileTransferHashSerializer testling = new JingleFileTransferHashSerializer();
+ JingleFileTransferHash hash = new JingleFileTransferHash();
+
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.setSize(513L);
+ fileInfo.setDate(new Date(1434056150620L));
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(566L);
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+
+ hash.setFileInfo(fileInfo);
+ String expectedResult = "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date>" +
+ "<desc>It is good.</desc><media-type>MediaAAC</media-type><name>Isaac</name><range offset=\"566\"/>" +
+ "<size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>";
+ assertEquals(expectedResult, testling.serialize(hash));
+ }
+
+ @Test
+ public void testSerialize_FileInfo_withSomeVariables() {
+ JingleFileTransferHashSerializer testling = new JingleFileTransferHashSerializer();
+ JingleFileTransferHash hash = new JingleFileTransferHash();
+
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("Isaac");
+ fileInfo.setDescription("It is good.");
+ fileInfo.setMediaType("MediaAAC");
+ fileInfo.addHash(new HashElement("MD5", new ByteArray()));
+ hash.setFileInfo(fileInfo);
+ String expectedResult = "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>";
+ assertEquals(expectedResult, testling.serialize(hash));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java
new file mode 100644
index 0000000..3f1f576
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleIBBTransportPayloadSerializer;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+
+public class JingleIBBTransportPayloadSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleIBBTransportPayloadSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ JingleIBBTransportPayloadSerializer testling = new JingleIBBTransportPayloadSerializer();
+ JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload();
+ jingleIBBTransportPayload.setBlockSize(4);
+ jingleIBBTransportPayload.setSessionID("546-45");
+ String expectedResult = "<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>";
+ assertEquals(expectedResult, testling.serialize(jingleIBBTransportPayload));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java
new file mode 100644
index 0000000..6a76c8c
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleS5BTransportPayloadSerializer;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.network.HostAddressPort;
+import com.isode.stroke.network.HostAddress;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleS5BTransportPayloadSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public JingleS5BTransportPayloadSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ JingleS5BTransportPayloadSerializer testling = new JingleS5BTransportPayloadSerializer();
+ JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload();
+ jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate();
+ candidate.cid = "cid";
+ candidate.jid = new JID("blas@nal.vx");
+ try {
+ candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112")));
+ } catch (UnknownHostException e) {
+
+ }
+ candidate.priority = 4;
+ candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType;
+ jingleS5BTransportPayload.addCandidate(candidate);
+ jingleS5BTransportPayload.setCandidateUsed("Candidate");
+ jingleS5BTransportPayload.setActivated("Activity");
+ jingleS5BTransportPayload.setDstAddr("UK");
+ jingleS5BTransportPayload.setCandidateError(false);
+ jingleS5BTransportPayload.setProxyError(true);
+
+ String expectedResult = "<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/>" +
+ "<proxy-error/><activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport>";
+ assertEquals(expectedResult, testling.serialize(jingleS5BTransportPayload));
+ }
+} \ No newline at end of file