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 /src/com/isode/stroke/elements
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
Diffstat (limited to 'src/com/isode/stroke/elements')
-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
10 files changed, 1066 insertions, 0 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