Conversations/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java

103 lines
2.7 KiB
Java
Raw Normal View History

package eu.siacs.conversations.xmpp.jingle.stanzas;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
public class Content extends Element {
2014-08-31 16:28:21 +02:00
private String transportId;
2014-08-31 16:28:21 +02:00
private Content(String name) {
super(name);
}
2014-08-31 16:28:21 +02:00
public Content() {
super("content");
}
2014-08-31 16:28:21 +02:00
2014-04-21 20:39:57 +02:00
public Content(String creator, String name) {
super("content");
this.setAttribute("creator", creator);
this.setAttribute("name", name);
}
public void setTransportId(String sid) {
this.transportId = sid;
}
2014-08-31 16:28:21 +02:00
public void setFileOffer(JingleFile actualFile, boolean otr) {
2014-08-31 16:28:21 +02:00
Element description = this.addChild("description",
"urn:xmpp:jingle:apps:file-transfer:3");
Element offer = description.addChild("offer");
Element file = offer.addChild("file");
2014-09-01 10:40:45 +02:00
file.addChild("size").setContent(Long.toString(actualFile.getSize()));
if (otr) {
2014-08-31 16:28:21 +02:00
file.addChild("name").setContent(actualFile.getName() + ".otr");
} else {
file.addChild("name").setContent(actualFile.getName());
}
}
2014-08-31 16:28:21 +02:00
public Element getFileOffer() {
2014-08-31 16:28:21 +02:00
Element description = this.findChild("description",
"urn:xmpp:jingle:apps:file-transfer:3");
if (description == null) {
return null;
}
Element offer = description.findChild("offer");
2014-08-31 16:28:21 +02:00
if (offer == null) {
return null;
}
return offer.findChild("file");
}
2014-08-31 16:28:21 +02:00
public void setFileOffer(Element fileOffer) {
2014-08-31 16:28:21 +02:00
Element description = this.findChild("description",
"urn:xmpp:jingle:apps:file-transfer:3");
if (description == null) {
description = this.addChild("description",
"urn:xmpp:jingle:apps:file-transfer:3");
}
description.addChild(fileOffer);
}
2014-08-31 16:28:21 +02:00
public String getTransportId() {
if (hasSocks5Transport()) {
this.transportId = socks5transport().getAttribute("sid");
} else if (hasIbbTransport()) {
this.transportId = ibbTransport().getAttribute("sid");
}
return this.transportId;
}
2014-08-31 16:28:21 +02:00
public Element socks5transport() {
2014-08-31 16:28:21 +02:00
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.setAttribute("sid", this.transportId);
}
return transport;
}
2014-08-31 16:28:21 +02:00
public Element ibbTransport() {
2014-08-31 16:28:21 +02:00
Element transport = this.findChild("transport",
"urn:xmpp:jingle:transports:ibb:1");
if (transport == null) {
transport = this.addChild("transport",
"urn:xmpp:jingle:transports:ibb:1");
transport.setAttribute("sid", this.transportId);
}
return transport;
}
2014-08-31 16:28:21 +02:00
public boolean hasSocks5Transport() {
return this.hasChild("transport", "urn:xmpp:jingle:transports:s5b:1");
2014-04-17 14:52:10 +02:00
}
2014-08-31 16:28:21 +02:00
public boolean hasIbbTransport() {
2014-08-31 16:28:21 +02:00
return this.hasChild("transport", "urn:xmpp:jingle:transports:ibb:1");
2014-04-17 14:52:10 +02:00
}
}