aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java
index 231a6ca7..7c791e70 100644
--- a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java
@@ -30,11 +30,21 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.UiCallback;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.Xmlns;
+import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived;
+import de.thedevstack.conversationsplus.xmpp.exceptions.MissingRequiredContentException;
+import de.thedevstack.conversationsplus.xmpp.exceptions.MissingRequiredElementException;
+import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException;
+import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUpload;
+import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadRequestSlotPacketGenerator;
+import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadSlot;
+import de.thedevstack.conversationsplus.xmpp.httpupload.SlotPacketParser;
+import de.thedevstack.conversationsplus.xmpp.httpupload.SlotRequestPacket;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+@Deprecated
public class HttpUploadConnection implements Transferable {
private HttpConnectionManager mHttpConnectionManager;
@@ -57,7 +67,7 @@ public class HttpUploadConnection implements Transferable {
public HttpUploadConnection(HttpConnectionManager httpConnectionManager) {
this.mHttpConnectionManager = httpConnectionManager;
- this.mXmppConnectionService = httpConnectionManager.getXmppConnectionService();
+ this.mXmppConnectionService = XmppConnectionServiceAccessor.xmppConnectionService;
}
@Override
@@ -107,7 +117,7 @@ public class HttpUploadConnection implements Transferable {
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|| message.getEncryption() == Message.ENCRYPTION_OTR) {
this.key = new byte[48];
- mXmppConnectionService.getRNG().nextBytes(this.key);
+ ConversationsPlusApplication.getSecureRandom().nextBytes(this.key);
this.file.setKeyAndIv(this.key);
}
Pair<InputStream,Integer> pair;
@@ -119,29 +129,25 @@ public class HttpUploadConnection implements Transferable {
}
this.file.setExpectedSize(pair.second);
this.mFileInputStream = pair.first;
- Jid host = account.getXmppConnection().findDiscoItemByFeature(Xmlns.HTTP_UPLOAD);
- IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file,mime);
+ Jid host = account.getXmppConnection().findDiscoItemByFeature(HttpUpload.NAMESPACE);
+ IqPacket request = HttpUploadRequestSlotPacketGenerator.generate(host, file.getName(), file.getSize(), mime);
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.RESULT) {
- Element slot = packet.findChild("slot",Xmlns.HTTP_UPLOAD);
- if (slot != null) {
- try {
- mGetUrl = new URL(slot.findChildContent("get"));
- mPutUrl = new URL(slot.findChildContent("put"));
- if (!canceled) {
- new Thread(new FileUploader()).start();
- }
- } catch (MalformedURLException e) {
- fail();
- }
- } else {
- fail();
- }
- } else {
- fail();
- }
+ try {
+ HttpUploadSlot slot = SlotPacketParser.parseGetAndPutUrl(packet);
+ mGetUrl = new URL(slot.getGetUrl());
+ mPutUrl = new URL(slot.getPutUrl());
+ if (!canceled) {
+ new Thread(new FileUploader()).start();
+ }
+ } catch (XmppException e) {
+ Logging.e("httpupload", e.getMessage());
+ fail();
+ } catch (MalformedURLException e) {
+ Logging.e("httpupload", "malformed url retrieved from slot", e);
+ fail();
+ }
}
});
message.setTransferable(this);
@@ -159,7 +165,7 @@ public class HttpUploadConnection implements Transferable {
OutputStream os = null;
InputStream errorStream = null;
HttpURLConnection connection = null;
- PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_upload_"+message.getUuid());
+ PowerManager.WakeLock wakeLock = ConversationsPlusApplication.createPartialWakeLock("http_upload_"+message.getUuid());
try {
wakeLock.acquire();
Logging.d(Config.LOGTAG, "uploading to " + mPutUrl.toString());