if (pPref->CreateChildList(PREF_LDAP_SERVER_TREE_NAME, &children) == PREF_NOERROR)
PRUint32 prefCount; rv = pPref->GetChildList(PREF_LDAP_SERVER_TREE_NAME, &prefCount, &children); if (NS_SUCCEEDED(rv))
char *DIR_CreateServerPrefName (DIR_Server *server, char *name){    nsresult rv = NS_OK;    nsCOMPtr<nsIPref> pPref(do_GetService(NS_PREF_CONTRACTID, &rv));     if (NS_FAILED(rv) || !pPref) 		return nsnull;	/* we are going to try to be smart in how we generate our server	   pref name. We'll try to convert the description into a pref name	   and then verify that it is unique. If it is unique then use it... */	char * leafName = nsnull;	char * prefName = nsnull;	PRBool isUnique = PR_FALSE;	if (name)        leafName = nsCRT::strdup(name);	else		leafName = dir_ConvertDescriptionToPrefName (server);	if (leafName)	{		PRInt32 uniqueIDCnt = 0;		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 */			if (pPref->CreateChildList(PREF_LDAP_SERVER_TREE_NAME, &children) == PREF_NOERROR)			{				PRInt16 i = 0; 				while ( (pPref->NextChild(children, &i, &child)) == NS_OK && isUnique)				{                    if (!nsCRT::strcasecmp(child, prefName) ) /* are they the same name?? */						isUnique = PR_FALSE;				}				PR_FREEIF(children);				if (!isUnique) /* then try generating a new pref name and try again */				{					PR_smprintf_free(prefName);					prefName = PR_smprintf(PREF_LDAP_SERVER_TREE_NAME".%s_%d", leafName, ++uniqueIDCnt);				}			} /* if we have a list of pref Names */		} /* while we don't have a unique name */		PR_Free(leafName);	} /* if leafName */	if (!prefName) /* last resort if we still don't have a pref name is to use user_directory string */		return PR_smprintf(PREF_LDAP_SERVER_TREE_NAME".user_directory_%d", ++dir_UserId);	else		return prefName;}