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
Родитель e228e19237
Коммит c71268194b
3 изменённых файлов: 134 добавлений и 41 удалений

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

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

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

@ -250,6 +250,10 @@ interface nsIPref : nsISupports {
[noscript] void RegisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure); [noscript] void RegisterCallback(in string domain, in PrefChangedFunc callback, in voidPtr closure);
[noscript] void UnregisterCallback(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 * EnumerateChildren
* *

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

@ -108,6 +108,8 @@ public:
NS_IMETHOD RegisterCallback(const char *domain, PrefChangedFunc callback, void * closure); NS_IMETHOD RegisterCallback(const char *domain, PrefChangedFunc callback, void * closure);
NS_IMETHOD UnregisterCallback(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); NS_IMETHOD EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void * data);
protected: protected:
@ -544,6 +546,96 @@ NS_IMETHODIMP nsPref::UnregisterCallback( const char* domain,
* Preference enumeration * 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) NS_IMETHODIMP nsPref::EnumerateChildren(const char *parent, PrefEnumerationFunc callback, void *arg)
{ {
PRUint32 theCount; PRUint32 theCount;