aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-14 01:06:45 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-14 01:06:45 +0200
commitbbb0693f4a9a62a872b61b12a5118b01c7ca9450 (patch)
tree7db16c0083e42461921936344fba1f9af7c58f97 /src/eu/siacs/conversations/entities
parent7e373bc89fd11cf214fb435f25063d77cc2c48ae (diff)
basic image over http downloading
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/Contact.java4
-rw-r--r--src/eu/siacs/conversations/entities/Downloadable.java4
-rw-r--r--src/eu/siacs/conversations/entities/Message.java41
-rw-r--r--src/eu/siacs/conversations/entities/Roster.java2
4 files changed, 43 insertions, 8 deletions
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java
index b1ebe662..40eee73d 100644
--- a/src/eu/siacs/conversations/entities/Contact.java
+++ b/src/eu/siacs/conversations/entities/Contact.java
@@ -374,4 +374,8 @@ public class Contact implements ListItem {
return false;
}
}
+
+ public boolean trusted() {
+ return getOption(Options.FROM) && getOption(Options.TO);
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Downloadable.java b/src/eu/siacs/conversations/entities/Downloadable.java
index 8fb4977e..c8ee357d 100644
--- a/src/eu/siacs/conversations/entities/Downloadable.java
+++ b/src/eu/siacs/conversations/entities/Downloadable.java
@@ -1,5 +1,9 @@
package eu.siacs.conversations.entities;
public interface Downloadable {
+
+ public final String[] VALID_EXTENSIONS = { "webp", "jpeg", "jpg", "png" };
+ public final String[] VALID_CRYPTO_EXTENSIONS = { "pgp", "gpg", "otr" };
+
public void start();
}
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index 49482bbc..b459510c 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -1,10 +1,15 @@
package eu.siacs.conversations.entities;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.text.InputFilter.LengthFilter;
public class Message extends AbstractEntity {
@@ -131,14 +136,8 @@ public class Message extends AbstractEntity {
if (this.trueCounterpart == null) {
return null;
} else {
- Account account = this.conversation.getAccount();
- Contact contact = account.getRoster().getContact(
+ return this.conversation.getAccount().getRoster().getContactFromRoster(
this.trueCounterpart);
- if (contact.showInRoster()) {
- return contact;
- } else {
- return null;
- }
}
}
}
@@ -369,4 +368,32 @@ public class Message extends AbstractEntity {
return prev.mergable(this);
}
}
+
+ public boolean bodyContainsDownloadable() {
+ Contact contact = this.getContact();
+ if (contact == null || !contact.trusted()) {
+ return false;
+ }
+ try {
+ URL url = new URL(this.getBody());
+ if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
+ return false;
+ }
+ if (url.getPath()==null) {
+ return false;
+ }
+ String[] pathParts = url.getPath().split("/");
+ String filename = pathParts[pathParts.length - 1];
+ String[] extensionParts = filename.split("\\.");
+ if (extensionParts.length == 2 && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(extensionParts[extensionParts.length -1])) {
+ return true;
+ } else if (extensionParts.length == 3 && Arrays.asList(Downloadable.VALID_CRYPTO_EXTENSIONS).contains(extensionParts.length -1) && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(extensionParts[extensionParts.length -2])) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Roster.java b/src/eu/siacs/conversations/entities/Roster.java
index b6908793..ef47c577 100644
--- a/src/eu/siacs/conversations/entities/Roster.java
+++ b/src/eu/siacs/conversations/entities/Roster.java
@@ -14,7 +14,7 @@ public class Roster {
this.account = account;
}
- public Contact getContactAsShownInRoster(String jid) {
+ public Contact getContactFromRoster(String jid) {
String cleanJid = jid.split("/", 2)[0];
Contact contact = contacts.get(cleanJid);
if (contact != null && contact.showInRoster()) {