aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/stanzas
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/stanzas')
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java22
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java32
2 files changed, 49 insertions, 5 deletions
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java b/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
index ebd212b86..ed51a2a5c 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
@@ -1,5 +1,8 @@
package eu.siacs.conversations.xmpp.stanzas.jingle;
+import java.io.File;
+import java.util.List;
+
import eu.siacs.conversations.xml.Element;
public class Content extends Element {
@@ -10,4 +13,23 @@ public class Content extends Element {
public Content() {
super("content");
}
+
+ public void offerFile(File actualFile) {
+ Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
+ Element offer = description.addChild("offer");
+ Element file = offer.addChild("file");
+ file.addChild("size").setContent(""+actualFile.length());
+ file.addChild("name").setContent(actualFile.getName());
+ }
+
+ public void setCanditates(List<Element> canditates) {
+ Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
+ if (transport==null) {
+ transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
+ }
+ transport.clearChildren();
+ for(Element canditate : canditates) {
+ transport.addChild(canditate);
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
index 51c60d1fb..4c444a74c 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
@@ -6,6 +6,7 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JinglePacket extends IqPacket {
Content content = null;
Reason reason = null;
+ Element jingle = new Element("jingle");
@Override
public Element addChild(Element child) {
@@ -22,27 +23,25 @@ public class JinglePacket extends IqPacket {
this.reason.setChildren(reasonElement.getChildren());
this.reason.setAttributes(reasonElement.getAttributes());
}
- this.build();
- this.findChild("jingle").setAttributes(child.getAttributes());
+ this.jingle.setAttributes(child.getAttributes());
}
return child;
}
public JinglePacket setContent(Content content) {
this.content = content;
- this.build();
return this;
}
public JinglePacket setReason(Reason reason) {
this.reason = reason;
- this.build();
return this;
}
private void build() {
this.children.clear();
- Element jingle = addChild("jingle", "urn:xmpp:jingle:1");
+ this.jingle.clearChildren();
+ this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
if (this.content!=null) {
jingle.addChild(this.content);
}
@@ -50,5 +49,28 @@ public class JinglePacket extends IqPacket {
jingle.addChild(this.reason);
}
this.children.add(jingle);
+ this.setAttribute("type", "set");
+ }
+
+ public String getSessionId() {
+ return this.jingle.getAttribute("sid");
+ }
+
+ public void setSessionId(String sid) {
+ this.jingle.setAttribute("sid", sid);
+ }
+
+ @Override
+ public String toString() {
+ this.build();
+ return super.toString();
+ }
+
+ public void setAction(String action) {
+ this.jingle.setAttribute("action", action);
+ }
+
+ public void setInitiator(String initiator) {
+ this.jingle.setAttribute("initiator", initiator);
}
}