summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/elements/IBB.java192
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java1
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/IBBParser.java100
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java1
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/IBBSerializer.java58
5 files changed, 352 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/IBB.java b/src/com/isode/stroke/elements/IBB.java
new file mode 100644
index 0000000..93864da
--- /dev/null
+++ b/src/com/isode/stroke/elements/IBB.java
@@ -0,0 +1,192 @@
+/*
+ * 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.elements.Payload;
+import java.util.Vector;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.ByteArray;
+
+public class IBB extends Payload {
+
+ public enum Action {
+ Open,
+ Close,
+ Data
+ };
+
+ public enum StanzaType {
+ IQStanza,
+ MessageStanza
+ };
+
+ private Action action;
+ private String streamID = "";
+ private ByteArray data = new ByteArray();
+ private StanzaType stanzaType;
+ private int blockSize;
+ private int sequenceNumber;
+
+ /**
+ * Default Constructor.
+ */
+ public IBB() {
+ this(Action.Open, "");
+ }
+
+ /**
+ * Parameterized Constructor
+ * @param action, NotNull.
+ */
+ public IBB(Action action) {
+ this(action, "");
+ }
+
+ /**
+ * Parameterized Constructor
+ * @param streamID, NotNull.
+ * @param action, NotNull.
+ */
+ public IBB(Action action, String streamID) {
+ NotNull.exceptIfNull(action, "action");
+ NotNull.exceptIfNull(streamID, "streamID");
+ this.action = action;
+ this.streamID = streamID;
+ this.stanzaType = StanzaType.IQStanza;
+ this.blockSize = -1;
+ this.sequenceNumber = -1;
+ }
+
+ /**
+ * @param streamID, NotNull.
+ * @param blockSize.
+ * @return IBB Object.
+ */
+ public static IBB createIBBOpen(String streamID, int blockSize) {
+ NotNull.exceptIfNull(streamID, "streamID");
+ IBB result = new IBB(Action.Open, streamID);
+ result.setBlockSize(blockSize);
+ return result;
+ }
+
+ /**
+ * @param streamID, NotNull.
+ * @param sequenceNumber.
+ * @param data, NotNull.
+ * @return IBB Object.
+ */
+ public static IBB createIBBData(String streamID, int sequenceNumber, ByteArray data) {
+ NotNull.exceptIfNull(streamID, "streamID");
+ NotNull.exceptIfNull(data, "data");
+ IBB result = new IBB(Action.Data, streamID);
+ result.setSequenceNumber(sequenceNumber);
+ result.setData(data);
+ return result;
+ }
+
+
+ /**
+ * @param streamID, NotNull.
+ * @return IBB Object.
+ */
+ public static IBB createIBBClose(String streamID) {
+ return new IBB(Action.Close, streamID);
+ }
+
+ /**
+ * @param action, Not Null.
+ */
+ public void setAction(Action action) {
+ NotNull.exceptIfNull(action, "action");
+ this.action = action;
+ }
+
+ /**
+ * @return action, Not Null.
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * @param stanzaType, Not Null.
+ */
+ public void setStanzaType(StanzaType stanzaType) {
+ NotNull.exceptIfNull(stanzaType, "stanzaType");
+ this.stanzaType = stanzaType;
+ }
+
+ /**
+ * @return stanzaType, Not Null.
+ */
+ public StanzaType getStanzaType() {
+ return stanzaType;
+ }
+
+ /**
+ * @param id, Not Null.
+ */
+ public void setStreamID(String id) {
+ NotNull.exceptIfNull(id, "id");
+ streamID = id;
+ }
+
+ /**
+ * @return id, Not Null.
+ */
+ public String getStreamID() {
+ return streamID;
+ }
+
+ /**
+ * @return data, Not Null.
+ */
+ public ByteArray getData() {
+ return data;
+ }
+
+ /**
+ * @param data, Not Null.
+ */
+ public void setData(ByteArray data) {
+ NotNull.exceptIfNull(data, "data");
+ this.data = data;
+ }
+
+ /**
+ * @return blockSize.
+ */
+ public int getBlockSize() {
+ return blockSize;
+ }
+
+ /**
+ * @param blockSize.
+ */
+ public void setBlockSize(int blockSize) {
+ this.blockSize = blockSize;
+ }
+
+ /**
+ * @return sequenceNumber.
+ */
+ public int getSequenceNumber() {
+ return sequenceNumber;
+ }
+
+ /**
+ * @param sequenceNumber.
+ */
+ public void setSequenceNumber(int i) {
+ sequenceNumber = i;
+ }
+} \ 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 5bdf421..84a0b43 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -27,6 +27,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new GenericPayloadParserFactory<IsodeIQDelegationParser>("delegate", "http://isode.com/iq_delegation", IsodeIQDelegationParser.class));
addFactory(new GenericPayloadParserFactory<StorageParser>("storage", "storage:bookmarks", StorageParser.class));
addFactory(new RosterParserFactory());
+ addFactory(new GenericPayloadParserFactory<IBBParser>("data", "http://jabber.org/protocol/ibb", IBBParser.class));
addFactory(new GenericPayloadParserFactory<DiscoInfoParser>("query", "http://jabber.org/protocol/disco#info", DiscoInfoParser.class));
addFactory(new GenericPayloadParserFactory<DiscoItemsParser>("query", "http://jabber.org/protocol/disco#items", DiscoItemsParser.class));
addFactory(new GenericPayloadParserFactory<CapsInfoParser> ("c", "http://jabber.org/protocol/caps", CapsInfoParser.class));
diff --git a/src/com/isode/stroke/parser/payloadparsers/IBBParser.java b/src/com/isode/stroke/parser/payloadparsers/IBBParser.java
new file mode 100644
index 0000000..cb405af
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/IBBParser.java
@@ -0,0 +1,100 @@
+/*
+ * 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.IBB;
+import com.isode.stroke.stringcodecs.Base64;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.ByteArray;
+import java.util.Vector;
+
+public class IBBParser extends GenericPayloadParser<IBB> {
+
+ public IBBParser() {
+ super(new IBB());
+ }
+
+ private final int TopLevel = 0;
+ private int level;
+ private String currentText = "";
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(attributes, "attributes");
+ if (level == TopLevel) {
+ if (element.equals("data")) {
+ getPayloadInternal().setAction(IBB.Action.Data);
+ getPayloadInternal().setStreamID(attributes.getAttribute("sid"));
+ try {
+ getPayloadInternal().setSequenceNumber(Integer.parseInt(attributes.getAttribute("seq")));
+ }
+ catch (NumberFormatException e) {
+
+ }
+ }
+ else if (element.equals("open")) {
+ getPayloadInternal().setAction(IBB.Action.Open);
+ getPayloadInternal().setStreamID(attributes.getAttribute("sid"));
+ if (attributes.getAttribute("stanza").equals("message")) {
+ getPayloadInternal().setStanzaType(IBB.StanzaType.MessageStanza);
+ }
+ else {
+ getPayloadInternal().setStanzaType(IBB.StanzaType.IQStanza);
+ }
+ try {
+ getPayloadInternal().setBlockSize(Integer.parseInt(attributes.getAttribute("block-size")));
+ }
+ catch (NumberFormatException e) {
+
+ }
+ }
+ else if (element.equals("close")) {
+ getPayloadInternal().setAction(IBB.Action.Close);
+ getPayloadInternal().setStreamID(attributes.getAttribute("sid"));
+ }
+ }
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ NotNull.exceptIfNull(element, "element");
+ --level;
+ if (level == TopLevel) {
+ if (element.equals("data")) {
+ ByteArray data = new ByteArray(currentText);
+ getPayloadInternal().setData(Base64.decode(data.toString()));
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ currentText += 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 a273fa0..d8f90c3 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -23,6 +23,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
//addSerializer(new PrioritySerializer());
addSerializer(new ErrorSerializer());
addSerializer(new InBandRegistrationPayloadSerializer());
+ addSerializer(new IBBSerializer());
addSerializer(new RosterSerializer());
addSerializer(new MUCPayloadSerializer());
addSerializer(new MUCDestroyPayloadSerializer());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/IBBSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/IBBSerializer.java
new file mode 100644
index 0000000..cb2f88c
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/IBBSerializer.java
@@ -0,0 +1,58 @@
+/*
+ * 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.IBB;
+import com.isode.stroke.stringcodecs.Base64;
+import com.isode.stroke.base.NotNull;
+
+public class IBBSerializer extends GenericPayloadSerializer<IBB> {
+
+ public IBBSerializer() {
+ super(IBB.class);
+ }
+
+ public String serializePayload(IBB ibb) {
+ switch(ibb.getAction()) {
+ case Data: {
+ XMLElement ibbElement = new XMLElement("data", "http://jabber.org/protocol/ibb");
+ ibbElement.setAttribute("sid", ibb.getStreamID());
+ if (ibb.getSequenceNumber() >= 0) {
+ ibbElement.setAttribute("seq", Integer.toString(ibb.getSequenceNumber()));
+ }
+ ibbElement.addNode(new XMLTextNode(Base64.encode(ibb.getData())));
+ return ibbElement.serialize();
+ }
+ case Open: {
+ XMLElement ibbElement = new XMLElement("open", "http://jabber.org/protocol/ibb");
+ ibbElement.setAttribute("sid", ibb.getStreamID());
+ switch (ibb.getStanzaType()) {
+ case IQStanza: ibbElement.setAttribute("stanza", "iq"); break;
+ case MessageStanza: ibbElement.setAttribute("stanza", "message"); break;
+ }
+ assert(ibb.getBlockSize() > 0);
+ ibbElement.setAttribute("block-size", Integer.toString(ibb.getBlockSize()));
+ return ibbElement.serialize();
+ }
+ case Close: {
+ XMLElement ibbElement = new XMLElement("close", "http://jabber.org/protocol/ibb");
+ ibbElement.setAttribute("sid", ibb.getStreamID());
+ return ibbElement.serialize();
+ }
+ }
+ assert(false);
+ return "";
+ }
+} \ No newline at end of file