Merge latest patch sent to dev mailinglist with subject "XCAP tests" which represents the work of Grigorii Balutsel on the "XCAP Support" GSoC 2010 project into trunk.

Fix merging already existing contacts with serverside list and storing password in credential service.
cusax-fix
Damian Minkov 15 years ago
parent 7ad9ba2eed
commit 39fb27ca51

@ -746,8 +746,8 @@
<sysproperty key="java.net.preferIPv6Addresses"
value="${java.net.preferIPv6Addresses}"/>
<sysproperty key="net.java.sip.communicator.SC_HOME_DIR_LOCATION"
value="${user.home}/schome"/>
<!--sysproperty key="net.java.sip.communicator.SC_HOME_DIR_LOCATION"
value="${user.home}/schome"/-->
<!-- this is a temporary option that would need to disappear once
we finalize jingle -->

@ -25,7 +25,12 @@
*/
public class ContactSipImpl
implements Contact
{
{
/**
* Property used for store in persistent data indicating that contact
* is resolved against xcap server.
*/
private static final String XCAP_RESOLVED_PROPERTY = "xcap.resolved";
/**
* The provider that created us.
@ -70,6 +75,11 @@ public class ContactSipImpl
*/
private boolean isResolvable = true;
/**
* Determines whether the contact has been resolved on the XCAP server.
*/
private boolean xCapResolved = false;
/**
* The XCAP equivalent of SIP contact group.
*/
@ -357,16 +367,59 @@ public void setPersistent(boolean isPersistent)
this.isPersistent = isPersistent;
}
/**
* Gets the value of the xCapResolved property.
*
* @return the xCapResolved property.
*/
public boolean isXCapResolved()
{
return xCapResolved;
}
/**
* Returns null as no persistent data is required and the contact address is
* sufficient for restoring the contact.
* <p>
* @return null as no such data is needed.
* Sets the value of the xCapResolved property.
*
* @param xCapResolved the xCapResolved to set.
*/
public void setXCapResolved(boolean xCapResolved)
{
this.xCapResolved = xCapResolved;
}
/**
* Gets the persistent data - for now only the XCAP resolved is needed
* for restoring the contact data. Fields are properties separated by ;
* <p/>
*
* @return the persistent data
*/
public String getPersistentData()
{
return null;
return XCAP_RESOLVED_PROPERTY + "="
+ Boolean.toString(xCapResolved) + ";";
}
/**
* Sets the persistent data.
*
* @param persistentData the persistent data to set.
*/
public void setPersistentData(String persistentData)
{
if (persistentData == null)
{
return;
}
StringTokenizer tokenizer = new StringTokenizer(persistentData, ";");
while (tokenizer.hasMoreTokens())
{
String data[] = tokenizer.nextToken().split("=");
if (data[0].equals(XCAP_RESOLVED_PROPERTY) && data.length > 1)
{
xCapResolved = Boolean.valueOf(data[1]);
}
}
}
/**

@ -1626,7 +1626,7 @@ public Contact createUnresolvedContact(
* the contact. When this happens the corresponding event would notify
* interested subscription listeners.
*
* @param addressStr an identifier of the contact that we'll be creating.
* @param contactId an identifier of the contact that we'll be creating.
* @param persistentData a String returned Contact's getPersistentData()
* method during a previous run and that has been persistently stored
* locally.
@ -1636,12 +1636,12 @@ public Contact createUnresolvedContact(
* @return the unresolved <tt>Contact</tt> created from the specified
* <tt>address</tt> and <tt>persistentData</tt>
*/
public Contact createUnresolvedContact(String addressStr,
public Contact createUnresolvedContact(String contactId,
String persistentData,
ContactGroup parent)
{
return ssContactList.createUnresolvedContact((ContactGroupSipImpl)
parent, addressStr);
parent, contactId, persistentData);
}
/**

@ -9,6 +9,7 @@
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
@ -32,6 +33,73 @@ public ProtocolProviderFactorySipImpl()
super(SipActivator.getBundleContext(), ProtocolNames.SIP);
}
/**
* Ovverides the original in order not to load the XCAP_PASSWORD field.
*
* @param accountID the account identifier.
*/
public boolean loadAccount(AccountID accountID)
{
boolean result = super.loadAccount(accountID);
if (result)
{
loadXCapPassword(accountID);
}
return result;
}
/**
* Ovverides the original in order not to save the XCAP_PASSWORD field.
*
* @param accountID the account identifier.
*/
protected void storeAccount(AccountID accountID)
{
storeXCapPassword(accountID);
super.storeAccount(accountID);
loadXCapPassword(accountID);
}
/**
* Stores XCAP_PASSWORD property.
*
* @param accountID the account identifier.
*/
private void storeXCapPassword(AccountID accountID)
{
CredentialsStorageService credentialsStorage
= ServiceUtils.getService(
getBundleContext(),
CredentialsStorageService.class);
String accountPrefix = accountID.getAccountUniqueID() + ".xcap";
String password = accountID.getAccountPropertyString(
ProtocolProviderServiceSipImpl.XCAP_PASSWORD);
if (password != null)
{
credentialsStorage.storePassword(accountPrefix, password);
accountID.removeAccountProperty(
ProtocolProviderServiceSipImpl.XCAP_PASSWORD);
}
}
/**
* Loads XCAP_PASSWORD property.
*
* @param accountID the AccountID corresponding to the account that we would
* like to store.
*/
private void loadXCapPassword(AccountID accountID)
{
CredentialsStorageService credentialsStorage
= ServiceUtils.getService(
getBundleContext(),
CredentialsStorageService.class);
String accountPrefix = accountID.getAccountUniqueID() + ".xcap";
accountID.putAccountProperty(
ProtocolProviderServiceSipImpl.XCAP_PASSWORD,
credentialsStorage.loadPassword(accountPrefix));
}
/**
* Initializes and creates an account corresponding to the specified
* accountProperties and registers the resulting ProtocolProvider in the

@ -196,10 +196,14 @@ else if (eventID == ServerStoredGroupEvent.GROUP_RESOLVED_EVENT)
* @param parentGroup the group where the unersolved contact is to be
* created.
* @param contactId the sip id of the contact to create.
* @param persistentData a String returned Contact's getPersistentData()
* method during a previous run and that has been persistently stored
* locally.
* @return the newly created unresolved <tt>ContactSipImpl</tt>.
*/
public synchronized ContactSipImpl createUnresolvedContact(
ContactGroupSipImpl parentGroup, String contactId)
ContactGroupSipImpl parentGroup, String contactId,
String persistentData)
{
if (parentGroup == null)
{
@ -226,6 +230,7 @@ public synchronized ContactSipImpl createUnresolvedContact(
ContactSipImpl newUnresolvedContact = new ContactSipImpl(contactAddress,
sipProvider);
parentGroup.addContact(newUnresolvedContact);
newUnresolvedContact.setPersistentData(persistentData);
fireContactAdded(parentGroup, newUnresolvedContact);
return newUnresolvedContact;
}
@ -301,6 +306,7 @@ synchronized public ContactSipImpl createContact(
OperationFailedException.NETWORK_FAILURE, e);
}
newContact.setResolved(true);
newContact.setXCapResolved(true);
// Update pres-rules if needed
if (!isContactExistsInWhiteRule(contactId))
{
@ -742,10 +748,10 @@ synchronized public void init()
{
return;
}
// Process resource-lists
ResourceListsType resourceLists = xCapClient.getResourceLists();
// Collect all root's subgroups to check if some of them were deleted
ListType serverRootList = new ListType();
//serverRootList.getLists().addAll(resourceLists.getList());
for (ListType list : resourceLists.getList())
{
// If root group has sub group with ROOT_GROUP_NAME - it is
@ -766,44 +772,38 @@ synchronized public void init()
serverRootList.getLists().add(list);
}
}
// TODO: get it from somewhere
boolean firstRun = false;
boolean updateResourceLists = false;
// Resolve localy saved contacts and groups with server stored
// contacts and groups
resolveContactGroup(rootGroup, serverRootList, !firstRun);
// If it is first run - upload unresolved contacts and groups to
// the server.
if(firstRun)
resolveContactGroup(rootGroup, serverRootList, false);
// Upload unresolved contacts and groups to the server.
for (ContactSipImpl contact : getAllContacts(rootGroup))
{
for(ContactSipImpl contact : getAllContacts(rootGroup))
if (!contact.isResolved() && contact.isPersistent())
{
if(!contact.isResolved() && contact.isPersistent())
{
updateResourceLists = true;
contact.setResolved(true);
fireContactResolved((ContactGroupSipImpl) contact
.getParentContactGroup(), contact);
}
updateResourceLists = true;
contact.setResolved(true);
contact.setXCapResolved(true);
fireContactResolved((ContactGroupSipImpl) contact
.getParentContactGroup(), contact);
}
for(ContactGroupSipImpl group : getAllGroups(rootGroup))
}
for (ContactGroupSipImpl group : getAllGroups(rootGroup))
{
if (!group.isResolved() && group.isPersistent())
{
if(!group.isResolved() && group.isPersistent())
{
updateResourceLists = true;
group.setResolved(true);
fireGroupEvent(group,
ServerStoredGroupEvent.GROUP_RESOLVED_EVENT);
}
updateResourceLists = true;
group.setResolved(true);
fireGroupEvent(group,
ServerStoredGroupEvent.GROUP_RESOLVED_EVENT);
}
firstRun = false;
}
// Update resource-lists if needed
if(updateResourceLists)
{
updateResourceLists();
}
// Process pres-rules
if (xCapClient.isPresRulesSupported())
{
// Get pres-rules and analyze it
@ -1193,6 +1193,7 @@ private void resolveContactGroup(
newContact.setOtherAttributes(serverEntry.getAnyAttributes());
newContact.setAny(serverEntry.getAny());
newContact.setResolved(true);
newContact.setXCapResolved(true);
clientGroup.addContact(newContact);
fireContactAdded(clientGroup, newContact);
@ -1203,6 +1204,7 @@ private void resolveContactGroup(
newContact.setOtherAttributes(serverEntry.getAnyAttributes());
newContact.setAny(serverEntry.getAny());
newContact.setResolved(true);
newContact.setXCapResolved(true);
unresolvedContacts.remove(newContact);
fireContactResolved(clientGroup, newContact);
@ -1224,6 +1226,7 @@ private void resolveContactGroup(
continue;
}
unresolvedContact.setResolved(true);
unresolvedContact.setXCapResolved(true);
// Remove unresolved contacts
clientGroup.removeContact(unresolvedContact);
// Tell listeners about the removed contact

@ -36,6 +36,7 @@ Import-Package: org.apache.log4j,
org.xml.sax,
net.java.sip.communicator.service.argdelegation,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.credentialsstorage,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.neomedia,

@ -56,10 +56,10 @@ public class PresencePanel
private JPanel xCapButtonsPanel
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
private JPanel xCapLabelsPanel
private JPanel xCapCredetialsLabelsPanel
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
private JPanel xCapValuesPanel
private JPanel xCapCredetialsValuesPanel
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
private JLabel xCapServerUriLabel = new JLabel(
@ -137,7 +137,6 @@ public void actionPerformed(ActionEvent evt)
setXCapEnableEnabled(checkBox.isSelected());
}
});
xCapButtonsPanel.add(xCapEnableBox);
xCapUseSipCredetialsBox.addActionListener(new ActionListener()
{
@ -147,21 +146,27 @@ public void actionPerformed(ActionEvent evt)
setXCapUseSipCredetialsEnabled(checkBox.isSelected());
}
});
xCapButtonsPanel.add(xCapUseSipCredetialsBox);
setXCapEnableEnabled(xCapEnableBox.isSelected());
xCapLabelsPanel.add(xCapServerUriLabel);
xCapLabelsPanel.add(xCapUserLabel);
xCapLabelsPanel.add(xCapPasswordLabel);
JPanel xCapServerUriPanel
= new TransparentPanel(new BorderLayout(10, 10));
xCapServerUriPanel.add(xCapServerUriLabel, BorderLayout.WEST);
xCapServerUriPanel.add(xCapServerUriValue, BorderLayout.CENTER);
xCapButtonsPanel.add(xCapEnableBox);
xCapButtonsPanel.add(xCapServerUriPanel);
xCapButtonsPanel.add(xCapUseSipCredetialsBox);
xCapCredetialsLabelsPanel.add(xCapUserLabel);
xCapCredetialsLabelsPanel.add(xCapPasswordLabel);
xCapValuesPanel.add(xCapServerUriValue);
xCapValuesPanel.add(xCapUserValue);
xCapValuesPanel.add(xCapPasswordValue);
xCapCredetialsValuesPanel.add(xCapUserValue);
xCapCredetialsValuesPanel.add(xCapPasswordValue);
xCapPanel.add(xCapButtonsPanel, BorderLayout.NORTH);
xCapPanel.add(xCapLabelsPanel, BorderLayout.WEST);
xCapPanel.add(xCapValuesPanel, BorderLayout.CENTER);
xCapPanel.add(xCapCredetialsLabelsPanel, BorderLayout.WEST);
xCapPanel.add(xCapCredetialsValuesPanel, BorderLayout.CENTER);
xCapPanel.setBorder(BorderFactory.createTitledBorder(
Resources.getString("plugin.sipaccregwizz.XCAP_OPTIONS")));

@ -282,6 +282,15 @@ public void putAccountProperty(String key, String value)
accountProperties.put(key, value);
}
/**
* Removes specified account property.
* @param key the key to remove.
*/
public void removeAccountProperty(String key)
{
accountProperties.remove(key);
}
/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by

Loading…
Cancel
Save