summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/isode')
-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
31 files changed, 2720 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