aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java18
-rw-r--r--src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java19
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java64
3 files changed, 59 insertions, 42 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index 969ea1611..39249c655 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -80,25 +80,23 @@ public class HttpDownloadConnection implements Transferable {
} else {
mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody().split("\n")[0]));
}
- 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)) {
+ final AbstractConnectionManager.Extension extension = AbstractConnectionManager.Extension.of(mUrl.getPath());
+ if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) {
this.message.setEncryption(Message.ENCRYPTION_PGP);
} else if (message.getEncryption() != Message.ENCRYPTION_OTR
&& message.getEncryption() != Message.ENCRYPTION_AXOLOTL) {
this.message.setEncryption(Message.ENCRYPTION_NONE);
}
- String extension;
- if (VALID_CRYPTO_EXTENSIONS.contains(lastPart)) {
- extension = secondToLast;
+ final String ext;
+ if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) {
+ ext = extension.secondary;
} else {
- extension = lastPart;
+ ext = extension.main;
}
if (message.getStatus() == Message.STATUS_RECEIVED){
- message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : ""));
+ message.setRelativeFilePath(fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (ext != null ? ("." + ext) : ""));
} else {
- message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (extension != null ? ("." + extension) : ""));
+ message.setRelativeFilePath("Sent/" + fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4) + (ext != null ? ("." + ext) : ""));
}
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
final String reference = mUrl.getRef();
diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
index 3399b7861..47c4c9171 100644
--- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
+++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
@@ -138,4 +138,23 @@ public class AbstractConnectionManager {
PowerManager powerManager = (PowerManager) mXmppConnectionService.getSystemService(Context.POWER_SERVICE);
return powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
}
+
+ public static class Extension {
+ public final String main;
+ public final String secondary;
+
+ private Extension(String main, String secondary) {
+ this.main = main;
+ this.secondary = secondary;
+ }
+
+ public static Extension of(String path) {
+ final int pos = path.lastIndexOf('/');
+ final String filename = path.substring(pos + 1).toLowerCase();
+ final String[] parts = filename.split("\\.");
+ final String main = parts.length >= 2 ? parts[parts.length - 1] : null;
+ final String secondary = parts.length >= 3 ? parts[parts.length - 2] : null;
+ return new Extension(main, secondary);
+ }
+ }
}
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index 83ef9ca33..532d56da5 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -417,25 +417,25 @@ public class JingleConnection implements Transferable {
this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().asBareJid());
}
Element fileSize = fileOffer.findChild("size");
- Element fileNameElement = fileOffer.findChild("name");
- if (fileNameElement != null) {
- String[] filename = fileNameElement.getContent()
- .toLowerCase(Locale.US).toLowerCase().split("\\.");
- String filename_new = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
- String extension = filename[filename.length - 1];
- if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
+ final String path = fileOffer.findChildContent("name");
+ if (path != null) {
+ AbstractConnectionManager.Extension extension = AbstractConnectionManager.Extension.of(path);
+ if (VALID_IMAGE_EXTENSIONS.contains(extension.main)) {
message.setType(Message.TYPE_IMAGE);
- message.setRelativeFilePath(filename_new + "." + extension);
- } else if (VALID_CRYPTO_EXTENSIONS.contains(
- filename[filename.length - 1])) {
- if (filename.length == 3) {
- extension = filename[filename.length - 2];
- if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
- message.setType(Message.TYPE_IMAGE);
- message.setRelativeFilePath(filename_new + "." + extension);
- } else {
- message.setType(Message.TYPE_FILE);
- }
+ message.setRelativeFilePath(message.getUuid() + "." + extension.main);
+ } else if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) {
+ if (VALID_IMAGE_EXTENSIONS.contains(extension.secondary)) {
+ message.setType(Message.TYPE_IMAGE);
+ message.setRelativeFilePath(message.getUuid() + "." + extension.main);
+ } else {
+ message.setType(Message.TYPE_FILE);
+ message.setRelativeFilePath(message.getUuid() + (extension.secondary != null ? ("." + extension.secondary) : ""));
+ }
+ // only for OTR compatibility
+ Element fileNameElement = fileOffer.findChild("name");
+ if (fileNameElement != null) {
+ String[] filename = fileNameElement.getContent()
+ .toLowerCase(Locale.US).toLowerCase().split("\\.");
if (filename[filename.length - 1].equals("otr")) {
message.setEncryption(Message.ENCRYPTION_OTR);
} else {
@@ -444,21 +444,9 @@ public class JingleConnection implements Transferable {
}
} else {
message.setType(Message.TYPE_FILE);
+ message.setRelativeFilePath(message.getUuid() + (extension.main != null ? ("." + extension.main) : ""));
}
- if (message.getType() == Message.TYPE_FILE) {
- String suffix = "";
- if (!fileNameElement.getContent().isEmpty()) {
- String[] parts = fileNameElement.getContent().split("/");
- suffix = parts[parts.length - 1];
- if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
- suffix = suffix.substring(0, suffix.length() - 4);
- } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) {
- suffix = suffix.substring(0, suffix.length() - 4);
- }
- }
- message.setRelativeFilePath(filename_new + "_" + suffix);
- }
- long size = Long.parseLong(fileSize.getContent());
+ long size = parseLong(fileSize, 0);
message.setBody(Long.toString(size));
conversation.add(message);
mJingleConnectionManager.updateConversationUi(true);
@@ -503,6 +491,18 @@ public class JingleConnection implements Transferable {
}
}
+ private static long parseLong(final Element element, final long l) {
+ final String input = element == null ? null : element.getContent();
+ if (input == null) {
+ return l;
+ }
+ try {
+ return Long.parseLong(input);
+ } catch (Exception e) {
+ return l;
+ }
+ }
+
private void sendInitRequest() {
JinglePacket packet = this.bootstrapPacket("session-initiate");
Content content = new Content(this.contentCreator, this.contentName);