Commit 629e17bb authored by Alexander Ivanov's avatar Alexander Ivanov

Add orbot proxy support. Close #230.

parent 5296a9a3
......@@ -109,6 +109,7 @@
<string name="account_proxy_type_http">HTTP</string>
<string name="account_proxy_type_socks4">SOCKS4</string>
<string name="account_proxy_type_socks5">SOCKS5</string>
<string name="account_proxy_type_orbot">Orbot</string>
<string name="account_proxy_host">Proxy host</string>
<string name="account_proxy_port">Proxy port</string>
<string name="account_proxy_user">Proxy user</string>
......
......@@ -414,12 +414,14 @@
<item>@string/account_proxy_type_http</item>
<item>@string/account_proxy_type_socks4</item>
<item>@string/account_proxy_type_socks5</item>
<item>@string/account_proxy_type_orbot</item>
</string-array>
<string-array name="account_proxy_type_entryvalues">
<item>@string/account_proxy_type_none</item>
<item>@string/account_proxy_type_http</item>
<item>@string/account_proxy_type_socks4</item>
<item>@string/account_proxy_type_socks5</item>
<item>@string/account_proxy_type_orbot</item>
</string-array>
<string-array name="account_archive_mode_entries">
......
......@@ -19,13 +19,13 @@ import java.util.Date;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.connection.ConnectionItem;
import com.xabber.android.data.connection.ConnectionState;
import com.xabber.android.data.connection.ConnectionThread;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.androiddev.R;
......
......@@ -24,7 +24,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import org.jivesoftware.smack.util.StringUtils;
import android.content.res.TypedArray;
......@@ -36,6 +35,7 @@ import com.xabber.android.data.OnLoadListener;
import com.xabber.android.data.OnWipeListener;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.connection.ConnectionState;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.android.data.extension.vcard.VCardManager;
import com.xabber.android.data.notification.BaseAccountNotificationProvider;
......@@ -446,7 +446,7 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
getNextColorIndex(), 0, StatusMode.available,
SettingsManager.statusText(), true, true,
tlsRequired ? TLSMode.required : TLSMode.enabled, false,
ProxyType.NONE, "localhost", 8080, "", "", syncable, null,
ProxyType.none, "localhost", 8080, "", "", syncable, null,
null, ArchiveMode.available);
onAccountChanged(accountItem.getAccount());
if (accountItems.size() > 1
......
......@@ -24,8 +24,6 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Date;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import android.content.ContentValues;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
......@@ -36,6 +34,7 @@ import android.provider.BaseColumns;
import com.xabber.android.data.AbstractTable;
import com.xabber.android.data.Application;
import com.xabber.android.data.DatabaseManager;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.androiddev.R;
......@@ -289,7 +288,7 @@ class AccountTable extends AbstractTable {
sql = "ALTER TABLE accounts ADD COLUMN proxy_password TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE accounts SET proxy_type = "
+ ProxyType.NONE.ordinal() + ", "
+ ProxyType.none.ordinal() + ", "
+ "proxy_host = \"localhost\", " + "proxy_port = 8080, "
+ "proxy_user = \"\", " + "proxy_password = \"\" "
+ "WHERE proxy_type IS NULL;";
......
......@@ -15,7 +15,6 @@
package com.xabber.android.data.connection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
......
......@@ -14,8 +14,6 @@
*/
package com.xabber.android.data.connection;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import com.xabber.android.data.account.AccountProtocol;
/**
......
......@@ -31,7 +31,6 @@ import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import org.xbill.DNS.Record;
import com.xabber.android.data.Application;
......@@ -279,7 +278,7 @@ public class ConnectionThread implements
*/
private void onReady(final InetAddress address, final int port) {
LogManager.i(this, "Use " + address);
ProxyInfo proxy = new ProxyInfo(proxyType, proxyHost, proxyPort,
ProxyInfo proxy = proxyType.getProxyInfo(proxyHost, proxyPort,
proxyUser, proxyPassword);
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(
address.getHostAddress(), port, serverName, proxy);
......
package com.xabber.android.data.connection;
import org.jivesoftware.smack.proxy.ProxyInfo;
public enum ProxyType {
none,
http,
socks4,
socks5,
orbot;
public ProxyInfo getProxyInfo(String proxyHost, int proxyPort,
String proxyUser, String proxyPassword) {
ProxyInfo.ProxyType proxyType;
if (this == none)
proxyType = ProxyInfo.ProxyType.NONE;
else if (this == http)
proxyType = ProxyInfo.ProxyType.HTTP;
else if (this == socks4)
proxyType = ProxyInfo.ProxyType.SOCKS4;
else if (this == socks5)
proxyType = ProxyInfo.ProxyType.SOCKS5;
else if (this == orbot) {
proxyType = ProxyInfo.ProxyType.SOCKS5;
proxyHost = "localhost";
proxyPort = 9050;
proxyUser = "";
proxyPassword = "";
} else
throw new IllegalStateException();
return new ProxyInfo(proxyType, proxyHost, proxyPort, proxyUser,
proxyPassword);
}
}
......@@ -17,8 +17,7 @@ package com.xabber.android.ui;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -31,6 +30,7 @@ import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountProtocol;
import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.helper.BaseSettingsActivity;
......@@ -145,7 +145,9 @@ public class AccountEditor extends BaseSettingsActivity implements
if (getString(R.string.account_proxy_type_key).equals(
preference.getKey())) {
boolean enabled = !getString(R.string.account_proxy_type_none)
.equals(newValue);
.equals(newValue)
&& !getString(R.string.account_proxy_type_orbot).equals(
newValue);
for (int id : new Integer[] { R.string.account_proxy_host_key,
R.string.account_proxy_port_key,
R.string.account_proxy_user_key,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment