зеркало из https://github.com/mozilla/gecko-dev.git
Parameterize LDAP autocomplete searchfilter via hidden pref (bug 77386); also improves default searchfilter (85315). r=leif@netscape.com,srilatha@netscape.com; sr=bienvenu@netscape.com; a=asa@mozilla.org
This commit is contained in:
Родитель
e7a494b141
Коммит
824a3f191b
|
@ -35,8 +35,8 @@
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIProxyObjectManager.h"
|
#include "nsIProxyObjectManager.h"
|
||||||
#include "nsString.h"
|
|
||||||
#include "nsILDAPURL.h"
|
#include "nsILDAPURL.h"
|
||||||
|
#include "nsILDAPService.h"
|
||||||
#include "nsXPIDLString.h"
|
#include "nsXPIDLString.h"
|
||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
#include "nsLDAP.h"
|
#include "nsLDAP.h"
|
||||||
|
@ -49,7 +49,9 @@ NS_IMPL_ISUPPORTS3(nsLDAPAutoCompleteSession, nsIAutoCompleteSession,
|
||||||
nsILDAPMessageListener, nsILDAPAutoCompleteSession)
|
nsILDAPMessageListener, nsILDAPAutoCompleteSession)
|
||||||
|
|
||||||
nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() :
|
nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() :
|
||||||
mState(UNBOUND), mMaxHits(100), mMinStringLength(0)
|
mState(UNBOUND),
|
||||||
|
mFilterTemplate(NS_LITERAL_STRING("(|(cn=%v*)(mail=%v*)(sn=%v*))")),
|
||||||
|
mMaxHits(100), mMinStringLength(0)
|
||||||
{
|
{
|
||||||
NS_INIT_ISUPPORTS();
|
NS_INIT_ISUPPORTS();
|
||||||
}
|
}
|
||||||
|
@ -852,16 +854,78 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXXdmose process the mFilterTemplate here; ensuring that it's been set.
|
// get the search filter associated with the directory server url;
|
||||||
// This is waiting on substring replacement code, bug 74896. Note that
|
// it will be ANDed with the rest of the search filter that we're using.
|
||||||
// we need to vet the input text for special LDAP filter chars lik
|
|
||||||
// '|', '(', etc.
|
|
||||||
//
|
//
|
||||||
nsCAutoString searchFilter("(|(cn=");
|
nsXPIDLCString urlFilter;
|
||||||
searchFilter.Append(NS_ConvertUCS2toUTF8(mSearchString));
|
rv = mServerURL->GetFilter(getter_Copies(urlFilter));
|
||||||
searchFilter.Append("*)(sn=");
|
if ( NS_FAILED(rv) ){
|
||||||
searchFilter.Append(NS_ConvertUCS2toUTF8(mSearchString));
|
mState = BOUND;
|
||||||
searchFilter.Append("*))");
|
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the LDAP service, since createFilter is called through it.
|
||||||
|
//
|
||||||
|
nsCOMPtr<nsILDAPService> ldapSvc = do_GetService(
|
||||||
|
"@mozilla.org/network/ldap-service;1", &rv);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
|
||||||
|
"get @mozilla.org/network/ldap-service;1");
|
||||||
|
mState = BOUND;
|
||||||
|
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if urlFilter is unset (or set to the default "objectclass=*"), there's
|
||||||
|
// no need to AND in an empty search term, so leave prefix and suffix empty
|
||||||
|
//
|
||||||
|
nsAutoString prefix, suffix;
|
||||||
|
if (urlFilter[0] != 0 && nsCRT::strcmp(urlFilter, "(objectclass=*)")) {
|
||||||
|
prefix = NS_LITERAL_STRING("(&") + NS_ConvertUTF8toUCS2(urlFilter);
|
||||||
|
suffix = PRUnichar(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate an LDAP search filter from mFilterTemplate. If it's unset,
|
||||||
|
// use the default.
|
||||||
|
//
|
||||||
|
#define MAX_AUTOCOMPLETE_FILTER_SIZE 1024
|
||||||
|
nsAutoString searchFilter;
|
||||||
|
rv = ldapSvc->CreateFilter(MAX_AUTOCOMPLETE_FILTER_SIZE, mFilterTemplate,
|
||||||
|
prefix, suffix, NS_LITERAL_STRING(""),
|
||||||
|
mSearchString, searchFilter);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
switch(rv) {
|
||||||
|
|
||||||
|
case NS_ERROR_OUT_OF_MEMORY:
|
||||||
|
mState=BOUND;
|
||||||
|
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
case NS_ERROR_NOT_AVAILABLE:
|
||||||
|
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||||
|
("nsLDAPAutoCompleteSession::StartLDAPSearch(): "
|
||||||
|
"createFilter generated filter longer than max filter "
|
||||||
|
"size of %d", MAX_AUTOCOMPLETE_FILTER_SIZE));
|
||||||
|
mState=BOUND;
|
||||||
|
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
case NS_ERROR_INVALID_ARG:
|
||||||
|
case NS_ERROR_UNEXPECTED:
|
||||||
|
default:
|
||||||
|
|
||||||
|
// all this stuff indicates code bugs
|
||||||
|
//
|
||||||
|
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): "
|
||||||
|
"createFilter returned unexpected value");
|
||||||
|
|
||||||
|
mState=BOUND;
|
||||||
|
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// create a result set
|
// create a result set
|
||||||
//
|
//
|
||||||
|
@ -918,8 +982,7 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||||
// attributes. requires tweaking SearchExt.
|
// attributes. requires tweaking SearchExt.
|
||||||
//
|
//
|
||||||
rv = mOperation->SearchExt(NS_ConvertUTF8toUCS2(dn).get(), scope,
|
rv = mOperation->SearchExt(NS_ConvertUTF8toUCS2(dn).get(), scope,
|
||||||
NS_ConvertUTF8toUCS2(searchFilter).get(),
|
searchFilter.get(), 0, 0, 0, mMaxHits);
|
||||||
0, 0, 0, mMaxHits);
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
switch(rv) {
|
switch(rv) {
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче