diff options
Diffstat (limited to 'src/main')
6 files changed, 50 insertions, 32 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java index 83d9b7b2e..ad5a41323 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java @@ -19,6 +19,7 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.UiCallback; import android.app.PendingIntent; @@ -56,9 +57,11 @@ public class PgpEngine { if (message.getEncryption() == Message.ENCRYPTION_PGP) { message.setBody(os.toString()); message.setEncryption(Message.ENCRYPTION_DECRYPTED); - if (message.trusted() && message.bodyContainsDownloadable()) { - mXmppConnectionService.getHttpConnectionManager() - .createNewConnection(message); + final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager(); + if (message.trusted() + && message.bodyContainsDownloadable() + && manager.getAutoAcceptFileSize() > 0) { + manager.createNewConnection(message); } callback.success(message); } diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 0eb41c551..27821c651 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.xml.Element; diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnection.java b/src/main/java/eu/siacs/conversations/http/HttpConnection.java index b715c3f39..8951de740 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpConnection.java @@ -14,6 +14,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -65,14 +66,22 @@ public class HttpConnection implements Downloadable { this.message.setDownloadable(this); try { mUrl = new URL(message.getBody()); - String path = mUrl.getPath().toLowerCase(); - if (path != null && (path.endsWith(".pgp") || path.endsWith(".gpg"))) { + String[] parts = mUrl.getPath().toLowerCase().split("\\."); + String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null; + String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null; + if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) { this.message.setEncryption(Message.ENCRYPTION_PGP); } else if (message.getEncryption() != Message.ENCRYPTION_OTR) { this.message.setEncryption(Message.ENCRYPTION_NONE); } - this.file = mXmppConnectionService.getFileBackend().getFile( - message, false); + String extension; + if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains(lastPart)) { + extension = secondToLast; + } else { + extension = lastPart; + } + message.setRelativeFilePath(message.getUuid()+"."+extension); + this.file = mXmppConnectionService.getFileBackend().getFile(message, false); String reference = mUrl.getRef(); if (reference != null && reference.length() == 96) { this.file.setKey(CryptoHelper.hexToBytes(reference)); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index bb9de0619..a15be622e 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -8,6 +8,8 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; +import eu.siacs.conversations.http.HttpConnection; +import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; @@ -575,9 +577,9 @@ public class MessageParser extends AbstractParser implements mXmppConnectionService.databaseBackend.createMessage(message); } } - if (message.trusted() && message.bodyContainsDownloadable()) { - this.mXmppConnectionService.getHttpConnectionManager() - .createNewConnection(message); + final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager(); + if (message.trusted() && message.bodyContainsDownloadable() && manager.getAutoAcceptFileSize() > 0) { + manager.createNewConnection(message); } else if (!message.isRead()) { mXmppConnectionService.getNotificationService().push(message); } diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index f7defcdf1..62987aaa5 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -57,28 +57,33 @@ public class FileBackend { public DownloadableFile getFile(Message message, boolean decrypted) { String path = message.getRelativeFilePath(); - if (!decrypted && (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED)) { - String extension; - if (path != null && !path.isEmpty()) { - String[] parts = path.split("\\."); - extension = "."+parts[parts.length - 1]; - } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) { + String extension; + if (path != null && !path.isEmpty()) { + String[] parts = path.split("\\."); + extension = "."+parts[parts.length - 1]; + } else { + if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) { extension = ".webp"; } else { extension = ""; } + path = message.getUuid()+extension; + } + final boolean encrypted = !decrypted + && (message.getEncryption() == Message.ENCRYPTION_PGP + || message.getEncryption() == Message.ENCRYPTION_DECRYPTED); + if (encrypted) { return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+extension+".pgp"); - } else if (path != null && !path.isEmpty()) { + } else { if (path.startsWith("/")) { return new DownloadableFile(path); } else { - return new DownloadableFile(getConversationsFileDirectory()+path); + if (message.getType() == Message.TYPE_FILE) { + return new DownloadableFile(getConversationsFileDirectory() + path); + } else { + return new DownloadableFile(getConversationsImageDirectory()+path); + } } - } else { - StringBuilder filename = new StringBuilder(); - filename.append(getConversationsImageDirectory()); - filename.append(message.getUuid()+".webp"); - return new DownloadableFile(filename.toString()); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index cea4346c4..843cf1e63 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -101,11 +101,9 @@ public class JingleConnection implements Downloadable { file.delete(); } } - Log.d(Config.LOGTAG, - "sucessfully transmitted file:" + file.getAbsolutePath()); + Log.d(Config.LOGTAG,"sucessfully transmitted file:" + file.getAbsolutePath()); if (message.getEncryption() != Message.ENCRYPTION_PGP) { - Intent intent = new Intent( - Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(file)); mXmppConnectionService.sendBroadcast(intent); } @@ -281,15 +279,17 @@ public class JingleConnection implements Downloadable { if (fileNameElement != null) { String[] filename = fileNameElement.getContent() .toLowerCase(Locale.US).toLowerCase().split("\\."); - if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains( - filename[filename.length - 1])) { + String extension = filename[filename.length - 1]; + if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) { message.setType(Message.TYPE_IMAGE); + message.setRelativeFilePath(message.getUuid()+"."+extension); } else if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains( filename[filename.length - 1])) { if (filename.length == 3) { - if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains( - filename[filename.length - 2])) { + extension = filename[filename.length - 2]; + if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) { message.setType(Message.TYPE_IMAGE); + message.setRelativeFilePath(message.getUuid()+"."+extension); } else { message.setType(Message.TYPE_FILE); } |