From 9ea16b6d8568cb383eb1f469d1dc54bfcad4f188 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 16 Oct 2017 00:23:51 +0200 Subject: PGP encrypted file transfers --- plugins/http-files/src/file_provider.vala | 2 +- plugins/http-files/src/manager.vala | 4 +--- plugins/http-files/src/upload_stream_module.vala | 17 ++++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'plugins/http-files/src') diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index d327ec5f..9e677a92 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -47,7 +47,7 @@ public class FileProvider : Dino.FileProvider, Object { if (name == "Content-Type") content_type = val; if (name == "Content-Length") content_length = val; }); - if (content_type != null && content_type.has_prefix("image") && content_length != null && int.parse(content_length) < 5000000) { + if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) { Soup.Request request = session.request (message.body); FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala index 9abf9843..dd168b3d 100644 --- a/plugins/http-files/src/manager.vala +++ b/plugins/http-files/src/manager.vala @@ -23,9 +23,7 @@ public class Manager : StreamInteractionModule, FileSender, Object { public void send_file(Conversation conversation, FileTransfer file_transfer) { Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(file_transfer.account); if (stream != null) { - file_transfer.provider = 0; - uploading(file_transfer); - stream_interactor.module_manager.get_module(file_transfer.account, UploadStreamModule.IDENTITY).upload(stream, Path.build_filename(FileManager.get_storage_dir(), file_transfer.path), + stream_interactor.module_manager.get_module(file_transfer.account, UploadStreamModule.IDENTITY).upload(stream, file_transfer.input_stream, file_transfer.server_file_name, file_transfer.size, file_transfer.mime_type, (stream, url_down) => { uploaded(file_transfer, url_down); stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(url_down, conversation); diff --git a/plugins/http-files/src/upload_stream_module.vala b/plugins/http-files/src/upload_stream_module.vala index c4fa3d2f..ee70e49d 100644 --- a/plugins/http-files/src/upload_stream_module.vala +++ b/plugins/http-files/src/upload_stream_module.vala @@ -14,16 +14,19 @@ public class UploadStreamModule : XmppStreamModule { public delegate void OnUploadOk(XmppStream stream, string url_down); public delegate void OnError(XmppStream stream, string error); - public void upload(XmppStream stream, string file_uri, owned OnUploadOk listener, owned OnError error_listener) { - File file = File.new_for_path(file_uri); - FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); - request_slot(stream, file.get_basename(), (int)file_info.get_size(), file_info.get_content_type(), + public void upload(XmppStream stream, InputStream input_stream, string file_name, int file_size, string file_content_type, owned OnUploadOk listener, owned OnError error_listener) { + request_slot(stream, file_name, file_size, file_content_type, (stream, url_down, url_up) => { - uint8[] data; - FileUtils.get_data(file_uri, out data); + uint8[] buf = new uint8[256]; + Array data = new Array(false, true, 0); + size_t len = -1; + do { + len = input_stream.read(buf); + data.append_vals(buf, (uint) len); + } while(len > 0); Soup.Message message = new Soup.Message("PUT", url_up); - message.set_request(file_info.get_content_type(), Soup.MemoryUse.COPY, data); + message.set_request(file_content_type, Soup.MemoryUse.COPY, data.data); Soup.Session session = new Soup.Session(); session.send_async.begin(message, null, (obj, res) => { try { -- cgit v1.2.3-70-g09d2