fix for #83091 (show LDAP autocomplete directories in addressbook).

and some code cleanup, and code bloat removal (see nsAbUtils.cpp)
r=dmose, sr=bienvenu
This commit is contained in:
sspitzer%netscape.com 2002-02-06 22:50:26 +00:00
Родитель 1c19cf11c0
Коммит f9149c7e46
42 изменённых файлов: 485 добавлений и 648 удалений

Просмотреть файл

@ -157,6 +157,17 @@
{0xa3, 0x16, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc} \
}
//
// nsAbDirectoryProperties
//
#define NS_ABDIRECTORYPROPERTIES_CONTRACTID \
"@mozilla.org/addressbook/properties;1"
#define NS_ABDIRECTORYPROPERTIES_CID \
{ /* 8b00a972-1dd2-11b2-9d9c-9c377a9c3dba */ \
0x8b00a972, 0x1dd2, 0x11b2, \
{0x9d, 0x9c, 0x9c, 0x37, 0x7a, 0x9c, 0x3d, 0xba} \
}
//
// nsAbAutoCompleteSession
//
@ -349,6 +360,14 @@
{0x84, 0xac, 0x12, 0x48, 0x25, 0xc7, 0x78, 0xf8} \
}
//
// LDAP autcomplete directory factory
//
#define NS_ABLDAPACDIRFACTORY_CONTRACTID \
NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX "ldap"
#define NS_ABLDAPSACDIRFACTORY_CONTRACTID \
NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX "ldaps"
// nsAbLDAPAutoCompFormatter
// 4e276d6d-9981-46b4-9070-92f344ac5f5a

Просмотреть файл

