mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2026-08-20 12:52:59 +00:00
HTTPClient: send application name & version code in User Agent
Also ignore cookies like owncloud android lib & set http version to 1.1
This commit is contained in:
@@ -241,7 +241,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
_returnCode = 0;
|
||||
OCHttpClient http = new OCHttpClient(_serverURI, _login, _password);
|
||||
OCHttpClient http = new OCHttpClient(getBaseContext(), _serverURI, _login, _password);
|
||||
GetMethod testMethod = http.getVersion();
|
||||
try {
|
||||
_returnCode = http.execute(testMethod);
|
||||
|
||||
@@ -17,12 +17,15 @@ package fr.unix_experience.owncloud_sms.engine;
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpVersion;
|
||||
import org.apache.commons.httpclient.cookie.CookiePolicy;
|
||||
import org.apache.commons.httpclient.params.HttpClientParams;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
|
||||
@@ -31,12 +34,16 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
||||
|
||||
public class OCHttpClient extends HttpClient {
|
||||
|
||||
private static final String TAG = OCHttpClient.class.getCanonicalName();
|
||||
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
|
||||
private final Uri _serverURI;
|
||||
private final String _username;
|
||||
private final String _password;
|
||||
@@ -53,7 +60,7 @@ public class OCHttpClient extends HttpClient {
|
||||
private static final String OC_V2_GET_MESSAGES_PHONE ="/index.php/apps/ocsms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json";
|
||||
private static final String OC_V2_GET_MESSAGES_SENDQUEUE = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json";
|
||||
|
||||
public OCHttpClient(Uri serverURI, String accountName, String accountPassword) {
|
||||
public OCHttpClient(Context context, Uri serverURI, String accountName, String accountPassword) {
|
||||
super(new MultiThreadedHttpConnectionManager());
|
||||
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
|
||||
Protocol.registerProtocol("https", easyhttps);
|
||||
@@ -61,6 +68,10 @@ public class OCHttpClient extends HttpClient {
|
||||
_username = accountName;
|
||||
_password = accountPassword;
|
||||
getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
||||
getParams().setParameter(PARAM_PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
|
||||
getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
|
||||
getParams().setParameter(HttpMethodParams.USER_AGENT,
|
||||
"nextcloud-phonesync (" + new AndroidVersionProvider(context).getVersionCode() + ")");
|
||||
}
|
||||
|
||||
private GetMethod get(String oc_call) {
|
||||
|
||||
@@ -56,7 +56,8 @@ public class OCSMSOwnCloudClient {
|
||||
}
|
||||
|
||||
Uri serverURI = Uri.parse(ocURI);
|
||||
_http = new OCHttpClient(serverURI, accountManager.getUserData(account, "ocLogin"),
|
||||
_http = new OCHttpClient(context,
|
||||
serverURI, accountManager.getUserData(account, "ocLogin"),
|
||||
accountManager.getPassword(account));
|
||||
_connectivityMonitor = new ConnectivityMonitor(_context);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package fr.unix_experience.owncloud_sms.providers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Loic Blot <loic.blot@unix-experience.fr>
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
public class AndroidVersionProvider {
|
||||
private Context _context;
|
||||
|
||||
public AndroidVersionProvider(Context context) {
|
||||
assert (context != null);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public String getVersionCode() {
|
||||
try {
|
||||
return _context.getPackageManager().
|
||||
getPackageInfo(_context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return "unknown version";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user