2014-04-08 23:15:55 +02:00
|
|
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
2014-03-27 02:02:59 +01:00
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-04-13 11:32:45 +02:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleFile;
|
2014-03-27 02:02:59 +01:00
|
|
|
|
|
|
|
public class Content extends Element {
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-20 22:34:27 +02:00
|
|
|
private String transportId;
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-03-27 02:02:59 +01:00
|
|
|
private Content(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-03-27 02:02:59 +01: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);
|
|
|
|
}
|
2014-04-07 20:05:45 +02:00
|
|
|
|
2014-04-20 22:34:27 +02:00
|
|
|
public void setTransportId(String sid) {
|
|
|
|
this.transportId = sid;
|
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-06-20 17:30:19 +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");
|
2014-04-07 20:05:45 +02:00
|
|
|
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()));
|
2014-06-20 17:30:19 +02:00
|
|
|
if (otr) {
|
2014-08-31 16:28:21 +02:00
|
|
|
file.addChild("name").setContent(actualFile.getName() + ".otr");
|
2014-06-20 17:30:19 +02:00
|
|
|
} else {
|
|
|
|
file.addChild("name").setContent(actualFile.getName());
|
|
|
|
}
|
2014-04-07 20:05:45 +02:00
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-13 18:09:40 +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) {
|
2014-04-13 18:09:40 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Element offer = description.findChild("offer");
|
2014-08-31 16:28:21 +02:00
|
|
|
if (offer == null) {
|
2014-04-13 18:09:40 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return offer.findChild("file");
|
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-20 22:34:27 +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");
|
2014-04-11 21:13:09 +02:00
|
|
|
}
|
2014-04-20 22:34:27 +02:00
|
|
|
description.addChild(fileOffer);
|
2014-04-11 21:13:09 +02:00
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-13 21:10:36 +02:00
|
|
|
public String getTransportId() {
|
2014-04-20 22:34:27 +02:00
|
|
|
if (hasSocks5Transport()) {
|
|
|
|
this.transportId = socks5transport().getAttribute("sid");
|
|
|
|
} else if (hasIbbTransport()) {
|
|
|
|
this.transportId = ibbTransport().getAttribute("sid");
|
2014-04-13 21:10:36 +02:00
|
|
|
}
|
2014-04-20 22:34:27 +02:00
|
|
|
return this.transportId;
|
2014-04-13 21:10:36 +02:00
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-20 22:34:27 +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");
|
2014-04-20 22:34:27 +02:00
|
|
|
transport.setAttribute("sid", this.transportId);
|
2014-04-13 21:10:36 +02:00
|
|
|
}
|
2014-04-20 22:34:27 +02:00
|
|
|
return transport;
|
2014-04-13 21:10:36 +02:00
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-20 22:34:27 +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");
|
2014-04-20 22:34:27 +02:00
|
|
|
transport.setAttribute("sid", this.transportId);
|
2014-04-13 18:09:40 +02:00
|
|
|
}
|
2014-04-20 22:34:27 +02:00
|
|
|
return transport;
|
2014-04-13 18:09:40 +02:00
|
|
|
}
|
2014-08-31 16:28:21 +02:00
|
|
|
|
2014-04-20 22:34:27 +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
|
|
|
|
2014-04-20 22:34:27 +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
|
|
|
}
|
2014-03-27 02:02:59 +01:00
|
|
|
}
|