|
|
|
|
@ -78,11 +78,6 @@ public class ProtocolProviderServiceJabberImpl
|
|
|
|
|
*/
|
|
|
|
|
private SecurityAuthority authority = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if we are reconnecting, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
private boolean reconnecting = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The icon corresponding to the jabber protocol.
|
|
|
|
|
*/
|
|
|
|
|
@ -261,7 +256,6 @@ void reregister(int authReasonCode)
|
|
|
|
|
// to know we are not registered
|
|
|
|
|
this.unregister(false);
|
|
|
|
|
|
|
|
|
|
this.reconnecting = true;
|
|
|
|
|
// reset states
|
|
|
|
|
this.abortConnecting = false;
|
|
|
|
|
this.abortConnectingAndReconnect = false;
|
|
|
|
|
@ -394,130 +388,113 @@ private synchronized void connectAndLogin(SecurityAuthority authority,
|
|
|
|
|
|
|
|
|
|
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
//Getting global proxy information from configuration files
|
|
|
|
|
org.jivesoftware.smack.proxy.ProxyInfo proxy = null;
|
|
|
|
|
String globalProxyType =
|
|
|
|
|
JabberActivator.getConfigurationService()
|
|
|
|
|
.getString(ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME);
|
|
|
|
|
if(globalProxyType == null ||
|
|
|
|
|
globalProxyType.equals(ProxyInfo.ProxyType.NONE.name()))
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forNoProxy();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Getting global proxy information from configuration files
|
|
|
|
|
org.jivesoftware.smack.proxy.ProxyInfo proxy = null;
|
|
|
|
|
String globalProxyType =
|
|
|
|
|
JabberActivator.getConfigurationService()
|
|
|
|
|
.getString(ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME);
|
|
|
|
|
if(globalProxyType == null ||
|
|
|
|
|
globalProxyType.equals(ProxyInfo.ProxyType.NONE.name()))
|
|
|
|
|
String globalProxyAddress =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME);
|
|
|
|
|
String globalProxyPortStr =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME);
|
|
|
|
|
int globalProxyPort;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forNoProxy();
|
|
|
|
|
globalProxyPort = Integer.parseInt(
|
|
|
|
|
globalProxyPortStr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
catch(NumberFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
String globalProxyAddress =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME);
|
|
|
|
|
String globalProxyPortStr =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME);
|
|
|
|
|
int globalProxyPort;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
globalProxyPort = Integer.parseInt(
|
|
|
|
|
globalProxyPortStr);
|
|
|
|
|
}
|
|
|
|
|
catch(NumberFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
throw new OperationFailedException("Wrong port",
|
|
|
|
|
OperationFailedException.INVALID_ACCOUNT_PROPERTIES,
|
|
|
|
|
ex);
|
|
|
|
|
}
|
|
|
|
|
String globalProxyUsername =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
|
|
|
|
|
String globalProxyPassword =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_PASSWORD_PROPERTY_NAME);
|
|
|
|
|
if(globalProxyAddress == null ||
|
|
|
|
|
globalProxyAddress.length() <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new OperationFailedException(
|
|
|
|
|
"Missing Proxy Address",
|
|
|
|
|
OperationFailedException.INVALID_ACCOUNT_PROPERTIES);
|
|
|
|
|
}
|
|
|
|
|
if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.HTTP.name()))
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forHttpProxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
else if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.SOCKS4.name()))
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forSocks4Proxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
else if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.SOCKS5.name()))
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forSocks5Proxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
throw new OperationFailedException("Wrong port",
|
|
|
|
|
OperationFailedException.INVALID_ACCOUNT_PROPERTIES,
|
|
|
|
|
ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConnectionConfiguration confConn =
|
|
|
|
|
new ConnectionConfiguration(
|
|
|
|
|
serverAddress,
|
|
|
|
|
Integer.parseInt(serverPort),
|
|
|
|
|
serviceName,
|
|
|
|
|
proxy
|
|
|
|
|
);
|
|
|
|
|
confConn.setReconnectionAllowed(false);
|
|
|
|
|
|
|
|
|
|
connection = new XMPPConnection(confConn);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
String globalProxyUsername =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
|
|
|
|
|
String globalProxyPassword =
|
|
|
|
|
JabberActivator.getConfigurationService().getString(
|
|
|
|
|
ProxyInfo.CONNECTON_PROXY_PASSWORD_PROPERTY_NAME);
|
|
|
|
|
if(globalProxyAddress == null ||
|
|
|
|
|
globalProxyAddress.length() <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new OperationFailedException(
|
|
|
|
|
"Missing Proxy Address",
|
|
|
|
|
OperationFailedException.INVALID_ACCOUNT_PROPERTIES);
|
|
|
|
|
}
|
|
|
|
|
if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.HTTP.name()))
|
|
|
|
|
{
|
|
|
|
|
CertificateVerificationService gvs =
|
|
|
|
|
getCertificateVerificationService();
|
|
|
|
|
if(gvs != null)
|
|
|
|
|
connection.setCustomTrustManager(
|
|
|
|
|
new HostTrustManager(gvs.getTrustManager(
|
|
|
|
|
serverAddress,
|
|
|
|
|
Integer.parseInt(serverPort))));
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forHttpProxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
else if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.SOCKS4.name()))
|
|
|
|
|
{
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forSocks4Proxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
catch(GeneralSecurityException e)
|
|
|
|
|
else if(globalProxyType.equals(
|
|
|
|
|
ProxyInfo.ProxyType.SOCKS5.name()))
|
|
|
|
|
{
|
|
|
|
|
logger.error("Error creating custom trust manager", e);
|
|
|
|
|
proxy = org.jivesoftware.smack.proxy.ProxyInfo
|
|
|
|
|
.forSocks5Proxy(
|
|
|
|
|
globalProxyAddress,
|
|
|
|
|
globalProxyPort,
|
|
|
|
|
globalProxyUsername,
|
|
|
|
|
globalProxyPassword);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConnectionConfiguration confConn =
|
|
|
|
|
new ConnectionConfiguration(
|
|
|
|
|
serverAddress,
|
|
|
|
|
Integer.parseInt(serverPort),
|
|
|
|
|
serviceName,
|
|
|
|
|
proxy
|
|
|
|
|
);
|
|
|
|
|
confConn.setReconnectionAllowed(false);
|
|
|
|
|
|
|
|
|
|
connection.connect();
|
|
|
|
|
connection = new XMPPConnection(confConn);
|
|
|
|
|
|
|
|
|
|
connection.addConnectionListener(
|
|
|
|
|
new JabberConnectionListener());
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CertificateVerificationService gvs =
|
|
|
|
|
getCertificateVerificationService();
|
|
|
|
|
if(gvs != null)
|
|
|
|
|
connection.setCustomTrustManager(
|
|
|
|
|
new HostTrustManager(gvs.getTrustManager(
|
|
|
|
|
serverAddress,
|
|
|
|
|
Integer.parseInt(serverPort))));
|
|
|
|
|
}
|
|
|
|
|
catch (XMPPException exc)
|
|
|
|
|
catch(GeneralSecurityException e)
|
|
|
|
|
{
|
|
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.info("Failed to establish a Jabber connection for "
|
|
|
|
|
+ getAccountID().getAccountUniqueID(), exc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new OperationFailedException(
|
|
|
|
|
"Failed to establish a Jabber connection for "
|
|
|
|
|
+ getAccountID().getAccountUniqueID()
|
|
|
|
|
, OperationFailedException.NETWORK_FAILURE
|
|
|
|
|
, exc);
|
|
|
|
|
logger.error("Error creating custom trust manager", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection.connect();
|
|
|
|
|
|
|
|
|
|
connection.addConnectionListener(
|
|
|
|
|
new JabberConnectionListener());
|
|
|
|
|
|
|
|
|
|
if(abortConnecting)
|
|
|
|
|
{
|
|
|
|
|
if(abortConnectingAndReconnect)
|
|
|
|
|
@ -606,8 +583,6 @@ else if(globalProxyType.equals(
|
|
|
|
|
|
|
|
|
|
if(connection.isAuthenticated())
|
|
|
|
|
{
|
|
|
|
|
this.reconnecting = false;
|
|
|
|
|
|
|
|
|
|
connection.getRoster().
|
|
|
|
|
setSubscriptionMode(Roster.SubscriptionMode.manual);
|
|
|
|
|
|
|
|
|
|
@ -685,7 +660,7 @@ private void unregister(boolean fireEvent)
|
|
|
|
|
{
|
|
|
|
|
RegistrationState currRegState = getRegistrationState();
|
|
|
|
|
|
|
|
|
|
if(connection != null && connection.isConnected())
|
|
|
|
|
if(connection != null)
|
|
|
|
|
connection.disconnect();
|
|
|
|
|
|
|
|
|
|
if(fireEvent)
|
|
|
|
|
@ -1006,10 +981,11 @@ else if(exception instanceof SSLHandshakeException &&
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!reconnecting)
|
|
|
|
|
reregister(SecurityAuthority.CONNECTION_FAILED);
|
|
|
|
|
else
|
|
|
|
|
reconnecting = false;
|
|
|
|
|
|
|
|
|
|
fireRegistrationStateChanged(getRegistrationState(),
|
|
|
|
|
RegistrationState.CONNECTION_FAILED,
|
|
|
|
|
RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,
|
|
|
|
|
exception.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|