diff options
author | lookshe <github@lookshe.org> | 2016-04-05 23:35:38 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-04-05 23:35:38 +0200 |
commit | 0beb3ca30b31f07e374b870e6a659256f6960170 (patch) | |
tree | 82a389561691afa508433d338e3f87aa6c8a5c7b /src/main/java/de/thedevstack/conversationsplus/xmpp | |
parent | 6899b9b01e416da95b9006d9f23bf1e1214f607d (diff) | |
parent | d6a076e11281d4c3fb6b9504fe99d799b04ebbbb (diff) |
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp')
3 files changed, 43 insertions, 13 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java index 9036bf8d..58352d4f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java @@ -1317,12 +1317,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; @@ -1330,9 +1330,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; } @@ -1481,7 +1481,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; @@ -1510,8 +1509,35 @@ 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 filesize <= maxsize; + } catch (Exception e) { + return true; + } + } else { + return false; + } + } + } + + 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; + } } } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java index cb612a07..caa1890e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java @@ -9,6 +9,8 @@ import de.thedevstack.conversationsplus.xml.Element; public class Data extends Element { + private static final String FORM_TYPE = "FORM_TYPE"; + public Data() { super("x"); this.setAttribute("xmlns","jabber:x:data"); @@ -17,7 +19,8 @@ public class Data extends Element { public List<Field> getFields() { ArrayList<Field> fields = new ArrayList<Field>(); for(Element child : getChildren()) { - if (child.getName().equals("field")) { + if (child.getName().equals("field") + && !FORM_TYPE.equals(child.getAttribute("var"))) { fields.add(Field.parse(child)); } } @@ -26,7 +29,8 @@ public class Data extends Element { public Field getFieldByName(String needle) { for(Element child : getChildren()) { - if (child.getName().equals("field") && needle.equals(child.getAttribute("var"))) { + if (child.getName().equals("field") + && needle.equals(child.getAttribute("var"))) { return Field.parse(child); } } @@ -76,11 +80,11 @@ public class Data extends Element { } public void setFormType(String formType) { - this.put("FORM_TYPE", formType); + this.put(FORM_TYPE, formType); } public String getFormType() { - String type = getValue("FORM_TYPE"); + String type = getValue(FORM_TYPE); return type == null ? "" : type; } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java index 618d75ee..b4c05ce4 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java @@ -381,7 +381,7 @@ public class JingleConnection implements Transferable { message.setEncryption(Message.ENCRYPTION_AXOLOTL); this.file.setKey(transportMessage.getKey()); this.file.setIv(transportMessage.getIv()); - message.setAxolotlFingerprint(transportMessage.getFingerprint()); + message.setFingerprint(transportMessage.getFingerprint()); } else { Logging.d(Config.LOGTAG,"could not process KeyTransportMessage"); } |