aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-07-18 02:03:42 +0200
committerfiaxh <git@lightrise.org>2019-07-18 02:03:42 +0200
commitf0abb8aaf9d06106235ca5e0e6b3ca2e425c4422 (patch)
tree03fce63f8c37b50b5202690a6801234724ed0021 /xmpp-vala/src/module
parent30353e92d63c033857ad0396c921b3bf5cab44c3 (diff)
downloaddino-f0abb8aaf9d06106235ca5e0e6b3ca2e425c4422.tar.gz
dino-f0abb8aaf9d06106235ca5e0e6b3ca2e425c4422.zip
Refactor file receive/send interfaces and UI
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r--xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala7
-rw-r--r--xmpp-vala/src/module/xep/0363_http_file_upload.vala40
2 files changed, 41 insertions, 6 deletions
diff --git a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala
index 57222bae..2e636491 100644
--- a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala
+++ b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala
@@ -62,11 +62,13 @@ public class Module : Jingle.ContentType, XmppStreamModule {
}
public class Parameters : Jingle.ContentParameters, Object {
+
Module parent;
string? media_type;
public string? name { get; private set; }
public int64 size { get; private set; }
public StanzaNode original_description { get; private set; }
+
public Parameters(Module parent, StanzaNode original_description, string? media_type, string? name, int64? size) {
this.parent = parent;
this.original_description = original_description;
@@ -74,6 +76,7 @@ public class Parameters : Jingle.ContentParameters, Object {
this.name = name;
this.size = size;
}
+
public static Parameters parse(Module parent, StanzaNode description) throws Jingle.IqError {
Gee.List<StanzaNode> files = description.get_subnodes("file", NS_URI);
if (files.size != 1) {
@@ -98,7 +101,8 @@ public class Parameters : Jingle.ContentParameters, Object {
return new Parameters(parent, description, media_type, name, size);
}
- void on_session_initiate(XmppStream stream, Jingle.Session session) {
+
+ public void on_session_initiate(XmppStream stream, Jingle.Session session) {
parent.file_incoming(stream, new FileTransfer(session, this));
}
}
@@ -122,6 +126,7 @@ public class FileTransfer : Object {
session.accept(stream, parameters.original_description);
session.conn.output_stream.close();
}
+
public void reject(XmppStream stream) {
session.reject(stream);
}
diff --git a/xmpp-vala/src/module/xep/0363_http_file_upload.vala b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
index 1d808ed1..eefe05eb 100644
--- a/xmpp-vala/src/module/xep/0363_http_file_upload.vala
+++ b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
@@ -6,6 +6,10 @@ namespace Xmpp.Xep.HttpFileUpload {
private const string NS_URI = "urn:xmpp:http:upload";
private const string NS_URI_0 = "urn:xmpp:http:upload:0";
+public errordomain HttpFileTransferError {
+ SLOT_REQUEST
+}
+
public class Module : XmppStreamModule {
public static Xmpp.ModuleIdentity<Module> IDENTITY = new Xmpp.ModuleIdentity<Module>(NS_URI, "0363_http_file_upload");
@@ -14,9 +18,15 @@ public class Module : XmppStreamModule {
public delegate void OnSlotOk(XmppStream stream, string url_get, string url_put);
public delegate void OnError(XmppStream stream, string error);
- public void request_slot(XmppStream stream, string filename, int file_size, string? content_type, owned OnSlotOk listener, owned OnError error_listener) {
+ public struct SlotResult {
+ public string url_get { get; set; }
+ public string url_put { get; set; }
+ }
+ public async SlotResult request_slot(XmppStream stream, string filename, int file_size, string? content_type) throws HttpFileTransferError {
Flag? flag = stream.get_flag(Flag.IDENTITY);
- if (flag == null) return;
+ if (flag == null) {
+ throw new HttpFileTransferError.SLOT_REQUEST("No flag");
+ }
StanzaNode? request_node = null;
switch (flag.ns_ver) {
@@ -34,10 +44,17 @@ public class Module : XmppStreamModule {
}
break;
}
+
+ SourceFunc callback = request_slot.callback;
+ var slot_result = SlotResult();
+
Iq.Stanza iq = new Iq.Stanza.get(request_node) { to=flag.file_store_jid };
+
+ HttpFileTransferError? e = null;
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, (stream, iq) => {
if (iq.is_error()) {
- error_listener(stream, "Error getting upload/download url (Error Iq)");
+ e = new HttpFileTransferError.SLOT_REQUEST("Error getting upload/download url (Error Iq)");
+ Idle.add((owned) callback);
return;
}
string? url_get = null, url_put = null;
@@ -49,10 +66,23 @@ public class Module : XmppStreamModule {
url_put = iq.stanza.get_deep_string_content(flag.ns_ver + ":slot", flag.ns_ver + ":put");
}
if (url_get == null || url_put == null) {
- error_listener(stream, "Error getting upload/download url");
+ e = new HttpFileTransferError.SLOT_REQUEST("Error getting upload/download url: %s".printf(iq.stanza.to_string()));
+ Idle.add((owned) callback);
+ return;
}
- listener(stream, url_get, url_put);
+
+ slot_result.url_get = url_get;
+ slot_result.url_put = url_put;
+
+ Idle.add((owned) callback);
});
+ yield;
+
+ if (e != null) {
+ throw e;
+ }
+
+ return slot_result;
}
public override void attach(XmppStream stream) {