1package eu.siacs.conversations.xmpp.jingle.stanzas;
2
3import eu.siacs.conversations.xml.Element;
4import eu.siacs.conversations.xmpp.jingle.JingleFile;
5
6public class Content extends Element {
7
8 private String transportId;
9
10 private Content(String name) {
11 super(name);
12 }
13
14 public Content() {
15 super("content");
16 }
17
18 public Content(String creator, String name) {
19 super("content");
20 this.setAttribute("creator", creator);
21 this.setAttribute("name", name);
22 }
23
24 public void setTransportId(String sid) {
25 this.transportId = sid;
26 }
27
28 public void setFileOffer(JingleFile actualFile, boolean otr) {
29 Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
30 Element offer = description.addChild("offer");
31 Element file = offer.addChild("file");
32 file.addChild("size").setContent(""+actualFile.getSize());
33 if (otr) {
34 file.addChild("name").setContent(actualFile.getName()+".otr");
35 } else {
36 file.addChild("name").setContent(actualFile.getName());
37 }
38 }
39
40 public Element getFileOffer() {
41 Element description = this.findChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
42 if (description==null) {
43 return null;
44 }
45 Element offer = description.findChild("offer");
46 if (offer==null) {
47 return null;
48 }
49 return offer.findChild("file");
50 }
51
52 public void setFileOffer(Element fileOffer) {
53 Element description = this.findChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
54 if (description==null) {
55 description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
56 }
57 description.addChild(fileOffer);
58 }
59
60 public String getTransportId() {
61 if (hasSocks5Transport()) {
62 this.transportId = socks5transport().getAttribute("sid");
63 } else if (hasIbbTransport()) {
64 this.transportId = ibbTransport().getAttribute("sid");
65 }
66 return this.transportId;
67 }
68
69 public Element socks5transport() {
70 Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
71 if (transport==null) {
72 transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
73 transport.setAttribute("sid", this.transportId);
74 }
75 return transport;
76 }
77
78 public Element ibbTransport() {
79 Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:ibb:1");
80 if (transport==null) {
81 transport = this.addChild("transport", "urn:xmpp:jingle:transports:ibb:1");
82 transport.setAttribute("sid", this.transportId);
83 }
84 return transport;
85 }
86
87 public boolean hasSocks5Transport() {
88 return this.hasChild("transport", "urn:xmpp:jingle:transports:s5b:1");
89 }
90
91 public boolean hasIbbTransport() {
92 return this.hasChild("transport","urn:xmpp:jingle:transports:ibb:1");
93 }
94}