Added hidden pref to allow short strings to be ignored by LDAP autocomplete session (bug 76593). r=leif@netscape.com,ducarroz@netscape.com,srilatha@netscape.com; sr=bienvenu@netscape.com

This commit is contained in:
dmose%netscape.com 2001-05-17 02:04:00 +00:00
parent 4be03d3937
commit ce464fac5a
4 changed files with 52 additions and 7 deletions

View File

@ -1866,8 +1866,19 @@ function LoadIdentity(startup)
try {
serverURL.spec = prefs.CopyCharPref(autocompleteDirectory + ".uri");
} catch (ex) {dump("ERROR: " + ex + "\n");}
dump("url is " + serverURL.spec +"\n");
session2.serverURL = serverURL;
// don't search on strings shorter than this
//
try {
session2.minStringLength =
prefs.GetIntPref(autocompleteDirectory +
".autoComplete.minStringLength");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default.
}
session2.filterTemplate = "cn=";
session2.outputFormat = "cn <mail>";
session2.sizeLimit = 10;

View File

@ -62,6 +62,18 @@ interface nsILDAPAutoCompleteSession : nsIAutoCompleteSession {
*/
attribute long sizeLimit;
/**
* Strings shorter than this will return |nsIAutoCompleteStatus::ignored|
* rather than triggering a search. This allows browsers to be
* configured to not search on substrings so short that they
* aren't indexed by the LDAP server (such searches can use significantly
* more server resources and return a very large number of entries).
* The default is 0, meaning that no such limit is in effect.
*
* @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter
*/
attribute unsigned long minStringLength;
/**
* LDAP server to complete against, in ldap: URL format.
* May change to an nsILDAPServer once that infrastructure lands.

View File

@ -50,7 +50,7 @@ NS_IMPL_ISUPPORTS3(nsLDAPAutoCompleteSession, nsIAutoCompleteSession,
nsILDAPMessageListener, nsILDAPAutoCompleteSession)
nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() :
mState(UNBOUND)
mState(UNBOUND), mMinStringLength(0)
{
NS_INIT_ISUPPORTS();
}
@ -89,11 +89,13 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
mListener = listener; // save it for later callbacks
}
// ignore the empty string and strings with @ in them
// ignore the empty string, strings with @ in them, and strings
// that are too short
//
if (searchString[0] == 0 ||
nsLiteralString(searchString).FindChar(PRUnichar('@'), 0)
!= kNotFound) {
if (searchString[0] == 0 ||
nsLiteralString(searchString).FindChar(PRUnichar('@'), 0) !=
kNotFound ||
mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength) {
FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored);
return NS_OK;
@ -1028,4 +1030,24 @@ nsLDAPAutoCompleteSession::SetServerURL(nsILDAPURL * aServerURL)
return NS_OK;
}
// attribute unsigned long minStringLength
NS_IMETHODIMP
nsLDAPAutoCompleteSession::GetMinStringLength(PRUint32 *aMinStringLength)
{
if (!aMinStringLength) {
return NS_ERROR_NULL_POINTER;
}
*aMinStringLength = mMinStringLength;
return NS_OK;
}
NS_IMETHODIMP
nsLDAPAutoCompleteSession::SetMinStringLength(PRUint32 aMinStringLength)
{
mMinStringLength = aMinStringLength;
return NS_OK;
}
#endif

View File

@ -61,7 +61,7 @@ class nsLDAPAutoCompleteSession : public nsILDAPMessageListener,
nsString mOutputFormat; // how to format output
nsCOMPtr<nsILDAPURL> mServerURL; // URL for the directory to search
PRInt32 mSizeLimit; // return at most this many entries
PRUint32 mMinStringLength; // strings < this size are ignored
// stopgap until nsLDAPService works
nsresult InitConnection();