Skip to content

Commit 9702fdb

Browse files
author
Grigory Fedorov
committed
prepare proxy info (but not turn on due to Smack issue)
1 parent 8c309b3 commit 9702fdb

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

xabber/src/main/java/com/xabber/android/data/connection/ConnectionBuilder.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.xabber.android.data.SettingsManager;
88

99
import org.jivesoftware.smack.SASLAuthentication;
10+
import org.jivesoftware.smack.proxy.ProxyInfo;
1011
import org.jivesoftware.smack.sasl.provided.SASLPlainMechanism;
1112
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
1213
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
@@ -61,6 +62,48 @@ public class ConnectionBuilder {
6162
return new XMPPTCPConnection(builder.build());
6263
}
6364

65+
private static ProxyInfo getProxyInfo(ConnectionSettings connectionSettings) {
66+
67+
ProxyInfo proxyInfo;
68+
69+
ProxyType proxyType = connectionSettings.getProxyType();
70+
71+
String proxyHost = connectionSettings.getProxyHost();
72+
int proxyPort = connectionSettings.getProxyPort();
73+
String proxyPassword = connectionSettings.getProxyPassword();
74+
String proxyUser = connectionSettings.getProxyUser();
75+
76+
if (proxyType == null) {
77+
proxyInfo = ProxyInfo.forDefaultProxy();
78+
} else {
79+
switch (proxyType) {
80+
case none:
81+
proxyInfo = ProxyInfo.forNoProxy();
82+
break;
83+
case http:
84+
proxyInfo = ProxyInfo.forHttpProxy(proxyHost, proxyPort, proxyUser, proxyPassword);
85+
break;
86+
case socks4:
87+
proxyInfo = ProxyInfo.forSocks4Proxy(proxyHost, proxyPort, proxyUser, proxyPassword);
88+
break;
89+
case socks5:
90+
proxyInfo = ProxyInfo.forSocks5Proxy(proxyHost, proxyPort, proxyUser, proxyPassword);
91+
break;
92+
case orbot:
93+
proxyHost = "localhost";
94+
proxyPort = 9050;
95+
proxyPassword = "";
96+
proxyUser = "";
97+
proxyInfo = ProxyInfo.forSocks5Proxy(proxyHost, proxyPort, proxyUser, proxyPassword);
98+
break;
99+
default:
100+
proxyInfo = ProxyInfo.forDefaultProxy();
101+
}
102+
}
103+
104+
return proxyInfo;
105+
}
106+
64107
private static void setUpSasl() {
65108
if (SettingsManager.connectionUsePlainTextAuth()) {
66109
final Map<String, String> registeredSASLMechanisms = SASLAuthentication.getRegisterdSASLMechanisms();
Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.xabber.android.data.connection;
22

3-
import org.jivesoftware.smack.proxy.ProxyInfo;
4-
53
public enum ProxyType {
64

75
none,
@@ -14,27 +12,4 @@ public enum ProxyType {
1412

1513
orbot;
1614

17-
public ProxyInfo getProxyInfo(String proxyHost, int proxyPort,
18-
String proxyUser, String proxyPassword) {
19-
ProxyInfo.ProxyType proxyType;
20-
if (this == none)
21-
proxyType = ProxyInfo.ProxyType.NONE;
22-
else if (this == http)
23-
proxyType = ProxyInfo.ProxyType.HTTP;
24-
else if (this == socks4)
25-
proxyType = ProxyInfo.ProxyType.SOCKS4;
26-
else if (this == socks5)
27-
proxyType = ProxyInfo.ProxyType.SOCKS5;
28-
else if (this == orbot) {
29-
proxyType = ProxyInfo.ProxyType.SOCKS5;
30-
proxyHost = "localhost";
31-
proxyPort = 9050;
32-
proxyUser = "";
33-
proxyPassword = "";
34-
} else
35-
throw new IllegalStateException();
36-
return new ProxyInfo(proxyType, proxyHost, proxyPort, proxyUser,
37-
proxyPassword);
38-
}
39-
4015
}

0 commit comments

Comments
 (0)