summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/isode')
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/S5BProxyRequestParser.java91
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/S5BProxyRequestSerializer.java47
2 files changed, 138 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/S5BProxyRequestParser.java b/src/com/isode/stroke/parser/payloadparsers/S5BProxyRequestParser.java
new file mode 100644
index 0000000..ff56fb5
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/S5BProxyRequestParser.java
@@ -0,0 +1,91 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.elements.S5BProxyRequest;
+import com.isode.stroke.elements.S5BProxyRequest.StreamHost;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.GenericPayloadParser;
+
+/**
+ * S5BProxyRequestParaser
+ */
+public class S5BProxyRequestParser extends
+ GenericPayloadParser<S5BProxyRequest> {
+
+ private boolean parseActivate = false;
+
+ private final StringBuilder activeJIDBuilder = new StringBuilder();
+
+ /**
+ * Constructor
+ */
+ public S5BProxyRequestParser() {
+ super(new S5BProxyRequest());
+ }
+
+ @Override
+ public void handleStartElement(String element, String ns,
+ AttributeMap attributes) {
+ if ("streamhost".equals(element)) {
+ String hostValue = attributes.getAttributeValue("host");
+ String jidValue = attributes.getAttributeValue("jid");
+ String portValue = attributes.getAttributeValue("port");
+ if (hostValue != null && jidValue != null && portValue != null) {
+ int port = -1;
+ try {
+ port = Integer.parseInt(portValue);
+ }
+ catch (NumberFormatException nfe) {
+ port = -1;
+ }
+ JID jid = new JID(jidValue);
+ if (!hostValue.isEmpty() && port != -1 && jid.isValid()) {
+ StreamHost streamHost = new StreamHost();
+ streamHost.host = hostValue;
+ streamHost.port = port;
+ streamHost.jid = jid;
+ getPayloadInternal().setStreamHost(streamHost);
+ }
+ }
+ }
+ else if ("active".equals(element)) {
+ parseActivate = true;
+ }
+ else if ("query".equals(element)) {
+ String sidValue = attributes.getAttributeValue("sid");
+ if (sidValue != null) {
+ getPayloadInternal().setSID(sidValue);
+ };
+ }
+
+ }
+
+ @Override
+ public void handleEndElement(String element, String ns) {
+ if ("activate".equals(element)) {
+ JID active = new JID(activeJIDBuilder.toString());
+ if (active.isValid()) {
+ getPayloadInternal().setActivate(active);
+ }
+ parseActivate = false;
+ }
+
+ }
+
+ @Override
+ public void handleCharacterData(String data) {
+ if (parseActivate) {
+ activeJIDBuilder.append(data);
+ }
+ }
+
+}
diff --git a/src/com/isode/stroke/serializer/payloadserializers/S5BProxyRequestSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/S5BProxyRequestSerializer.java
new file mode 100644
index 0000000..d2e8dae
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/S5BProxyRequestSerializer.java
@@ -0,0 +1,47 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.elements.S5BProxyRequest;
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLElement;
+
+/**
+ *
+ */
+public class S5BProxyRequestSerializer extends
+ GenericPayloadSerializer<S5BProxyRequest> {
+
+ /**
+ * Constructor
+ */
+ public S5BProxyRequestSerializer() {
+ super(S5BProxyRequest.class);
+ }
+
+ @Override
+ protected String serializePayload(S5BProxyRequest s5bProxyRequest) {
+ XMLElement queryElement = new XMLElement("query", "http://jabber.org/protocol/bytestreams");
+ if (s5bProxyRequest != null && s5bProxyRequest.getStreamHost() != null) {
+ XMLElement streamHost = new XMLElement("streamhost");
+ streamHost.setAttribute("host", s5bProxyRequest.getStreamHost().host);
+ streamHost.setAttribute("port", String.valueOf(s5bProxyRequest.getStreamHost().port));
+ streamHost.setAttribute("jid", s5bProxyRequest.getStreamHost().jid.toString());
+ queryElement.addNode(streamHost);
+ }
+ else if (s5bProxyRequest != null && s5bProxyRequest.getActivate() != null) {
+ queryElement.setAttribute("sid", s5bProxyRequest.getSID());
+ XMLElement active = new XMLElement("active","",s5bProxyRequest.getActivate().toString());
+ queryElement.addNode(active);
+ }
+ return queryElement.serialize();
+ }
+
+}