diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java | 49 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/utils/ErrorIqPacketExceptionHelper.java | 15 |
2 files changed, 48 insertions, 16 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; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/utils/ErrorIqPacketExceptionHelper.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/utils/ErrorIqPacketExceptionHelper.java index f02d8d46..bcc5e9dd 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/utils/ErrorIqPacketExceptionHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/utils/ErrorIqPacketExceptionHelper.java @@ -14,20 +14,23 @@ import de.thedevstack.conversationsplus.xmpp.exceptions.UndefinedConditionExcept public final class ErrorIqPacketExceptionHelper { private final static String ERROR_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-stanzas"; - public static void throwIqErrorException(Element packet) throws IqPacketErrorException { + public static void throwIqErrorException(Element errorIqPacket) throws IqPacketErrorException { + Element packet = IqPacketParser.findChild(errorIqPacket, "error", "jabber:client"); + if (null != packet) { if (hasErrorElement(packet, "bad-request")) { - throw new BadRequestIqErrorException(packet, getErrorText(packet)); + throw new BadRequestIqErrorException(errorIqPacket, getErrorText(packet)); } if (hasErrorElement(packet, "service-unavailable")) { - throw new ServiceUnavailableException(packet, getErrorText(packet)); + throw new ServiceUnavailableException(errorIqPacket, getErrorText(packet)); } if (hasErrorElement(packet, "internal-server-error")) { - throw new InternalServerErrorException(packet, getErrorText(packet)); + throw new InternalServerErrorException(errorIqPacket, getErrorText(packet)); } if (hasErrorElement(packet, "undefined-condition")) { - throw new UndefinedConditionException(packet, getErrorText(packet)); + throw new UndefinedConditionException(errorIqPacket, getErrorText(packet)); } - throw new IqPacketErrorException(packet, "Unknown error packet."); + } + throw new IqPacketErrorException(errorIqPacket, "Unknown error packet."); } private static boolean hasErrorElement(Element packet, String elementName) { |