From 11e2b1accd933eb9fcb4477a60dd0864d9f72a67 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 31 Jul 2017 08:44:32 +0200 Subject: Implements FS#245: Implement FiletransferHttp (upload and delete), some minor bug fixes including to fail a JingleTransfer in case criterias are not met --- .../HttpUploadRequestSlotPacketGenerator.java | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java index 4b0a956c..db455b7a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java @@ -1,5 +1,7 @@ package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; +import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; @@ -24,17 +26,38 @@ public final class HttpUploadRequestSlotPacketGenerator { * * * - * @param host the jid of the host to request a slot from + * @param account the account requesting a slot * @param filename the filename of the file which will be transferred * @param filesize the filesize of the file which will be transferred * @param mime the mime type of the file which will be transferred - optional and therefore nullable * @return the IqPacket */ - public static IqPacket generate(Jid host, String filename, long filesize, String mime) { - SlotRequestPacket packet = new SlotRequestPacket(filename, filesize); - packet.setTo(host); - packet.setMime((mime == null || mime.isEmpty()) ? HttpUpload.DEFAULT_MIME_TYPE : mime); - return packet; + public static IqPacket generate(Account account, Jid recipient, String filename, long filesize, String mime) { + String namespace = getNamespace(account); + Jid host = getHost(account, namespace); + IqPacket requestPacket; + switch (namespace) { + case HttpUpload.NAMESPACE: + requestPacket = new HttpUploadSlotRequestPacket(filename, filesize, mime); + break; + case FileTransferHttp.NAMESPACE: + default: + requestPacket = new FileTransferHttpUploadSlotRequestPacket(recipient.toString(), filename, filesize, mime); + } + requestPacket.setTo(host); + return requestPacket; + } + + private static String getNamespace(Account account) { + if (null != account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE)) { + return FileTransferHttp.NAMESPACE; + } else { + return HttpUpload.NAMESPACE; + } + } + + private static Jid getHost(Account account, String namespace) { + return account.getXmppConnection().findDiscoItemByFeature(namespace); } /** -- cgit v1.2.3