Back to index

lightning-sunbird  0.9+nobinonly
nsLDAPAutoCompleteSession.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * 
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Dan Mosedale <dmose@netscape.com> (Original Author)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsCOMPtr.h"
00041 #include "nsIAutoCompleteSession.h"
00042 #include "nsILDAPConnection.h"
00043 #include "nsILDAPOperation.h"
00044 #include "nsILDAPMessageListener.h"
00045 #include "nsILDAPAutoCompleteSession.h"
00046 #include "nsILDAPAutoCompFormatter.h"
00047 #include "nsILDAPURL.h"
00048 #include "nsString.h"
00049 #include "nsISupportsArray.h"
00050 #include "nsIConsoleService.h"
00051 #include "nsIAuthPrompt.h"
00052 #include "nsIArray.h"
00053 
00054 // 964665d0-1dd1-11b2-aeae-897834fb00b9
00055 //
00056 #define NS_LDAPAUTOCOMPLETESESSION_CID \
00057 { 0x964665d0, 0x1dd1, 0x11b2, \
00058  { 0xae, 0xae, 0x89, 0x78, 0x34, 0xfb, 0x00, 0xb9 }}
00059 
00060 class nsLDAPAutoCompleteSession : public nsILDAPMessageListener, 
00061                                   public nsILDAPAutoCompleteSession
00062 {
00063   public:
00064     NS_DECL_ISUPPORTS
00065     NS_DECL_NSIAUTOCOMPLETESESSION
00066     NS_DECL_NSILDAPMESSAGELISTENER
00067     NS_DECL_NSILDAPAUTOCOMPLETESESSION
00068 
00069     nsLDAPAutoCompleteSession();
00070     virtual ~nsLDAPAutoCompleteSession();
00071 
00072   protected:
00073     enum SessionState { 
00074         UNBOUND = nsILDAPAutoCompFormatter::STATE_UNBOUND,
00075         INITIALIZING = nsILDAPAutoCompFormatter::STATE_INITIALIZING, 
00076         BINDING = nsILDAPAutoCompFormatter::STATE_BINDING, 
00077         BOUND = nsILDAPAutoCompFormatter::STATE_BOUND, 
00078         SEARCHING = nsILDAPAutoCompFormatter::STATE_SEARCHING 
00079     } mState;
00080     PRUint32 mEntriesReturned;                    // # of entries returned?
00081     nsCOMPtr<nsILDAPConnection> mConnection;      // connection used for search
00082     nsCOMPtr<nsILDAPOperation> mOperation;        // current ldap op
00083     nsCOMPtr<nsIAutoCompleteListener> mListener;  // callback 
00084     nsCOMPtr<nsIAutoCompleteResults> mResults;    // being built up
00085     nsCOMPtr<nsISupportsArray> mResultsArray;     // cached, to avoid re-gets
00086     nsString mSearchString;                       // autocomplete this string
00087     nsCString mFilterTemplate;                    // search filter template
00088     nsCOMPtr<nsILDAPURL> mServerURL;        // URL for the directory to search
00089     PRInt32 mMaxHits;                       // return at most this many entries
00090     PRUint32 mMinStringLength;              // strings < this size are ignored
00091     PRUint32 mCjkMinStringLength;           // ignore CJK strings < this size
00092     char **mSearchAttrs;        // outputFormat search attrs for SearchExt call
00093     PRUint32 mSearchAttrsSize;              // size of above array
00094     nsCOMPtr<nsIAuthPrompt> mAuthPrompter;  // used to prompt for the password
00095     PRUint32 mVersion;                      // version of LDAP to use
00096 
00097 // XXX hack until nsUTF8String exists
00098 #define nsUTF8String nsCString
00099     nsUTF8String mLogin;                       // authenticate as this user
00100 
00101     // used to format the ldap message into an nsIAutoCompleteItem
00102     //
00103     nsCOMPtr<nsILDAPAutoCompFormatter> mFormatter;
00104 
00105     // stopgap until nsLDAPService works
00106     nsresult InitConnection();             
00107 
00108     // check that we bound ok and start then call StartLDAPSearch
00109     nsresult OnLDAPBind(nsILDAPMessage *aMessage); 
00110 
00111     // add to the results set
00112     nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage); 
00113 
00114     // all done; call OnAutoComplete
00115     nsresult OnLDAPSearchResult(nsILDAPMessage *aMessage); 
00116 
00117     // kick off a search
00118     nsresult StartLDAPSearch();
00119 
00120     // check if the LDAP message received is current
00121     nsresult IsMessageCurrent(nsILDAPMessage *aMessage, PRBool *aIsCurrent);
00122 
00123     // finish a search by calling mListener->OnAutoComplete, resetting state,
00124     // and freeing resources.  if aACStatus == 
00125     // nsIAutoCompleteStatus::failureItems, then the formatter is called with
00126     // aResult and aEndState to create an autocomplete item with the error
00127     // info in it.  See nsILDAPAutoCompFormatter.idl for more info on this.
00128     void FinishAutoCompleteLookup(AutoCompleteStatus aACStatus, 
00129                                   const nsresult aResult,
00130                                   enum SessionState aEndState);
00131 
00132     // create and initialize the results array
00133     nsresult CreateResultsArray(void);
00134 
00135     nsCOMPtr<nsIMutableArray> mSearchServerControls;
00136     nsCOMPtr<nsIMutableArray> mSearchClientControls;
00137 };
00138