diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-03-31 21:56:59 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-03-31 21:56:59 +0200 |
commit | 74c496fe3ef544d45c94365799c061ddfe898330 (patch) | |
tree | 7a02e6eaeffd576d8e87e590a182ab5c361c2c6b /src/main/java/eu/siacs/conversations/xmpp | |
parent | e074104004fa146611ce39cd32751ab3cd718dd1 (diff) |
add methods to check max file size for http upload
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 29 |
1 files changed, 21 insertions, 8 deletions
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<Jid> findDiscoItemsByFeature(final String feature) { + private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { synchronized (this.disco) { - final List<Jid> items = new ArrayList<>(); + final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>(); for (final Entry<Jid, ServiceDiscoveryResult> 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<Jid> items = findDiscoItemsByFeature(feature); + final List<Entry<Jid, ServiceDiscoveryResult>> 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<String, String> 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<Entry<Jid, ServiceDiscoveryResult>> 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; + } + } } } |