package de.thedevstack.conversationsplus.services.filetransfer.httpupload; import java.net.MalformedURLException; import java.net.URL; import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferEntity; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadSlot; /** * */ public class HttpFileTransferEntity extends FileTransferEntity { private HttpUploadSlot slot; private final byte[] key; private final boolean delayed; public HttpFileTransferEntity(Message message, boolean delayed) { super(message); this.getMessage().setHttpUploaded(true); this.getMessage().setNoDownloadable(); if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) { this.key = new byte[48]; ConversationsPlusApplication.getSecureRandom().nextBytes(this.key); this.getFile().setKeyAndIv(this.key); } else { this.key = null; } this.delayed = delayed; } public void setSlot(HttpUploadSlot slot) { this.slot = slot; } public String getGetUrl() { return this.slot.getGetUrl(); } public String getPutUrl() { return this.slot.getPutUrl(); } public byte[] getKey() { return key; } public boolean isDelayed() { return this.delayed; } @Override public void fail(FileTransferFailureReason failureReason) { this.getMessage().setHttpUploaded(false); super.fail(failureReason); } @Override public void cancel() { this.getMessage().setHttpUploaded(false); super.cancel(); } @Override public void transferred() { try { URL getUrl = new URL(this.getGetUrl()); if (this.getKey() != null) { getUrl = new URL(getUrl.toString() + "#" + CryptoHelper.bytesToHex(this.getKey())); } MessageUtil.updateFileParams(this.getMessage(), getUrl); } catch (MalformedURLException e) { Logging.e("httpupload", "Not a valid get url"); } super.transferred(); } }