aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala
diff options
context:
space:
mode:
authorhrxi <hrrrxi@gmail.com>2019-06-23 14:53:18 +0200
committerhrxi <hrrrxi@gmail.com>2019-07-09 11:21:39 +0200
commit877c46628fa2836f9226e24a3d0a84b9a3f821e6 (patch)
tree08f319b9223ed8eac4c44e70dfc77ead881e722c /xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala
parent6c480b862eefc38b2d3ba8dc7e02ddbe8d13edee (diff)
downloaddino-877c46628fa2836f9226e24a3d0a84b9a3f821e6.tar.gz
dino-877c46628fa2836f9226e24a3d0a84b9a3f821e6.zip
Implement file sending via Jingle
This is still disabled by default until prioritization is implemented; otherwise this could be preferred to HTTP uploads. File sending only works via Jingle In-Band-Bytestreams right now, more transports are going to be implemented. To test this, uncomment the line with `JingleFileTransfer` in libdino/src/application.vala.
Diffstat (limited to 'xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala')
-rw-r--r--xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala75
1 files changed, 75 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala
new file mode 100644
index 00000000..57dbaaa3
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala
@@ -0,0 +1,75 @@
+using Xmpp;
+using Xmpp.Xep;
+
+namespace Xmpp.Xep.JingleInBandBytestreams {
+
+private const string NS_URI = "urn:xmpp:jingle:transports:ibb:1";
+private const int DEFAULT_BLOCKSIZE = 4096;
+
+public class Module : Jingle.Transport, XmppStreamModule {
+ public static Xmpp.ModuleIdentity<Module> IDENTITY = new Xmpp.ModuleIdentity<Module>(NS_URI, "0261_jingle_in_band_bytestreams");
+
+ public override void attach(XmppStream stream) {
+ stream.get_module(Jingle.Module.IDENTITY).add_transport(stream, this);
+ stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
+ }
+ public override void detach(XmppStream stream) { }
+
+ public override string get_ns() { return NS_URI; }
+ public override string get_id() { return IDENTITY.id; }
+
+ public bool is_transport_available(XmppStream stream, Jid full_jid) {
+ bool? result = stream.get_flag(ServiceDiscovery.Flag.IDENTITY).has_entity_feature(full_jid, NS_URI);
+ return result != null && result;
+ }
+
+ public Jingle.TransportType transport_type() {
+ return Jingle.TransportType.STREAMING;
+ }
+ public StanzaNode to_transport_stanza_node() {
+ return new StanzaNode.build("transport", NS_URI)
+ .add_self_xmlns()
+ .put_attribute("block-size", DEFAULT_BLOCKSIZE.to_string())
+ .put_attribute("sid", random_uuid());
+ }
+
+ public Jingle.Connection? create_transport_connection(XmppStream stream, Jid peer_full_jid, StanzaNode content) throws Jingle.CreateConnectionError {
+ StanzaNode? transport = content.get_subnode("transport", NS_URI);
+ if (transport == null) {
+ return null;
+ }
+ string? sid = transport.get_attribute("sid");
+ int block_size = transport.get_attribute_int("block-size");
+ if (sid == null || block_size <= 0) {
+ throw new Jingle.CreateConnectionError.BAD_REQUEST("Invalid IBB parameters");
+ }
+ if (block_size > DEFAULT_BLOCKSIZE) {
+ throw new Jingle.CreateConnectionError.NOT_ACCEPTABLE("Invalid IBB parameters: peer increased block size");
+ }
+ return new Connection(peer_full_jid, new InBandBytestreams.Connection(peer_full_jid, sid, block_size));
+ }
+}
+
+public class Connection : Jingle.Connection {
+ InBandBytestreams.Connection inner;
+
+ public Connection(Jid full_jid, InBandBytestreams.Connection inner) {
+ base(full_jid);
+ inner.on_error.connect((stream, error) => on_error(stream, new Jingle.Error.TRANSPORT_ERROR(error)));
+ inner.on_data.connect((stream, data) => on_data(stream, data));
+ inner.on_ready.connect((stream) => on_ready(stream));
+ this.inner = inner;
+ }
+
+ public override void connect(XmppStream stream) {
+ inner.connect(stream);
+ }
+ public override void send(XmppStream stream, uint8[] data) {
+ inner.send(stream, data);
+ }
+ public override void close(XmppStream stream) {
+ inner.close(stream);
+ }
+}
+
+}