aboutsummaryrefslogtreecommitdiff
path: root/plugins/http-files
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/http-files')
-rw-r--r--plugins/http-files/src/file_provider.vala34
-rw-r--r--plugins/http-files/src/file_sender.vala37
2 files changed, 65 insertions, 6 deletions
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index d62e3561..bbee8e50 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -38,6 +38,9 @@ public class FileProvider : Dino.FileProvider, Object {
}
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
+ if (Xep.StatelessFileSharing.MessageFlag.get_flag(stanza) != null) {
+ return true;
+ }
string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(stanza);
bool normal_file = oob_url != null && oob_url == message.body && FileProvider.http_url_regex.match(message.body);
bool omemo_file = FileProvider.omemo_url_regex.match(message.body);
@@ -180,6 +183,16 @@ public class FileProvider : Dino.FileProvider, Object {
}
public FileMeta get_file_meta(FileTransfer file_transfer) throws FileReceiveError {
+ // TODO: replace '2' with constant?
+ if (file_transfer.provider == 2) {
+ var file_meta = new HttpFileMeta();
+ file_meta.size = file_transfer.size;
+ file_meta.mime_type = file_transfer.mime_type;
+ file_meta.file_name = file_transfer.file_name;
+ file_meta.message = null;
+ return file_meta;
+ }
+
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
if (conversation == null) throw new FileReceiveError.GET_METADATA_FAILED("No conversation");
@@ -197,7 +210,26 @@ public class FileProvider : Dino.FileProvider, Object {
return file_meta;
}
- public FileReceiveData? get_file_receive_data(FileTransfer file_transfer) {
+ public async FileReceiveData? get_file_receive_data(FileTransfer file_transfer) {
+ // TODO: replace '2' with constant?
+ if (file_transfer.provider == 2) {
+ Xep.StatelessFileSharing.HttpSource http_source = null;
+ for(int i = 0; i < file_transfer.sfs_sources.get_n_items(); i++) {
+ Object source_object = file_transfer.sfs_sources.get_item(i);
+ FileTransfer.SerializedSfsSource source = source_object as FileTransfer.SerializedSfsSource;
+ if (source.type == Xep.StatelessFileSharing.HttpSource.SOURCE_TYPE) {
+ http_source = yield Xep.StatelessFileSharing.HttpSource.deserialize(source.data);
+ assert(source != null);
+ }
+ }
+ if (http_source == null) {
+ printerr("Sfs file transfer has no http sources attached!");
+ return null;
+ }
+ var receive_data = new HttpFileReceiveData();
+ receive_data.url = http_source.url;
+ return receive_data;
+ }
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
if (conversation == null) return null;
diff --git a/plugins/http-files/src/file_sender.vala b/plugins/http-files/src/file_sender.vala
index a2f4769b..91b50944 100644
--- a/plugins/http-files/src/file_sender.vala
+++ b/plugins/http-files/src/file_sender.vala
@@ -45,11 +45,38 @@ public class HttpFileSender : FileSender, Object {
yield upload(file_transfer, send_data, file_meta);
- Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(send_data.url_down, conversation);
- file_transfer.info = message.id.to_string();
-
- message.encryption = send_data.encrypt_message ? conversation.encryption : Encryption.NONE;
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(message, conversation);
+ if (send_data.encrypt_message && conversation.encryption != Encryption.NONE) {
+ Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(send_data.url_down, conversation);
+ file_transfer.info = message.id.to_string();
+
+ message.encryption = conversation.encryption;
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(message, conversation);
+ } else {
+ // Use stateless file sharing for unencrypted file sharing
+ Xep.StatelessFileSharing.HttpSource source = new Xep.StatelessFileSharing.HttpSource();
+ source.url = send_data.url_down;
+ file_transfer.sfs_sources.append(new FileTransfer.SerializedSfsSource.from_sfs_source(source) as Object);
+ this.db.sfs_sources.insert()
+ .value(db.sfs_sources.id, file_transfer.id)
+ .value(db.sfs_sources.type, source.type())
+ .value(db.sfs_sources.data, source.serialize())
+ .perform();
+ XmppStream stream = stream_interactor.get_stream(conversation.account);
+ Xep.StatelessFileSharing.Module sfs_module = stream.get_module(Xep.StatelessFileSharing.Module.IDENTITY);
+ string message_type;
+ if (conversation.type_ == Conversation.Type.GROUPCHAT) {
+ message_type = MessageStanza.TYPE_GROUPCHAT;
+ } else {
+ message_type = MessageStanza.TYPE_CHAT;
+ }
+ MessageStanza sfs_message = new MessageStanza() { to=conversation.counterpart, type_=message_type };
+ // TODO: is this the correct way of adding out-of-band-data?
+ sfs_message.body = source.url;
+ Xep.OutOfBandData.add_url_to_message(sfs_message, source.url);
+ // TODO: message hint correct?
+ Xep.MessageProcessingHints.set_message_hint(sfs_message, Xep.MessageProcessingHints.HINT_STORE);
+ sfs_module.send_stateless_file_transfer(stream, sfs_message, yield file_transfer.to_sfs_element());
+ }
}
public async bool can_send(Conversation conversation, FileTransfer file_transfer) {