diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java index 26afbc8de2..4cd6018e96 100644 --- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java +++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java @@ -2,7 +2,6 @@ package org.whispersystems.textsecure.push; import android.content.Context; import android.util.Log; -import android.util.Pair; import com.google.thoughtcrimegson.Gson; import com.google.thoughtcrimegson.JsonParseException; @@ -167,19 +166,18 @@ public class PushServiceSocket { } public long sendAttachment(PushAttachmentData attachment) throws IOException { - Pair response = makeRequestForResponseHeader(String.format(ATTACHMENT_PATH, ""), - "GET", null, "Content-Location"); + String response = makeRequest(String.format(ATTACHMENT_PATH, ""), "GET", null); + AttachmentDescriptor attachmentKey = new Gson().fromJson(response, AttachmentDescriptor.class); - String contentLocation = response.first; - Log.w("PushServiceSocket", "Got attachment content location: " + contentLocation); - - if (contentLocation == null) { + if (attachmentKey == null || attachmentKey.getLocation() == null) { throw new IOException("Server failed to allocate an attachment key!"); } - uploadExternalFile("PUT", contentLocation, attachment.getData()); + Log.w("PushServiceSocket", "Got attachment content location: " + attachmentKey.getLocation()); - return new Gson().fromJson(response.second, AttachmentKey.class).getId(); + uploadExternalFile("PUT", attachmentKey.getLocation(), attachment.getData()); + + return attachmentKey.getId(); } public File retrieveAttachment(String relay, long attachmentId) throws IOException { @@ -189,14 +187,15 @@ public class PushServiceSocket { path = path + "?relay=" + relay; } - Pair response = makeRequestForResponseHeader(path, "GET", null, "Content-Location"); + String response = makeRequest(path, "GET", null); + AttachmentDescriptor descriptor = new Gson().fromJson(response, AttachmentDescriptor.class); - Log.w("PushServiceSocket", "Attachment: " + attachmentId + " is at: " + response.first); + Log.w("PushServiceSocket", "Attachment: " + attachmentId + " is at: " + descriptor.getLocation()); File attachment = File.createTempFile("attachment", ".tmp", context.getFilesDir()); attachment.deleteOnExit(); - downloadExternalFile(response.first, attachment); + downloadExternalFile(descriptor.getLocation(), attachment); return attachment; } @@ -276,18 +275,6 @@ public class PushServiceSocket { } } - private Pair makeRequestForResponseHeader(String urlFragment, String method, - String body, String responseHeader) - throws IOException - { - HttpURLConnection connection = makeBaseRequest(urlFragment, method, body); - String response = Util.readFully(connection.getInputStream()); - String headerValue = connection.getHeaderField(responseHeader); - connection.disconnect(); - - return new Pair(headerValue, response); - } - private String makeRequest(String urlFragment, String method, String body) throws IOException { @@ -321,7 +308,7 @@ public class PushServiceSocket { throw new RateLimitException("Rate limit exceeded: " + connection.getResponseCode()); } - if (connection.getResponseCode() == 403) { + if (connection.getResponseCode() == 401 || connection.getResponseCode() == 403) { throw new AuthorizationFailedException("Authorization failed!"); } @@ -409,16 +396,17 @@ public class PushServiceSocket { } } - private static class AttachmentKey { + private static class AttachmentDescriptor { private long id; - - public AttachmentKey(long id) { - this.id = id; - } + private String location; public long getId() { return id; } + + public String getLocation() { + return location; + } } public interface TrustStore { diff --git a/src/org/thoughtcrime/securesms/Release.java b/src/org/thoughtcrime/securesms/Release.java index 423afdb13e..9005d8057c 100644 --- a/src/org/thoughtcrime/securesms/Release.java +++ b/src/org/thoughtcrime/securesms/Release.java @@ -3,6 +3,6 @@ package org.thoughtcrime.securesms; public class Release { public static final String PUSH_URL = "https://textsecure-service.whispersystems.org"; -// public static final String PUSH_SERVICE_URL = "http://192.168.1.135:8080"; +// public static final String PUSH_URL = "http://192.168.1.135:8080"; }