Fix specified size for encrypted file uploads

This commit is contained in:
fiaxh 2019-08-21 19:31:46 +02:00
parent 3ad2891eb8
commit 0521afa3d8
6 changed files with 17 additions and 13 deletions

View file

@ -86,7 +86,7 @@ public class FileManager : StreamInteractionModule, Object {
FileSendData file_send_data = null; FileSendData file_send_data = null;
foreach (FileSender file_sender in file_senders) { foreach (FileSender file_sender in file_senders) {
if (file_sender.can_send(conversation, file_transfer)) { if (file_sender.can_send(conversation, file_transfer)) {
file_send_data = yield file_sender.prepare_send_file(conversation, file_transfer); file_send_data = yield file_sender.prepare_send_file(conversation, file_transfer, file_meta);
break; break;
} }
} }
@ -393,7 +393,7 @@ public interface FileSender : Object {
public abstract bool is_upload_available(Conversation conversation); public abstract bool is_upload_available(Conversation conversation);
public abstract bool can_send(Conversation conversation, FileTransfer file_transfer); public abstract bool can_send(Conversation conversation, FileTransfer file_transfer);
public abstract async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer) throws FileSendError; public abstract async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer, FileMeta file_meta) throws FileSendError;
public abstract async void send_file(Conversation conversation, FileTransfer file_transfer, FileSendData file_send_data) throws FileSendError; public abstract async void send_file(Conversation conversation, FileTransfer file_transfer, FileSendData file_send_data) throws FileSendError;
public abstract int get_id(); public abstract int get_id();

View file

@ -107,7 +107,7 @@ public class JingleFileSender : FileSender, Object {
return false; return false;
} }
public async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer) throws FileSendError { public async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer, FileMeta file_meta) throws FileSendError {
return new FileSendData(); return new FileSendData();
} }

View file

@ -62,7 +62,7 @@ public class FileProvider : Dino.FileProvider, Object {
receive_data.url = message.body; receive_data.url = message.body;
var file_meta = new HttpFileMeta(); var file_meta = new HttpFileMeta();
file_meta.file_name = Uri.unescape_string(message.body.substring(message.body.last_index_of("/") + 1)); file_meta.file_name = extract_file_name_from_url(message.body);
file_meta.message = message; file_meta.message = message;
file_incoming(additional_info, message.from, message.time, message.local_time, conversation, receive_data, file_meta); file_incoming(additional_info, message.from, message.time, message.local_time, conversation, receive_data, file_meta);
@ -121,11 +121,7 @@ public class FileProvider : Dino.FileProvider, Object {
file_meta.size = file_transfer.size; file_meta.size = file_transfer.size;
file_meta.mime_type = file_transfer.mime_type; file_meta.mime_type = file_transfer.mime_type;
// Extract file name from URL file_meta.file_name = extract_file_name_from_url(message.body);
file_meta.file_name = Uri.unescape_string(message.body.substring(message.body.last_index_of("/") + 1));
if (file_meta.file_name.contains("#")) {
file_meta.file_name = file_meta.file_name.substring(0, file_meta.file_name.last_index_of("#"));
}
file_meta.message = message; file_meta.message = message;
@ -145,6 +141,14 @@ public class FileProvider : Dino.FileProvider, Object {
return receive_data; return receive_data;
} }
private string extract_file_name_from_url(string url) {
string ret = Uri.unescape_string(url.substring(url.last_index_of("/") + 1));
if (ret.contains("#")) {
ret = ret.substring(0, ret.last_index_of("#"));
}
return ret;
}
public int get_id() { return 0; } public int get_id() { return 0; }
} }

View file

@ -17,7 +17,7 @@ public class HttpFileSender : FileSender, Object {
stream_interactor.get_module(MessageProcessor.IDENTITY).build_message_stanza.connect(check_add_oob); stream_interactor.get_module(MessageProcessor.IDENTITY).build_message_stanza.connect(check_add_oob);
} }
public async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer) throws FileSendError { public async FileSendData? prepare_send_file(Conversation conversation, FileTransfer file_transfer, FileMeta file_meta) throws FileSendError {
HttpFileSendData send_data = new HttpFileSendData(); HttpFileSendData send_data = new HttpFileSendData();
if (send_data == null) return null; if (send_data == null) return null;
@ -25,7 +25,7 @@ public class HttpFileSender : FileSender, Object {
if (stream == null) return null; if (stream == null) return null;
try { try {
var slot_result = yield stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, file_transfer.size, file_transfer.mime_type); var slot_result = yield stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, file_meta.size, file_meta.mime_type);
send_data.url_down = slot_result.url_get; send_data.url_down = slot_result.url_get;
send_data.url_up = slot_result.url_put; send_data.url_up = slot_result.url_put;
} catch (Xep.HttpFileUpload.HttpFileTransferError e) { } catch (Xep.HttpFileUpload.HttpFileTransferError e) {

View file

@ -15,7 +15,7 @@ public class OmemoFileDecryptor : FileDecryptor, Object {
public FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) { public FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
HttpFileReceiveData? http_receive_data = receive_data as HttpFileReceiveData; HttpFileReceiveData? http_receive_data = receive_data as HttpFileReceiveData;
if (http_receive_data == null) assert(false); if (http_receive_data == null) assert(false);
// if ((receive_data as OmemoHttpFileReceiveData) != null) return receive_data; if ((receive_data as OmemoHttpFileReceiveData) != null) return receive_data;
var omemo_http_receive_data = new OmemoHttpFileReceiveData(); var omemo_http_receive_data = new OmemoHttpFileReceiveData();
omemo_http_receive_data.url = aesgcm_to_https_link(http_receive_data.url); omemo_http_receive_data.url = aesgcm_to_https_link(http_receive_data.url);

View file

@ -22,7 +22,7 @@ public class Module : XmppStreamModule {
public string url_get { get; set; } public string url_get { get; set; }
public string url_put { 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 { public async SlotResult request_slot(XmppStream stream, string filename, int64 file_size, string? content_type) throws HttpFileTransferError {
Flag? flag = stream.get_flag(Flag.IDENTITY); Flag? flag = stream.get_flag(Flag.IDENTITY);
if (flag == null) { if (flag == null) {
throw new HttpFileTransferError.SLOT_REQUEST("No flag"); throw new HttpFileTransferError.SLOT_REQUEST("No flag");