|
|
@ -17,22 +17,30 @@
|
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.net.http.AndroidHttpClient;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.http.HttpHost;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
import org.apache.http.StatusLine;
|
|
|
|
import org.apache.http.StatusLine;
|
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
|
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.entity.ByteArrayEntity;
|
|
|
|
import org.apache.http.entity.ByteArrayEntity;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
|
|
|
|
|
|
public class MmsSendHelper extends MmsCommunication {
|
|
|
|
public class MmsSendHelper extends MmsCommunication {
|
|
|
|
|
|
|
|
|
|
|
|
private static byte[] makePost(MmsConnectionParameters parameters, byte[] mms) throws ClientProtocolException, IOException {
|
|
|
|
private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms) throws ClientProtocolException, IOException {
|
|
|
|
|
|
|
|
AndroidHttpClient client = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
Log.w("MmsSender", "Sending MMS1 of length: " + mms.length);
|
|
|
|
Log.w("MmsSender", "Sending MMS1 of length: " + mms.length);
|
|
|
|
HttpClient client = constructHttpClient(parameters);
|
|
|
|
client = constructHttpClient(context, parameters);
|
|
|
|
|
|
|
|
URI targetUrl = new URI(parameters.getMmsc());
|
|
|
|
|
|
|
|
HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
|
|
|
|
HttpPost request = new HttpPost(parameters.getMmsc());
|
|
|
|
HttpPost request = new HttpPost(parameters.getMmsc());
|
|
|
|
ByteArrayEntity entity = new ByteArrayEntity(mms);
|
|
|
|
ByteArrayEntity entity = new ByteArrayEntity(mms);
|
|
|
|
|
|
|
|
|
|
|
@ -42,13 +50,20 @@ public class MmsSendHelper extends MmsCommunication {
|
|
|
|
request.setParams(client.getParams());
|
|
|
|
request.setParams(client.getParams());
|
|
|
|
request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
|
|
|
request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = client.execute(request);
|
|
|
|
HttpResponse response = client.execute(target, request);
|
|
|
|
StatusLine status = response.getStatusLine();
|
|
|
|
StatusLine status = response.getStatusLine();
|
|
|
|
|
|
|
|
|
|
|
|
if (status.getStatusCode() != 200)
|
|
|
|
if (status.getStatusCode() != 200)
|
|
|
|
throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());
|
|
|
|
throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());
|
|
|
|
|
|
|
|
|
|
|
|
return parseResponse(response.getEntity());
|
|
|
|
return parseResponse(response.getEntity());
|
|
|
|
|
|
|
|
} catch (URISyntaxException use) {
|
|
|
|
|
|
|
|
Log.w("MmsSendHelper", use);
|
|
|
|
|
|
|
|
throw new IOException("Couldn't parse URI.");
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
|
|
|
client.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] sendMms(Context context, byte[] mms, String apn) throws IOException {
|
|
|
|
public static byte[] sendMms(Context context, byte[] mms, String apn) throws IOException {
|
|
|
@ -56,7 +71,7 @@ public class MmsSendHelper extends MmsCommunication {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn);
|
|
|
|
MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn);
|
|
|
|
checkRouteToHost(context, parameters, parameters.getMmsc());
|
|
|
|
checkRouteToHost(context, parameters, parameters.getMmsc());
|
|
|
|
return makePost(parameters, mms);
|
|
|
|
return makePost(context, parameters, mms);
|
|
|
|
} catch (ApnUnavailableException aue) {
|
|
|
|
} catch (ApnUnavailableException aue) {
|
|
|
|
Log.w("MmsSender", aue);
|
|
|
|
Log.w("MmsSender", aue);
|
|
|
|
throw new IOException("Failed to get MMSC information...");
|
|
|
|
throw new IOException("Failed to get MMSC information...");
|
|
|
|