From 74c496fe3ef544d45c94365799c061ddfe898330 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 31 Mar 2016 21:56:59 +0200 Subject: add methods to check max file size for http upload --- .../siacs/conversations/xmpp/XmppConnection.java | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index fd0e355d..1552fe1a 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1346,12 +1346,12 @@ public class XmppConnection implements Runnable { this.streamId = null; } - public List findDiscoItemsByFeature(final String feature) { + private List> findDiscoItemsByFeature(final String feature) { synchronized (this.disco) { - final List items = new ArrayList<>(); + final List> items = new ArrayList<>(); for (final Entry cursor : this.disco.entrySet()) { if (cursor.getValue().getFeatures().contains(feature)) { - items.add(cursor.getKey()); + items.add(cursor); } } return items; @@ -1359,9 +1359,9 @@ public class XmppConnection implements Runnable { } public Jid findDiscoItemByFeature(final String feature) { - final List items = findDiscoItemsByFeature(feature); + final List> items = findDiscoItemsByFeature(feature); if (items.size() >= 1) { - return items.get(0); + return items.get(0).getKey(); } return null; } @@ -1505,7 +1505,6 @@ public class XmppConnection implements Runnable { public boolean pep() { synchronized (XmppConnection.this.disco) { - final Pair needle = new Pair<>("pubsub", "pep"); ServiceDiscoveryResult info = disco.get(account.getServer()); if (info != null && info.hasIdentity("pubsub", "pep")) { return true; @@ -1534,8 +1533,22 @@ public class XmppConnection implements Runnable { this.blockListRequested = value; } - public boolean httpUpload() { - return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0; + public boolean httpUpload(long filesize) { + if (Config.DISABLE_HTTP_UPLOAD) { + return false; + } else { + List> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD); + if (items.size() > 0) { + try { + long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size")); + return maxsize <= filesize; + } catch (Exception e) { + return filesize <= 0; + } + } else { + return false; + } + } } } -- cgit v1.2.3 From 2549ce89b0fac2a41c4de61c42d76e521875717f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 1 Apr 2016 00:03:14 +0200 Subject: check max http file size when attaching files --- .../eu/siacs/conversations/xmpp/XmppConnection.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 1552fe1a..6371f115 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1541,15 +1541,28 @@ public class XmppConnection implements Runnable { if (items.size() > 0) { try { long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size")); - return maxsize <= filesize; + return filesize <= maxsize; } catch (Exception e) { - return filesize <= 0; + return true; } } else { return false; } } } + + public long getMaxHttpUploadSize() { + List> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD); + if (items.size() > 0) { + try { + return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size")); + } catch (Exception e) { + return -1; + } + } else { + return -1; + } + } } private IqGenerator getIqGenerator() { -- cgit v1.2.3