diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java index c5a8fe3b..1082e19f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java @@ -71,6 +71,8 @@ import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xml.Tag; import de.thedevstack.conversationsplus.xml.TagWriter; import de.thedevstack.conversationsplus.xml.XmlReader; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload; import de.thedevstack.conversationsplus.xmpp.forms.Data; import de.thedevstack.conversationsplus.xmpp.forms.Field; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; @@ -1534,35 +1536,62 @@ public class XmppConnection implements Runnable { this.blockListRequested = value; } + public boolean hasFeatureFileTransferHttp(long filesize) { + if (Config.DISABLE_HTTP_UPLOAD) { + return false; + } else { + List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(FileTransferHttp.NAMESPACE); + if (items.size() > 0) { + long maxsize = this.parseMaxHttpUploadSize(items.get(0), FileTransferHttp.NAMESPACE); + return filesize <= maxsize; + } else { + return false; + } + } + } + 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 filesize <= maxsize; - } catch (Exception e) { - return true; - } - } else { - return false; - } + if (hasFeatureFileTransferHttp(filesize)) { + return true; + } else { + List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(HttpUpload.NAMESPACE); + if (items.size() > 0) { + long maxsize = this.parseMaxHttpUploadSize(items.get(0), HttpUpload.NAMESPACE); + return filesize <= maxsize; + } else { + return false; + } + } } } + private long parseMaxHttpUploadSize(Entry<Jid, ServiceDiscoveryResult> item, String namespace) { + long maxsize = Long.MAX_VALUE; + if (null != item && null != namespace) { + try { + maxsize = Long.parseLong(item.getValue().getExtendedDiscoInformation(namespace, "max-file-size")); + } catch (Exception e) { + // Suppress exception + } + } + return maxsize; + } + public long getMaxHttpUploadSize() { - List<Entry<Jid, ServiceDiscoveryResult>> 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; - } + List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(HttpUpload.NAMESPACE); + if (items.size() > 0) { + long maxsize = this.parseMaxHttpUploadSize(items.get(0), HttpUpload.NAMESPACE); + if (Long.MAX_VALUE == maxsize) { // For code compatibility - legacy behavior returns -1 in case of no max-file-size + return -1; + } else { + return maxsize; + } + } else { + return -1; + } } } |