aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java49
1 files changed, 39 insertions, 10 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,31 +1536,58 @@ public class XmppConnection implements Runnable {
this.blockListRequested = value;
}
- public boolean httpUpload(long filesize) {
+ public boolean hasFeatureFileTransferHttp(long filesize) {
if (Config.DISABLE_HTTP_UPLOAD) {
return false;
} else {
- List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD);
+ List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(FileTransferHttp.NAMESPACE);
if (items.size() > 0) {
- try {
- long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size"));
+ long maxsize = this.parseMaxHttpUploadSize(items.get(0), FileTransferHttp.NAMESPACE);
return filesize <= maxsize;
- } catch (Exception e) {
- return true;
- }
} else {
return false;
}
}
}
- public long getMaxHttpUploadSize() {
- List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD);
+ public boolean httpUpload(long filesize) {
+ if (Config.DISABLE_HTTP_UPLOAD) {
+ return false;
+ } else {
+ 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 {
- return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size"));
+ 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(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;