Back to index

lightning-sunbird  0.9+nobinonly
nsLDAPConnection.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 the mozilla.org LDAP XPCOM SDK.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2000
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Dan Mosedale <dmose@mozilla.org>
00025  *   Leif Hedstrom <leif@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef _nsLDAPConnection_h_
00042 #define _nsLDAPConnection_h_
00043 
00044 #include "nsILDAPConnection.h"
00045 #include "ldap.h"
00046 #include "nsString.h"
00047 #include "nsIThread.h"
00048 #include "nsIRunnable.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsILDAPMessageListener.h"
00051 #include "nsHashtable.h"
00052 #include "nspr.h"
00053 #include "nsWeakReference.h"
00054 #include "nsWeakPtr.h"
00055 #include "nsIDNSListener.h"
00056 #include "nsICancelable.h"
00057 #include "nsIRequest.h"
00058 
00059 // 0d871e30-1dd2-11b2-8ea9-831778c78e93
00060 //
00061 #define NS_LDAPCONNECTION_CID \
00062 { 0x0d871e30, 0x1dd2, 0x11b2, \
00063  { 0x8e, 0xa9, 0x83, 0x17, 0x78, 0xc7, 0x8e, 0x93 }}
00064 
00065 class nsLDAPConnectionLoop;
00066 
00067 class nsLDAPConnection : public nsILDAPConnection,
00068                          public nsSupportsWeakReference,
00069                          public nsIDNSListener
00070 
00071 {
00072     friend class nsLDAPOperation;
00073     friend class nsLDAPMessage;
00074     friend class nsLDAPConnectionLoop;
00075     friend PRBool PR_CALLBACK CheckLDAPOperationResult(nsHashKey *aKey, 
00076                                                        void *aData,
00077                                                        void* aClosure);
00078 
00079   public:
00080     NS_DECL_ISUPPORTS
00081     NS_DECL_NSILDAPCONNECTION
00082     NS_DECL_NSIDNSLISTENER
00083 
00084     // constructor & destructor
00085     //
00086     nsLDAPConnection();
00087     virtual ~nsLDAPConnection();
00088 
00089   protected:
00090     // invoke the callback associated with a given message, and possibly 
00091     // delete it from the connection queue
00092     //
00093     nsresult InvokeMessageCallback(LDAPMessage *aMsgHandle, 
00094                                    nsILDAPMessage *aMsg,
00095                                    PRBool aRemoveOpFromConnQ);
00108     nsresult AddPendingOperation(nsILDAPOperation *aOperation);
00109 
00119     nsresult RemovePendingOperation(nsILDAPOperation *aOperation);
00120 
00121     void Close();                       // close the connection
00122     LDAP *mConnectionHandle;            // the LDAP C SDK's connection object
00123     nsCString mBindName;                // who to bind as
00124     nsCOMPtr<nsIThread> mThread;        // thread which marshals results
00125 
00126     nsSupportsHashtable *mPendingOperations; // keep these around for callbacks
00127     nsLDAPConnectionLoop *mRunnable;    // nsIRunnable object
00128 
00129     PRInt32 mPort;                      // The LDAP port we're binding to
00130     PRBool mSSL;                        // the options
00131     PRUint32 mVersion;                  // LDAP protocol version
00132 
00133     nsCString mResolvedIP;              // Preresolved list of host IPs
00134     nsCOMPtr<nsILDAPMessageListener> mInitListener; // Init callback
00135     nsCOMPtr<nsICancelable> mDNSRequest;   // The "active" DNS request
00136     nsCString               mDNSHost;   // The hostname being resolved
00137     nsCOMPtr<nsISupports> mClosure;     // private parameter (anything caller desires)
00138 };
00139 
00140 // This class implements the nsIRunnable interface, in this case just a
00141 // Run() method. This is to be used within the nsLDAPConnection only, when
00142 // creating a new thread.
00143 //
00144 class nsLDAPConnectionLoop : public nsIRunnable
00145 {
00146     friend class nsLDAPConnection;
00147     friend class nsLDAPMessage;
00148 
00149   public:
00150     NS_DECL_ISUPPORTS
00151     NS_DECL_NSIRUNNABLE
00152 
00153     // constructor & destructor
00154     //
00155     nsLDAPConnectionLoop();
00156     virtual ~nsLDAPConnectionLoop();
00157 
00158     NS_IMETHOD Init();
00159 
00160     nsWeakPtr mWeakConn;        // the connection object, a weak reference
00161     nsLDAPConnection *mRawConn; // raw version of the connection object ptr
00162     PRLock *mLock;              // Lock mechanism, since weak references
00163                                 // aren't thread safe
00164 };
00165 
00166 #endif // _nsLDAPConnection_h_