Commit 4efe2dbe authored by Alexander Ivanov's avatar Alexander Ivanov

Proxy settings. Close #30.

parent 4f5bd1c3
...@@ -104,6 +104,15 @@ ...@@ -104,6 +104,15 @@
<string name="account_protocol_wlm_title">WLM</string> <string name="account_protocol_wlm_title">WLM</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_01.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_01.png -->
<string name="account_protocol_xmpp_title">XMPP</string> <string name="account_protocol_xmpp_title">XMPP</string>
<string name="account_proxy_type">Proxy type</string>
<string name="account_proxy_type_none">Disabled</string>
<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_host">Proxy host</string>
<string name="account_proxy_port">Proxy port</string>
<string name="account_proxy_user">Proxy user</string>
<string name="account_proxy_password">Proxy password</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
<string name="account_sasl">Use SASL Authentication (recommended)</string> <string name="account_sasl">Use SASL Authentication (recommended)</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_02.png -->
......
...@@ -390,6 +390,11 @@ ...@@ -390,6 +390,11 @@
<string name="account_sasl_key">account_sasl</string> <string name="account_sasl_key">account_sasl</string>
<string name="account_tls_mode_key">account_tls_mode</string> <string name="account_tls_mode_key">account_tls_mode</string>
<string name="account_compression_key">account_compression</string> <string name="account_compression_key">account_compression</string>
<string name="account_proxy_type_key">account_proxy_type</string>
<string name="account_proxy_host_key">account_proxy_host</string>
<string name="account_proxy_port_key">account_proxy_port</string>
<string name="account_proxy_user_key">account_proxy_user</string>
<string name="account_proxy_password_key">account_proxy_password</string>
<string name="account_custom_key">account_custom</string> <string name="account_custom_key">account_custom</string>
<string name="account_archive_mode_key">account_archive_mode</string> <string name="account_archive_mode_key">account_archive_mode</string>
...@@ -404,6 +409,19 @@ ...@@ -404,6 +409,19 @@
<item>@string/account_tls_legacy_summary</item> <item>@string/account_tls_legacy_summary</item>
</string-array> </string-array>
<string-array name="account_proxy_type_entries">
<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>
</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>
</string-array>
<string-array name="account_archive_mode_entries"> <string-array name="account_archive_mode_entries">
<item>@string/account_archive_mode_server</item> <item>@string/account_archive_mode_server</item>
<item>@string/account_archive_mode_available</item> <item>@string/account_archive_mode_available</item>
......
...@@ -41,6 +41,33 @@ ...@@ -41,6 +41,33 @@
android:dialogTitle="@string/account_priority" android:dialogTitle="@string/account_priority"
android:singleLine="true" android:singleLine="true"
/> />
<ListPreference
android:title="@string/account_proxy_type"
android:key="@string/account_proxy_type_key"
android:entries="@array/account_proxy_type_entries"
android:entryValues="@array/account_proxy_type_entryvalues"
/>
<EditTextPreference
android:key="@string/account_proxy_host_key"
android:title="@string/account_proxy_host"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_port_key"
android:title="@string/account_proxy_port"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_user_key"
android:title="@string/account_proxy_user"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_password_key"
android:title="@string/account_proxy_password"
android:password="true"
android:singleLine="true"
/>
<ListPreference <ListPreference
android:title="@string/account_archive_mode" android:title="@string/account_archive_mode"
android:key="@string/account_archive_mode_key" android:key="@string/account_archive_mode_key"
......
...@@ -95,6 +95,33 @@ ...@@ -95,6 +95,33 @@
android:summary="@string/account_compression_summary" android:summary="@string/account_compression_summary"
android:key="@string/account_compression_key" android:key="@string/account_compression_key"
/> />
<ListPreference
android:title="@string/account_proxy_type"
android:key="@string/account_proxy_type_key"
android:entries="@array/account_proxy_type_entries"
android:entryValues="@array/account_proxy_type_entryvalues"
/>
<EditTextPreference
android:key="@string/account_proxy_host_key"
android:title="@string/account_proxy_host"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_port_key"
android:title="@string/account_proxy_port"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_user_key"
android:title="@string/account_proxy_user"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_proxy_password_key"
android:title="@string/account_proxy_password"
android:password="true"
android:singleLine="true"
/>
<ListPreference <ListPreference
android:title="@string/account_archive_mode" android:title="@string/account_archive_mode"
android:key="@string/account_archive_mode_key" android:key="@string/account_archive_mode_key"
......
...@@ -38,7 +38,7 @@ public class DatabaseManager extends SQLiteOpenHelper implements ...@@ -38,7 +38,7 @@ public class DatabaseManager extends SQLiteOpenHelper implements
OnLoadListener, OnClearListener { OnLoadListener, OnClearListener {
private static final String DATABASE_NAME = "xabber.db"; private static final String DATABASE_NAME = "xabber.db";
private static final int DATABASE_VERSION = 65; private static final int DATABASE_VERSION = 66;
private static final SQLiteException DOWNGRAD_EXCEPTION = new SQLiteException( private static final SQLiteException DOWNGRAD_EXCEPTION = new SQLiteException(
"Database file was deleted"); "Database file was deleted");
......
...@@ -19,6 +19,7 @@ import java.util.Date; ...@@ -19,6 +19,7 @@ import java.util.Date;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type; 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.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
...@@ -106,10 +107,13 @@ public class AccountItem extends ConnectionItem { ...@@ -106,10 +107,13 @@ public class AccountItem extends ConnectionItem {
boolean storePassword, String password, int colorIndex, boolean storePassword, String password, int colorIndex,
int priority, StatusMode statusMode, String statusText, int priority, StatusMode statusMode, String statusText,
boolean enabled, boolean saslEnabled, TLSMode tlsMode, boolean enabled, boolean saslEnabled, TLSMode tlsMode,
boolean compression, boolean syncable, KeyPair keyPair, boolean compression, ProxyType proxyType, String proxyHost,
Date lastSync, ArchiveMode archiveMode) { int proxyPort, String proxyUser, String proxyPassword,
boolean syncable, KeyPair keyPair, Date lastSync,
ArchiveMode archiveMode) {
super(protocol, custom, host, port, serverName, userName, resource, super(protocol, custom, host, port, serverName, userName, resource,
storePassword, password, saslEnabled, tlsMode, compression); storePassword, password, saslEnabled, tlsMode, compression,
proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
this.id = null; this.id = null;
this.account = userName + "@" + serverName + "/" + resource; this.account = userName + "@" + serverName + "/" + resource;
this.colorIndex = colorIndex; this.colorIndex = colorIndex;
...@@ -334,9 +338,11 @@ public class AccountItem extends ConnectionItem { ...@@ -334,9 +338,11 @@ public class AccountItem extends ConnectionItem {
*/ */
void updateConnectionSettings(boolean custom, String host, int port, void updateConnectionSettings(boolean custom, String host, int port,
String password, boolean saslEnabled, TLSMode tlsMode, String password, boolean saslEnabled, TLSMode tlsMode,
boolean compression) { boolean compression, ProxyType proxyType, String proxyHost,
int proxyPort, String proxyUser, String proxyPassword) {
getConnectionSettings().update(custom, host, port, password, getConnectionSettings().update(custom, host, port, password,
saslEnabled, tlsMode, compression); saslEnabled, tlsMode, compression, proxyType, proxyHost,
proxyPort, proxyUser, proxyPassword);
passwordRequested = false; passwordRequested = false;
AccountManager.getInstance().removePasswordRequest(account); AccountManager.getInstance().removePasswordRequest(account);
} }
......
...@@ -24,6 +24,7 @@ import java.util.HashSet; ...@@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import android.content.res.TypedArray; import android.content.res.TypedArray;
...@@ -192,6 +193,11 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -192,6 +193,11 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
AccountTable.isSaslEnabled(cursor), AccountTable.isSaslEnabled(cursor),
AccountTable.getTLSMode(cursor), AccountTable.getTLSMode(cursor),
AccountTable.isCompression(cursor), AccountTable.isCompression(cursor),
AccountTable.getProxyType(cursor),
AccountTable.getProxyHost(cursor),
AccountTable.getProxyPort(cursor),
AccountTable.getProxyUser(cursor),
AccountTable.getProxyPassword(cursor),
AccountTable.isSyncable(cursor), AccountTable.isSyncable(cursor),
AccountTable.getKeyPair(cursor), AccountTable.getKeyPair(cursor),
AccountTable.getLastSync(cursor), AccountTable.getLastSync(cursor),
...@@ -300,6 +306,16 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -300,6 +306,16 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
.getTlsMode(); .getTlsMode();
final boolean compression = accountItem.getConnectionSettings() final boolean compression = accountItem.getConnectionSettings()
.useCompression(); .useCompression();
final ProxyType proxyType = accountItem.getConnectionSettings()
.getProxyType();
final String proxyHost = accountItem.getConnectionSettings()
.getProxyHost();
final int proxyPort = accountItem.getConnectionSettings()
.getProxyPort();
final String proxyUser = accountItem.getConnectionSettings()
.getProxyUser();
final String proxyPassword = accountItem.getConnectionSettings()
.getProxyPassword();
final boolean syncable = accountItem.isSyncable(); final boolean syncable = accountItem.isSyncable();
final KeyPair keyPair = accountItem.getKeyPair(); final KeyPair keyPair = accountItem.getKeyPair();
final Date lastSync = accountItem.getLastSync(); final Date lastSync = accountItem.getLastSync();
...@@ -311,8 +327,9 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -311,8 +327,9 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
accountItem.getId(), protocol, custom, host, port, accountItem.getId(), protocol, custom, host, port,
serverName, userName, resource, storePassword, serverName, userName, resource, storePassword,
password, colorIndex, priority, statusMode, statusText, password, colorIndex, priority, statusMode, statusText,
enabled, saslEnabled, tlsMode, compression, syncable, enabled, saslEnabled, tlsMode, compression, proxyType,
keyPair, lastSync, archiveMode)); proxyHost, proxyPort, proxyUser, proxyPassword,
syncable, keyPair, lastSync, archiveMode));
} }
}); });
} }
...@@ -325,12 +342,16 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -325,12 +342,16 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
boolean storePassword, String password, String resource, int color, boolean storePassword, String password, String resource, int color,
int priority, StatusMode statusMode, String statusText, int priority, StatusMode statusMode, String statusText,
boolean enabled, boolean saslEnabled, TLSMode tlsMode, boolean enabled, boolean saslEnabled, TLSMode tlsMode,
boolean compression, boolean syncable, KeyPair keyPair, boolean compression, ProxyType proxyType, String proxyHost,
Date lastSync, ArchiveMode archiveMode) { int proxyPort, String proxyUser, String proxyPassword,
boolean syncable, KeyPair keyPair, Date lastSync,
ArchiveMode archiveMode) {
AccountItem accountItem = new AccountItem(protocol, custom, host, port, AccountItem accountItem = new AccountItem(protocol, custom, host, port,
serverName, userName, resource, storePassword, password, color, serverName, userName, resource, storePassword, password, color,
priority, statusMode, statusText, enabled, saslEnabled, priority, statusMode, statusText, enabled, saslEnabled,
tlsMode, compression, syncable, keyPair, lastSync, archiveMode); tlsMode, compression, proxyType, proxyHost, proxyPort,
proxyUser, proxyPassword, syncable, keyPair, lastSync,
archiveMode);
requestToWriteAccount(accountItem); requestToWriteAccount(accountItem);
addAccount(accountItem); addAccount(accountItem);
accountItem.updateConnection(true); accountItem.updateConnection(true);
...@@ -425,7 +446,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -425,7 +446,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
getNextColorIndex(), 0, StatusMode.available, getNextColorIndex(), 0, StatusMode.available,
SettingsManager.statusText(), true, true, SettingsManager.statusText(), true, true,
tlsRequired ? TLSMode.required : TLSMode.enabled, false, tlsRequired ? TLSMode.required : TLSMode.enabled, false,
syncable, null, null, ArchiveMode.available); ProxyType.NONE, "localhost", 8080, "", "", syncable, null,
null, ArchiveMode.available);
onAccountChanged(accountItem.getAccount()); onAccountChanged(accountItem.getAccount());
if (accountItems.size() > 1 if (accountItems.size() > 1
&& SettingsManager.contactsEnableShowAccounts()) && SettingsManager.contactsEnableShowAccounts())
...@@ -500,8 +522,9 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -500,8 +522,9 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
int port, String serverName, String userName, int port, String serverName, String userName,
boolean storePassword, String password, String resource, boolean storePassword, String password, String resource,
int priority, boolean enabled, boolean saslEnabled, int priority, boolean enabled, boolean saslEnabled,
TLSMode tlsMode, boolean compression, boolean syncable, TLSMode tlsMode, boolean compression, ProxyType proxyType,
ArchiveMode archiveMode) { String proxyHost, int proxyPort, String proxyUser,
String proxyPassword, boolean syncable, ArchiveMode archiveMode) {
AccountItem result; AccountItem result;
AccountItem accountItem = getAccount(account); AccountItem accountItem = getAccount(account);
if (accountItem.getConnectionSettings().getServerName() if (accountItem.getConnectionSettings().getServerName()
...@@ -520,9 +543,18 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -520,9 +543,18 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
.equals(password) .equals(password)
|| accountItem.getConnectionSettings().getTlsMode() != tlsMode || accountItem.getConnectionSettings().getTlsMode() != tlsMode
|| accountItem.getConnectionSettings().isSaslEnabled() != saslEnabled || accountItem.getConnectionSettings().isSaslEnabled() != saslEnabled
|| accountItem.getConnectionSettings().useCompression() != compression) { || accountItem.getConnectionSettings().useCompression() != compression
|| accountItem.getConnectionSettings().getProxyType() != proxyType
|| !accountItem.getConnectionSettings().getProxyHost()
.equals(proxyHost)
|| accountItem.getConnectionSettings().getProxyPort() != proxyPort
|| !accountItem.getConnectionSettings().getProxyUser()
.equals(proxyUser)
|| !accountItem.getConnectionSettings().getProxyPassword()
.equals(proxyPassword)) {
result.updateConnectionSettings(custom, host, port, password, result.updateConnectionSettings(custom, host, port, password,
saslEnabled, tlsMode, compression); saslEnabled, tlsMode, compression, proxyType,
proxyHost, proxyPort, proxyUser, proxyPassword);
reconnect = true; reconnect = true;
} }
if (result.isSyncable() != syncable) { if (result.isSyncable() != syncable) {
...@@ -577,7 +609,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -577,7 +609,8 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
result = addAccount(protocol, custom, host, port, serverName, result = addAccount(protocol, custom, host, port, serverName,
userName, storePassword, password, resource, colorIndex, userName, storePassword, password, resource, colorIndex,
priority, statusMode, statusText, enabled, saslEnabled, priority, statusMode, statusText, enabled, saslEnabled,
tlsMode, compression, syncable, keyPair, lastSync, tlsMode, compression, proxyType, proxyHost, proxyPort,
proxyUser, proxyPassword, syncable, keyPair, lastSync,
archiveMode); archiveMode);
} }
onAccountChanged(result.getAccount()); onAccountChanged(result.getAccount());
...@@ -608,7 +641,12 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -608,7 +641,12 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
accountItem.getPriority(), accountItem.isEnabled(), accountItem accountItem.getPriority(), accountItem.isEnabled(), accountItem
.getConnectionSettings().isSaslEnabled(), accountItem .getConnectionSettings().isSaslEnabled(), accountItem
.getConnectionSettings().getTlsMode(), accountItem .getConnectionSettings().getTlsMode(), accountItem
.getConnectionSettings().useCompression(), syncable, .getConnectionSettings().useCompression(), accountItem
.getConnectionSettings().getProxyType(), accountItem
.getConnectionSettings().getProxyHost(), accountItem
.getConnectionSettings().getProxyPort(), accountItem
.getConnectionSettings().getProxyUser(), accountItem
.getConnectionSettings().getProxyPassword(), syncable,
accountItem.getArchiveMode()); accountItem.getArchiveMode());
} }
...@@ -624,7 +662,12 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -624,7 +662,12 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
accountItem.getPriority(), accountItem.isEnabled(), accountItem accountItem.getPriority(), accountItem.isEnabled(), accountItem
.getConnectionSettings().isSaslEnabled(), accountItem .getConnectionSettings().isSaslEnabled(), accountItem
.getConnectionSettings().getTlsMode(), accountItem .getConnectionSettings().getTlsMode(), accountItem
.getConnectionSettings().useCompression(), .getConnectionSettings().useCompression(), accountItem
.getConnectionSettings().getProxyType(), accountItem
.getConnectionSettings().getProxyHost(), accountItem
.getConnectionSettings().getProxyPort(), accountItem
.getConnectionSettings().getProxyUser(), accountItem
.getConnectionSettings().getProxyPassword(),
accountItem.isSyncable(), accountItem.getArchiveMode()); accountItem.isSyncable(), accountItem.getArchiveMode());
} }
...@@ -644,6 +687,11 @@ public class AccountManager implements OnLoadListener, OnWipeListener { ...@@ -644,6 +687,11 @@ public class AccountManager implements OnLoadListener, OnWipeListener {
accountItem.getConnectionSettings().isSaslEnabled(), accountItem.getConnectionSettings().isSaslEnabled(),
accountItem.getConnectionSettings().getTlsMode(), accountItem.getConnectionSettings().getTlsMode(),
accountItem.getConnectionSettings().useCompression(), accountItem.getConnectionSettings().useCompression(),
accountItem.getConnectionSettings().getProxyType(),
accountItem.getConnectionSettings().getProxyHost(),
accountItem.getConnectionSettings().getProxyPort(),
accountItem.getConnectionSettings().getProxyUser(),
accountItem.getConnectionSettings().getProxyPassword(),
accountItem.isSyncable(), archiveMode); accountItem.isSyncable(), archiveMode);
} }
......
...@@ -24,6 +24,8 @@ import java.security.spec.PKCS8EncodedKeySpec; ...@@ -24,6 +24,8 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.util.Date; import java.util.Date;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.database.Cursor; import android.database.Cursor;
...@@ -70,6 +72,11 @@ class AccountTable extends AbstractTable { ...@@ -70,6 +72,11 @@ class AccountTable extends AbstractTable {
public static final String PRIVATE_KEY = "private_key"; public static final String PRIVATE_KEY = "private_key";
public static final String LAST_SYNC = "last_sync"; public static final String LAST_SYNC = "last_sync";
public static final String ARCHIVE_MODE = "archive_mode"; public static final String ARCHIVE_MODE = "archive_mode";
public static final String PROXY_TYPE = "proxy_type";
public static final String PROXY_HOST = "proxy_host";
public static final String PROXY_PORT = "proxy_port";
public static final String PROXY_USER = "proxy_user";
public static final String PROXY_PASSWORD = "proxy_password";
} }
private static final String NAME = "accounts"; private static final String NAME = "accounts";
...@@ -80,7 +87,9 @@ class AccountTable extends AbstractTable { ...@@ -80,7 +87,9 @@ class AccountTable extends AbstractTable {
Fields.STATUS_MODE, Fields.STATUS_TEXT, Fields.ENABLED, Fields.STATUS_MODE, Fields.STATUS_TEXT, Fields.ENABLED,
Fields.SASL_ENABLED, Fields.TLS_MODE, Fields.COMPRESSION, Fields.SASL_ENABLED, Fields.TLS_MODE, Fields.COMPRESSION,
Fields.SYNCABLE, Fields.STORE_PASSWORD, Fields.PUBLIC_KEY, Fields.SYNCABLE, Fields.STORE_PASSWORD, Fields.PUBLIC_KEY,
Fields.PRIVATE_KEY, Fields.LAST_SYNC, Fields.ARCHIVE_MODE }; Fields.PRIVATE_KEY, Fields.LAST_SYNC, Fields.ARCHIVE_MODE,
Fields.PROXY_TYPE, Fields.PROXY_HOST, Fields.PROXY_PORT,
Fields.PROXY_USER, Fields.PROXY_PASSWORD };
private final DatabaseManager databaseManager; private final DatabaseManager databaseManager;
...@@ -114,7 +123,11 @@ class AccountTable extends AbstractTable { ...@@ -114,7 +123,11 @@ class AccountTable extends AbstractTable {
+ " INTEGER," + Fields.SYNCABLE + " INTEGER," + " INTEGER," + Fields.SYNCABLE + " INTEGER,"
+ Fields.STORE_PASSWORD + " INTEGER," + Fields.PUBLIC_KEY + Fields.STORE_PASSWORD + " INTEGER," + Fields.PUBLIC_KEY
+ " BLOB," + Fields.PRIVATE_KEY + " BLOB," + Fields.LAST_SYNC + " BLOB," + Fields.PRIVATE_KEY + " BLOB," + Fields.LAST_SYNC
+ " INTEGER," + Fields.ARCHIVE_MODE + " INTEGER);"; + " INTEGER," + Fields.ARCHIVE_MODE + " INTEGER,"
+ Fields.PROXY_TYPE + " INTEGER," + Fields.PROXY_HOST
+ " TEXT," + Fields.PROXY_PORT + " INTEGER,"
+ Fields.PROXY_USER + " TEXT," + Fields.PROXY_PASSWORD
+ " TEXT);";
DatabaseManager.execSQL(db, sql); DatabaseManager.execSQL(db, sql);
} }
...@@ -264,6 +277,24 @@ class AccountTable extends AbstractTable { ...@@ -264,6 +277,24 @@ class AccountTable extends AbstractTable {
+ ";"; + ";";
DatabaseManager.execSQL(db, sql); DatabaseManager.execSQL(db, sql);
break; break;
case 66:
sql = "ALTER TABLE accounts ADD COLUMN proxy_type INTEGER;";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE accounts ADD COLUMN proxy_host TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE accounts ADD COLUMN proxy_port INTEGER;";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE accounts ADD COLUMN proxy_user TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE accounts ADD COLUMN proxy_password TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE accounts SET proxy_type = "
+ ProxyType.NONE.ordinal() + ", "
+ "proxy_host = \"localhost\", " + "proxy_port = 8080, "
+ "proxy_user = \"\", " + "proxy_password = \"\" "
+ "WHERE proxy_type IS NULL;";
DatabaseManager.execSQL(db, sql);
break;
default: default:
break; break;
} }
...@@ -272,28 +303,6 @@ class AccountTable extends AbstractTable { ...@@ -272,28 +303,6 @@ class AccountTable extends AbstractTable {
/** /**
* Adds or updates account. * Adds or updates account.
* *
* @param id
* @param protocol
* @param custom
* @param host
* @param port
* @param serverName
* @param userName
* @param resource
* @param storePassword
* @param password
* @param colorIndex
* @param priority
* @param statusMode
* @param statusText
* @param enabled
* @param saslEnabled
* @param tlsMode
* @param compression
* @param syncable
* @param keyPair
* @param lastSync
* @param archiveMode
* @return Assigned id. * @return Assigned id.
*/ */
long write(Long id, AccountProtocol protocol, boolean custom, String host, long write(Long id, AccountProtocol protocol, boolean custom, String host,
...@@ -301,8 +310,10 @@ class AccountTable extends AbstractTable { ...@@ -301,8 +310,10 @@ class AccountTable extends AbstractTable {
boolean storePassword, String password, int colorIndex, boolean storePassword, String password, int colorIndex,
int priority, StatusMode statusMode, String statusText, int priority, StatusMode statusMode, String statusText,
boolean enabled, boolean saslEnabled, TLSMode tlsMode, boolean enabled, boolean saslEnabled, TLSMode tlsMode,
boolean compression, boolean syncable, KeyPair keyPair, boolean compression, ProxyType proxyType, String proxyHost,
Date lastSync, ArchiveMode archiveMode) { int proxyPort, String proxyUser, String proxyPassword,
boolean syncable, KeyPair keyPair, Date lastSync,
ArchiveMode archiveMode) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Fields.PROTOCOL, protocol.name()); values.put(Fields.PROTOCOL, protocol.name());
values.put(Fields.CUSTOM, custom ? 1 : 0); values.put(Fields.CUSTOM, custom ? 1 : 0);
...@@ -322,6 +333,11 @@ class AccountTable extends AbstractTable { ...@@ -322,6 +333,11 @@ class AccountTable extends AbstractTable {
values.put(Fields.SASL_ENABLED, saslEnabled ? 1 : 0); values.put(Fields.SASL_ENABLED, saslEnabled ? 1 : 0);
values.put(Fields.TLS_MODE, tlsMode.ordinal()); values.put(Fields.TLS_MODE, tlsMode.ordinal());
values.put(Fields.COMPRESSION, compression ? 1 : 0); values.put(Fields.COMPRESSION, compression ? 1 : 0);
values.put(Fields.PROXY_TYPE, proxyType.ordinal());
values.put(Fields.PROXY_HOST, proxyHost);
values.put(Fields.PROXY_PORT, proxyPort);
values.put(Fields.PROXY_USER, proxyUser);
values.put(Fields.PROXY_PASSWORD, proxyPassword);
values.put(Fields.SYNCABLE, syncable ? 1 : 0); values.put(Fields.SYNCABLE, syncable ? 1 : 0);
values.put(Fields.STORE_PASSWORD, storePassword ? 1 : 0); values.put(Fields.STORE_PASSWORD, storePassword ? 1 : 0);
if (keyPair == null) { if (keyPair == null) {
...@@ -480,6 +496,27 @@ class AccountTable extends AbstractTable { ...@@ -480,6 +496,27 @@ class AccountTable extends AbstractTable {
return ArchiveMode.values()[index]; return ArchiveMode.values()[index];
} }
static ProxyType getProxyType(Cursor cursor) {
int index = cursor.getInt(cursor.getColumnIndex(Fields.PROXY_TYPE));
return ProxyType.values()[index];
}
static String getProxyHost(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.PROXY_HOST));
}
static int getProxyPort(Cursor cursor) {
return cursor.getInt(cursor.getColumnIndex(Fields.PROXY_PORT));
}
static String getProxyUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.PROXY_USER));
}
static String getProxyPassword(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.PROXY_PASSWORD));
}
static KeyPair getKeyPair(Cursor cursor) { static KeyPair getKeyPair(Cursor cursor) {
byte[] publicKeyBytes = cursor.getBlob(cursor byte[] publicKeyBytes = cursor.getBlob(cursor
.getColumnIndex(Fields.PUBLIC_KEY)); .getColumnIndex(Fields.PUBLIC_KEY));
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
package com.xabber.android.data.connection; package com.xabber.android.data.connection;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
...@@ -57,10 +58,13 @@ public abstract class ConnectionItem { ...@@ -57,10 +58,13 @@ public abstract class ConnectionItem {
public ConnectionItem(AccountProtocol protocol, boolean custom, public ConnectionItem(AccountProtocol protocol, boolean custom,
String host, int port, String serverName, String userName, String host, int port, String serverName, String userName,
String resource, boolean storePassword, String password, String resource, boolean storePassword, String password,
boolean saslEnabled, TLSMode tlsMode, boolean compression) { boolean saslEnabled, TLSMode tlsMode, boolean compression,
ProxyType proxyType, String proxyHost, int proxyPort,
String proxyUser, String proxyPassword) {
connectionSettings = new ConnectionSettings(protocol, userName, connectionSettings = new ConnectionSettings(protocol, userName,
serverName, resource, custom, host, port, password, serverName, resource, custom, host, port, password,
saslEnabled, tlsMode, compression); saslEnabled, tlsMode, compression, proxyType, proxyHost,
proxyPort, proxyUser, proxyPassword);
connectionRequest = false; connectionRequest = false;
disconnectionRequested = false; disconnectionRequested = false;
connectionThread = null; connectionThread = null;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
*/ */
package com.xabber.android.data.connection; package com.xabber.android.data.connection;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import com.xabber.android.data.account.AccountProtocol; import com.xabber.android.data.account.AccountProtocol;
/** /**
...@@ -79,10 +81,21 @@ public class ConnectionSettings { ...@@ -79,10 +81,21 @@ public class ConnectionSettings {
*/ */
private boolean compression; private boolean compression;
private ProxyType proxyType;
private String proxyHost;
private int proxyPort;
private String proxyUser;
private String proxyPassword;
public ConnectionSettings(AccountProtocol protocol, String userName, public ConnectionSettings(AccountProtocol protocol, String userName,
String serverName, String resource, boolean custom, String host, String serverName, String resource, boolean custom, String host,
int port, String password, boolean saslEnabled, TLSMode tlsMode, int port, String password, boolean saslEnabled, TLSMode tlsMode,
boolean compression) { boolean compression, ProxyType proxyType, String proxyHost,
int proxyPort, String proxyUser, String proxyPassword) {
super(); super();
this.protocol = protocol; this.protocol = protocol;
this.userName = userName; this.userName = userName;
...@@ -95,6 +108,11 @@ public class ConnectionSettings { ...@@ -95,6 +108,11 @@ public class ConnectionSettings {
this.saslEnabled = saslEnabled; this.saslEnabled = saslEnabled;
this.tlsMode = tlsMode; this.tlsMode = tlsMode;
this.compression = compression; this.compression = compression;
this.proxyType = proxyType;
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.proxyUser = proxyUser;
this.proxyPassword = proxyPassword;
} }
public AccountProtocol getProtocol() { public AccountProtocol getProtocol() {
...@@ -162,6 +180,26 @@ public class ConnectionSettings { ...@@ -162,6 +180,26 @@ public class ConnectionSettings {
return compression; return compression;
} }
public ProxyType getProxyType() {
return proxyType;
}
public String getProxyHost() {
return proxyHost;
}
public int getProxyPort() {
return proxyPort;
}
public String getProxyUser() {
return proxyUser;
}
public String getProxyPassword() {
return proxyPassword;
}
/** /**
* Updates options. * Updates options.
* *
...@@ -174,7 +212,9 @@ public class ConnectionSettings { ...@@ -174,7 +212,9 @@ public class ConnectionSettings {
* @param compression * @param compression
*/ */
public void update(boolean custom, String host, int port, String password, public void update(boolean custom, String host, int port, String password,
boolean saslEnabled, TLSMode tlsMode, boolean compression) { boolean saslEnabled, TLSMode tlsMode, boolean compression,
ProxyType proxyType, String proxyHost, int proxyPort,
String proxyUser, String proxyPassword) {
this.custom = custom; this.custom = custom;
this.host = host; this.host = host;
this.port = port; this.port = port;
...@@ -182,6 +222,11 @@ public class ConnectionSettings { ...@@ -182,6 +222,11 @@ public class ConnectionSettings {
this.saslEnabled = saslEnabled; this.saslEnabled = saslEnabled;
this.tlsMode = tlsMode; this.tlsMode = tlsMode;
this.compression = compression; this.compression = compression;
this.proxyType = proxyType;
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.proxyUser = proxyUser;
this.proxyPassword = proxyPassword;
} }
/** /**
......
...@@ -30,6 +30,8 @@ import org.jivesoftware.smack.XMPPException; ...@@ -30,6 +30,8 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.StreamError; 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 org.xbill.DNS.Record;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
...@@ -92,6 +94,16 @@ public class ConnectionThread implements ...@@ -92,6 +94,16 @@ public class ConnectionThread implements
private final boolean compression; private final boolean compression;
private final ProxyType proxyType;
private final String proxyHost;
private final int proxyPort;
private final String proxyUser;
private final String proxyPassword;
private boolean started; private boolean started;
public ConnectionThread(final ConnectionItem connectionItem) { public ConnectionThread(final ConnectionItem connectionItem) {
...@@ -125,6 +137,11 @@ public class ConnectionThread implements ...@@ -125,6 +137,11 @@ public class ConnectionThread implements
+ connectionSettings.getServerName(); + connectionSettings.getServerName();
else else
login = connectionSettings.getUserName(); login = connectionSettings.getUserName();
proxyType = connectionSettings.getProxyType();
proxyHost = connectionSettings.getProxyHost();
proxyPort = connectionSettings.getProxyPort();
proxyUser = connectionSettings.getProxyUser();
proxyPassword = connectionSettings.getProxyPassword();
started = false; started = false;
} }
...@@ -262,8 +279,10 @@ public class ConnectionThread implements ...@@ -262,8 +279,10 @@ public class ConnectionThread implements
*/ */
private void onReady(final InetAddress address, final int port) { private void onReady(final InetAddress address, final int port) {
LogManager.i(this, "Use " + address); LogManager.i(this, "Use " + address);
ProxyInfo proxy = new ProxyInfo(proxyType, proxyHost, proxyPort,
proxyUser, proxyPassword);
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration( ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(
address.getHostAddress(), port, serverName); address.getHostAddress(), port, serverName, proxy);
if (Application.SDK_INT >= 14) { if (Application.SDK_INT >= 14) {
connectionConfiguration.setTruststoreType("AndroidCAStore"); connectionConfiguration.setTruststoreType("AndroidCAStore");
connectionConfiguration.setTruststorePassword(null); connectionConfiguration.setTruststorePassword(null);
......
...@@ -17,6 +17,8 @@ package com.xabber.android.ui; ...@@ -17,6 +17,8 @@ package com.xabber.android.ui;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
...@@ -129,13 +131,30 @@ public class AccountEditor extends BaseSettingsActivity implements ...@@ -129,13 +131,30 @@ public class AccountEditor extends BaseSettingsActivity implements
if (getString(R.string.account_tls_mode_key) if (getString(R.string.account_tls_mode_key)
.equals(preference.getKey()) .equals(preference.getKey())
|| getString(R.string.account_archive_mode_key).equals( || getString(R.string.account_archive_mode_key).equals(
preference.getKey())
|| getString(R.string.account_proxy_type_key).equals(
preference.getKey())) preference.getKey()))
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
else if (!getString(R.string.account_password_key).equals( else if (!getString(R.string.account_password_key).equals(
preference.getKey()) preference.getKey())
&& !getString(R.string.account_proxy_password_key).equals(
preference.getKey())
&& !getString(R.string.account_priority_key).equals( && !getString(R.string.account_priority_key).equals(
preference.getKey())) preference.getKey()))
super.onPreferenceChange(preference, newValue); super.onPreferenceChange(preference, newValue);
if (getString(R.string.account_proxy_type_key).equals(
preference.getKey())) {
boolean enabled = !getString(R.string.account_proxy_type_none)
.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,
R.string.account_proxy_password_key, }) {
Preference proxyPreference = findPreference(getString(id));
if (proxyPreference != null)
proxyPreference.setEnabled(enabled);
}
}
return true; return true;
} }
...@@ -190,6 +209,19 @@ public class AccountEditor extends BaseSettingsActivity implements ...@@ -190,6 +209,19 @@ public class AccountEditor extends BaseSettingsActivity implements
.getTlsMode().ordinal())); .getTlsMode().ordinal()));
putValue(source, R.string.account_compression_key, accountItem putValue(source, R.string.account_compression_key, accountItem
.getConnectionSettings().useCompression()); .getConnectionSettings().useCompression());
putValue(
source,
R.string.account_proxy_type_key,
Integer.valueOf(accountItem.getConnectionSettings()
.getProxyType().ordinal()));
putValue(source, R.string.account_proxy_host_key, accountItem
.getConnectionSettings().getProxyHost());
putValue(source, R.string.account_proxy_port_key, accountItem
.getConnectionSettings().getProxyPort());
putValue(source, R.string.account_proxy_user_key, accountItem
.getConnectionSettings().getProxyUser());
putValue(source, R.string.account_proxy_password_key, accountItem
.getConnectionSettings().getProxyPassword());
putValue(source, R.string.account_syncable_key, putValue(source, R.string.account_syncable_key,
accountItem.isSyncable()); accountItem.isSyncable());
putValue(source, R.string.account_archive_mode_key, putValue(source, R.string.account_archive_mode_key,
...@@ -226,6 +258,12 @@ public class AccountEditor extends BaseSettingsActivity implements ...@@ -226,6 +258,12 @@ public class AccountEditor extends BaseSettingsActivity implements
TLSMode.values()[getInt(result, TLSMode.values()[getInt(result,
R.string.account_tls_mode_key)], R.string.account_tls_mode_key)],
getBoolean(result, R.string.account_compression_key), getBoolean(result, R.string.account_compression_key),
ProxyType.values()[getInt(result,
R.string.account_proxy_type_key)],
getString(result, R.string.account_proxy_host_key),
getInt(result, R.string.account_proxy_port_key),
getString(result, R.string.account_proxy_user_key),
getString(result, R.string.account_proxy_password_key),
getBoolean(result, R.string.account_syncable_key), getBoolean(result, R.string.account_syncable_key),
ArchiveMode.values()[getInt(result, ArchiveMode.values()[getInt(result,
R.string.account_archive_mode_key)]); R.string.account_archive_mode_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