Backing out previous patch since it was causing addressbook problems.

This commit is contained in:
caillon%returnzero.com 2003-04-27 10:36:58 +00:00
parent 0282489c03
commit 731073c19a
3 changed files with 134 additions and 41 deletions

View File

@ -2486,31 +2486,33 @@ static nsresult DIR_GetCustomAttributePrefs(const char *prefstring, DIR_Server *
return NS_ERROR_FAILURE;
char **tokenList = nsnull;
char **childList = nsnull;
char *childList = nsnull;
PL_strcpy(scratch, prefstring);
PL_strcat(scratch, ".attributes");
PRUint32 prefCount;
rv = pPref->GetChildList(scratch, &prefCount, &childList);
if (NS_SUCCEEDED(rv))
if (PREF_NOERROR == pPref->CreateChildList(scratch, &childList))
{
for (PRUint32 i = 0; i < prefCount; ++i)
if (childList && childList[0])
{
char *jsValue = nsnull;
rv = pPref->CopyCharPref(childList[i], &jsValue);
if (NS_SUCCEEDED(rv))
char *child = nsnull;
PRInt16 indx = 0;
while ((pPref->NextChild (childList, &indx, &child)) == NS_OK)
{
if (jsValue && jsValue[0])
char *jsValue = nsnull;
if (PREF_NOERROR == pPref->CopyCharPref (child, &jsValue))
{
char *attrName = childList[i] + PL_strlen(scratch) + 1;
DIR_AddCustomAttribute (server, attrName, jsValue);
if (jsValue && jsValue[0])
{
char *attrName = child + PL_strlen(scratch) + 1;
DIR_AddCustomAttribute (server, attrName, jsValue);
}
PR_FREEIF(jsValue);
}
PR_FREEIF(jsValue);
}
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, childList);
PR_FREEIF(childList);
}
if (0 == dir_CreateTokenListFromPref (prefstring, "basicSearchAttributes", scratch,
@ -2555,15 +2557,12 @@ static nsresult DIR_GetCustomFilterPrefs(const char *prefstring, DIR_Server *ser
server->tokenSeps = DIR_GetStringPref (prefstring, "wordSeparators", localScratch, kDefaultTokenSeps);
while (keepGoing && NS_SUCCEEDED(status))
{
char **childList = nsnull;
char *childList = nsnull;
PR_snprintf (scratch, 128, "%s.filter%d", prefstring, filterNum);
PRUint32 prefCount;
status = pPref->GetChildList(scratch, &prefCount, &childList);
if (NS_SUCCEEDED(status))
if (PREF_NOERROR == pPref->CreateChildList(scratch, &childList))
{
if (prefCount > 0)
if ('\0' != childList[0])
{
DIR_Filter *filter = (DIR_Filter*) PR_Malloc (sizeof(DIR_Filter));
if (filter)
@ -2595,7 +2594,7 @@ static nsresult DIR_GetCustomFilterPrefs(const char *prefstring, DIR_Server *ser
}
else
keepGoing = PR_FALSE;
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, childList);
PR_Free(childList);
}
else
keepGoing = PR_FALSE;
@ -2757,23 +2756,23 @@ char *DIR_CreateServerPrefName (DIR_Server *server, char *name)
if (leafName)
{
PRInt32 uniqueIDCnt = 0;
char **children = nsnull;
char * children = nsnull;
char * child = nsnull;
/* we need to verify that this pref string name is unique */
prefName = PR_smprintf(PREF_LDAP_SERVER_TREE_NAME".%s", leafName);
isUnique = PR_FALSE;
while (!isUnique && prefName)
{
isUnique = PR_TRUE; /* now flip the logic and assume we are unique until we find a match */
PRUint32 prefCount;
rv = pPref->GetChildList(PREF_LDAP_SERVER_TREE_NAME, &prefCount, &children);
if (NS_SUCCEEDED(rv))
if (pPref->CreateChildList(PREF_LDAP_SERVER_TREE_NAME, &children) == PREF_NOERROR)
{
for (PRUint32 i = 0; i < prefCount && isUnique; ++i)
PRInt16 i = 0;
while ( (pPref->NextChild(children, &i, &child)) == NS_OK && isUnique)
{
if (!nsCRT::strcasecmp(children[i], prefName)) /* are they the same name?? */
if (!nsCRT::strcasecmp(child, prefName) ) /* are they the same name?? */
isUnique = PR_FALSE;
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, children);
PR_FREEIF(children);
if (!isUnique) /* then try generating a new pref name and try again */
{
PR_smprintf_free(prefName);
@ -2999,7 +2998,7 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
if (NS_FAILED(result) || !pPref)
return NS_ERROR_FAILURE;
char **children;
char *children;
(*list) = new nsVoidArray();
if (!(*list))
@ -3011,10 +3010,8 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
if (!(*obsoleteList))
return NS_ERROR_OUT_OF_MEMORY;
}
PRUint32 prefCount;
result = pPref->GetChildList(PREF_LDAP_SERVER_TREE_NAME, &prefCount, &children);
if (NS_SUCCEEDED(result))
if (pPref->CreateChildList(PREF_LDAP_SERVER_TREE_NAME, &children) == PREF_NOERROR)
{
/* TBD: Temporary code to read broken "ldap" preferences tree.
* Remove line with if statement after M10.
@ -3022,8 +3019,10 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
if (dir_UserId == 0)
pPref->GetIntPref(PREF_LDAP_GLOBAL_TREE_NAME".user_id", &dir_UserId);
PRInt16 i = 0;
char *child;
for (PRUint32 i = 0; i < prefCount; ++i)
while ((pPref->NextChild(children, &i, &child)) == NS_OK)
{
DIR_Server *server;
@ -3031,7 +3030,7 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
if (server)
{
DIR_InitServer(server);
server->prefName = nsCRT::strdup(children[i]);
server->prefName = nsCRT::strdup(child);
DIR_GetPrefsForOneServer(server, PR_FALSE, PR_FALSE);
if ( server->description && server->description[0]
&& ( (server->dirType == PABDirectory ||
@ -3057,7 +3056,7 @@ static nsresult dir_GetPrefsFrom45Branch(nsVoidArray **list, nsVoidArray **obsol
}
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, children);
PR_Free(children);
}
return result;
@ -3073,7 +3072,7 @@ nsresult DIR_GetServerPreferences(nsVoidArray** list)
PRInt32 position = 1;
PRInt32 version = -1;
char **oldChildren = nsnull;
char *oldChildren = nsnull;
PRBool savePrefs = PR_FALSE;
PRBool migrating = PR_FALSE;
nsVoidArray *oldList = nsnull;
@ -3090,16 +3089,14 @@ nsresult DIR_GetServerPreferences(nsVoidArray** list)
pPref->SetIntPref(PREF_LDAP_VERSION_NAME, kCurrentListVersion);
/* Look to see if there's an old-style "ldap_1" tree in prefs */
PRUint32 prefCount;
err = pPref->GetChildList("ldap_1", &prefCount, &oldChildren);
if (NS_SUCCEEDED(err))
if (PREF_NOERROR == pPref->CreateChildList("ldap_1", &oldChildren))
{
if (prefCount > 0)
if (PL_strlen(oldChildren))
{
migrating = PR_TRUE;
position = dir_GetPrefsFrom40Branch(&oldList);
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, oldChildren);
PR_Free(oldChildren);
}
}
}

View File

@ -250,6 +250,10 @@ interface nsIPref : nsISupports {
[noscript] void RegisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure);
[noscript] void UnregisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure);
string CreateChildList(in string parent_node);
[noscript] string NextChild(in string child_list, inout short index);
/**
* EnumerateChildren
*

View File

@ -108,6 +108,8 @@ public:
NS_IMETHOD RegisterCallback(const char *domain, PrefChangedFunc callback, void * closure);
NS_IMETHOD UnregisterCallback(const char *domain, PrefChangedFunc callback, void * closure);
NS_IMETHOD CreateChildList(const char *parent_node, char **childList);
NS_IMETHOD NextChild(const char *child_list, PRInt16 *index, char **_retval);
NS_IMETHOD EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void * data);
protected:
@ -544,6 +546,96 @@ NS_IMETHODIMP nsPref::UnregisterCallback( const char* domain,
* Preference enumeration
*/
NS_IMETHODIMP nsPref::CreateChildList(const char* parent_node, char **child_list)
{
PRUint32 bufferSize;
PRUint32 theCount;
PRUint32 i;
nsresult rv;
char **childArray;
char *childList;
char *prefName;
NS_ENSURE_ARG_POINTER(parent_node);
NS_ENSURE_ARG_POINTER(child_list);
if (*parent_node > 0)
prefName = PR_smprintf("%s.", parent_node);
else
prefName = PL_strdup("");
if (prefName == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = GetChildList(prefName, &theCount, &childArray);
if (NS_SUCCEEDED(rv)) {
// now that we've built up the list, build a buffer from the results
bufferSize = 2048;
childList = (char *)nsMemory::Alloc(sizeof(char) * bufferSize);
if (childList != nsnull) {
char buf[512];
char* nextdelim;
PRUint32 parentlen = PL_strlen(prefName);
char* substring;
childList[0] = '\0';
for (i = 0; i < theCount; ++i) {
PL_strncpy(buf, (char *)childArray[i], PR_MIN(512, PL_strlen((char *)childArray[i]) + 1));
nextdelim = buf + parentlen;
if (parentlen < PL_strlen(buf)) {
// Find the next delimiter if any and truncate the string there
nextdelim = PL_strstr(nextdelim, ".");
if (nextdelim) {
*nextdelim = ';';
*(nextdelim + 1) = '\0';
}
}
// if this substring isn't already in the buffer, add it
substring = PL_strstr(childList, buf);
if (!substring) {
unsigned int newsize = PL_strlen(childList) + PL_strlen(buf) + 2;
if (newsize > bufferSize) {
bufferSize *= 2;
childList = (char *)nsMemory::Realloc(childList, sizeof(char) * bufferSize);
if (childList == nsnull) {
// problem... break out of for loop
break;
}
}
PL_strcat(childList, buf);
}
}
*child_list = childList;
}
// if we had an Alloc or Realloc problem
if (childList == nsnull) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
// release the memory allocated by GetChildList
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount, childArray);
}
PR_Free(prefName);
return rv;
}
NS_IMETHODIMP nsPref::NextChild(const char *child_list, PRInt16 *indx, char **listchild)
{
char* temp = (char*)&child_list[*indx];
char* newstr;
char* child = nsCRT::strtok(temp, ";", &newstr);
if (child) {
*indx += PL_strlen(child) + 1;
*listchild = child;
return NS_OK;
} else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsPref::EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void *arg)
{
PRUint32 theCount;