1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package de.pixart.messenger.xmpp.jingle.stanzas;
import de.pixart.messenger.entities.DownloadableFile;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
public class Content extends Element {
public enum Version {
FT_3("urn:xmpp:jingle:apps:file-transfer:3"),
FT_4("urn:xmpp:jingle:apps:file-transfer:4"),
FT_5("urn:xmpp:jingle:apps:file-transfer:5");
private final String namespace;
Version(String namespace) {
this.namespace = namespace;
}
public String getNamespace() {
return namespace;
}
}
private String transportId;
public Content() {
super("content");
}
public Content(String creator, String name) {
super("content");
this.setAttribute("creator", creator);
this.setAttribute("senders", creator);
this.setAttribute("name", name);
}
public Version getVersion() {
if (hasChild("description", Version.FT_3.namespace)) {
return Version.FT_3;
} else if (hasChild("description", Version.FT_4.namespace)) {
return Version.FT_4;
} else if (hasChild("description", Version.FT_5.namespace)) {
return Version.FT_5;
}
return null;
}
public void setTransportId(String sid) {
this.transportId = sid;
}
public Element setFileOffer(DownloadableFile actualFile, boolean otr, Version version) {
Element description = this.addChild("description", version.namespace);
Element file;
if (version == Version.FT_3) {
Element offer = description.addChild("offer");
file = offer.addChild("file");
} else {
file = description.addChild("file");
}
file.addChild("size").setContent(Long.toString(actualFile.getExpectedSize()));
if (otr) {
file.addChild("name").setContent(actualFile.getName() + ".otr");
} else {
file.addChild("name").setContent(actualFile.getName());
}
return file;
}
public Element getFileOffer(Version version) {
Element description = this.findChild("description", version.namespace);
if (description == null) {
return null;
}
if (version == Version.FT_3) {
Element offer = description.findChild("offer");
if (offer == null) {
return null;
}
return offer.findChild("file");
} else {
return description.findChild("file");
}
}
public void setFileOffer(Element fileOffer, Version version) {
Element description = this.addChild("description", version.namespace);
if (version == Version.FT_3) {
description.addChild("offer").addChild(fileOffer);
} else {
description.addChild(fileOffer);
}
}
public String getTransportId() {
if (hasSocks5Transport()) {
this.transportId = socks5transport().getAttribute("sid");
} else if (hasIbbTransport()) {
this.transportId = ibbTransport().getAttribute("sid");
}
return this.transportId;
}
public Element socks5transport() {
Element transport = this.findChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
if (transport == null) {
transport = this.addChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public Element ibbTransport() {
Element transport = this.findChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
if (transport == null) {
transport = this.addChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
transport.setAttribute("sid", this.transportId);
}
return transport;
}
public boolean hasSocks5Transport() {
return this.hasChild("transport", Namespace.JINGLE_TRANSPORTS_S5B);
}
public boolean hasIbbTransport() {
return this.hasChild("transport", Namespace.JINGLE_TRANSPORTS_IBB);
}
}
|