aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-01-11 14:55:53 +0100
committersteckbrief <steckbrief@chefmail.de>2017-01-11 14:55:53 +0100
commit0a9bba28616e594279cd659ec2eb57da2074b3cd (patch)
treecb643f89080eee8745be1ee6590429488400f6c1 /src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
parent563fcfa77580292a7ff2360eea20553743bd0ae7 (diff)
Improved error handling for filetransfer:http:delete, Check for httpupload feature available extended to include filetransfer:http as well, method to check if http upload is available moved from data class 'Account' to 'AccountUtil'
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java71
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;
+ }
}
}