Fixes bug with additional STUN servers and Jingle Nodes not being removed after Jabber account is edited

cusax-fix
paweldomas 13 years ago
parent c4a62a0f18
commit 03af0f5b4e

@ -10,6 +10,7 @@
import net.java.sip.communicator.service.protocol.*;
import org.jitsi.service.configuration.*;
import org.jivesoftware.smack.util.*;
import org.osgi.framework.*;
@ -213,6 +214,32 @@ public void modifyAccount( ProtocolProviderService protocolProvider,
accountID.setAccountProperties(accountProperties);
// Remove additional STUN servers and Jingle Nodes properties.
// This is required because there is no check if some of them were
// removed during account edit process. Those that are valid will be
// restored during account storage process.
AccountManager accManager = getAccountManager();
ConfigurationService configSrvc
= JabberActivator.getConfigurationService();
String accountNodeName
= getAccountManager().getAccountNodeName(this, accountID);
String factoryPackage = accManager.getFactoryImplPackageName(this);
String accountPrefix = factoryPackage + "." + accountNodeName;
List<String> allProperties = configSrvc.getAllPropertyNames();
String stunPrefix
= accountPrefix+"."+ProtocolProviderFactory.STUN_PREFIX;
String jinglePrefix
= accountPrefix+"."+JingleNodeDescriptor.JN_PREFIX;
for(String property : allProperties)
{
if( property.startsWith(stunPrefix)
|| property.startsWith(jinglePrefix) )
{
configSrvc.removeProperty(property);
}
}
// First store the account and only then load it as the load generates
// an osgi event, the osgi event triggers (trhgough the UI) a call to
// the register() method and it needs to acces the configuration service

@ -247,7 +247,7 @@ private void fireStoredAccountsLoaded(ProtocolProviderFactory factory)
* @param factory the factory which package will be returned.
* @return the package name of the <tt>factory</tt>.
*/
private String getFactoryImplPackageName(ProtocolProviderFactory factory)
public String getFactoryImplPackageName(ProtocolProviderFactory factory)
{
String className = factory.getClass().getName();
@ -660,30 +660,7 @@ public void storeAccount(
= ProtocolProviderActivator.getConfigurationService();
String factoryPackage = getFactoryImplPackageName(factory);
// First check if such accountID already exists in the configuration.
List<String> storedAccounts =
configurationService.getPropertyNamesByPrefix(factoryPackage, true);
String accountUID = accountID.getAccountUniqueID();
String accountNodeName = null;
for (Iterator<String> storedAccountIter = storedAccounts.iterator();
storedAccountIter.hasNext();)
{
String storedAccount = storedAccountIter.next();
// If the property is not related to an account we skip it.
int dotIndex = storedAccount.lastIndexOf(".");
if (!storedAccount.substring(dotIndex + 1)
.startsWith(ACCOUNT_UID_PREFIX))
continue;
String storedAccountUID =
configurationService.getString(storedAccount + "."
+ ProtocolProviderFactory.ACCOUNT_UID);
if (storedAccountUID.equals(accountUID))
accountNodeName = configurationService.getString(storedAccount);
}
String accountNodeName = getAccountNodeName(factory, accountID);
Map<String, Object> configurationProperties
= new HashMap<String, Object>();
@ -782,6 +759,49 @@ else if(property.endsWith("." + ProtocolProviderFactory.PASSWORD))
+ " for package " + factoryPackage);
}
/**
* Gets account node name under which account configuration properties are
* stored.
*
* @param factory account's protocol provider factory
* @param accountID account for which the prefix will be returned
* @return configuration prefix for given <tt>accountID</tt> if exists or
* <tt>null</tt> otherwise
*/
public String getAccountNodeName( ProtocolProviderFactory factory,
AccountID accountID )
{
ConfigurationService configurationService
= ProtocolProviderActivator.getConfigurationService();
String factoryPackage = getFactoryImplPackageName(factory);
// First check if such accountID already exists in the configuration.
List<String> storedAccounts =
configurationService.getPropertyNamesByPrefix(factoryPackage, true);
String accountUID = accountID.getAccountUniqueID();
String accountNodeName = null;
for (Iterator<String> storedAccountIter = storedAccounts.iterator();
storedAccountIter.hasNext();)
{
String storedAccount = storedAccountIter.next();
// If the property is not related to an account we skip it.
int dotIndex = storedAccount.lastIndexOf(".");
if (!storedAccount.substring(dotIndex + 1)
.startsWith(ACCOUNT_UID_PREFIX))
continue;
String storedAccountUID
= configurationService.getString(
storedAccount + "." + ProtocolProviderFactory.ACCOUNT_UID);
if (storedAccountUID.equals(accountUID))
accountNodeName = configurationService.getString(storedAccount);
}
return accountNodeName;
}
/**
* Removes the account with <tt>accountID</tt> from the set of accounts
* that are persistently stored inside the configuration service.

@ -1191,7 +1191,7 @@ protected void stop(ServiceRegistration registeredAccount)
*
* @return <tt>AccountManager</tt> of the protocol
*/
private AccountManager getAccountManager()
protected AccountManager getAccountManager()
{
BundleContext bundleContext = getBundleContext();
ServiceReference serviceReference =

Loading…
Cancel
Save