diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-10 19:22:13 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-11 02:53:10 +0100 |
commit | 08023210ba875f3cd088eca2b4b3df7410966344 (patch) | |
tree | 4cfbbe21353559664ccbc4c5ffb7e33cb8e6ea4a /src/eu/siacs/conversations/xmpp/stanzas | |
parent | e441005c8768091e9e975f3d5f797fab8466861b (diff) |
basic stream managment functionality
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/stanzas')
8 files changed, 191 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java b/src/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java new file mode 100644 index 00000000..204a6bec --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java @@ -0,0 +1,34 @@ +package eu.siacs.conversations.xmpp.stanzas; + +import eu.siacs.conversations.xml.Element; + +public class AbstractStanza extends Element { + + protected AbstractStanza(String name) { + super(name); + } + + public String getTo() { + return getAttribute("to"); + } + + public String getFrom() { + return getAttribute("from"); + } + + public String getId() { + return this.getAttribute("id"); + } + + public void setTo(String to) { + setAttribute("to", to); + } + + public void setFrom(String from) { + setAttribute("from",from); + } + + public void setId(String id) { + setAttribute("id",id); + } +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java new file mode 100644 index 00000000..1675d19d --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java @@ -0,0 +1,35 @@ +package eu.siacs.conversations.xmpp.stanzas; + + +public class IqPacket extends AbstractStanza { + + public static final int TYPE_SET = 0; + public static final int TYPE_RESULT = 1; + public static final int TYPE_GET = 2; + + private IqPacket(String name) { + super(name); + } + + public IqPacket(int type) { + super("iq"); + switch (type) { + case TYPE_SET: + this.setAttribute("type", "set"); + break; + case TYPE_GET: + this.setAttribute("type", "get"); + break; + case TYPE_RESULT: + this.setAttribute("type", "result"); + break; + default: + break; + } + } + + public IqPacket() { + super("iq"); + } + +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java new file mode 100644 index 00000000..f31a78e6 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java @@ -0,0 +1,61 @@ +package eu.siacs.conversations.xmpp.stanzas; + +import eu.siacs.conversations.xml.Element; + +public class MessagePacket extends AbstractStanza { + public static final int TYPE_CHAT = 0; + public static final int TYPE_UNKNOWN = 1; + public static final int TYPE_NO = 2; + public static final int TYPE_GROUPCHAT = 3; + public static final int TYPE_ERROR = 4; + + public MessagePacket() { + super("message"); + } + + public String getBody() { + Element body = this.findChild("body"); + if (body!=null) { + return body.getContent(); + } else { + return null; + } + } + + public void setBody(String text) { + this.children.remove(findChild("body")); + Element body = new Element("body"); + body.setContent(text); + this.children.add(body); + } + + public void setType(int type) { + switch (type) { + case TYPE_CHAT: + this.setAttribute("type","chat"); + break; + case TYPE_GROUPCHAT: + this.setAttribute("type", "groupchat"); + break; + default: + this.setAttribute("type","chat"); + break; + } + } + + public int getType() { + String type = getAttribute("type"); + if (type==null) { + return TYPE_NO; + } + if (type.equals("chat")) { + return TYPE_CHAT; + } else if (type.equals("groupchat")) { + return TYPE_GROUPCHAT; + } else if (type.equals("error")) { + return TYPE_ERROR; + } else { + return TYPE_UNKNOWN; + } + } +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java new file mode 100644 index 00000000..dfbab78c --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java @@ -0,0 +1,9 @@ +package eu.siacs.conversations.xmpp.stanzas; + + +public class PresencePacket extends AbstractStanza { + + public PresencePacket() { + super("presence"); + } +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java new file mode 100644 index 00000000..7bc66e9b --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/AckPacket.java @@ -0,0 +1,13 @@ +package eu.siacs.conversations.xmpp.stanzas.streammgmt; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class AckPacket extends AbstractStanza { + + public AckPacket(int sequence) { + super("a"); + this.setAttribute("xmlns","urn:xmpp:sm:3"); + this.setAttribute("h", ""+sequence); + } + +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/EnablePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/EnablePacket.java new file mode 100644 index 00000000..ae6a513a --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/EnablePacket.java @@ -0,0 +1,13 @@ +package eu.siacs.conversations.xmpp.stanzas.streammgmt; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class EnablePacket extends AbstractStanza { + + public EnablePacket() { + super("enable"); + this.setAttribute("xmlns","urn:xmpp:sm:3"); + this.setAttribute("resume", "true"); + } + +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/RequestPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/RequestPacket.java new file mode 100644 index 00000000..4d409fd2 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/RequestPacket.java @@ -0,0 +1,12 @@ +package eu.siacs.conversations.xmpp.stanzas.streammgmt; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class RequestPacket extends AbstractStanza { + + public RequestPacket() { + super("r"); + this.setAttribute("xmlns","urn:xmpp:sm:3"); + } + +} diff --git a/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java new file mode 100644 index 00000000..bebfa1a2 --- /dev/null +++ b/src/eu/siacs/conversations/xmpp/stanzas/streammgmt/ResumePacket.java @@ -0,0 +1,14 @@ +package eu.siacs.conversations.xmpp.stanzas.streammgmt; + +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; + +public class ResumePacket extends AbstractStanza { + + public ResumePacket(String id, int sequence) { + super("resume"); + this.setAttribute("xmlns","urn:xmpp:sm:3"); + this.setAttribute("previd", id); + this.setAttribute("h", ""+sequence); + } + +} |