diff --git a/mozilla/mailnews/addrbook/build/nsAbFactory.cpp b/mozilla/mailnews/addrbook/build/nsAbFactory.cpp index 4e6f51a39de..dc97a083483 100644 --- a/mozilla/mailnews/addrbook/build/nsAbFactory.cpp +++ b/mozilla/mailnews/addrbook/build/nsAbFactory.cpp @@ -87,6 +87,7 @@ #include "nsAbLDAPReplicationData.h" #include "nsAbLDAPChangeLogQuery.h" #include "nsAbLDAPChangeLogData.h" +#include "nsLDAPAutoCompleteSession.h" #endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddressBook) @@ -126,6 +127,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPReplicationQuery) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessReplicationData) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPChangeLogQuery) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessChangeLogData) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession) #endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryQueryProxy) @@ -315,6 +317,11 @@ static const nsModuleComponentInfo components[] = NS_ABLDAPAUTOCOMPFORMATTER_CONTRACTID, nsAbLDAPAutoCompFormatterConstructor }, + { "LDAP Autocomplete Session", + NS_LDAPAUTOCOMPLETESESSION_CID, + "@mozilla.org/autocompleteSession;1?type=ldap", + nsLDAPAutoCompleteSessionConstructor }, + #endif { "The directory query proxy interface", diff --git a/mozilla/mailnews/addrbook/public/Makefile.in b/mozilla/mailnews/addrbook/public/Makefile.in index 3bcbf59a68c..5dec47b5a73 100644 --- a/mozilla/mailnews/addrbook/public/Makefile.in +++ b/mozilla/mailnews/addrbook/public/Makefile.in @@ -73,6 +73,8 @@ XPIDLSRCS = \ ifdef MOZ_LDAP_XPCOM XPIDLSRCS += \ nsILDAPPrefsService.idl \ + nsILDAPAutoCompleteSession.idl \ + nsILDAPAutoCompFormatter.idl \ nsIAbLDAPAutoCompFormatter.idl \ nsIAbLDAPReplicationService.idl \ nsIAbLDAPReplicationQuery.idl \ diff --git a/mozilla/mailnews/addrbook/src/Makefile.in b/mozilla/mailnews/addrbook/src/Makefile.in index bf46c244f71..54e17d8e6fd 100644 --- a/mozilla/mailnews/addrbook/src/Makefile.in +++ b/mozilla/mailnews/addrbook/src/Makefile.in @@ -146,6 +146,7 @@ CPPSRCS += nsAbLDAPDirectory.cpp \ nsAbLDAPReplicationData.cpp \ nsAbLDAPChangeLogQuery.cpp \ nsAbLDAPChangeLogData.cpp \ + nsLDAPAutoCompleteSession.cpp \ $(NULL) endif diff --git a/mozilla/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp b/mozilla/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp index 5f975863584..2043d6364de 100644 --- a/mozilla/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp +++ b/mozilla/mailnews/addrbook/src/nsAbLDAPAutoCompFormatter.cpp @@ -212,12 +212,12 @@ nsAbLDAPAutoCompFormatter::FormatException(PRInt32 aState, } rv = stringBundleSvc->CreateBundle( - "chrome://global/locale/ldapAutoCompErrs.properties", + "chrome://mailnews/locale/addressbook/ldapAutoCompErrs.properties", getter_AddRefs(ldapACBundle)); if (NS_FAILED(rv)) { NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():" " error creating string bundle" - " chrome://global/locale/ldapAutoCompErrs.properties"); + " chrome://mailnews/locale/addressbook/ldapAutoCompErrs.properties"); return rv; } @@ -228,7 +228,7 @@ nsAbLDAPAutoCompFormatter::FormatException(PRInt32 aState, if (NS_FAILED(rv)) { NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():" " error getting general error from bundle" - " chrome://global/locale/ldapAutoCompErrs.properties"); + " chrome://mailnews/locale/addressbook/ldapAutoCompErrs.properties"); return rv; } diff --git a/mozilla/mailnews/build/nsMailModule.cpp b/mozilla/mailnews/build/nsMailModule.cpp index 1bdd213d7ad..86aba28e619 100644 --- a/mozilla/mailnews/build/nsMailModule.cpp +++ b/mozilla/mailnews/build/nsMailModule.cpp @@ -158,6 +158,7 @@ #include "nsAbLDAPReplicationData.h" #include "nsAbLDAPChangeLogQuery.h" #include "nsAbLDAPChangeLogData.h" +#include "nsLDAPAutoCompleteSession.h" #endif //////////////////////////////////////////////////////////////////////////////// @@ -381,6 +382,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPReplicationQuery) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessReplicationData) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPChangeLogQuery) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessChangeLogData) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession) #endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryQueryProxy) @@ -923,6 +925,10 @@ static const nsModuleComponentInfo gComponents[] = { NS_ABLDAPSACDIRFACTORY_CONTRACTID, nsAbLDAPDirFactoryConstructor }, { "Address book LDAP autocomplete formatter", NS_ABLDAPAUTOCOMPFORMATTER_CID, NS_ABLDAPAUTOCOMPFORMATTER_CONTRACTID,nsAbLDAPAutoCompFormatterConstructor }, + { "LDAP Autocomplete Session", + NS_LDAPAUTOCOMPLETESESSION_CID, + "@mozilla.org/autocompleteSession;1?type=ldap", + nsLDAPAutoCompleteSessionConstructor }, #endif { "The directory query proxy interface", NS_ABDIRECTORYQUERYPROXY_CID, NS_ABDIRECTORYQUERYPROXY_CONTRACTID, nsAbDirectoryQueryProxyConstructor}, diff --git a/mozilla/mailnews/jar.mn b/mozilla/mailnews/jar.mn index 3adf5dbc6b6..98fd70d81ea 100644 --- a/mozilla/mailnews/jar.mn +++ b/mozilla/mailnews/jar.mn @@ -192,6 +192,7 @@ messenger.jar: en-US.jar: * locale/en-US/messenger/contents.rdf (base/resources/locale/en-US/contents.rdf) + locale/en-US/messenger/addressbook/ldapAutoCompErrs.properties (addrbook/resources/locale/en-US/ldapAutoCompErrs.properties) locale/en-US/messenger/addressbook/abAddressBookNameDialog.dtd (addrbook/resources/locale/en-US/abAddressBookNameDialog.dtd) locale/en-US/messenger/addressbook/abCardOverlay.dtd (addrbook/resources/locale/en-US/abCardOverlay.dtd) locale/en-US/messenger/addressbook/abCardViewOverlay.dtd (addrbook/resources/locale/en-US/abCardViewOverlay.dtd) diff --git a/mozilla/xpfe/components/autocomplete/public/Makefile.in b/mozilla/xpfe/components/autocomplete/public/Makefile.in index b73ec81cd90..d89dd951b0c 100644 --- a/mozilla/xpfe/components/autocomplete/public/Makefile.in +++ b/mozilla/xpfe/components/autocomplete/public/Makefile.in @@ -51,13 +51,5 @@ XPIDLSRCS = \ nsIAutoCompleteSession.idl \ $(NULL) -ifdef MOZ_LDAP_XPCOM -REQUIRES += mozldap necko -XPIDLSRCS += \ - nsILDAPAutoCompleteSession.idl \ - nsILDAPAutoCompFormatter.idl \ - $(NULL) -endif - include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompFormatter.idl b/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompFormatter.idl deleted file mode 100644 index 35107968aef..00000000000 --- a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompFormatter.idl +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dan Mosedale (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -interface nsIAutoCompleteItem; -interface nsILDAPMessage; - -/** - * An interface to allow different users of nsILDAPAutoCompleteSession to - * format each nsILDAPMessage into an nsIAutoCompleteItem as it sees fit. - */ -[scriptable, uuid(cbec617c-22d2-4286-8308-0ef8bf57c0ce)] -interface nsILDAPAutoCompFormatter : nsISupports { - - /** - * Returns an nsIAutoCompleteItem generated from the data in - * the given nsILDAPMessage. - * - * @param aMessage message to be formatted - * @return resulting nsIAutoCompleteItem - */ - nsIAutoCompleteItem format(in nsILDAPMessage aMessage); - - /** - * Gets a list of all the LDAP attributes that should be requested - * from the LDAP server when a lookup is done. This avoids - * wasting server time, bandwidth, and client time processing - * unused attributes. - * - * Note that this is only required to be called by the - * nsILDAPAutoCompleteSession implementation when the - * nsILDAPAutoCompleteSession::formatter IDL attribute is set. . - * So if for some reason, the LDAP attributes to be returned by - * searches has to change (eg because the user changed a - * preference), the nsILDAPAutoCompleteSession::formatter IDL - * attribute should be re-set to the same object to force a new - * getAttributes() call. - * - * @param aCount number of attributes in the array - * @param aAttrs list of LDAP attributes to request - */ - void getAttributes(out unsigned long aCount, - [retval, array, size_is(aCount)] out string aAttrs); - - /** - * This method formats an error condition into an nsIAutoCompleteItem - * for display to the user. Specifically, the state that the session - * was in when the error occured (aState) is formatted into a general - * error message which is put in the value attribute of the item, - * and the specific error (aErrorCode) is formatted into another message - * which is put in an nsISupportsString in the param attribute of the - * item. - * - * @param aState state of autocomplete session when error occurred - * @param aErrorCode specific error encountered - * - * @return newly generated item - */ - nsIAutoCompleteItem formatException(in long aState, - in nsresult aErrorCode); - - /** - * Possible states that can be passed in aState to formatException - */ - const long STATE_UNBOUND = 0; - const long STATE_INITIALIZING = 1; - const long STATE_BINDING = 2; - const long STATE_BOUND = 3; - const long STATE_SEARCHING = 4; - -}; diff --git a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl b/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl deleted file mode 100644 index 9f08e91414a..00000000000 --- a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dan Mosedale (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIAutoCompleteSession.idl" - -// forward decls -// -interface nsILDAPURL; -interface nsILDAPAutoCompFormatter; -interface nsIAuthPrompt; -interface nsIMutableArray; - -/** - * Extends nsIAutoCompleteSession to have various LDAP-specific parameters. - * and output format. - */ -[scriptable, uuid(e7f26534-f96c-4c87-803c-30cdf0bc2973)] -interface nsILDAPAutoCompleteSession : nsIAutoCompleteSession { - - /** - * A template used to construct the RFC 1960 LDAP search filter to use - * while autocompleting. - * - * The authoritative documentation for the format in use can be found at - * at . - * The Linux/OpenLDAP man page for ldapfilter.conf(5) does a pretty decent - * job as well, however. - * - * As of this writing, the "@mozilla.org/autocompleteSession;1?type=ldap" - * contractid happens to use a default value of - * (|(cn=%v1*%v2-*)(mail=%v1*%v2-*)(sn=%v1*%v2-*)) - * - * @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter - * @exception NS_ERROR_OUT_OF_MEMORY Getter couldn't allocate string - */ - attribute AUTF8String filterTemplate; - - /** - * At most this many nsIAutoCompleteItems will be returned. This - * is useful for keeping bandwidth usage over slow-speed - * connections as well as ensuring that the number of choices - * offered in the UI is manageble. - * - * 1-65535 are interpreted literally - * 0 means "unlimited" - * -1 uses the default limit for the LDAP connection in use - * - * @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter - * @exception NS_ERROR_ILLEGAL_VALUE Out-of-range value passed to setter - */ - attribute long maxHits; - - /** - * 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). cjkMinStringLength is used for CJK - * languages, and minStringLength for everything else. As of this - * writing, the "@mozilla.org/autocompleteSession;1?type=ldap" - * contractid uses defaults of two and zero, respectively. This - * avoids most unindexed searches with at least one widely-deployed - * webserver, but allows CJK languages, where a single glyph can be an - * an entire name to still get results. - * - * @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter - */ - attribute unsigned long minStringLength; - attribute unsigned long cjkMinStringLength; - - /** - * LDAP server to complete against, in ldap: URL format. - * May change to an nsILDAPServer once that infrastructure lands. - * - * @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter - */ - attribute nsILDAPURL serverURL; - - /** - * Callback used to format an individual LDAP message into an - * nsIAutoCompleteItem. - */ - attribute nsILDAPAutoCompFormatter formatter; - - /** - * "Login as..." this ID. Currently, this must be specified as a DN. - * In the future, we may support userid and/or email address as well. - * If unset, bind anonymously. - */ - attribute AUTF8String login; - - /** - * If set, use this object to get a password for logging in to the server. - */ - attribute nsIAuthPrompt authPrompter; - - /** - * What version of the LDAP protocol should be used? Allowed version - * number constants are defined in nsILDAPConnection.idl. - * - * @exception NS_ERROR_ILLEGAL_VALUE illegal version num passed to setter - * @exception NS_ERROR_NULL_POINTER null pointer passed to getter - */ - attribute unsigned long version; - - /** - * If set, these arrays of nsILDAPControls are passed through to the - * nsILDAPOperation that searchExt is called on. - */ - attribute nsIMutableArray searchServerControls; - attribute nsIMutableArray searchClientControls; -}; diff --git a/mozilla/xpfe/components/autocomplete/resources/locale/en-US/contents.rdf b/mozilla/xpfe/components/autocomplete/resources/locale/en-US/contents.rdf deleted file mode 100644 index 0e5cd911311..00000000000 --- a/mozilla/xpfe/components/autocomplete/resources/locale/en-US/contents.rdf +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/mozilla/xpfe/components/autocomplete/resources/locale/en-US/ldapAutoCompErrs.properties b/mozilla/xpfe/components/autocomplete/resources/locale/en-US/ldapAutoCompErrs.properties deleted file mode 100644 index 51c83e1fb7f..00000000000 --- a/mozilla/xpfe/components/autocomplete/resources/locale/en-US/ldapAutoCompErrs.properties +++ /dev/null @@ -1,145 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is the mozilla.org autocomplete code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Dan Mosedale -# Robin Foster-Clark -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -# These are error strings for problems that happen while in the -# various states declared in nsILDAPAutoCompFormatter.idl. Note that -# the number that indexes each error state is the same as the number -# corresponding to that state in nsILDAPAutoCompFormatter.idl. - -## @name ERR_STATE_UNBOUND -## @loc none -0=LDAP initialization problem - -## @name ERR_STATE_INITIALIZING -## @loc none -1=LDAP server connection failed - -## @name ERR_STATE_BINDING -## @loc none -2=LDAP server connection failed - -## @name ERR_STATE_BOUND -## @loc none -3=LDAP server communications problem - -## @name ERR_STATE_SEARCHING -## @loc none -4=LDAP server search problem - - -# The format of the alert dialog itself -# -## @name ALERT_FORMAT -## @loc None of %1$S, %2$S, %3$S, and %4$S should be localized. %1$S is the -## ERROR_CODE string below, %2$S is the error code itself, %3$S is an -## LDAP SDK error message from chrome://mozldap/locale/ldap.properties, -## and %4$S is a hint relating to that specific error, found in this file. -alertFormat=%1$S %2$S: %3$S\n\n %4$S - -# This string is used in ALERT_FORMAT -# -## @name ERROR_CODE -## @loc none -errCode=Error code - - -## The following errors are for error codes other than LDAP-specific ones. -## Someday mozilla will actually have a system for mapping nsresults to -## error strings that's actually widely used, unlike nsIErrorService. But -## until it does, these strings live here... - -## @name HOST_NOT_FOUND -## @loc none -5000=Host not found - -## @name GENERIC_ERROR -## @loc none -9999=Unknown error - - -# Hints to for the user, associated with specific error codes (ie error code -# + 10000) - - -## @name TIMELIMIT_EXCEEDED_HINT -## @loc none -10003=Please try again later, or else contact your System Administrator. - -## @name STRONGAUTH_REQUIRED_HINT -## @loc none -10008=Strong authentication is not currently supported. - -## @name INVALID_SYNTAX_HINT -## @loc none -10021=Verify that the search filter is correct, and then try again, or else contact your System Administrator. To verify that the search filter is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit, and then click Advanced to display the Search Filter. - -## @name NO_SUCH_OBJECT_HINT -## @loc none -10032=Verify that the Base DN is correct, and then try again, or else contact your System Administrator. To verify that the Base DN is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Base DN. - -## @name BUSY_HINT -## @loc none -10051=Please try again later. - -## @name SERVER_DOWN_HINT -## @loc none -10081=Verify that the Hostname and Port Number are correct, and then try again, or else contact your System Administrator. To verify that the Hostname and Port Number are correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname. Click Advanced to display the Port Number. - -## @name TIMEOUT_HINT -## @loc none -10085=Please try again later. - -## @name FILTER_ERROR_HINT -## @loc none -10087=Verify that the search filter is correct, and then try again, or else contact your System Administrator. To verify that the search filter is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit, and then click Advanced to display the Search Filter. - -## @name NO_MEMORY_HINT -## @loc none -10090=Please close some other windows and/or applications and try again. - -## @name CONNECT_ERROR_HINT -## @loc none -10091=Verify that the Hostname and Port Number are correct, and then try again, or else contact your System Administrator. To verify that the Hostname and Port Number are correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname. Click Advanced to display the Port Number. - -## @name HOST_NOT_FOUND_HINT -## @loc none -15000=Verify that the Hostname is correct, and then try again, or else contact your System Administrator. To verify that the Hostname is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname. - -## @name GENERIC_HINT -## @loc none -19999=Please contact your System Administrator. diff --git a/mozilla/xpfe/components/autocomplete/src/Makefile.in b/mozilla/xpfe/components/autocomplete/src/Makefile.in index 13126db190f..f72a19645e9 100644 --- a/mozilla/xpfe/components/autocomplete/src/Makefile.in +++ b/mozilla/xpfe/components/autocomplete/src/Makefile.in @@ -58,12 +58,6 @@ REQUIRES = xpcom \ CPPSRCS = nsAutoComplete.cpp -ifdef MOZ_LDAP_XPCOM -REQUIRES += mozldap necko -CPPSRCS += nsLDAPAutoCompleteSession.cpp -DEFINES += -DMOZ_LDAP_XPCOM -endif - EXTRA_DSO_LDOPTS += \ $(MOZ_UNICHARUTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) \ diff --git a/mozilla/xpfe/components/autocomplete/src/nsAutoComplete.cpp b/mozilla/xpfe/components/autocomplete/src/nsAutoComplete.cpp index e5caf527e6b..c4f3c12f67a 100644 --- a/mozilla/xpfe/components/autocomplete/src/nsAutoComplete.cpp +++ b/mozilla/xpfe/components/autocomplete/src/nsAutoComplete.cpp @@ -42,10 +42,6 @@ #include "nsReadableUtils.h" #include "nsIGenericFactory.h" -#if defined(MOZ_LDAP_XPCOM) -#include "nsLDAPAutoCompleteSession.h" -#endif - /****************************************************************************** * nsAutoCompleteItem ******************************************************************************/ @@ -184,19 +180,7 @@ NS_IMETHODIMP nsAutoCompleteResults::SetDefaultItemIndex(PRInt32 aDefaultItemInd NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteItem) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteResults) -#if defined(MOZ_LDAP_XPCOM) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession) -#endif - static const nsModuleComponentInfo components[] = { -#if defined(MOZ_LDAP_XPCOM) - { - "LDAP Autocomplete Session", - NS_LDAPAUTOCOMPLETESESSION_CID, - "@mozilla.org/autocompleteSession;1?type=ldap", - nsLDAPAutoCompleteSessionConstructor - }, -#endif { "AutoComplete Search Results", NS_AUTOCOMPLETERESULTS_CID, diff --git a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp deleted file mode 100644 index 82dd418e8d0..00000000000 --- a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp +++ /dev/null @@ -1,1658 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dan Mosedale (Original Author) - * Leif Hedstrom - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Work around lack of conditional build logic in codewarrior's -// build system. The MOZ_LDAP_XPCOM preprocessor symbol is only -// defined on Mac because noone else needs this weirdness; thus -// the XP_MAC check first. This conditional encloses the entire -// file, so that in the case where the ldap option is turned off -// in the mac build, a dummy (empty) object will be generated. -// -#if !defined(XP_MAC) || defined(MOZ_LDAP_XPCOM) - -#include "nsString.h" -#include "nsLDAPAutoCompleteSession.h" -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" -#include "nsIProxyObjectManager.h" -#include "nsILDAPURL.h" -#include "nsILDAPService.h" -#include "nsXPIDLString.h" -#include "nsReadableUtils.h" -#include "nspr.h" -#include "nsLDAP.h" -#include "nsIStringBundle.h" -#include "nsCRT.h" -#include "nsIObserverService.h" -#include "nsNetUtil.h" -#include "nsICategoryManager.h" -#include "nsCategoryManagerUtils.h" -#include "nsILDAPService.h" -#include "nsILDAPMessage.h" - -#ifdef PR_LOGGING -static PRLogModuleInfo *sLDAPAutoCompleteLogModule = 0; -#endif - - -// Because this object gets called via proxies, we need to use a THREADSAFE -// ISUPPORTS; if bug 101252 gets fixed, we can go back to the non-threadsafe -// version. -// -NS_IMPL_THREADSAFE_ISUPPORTS3(nsLDAPAutoCompleteSession, - nsIAutoCompleteSession, nsILDAPMessageListener, - nsILDAPAutoCompleteSession) - -nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() : - mState(UNBOUND), - mFilterTemplate("(|(cn=%v1*%v2-*)(mail=%v1*%v2-*)(sn=%v1*%v2-*))"), - mMaxHits(100), mMinStringLength(2), mCjkMinStringLength(0), - mSearchAttrs(0), mSearchAttrsSize(0), mVersion(nsILDAPConnection::VERSION3) -{ -} - -nsLDAPAutoCompleteSession::~nsLDAPAutoCompleteSession() -{ - if (mSearchAttrs) { - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mSearchAttrsSize, mSearchAttrs); - } -} - -#define IS_CJK_CHAR_FOR_LDAP(u) (0x2e80 <= (u) && (u) <= 0xd7ff) - -/* void onStartLookup (in wstring searchString, in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener); */ -NS_IMETHODIMP -nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString, - nsIAutoCompleteResults *previousSearchResult, - nsIAutoCompleteListener *listener) -{ - nsresult rv; // hold return values from XPCOM calls - -#ifdef PR_LOGGING - // initialize logging, if it hasn't been already - // - if (!sLDAPAutoCompleteLogModule) { - sLDAPAutoCompleteLogModule = PR_NewLogModule("ldapautocomplete"); - - NS_ABORT_IF_FALSE(sLDAPAutoCompleteLogModule, - "failed to initialize ldapautocomplete log module"); - } -#endif - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnStartLookup entered\n")); - - if (!listener) { - NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): NULL listener" - "passed in"); - return NS_ERROR_NULL_POINTER; - } else { - mListener = listener; // save it for later callbacks - } - - // ignore the empty string, strings with @ in them, and strings - // that are too short - // - if (searchString[0] == 0 || - nsDependentString(searchString).FindChar(PRUnichar('@'), 0) != - kNotFound || - nsDependentString(searchString).FindChar(PRUnichar(','), 0) != - kNotFound || - ( !IS_CJK_CHAR_FOR_LDAP(searchString[0]) ? - mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength : - mCjkMinStringLength && nsCRT::strlen(searchString) < - mCjkMinStringLength ) ) { - - FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored, 0, mState); - return NS_OK; - } else { - mSearchString = searchString; // save it for later use - } - - // make sure this was called appropriately. - // - if (mState == SEARCHING || mState == BINDING) { - NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): called while " - "search already in progress; no lookup started."); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - NS_ERROR_FAILURE, mState); - return NS_ERROR_FAILURE; - } - - NS_ASSERTION(mFormatter, "nsLDAPAutoCompleteSession::OnStartLookup(): " - "formatter attribute has not been set"); - - // see if this is a narrow search that we could potentially do locally - // - if (previousSearchResult) { - - // get the string representing previous search results - // - nsXPIDLString prevSearchStr; - - rv = previousSearchResult->GetSearchString( - getter_Copies(prevSearchStr)); - if ( NS_FAILED(rv) ) { - NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): couldn't " - "get search string from previousSearchResult"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - NS_ERROR_FAILURE, mState); - return NS_ERROR_FAILURE; - } - - // does the string actually contain anything? - // - if ( prevSearchStr.get() && prevSearchStr.get()[0]) { - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnStartLookup(): starting " - "narrowing search\n")); - - // XXXdmose for performance, we should really do a local, - // synchronous search against the existing dataset instead of - // just kicking off a new LDAP search here. When implementing - // this, need to be sure that only previous results which did not - // hit the size limit and were successfully completed are used. - // - mState = SEARCHING; - return StartLDAPSearch(); - } - } - - // init connection if necesary - // - switch (mState) { - case UNBOUND: - - // initialize the connection. - // - rv = InitConnection(); - if (NS_FAILED(rv)) { - - // InitConnection() will have already called - // FinishAutoCompleteLookup for us as necessary - // - return rv; - } - - return NS_OK; - - case BOUND: - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoComplete::OnStartLookup(): subsequent search " - "starting")); - - // kick off an LDAP search - mState = SEARCHING; - return StartLDAPSearch(); - - case INITIALIZING: - // We don't need to do anything here (for now at least), because - // we can't really abandon the initialization. If we allowed the - // initialization to be aborted, we could potentially lock the - // UI thread again, since the DNS service might be stalled. - // - return NS_OK; - - case BINDING: - case SEARCHING: - // we should never get here - NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): unexpected " - "value of mStatus"); - return NS_ERROR_UNEXPECTED; - } - - return NS_ERROR_UNEXPECTED; /*NOTREACHED*/ -} - -/* void onStopLookup (); */ -NS_IMETHODIMP -nsLDAPAutoCompleteSession::OnStopLookup() -{ -#ifdef PR_LOGGING - // initialize logging, if it hasn't been already - // - if (!sLDAPAutoCompleteLogModule) { - sLDAPAutoCompleteLogModule = PR_NewLogModule("ldapautocomplete"); - - NS_ABORT_IF_FALSE(sLDAPAutoCompleteLogModule, - "failed to initialize ldapautocomplete log module"); - } -#endif - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnStopLookup entered\n")); - - switch (mState) { - case UNBOUND: - // nothing to stop - return NS_OK; - - case BOUND: - // nothing to stop - return NS_OK; - - case INITIALIZING: - // We can't or shouldn't abor the initialization, because then the - // DNS service can hang again... - // - return NS_OK; - - case BINDING: - case SEARCHING: - // Abandon the operation, if there is one - // - if (mOperation) { - nsresult rv = mOperation->AbandonExt(); - - if (NS_FAILED(rv)) { - // since there's nothing interesting that can or should be - // done if this abandon failed, warn about it and move on - // - NS_WARNING("nsLDAPAutoCompleteSession::OnStopLookup(): " - "error calling mOperation->AbandonExt()"); - } - - // force nsCOMPtr to release mOperation - // - mOperation = 0; - } - - // Set the status properly, set to UNBOUND of we were binding, or - // to BOUND if we were searching. - // - mState = (mState == BINDING ? UNBOUND : BOUND); - } - - mResultsArray = 0; - mResults = 0; - mListener = 0; - - return NS_OK; -} - -/* void onAutoComplete (in wstring searchString, in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener); */ -NS_IMETHODIMP -nsLDAPAutoCompleteSession::OnAutoComplete(const PRUnichar *searchString, - nsIAutoCompleteResults *previousSearchResult, - nsIAutoCompleteListener *listener) -{ - // OnStopLookup should have already been called, so there's nothing to - // free here. Additionally, as of this writing, noone is hanging around - // waiting for mListener->OnAutoComplete() to be called either, and if - // they were, it's unclear what we'd return, since we're not guaranteed - // to be in any particular state. My suspicion is that this method - // (nsIAutoCompleteSession::OnAutoComplete) should probably be removed - // from the interface. - - return NS_OK; -} - -/** - * Messages received are passed back via this function. - * - * @arg aMessage The message that was returned, NULL if none was. - * - * void OnLDAPMessage (in nsILDAPMessage aMessage) - */ -NS_IMETHODIMP -nsLDAPAutoCompleteSession::OnLDAPMessage(nsILDAPMessage *aMessage) -{ - PRInt32 messageType; - - // just in case. - // XXXdmose the semantics of NULL are currently undefined, but are likely - // to be defined once we insert timeout handling code into the XPCOM SDK - // At that time we should figure out if this still the right thing to do. - // - if (!aMessage) { - return NS_OK; - } - - // figure out what sort of message was returned - // - nsresult rv = aMessage->GetType(&messageType); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPMessage(): unexpected " - "error in aMessage->GetType()"); - - // don't call FinishAutoCompleteLookup(), as this could conceivably - // be an anomaly, and perhaps the next message will be ok. if this - // really was a problem, this search should eventually get - // reaped by a timeout (once that code gets implemented). - // - return NS_ERROR_UNEXPECTED; - } - - // if this message is not associated with the current operation, - // discard it, since it is probably from a previous (aborted) - // operation - // - PRBool isCurrent; - rv = IsMessageCurrent(aMessage, &isCurrent); - if (NS_FAILED(rv)) { - // IsMessageCurrent will have logged any necessary errors - return rv; - } - if ( ! isCurrent ) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPMessage(): received message " - "from operation other than current one; discarded")); - return NS_OK; - } - - // XXXdmose - we may want a small state machine either here or - // or in the nsLDAPConnection object, to make sure that things are - // happening in the right order and timing out appropriately. this will - // certainly depend on how timeouts are implemented, and how binding - // gets is dealt with by nsILDAPService. also need to deal with the case - // where a bind callback happens after onStopLookup was called. - // - switch (messageType) { - - case nsILDAPMessage::RES_BIND: - - // a bind has completed - // - if (mState != BINDING) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPMessage(): LDAP bind " - "entry returned after OnStopLookup() called; ignoring")); - - // XXXdmose when nsLDAPService integration happens, need to make - // sure that the possibility of having an already bound - // connection, due to a previously unaborted bind, doesn't cause - // any problems. - - return NS_OK; - } - - return OnLDAPBind(aMessage); - - case nsILDAPMessage::RES_SEARCH_ENTRY: - - // ignore this if OnStopLookup was already called - // - if (mState != SEARCHING) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPMessage(): LDAP search " - "entry returned after OnStopLoookup() called; ignoring")); - return NS_OK; - } - - // a search entry has been returned - // - return OnLDAPSearchEntry(aMessage); - - case nsILDAPMessage::RES_SEARCH_RESULT: - - // ignore this if OnStopLookup was already called - // - if (mState != SEARCHING) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPMessage(): LDAP search " - "result returned after OnStopLookup called; ignoring")); - return NS_OK; - } - - // the search is finished; we're all done - // - return OnLDAPSearchResult(aMessage); - - default: - - // Given the LDAP operations nsLDAPAutoCompleteSession uses, we should - // never get here. If we do get here in a release build, it's - // probably a bug, but maybe it's the LDAP server doing something - // weird. Might as well try and continue anyway. The session should - // eventually get reaped by the timeout code, if necessary. - // - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPMessage(): unexpected " - "LDAP message received"); - return NS_OK; - } -} - -// void onLDAPInit (in nsresult aStatus); -// -NS_IMETHODIMP -nsLDAPAutoCompleteSession::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus) -{ - nsresult rv; // temp for xpcom return values - nsCOMPtr selfProxy; - nsXPIDLString passwd; // passwd to use to connect to server - - // Check the status from the initialization of the LDAP connection - // - if (NS_FAILED(aStatus)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, aStatus, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // If mAuthPrompter is set, we're expected to use it to get a password. - // - if (mAuthPrompter) { - nsUTF8String spec; - PRBool status; - - // we're going to use the URL spec of the server as the "realm" for - // wallet to remember the password by / for. - // - rv = mServerURL->GetSpec(spec); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit(): GetSpec" - " failed\n"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - rv, UNBOUND); - return NS_ERROR_FAILURE; - } - - // get the string bundle service - // - nsCOMPtr - stringBundleSvc(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit():" - " error getting string bundle service"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - rv, UNBOUND); - return rv; - } - - // get the LDAP string bundle - // - nsCOMPtr ldapBundle; - rv = stringBundleSvc->CreateBundle( - "chrome://mozldap/locale/ldap.properties", - getter_AddRefs(ldapBundle)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit():" - " error creating string bundle" - " chrome://mozldap/locale/ldap.properties"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - rv, UNBOUND); - return rv; - } - - // get the title for the authentication prompt - // - nsXPIDLString authPromptTitle; - rv = ldapBundle->GetStringFromName( - NS_LITERAL_STRING("authPromptTitle").get(), - getter_Copies(authPromptTitle)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit():" - "error getting 'authPromptTitle' string from bundle " - "chrome://mozldap/locale/ldap.properties"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - rv, UNBOUND); - return rv; - } - - // get the host name for the auth prompt - // - nsCAutoString host; - rv = mServerURL->GetAsciiHost(host); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return rv; - } - - // hostTemp is only necessary to work around a code-generation - // bug in egcs 1.1.2 (the version of gcc that comes with Red Hat 6.2), - // which is the default compiler for Mozilla on linux at the moment. - // - NS_ConvertASCIItoUCS2 hostTemp(host); - const PRUnichar *hostArray[1] = { hostTemp.get() }; - - // format the hostname into the authprompt text string - // - nsXPIDLString authPromptText; - rv = ldapBundle->FormatStringFromName( - NS_LITERAL_STRING("authPromptText").get(), - hostArray, sizeof(hostArray) / sizeof(const PRUnichar *), - getter_Copies(authPromptText)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit():" - "error getting 'authPromptText' string from bundle " - "chrome://mozldap/locale/ldap.properties"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - rv, UNBOUND); - return rv; - } - - // get authentication password, prompting the user if necessary - // - rv = mAuthPrompter->PromptPassword( - authPromptTitle.get(), authPromptText.get(), - NS_ConvertUTF8toUCS2(spec).get(), - nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, getter_Copies(passwd), - &status); - if (NS_FAILED(rv) || status == PR_FALSE) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPInit(): PromptPassword" - " encountered an error or was cancelled by the user")); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - NS_ERROR_FAILURE, UNBOUND); - return NS_ERROR_FAILURE; - } - } - - // create and initialize an LDAP operation (to be used for the bind) - // - mOperation = do_CreateInstance("@mozilla.org/network/ldap-operation;1", - &rv); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // get a proxy object so the callback happens on the main thread - // - rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsILDAPMessageListener), - NS_STATIC_CAST(nsILDAPMessageListener *, this), - PROXY_ASYNC | PROXY_ALWAYS, - getter_AddRefs(selfProxy)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit(): couldn't " - "create proxy to this object for callback"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // our OnLDAPMessage accepts all result callbacks - // - rv = mOperation->Init(mConnection, selfProxy, nsnull); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_UNEXPECTED; // this should never happen - } - - // kick off a bind operation - // - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession:OnLDAPInit(): initiating " - "SimpleBind\n")); - rv = mOperation->SimpleBind(NS_ConvertUCS2toUTF8(passwd)); - if (NS_FAILED(rv)) { - - switch (rv) { - - case NS_ERROR_LDAP_SERVER_DOWN: - // XXXdmose try to rebind for this one? wait for nsILDAPServer to - // see... - // - case NS_ERROR_LDAP_CONNECT_ERROR: - case NS_ERROR_LDAP_ENCODING_ERROR: - case NS_ERROR_OUT_OF_MEMORY: - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPInit(): mSimpleBind " - "failed, rv = 0x%lx", rv)); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_OK; - - case NS_ERROR_UNEXPECTED: - default: - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_UNEXPECTED; - } - } - - // Change our state to binding. - // - mState = BINDING; - - return NS_OK; -} - -nsresult -nsLDAPAutoCompleteSession::OnLDAPBind(nsILDAPMessage *aMessage) -{ - PRInt32 errCode; - - mOperation = 0; // done with bind op; make nsCOMPtr release it - - // get the status of the bind - // - nsresult rv = aMessage->GetErrorCode(&errCode); - if (NS_FAILED(rv)) { - - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPBind(): couldn't get " - "error code from aMessage"); - - // reset to the default state, and pass along the LDAP error code - // to the formatter - // - FinishAutoCompleteLookup( - nsIAutoCompleteStatus::failureItems, - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, errCode), - UNBOUND); - return NS_ERROR_FAILURE; - } - - // check to be sure the bind succeeded - // - if (errCode != nsILDAPErrors::SUCCESS) { - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_WARNING, - ("nsLDAPAutoCompleteSession::OnLDAPBind(): error binding to " - "LDAP server, errCode = 0x%x", errCode)); - - // if the login failed, tell the wallet to forget this password - // - if ( errCode == nsILDAPErrors::INAPPROPRIATE_AUTH || - errCode == nsILDAPErrors::INVALID_CREDENTIALS ) { - - // make sure the wallet service has been created, and in doing so, - // pass in a login-failed message to tell it to forget this passwd. - // - // apparently getting passwords stored in the wallet - // doesn't require the service to be running, which is why - // this might not exist yet. - // - rv = NS_CreateServicesFromCategory("passwordmanager", mServerURL, - "login-failed"); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::ForgetPassword(): error" - " creating password manager service"); - // not much to do at this point, though conceivably we could - // pop up a dialog telling the user to go manually delete - // this password in the password manager. - } - - // XXXdmose We should probably pop up an error dialog telling - // the user that the login failed here, rather than just bringing - // up the password dialog again, which is what calling OnLDAPInit() - // does. See bug 152997. - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPBind(): auth error;" - " calling OnLDAPInit() again")); - - return OnLDAPInit(nsnull, NS_OK); - } - - // reset to the default state - // - mState = UNBOUND; - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, errCode), - UNBOUND); - return NS_ERROR_FAILURE; - } - - // ok, we're starting a search - // - mState = SEARCHING; - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPBind(): initial search " - "starting\n")); - - return StartLDAPSearch(); -} - -nsresult -nsLDAPAutoCompleteSession::OnLDAPSearchEntry(nsILDAPMessage *aMessage) -{ - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPSearchEntry entered\n")); - - // make sure this is only getting called after StartLDAPSearch has - // initialized the result set - // - NS_ASSERTION(mResultsArray, - "nsLDAPAutoCompleteSession::OnLDAPSearchEntry(): " - "mResultsArrayItems is uninitialized"); - - // Errors in this method return an error (which ultimately gets - // ignored, since this is being called through an async proxy). - // But the important thing is that we're bailing out here rather - // than trying to generate a bogus nsIAutoCompleteItem. Also note - // that FinishAutoCompleteLookup is _NOT_ being called here, because - // this error may just have to do with this particular item. - - // generate an autocomplete item from this message by calling the - // formatter - // - nsCOMPtr item; - nsresult rv = mFormatter->Format(aMessage, getter_AddRefs(item)); - if (NS_FAILED(rv)) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPSearchEntry(): " - "mFormatter->Format() failed")); - return NS_ERROR_FAILURE; - } - - rv = mResultsArray->AppendElement(item); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchEntry(): " - "mItems->AppendElement() failed"); - return NS_ERROR_FAILURE; - } - - // remember that something has been returned - // - mEntriesReturned++; - - return NS_OK; -} - -nsresult -nsLDAPAutoCompleteSession::OnLDAPSearchResult(nsILDAPMessage *aMessage) -{ - nsresult rv; // temp for return vals - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPSearchResult entered\n")); - - // figure out if we succeeded or failed, and set the status - // and default index appropriately - // - AutoCompleteStatus status; - PRInt32 lderrno; - - if (mEntriesReturned) { - - status = nsIAutoCompleteStatus::matchFound; - - // there's at least one match, so the default index should - // point to the first thing here. This ensures that if the local - // addressbook autocomplete session only found foo@local.domain, - // this will be given preference - // - rv = mResults->SetDefaultItemIndex(0); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): " - "mResults->SetDefaultItemIndex(0) failed"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - } - } else { - // note that we only look at the error code if there are no results for - // this session; if we got results and then an error happened, this - // is ignored, in part because it seems likely to be confusing to the - // user, and in part because it is likely to be scrolled out of view - // anyway - // - aMessage->GetErrorCode(&lderrno); - if (lderrno != nsILDAPErrors::SUCCESS) { - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): " - "lderrno=%d\n", lderrno)); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, - NS_ERROR_GENERATE_FAILURE( - NS_ERROR_MODULE_LDAP, lderrno), - BOUND); - return NS_OK; - } - - // we could potentially keep track of non-fatal errors to the - // search, and if there has been more than 1, and there are no entries, - // we could return |failed| instead of |noMatch|. It's unclear to me - // that this actually buys us anything though. - // - status = nsIAutoCompleteStatus::noMatch; - } - - // call the mListener's OnAutoComplete and clean up - // - // XXXdmose should we really leave the connection BOUND here? - FinishAutoCompleteLookup(status, NS_OK, BOUND); - - return NS_OK; -} - -nsresult -nsLDAPAutoCompleteSession::StartLDAPSearch() -{ - nsresult rv; // temp for xpcom return values - nsCOMPtr selfProxy; // for callback - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::StartLDAPSearch entered\n")); - - // create and initialize an LDAP operation (to be used for the search - // - mOperation = - do_CreateInstance("@mozilla.org/network/ldap-operation;1", &rv); - - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't " - "create @mozilla.org/network/ldap-operation;1"); - - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_FAILURE; - } - - // get a proxy object so the callback happens on the main thread - // - rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsILDAPMessageListener), - NS_STATIC_CAST(nsILDAPMessageListener *, this), - PROXY_ASYNC | PROXY_ALWAYS, - getter_AddRefs(selfProxy)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't " - "create proxy to this object for callback"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_FAILURE; - } - - // initialize the LDAP operation object - // - rv = mOperation->Init(mConnection, selfProxy, nsnull); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't " - "initialize LDAP operation"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - // set the server and client controls on the operation - if (mSearchServerControls) { - rv = mOperation->SetServerControls(mSearchServerControls); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't " - "initialize LDAP search operation server controls"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - } - if (mSearchClientControls) { - rv = mOperation->SetClientControls(mSearchClientControls); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't " - "initialize LDAP search operation client controls"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - } - - // get the search filter associated with the directory server url; - // it will be ANDed with the rest of the search filter that we're using. - // - nsCAutoString urlFilter; - rv = mServerURL->GetFilter(urlFilter); - if ( NS_FAILED(rv) ){ - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - // get the LDAP service, since createFilter is called through it. - // - nsCOMPtr 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"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - 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 - // - nsCAutoString prefix, suffix; - if (urlFilter.Length() && !urlFilter.Equals(NS_LITERAL_CSTRING("(objectclass=*)"))) { - - // if urlFilter isn't parenthesized, we need to add in parens so that - // the filter works as a term to & - // - if (urlFilter[0] != '(') { - prefix = NS_LITERAL_CSTRING("(&(") + urlFilter + - NS_LITERAL_CSTRING(")"); - } else { - prefix = NS_LITERAL_CSTRING("(&") + urlFilter; - } - - suffix = ')'; - } - - // generate an LDAP search filter from mFilterTemplate. If it's unset, - // use the default. - // -#define MAX_AUTOCOMPLETE_FILTER_SIZE 1024 - nsCAutoString searchFilter; - rv = ldapSvc->CreateFilter(MAX_AUTOCOMPLETE_FILTER_SIZE, - mFilterTemplate, - prefix, suffix, EmptyCString(), - NS_ConvertUCS2toUTF8(mSearchString), - searchFilter); - if (NS_FAILED(rv)) { - switch(rv) { - - case NS_ERROR_OUT_OF_MEMORY: - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - 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)); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - 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"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - } - - // If the results array for this search hasn't already been created, do - // so now. Note that we don't return ::failureItems here, because if - // there's no array, there's nowhere to put the items. - // - rv = CreateResultsArray(); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed, rv, BOUND); - } - - // nothing returned yet! - // - mEntriesReturned = 0; - - // get the base dn to search - // - nsCAutoString dn; - rv = mServerURL->GetDn(dn); - if ( NS_FAILED(rv) ){ - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - // and the scope - // - PRInt32 scope; - rv = mServerURL->GetScope(&scope); - if ( NS_FAILED(rv) ){ - mState = BOUND; - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - // take the relevant controls on this object and set them - // on the operation - rv = mOperation->SetServerControls(mSearchServerControls.get()); - if ( NS_FAILED(rv) ){ - mState = BOUND; - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - rv = mOperation->SetClientControls(mSearchClientControls.get()); - if ( NS_FAILED(rv) ){ - mState = BOUND; - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - - // time to kick off the search. - // - // XXXdmose what about timeouts? - // - rv = mOperation->SearchExt(dn, scope, searchFilter, mSearchAttrsSize, - NS_CONST_CAST(const char **, mSearchAttrs), - 0, mMaxHits); - if (NS_FAILED(rv)) { - switch(rv) { - - case NS_ERROR_LDAP_ENCODING_ERROR: - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt " - "returned NS_ERROR_LDAP_ENCODING_ERROR")); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_OK; - - case NS_ERROR_LDAP_FILTER_ERROR: - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt " - "returned NS_ERROR_LDAP_FILTER_ERROR")); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_OK; - - case NS_ERROR_LDAP_SERVER_DOWN: - // XXXdmose discuss with leif how to handle this in general in the - // LDAP XPCOM SDK. - - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt " - "returned NS_ERROR_LDAP_SERVER_DOWN")); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_OK; - - case NS_ERROR_OUT_OF_MEMORY: - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_OUT_OF_MEMORY; - - case NS_ERROR_LDAP_NOT_SUPPORTED: - case NS_ERROR_NOT_INITIALIZED: - case NS_ERROR_INVALID_ARG: - default: - - // all this stuff indicates code bugs - // - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt " - "returned unexpected value"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - BOUND); - return NS_ERROR_UNEXPECTED; - } - } - - return NS_OK; -} - -// XXXdmose - stopgap routine until nsLDAPService is working -// -nsresult -nsLDAPAutoCompleteSession::InitConnection() -{ - nsresult rv; // temp for xpcom return values - nsCOMPtr selfProxy; - - // create an LDAP connection - // - mConnection = do_CreateInstance( - "@mozilla.org/network/ldap-connection;1", &rv); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): could " - "not create @mozilla.org/network/ldap-connection;1"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // have we been properly initialized? - // - if (!mServerURL) { - NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): mServerURL " - "is NULL"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_NOT_INITIALIZED; - } - - // host to connect to - // - nsCAutoString host; - rv = mServerURL->GetAsciiHost(host); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // on which port - // - PRInt32 port; - rv = mServerURL->GetPort(&port); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // which options - // - PRUint32 options; - rv = mServerURL->GetOptions(&options); - if (NS_FAILED(rv)) { - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // get a proxy object so the callback happens on the main thread - // - rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsILDAPMessageListener), - NS_STATIC_CAST(nsILDAPMessageListener *, this), - PROXY_ASYNC | PROXY_ALWAYS, - getter_AddRefs(selfProxy)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): couldn't " - "create proxy to this object for callback"); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_FAILURE; - } - - // Initialize the connection. This will cause an asynchronous DNS - // lookup to occur, and we'll finish the binding of the connection - // in the OnLDAPInit() listener function. - // - rv = mConnection->Init(host.get(), port, - (options & nsILDAPURL::OPT_SECURE) ? PR_TRUE - : PR_FALSE, mLogin, selfProxy, nsnull, mVersion); - if (NS_FAILED(rv)) { - switch (rv) { - - case NS_ERROR_OUT_OF_MEMORY: - case NS_ERROR_NOT_AVAILABLE: - case NS_ERROR_FAILURE: - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::InitConnection(): mSimpleBind " - "failed, rv = 0x%lx", rv)); - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return rv; - - case NS_ERROR_ILLEGAL_VALUE: - default: - FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv, - UNBOUND); - return NS_ERROR_UNEXPECTED; - } - } - - // set our state - // - mState = INITIALIZING; - - return NS_OK; -} - -nsresult -nsLDAPAutoCompleteSession::CreateResultsArray(void) -{ - nsresult rv; - - // create a result set - // - mResults = do_CreateInstance(NS_AUTOCOMPLETERESULTS_CONTRACTID, &rv); - - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't" - " create " NS_AUTOCOMPLETERESULTS_CONTRACTID); - return NS_ERROR_FAILURE; - } - - // This seems to be necessary for things to work, though I'm not sure - // why that's true. - // - rv = mResults->SetSearchString(mSearchString.get()); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): couldn't " - "set search string in results object"); - return NS_ERROR_FAILURE; - } - - // get a pointer to the array in question now, so that we don't have to - // keep re-fetching it every time an entry callback happens - // - rv = mResults->GetItems(getter_AddRefs(mResultsArray)); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't " - "get results array."); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -void -nsLDAPAutoCompleteSession::FinishAutoCompleteLookup( - AutoCompleteStatus aACStatus, const nsresult aResult, - enum SessionState aEndState) -{ - nsCOMPtr errorItem; // pointer to item we may create - nsresult rv; // temp for return value - - // if there's a listener, inform the listener that the search is over - // - rv = NS_OK; - if (mListener) { - - switch (aACStatus) { - - case nsIAutoCompleteStatus::matchFound: - rv = mListener->OnAutoComplete(mResults, aACStatus); - break; - - case nsIAutoCompleteStatus::failureItems: - // if the results array hasn't already been created, make one - // to return the error message. If there's an error, fallback - // to ::failed - // - if (!mResults) { - rv = CreateResultsArray(); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::" - "FinishAutoCompleteLookup():" - " CreateResultsArray() failed"); - rv = mListener->OnAutoComplete(0, - nsIAutoCompleteStatus::failed); - break; - } - } - - // create the error item - // - rv = mFormatter->FormatException(mState, aResult, - getter_AddRefs(errorItem)); - if (NS_SUCCEEDED(rv)) { - - // try and append the error item; falling back to ::failed - // if there's a problem - // - rv = mResultsArray->AppendElement(errorItem); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::" - "FinishAutoCompleteLookup():" - " mItems->AppendElement() failed"); - rv = mListener->OnAutoComplete(0, - nsIAutoCompleteStatus::failed); - break; - } - - // we don't want the autocomplete widget trying to - // automagically use the error item for anything. If - // something goes wrong here, continue on anyway. - // - (void)mResults->SetDefaultItemIndex(-1); - - rv = mListener->OnAutoComplete(mResults, - nsIAutoCompleteStatus::failureItems); - break; - } - - // fallback to ::failed - NS_ERROR("nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(): " - "error calling FormatException()"); - - rv = mListener->OnAutoComplete(0, nsIAutoCompleteStatus::failed); - break; - - case nsIAutoCompleteStatus::failed: - default: - rv = mListener->OnAutoComplete(0, aACStatus); - break; - } - - } else { - // if there's no listener, something's wrong - // - NS_ERROR("nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(): " - "called with mListener unset!"); - } - - if (NS_FAILED(rv)) { - - // there's nothing we can actually do here other than warn - // - NS_WARNING("nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(): " - "error calling mListener->OnAutoComplete()"); - } - - // set the state appropriately - // - mState = aEndState; - - // we're done with various things; cause nsCOMPtr to release them - // - mResultsArray = 0; - mResults = 0; - mListener = 0; - mOperation = 0; - - // If we are unbound, drop the connection (if any) - // - if (mState == UNBOUND) { - mConnection = 0; - } -} - -// methods for nsILDAPAutoCompleteSession - -// attribute AUTF8String searchFilter; -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetFilterTemplate(nsACString & aFilterTemplate) -{ - aFilterTemplate.Assign(mFilterTemplate); - - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetFilterTemplate(const nsACString & aFilterTemplate) -{ - mFilterTemplate.Assign(aFilterTemplate); - - return NS_OK; -} - - -// attribute long maxHits; -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetMaxHits(PRInt32 *aMaxHits) -{ - if (!aMaxHits) { - return NS_ERROR_NULL_POINTER; - } - - *aMaxHits = mMaxHits; - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetMaxHits(PRInt32 aMaxHits) -{ - if ( aMaxHits < -1 || aMaxHits > 65535) { - return NS_ERROR_ILLEGAL_VALUE; - } - - mMaxHits = aMaxHits; - return NS_OK; -} - -// attribute nsILDAPURL serverURL; -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetServerURL(nsILDAPURL * *aServerURL) -{ - if (! aServerURL ) { - return NS_ERROR_NULL_POINTER; - } - - NS_IF_ADDREF(*aServerURL = mServerURL); - - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetServerURL(nsILDAPURL * aServerURL) -{ - if (! aServerURL ) { - return NS_ERROR_NULL_POINTER; - } - - mServerURL = aServerURL; - - // the following line will cause the next call to OnStartLookup to - // call InitConnection again. This will reinitialize all the relevant - // member variables and kick off an LDAP bind. By virtue of the magic of - // nsCOMPtrs, doing this will cause all the nsISupports-based stuff to - // be Released, which will eventually result in the old connection being - // destroyed, and the destructor for that calls ldap_unbind() - // - mState = UNBOUND; - - 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; -} - -// attribute unsigned long cjkMinStringLength -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetCjkMinStringLength(PRUint32 *aCjkMinStringLength) -{ - if (!aCjkMinStringLength) { - return NS_ERROR_NULL_POINTER; - } - - *aCjkMinStringLength = mCjkMinStringLength; - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetCjkMinStringLength(PRUint32 aCjkMinStringLength) -{ - mCjkMinStringLength = aCjkMinStringLength; - - return NS_OK; -} - -// check to see if the message returned is related to our current operation -// if there is no current operation, it's not. :-) -// -nsresult -nsLDAPAutoCompleteSession::IsMessageCurrent(nsILDAPMessage *aMessage, - PRBool *aIsCurrent) -{ - // if there's no operation, this message must be stale (ie non-current) - // - if ( !mOperation ) { - *aIsCurrent = PR_FALSE; - return NS_OK; - } - - // get the message id from the current operation - // - PRInt32 currentId; - nsresult rv = mOperation->GetMessageID(¤tId); - if (NS_FAILED(rv)) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::IsMessageCurrent(): unexpected " - "error 0x%lx calling mOperation->GetMessageId()", rv)); - return NS_ERROR_UNEXPECTED; - } - - // get the message operation from the message - // - nsCOMPtr msgOp; - rv = aMessage->GetOperation(getter_AddRefs(msgOp)); - if (NS_FAILED(rv)) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::IsMessageCurrent(): unexpected " - "error 0x%lx calling aMessage->GetOperation()", rv)); - return NS_ERROR_UNEXPECTED; - } - - // get the message operation id from the message operation - // - PRInt32 msgOpId; - rv = msgOp->GetMessageID(&msgOpId); - if (NS_FAILED(rv)) { - PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG, - ("nsLDAPAutoCompleteSession::IsMessageCurrent(): unexpected " - "error 0x%lx calling msgOp->GetMessageId()", rv)); - return NS_ERROR_UNEXPECTED; - } - - *aIsCurrent = (msgOpId == currentId); - - return NS_OK; -} - -// attribute nsILDAPAutoCompFormatter formatter -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetFormatter(nsILDAPAutoCompFormatter* *aFormatter) -{ - if (! aFormatter ) { - return NS_ERROR_NULL_POINTER; - } - - NS_IF_ADDREF(*aFormatter = mFormatter); - - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetFormatter(nsILDAPAutoCompFormatter* aFormatter) -{ - if (! aFormatter ) { - return NS_ERROR_NULL_POINTER; - } - - NS_ASSERTION(mState == UNBOUND || mState == BOUND, - "nsLDAPAutoCompleteSession::SetFormatter was called when " - "mState was set to something other than BOUND or UNBOUND"); - - mFormatter = aFormatter; - - // get and cache the attributes that will be used to do lookups - // - nsresult rv = mFormatter->GetAttributes(&mSearchAttrsSize, &mSearchAttrs); - if (NS_FAILED(rv)) { - NS_ERROR("nsLDAPAutoCompleteSession::SetFormatter(): " - " mFormatter->GetAttributes failed"); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetLogin(const nsACString & aLogin) -{ - mLogin = aLogin; - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetLogin(nsACString & aLogin) -{ - aLogin = mLogin; - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetAuthPrompter(nsIAuthPrompt **aAuthPrompter) -{ - NS_IF_ADDREF(*aAuthPrompter = mAuthPrompter); - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetAuthPrompter(nsIAuthPrompt *aAuthPrompter) -{ - mAuthPrompter = aAuthPrompter; - return NS_OK; -} - -// attribute unsigned long version; -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetVersion(PRUint32 *aVersion) -{ - if (!aVersion) { - return NS_ERROR_NULL_POINTER; - } - - *aVersion = mVersion; - return NS_OK; -} -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetVersion(PRUint32 aVersion) -{ - if ( mVersion != nsILDAPConnection::VERSION2 && - mVersion != nsILDAPConnection::VERSION3) { - return NS_ERROR_ILLEGAL_VALUE; - } - - mVersion = aVersion; - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetSearchServerControls(nsIMutableArray **aControls) -{ - NS_IF_ADDREF(*aControls = mSearchServerControls); - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetSearchServerControls(nsIMutableArray *aControls) -{ - mSearchServerControls = aControls; - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::GetSearchClientControls(nsIMutableArray **aControls) -{ - NS_IF_ADDREF(*aControls = mSearchClientControls); - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPAutoCompleteSession::SetSearchClientControls(nsIMutableArray *aControls) -{ - mSearchClientControls = aControls; - return NS_OK; -} - -#endif diff --git a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h deleted file mode 100644 index eb5209f6656..00000000000 --- a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dan Mosedale (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCOMPtr.h" -#include "nsIAutoCompleteSession.h" -#include "nsILDAPConnection.h" -#include "nsILDAPOperation.h" -#include "nsILDAPMessageListener.h" -#include "nsILDAPAutoCompleteSession.h" -#include "nsILDAPAutoCompFormatter.h" -#include "nsILDAPURL.h" -#include "nsString.h" -#include "nsISupportsArray.h" -#include "nsIConsoleService.h" -#include "nsIAuthPrompt.h" -#include "nsIArray.h" - -// 964665d0-1dd1-11b2-aeae-897834fb00b9 -// -#define NS_LDAPAUTOCOMPLETESESSION_CID \ -{ 0x964665d0, 0x1dd1, 0x11b2, \ - { 0xae, 0xae, 0x89, 0x78, 0x34, 0xfb, 0x00, 0xb9 }} - -class nsLDAPAutoCompleteSession : public nsILDAPMessageListener, - public nsILDAPAutoCompleteSession -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIAUTOCOMPLETESESSION - NS_DECL_NSILDAPMESSAGELISTENER - NS_DECL_NSILDAPAUTOCOMPLETESESSION - - nsLDAPAutoCompleteSession(); - virtual ~nsLDAPAutoCompleteSession(); - - protected: - enum SessionState { - UNBOUND = nsILDAPAutoCompFormatter::STATE_UNBOUND, - INITIALIZING = nsILDAPAutoCompFormatter::STATE_INITIALIZING, - BINDING = nsILDAPAutoCompFormatter::STATE_BINDING, - BOUND = nsILDAPAutoCompFormatter::STATE_BOUND, - SEARCHING = nsILDAPAutoCompFormatter::STATE_SEARCHING - } mState; - PRUint32 mEntriesReturned; // # of entries returned? - nsCOMPtr mConnection; // connection used for search - nsCOMPtr mOperation; // current ldap op - nsCOMPtr mListener; // callback - nsCOMPtr mResults; // being built up - nsCOMPtr mResultsArray; // cached, to avoid re-gets - nsString mSearchString; // autocomplete this string - nsCString mFilterTemplate; // search filter template - nsCOMPtr mServerURL; // URL for the directory to search - PRInt32 mMaxHits; // return at most this many entries - PRUint32 mMinStringLength; // strings < this size are ignored - PRUint32 mCjkMinStringLength; // ignore CJK strings < this size - char **mSearchAttrs; // outputFormat search attrs for SearchExt call - PRUint32 mSearchAttrsSize; // size of above array - nsCOMPtr mAuthPrompter; // used to prompt for the password - PRUint32 mVersion; // version of LDAP to use - -// XXX hack until nsUTF8String exists -#define nsUTF8String nsCString - nsUTF8String mLogin; // authenticate as this user - - // used to format the ldap message into an nsIAutoCompleteItem - // - nsCOMPtr mFormatter; - - // stopgap until nsLDAPService works - nsresult InitConnection(); - - // check that we bound ok and start then call StartLDAPSearch - nsresult OnLDAPBind(nsILDAPMessage *aMessage); - - // add to the results set - nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage); - - // all done; call OnAutoComplete - nsresult OnLDAPSearchResult(nsILDAPMessage *aMessage); - - // kick off a search - nsresult StartLDAPSearch(); - - // check if the LDAP message received is current - nsresult IsMessageCurrent(nsILDAPMessage *aMessage, PRBool *aIsCurrent); - - // finish a search by calling mListener->OnAutoComplete, resetting state, - // and freeing resources. if aACStatus == - // nsIAutoCompleteStatus::failureItems, then the formatter is called with - // aResult and aEndState to create an autocomplete item with the error - // info in it. See nsILDAPAutoCompFormatter.idl for more info on this. - void FinishAutoCompleteLookup(AutoCompleteStatus aACStatus, - const nsresult aResult, - enum SessionState aEndState); - - // create and initialize the results array - nsresult CreateResultsArray(void); - - nsCOMPtr mSearchServerControls; - nsCOMPtr mSearchClientControls; -}; - diff --git a/mozilla/xpfe/components/jar.mn b/mozilla/xpfe/components/jar.mn index 772ffec0009..fe0a0fd4cba 100644 --- a/mozilla/xpfe/components/jar.mn +++ b/mozilla/xpfe/components/jar.mn @@ -186,7 +186,6 @@ en-US.jar: locale/en-US/global/console.properties (console/resources/locale/en-US/console.properties) locale/en-US/global/finddialog.dtd (find/resources/locale/en-US/finddialog.dtd) locale/en-US/global/finddialog.properties (find/resources/locale/en-US/finddialog.properties) - locale/en-US/global/ldapAutoCompErrs.properties (autocomplete/resources/locale/en-US/ldapAutoCompErrs.properties) * locale/en-US/cookie/contents.rdf (cookie/locale/en-US/contents.rdf) locale/en-US/cookie/cookieAcceptDialog.properties (/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.properties) locale/en-US/cookie/cookieAcceptDialog.dtd (/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.dtd)