summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/elements/Bytestreams.java159
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/BytestreamsParser.java69
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java2
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializer.java52
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java2
5 files changed, 282 insertions, 2 deletions
diff --git a/src/com/isode/stroke/elements/Bytestreams.java b/src/com/isode/stroke/elements/Bytestreams.java
new file mode 100644
index 0000000..9c351b5
--- /dev/null
+++ b/src/com/isode/stroke/elements/Bytestreams.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2010 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.jid.JID;
+import com.isode.stroke.elements.Payload;
+import java.util.Vector;
+
+public class Bytestreams extends Payload {
+
+ public class StreamHost {
+
+ public String host;
+ public JID jid;
+ public int port;
+
+ /**
+ * Default Constructor.
+ */
+ public StreamHost() {
+ this("", new JID(), -1);
+ }
+
+ /**
+ * StreamHost with single parameter, host.
+ */
+ public StreamHost(String host) {
+ this(host, new JID(), -1);
+ }
+
+ /**
+ * StreamHost with two parameter, host and jid.
+ */
+ public StreamHost(String host, JID jid) {
+ this(host, jid, -1);
+ }
+
+ /**
+ * StreamHost with three parameter, host, jid and port.
+ */
+ public StreamHost(String host, JID jid, int port) {
+ NotNull.exceptIfNull(host, "host");
+ NotNull.exceptIfNull(jid, "jid");
+ this.host = host;
+ this.jid = jid;
+ this.port = port;
+ }
+
+ /**
+ * @return host, NotNull.
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * @param host, NotNull.
+ */
+ public void setHost(String host) {
+ NotNull.exceptIfNull(host, "host");
+ this.host = host;
+ }
+
+ /**
+ * @return jid, NotNull.
+ */
+ public JID getJID() {
+ return jid;
+ }
+
+ /**
+ * @param jid, NotNull.
+ */
+ public void setJID(JID jid) {
+ NotNull.exceptIfNull(jid, "jid");
+ this.jid = jid;
+ }
+
+ /**
+ * @return port.
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * @param port.
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ }
+
+ private String id = "";
+ JID usedStreamHost;
+ Vector<StreamHost> streamHosts = new Vector<StreamHost>();
+
+ /**
+ * Default Constructor.
+ */
+ public Bytestreams() {
+
+ }
+
+ /**
+ * @return id, notnull.
+ */
+ public String getStreamID() {
+ return id;
+ }
+
+ /**
+ * @param id, notnull.
+ */
+ public void setStreamID(String id) {
+ NotNull.exceptIfNull(id, "id");
+ this.id = id;
+ }
+
+ /**
+ * @return usedStreamHost
+ */
+ public JID getUsedStreamHost() {
+ return usedStreamHost;
+ }
+
+ /**
+ * @param host
+ */
+ public void setUsedStreamHost(JID host) {
+ usedStreamHost = host;
+ }
+
+ /**
+ * @return streamHosts, notnull.
+ */
+ public Vector<StreamHost> getStreamHosts() {
+ return streamHosts;
+ }
+
+ /**
+ * @param streamHost, notnull.
+ */
+ public void addStreamHost(StreamHost streamHost) {
+ NotNull.exceptIfNull(streamHost, "streamHost");
+ streamHosts.add(streamHost);
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/BytestreamsParser.java b/src/com/isode/stroke/parser/payloadparsers/BytestreamsParser.java
new file mode 100644
index 0000000..879a97d
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/BytestreamsParser.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010 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.Bytestreams;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.base.NotNull;
+
+public class BytestreamsParser extends GenericPayloadParser<Bytestreams> {
+
+ private final int TopLevel = 0;
+ private final int PayloadLevel = 1;
+ private int level = TopLevel;
+
+ public BytestreamsParser() {
+ super(new Bytestreams());
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes, notnull.
+ */
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(attributes, "attributes");
+ if (level == TopLevel) {
+ getPayloadInternal().setStreamID(attributes.getAttribute("sid"));
+ }
+ else if (level == PayloadLevel) {
+ if (element.equals("streamhost")) {
+ Bytestreams bytestreams = new Bytestreams();
+ try {
+ getPayloadInternal().addStreamHost(bytestreams.new StreamHost(attributes.getAttribute("host"), new JID(attributes.getAttribute("jid")), Integer.parseInt(attributes.getAttribute("port"))));
+ }
+ catch(NumberFormatException e) {
+
+ }
+ }
+ else if (element.equals("streamhost-used")) {
+ getPayloadInternal().setUsedStreamHost(new JID(attributes.getAttribute("jid")));
+ }
+ }
+ ++level;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ public void handleEndElement(String element, String ns) {
+ --level;
+ }
+
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index 80d5a5b..7c9679b 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -39,7 +39,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
//addFactery(new InBandRegistrationPayloadParserFactory());
addFactory(new SearchPayloadParserFactory());
//addFactory(new StreamInitiationParserFactory());
- //addFactory(new BytestreamsParserFactory());
+ addFactory(new GenericPayloadParserFactory<BytestreamsParser>("query", "http://jabber.org/protocol/bytestreams", BytestreamsParser.class));
addFactory(new GenericPayloadParserFactory<VCardUpdateParser>("x", "vcard-temp:x:update", VCardUpdateParser.class));
addFactory(new GenericPayloadParserFactory<VCardParser>("vCard", "vcard-temp", VCardParser.class));
addFactory(new PrivateStorageParserFactory(this));
diff --git a/src/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializer.java
new file mode 100644
index 0000000..67efc52
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializer.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 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.Bytestreams;
+import com.isode.stroke.base.NotNull;
+
+public class BytestreamsSerializer extends GenericPayloadSerializer<Bytestreams> {
+
+ /**
+ * Constructor.
+ */
+ public BytestreamsSerializer() {
+ super(Bytestreams.class);
+ }
+
+ /**
+ * @param bytestreams, notnull
+ */
+ @Override
+ public String serializePayload(Bytestreams bytestreams) {
+ NotNull.exceptIfNull(bytestreams, "bytestreams");
+ XMLElement queryElement = new XMLElement("query", "http://jabber.org/protocol/bytestreams");
+ queryElement.setAttribute("sid", bytestreams.getStreamID());
+ for(Bytestreams.StreamHost streamHost: bytestreams.getStreamHosts()) {
+ XMLElement streamHostElement = new XMLElement("streamhost");
+ streamHostElement.setAttribute("host", streamHost.host);
+ streamHostElement.setAttribute("jid", streamHost.jid.toString());
+ streamHostElement.setAttribute("port", Integer.toString(streamHost.port));
+ queryElement.addNode(streamHostElement);
+ }
+
+ if (bytestreams.getUsedStreamHost() != null) {
+ XMLElement streamHostElement = new XMLElement("streamhost-used");
+ streamHostElement.setAttribute("jid", bytestreams.getUsedStreamHost().toString());
+ queryElement.addNode(streamHostElement);
+ }
+ return queryElement.serialize();
+ }
+} \ 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 5232d2c..644b7e0 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -40,7 +40,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new SecurityLabelSerializer());
addSerializer(new SecurityLabelsCatalogSerializer());
//addSerializer(new StreamInitiationSerializer());
- //addSerializer(new BytestreamsSerializer());
+ addSerializer(new BytestreamsSerializer());
addSerializer(new VCardSerializer());
addSerializer(new VCardUpdateSerializer());
addSerializer(new RawXMLPayloadSerializer());