From a554be18a60380d624fc9c65416368775cba9bae Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 26 May 2018 22:56:17 +0200 Subject: add support for S3 file transfers --- .../de/pixart/messenger/xmpp/XmppConnection.java | 57 ++++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'src/main/java/de/pixart/messenger/xmpp/XmppConnection.java') diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 5c9d1108a..1d5587d7c 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1842,45 +1842,50 @@ public class XmppConnection implements Runnable { this.blockListRequested = value; } + public boolean p1S3FileTransfer() { + return hasDiscoFeature(Jid.of(account.getServer()), Namespace.P1_S3_FILE_TRANSFER); + } + public boolean httpUpload(long filesize) { if (Config.DISABLE_HTTP_UPLOAD) { return false; } else { - List> items = findDiscoItemsByFeature(this.http_upload_namespace); - if (items.size() == 0) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": this server does not support the latest version of XEP-0363"); - this.http_upload_namespace = Namespace.HTTP_UPLOAD_LEGACY; - items = findDiscoItemsByFeature(this.http_upload_namespace); - } - if (items.size() > 0) { - try { - long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(this.http_upload_namespace, "max-file-size")); - if (filesize <= maxsize) { - return true; - } else { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": http upload is not available for files with size " + filesize + " (max is " + maxsize + ")"); - return false; + for (String namespace : new String[]{Namespace.HTTP_UPLOAD, Namespace.HTTP_UPLOAD_LEGACY}) { + List> items = findDiscoItemsByFeature(namespace); + if (items.size() > 0) { + try { + long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(namespace, "max-file-size")); + if (filesize <= maxsize) { + return true; + } else { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": http upload is not available for files with size " + filesize + " (max is " + maxsize + ")"); + return false; + } + } catch (Exception e) { + //ignored } - } catch (Exception e) { - return true; } - } else { - return false; } + return false; } } + public boolean useLegacyHttpUpload() { + return findDiscoItemByFeature(Namespace.HTTP_UPLOAD) == null && findDiscoItemByFeature(Namespace.HTTP_UPLOAD_LEGACY) != null; + } + public long getMaxHttpUploadSize() { - List> items = findDiscoItemsByFeature(this.http_upload_namespace); - if (items.size() > 0) { - try { - return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(this.http_upload_namespace, "max-file-size")); - } catch (Exception e) { - return -1; + for (String namespace : new String[]{Namespace.HTTP_UPLOAD, Namespace.HTTP_UPLOAD_LEGACY}) { + List> items = findDiscoItemsByFeature(namespace); + if (items.size() > 0) { + try { + return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(namespace, "max-file-size")); + } catch (Exception e) { + //ignored + } } - } else { - return -1; } + return -1; } public boolean stanzaIds() { -- cgit v1.2.3