diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gpgme-vala/src/gpgme_helper.vala | 13 | ||||
-rw-r--r-- | plugins/gpgme-vala/vapi/gpgme.vapi | 6 | ||||
-rw-r--r-- | plugins/http-files/src/file_provider.vala | 12 | ||||
-rw-r--r-- | plugins/http-files/src/manager.vala | 14 | ||||
-rw-r--r-- | plugins/openpgp/src/in_file_processor.vala | 8 | ||||
-rw-r--r-- | plugins/openpgp/src/out_file_processor.vala | 4 |
6 files changed, 30 insertions, 27 deletions
diff --git a/plugins/gpgme-vala/src/gpgme_helper.vala b/plugins/gpgme-vala/src/gpgme_helper.vala index cc013164..c0121842 100644 --- a/plugins/gpgme-vala/src/gpgme_helper.vala +++ b/plugins/gpgme-vala/src/gpgme_helper.vala @@ -19,11 +19,12 @@ public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) } } -public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags) throws GLib.Error { +public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags, string file_name) throws GLib.Error { global_mutex.lock(); try { initialize(); Data plain_data = Data.create_from_file(uri); + plain_data.set_file_name(file_name); Context context = Context.create(); context.set_armor(true); Data enc_data = context.op_encrypt(keys, flags, plain_data); @@ -46,14 +47,20 @@ public static string decrypt(string encr) throws GLib.Error { } } -public static uint8[] decrypt_data(uint8[] data) throws GLib.Error { +public class DecryptedData { + public uint8[] data { get; set; } + public string filename { get; set; } +} + +public static DecryptedData decrypt_data(uint8[] data) throws GLib.Error { global_mutex.lock(); try { initialize(); Data enc_data = Data.create_from_memory(data, false); Context context = Context.create(); Data dec_data = context.op_decrypt(enc_data); - return get_uint8_from_data(dec_data); + DecryptResult* dec_res = context.op_decrypt_result(); + return new DecryptedData() { data=get_uint8_from_data(dec_data), filename=dec_res->file_name}; } finally { global_mutex.unlock(); } diff --git a/plugins/gpgme-vala/vapi/gpgme.vapi b/plugins/gpgme-vala/vapi/gpgme.vapi index 55031bfa..e66aee1f 100644 --- a/plugins/gpgme-vala/vapi/gpgme.vapi +++ b/plugins/gpgme-vala/vapi/gpgme.vapi @@ -59,7 +59,7 @@ namespace GPG { string unsupported_algorithm; bool wrong_key_usage; Recipient recipients; - string filename; + string file_name; } [CCode (cname = "struct _gpgme_recipient")] @@ -481,7 +481,9 @@ namespace GPG { public long seek(long offset, int whence=0); - public DataEncoding *get_encoding(); + public GPGError.Error set_file_name(string file_name); + + public DataEncoding* get_encoding(); public GPGError.Error set_encoding(DataEncoding enc); } diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index bfeca922..5737ebf8 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -20,10 +20,8 @@ public class FileProvider : Dino.FileProvider, Object { this.url_regex = new Regex("""^(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))$"""); this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif|pgp)$"""); - stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_out_message); stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new ReceivedMessageListener(this)); stream_interactor.get_module(Manager.IDENTITY).uploaded.connect((file_transfer, url) => { - file_transfer.info = url; ignore_once.add(url); }); } @@ -56,14 +54,6 @@ public class FileProvider : Dino.FileProvider, Object { } } - public void check_out_message(Message message, Conversation conversation) { - if (ignore_once.remove(message.body)) return; - if (message.body.length < 5) return; - if (!url_regex.match(message.body)) return; - if (!file_ext_regex.match(message.body)) return; - download_url(message, conversation); - } - private async bool download_url(Message message, Conversation conversation) { bool success = false; var session = new Soup.Session(); @@ -101,7 +91,7 @@ public class FileProvider : Dino.FileProvider, Object { file_transfer.size = int.parse(content_length); file_transfer.state = FileTransfer.State.NOT_STARTED; file_transfer.provider = 0; - file_transfer.info = message.body; + file_transfer.info = message.id.to_string(); file_incoming(file_transfer); success = true; Idle.add((owned)callback); diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala index 3be3c6a7..c27babe2 100644 --- a/plugins/http-files/src/manager.vala +++ b/plugins/http-files/src/manager.vala @@ -35,7 +35,11 @@ public class Manager : StreamInteractionModule, FileSender, Object { 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); + file_transfer.info = url_down; + Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(url_down, conversation); + message.encryption = Encryption.NONE; + stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(message, conversation); + file_transfer.info = message.id.to_string(); }, (stream, error_str) => { print(@"Failed getting upload url + $error_str\n"); @@ -97,11 +101,9 @@ public class FileMessageFilterDisplay : Plugins.MessageDisplayProvider, Object { } private bool message_is_file(Database db, Entities.Message message) { - Qlite.QueryBuilder builder = db.file_transfer.select() - .with(db.file_transfer.info, "=", message.body) - .with(db.file_transfer.account_id, "=", message.account.id) - .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(message.counterpart)); - return builder.count() > 0; + Qlite.QueryBuilder builder = db.file_transfer.select().with(db.file_transfer.info, "=", message.id.to_string()); + Qlite.QueryBuilder builder2 = db.file_transfer.select().with(db.file_transfer.info, "=", message.body); + return builder.count() > 0 || builder2.count() > 0; } } diff --git a/plugins/openpgp/src/in_file_processor.vala b/plugins/openpgp/src/in_file_processor.vala index 61baa37e..568315f9 100644 --- a/plugins/openpgp/src/in_file_processor.vala +++ b/plugins/openpgp/src/in_file_processor.vala @@ -17,10 +17,12 @@ public class InFileProcessor : IncommingFileProcessor, Object { data.append_vals(buf, (uint) len); } while(len > 0); - uint8[] clear_data = GPGHelper.decrypt_data(data.data); - file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free); + GPGHelper.DecryptedData clear_data = GPGHelper.decrypt_data(data.data); + file_transfer.input_stream = new MemoryInputStream.from_data(clear_data.data, GLib.free); file_transfer.encryption = Encryption.PGP; - if (file_transfer.file_name.has_suffix(".pgp")) { + if (clear_data.filename != null && clear_data.filename != "") { + file_transfer.file_name = clear_data.filename; + } else if (file_transfer.file_name.has_suffix(".pgp")) { file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); } } catch (Error e) { diff --git a/plugins/openpgp/src/out_file_processor.vala b/plugins/openpgp/src/out_file_processor.vala index c644a190..522e518a 100644 --- a/plugins/openpgp/src/out_file_processor.vala +++ b/plugins/openpgp/src/out_file_processor.vala @@ -15,10 +15,10 @@ public class OutFileProcessor : OutgoingFileProcessor, Object { } public void process(Conversation conversation, FileTransfer file_transfer) { - string uri = file_transfer.get_uri(); + string path = file_transfer.get_file().get_path(); try { GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); - uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); + uint8[] enc_content = GPGHelper.encrypt_file(path, keys, GPG.EncryptFlags.ALWAYS_TRUST, file_transfer.file_name); file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); file_transfer.encryption = Encryption.PGP; file_transfer.server_file_name = Xmpp.random_uuid() + ".pgp"; |