@ -84,6 +84,7 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddressBook)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbDirectoryDataSource,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirProperty)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryProperties)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbCardProperty)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbBSDirectory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbMDBDirectory)
@ -165,6 +166,10 @@ static const nsModuleComponentInfo components[] =
NS_ABDIRPROPERTY_CID,
NS_ABDIRPROPERTY_CONTRACTID,
nsAbDirPropertyConstructor },
{ "AB Directory Properties",
NS_ABDIRECTORYPROPERTIES_CID,
NS_ABDIRECTORYPROPERTIES_CONTRACTID,
nsAbDirectoryPropertiesConstructor },
{ "Address Book Session",
NS_ADDRBOOKSESSION_CID,
NS_ADDRBOOKSESSION_CONTRACTID,
@ -245,6 +250,16 @@ static const nsModuleComponentInfo components[] =
NS_ABLDAPDIRFACTORY_CONTRACTID,
nsAbLDAPDirFactoryConstructor },
{ "Address LDAP autocomplete factory Interface",
NS_ABLDAPDIRFACTORY_CID,
NS_ABLDAPACDIRFACTORY_CONTRACTID,
nsAbLDAPDirFactoryConstructor },
{ "Address LDAP over SSL autocomplete factory Interface",
NS_ABLDAPDIRFACTORY_CID,
NS_ABLDAPSACDIRFACTORY_CONTRACTID,
nsAbLDAPDirFactoryConstructor },
{ "Address book LDAP autocomplete formatter",
NS_ABLDAPAUTOCOMPFORMATTER_CID,
NS_ABLDAPAUTOCOMPFORMATTER_CONTRACTID,

Просмотреть файл

@ -15,13 +15,14 @@
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Paul Sandoz <paul.sandoz@sun.com>
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Created by: Paul Sandoz <paul.sandoz@sun.com>
* Contributor(s): Csaba Borbola <csaba.borbola@sun.com>
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -41,34 +42,26 @@
#include "nsISimpleEnumerator.idl"
interface nsIAbDirectory;
interface nsIAbDirectoryProperties;
[scriptable, uuid(C2308606-1DD1-11B2-87D4-85FCA9B1DC08)]
interface nsIAbDirFactory : nsISupports
{
/**
* Instantiate new top level address book
* directories given an array of property names
* and values. More than one directory may be
* directories given some properties.
* More than one directory may be
* returned depending on the implementation
* and integration with the associated address book
* sources
*
* @param propertiesSize
* The number of properties
* @param propertyNamesArray
* The array of property names
* @param propertyValuesArray
* The array of property values
* @param aProperties
* nsIAbDirectoryProperties with the properties
* @return
* Enumeration of nsIAbDirectory
* interfaces
*/
nsISimpleEnumerator createDirectory (
in unsigned long propertiesSize,
[array, size_is(propertiesSize)]
in string propertyNamesArray,
[array, size_is(propertiesSize)]
in wstring propertyValuesArray);
nsISimpleEnumerator createDirectory(in nsIAbDirectoryProperties aProperties);
/**
* Delete a top level address book directory

Просмотреть файл

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -46,26 +47,39 @@
#include "nsDirPrefs.h"
%}
// used for when creating new directories
// either from user input, or during bootstrapping
[scriptable, uuid(f94812de-1dd1-11b2-b0ab-9eb5e055f712)]
interface nsIAbDirectoryProperties : nsISupports {
attribute AString description;
attribute string URI;
attribute string prefName;
attribute string fileName;
};
[scriptable, uuid(AA920C90-1DD1-11B2-96D3-AA81268ADAFC)]
interface nsIAbDirectory : nsISupports {
// Types of operation
// Perform linear reading of directory card
// content
const long opRead = 1;
const long opRead = 0x1;
// Perform modification and deletion on a
// directories content
const long opWrite = 2;
const long opWrite = 0x2;
// Perform searching on a directory card
// content via the uri format:
// scheme://path?query
const long opSearch = 4;
const long opSearch = 0x4;
// The supported operations
readonly attribute long operations;
// The name of the directory
attribute wstring dirName;
// will be used for LDAP replication
attribute unsigned long lastModifiedDate;
// Defines whether this directory is a mail
@ -117,6 +131,11 @@ interface nsIAbDirectory : nsISupports {
*/
readonly attribute boolean isRemote;
/**
* directory should be searched when doing local autocomplete
*/
readonly attribute boolean searchDuringLocalAutocomplete;
// Mail list specific
readonly attribute boolean supportsMailingLists;
@ -165,7 +184,7 @@ interface nsIAbDirectory : nsISupports {
This method should become redundant or
be only associated with card folders
*/
void createNewDirectory(in unsigned long prefCount,[array, size_is(prefCount)] in string prefName, [array, size_is(prefCount)] in wstring prefValue);
void createNewDirectory(in nsIAbDirectoryProperties aProperties);
/* create a directory by passing the display name and address book uri */
void createDirectoryByURI(in wstring displayName, in string uri, in boolean migrating);

Просмотреть файл

@ -47,7 +47,7 @@ interface nsIAbDirectory;
[scriptable, uuid(D60B84F1-2A8C-11d3-9E07-00A0C92B5F0D)]
interface nsIAddressBook : nsISupports
{
void newAddressBook(in nsIRDFCompositeDataSource db, in unsigned long prefCount,[array, size_is(prefCount)] in string prefName, [array, size_is(prefCount)] in wstring prefValue);
void newAddressBook(in nsIAbDirectoryProperties aProperties);
void deleteAddressBooks(in nsIRDFCompositeDataSource db, in nsISupportsArray parentDir, in nsISupportsArray aResourceArray);
void setDocShellWindow(in nsIDOMWindowInternal win);
void exportAddressBook(in nsIAbDirectory aDirectory);

Просмотреть файл

@ -250,11 +250,9 @@ function AbNewAddressBook()
function AbCreateNewAddressBook(name)
{
var prefsAttr = new Array;
var prefsValue = new Array;
prefsAttr[0] = "description";
prefsValue[0] = name;
top.addressbook.newAddressBook(dirTree.database, 1, prefsAttr, prefsValue);
var properties = Components.classes["@mozilla.org/addressbook/properties;1"].createInstance(Components.interfaces.nsIAbDirectoryProperties);
properties.description = name;
top.addressbook.newAddressBook(properties);
}
function AbPrintCard()

Просмотреть файл

@ -60,7 +60,7 @@ NS_IMPL_ISUPPORTS1(nsAbAddressCollecter, nsIAbAddressCollecter)
nsAbAddressCollecter::nsAbAddressCollecter()
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
m_maxCABsize = -1;
m_sizeLimitEnabled = PR_FALSE;

Просмотреть файл

@ -56,7 +56,7 @@ NS_IMPL_ISUPPORTS2(nsAbAutoCompleteSession, nsIAbAutoCompleteSession, nsIAutoCom
nsAbAutoCompleteSession::nsAbAutoCompleteSession()
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mParser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID);
}
@ -492,21 +492,32 @@ nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAut
}
nsresult nsAbAutoCompleteSession::SearchDirectory(const char *fileName, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results, PRBool searchSubDirectory)
nsresult nsAbAutoCompleteSession::SearchDirectory(const char *aURI, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results, PRBool searchSubDirectory)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIRDFService> rdfService(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIRDFResource> resource;
rv = rdfService->GetResource(fileName, getter_AddRefs(resource));
rv = rdfService->GetResource(aURI, getter_AddRefs(resource));
NS_ENSURE_SUCCESS(rv, rv);
// query interface
nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
NS_ENSURE_SUCCESS(rv, rv);
if (nsCRT::strcmp(kAllDirectoryRoot, fileName))
// when autocompleteing against directories,
// we only want to match against certain directories
// we ask the directory if it wants to be used
// for local autocompleting.
PRBool searchDuringLocalAutocomplete;
rv = directory->GetSearchDuringLocalAutocomplete(&searchDuringLocalAutocomplete);
NS_ENSURE_SUCCESS(rv, rv);
if (!searchDuringLocalAutocomplete)
return NS_OK;
if (nsCRT::strcmp(kAllDirectoryRoot, aURI))
rv = SearchCards(directory, searchStr, results);
if (!searchSubDirectory)

Просмотреть файл

@ -107,7 +107,7 @@ protected:
PRBool CheckEntry(nsAbAutoCompleteSearchString* searchStr, const PRUnichar* nickName,const PRUnichar* displayName,
const PRUnichar* firstName, const PRUnichar* lastName, const PRUnichar* emailAddress, MatchType* matchType);
nsresult SearchCards(nsIAbDirectory* directory, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results);
nsresult SearchDirectory(const char *fileName, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results, PRBool searchSubDirectory = PR_FALSE);
nsresult SearchDirectory(const char *aURI, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results, PRBool searchSubDirectory = PR_FALSE);
nsresult SearchPreviousResults(nsAbAutoCompleteSearchString *uSearchString, nsIAutoCompleteResults *previousSearchResult, nsIAutoCompleteResults* results);
nsCOMPtr<nsIMsgHeaderParser> mParser;

Просмотреть файл

@ -20,8 +20,9 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Paul Sandoz <paul.sandoz@sun.com>
* Paul Sandoz <paul.sandoz@sun.com>
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -55,14 +56,6 @@
#include "nsAbDirFactoryService.h"
#include "nsAbMDBDirFactory.h"
#include "prmem.h"
#include "prprf.h"
const char* kDescriptionPropertyName = "description";
const char* kFileNamePropertyName = "filename";
const char* kURIPropertyName = "uri";
const char* kMigratingPropertyName = "migrating";
nsAbBSDirectory::nsAbBSDirectory()
: nsRDFResource(),
mInitialized(PR_FALSE),
@ -109,14 +102,12 @@ nsresult nsAbBSDirectory::NotifyItemDeleted(nsISupports *item)
}
nsresult nsAbBSDirectory::CreateDirectoriesFromFactory(
const char* URI,
DIR_Server* server,
PRUint32 propertiesSize,
const char** propertyNameArray,
const PRUnichar** propertyValueArray,
PRBool notify)
nsIAbDirectoryProperties *aProperties,
DIR_Server *aServer,
PRBool aNotify)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aProperties);
// Get the directory factory service
nsCOMPtr<nsIAbDirFactoryService> dirFactoryService =
@ -124,16 +115,17 @@ nsresult nsAbBSDirectory::CreateDirectoriesFromFactory(
NS_ENSURE_SUCCESS (rv, rv);
// Get the directory factory from the URI
nsXPIDLCString uri;
rv = aProperties->GetURI(getter_Copies(uri));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIAbDirFactory> dirFactory;
rv = dirFactoryService->GetDirFactory (URI, getter_AddRefs(dirFactory));
rv = dirFactoryService->GetDirFactory(uri.get(), getter_AddRefs(dirFactory));
NS_ENSURE_SUCCESS (rv, rv);
// Create the directories
nsCOMPtr<nsISimpleEnumerator> newDirEnumerator;
rv = dirFactory->CreateDirectory(propertiesSize,
propertyNameArray,
propertyValueArray,
getter_AddRefs(newDirEnumerator));
rv = dirFactory->CreateDirectory(aProperties, getter_AddRefs(newDirEnumerator));
NS_ENSURE_SUCCESS (rv, rv);
// Enumerate through the directories adding them
@ -150,16 +142,16 @@ nsresult nsAbBSDirectory::CreateDirectoriesFromFactory(
if(NS_FAILED(rv))
continue;
// Define realtion ship between the preference
// Define a relationship between the preference
// entry and the directory
nsVoidKey key((void *)childDir);
mServers.Put (&key, (void *)server);
mServers.Put (&key, (void *)aServer);
mSubDirectories->AppendElement(childDir);
// Inform the listener, i.e. the RDF directory data
// source that a new address book has been added
if (notify == PR_TRUE)
if (aNotify)
NotifyItemAdded(childDir);
}
@ -175,78 +167,58 @@ NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsIEnumerator* *result)
do_GetService(NS_ABDIRFACTORYSERVICE_CONTRACTID,&rv);
NS_ENSURE_SUCCESS (rv, rv);
if (!GetDirList())
if (!DIR_GetDirectories())
return NS_ERROR_FAILURE;
PRInt32 count = GetDirList()->Count();
PRInt32 count = DIR_GetDirectories()->Count();
for (PRInt32 i = 0; i < count; i++)
{
DIR_Server *server = (DIR_Server *)GetDirList()->ElementAt(i);
DIR_Server *server = (DIR_Server *)(DIR_GetDirectories()->ElementAt(i));
NS_ConvertUTF8toUCS2 fileName (server->fileName);
PRInt32 pos = fileName.Find("na2");
if (pos >= 0) // check: this is a 4.x file, remove when conversion is done
// check: this is a 4.x file, remove when conversion is done
PRUint32 fileNameLen = strlen(server->fileName);
if ((fileNameLen > kABFileName_PreviousSuffixLen) &&
strcmp(server->fileName + fileNameLen - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0)
continue;
nsHashtable propertySet;
nsCOMPtr <nsIAbDirectoryProperties> properties;
properties = do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
// Set the description property
nsCStringKey descriptionKey (kDescriptionPropertyName, -1, nsCStringKey::NEVER_OWN);
NS_ConvertUTF8toUCS2 description (server->description);
propertySet.Put (&descriptionKey, (void* )description.get ());
rv = properties->SetDescription(description);
NS_ENSURE_SUCCESS(rv,rv);
// Set the file name property
nsCStringKey fileNameKey (kFileNamePropertyName, -1, nsCStringKey::NEVER_OWN);
propertySet.Put (&fileNameKey, (void* )fileName.get ());
rv = properties->SetFileName(server->fileName);
NS_ENSURE_SUCCESS(rv,rv);
// Set the uri property
nsCStringKey URIKey (kURIPropertyName, -1, nsCStringKey::NEVER_OWN);
nsCAutoString URIUTF8 (server->uri);
nsCAutoString URI (server->uri);
// This is in case the uri is never set
// in the nsDirPref.cpp code.
if (!server->uri)
{
URIUTF8 = kMDBDirectoryRoot;
URIUTF8.Append (server->fileName);
URI = NS_LITERAL_CSTRING(kMDBDirectoryRoot) + nsDependentCString(server->fileName);
}
/*
* Check that we are not converting from a
* a 4.x address book file e.g. pab.na2
* check if the URI ends with ".na2"
*/
nsCAutoString uriName (URIUTF8.get());
pos = uriName.Find("na2");
if (pos >= 0)
{
const char* tempFileName = nsnull;
const char* uri = URIUTF8.get ();
if (PL_strstr(uri, kMDBDirectoryRoot)) // for moz-abmdbdirectory://
{
tempFileName = &(uri[PL_strlen(kMDBDirectoryRoot)]);
uriName.ReplaceSubstring (tempFileName,server->fileName);
}
if (Substring(URI, URI.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffixLen).Equals(kABFileName_PreviousSuffix)) {
URI.ReplaceSubstring(URI.get() + kMDBDirectoryRootLen, server->fileName);
}
NS_ConvertUTF8toUCS2 URIUCS2 (uriName.get ());
propertySet.Put (&URIKey, (void* )URIUCS2.get ());
// Convert the hastable (property set) to pointer
// arrays, using the array guards
CharPtrArrayGuard factoryPropertyNames (PR_FALSE);
PRUnicharPtrArrayGuard factoryPropertyValues (PR_FALSE);
HashtableToPropertyPtrArrays::Convert (propertySet,
factoryPropertyNames.GetSizeAddr (),
factoryPropertyNames.GetArrayAddr (),
factoryPropertyValues.GetArrayAddr ());
*(factoryPropertyNames.GetSizeAddr ()) = factoryPropertyNames.GetSize ();
rv = properties->SetPrefName(server->prefName);
NS_ENSURE_SUCCESS(rv,rv);
rv = properties->SetURI(URI.get());
NS_ENSURE_SUCCESS(rv,rv);
// Create the directories
rv = CreateDirectoriesFromFactory (uriName.get (),
server,
factoryPropertyNames.GetSize (),
factoryPropertyNames.GetArray(),
factoryPropertyValues.GetArray(),
PR_FALSE);
rv = CreateDirectoriesFromFactory(properties,
server, PR_FALSE /* notify */);
}
mInitialized = PR_TRUE;
@ -254,34 +226,7 @@ NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsIEnumerator* *result)
return mSubDirectories->Enumerate(result);
}
nsresult nsAbBSDirectory::CreateNewDirectory(nsHashtable &propertySet, const char *uri, DIR_Server* server)
{
nsresult rv;
// Convert the hastable (property set) to pointer
// arrays, using the array guards
// This is done because the original hashtable
// has been modified (added the uri and changed
// the file name)
CharPtrArrayGuard factoryPropertyNames (PR_FALSE);
PRUnicharPtrArrayGuard factoryPropertyValues (PR_FALSE);
HashtableToPropertyPtrArrays::Convert (propertySet,
factoryPropertyNames.GetSizeAddr (),
factoryPropertyNames.GetArrayAddr (),
factoryPropertyValues.GetArrayAddr ());
*(factoryPropertyNames.GetSizeAddr ()) = factoryPropertyNames.GetSize ();
// Create the directories
rv = CreateDirectoriesFromFactory (uri,
server,
factoryPropertyNames.GetSize (),
factoryPropertyNames.GetArray(),
factoryPropertyValues.GetArray());
return rv;
}
NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 propCount, const char **propName, const PRUnichar **propValue)
NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(nsIAbDirectoryProperties *aProperties)
{
/*
* TODO
@ -290,35 +235,17 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 propCount, const char
* nsDirPref.cpp code
*
*/
if (!propValue || !propName)
return NS_ERROR_NULL_POINTER;
if (propCount == 0)
return NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(aProperties);
nsresult rv;
// Create hash table from property arrays
nsHashtable propertySet;
rv = PropertyPtrArraysToHashtable::Convert (propertySet, propCount, propName, propValue);
NS_ENSURE_SUCCESS (rv, rv);
nsAutoString description;
nsXPIDLCString fileName;
// Get description property
nsCStringKey descriptionKey (kDescriptionPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* description = (PRUnichar* )propertySet.Get (&descriptionKey);
rv = aProperties->GetDescription(description);
NS_ENSURE_SUCCESS(rv, rv);
// Get file name property
nsCStringKey fileNameKey (kFileNamePropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* fileName = (PRUnichar* )propertySet.Get (&fileNameKey);
NS_ConvertUCS2toUTF8 fileNameUTF8(fileName);
// Get migrating property
nsCStringKey migratingKey (kMigratingPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* migrating = (PRUnichar* )propertySet.Get (&migratingKey);
PRBool is_migrating = PR_FALSE;
if (migrating && nsCRT::strcmp (migrating, NS_LITERAL_STRING("true").get()))
is_migrating = PR_TRUE;
rv = aProperties->GetFileName(getter_Copies(fileName));
NS_ENSURE_SUCCESS(rv, rv);
/*
* The creation of the address book in the preferences
@ -330,72 +257,62 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(PRUint32 propCount, const char
*
*/
DIR_Server* server = nsnull;
rv = DIR_AddNewAddressBook(description,
(fileNameUTF8.Length ()) ? fileNameUTF8.get () : nsnull,
is_migrating,
rv = DIR_AddNewAddressBook(description.get(),
(fileName.Length ()) ? fileName.get () : nsnull,
PR_FALSE /* is_migrating */,
PABDirectory,
&server);
NS_ENSURE_SUCCESS (rv, rv);
// Update the file name property
NS_ConvertUTF8toUCS2 fileNameUCS2(server->fileName);
propertySet.Put (&fileNameKey, (void* )fileNameUCS2.get ());
rv = aProperties->SetFileName(server->fileName);
NS_ENSURE_SUCCESS(rv, rv);
// Add the URI property
nsAutoString URI;
URI.AssignWithConversion (kMDBDirectoryRoot);
URI.Append (fileNameUCS2);
nsCStringKey URIKey (kURIPropertyName, -1, nsCStringKey::NEVER_OWN);
propertySet.Put (&URIKey, (void* )URI.get ());
// Get the directory factory from the URI
NS_ConvertUCS2toUTF8 URIUTF8(URI);
rv = CreateNewDirectory (propertySet, URIUTF8.get (), server);
nsCAutoString URI(NS_LITERAL_CSTRING(kMDBDirectoryRoot) + nsDependentCString(server->fileName));
rv = aProperties->SetURI(URI.get());
NS_ENSURE_SUCCESS(rv, rv);
rv = CreateDirectoriesFromFactory(aProperties, server, PR_TRUE /* notify */);
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const PRUnichar *displayName, const char *uri, PRBool migrating)
NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const PRUnichar *aDisplayName, const char *aURI, PRBool migrating)
{
if (!displayName || !uri)
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aURI);
NS_ENSURE_ARG_POINTER(aDisplayName);
nsresult rv = NS_OK;
const char* fileName = nsnull;
if (PL_strstr(uri, kMDBDirectoryRoot)) // for moz-abmdbdirectory://
fileName = &(uri[nsCRT::strlen(kMDBDirectoryRoot)]);
nsCAutoString uriStr(aURI);
if (Substring(uriStr, 0, kMDBDirectoryRootLen).Equals(kMDBDirectoryRoot))
fileName = aURI + kMDBDirectoryRootLen;
DIR_Server * server = nsnull;
rv = DIR_AddNewAddressBook(displayName, fileName, migrating, PABDirectory, &server);
rv = DIR_AddNewAddressBook(aDisplayName, fileName, migrating, PABDirectory, &server);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIAbDirectoryProperties> properties;
properties = do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsHashtable propertySet;
// Set the description property
nsCStringKey descriptionKey (kDescriptionPropertyName, -1, nsCStringKey::NEVER_OWN);
propertySet.Put (&descriptionKey, (void* )displayName);
rv = properties->SetDescription(nsDependentString(aDisplayName));
NS_ENSURE_SUCCESS(rv,rv);
// Set the file name property
nsCStringKey fileNameKey (kFileNamePropertyName, -1, nsCStringKey::NEVER_OWN);
NS_ConvertUTF8toUCS2 fileNameUCS2 (server->fileName);
propertySet.Put (&fileNameKey, (void* )fileNameUCS2.get ());
// Set the uri property
nsCStringKey URIKey (kURIPropertyName, -1, nsCStringKey::NEVER_OWN);
NS_ConvertUTF8toUCS2 URIUCS2 (uri);
propertySet.Put (&URIKey, (void* )URIUCS2.get ());
rv = properties->SetFileName(server->fileName);
NS_ENSURE_SUCCESS(rv,rv);
rv = CreateNewDirectory (propertySet, uri, server);
rv = properties->SetURI(aURI);
NS_ENSURE_SUCCESS(rv,rv);
rv = CreateDirectoriesFromFactory(properties, server, PR_TRUE /* notify */);
NS_ENSURE_SUCCESS(rv,rv);
return rv;
}
struct GetDirectories
{
GetDirectories (DIR_Server* aServer) :

Просмотреть файл

@ -55,29 +55,19 @@ public:
// nsIAbDirectory methods
NS_IMETHOD GetChildNodes(nsIEnumerator* *result);
NS_IMETHOD CreateNewDirectory(PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue);
NS_IMETHOD CreateNewDirectory(nsIAbDirectoryProperties *aProperties);
NS_IMETHOD CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating);
NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
protected:
nsresult AddDirectory(const char *uriName, nsIAbDirectory **childDir);
nsVoidArray* GetDirList(){ return DIR_GetDirectories(); }
nsresult NotifyItemAdded(nsISupports *item);
nsresult NotifyItemDeleted(nsISupports *item);
nsresult CreateDirectoriesFromFactory(
const char* URI,
DIR_Server* server,
PRUint32 propertiesSize,
const char** propertyNameArray,
const PRUnichar** propertyValueArray,
PRBool notify = PR_TRUE);
nsresult CreateNewDirectory(nsHashtable &propertySet,
const char *uri,
DIR_Server* server);
nsIAbDirectoryProperties *aProperties,
DIR_Server* aServer, PRBool aNotify);
protected:
PRBool mInitialized;

Просмотреть файл

@ -41,9 +41,6 @@
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsAbBaseCID.h"
#include "prmem.h"
#include "prlog.h"
#include "prprf.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
@ -105,7 +102,7 @@ static const char *CARD_ATTRS_ARRAY[] = {
nsAbCardProperty::nsAbCardProperty(void)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
m_LastModDate = 0;

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -50,14 +51,11 @@
#include "rdf.h"
#include "mdb.h"
#include "prlog.h"
#include "prprf.h"
#include "prmem.h"
nsAbDirProperty::nsAbDirProperty(void)
: m_LastModifiedDate(0)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
m_IsMailList = PR_FALSE;
}
@ -68,15 +66,11 @@ nsAbDirProperty::~nsAbDirProperty(void)
NS_IMPL_ISUPPORTS1(nsAbDirProperty,nsIAbDirectory)
/* readonly attribute long operations; */
NS_IMETHODIMP nsAbDirProperty::GetOperations(PRInt32 *aOperations)
{
/*
* Default is to support all operations.
* Inheriting implementations may override
* to reduce supported operations
*
*/
// Default is to support all operations.
// Inheriting implementations may override
// to reduce supported operations
*aOperations = nsIAbDirectory::opRead |
nsIAbDirectory::opWrite |
nsIAbDirectory::opSearch;
@ -252,7 +246,7 @@ nsAbDirProperty::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP
nsAbDirProperty::CreateNewDirectory(PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue)
nsAbDirProperty::CreateNewDirectory(nsIAbDirectoryProperties *aProperties)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHODIMP nsAbDirProperty::CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating)
@ -290,4 +284,81 @@ NS_IMETHODIMP nsAbDirProperty::GetIsRemote(PRBool *aIsRemote)
return NS_OK;
}
NS_IMETHODIMP nsAbDirProperty::GetSearchDuringLocalAutocomplete(PRBool *aSearchDuringLocalAutocomplete)
{
NS_ENSURE_ARG_POINTER(aSearchDuringLocalAutocomplete);
*aSearchDuringLocalAutocomplete = PR_TRUE;
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
nsAbDirectoryProperties::nsAbDirectoryProperties(void)
{
NS_INIT_ISUPPORTS();
}
nsAbDirectoryProperties::~nsAbDirectoryProperties(void)
{
}
NS_IMPL_ISUPPORTS1(nsAbDirectoryProperties,nsIAbDirectoryProperties)
NS_IMETHODIMP
nsAbDirectoryProperties::SetDescription(const nsAString &aDescription)
{
mDescription = aDescription;
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::GetDescription(nsAString &aDescription)
{
aDescription = mDescription;
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::SetURI(const char *aURI)
{
mURI = aURI;
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::GetURI(char **aURI)
{
NS_ENSURE_ARG_POINTER(aURI);
*aURI = ToNewCString(mURI);
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::SetFileName(const char *aFileName)
{
mFileName = aFileName;
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::GetFileName(char **aFileName)
{
NS_ENSURE_ARG_POINTER(aFileName);
*aFileName = ToNewCString(mFileName);
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::SetPrefName(const char *aPrefName)
{
mPrefName = aPrefName;
return NS_OK;
}
NS_IMETHODIMP
nsAbDirectoryProperties::GetPrefName(char **aPrefName)
{
NS_ENSURE_ARG_POINTER(aPrefName);
*aPrefName = ToNewCString(mPrefName);
return NS_OK;
}

Просмотреть файл

@ -83,4 +83,19 @@ protected:
};
class nsAbDirectoryProperties: public nsIAbDirectoryProperties
{
public:
nsAbDirectoryProperties(void);
virtual ~nsAbDirectoryProperties(void);
NS_DECL_ISUPPORTS
NS_DECL_NSIABDIRECTORYPROPERTIES
private:
nsString mDescription;
nsCString mURI;
nsCString mFileName;
nsCString mPrefName;
};
#endif

Просмотреть файл

@ -45,7 +45,6 @@
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "prthread.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQuerySimpleBooleanExpression, nsIAbBooleanExpression)

Просмотреть файл

@ -35,7 +35,6 @@
#include "nsIMsgHeaderParser.h"
#include "nsILDAPMessage.h"
#include "nsLDAP.h"
#include "prlog.h"
#include "nsReadableUtils.h"
#include "nsIStringBundle.h"
#include "nsISupportsPrimitives.h"

Просмотреть файл

@ -19,9 +19,13 @@
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Created by: Paul Sandoz <paul.sandoz@sun.com>
* Contributor(s): Csaba Borbola <csaba.borbola@sun.com>
*
* Original Author:
* Paul Sandoz <paul.sandoz@sun.com>
*
* Contributors:
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -50,16 +54,8 @@
#include "nsIAddressBook.h"
#include "nsEnumeratorUtils.h"
#include "nsAbBaseCID.h"
extern const char* kDescriptionPropertyName;
extern const char* kURIPropertyName;
NS_IMPL_ISUPPORTS1(nsAbLDAPDirFactory, nsIAbDirFactory);
nsAbLDAPDirFactory::nsAbLDAPDirFactory()
@ -71,57 +67,67 @@ nsAbLDAPDirFactory::~nsAbLDAPDirFactory()
{
}
/* nsISimpleEnumerator createDirectory (in unsigned long propertiesSize, [array, size_is (propertiesSize)] in string propertyNamesArray, [array, size_is (propertiesSize)] in wstring propertyValuesArray); */
NS_IMETHODIMP nsAbLDAPDirFactory::CreateDirectory(
PRUint32 propertiesSize,
const char **propertyNamesArray,
const PRUnichar **propertyValuesArray,
nsISimpleEnumerator **_retval)
NS_IMETHODIMP nsAbLDAPDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProperties,
nsISimpleEnumerator **aDirectories)
{
if (!*propertyNamesArray || !*propertyValuesArray)
return NS_ERROR_NULL_POINTER;
if (propertiesSize == 0)
return NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(aProperties);
NS_ENSURE_ARG_POINTER(aDirectories);
nsresult rv;
// Create hash table from property arrays
nsHashtable propertySet;
rv = PropertyPtrArraysToHashtable::Convert (
propertySet,
propertiesSize,
propertyNamesArray,
propertyValuesArray);
NS_ENSURE_SUCCESS (rv, rv);
// Get description property
nsCStringKey descriptionKey (kDescriptionPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* description = NS_REINTERPRET_CAST(PRUnichar* ,propertySet.Get (&descriptionKey));
// Get uri property
nsCStringKey URIKey (kURIPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* URIUCS2 = NS_REINTERPRET_CAST(PRUnichar* ,propertySet.Get (&URIKey));
if (!URIUCS2)
return NS_ERROR_FAILURE;
NS_ConvertUCS2toUTF8 URIUTF8(URIUCS2);
nsXPIDLCString uri;
nsAutoString description;
rv = aProperties->GetDescription(description);
NS_ENSURE_SUCCESS(rv, rv);
rv = aProperties->GetURI(getter_Copies(uri));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFResource> resource;
rv = rdf->GetResource(URIUTF8.get (), getter_AddRefs(resource));
if ((strncmp(uri.get(), "ldap:", 5) == 0) ||
(strncmp(uri.get(), "ldaps:", 6) == 0)) {
nsXPIDLCString prefName;
rv = aProperties->GetPrefName(getter_Copies(prefName));
NS_ENSURE_SUCCESS(rv, rv);
/*
* if the URI starts with ldap: or ldaps:
* then this directory is an LDAP directory.
*
* we don't want to use the ldap:// or ldaps:// URI
* as the RDF resource URI because the ldap:// or ldaps:// URI
* will contain the hostname, basedn, port, etc.
* so if those attributes changed, we'll run into the
* the same problem that we hit with changing username / hostname
* for mail servers. to solve this problem, we add an extra
* level of indirection. the RDF resource URI that we generate
* (the bridge URI) will be moz-abldapdirectory://<prefName>
* and when we need the hostname, basedn, port, etc,
* we'll use the <prefName> to get the necessary prefs.
* note, <prefName> does not change.
*/
nsCAutoString bridgeURI;
bridgeURI = NS_LITERAL_CSTRING(kLDAPDirectoryRoot) + prefName;
rv = rdf->GetResource(bridgeURI.get(), getter_AddRefs(resource));
}
else {
rv = rdf->GetResource(uri.get(), getter_AddRefs(resource));
}
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
NS_ENSURE_SUCCESS(rv, rv);
directory->SetDirName(description);
rv = directory->SetDirName(description.get());
NS_ENSURE_SUCCESS(rv,rv);
NS_IF_ADDREF(*_retval = new nsSingletonEnumerator(directory));
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
NS_IF_ADDREF(*aDirectories = new nsSingletonEnumerator(directory));
return *aDirectories ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/* void deleteDirectory (in nsIAbDirectory directory); */

Просмотреть файл

@ -52,5 +52,4 @@ public:
virtual ~nsAbLDAPDirFactory();
};
#endif

Просмотреть файл

@ -14,13 +14,13 @@
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Initial Developer of the Original Code is Paul Sandoz <paul.sandoz@sun.com>
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Created by: Paul Sandoz <paul.sandoz@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -44,12 +44,12 @@
#include "nsAbBaseCID.h"
#include "nsIAddrBookSession.h"
#include "nsIRDFService.h"
#include "nsIPref.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prprf.h"
#include "nsAutoLock.h"
@ -71,14 +71,12 @@ nsAbLDAPDirectory::~nsAbLDAPDirectory()
}
NS_IMPL_ISUPPORTS_INHERITED3(nsAbLDAPDirectory, nsAbDirectoryRDFResource, nsIAbDirectory, nsIAbDirectoryQuery, nsIAbDirectorySearch)
nsresult nsAbLDAPDirectory::Initiate ()
{
if (mIsQueryURI == PR_FALSE)
if (!mIsQueryURI)
return NS_ERROR_FAILURE;
if (mInitialized == PR_TRUE)
if (mInitialized)
return NS_OK;
nsresult rv;
@ -101,7 +99,7 @@ nsresult nsAbLDAPDirectory::Initiate ()
nsresult nsAbLDAPDirectory::InitiateConnection ()
{
if (mInitializedConnection == PR_TRUE)
if (mInitializedConnection)
return NS_OK;
nsresult rv;
@ -109,10 +107,20 @@ nsresult nsAbLDAPDirectory::InitiateConnection ()
mURL = do_CreateInstance(NS_LDAPURL_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString uriString (mURINoQuery);
uriString.ReplaceSubstring ("moz-abldapdirectory:", "ldap:");
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv,rv);
rv = mURL->SetSpec(uriString.get ());
// turn mURINoQuery into a pref name;
// moz-abldapdirectory://ldap_2.servers.nscpphonebook into -> "ldap_2.servers.nscpphonebook.uri"
nsCAutoString prefName;
prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) + NS_LITERAL_CSTRING(".uri");
nsXPIDLCString ldapURL;
rv = pref->CopyCharPref(prefName.get(), getter_Copies(ldapURL));
NS_ENSURE_SUCCESS(rv,rv);
rv = mURL->SetSpec(ldapURL.get());
NS_ENSURE_SUCCESS(rv, rv);
mConnection = do_CreateInstance(NS_LDAPCONNECTION_CONTRACTID, &rv);
@ -174,7 +182,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::HasCard(nsIAbCard* card, PRBool* hasCard)
nsAutoLock lock (mLock);
*hasCard = mCache.Exists (&key);
if (*hasCard == PR_FALSE && mPerformingQuery == PR_TRUE)
if (!*hasCard && mPerformingQuery)
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
@ -229,11 +237,9 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSearch ()
{
nsresult rv;
if (mIsQueryURI == PR_FALSE ||
mQueryString.Length () == 0)
if (!mIsQueryURI || mQueryString.IsEmpty())
return NS_OK;
rv = Initiate ();
NS_ENSURE_SUCCESS(rv, rv);
@ -295,7 +301,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::StopSearch ()
// Enter lock
{
nsAutoLock lockGuard (mLock);
if (mPerformingQuery == PR_FALSE)
if (!mPerformingQuery)
return NS_OK;
mPerformingQuery = PR_FALSE;
}
@ -360,3 +366,15 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetIsRemote(PRBool *aIsRemote)
*aIsRemote = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP nsAbLDAPDirectory::GetSearchDuringLocalAutocomplete(PRBool *aSearchDuringLocalAutocomplete)
{
NS_ENSURE_ARG_POINTER(aSearchDuringLocalAutocomplete);
// always skip LDAP directories when doing local autocomplete.
// we do the LDAP autocompleting
// in nsLDAPAutoCompleteSession
*aSearchDuringLocalAutocomplete = PR_FALSE;
return NS_OK;
}

Просмотреть файл

@ -14,13 +14,13 @@
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Initial Developer of the Original Code is Paul Sandoz <paul.sandoz@sun.com>
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Created by: Paul Sandoz <paul.sandoz@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -67,6 +67,7 @@ public:
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
NS_IMETHOD GetSupportsMailingLists(PRBool *aSupportsMailingsLists);
NS_IMETHOD GetIsRemote(PRBool *aIsRemote);
NS_IMETHOD GetSearchDuringLocalAutocomplete(PRBool *aSearchDuringLocalAutocomplete);
// nsAbLDAPDirectoryQuery methods
nsresult GetLDAPConnection (nsILDAPConnection** connection);
@ -85,9 +86,9 @@ protected:
nsresult InitiateConnection ();
protected:
PRBool mInitialized;
PRBool mInitializedConnection;
PRBool mPerformingQuery;
PRPackedBool mInitialized;
PRPackedBool mInitializedConnection;
PRPackedBool mPerformingQuery;
PRInt32 mContext;
PRInt32 mMaxHits;

Просмотреть файл

@ -49,6 +49,7 @@
#include "nsXPIDLString.h"
#include "nsAutoLock.h"
#include "nsIProxyObjectManager.h"
#include "prprf.h"
class nsAbQueryLDAPMessageListener : public nsILDAPMessageListener
{

Просмотреть файл

@ -39,9 +39,6 @@
#ifndef nsAbLDAPProperties_h__
#define nsAbLDAPProperties_h__
#include "prio.h"
#include "nsMemory.h"
#include "nsILDAPMessage.h"
#include "nsIAbCard.h"
#include "nsHashtable.h"

Просмотреть файл

@ -44,9 +44,6 @@
#include "nsReadableUtils.h"
#include "nsCOMPtr.h"
#include "nsAbBaseCID.h"
#include "prmem.h"
#include "prlog.h"
#include "prprf.h"
#include "nsAddrDatabase.h"
#include "nsIAddrBookSession.h"

Просмотреть файл

@ -42,9 +42,6 @@
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsAbBaseCID.h"
#include "prmem.h"
#include "prlog.h"
#include "prprf.h"
#include "rdf.h"
#include "nsCOMPtr.h"
@ -254,7 +251,7 @@ nsresult nsAbMDBCardProperty::GetCardDatabase(const char *uri)
abSession->GetUserProfileDirectory(&dbPath);
const char* file = nsnull;
file = &(uri[PL_strlen(kMDBDirectoryRoot)]);
file = &(uri[kMDBDirectoryRootLen]);
(*dbPath) += file;
if (dbPath->Exists())

Просмотреть файл

@ -20,8 +20,9 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Paul Sandoz <paul.sandoz@sun.com>
* Paul Sandoz <paul.sandoz@sun.com>
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -55,13 +56,6 @@
#include "nsAbBaseCID.h"
extern const char* kDescriptionPropertyName;
extern const char* kURIPropertyName;
NS_IMPL_ISUPPORTS1(nsAbMDBDirFactory, nsIAbDirFactory);
nsAbMDBDirFactory::nsAbMDBDirFactory()
@ -73,7 +67,6 @@ nsAbMDBDirFactory::~nsAbMDBDirFactory()
{
}
static nsresult RemoveMailListDBListeners (nsIAddrDatabase* database, nsIAbDirectory* directory)
{
nsresult rv;
@ -106,53 +99,35 @@ static nsresult RemoveMailListDBListeners (nsIAddrDatabase* database, nsIAbDirec
return NS_OK;
}
/* nsISimpleEnumerator createDirectory (in unsigned long propertiesSize, [array, size_is (propertiesSize)] in string propertyNamesArray, [array, size_is (propertiesSize)] in wstring propertyValuesArray); */
NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(
PRUint32 propertiesSize,
const char **propertyNamesArray,
const PRUnichar **propertyValuesArray,
NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProperties,
nsISimpleEnumerator **_retval)
{
if (!*propertyNamesArray || !*propertyValuesArray)
return NS_ERROR_NULL_POINTER;
if (propertiesSize == 0)
return NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(aProperties);
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
// Create hash table from property arrays
nsHashtable propertySet;
rv = PropertyPtrArraysToHashtable::Convert (
propertySet,
propertiesSize,
propertyNamesArray,
propertyValuesArray);
NS_ENSURE_SUCCESS (rv, rv);
nsXPIDLCString uri;
nsAutoString description;
// Get description property
nsCStringKey descriptionKey (kDescriptionPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* description = NS_REINTERPRET_CAST(PRUnichar*, propertySet.Get (&descriptionKey));
rv = aProperties->GetDescription(description);
NS_ENSURE_SUCCESS(rv, rv);
// Get uri property
nsCStringKey URIKey (kURIPropertyName, -1, nsCStringKey::NEVER_OWN);
const PRUnichar* URIUCS2 = NS_REINTERPRET_CAST(PRUnichar*, propertySet.Get (&URIKey));
if (!URIUCS2)
return NS_ERROR_FAILURE;
NS_ConvertUCS2toUTF8 URIUTF8(URIUCS2);
rv = aProperties->GetURI(getter_Copies(uri));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFResource> resource;
rv = rdf->GetResource(URIUTF8.get (), getter_AddRefs(resource));
rv = rdf->GetResource(uri.get(), getter_AddRefs(resource));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
NS_ENSURE_SUCCESS(rv, rv);
directory->SetDirName(description);
rv = directory->SetDirName(description.get());
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -163,12 +138,13 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(
nsCOMPtr<nsIAddrDatabase> listDatabase;
if (dbPath)
{
const char* fileName = nsnull;
const char* uri = URIUTF8.get ();
if (PL_strstr(uri, kMDBDirectoryRoot)) // for moz-abmdbdirectory://
fileName = &(uri[PL_strlen(kMDBDirectoryRoot)]);
nsCAutoString fileName;
nsDependentCString uriStr(uri);
if (Substring(uriStr, 0, kMDBDirectoryRootLen).Equals(kMDBDirectoryRoot))
uriStr.Right(fileName, uriStr.Length() - kMDBDirectoryRootLen);
(*dbPath) += fileName;
(*dbPath) += fileName.get();
nsCOMPtr<nsIAddrDatabase> addrDBFactory = do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -53,9 +53,6 @@
#include "nsIAbMDBCard.h"
#include "mdb.h"
#include "prlog.h"
#include "prprf.h"
#include "prmem.h"
nsAbMDBDirProperty::nsAbMDBDirProperty(void)
{

Просмотреть файл

@ -59,9 +59,7 @@
#include "nsAbMDBCardProperty.h"
#include "mdb.h"
#include "prlog.h"
#include "prprf.h"
#include "prmem.h"
// XXX todo
// fix this -1,0,1 crap, use an enum or #define
@ -276,13 +274,11 @@ NS_IMETHODIMP nsAbMDBDirectory::Init(const char* aURI)
rv = url->GetPath (getter_Copies(path));
mPath = path;
PRUint32 queryStringLength;
if (queryString.get () && (queryStringLength = nsCRT::strlen (queryString)))
if (!queryString.IsEmpty())
{
int pathLength = nsCRT::strlen (path) - queryStringLength - 1;
mPath.Truncate (pathLength);
mPath.Truncate(path.Length() - queryString.Length() - 1);
mURINoQuery.Truncate (mURINoQuery.Length () - queryStringLength - 1);
mURINoQuery.Truncate(mURINoQuery.Length() - queryString.Length() - 1);
mQueryString = queryString;
@ -426,9 +422,13 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result)
if (mURI && mIsMailingList == -1)
{
NS_ConvertUTF8toUCS2 file(&(mURI[strlen(kMDBDirectoryRoot)]));
PRInt32 pos = file.Find("/");
if (pos != kNotFound)
/* directory URIs are of the form
* moz-abmdbdirectory://foo
* mailing list URIs are of the form
* moz-abmdbdirectory://foo/bar
*/
NS_ENSURE_TRUE(strlen(mURI) > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI + kMDBDirectoryRootLen, '/'))
mIsMailingList = 1;
else
mIsMailingList = 0;
@ -644,11 +644,8 @@ NS_IMETHODIMP nsAbMDBDirectory::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir
return rv;
}
NS_IMETHODIMP nsAbMDBDirectory::CreateNewDirectory(PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue)
NS_IMETHODIMP nsAbMDBDirectory::CreateNewDirectory(nsIAbDirectoryProperties *aProperties)
{
if (!*prefName || !*prefValue)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -760,9 +757,13 @@ NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, PRBool needToCopyCard
if (mURI && mIsMailingList == -1)
{
NS_ConvertUTF8toUCS2 file(&(mURI[strlen(kMDBDirectoryRoot)]));
PRInt32 pos = file.Find("/");
if (pos != kNotFound)
/* directory URIs are of the form
* moz-abmdbdirectory://foo
* mailing list URIs are of the form
* moz-abmdbdirectory://foo/bar
*/
NS_ENSURE_TRUE(strlen(mURI) > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI + kMDBDirectoryRootLen, '/'))
mIsMailingList = 1;
else
mIsMailingList = 0;
@ -905,7 +906,7 @@ NS_IMETHODIMP nsAbMDBDirectory::OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instiga
NS_IMETHODIMP nsAbMDBDirectory::StartSearch()
{
if (mIsQueryURI == PR_FALSE)
if (!mIsQueryURI)
return NS_ERROR_FAILURE;
nsresult rv;
@ -967,7 +968,7 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSearch()
NS_IMETHODIMP nsAbMDBDirectory::StopSearch()
{
if (mIsQueryURI == PR_FALSE)
if (!mIsQueryURI)
return NS_ERROR_FAILURE;
return NS_OK;

Просмотреть файл

@ -91,7 +91,7 @@ public:
NS_IMETHOD DeleteCards(nsISupportsArray *cards);
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
NS_IMETHOD CreateNewDirectory(PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue);
NS_IMETHOD CreateNewDirectory(nsIAbDirectoryProperties *aProperties);
NS_IMETHOD CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating);
NS_IMETHOD AddMailList(nsIAbDirectory *list);
NS_IMETHOD AddCard(nsIAbCard *card, nsIAbCard **addedCard);
@ -116,8 +116,6 @@ protected:
nsresult AddMailList(const char *uriName);
nsVoidArray* GetDirList(){ return DIR_GetDirectories(); }
nsresult GetAbDatabase();
nsCOMPtr<nsIAddrDatabase> mDatabase;

Просмотреть файл

@ -46,8 +46,6 @@
#include "nsAbBaseCID.h"
#include "prprf.h"
#include "prlog.h"
#ifdef PR_LOGGING
@ -79,42 +77,35 @@ nsAbOutlookDirFactory::~nsAbOutlookDirFactory(void)
}
extern const char *kOutlookDirectoryScheme ;
extern const char *kURIPropertyName ;
static void parseProperties(PRUint32 aNbProperties, const char **aPropertyNames,
const PRUnichar **aPropertyValues, nsAbWinType& aWinType)
static nsresult parseProperties(nsIAbDirectoryProperties *aProperties, nsAbWinType& aWinType)
{
aWinType = nsAbWinType_Unknown ;
PRUint32 i = 0 ;
for (i = 0 ; i < aNbProperties ; ++ i) {
if (nsCRT::strcmp(aPropertyNames [i], kURIPropertyName) == 0) {
nsCAutoString uri ;
nsXPIDLCString uri;
nsresult rv = aProperties->GetURI(getter_Copies(uri));
NS_ENSURE_SUCCESS(rv,rv);
nsCString stub ;
nsCString entry ;
uri.AssignWithConversion(aPropertyValues [i]) ;
aWinType = getAbWinType(kOutlookDirectoryScheme, uri.get(), stub, entry) ;
break ;
}
}
return NS_OK;
}
NS_IMETHODIMP nsAbOutlookDirFactory::CreateDirectory(PRUint32 aNbProperties,
const char **aPropertyNames,
const PRUnichar **aPropertyValues,
NS_IMETHODIMP nsAbOutlookDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProperties,
nsISimpleEnumerator **aDirectories)
{
if (!aPropertyNames || !aPropertyValues || !aDirectories) {
return NS_ERROR_NULL_POINTER ;
}
NS_ENSURE_ARG_POINTER(aProperties);
NS_ENSURE_ARG_POINTER(aDirectories);
*aDirectories = nsnull ;
nsresult retCode = NS_OK ;
nsAbWinType abType = nsAbWinType_Unknown ;
parseProperties(aNbProperties, aPropertyNames, aPropertyValues, abType) ;
retCode = parseProperties(aProperties, abType) ;
NS_ENSURE_SUCCESS(retCode, retCode);
if (abType == nsAbWinType_Unknown) {
return NS_ERROR_FAILURE ;
}

Просмотреть файл

@ -50,10 +50,8 @@
#include "nsAbQueryStringToExpression.h"
#include "nsAbUtils.h"
#include "prprf.h"
#include "prthread.h"
#include "prlog.h"
#include "prthread.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gAbOutlookDirectoryLog

Просмотреть файл

@ -58,9 +58,6 @@
#include "nsXPIDLString.h"
#include "nsAutoLock.h"
#include "prprf.h"
#include "prlog.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsAbRDFNotification {
nsIRDFDataSource *datasource;
@ -297,8 +294,7 @@ nsAbRDFDataSource::nsAbRDFDataSource():
mRDFService(nsnull),
mLock(nsnull)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mLock = PR_NewLock ();
}

Просмотреть файл

@ -53,8 +53,7 @@ static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
nsAbRDFResource::nsAbRDFResource(void)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mDatabase = nsnull;
}
@ -106,7 +105,7 @@ nsresult nsAbRDFResource::GetAbDatabase()
if(NS_SUCCEEDED(rv))
abSession->GetUserProfileDirectory(&dbPath);
NS_ConvertUTF8toUCS2 file(&(mURI[strlen(kMDBDirectoryRoot)]));
NS_ConvertUTF8toUCS2 file(&(mURI[kMDBDirectoryRootLen]));
PRInt32 pos = file.Find("/");
if (pos != -1)
file.Truncate(pos);

Просмотреть файл

@ -147,105 +147,3 @@ nsresult PRUnicharPtrArrayToStringArray::Convert (nsStringArray& returnPropertie
return NS_OK;
}
/*
* Convert array of keys and values to nsHashtable
*/
nsresult PropertyPtrArraysToHashtable::Convert (
nsHashtable& propertySet,
PRUint32 propertiesSize,
const char** propertyNameArray,
const PRUnichar** propertyValueArray)
{
if (!propertyNameArray || !propertyValueArray)
return NS_ERROR_NULL_POINTER;
if (!propertiesSize)
return NS_OK;
propertySet.Reset ();
for (PRUint32 i = 0; i < propertiesSize; i++)
{
nsCStringKey key (propertyNameArray[i], -1, nsCStringKey::NEVER_OWN);
propertySet.Put (&key, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(PRUnichar *, propertyValueArray[i])));
}
return NS_OK;
}
/*
* nsHashtable enumerator callback data
*
* Contains the key and value arrays and
* the current position a new entry may
* be added
*/
struct closureStruct
{
PRUint32 position;
char** propertyNameArray;
PRUnichar** propertyValueArray;
};
/*
* nsHashtable enumeration callback procedure
*
* References values from the hashtable entry
* into the associated position of the key and
* value arrays
*/
PR_STATIC_CALLBACK(PRBool) enumerateEntries(nsHashKey *aKey, void *aData, void* closure)
{
closureStruct* s = NS_REINTERPRET_CAST(closureStruct*, closure);
nsCStringKey* key = NS_REINTERPRET_CAST(nsCStringKey*, aKey);
s->propertyNameArray[s->position] = NS_CONST_CAST(char* ,key->GetString ());
s->propertyValueArray[s->position] = NS_STATIC_CAST(PRUnichar *, aData);
s->position++;
return PR_TRUE;
}
/*
* Convert nsHashtable to array of keys and values
*/
nsresult HashtableToPropertyPtrArrays::Convert (
nsHashtable& propertySet,
PRUint32* propertiesSize,
char*** propertyNameArray,
PRUnichar*** propertyValueArray)
{
if (!propertyNameArray || !propertyValueArray || !propertiesSize)
return NS_ERROR_NULL_POINTER;
*propertiesSize = propertySet.Count ();
if (*propertiesSize == 0)
return NS_OK;
*propertyNameArray =
NS_STATIC_CAST(char**, nsMemory::Alloc (sizeof (char* ) * (*propertiesSize)));
if (!(*propertyNameArray))
return NS_ERROR_OUT_OF_MEMORY;
*propertyValueArray =
NS_STATIC_CAST(PRUnichar**, nsMemory::Alloc (sizeof (PRUnichar* ) * (*propertiesSize)));
if (!(*propertyValueArray))
{
nsMemory::Free (*propertyNameArray);
return NS_ERROR_OUT_OF_MEMORY;
}
// Set up enumerator callback structure
closureStruct s;
s.position = 0;
s.propertyNameArray = *propertyNameArray;
s.propertyValueArray = *propertyValueArray;
// Enumerate over hashtable entries
propertySet.Enumerate (enumerateEntries, NS_STATIC_CAST(void* ,&s));
return NS_OK;
}

Просмотреть файл

@ -43,8 +43,6 @@
#include "nsMemory.h"
#include "nsVoidArray.h"
#include "nsHashtable.h"
#include "prprf.h"
/*
* Wrapper class to automatically free an array of
@ -233,44 +231,4 @@ public:
const PRUnichar** array);
};
/*
* Helper class to convert a pair of char*
* array of keys and corresponding PRUnichar*
* array of values to a nsHashtable
*
* Does not copy array values. The nsHashtable
* refers directly to the array elements thus
* the contents may only be valid for the scope
* of the arrays
*/
class PropertyPtrArraysToHashtable
{
public:
static nsresult Convert (
nsHashtable& propertySet,
PRUint32 propertiesSize,
const char** propertyNameArray,
const PRUnichar** propertyValueArray);
};
/*
* Helper class to convert a nsHashtable to
* corresponding char* key arrays and PRUnichar*
* arrays
*
* Does not copy nsHashtable keys and values
* thus the elements of the arrays may only be
* valid for the scope of the hashtable
*/
class HashtableToPropertyPtrArrays
{
public:
static nsresult Convert (
nsHashtable& propertySet,
PRUint32* propertiesSize,
char*** propertyNameArray,
PRUnichar*** propertyValueArray);
};
#endif
#endif /* nsAbUtils_h__ */

Просмотреть файл

@ -337,9 +337,7 @@ NS_IMETHODIMP nsAbView::GetRowProperties(PRInt32 index, nsISupportsArray *proper
NS_IMETHODIMP nsAbView::GetCellProperties(PRInt32 row, const PRUnichar *colID, nsISupportsArray *properties)
{
// XXX todo remove once #116341 is fixed
if (!colID[0])
return NS_OK;
NS_ENSURE_TRUE(row >= 0, NS_ERROR_UNEXPECTED);
if (mCards.Count() <= row)
return NS_OK;
@ -453,9 +451,7 @@ nsresult nsAbView::GetCardValue(nsIAbCard *card, const PRUnichar *colID, PRUnich
NS_IMETHODIMP nsAbView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval)
{
// XXX todo remove once #116341 is fixed
if (!colID[0])
return NS_OK;
NS_ENSURE_TRUE(row >= 0, NS_ERROR_UNEXPECTED);
nsIAbCard *card = ((AbCard *)(mCards.ElementAt(row)))->card;
// XXX fix me by converting GetCardValue to take an nsAString&
@ -534,10 +530,12 @@ NS_IMETHODIMP nsAbView::PerformActionOnCell(const PRUnichar *action, PRInt32 row
NS_IMETHODIMP nsAbView::GetCardFromRow(PRInt32 row, nsIAbCard **aCard)
{
*aCard = nsnull;
if ((mCards.Count() <= row) || (row < 0)) {
if (mCards.Count() <= row) {
return NS_OK;
}
NS_ENSURE_TRUE(row >= 0, NS_ERROR_UNEXPECTED);
AbCard *a = ((AbCard *)(mCards.ElementAt(row)));
if (!a)
return NS_OK;

Просмотреть файл

@ -65,7 +65,7 @@
nsAddbookProtocolHandler::nsAddbookProtocolHandler()
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mAddbookOperation = nsIAddbookUrlOperation::InvalidUrl;
}

Просмотреть файл

@ -51,7 +51,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsAddrBookSession, nsIAddrBookSession)
nsAddrBookSession::nsAddrBookSession():
mRefCnt(0)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
}
nsAddrBookSession::~nsAddrBookSession()

Просмотреть файл

@ -52,9 +52,6 @@
#include "nsIAbMDBDirectory.h"
#include "nsIAddrBookSession.h"
#include "prmem.h"
#include "prprf.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
@ -65,6 +62,7 @@
#include "nsIRDFService.h"
#include "nsIProxyObjectManager.h"
#include "nsProxiedService.h"
#include "prprf.h"
#define ID_PAB_TABLE 1
@ -141,7 +139,7 @@ nsAddrDatabase::nsAddrDatabase()
m_LastRecordKey(0),
m_dbDirectory(nsnull)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
}
nsAddrDatabase::~nsAddrDatabase()
@ -2651,7 +2649,7 @@ protected:
nsAddrDBEnumerator::nsAddrDBEnumerator(nsAddrDatabase* db)
: mDB(db), mRowCursor(nsnull), mCurrentRow(nsnull), mDone(PR_FALSE)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mDbTable = mDB->GetPabTable();
mCurrentRowIsList = PR_FALSE;
}
@ -2775,7 +2773,7 @@ protected:
nsListAddressEnumerator::nsListAddressEnumerator(nsAddrDatabase* db, mdb_id rowID)
: mDB(db), mCurrentRow(nsnull), mListRowID(rowID), mDone(PR_FALSE)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
mDbTable = mDB->GetPabTable();
mDB->GetListRowByRowID(mListRowID, &mListRow);
mAddressTotal = mDB->GetListAddressTotal(mListRow);

Просмотреть файл

@ -163,7 +163,7 @@ static ExportAttributesTableStruct EXPORT_ATTRIBUTES_TABLE[] = {
//
nsAddressBook::nsAddressBook()
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
}
nsAddressBook::~nsAddressBook()
@ -179,13 +179,12 @@ NS_IMPL_QUERY_INTERFACE2(nsAddressBook, nsIAddressBook, nsICmdLineHandler);
// nsIAddressBook
//
NS_IMETHODIMP nsAddressBook::NewAddressBook
(nsIRDFCompositeDataSource* db, PRUint32 prefCount, const char **prefName, const PRUnichar **prefValue)
NS_IMETHODIMP nsAddressBook::NewAddressBook(nsIAbDirectoryProperties *aProperties)
{
if(!db || !*prefName || !*prefValue)
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aProperties);
nsresult rv;
nsresult rv = NS_OK;
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -196,7 +195,7 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook
nsCOMPtr<nsIAbDirectory> parentDir = do_QueryInterface(parentResource, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = parentDir->CreateNewDirectory (prefCount, prefName, prefValue);
rv = parentDir->CreateNewDirectory(aProperties);
return rv;
}
@ -357,9 +356,10 @@ NS_IMETHODIMP nsAddressBook::MailListNameExists(const PRUnichar *name, PRBool *e
DIR_Server *server = (DIR_Server *)pDirectories->ElementAt(i);
if (server->dirType == PABDirectory)
{
nsAutoString dbfile; dbfile.AssignWithConversion(server->fileName);
PRInt32 pos = dbfile.Find("na2");
if (pos >= 0) /* check: this is a 4.x file, remove when conversion is done */
/* check: this is a 4.x file, remove when conversion is done */
PRUint32 fileNameLen = strlen(server->fileName);
if ((fileNameLen > kABFileName_PreviousSuffixLen) &&
strcmp(server->fileName + fileNameLen - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0)
continue;
nsCOMPtr<nsIAddrDatabase> database;
@ -1394,7 +1394,7 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const
for (i = 0; i < EXPORT_ATTRIBUTES_TABLE_COUNT; i++) {
if (EXPORT_ATTRIBUTES_TABLE[i].includeForPlainText) {
// XXX localize this?
length = PL_strlen(EXPORT_ATTRIBUTES_TABLE[i].abColName);
length = strlen(EXPORT_ATTRIBUTES_TABLE[i].abColName);
rv = outputStream->Write(EXPORT_ATTRIBUTES_TABLE_COUNT[i].abColName, length, &writeCount);
NS_ENSURE_SUCCESS(rv,rv);
if (length != writeCount)

Просмотреть файл

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -59,15 +60,6 @@
#define LDAPS_PORT 636
#define PREF_NOERROR 0
/* This format suffix is being defined here because it is needed by the FEs in their
file operation routines */
#define ABFileName_kPreviousSuffix ".na2" /* final v2 address book format */
const char *kMainLdapAddressBook = "ldap.mab"; /* v3 main ldap address book file */
#define ABFileName_kCurrentSuffix ".mab" /* v3 address book extension */
#define ABPabFileName_kCurrent "abook" /* v3 address book name */
#if !defined(MOZADDRSTANDALONE)
typedef enum
@ -348,9 +340,10 @@ static nsresult dir_ConvertToMabFileName()
// do other address book when convert from 4.5 to mork is done
if (server && server->position == 1 && server->fileName)
{
nsString name; name.AssignWithConversion(server->fileName);
PRInt32 pos = name.Find(ABFileName_kPreviousSuffix);
if (pos > 0)
// determine if server->fileName ends with ".na2"
PRUint32 fileNameLen = strlen(server->fileName);
if ((fileNameLen > kABFileName_PreviousSuffixLen) &&
strcmp(server->fileName + fileNameLen - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0)
{
//Move old abook.na2 to end of the list and change the description
DIR_Server * newServer = nsnull;
@ -370,22 +363,6 @@ static nsresult dir_ConvertToMabFileName()
DIR_SavePrefsForOneServer(server);
}
}
#ifdef CONVERT_TO_MORK_DONE
if (server && server->fileName)
{
nsString name(server->fileName);
PRInt32 pos = name.Find(ABFileName_kPreviousSuffix);
if (pos)
{
name.Cut(pos, PL_strlen(ABFileName_kPreviousSuffix));
name.Append(ABFileName_kCurrentSuffix);
PR_FREEIF (server->fileName);
server->fileName = ToNewCString(name);
}
DIR_SavePrefsForOneServer(server);
}
#endif /* CONVERT_TO_MORK_DONE */
}
}
return NS_OK;
@ -1962,6 +1939,13 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server)
if (dbPath)
{
// close the database, as long as it isn't the special ones
// (personal addressbook and collected addressbook)
// which can never be deleted. There was a bug where we would slap in
// "abook.mab" as the file name for LDAP directories, which would cause a crash
// on delete of LDAP directories. this is just extra protection.
if (strcmp(server->fileName, kPersonalAddressbook) &&
strcmp(server->fileName, kCollectedAddressbook)) {
nsCOMPtr<nsIAddrDatabase> database;
(*dbPath) += server->fileName;
@ -1979,6 +1963,7 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server)
}
delete dbPath;
}
nsVoidArray *dirList = DIR_GetDirectories();
DIR_SetServerPosition(dirList, server, DIR_POS_DELETE);
@ -1988,10 +1973,12 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server)
nsCOMPtr<nsIPref> pPref(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_FAILED(rv) || !pPref)
return NS_ERROR_FAILURE;
pPref->SavePrefFile(nsnull);
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
@ -2853,7 +2840,7 @@ void DIR_SetServerFileName(DIR_Server *server, const char* leafName)
server->prefName = DIR_CreateServerPrefName (server, nsnull);
/* set default personal address book file name*/
if (server->position == 1)
if ((server->position == 1) && (server->dirType == PABDirectory))
server->fileName = nsCRT::strdup(kPersonalAddressbook);
else
{
@ -2869,7 +2856,7 @@ void DIR_SetServerFileName(DIR_Server *server, const char* leafName)
if (tempName)
{
server->fileName = PR_smprintf("%s%s", tempName, ABFileName_kCurrentSuffix);
server->fileName = PR_smprintf("%s%s", tempName, kABFileName_CurrentSuffix);
PR_Free(tempName);
}
}
@ -3225,7 +3212,8 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
if ( server->description && server->description[0]
&& ( (server->dirType == PABDirectory ||
server->dirType == MAPIDirectory ||
server->dirType == FixedQueryLDAPDirectory)
server->dirType == FixedQueryLDAPDirectory || // this one might go away
server->dirType == LDAPDirectory)
|| (server->serverName && server->serverName[0])))
{
@ -3433,16 +3421,10 @@ nsresult DIR_GetServerPreferences(nsVoidArray** list)
nsresult rv;
nsCOMPtr <nsIAbUpgrader> abUpgrader = do_GetService(NS_AB4xUPGRADER_CONTRACTID, &rv);
if (NS_FAILED(rv) || !abUpgrader) {
#ifdef DEBUG_sspitzer_
printf("move the pab aside, since we don't have the ab upgrader\n");
#endif
// if we can upgrade, don't touch the 4.x pab.
// if we can't, move the 4.x pab aside
dir_ConvertToMabFileName();
}
#ifdef DEBUG_sspitzer_
else {
printf("don't touch the 4.x pab. we will migrate it\n");
}
#endif
}
/* Write the merged list so we get it next time we ask */
if (savePrefs)
@ -3451,7 +3433,6 @@ nsresult DIR_GetServerPreferences(nsVoidArray** list)
return err;
}
void DIR_ClearPrefBranch(const char *branch)
{
nsresult rv = NS_OK;
@ -3462,7 +3443,6 @@ void DIR_ClearPrefBranch(const char *branch)
pPref->DeleteBranch (branch);
}
static void DIR_ClearIntPref (const char *pref)
{
nsresult rv = NS_OK;

Просмотреть файл

@ -53,12 +53,21 @@ class nsIPref;
#define kMDBDirectoryRoot "moz-abmdbdirectory://"
#define kMDBDirectoryRootLen 21
#define kLDAPDirectoryRoot "moz-abldapdirectory://"
#define kLDAPDirectoryRootLen 22
#define kPersonalAddressbook "abook.mab"
#define kPersonalAddressbookUri "moz-abmdbdirectory://abook.mab"
#define kCollectedAddressbook "history.mab"
#define kCollectedAddressbookUri "moz-abmdbdirectory://history.mab"
#define kABFileName_PreviousSuffix ".na2" /* final v2 address book format */
#define kABFileName_PreviousSuffixLen 4
#define kABFileName_CurrentSuffix ".mab" /* v3 address book extension */
#define kMainLdapAddressBook "ldap.mab" /* v3 main ldap address book file */
/* DIR_Server.dirType */
typedef enum
{

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Seth Spitzer <sspitzer@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -53,9 +54,6 @@
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "prprf.h"
#include "prlog.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsAbRDFNotification {
nsIRDFResource *subject;
@ -702,38 +700,21 @@ nsresult nsAbDirectoryDataSource::DoNewDirectory(nsIAbDirectory *directory, nsIS
nsresult rv = NS_OK;
nsCOMPtr<nsISupports> elem = getter_AddRefs(arguments->ElementAt(0));
nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(elem, &rv);
if(NS_SUCCEEDED(rv))
{
PRUnichar *name;
literal->GetValue(&name);
PRUint32 prefCount = 1;
char **prefNames = (char **) nsMemory::Alloc(prefCount * (sizeof (char *)));
PRUnichar ** prefValues = (PRUnichar **) nsMemory::Alloc(prefCount * (sizeof(PRUnichar *)));
if(NS_SUCCEEDED(rv)) {
nsXPIDLString description;
rv = literal->GetValue(getter_Copies(description));
NS_ENSURE_SUCCESS(rv,rv);
if (prefNames && prefValues)
{
prefNames[0] = PR_smprintf("description");
prefValues[0] = name;
rv = directory->CreateNewDirectory((unsigned int) prefCount, (const char**)prefNames, (const PRUnichar**)prefValues);
nsCOMPtr <nsIAbDirectoryProperties> properties;
properties = do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
if (prefNames[0])
PR_smprintf_free(prefNames[0]);
if (prefValues[0])
nsMemory::Free(prefValues[0]);
}
else
{
rv = NS_ERROR_NULL_POINTER;
}
if (prefNames)
nsMemory::Free(prefNames);
if (prefValues)
nsMemory::Free(prefValues);
rv = properties->SetDescription(description);
NS_ENSURE_SUCCESS(rv,rv);
rv = directory->CreateNewDirectory(properties);
NS_ENSURE_SUCCESS(rv,rv);
}
return rv;
}