Bug 1672902 - Remove unused nsILDAPService methods. r=mkmelin
authorBen Campbell <ben@thunderbird.net>
Fri, 27 Nov 2020 12:53:07 +0200
changeset 95752 75d7bbd322cc6c229ae7744c40ea008ca433331f
parent 95748 508b9ca35fac86bb69aed35998ed4dce81b39634
child 95753 dcb6687561af00e4e22b463c27b66b2f222190f9
push id12266
push useralessandro@thunderbird.net
push dateFri, 27 Nov 2020 18:08:17 +0000
treeherdertry-comm-central@8c7cdfd510a2 [default view] [failures only]
reviewersmkmelin
bugs1672902
Bug 1672902 - Remove unused nsILDAPService methods. r=mkmelin
ldap/xpcom/public/nsILDAPService.idl
ldap/xpcom/src/nsLDAPService.cpp
ldap/xpcom/src/nsLDAPService.h
--- a/ldap/xpcom/public/nsILDAPService.idl
+++ b/ldap/xpcom/public/nsILDAPService.idl
@@ -1,171 +1,34 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 interface nsILDAPServer;
-interface nsILDAPConnection;
-interface nsILDAPMessageListener;
+
 
 /**
- * This interface provides an LDAP connection management service.
- * It's used to cache already established LDAP connections, as well
- * as reaping unused connections after a certain time period. This
- * is done completely asynchronously, using callback functions.
+ * This interface is a catch-all for any LDAP functionality that is needed
+ * in XPCOM and not provided elsewhere.
  */
-
-
 [scriptable, uuid(69de6fbc-2e8c-4482-bf14-358d68b785d1)]
 interface nsILDAPService : nsISupports {
 
     /**
-     * Add a (possibly) new LDAP server entry to the service. A
-     * server entry holds information about the host, port and
-     * other components of the LDAP URL, as well as information
-     * used for binding a connection to the LDAP server.
-     *
-     * An LDAP Server entry (nsILDAPServer) contains the URL,
-     * user credentials, and other information related to the actual
-     * server itself. It is used for connecting, binding, rebinding,
-     * setting timeouts and so forth.
-     *
-     * @param aServer          an nsILDAPServer object
-     *
-     * @exception NS_ERROR_FAILURE          the server has already been
-     *                                      added to the service
-     * @exception NS_ERROR_NULL_POINTER     NULL pointer
-     * @exception NS_ERROR_OUT_OF_MEMORY    ran out of memory
-     */
-    void addServer(in nsILDAPServer aServer);
-
-    /**
-     * Mark an LDAP server, in the Service, as a candidate for
-     * deletion. If there are still leases ("users") of this server,
-     * the operation fails.
-     *
-     * @param aKey             unique key identifying the server entry
-     *
-     * @exception NS_ERROR_FAILURE          either the server doesn't
-     *                                      exist, or there are still
-     *                                      leases outstanding
-     */
-    void deleteServer(in wstring aKey);
-
-    /**
-     * Get the nsILDAPServer object for the specified server entry
-     * in the service.
-     *
-     * @param aKey             unique key identifying the server entry
-     *
-     * @exception NS_ERROR_FAILURE          there is no server registered
-     *                                      in the service with this key
-     * @exception NS_ERROR_NULL_POINTER     NULL pointer
-     */
-    nsILDAPServer getServer(in wstring aKey);
-
-    /**
-     * Request a connection from the service, asynchronously. If there is
-     * one "cached" already, we will actually call the callback function
-     * before returning from this function. This might be considered a bug,
-     * but for now be aware of this (see Bugzilla bug #75989).
-     *
-     * Calling this method does not increment the leases on this connection,
-     * you'll have to use the getConnection() method to actually get the
-     * connection itself (presumably from the callback/listener object).
-     * The listener needs to implement nsILDAPMessageListener, providing
-     * the OnLDAPMessage() method.
-     *
-     * @param aKey             unique key identifying the server entry
-     * @param aMessageListener the listener object, which we will call
-     *                         when the LDAP bind message is available
-     *
-     * @exception NS_ERROR_FAILURE          there is no server registered
-     *                                      in the service with this key,
-     *                                      or we were unable to get a
-     *                                      connection properly to the server
-     * @exception NS_ERROR_NOT_AVAILABLE    couldn't create connection thread
-     * @exception NS_ERROR_OUT_OF_MEMORY    ran out of memory
-     * @exception NS_ERROR_UNEXPECTED       unknown or unexpected error...
-     */
-    void requestConnection(in wstring aKey,
-                           in nsILDAPMessageListener aListener);
-
-    /**
-     * This is the nsLDAPConnection object related to this server.
-     * This does increase the lease counter on the object, so you have
-     * to call the releaseConnection() method to return it. It is
-     * important that you do this in matching pairs, and that you do
-     * not keep any dangling references to an object around after you
-     * have called the releaseConnection() method.
-     *
-     * @param aKey             unique key identifying the server entry
-     *
-     * @exception NS_ERROR_FAILURE          there is no server registered
-     *                                      in the service with this key
-     * @exception NS_ERROR_NULL_POINTER     NULL pointer
-     */
-    nsILDAPConnection getConnection(in wstring aKey);
-
-    /**
-     * Release the lease on a (cached) LDAP connection, making it a
-     * potential candidate for disconnection. Note that this will not
-     * delete the actual LDAP server entry in the service, it's still
-     * registered and can be used in future calls to requestConnection().
-     *
-     * This API might be deprecated in the future, once we figure out how
-     * to use weak references to support our special needs for reference
-     * counting. For the time being, it is vital that you call this function
-     * when you're done with a Connection, and that you do not keep any
-     * copies of the Connection object lingering around.
-     *
-     * @param aKey             unique key identifying the server entry
-     *
-     * @exception NS_ERROR_FAILURE          there is no server registered
-     *                                      in the service with this key
-     * @exception NS_ERROR_OUT_OF_MEMORY    ran out of memory
-     */
-    void releaseConnection(in wstring aKey);
-
-    /**
-     * If we detect that a connection is broken (server disconnected us,
-     * or any other problem with the link), we need to try to reestablish
-     * the connection. This is very similar to requestConnection(),
-     * except you use this when detecting an error with a connection
-     * that is being cached.
-     *
-     * @param aKey             unique key identifying the server entry
-     * @param aMessageListener the listener object, which we will call
-     *                         when the LDAP bind message is available
-     *
-     * @exception NS_ERROR_FAILURE          there is no server registered
-     *                                      in the service with this key,
-     *                                      or we were unable to get a
-     *                                      connection properly to the server
-     * @exception NS_ERROR_NOT_AVAILABLE    couldn't create connection thread
-     * @exception NS_ERROR_OUT_OF_MEMORY    ran out of memory
-     * @exception NS_ERROR_UNEXPECTED       unknown or unexpected error...
-     */
-    void reconnectConnection(in wstring aKey,
-                             in nsILDAPMessageListener aListener);
-
-    /**
      * Generates and returns an LDAP search filter by substituting
      * aValue, aAttr, aPrefix, and aSuffix into aPattern.
      *
-     * The only good documentation I'm aware of for this function is
-     * at <http://docs.iplanet.com/docs/manuals/dirsdk/csdk41/html/filter.htm>
-     * and
-     * <http://docs.iplanet.com/docs/manuals/dirsdk/csdk41/html/function.htm#17835>
-     * Unfortunately, this does not currently seem to be available
-     * under any open source license, so I can't include that
-     * documentation here in the doxygen comments.
+     * Exposes the functionality of ldap_create_filter() via XPCOM.
+     *
+     * There is some documentation on the filter template format
+     * (passed in via aPattern) here:
+     * https://docs.oracle.com/cd/E19957-01/817-6707/filter.html
      *
      * @param aMaxSize   maximum size (in char) of string to be
      *                   created and returned (including final \0)
      * @param aPattern   pattern to be used for the filter
      * @param aPrefix    prefix to prepend to the filter
      * @param aSuffix    suffix to be appended to the filer
      * @param aAttr      replacement for %a in the pattern
      * @param aValue     replacement for %v in the pattern
@@ -174,23 +37,9 @@ interface nsILDAPService : nsISupports {
      * @exception NS_ERROR_OUT_OF_MEMORY    allocation failed
      * @exception NS_ERROR_NOT_AVAILABLE    filter longer than maxsiz chars
      * @exception NS_ERROR_UNEXPECTED       ldap_create_filter returned
      *                                      unexpected error code
      */
     AUTF8String createFilter(in unsigned long aMaxSize, in AUTF8String aPattern,
                              in AUTF8String aPrefix, in AUTF8String aSuffix,
                              in AUTF8String aAttr, in AUTF8String aValue);
-
-    /**
-     * Parses a distinguished name (DN) and returns the relative DN,
-     * base DN and the list of attributes that make up the relative DN.
-     *
-     * @param dn        DN to parse
-     * @param rdn       The relative DN for the given DN
-     * @param baseDn    The base DN for the given DN
-     *
-     * @return          Array of attribute names
-     *
-     */
-    Array<AUTF8String> parseDn(in string dn, out AUTF8String rdn,
-                               out AUTF8String baseDn);
 };
--- a/ldap/xpcom/src/nsLDAPService.cpp
+++ b/ldap/xpcom/src/nsLDAPService.cpp
@@ -1,685 +1,40 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsLDAPInternal.h"
+#include "ldap.h"
 #include "nsLDAPService.h"
-#include "nsLDAPConnection.h"
-#include "nsLDAPOperation.h"
 #include "nsIServiceManager.h"
 #include "nsIConsoleService.h"
-#include "nsILDAPURL.h"
 #include "nsMemory.h"
 #include "nsILDAPErrors.h"
-#include "nsComponentManagerUtils.h"
-#include "nsServiceManagerUtils.h"
+#include "mozilla/Logging.h"
 
 using namespace mozilla;
 
 LazyLogModule gLDAPLogModule("LDAP");
 
-// Constants for CIDs used here.
-//
-static NS_DEFINE_CID(kLDAPConnectionCID, NS_LDAPCONNECTION_CID);
-static NS_DEFINE_CID(kLDAPOperationCID, NS_LDAPOPERATION_CID);
-
-// First we provide all the methods for the "local" class
-// nsLDAPServiceEntry.
-//
+NS_IMPL_ISUPPORTS(nsLDAPService, nsILDAPService)
 
 // constructor
 //
-nsLDAPServiceEntry::nsLDAPServiceEntry()
-    : mLeases(0),
-      mTimestamp(0),
-      mDelete(false),
-      mRebinding(false)
-
-{}
-
-// Init function
-//
-bool nsLDAPServiceEntry::Init() { return true; }
-
-// Set/Get the timestamp when this server was last used. We might have
-// to use an "interval" here instead, see Bug #76887.
-//
-PRTime nsLDAPServiceEntry::GetTimestamp() { return mTimestamp; }
-void nsLDAPServiceEntry::SetTimestamp() { mTimestamp = PR_Now(); }
-
-// Increment, decrement and Get the leases. This code might go away
-// with bug #75954.
-//
-void nsLDAPServiceEntry::IncrementLeases() { mLeases++; }
-bool nsLDAPServiceEntry::DecrementLeases() {
-  if (!mLeases) {
-    return false;
-  }
-  mLeases--;
-
-  return true;
-}
-uint32_t nsLDAPServiceEntry::GetLeases() { return mLeases; }
-
-// Get/Set the nsLDAPServer object for this entry.
-//
-already_AddRefed<nsILDAPServer> nsLDAPServiceEntry::GetServer() {
-  nsCOMPtr<nsILDAPServer> server = mServer;
-  return server.forget();
-}
-bool nsLDAPServiceEntry::SetServer(nsILDAPServer* aServer) {
-  if (!aServer) {
-    return false;
-  }
-  mServer = aServer;
-
-  return true;
-}
-
-// Get/Set/Clear the nsLDAPConnection object for this entry.
-//
-already_AddRefed<nsILDAPConnection> nsLDAPServiceEntry::GetConnection() {
-  nsCOMPtr<nsILDAPConnection> conn = mConnection;
-  return conn.forget();
-}
-void nsLDAPServiceEntry::SetConnection(nsILDAPConnection* aConnection) {
-  mConnection = aConnection;
-}
-
-// Get/Set the nsLDAPMessage object for this entry (it's a "cache").
-//
-already_AddRefed<nsILDAPMessage> nsLDAPServiceEntry::GetMessage() {
-  nsCOMPtr<nsILDAPMessage> message = mMessage;
-  return message.forget();
-}
-void nsLDAPServiceEntry::SetMessage(nsILDAPMessage* aMessage) {
-  mMessage = aMessage;
-}
-
-// Push/Pop pending listeners/callback for this server entry. This is
-// implemented as a "stack" on top of the nsCOMArray, since we can
-// potentially have more than one listener waiting for the connection
-// to be available for consumption.
-//
-already_AddRefed<nsILDAPMessageListener> nsLDAPServiceEntry::PopListener() {
-  if (mListeners.IsEmpty()) {
-    return 0;
-  }
-
-  nsCOMPtr<nsILDAPMessageListener> listener = mListeners[0];
-  mListeners.RemoveObjectAt(0);
-  return listener.forget();
-}
-bool nsLDAPServiceEntry::PushListener(nsILDAPMessageListener* listener) {
-  return mListeners.AppendObject(listener);
-}
-
-// Mark this server to currently be rebinding. This is to avoid a
-// race condition where multiple consumers could potentially request
-// to reconnect the connection.
-//
-bool nsLDAPServiceEntry::IsRebinding() { return mRebinding; }
-void nsLDAPServiceEntry::SetRebinding(bool aState) { mRebinding = aState; }
-
-// Mark a service entry for deletion, this is "dead" code right now,
-// see bug #75966.
-//
-bool nsLDAPServiceEntry::DeleteEntry() {
-  mDelete = true;
-
-  return true;
-}
-// This is the end of the nsLDAPServiceEntry class
-
-// Here begins the implementation for nsLDAPService
-//
-NS_IMPL_ISUPPORTS(nsLDAPService, nsILDAPService, nsILDAPMessageListener)
-
-// constructor
-//
-nsLDAPService::nsLDAPService() : mLock("nsLDAPService.mLock") {}
+nsLDAPService::nsLDAPService() {}
 
 // destructor
 //
 nsLDAPService::~nsLDAPService() {}
 
 // Initializer
 //
 nsresult nsLDAPService::Init() { return NS_OK; }
 
-// void addServer (in nsILDAPServer aServer);
-NS_IMETHODIMP nsLDAPService::AddServer(nsILDAPServer* aServer) {
-  nsLDAPServiceEntry* entry;
-  nsString key;
-  nsresult rv;
-
-  if (!aServer) {
-    NS_ERROR("nsLDAPService::AddServer: null pointer ");
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  // Set up the hash key for the server entry
-  //
-  rv = aServer->GetKey(getter_Copies(key));
-  if (NS_FAILED(rv)) {
-    // Only pass along errors we are aware of
-    if ((rv == NS_ERROR_OUT_OF_MEMORY) || (rv == NS_ERROR_NULL_POINTER))
-      return rv;
-    else
-      return NS_ERROR_FAILURE;
-  }
-
-  // Create the new service server entry, and add it into the hash table
-  //
-  entry = new nsLDAPServiceEntry;
-  if (!entry) {
-    NS_ERROR("nsLDAPService::AddServer: out of memory ");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  if (!entry->Init()) {
-    delete entry;
-    NS_ERROR("nsLDAPService::AddServer: out of memory ");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  if (!entry->SetServer(aServer)) {
-    delete entry;
-    return NS_ERROR_FAILURE;
-  }
-
-  // We increment the refcount here for the server entry, when
-  // we purge a server completely from the service (TBD), we
-  // need to decrement the counter as well.
-  //
-  {
-    MutexAutoLock lock(mLock);
-
-    if (mServers.Get(key)) {
-      // Collision detected, lets just throw away this service entry
-      // and keep the old one.
-      //
-      delete entry;
-      return NS_ERROR_FAILURE;
-    }
-    mServers.Put(key, entry);
-  }
-  NS_ADDREF(aServer);
-
-  return NS_OK;
-}
-
-// void deleteServer (in wstring aKey);
-NS_IMETHODIMP nsLDAPService::DeleteServer(const char16_t* aKey) {
-  nsLDAPServiceEntry* entry;
-  MutexAutoLock lock(mLock);
-
-  // We should probably rename the key for this entry now that it's
-  // "deleted", so that we can add in a new one with the same ID.
-  // This is bug #77669.
-  //
-  if (mServers.Get(nsDependentString(aKey), &entry) && entry) {
-    if (entry->GetLeases() > 0) {
-      return NS_ERROR_FAILURE;
-    }
-    entry->DeleteEntry();
-  } else {
-    // There is no Server entry for this key
-    //
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-// nsILDAPServer getServer (in wstring aKey);
-NS_IMETHODIMP nsLDAPService::GetServer(const char16_t* aKey,
-                                       nsILDAPServer** _retval) {
-  nsLDAPServiceEntry* entry;
-  MutexAutoLock lock(mLock);
-
-  if (!_retval) {
-    NS_ERROR("nsLDAPService::GetServer: null pointer ");
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  if (!mServers.Get(nsDependentString(aKey), &entry)) {
-    *_retval = 0;
-    return NS_ERROR_FAILURE;
-  }
-  if (!(*_retval = entry->GetServer().take())) {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-// void requestConnection (in wstring aKey,
-//                        in nsILDAPMessageListener aMessageListener);
-NS_IMETHODIMP nsLDAPService::RequestConnection(
-    const char16_t* aKey, nsILDAPMessageListener* aListener) {
-  nsLDAPServiceEntry* entry;
-  nsCOMPtr<nsILDAPConnection> conn;
-  nsCOMPtr<nsILDAPMessage> message;
-  nsresult rv;
-
-  if (!aListener) {
-    NS_ERROR("nsLDAPService::RequestConection: null pointer ");
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  // Try to find a possibly cached connection and LDAP message.
-  //
-  {
-    MutexAutoLock lock(mLock);
-
-    if (!mServers.Get(nsDependentString(aKey), &entry)) {
-      return NS_ERROR_FAILURE;
-    }
-    entry->SetTimestamp();
-
-    conn = entry->GetConnection();
-    message = entry->GetMessage();
-  }
-
-  if (conn) {
-    if (message) {
-      // We already have the connection, and the message, ready to
-      // be used. This might be confusing, since we actually call
-      // the listener before this function returns, see bug #75899.
-      //
-      aListener->OnLDAPMessage(message);
-      return NS_OK;
-    }
-  } else {
-    rv = EstablishConnection(entry, aListener);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
-  // We got a new connection, now push the listeners on our stack,
-  // until we get the LDAP message back.
-  //
-  {
-    MutexAutoLock lock(mLock);
-
-    if (!mServers.Get(nsDependentString(aKey), &entry) ||
-        !entry->PushListener(static_cast<nsILDAPMessageListener*>(aListener))) {
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  return NS_OK;
-}
-
-// nsILDAPConnection getConnection (in wstring aKey);
-NS_IMETHODIMP nsLDAPService::GetConnection(const char16_t* aKey,
-                                           nsILDAPConnection** _retval) {
-  nsLDAPServiceEntry* entry;
-  MutexAutoLock lock(mLock);
-
-  if (!_retval) {
-    NS_ERROR("nsLDAPService::GetConnection: null pointer ");
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  if (!mServers.Get(nsDependentString(aKey), &entry)) {
-    *_retval = 0;
-    return NS_ERROR_FAILURE;
-  }
-  entry->SetTimestamp();
-  entry->IncrementLeases();
-  if (!(*_retval = entry->GetConnection().take())) {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-// void releaseConnection (in wstring aKey);
-NS_IMETHODIMP nsLDAPService::ReleaseConnection(const char16_t* aKey) {
-  nsLDAPServiceEntry* entry;
-  MutexAutoLock lock(mLock);
-
-  if (!mServers.Get(nsDependentString(aKey), &entry)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (entry->GetLeases() > 0) {
-    entry->SetTimestamp();
-    entry->DecrementLeases();
-  } else {
-    // Releasing a non-leased connection is currently a No-Op.
-    //
-  }
-
-  return NS_OK;
-}
-
-// void reconnectConnection (in wstring aKey,
-//                           in nsILDAPMessageListener aMessageListener);
-NS_IMETHODIMP nsLDAPService::ReconnectConnection(
-    const char16_t* aKey, nsILDAPMessageListener* aListener) {
-  nsLDAPServiceEntry* entry;
-  nsresult rv;
-
-  if (!aListener) {
-    NS_ERROR("nsLDAPService::ReconnectConnection: null pointer ");
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  {
-    MutexAutoLock lock(mLock);
-
-    if (!mServers.Get(nsDependentString(aKey), &entry)) {
-      return NS_ERROR_FAILURE;
-    }
-    entry->SetTimestamp();
-
-    if (entry->IsRebinding()) {
-      if (!entry->PushListener(aListener)) {
-        return NS_ERROR_FAILURE;
-      }
-
-      return NS_OK;
-    }
-
-    // Clear the old connection and message, which should get garbaged
-    // collected now. We mark this as being "rebinding" now, and it
-    // we be marked as finished either if there's an error condition,
-    // or if the OnLDAPMessage() method gets called (i.e. bind() done).
-    //
-    entry->SetMessage(0);
-    entry->SetConnection(0);
-
-    // Get a new connection
-    //
-    entry->SetRebinding(true);
-  }
-
-  rv = EstablishConnection(entry, aListener);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  {
-    MutexAutoLock lock(mLock);
-
-    if (!entry->PushListener(static_cast<nsILDAPMessageListener*>(aListener))) {
-      entry->SetRebinding(false);
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  return NS_OK;
-}
-
-/**
- * Messages received are passed back via this function.
- *
- * @arg aMessage  The message that was returned, 0 if none was.
- *
- * void OnLDAPMessage (in nsILDAPMessage aMessage)
- */
-NS_IMETHODIMP
-nsLDAPService::OnLDAPMessage(nsILDAPMessage* aMessage) {
-  nsCOMPtr<nsILDAPOperation> operation;
-  nsCOMPtr<nsILDAPConnection> connection;
-  int32_t messageType;
-
-  // XXXleif: NULL messages are supposedly allowed, but the semantics
-  // are not definted (yet?). This is something to look out for...
-  //
-
-  // figure out what sort of message was returned
-  //
-  nsresult rv = aMessage->GetType(&messageType);
-  if (NS_FAILED(rv)) {
-    NS_ERROR(
-        "nsLDAPService::OnLDAPMessage(): unexpected error in "
-        "nsLDAPMessage::GetType()");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  switch (messageType) {
-    case LDAP_RES_BIND:
-      // a bind has completed
-      //
-      rv = aMessage->GetOperation(getter_AddRefs(operation));
-      if (NS_FAILED(rv)) {
-        NS_ERROR(
-            "nsLDAPService::OnLDAPMessage(): unexpected error in "
-            "nsLDAPMessage::GetOperation()");
-        return NS_ERROR_UNEXPECTED;
-      }
-
-      rv = operation->GetConnection(getter_AddRefs(connection));
-      if (NS_FAILED(rv)) {
-        NS_ERROR(
-            "nsLDAPService::OnLDAPMessage(): unexpected error in "
-            "nsLDAPOperation::GetConnection()");
-        return NS_ERROR_UNEXPECTED;
-      }
-
-      // Now we have the connection, lets find the corresponding
-      // server entry in the Service.
-      //
-      {
-        nsCOMPtr<nsILDAPMessageListener> listener;
-        nsCOMPtr<nsILDAPMessage> message;
-        nsLDAPServiceEntry* entry;
-        MutexAutoLock lock(mLock);
-
-        if (!mConnections.Get(connection, &entry)) {
-          return NS_ERROR_FAILURE;
-        }
-
-        message = entry->GetMessage();
-        if (message) {
-          // We already have a message, lets keep that one.
-          //
-          return NS_ERROR_FAILURE;
-        }
-
-        entry->SetRebinding(false);
-        entry->SetMessage(aMessage);
-
-        // Now process all the pending callbacks/listeners. We
-        // have to make sure to unlock before calling a listener,
-        // since it's likely to call back into us again.
-        //
-        while ((listener = entry->PopListener())) {
-          MutexAutoUnlock unlock(mLock);
-          listener->OnLDAPMessage(aMessage);
-        }
-      }
-      break;
-
-    default:
-      NS_WARNING(
-          "nsLDAPService::OnLDAPMessage(): unexpected LDAP message "
-          "received");
-
-      // get the console service so we can log a message
-      //
-      nsCOMPtr<nsIConsoleService> consoleSvc =
-          do_GetService("@mozilla.org/consoleservice;1", &rv);
-      if (NS_FAILED(rv)) {
-        NS_ERROR(
-            "nsLDAPChannel::OnLDAPMessage() couldn't get console "
-            "service");
-        break;
-      }
-
-      // log the message
-      //
-      rv = consoleSvc->LogStringMessage(
-          u"LDAP: WARNING: nsLDAPService::OnLDAPMessage(): Unexpected LDAP "
-          u"message received");
-      NS_ASSERTION(NS_SUCCEEDED(rv),
-                   "nsLDAPService::OnLDAPMessage(): "
-                   "consoleSvc->LogStringMessage() failed");
-      break;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsLDAPService::OnLDAPInit() { return NS_ERROR_NOT_IMPLEMENTED; }
-
-NS_IMETHODIMP
-nsLDAPService::OnLDAPError(nsresult status, nsITransportSecurityInfo* secInfo,
-                           nsACString const& location) {
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-// Helper function to establish an LDAP connection properly.
-//
-nsresult nsLDAPService::EstablishConnection(nsLDAPServiceEntry* aEntry,
-                                            nsILDAPMessageListener* aListener) {
-  nsCOMPtr<nsILDAPOperation> operation;
-  nsCOMPtr<nsILDAPServer> server;
-  nsCOMPtr<nsILDAPURL> url;
-  nsCOMPtr<nsILDAPConnection> conn, conn2;
-  nsCOMPtr<nsILDAPMessage> message;
-  nsAutoCString binddn;
-  nsAutoCString password;
-  uint32_t protocolVersion;
-  nsresult rv;
-
-  server = aEntry->GetServer();
-  if (!server) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Get username, password, and protocol version from the server entry.
-  //
-  rv = server->GetBinddn(binddn);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-  rv = server->GetPassword(password);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-  rv = server->GetProtocolVersion(&protocolVersion);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Get the host and port out of the URL, which is in the server entry.
-  //
-  rv = server->GetUrl(getter_AddRefs(url));
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-  // Create a new connection for this server.
-  //
-  conn = do_CreateInstance(kLDAPConnectionCID, &rv);
-  if (NS_FAILED(rv)) {
-    NS_ERROR(
-        "nsLDAPService::EstablishConnection(): could not create "
-        "@mozilla.org/network/ldap-connection;1");
-    return NS_ERROR_FAILURE;
-  }
-
-  rv = conn->Init(url, binddn, this, nullptr, protocolVersion);
-  if (NS_FAILED(rv)) {
-    switch (rv) {
-      // Only pass along errors we are aware of
-      //
-      case NS_ERROR_OUT_OF_MEMORY:
-      case NS_ERROR_NOT_AVAILABLE:
-      case NS_ERROR_FAILURE:
-        return rv;
-
-      case NS_ERROR_ILLEGAL_VALUE:
-      default:
-        return NS_ERROR_UNEXPECTED;
-    }
-  }
-
-  // Try to detect a collision, i.e. someone established a connection
-  // just before we did. If so, we drop ours. This code is somewhat
-  // similar to what happens in RequestConnection(), i.e. we try to
-  // call the listener directly if possible, and if not, push it on
-  // the stack of pending requests.
-  //
-  {
-    MutexAutoLock lock(mLock);
-
-    conn2 = aEntry->GetConnection();
-    message = aEntry->GetMessage();
-  }
-
-  if (conn2) {
-    // Drop the new connection, we can't use it.
-    //
-    conn = nullptr;
-    if (message) {
-      aListener->OnLDAPMessage(message);
-      return NS_OK;
-    }
-
-    {
-      MutexAutoLock lock(mLock);
-
-      if (!aEntry->PushListener(
-              static_cast<nsILDAPMessageListener*>(aListener))) {
-        return NS_ERROR_FAILURE;
-      }
-    }
-
-    return NS_OK;
-  }
-
-  // We made the connection, lets store it to the server entry,
-  // and also update the reverse lookup tables (for finding the
-  // server entry related to a particular connection).
-  //
-  {
-    MutexAutoLock lock(mLock);
-
-    aEntry->SetConnection(conn);
-    mConnections.Put(conn, aEntry);
-  }
-
-  // Setup the bind() operation.
-  //
-  operation = do_CreateInstance(kLDAPOperationCID, &rv);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  rv = operation->Init(conn, this, nullptr);
-  if (NS_FAILED(rv)) {
-    return NS_ERROR_UNEXPECTED;  // this should never happen
-  }
-
-  // Start a bind operation
-  //
-  // Here we need to support the password, see bug #75990
-  //
-  rv = operation->SimpleBind(password);
-  if (NS_FAILED(rv)) {
-    // Only pass along errors we are aware of
-    if ((rv == NS_ERROR_LDAP_ENCODING_ERROR) || (rv == NS_ERROR_FAILURE) ||
-        (rv == NS_ERROR_OUT_OF_MEMORY))
-      return rv;
-    else
-      return NS_ERROR_UNEXPECTED;
-  }
-
-  return NS_OK;
-}
-
 /* AString createFilter (in unsigned long aMaxSize, in AString aPattern, in
  * AString aPrefix, in AString aSuffix, in AString aAttr, in AString aValue); */
 NS_IMETHODIMP nsLDAPService::CreateFilter(
     uint32_t aMaxSize, const nsACString& aPattern, const nsACString& aPrefix,
     const nsACString& aSuffix, const nsACString& aAttr,
     const nsACString& aValue, nsACString& _retval) {
   if (!aMaxSize) {
     return NS_ERROR_INVALID_ARG;
@@ -758,88 +113,16 @@ NS_IMETHODIMP nsLDAPService::CreateFilte
   // done with the array and the buffer
   //
   NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(numTokens, valueWords);
   free(buffer);
 
   return rv;
 }
 
-// Parse a distinguished name (DN) and returns the relative DN,
-// base DN and the list of attributes that make up the relative DN.
-NS_IMETHODIMP nsLDAPService::ParseDn(const char* aDn, nsACString& aRdn,
-                                     nsACString& aBaseDn,
-                                     nsTArray<nsCString>& aRdnAttrs) {
-  aRdnAttrs.Clear();
-
-  // explode the DN
-  char** dnComponents = ldap_explode_dn(aDn, 0);
-  if (!dnComponents) {
-    NS_ERROR("nsLDAPService::ParseDn: parsing DN failed");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  // require at least 2 components
-  if (!*dnComponents || !*(dnComponents + 1)) {
-    NS_ERROR("nsLDAPService::ParseDn: DN has too few components");
-    ldap_value_free(dnComponents);
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  // get the base DN
-  nsAutoCString baseDn(nsDependentCString(*(dnComponents + 1)));
-  for (char** component = dnComponents + 2; *component; ++component) {
-    baseDn.AppendLiteral(",");
-    baseDn.Append(nsDependentCString(*component));
-  }
-
-  // explode the RDN
-  char** rdnComponents = ldap_explode_rdn(*dnComponents, 0);
-  if (!rdnComponents) {
-    NS_ERROR("nsLDAPService::ParseDn: parsing RDN failed");
-    ldap_value_free(dnComponents);
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  // count RDN attributes
-  uint32_t rdnCount = 0;
-  for (char** component = rdnComponents; *component; ++component) ++rdnCount;
-  if (rdnCount < 1) {
-    NS_ERROR("nsLDAPService::ParseDn: RDN has too few components");
-    ldap_value_free(dnComponents);
-    ldap_value_free(rdnComponents);
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  // get the RDN attribute names
-  aRdnAttrs.SetCapacity(rdnCount);
-  for (char** component = rdnComponents; *component; ++component) {
-    uint32_t len = 0;
-    char* p;
-    for (p = *component; *p != '\0' && *p != '='; ++p) ++len;
-    if (*p != '=') {
-      NS_ERROR(
-          "nsLDAPService::ParseDn: "
-          "could not find '=' in RDN component");
-      ldap_value_free(dnComponents);
-      ldap_value_free(rdnComponents);
-      return NS_ERROR_UNEXPECTED;
-    }
-    aRdnAttrs.AppendElement(nsCString(*component, len));
-  }
-
-  // perform assignments
-  aRdn.Assign(*dnComponents);
-  aBaseDn.Assign(baseDn);
-
-  ldap_value_free(dnComponents);
-  ldap_value_free(rdnComponents);
-  return NS_OK;
-}
-
 // Count the number of space-separated tokens between aIter and aIterEnd
 //
 uint32_t nsLDAPService::CountTokens(const char* aIter, const char* aIterEnd) {
   uint32_t count(0);
 
   // keep iterating through the string until we hit the end
   //
   while (aIter != aIterEnd) {
--- a/ldap/xpcom/src/nsLDAPService.h
+++ b/ldap/xpcom/src/nsLDAPService.h
@@ -1,113 +1,45 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "ldap.h"
 #include "nsString.h"
-#include "nsCOMArray.h"
-#include "nsDataHashtable.h"
 #include "nsILDAPService.h"
-#include "nsILDAPMessage.h"
-#include "nsILDAPMessageListener.h"
-#include "nsCOMPtr.h"
-#include "nsILDAPServer.h"
-#include "nsILDAPConnection.h"
-#include "nsILDAPMessage.h"
-#include "mozilla/Mutex.h"
 
 // 6a89ae33-7a90-430d-888c-0dede53a951a
 //
 #define NS_LDAPSERVICE_CID                           \
   {                                                  \
     0x6a89ae33, 0x7a90, 0x430d, {                    \
       0x88, 0x8c, 0x0d, 0xed, 0xe5, 0x3a, 0x95, 0x1a \
     }                                                \
   }
 
-// This is a little "helper" class, we use to store information
-// related to one Service entry (one LDAP server).
-//
-class nsLDAPServiceEntry {
- public:
-  nsLDAPServiceEntry();
-  virtual ~nsLDAPServiceEntry(){};
-  bool Init();
-
-  inline uint32_t GetLeases();
-  inline void IncrementLeases();
-  inline bool DecrementLeases();
-
-  inline PRTime GetTimestamp();
-  inline void SetTimestamp();
-
-  inline already_AddRefed<nsILDAPServer> GetServer();
-  inline bool SetServer(nsILDAPServer* aServer);
-
-  inline already_AddRefed<nsILDAPConnection> GetConnection();
-  inline void SetConnection(nsILDAPConnection* aConnection);
-
-  inline already_AddRefed<nsILDAPMessage> GetMessage();
-  inline void SetMessage(nsILDAPMessage* aMessage);
-
-  inline already_AddRefed<nsILDAPMessageListener> PopListener();
-  inline bool PushListener(nsILDAPMessageListener*);
-
-  inline bool IsRebinding();
-  inline void SetRebinding(bool);
-
-  inline bool DeleteEntry();
-
- protected:
-  uint32_t mLeases;   // The number of leases currently granted
-  PRTime mTimestamp;  // Last time this server was "used"
-  bool mDelete;       // This entry is due for deletion
-  bool mRebinding;    // Keep state if we are rebinding or not
-
-  nsCOMPtr<nsILDAPServer> mServer;
-  nsCOMPtr<nsILDAPConnection> mConnection;
-  nsCOMPtr<nsILDAPMessage> mMessage;
-
-  // Array holding all the pending callbacks (listeners) for this entry
-  nsCOMArray<nsILDAPMessageListener> mListeners;
-};
-
 // This is the interface we're implementing.
 //
-class nsLDAPService : public nsILDAPService, public nsILDAPMessageListener {
+class nsLDAPService : public nsILDAPService {
  public:
   // interface decls
   //
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSILDAPSERVICE
-  NS_DECL_NSILDAPMESSAGELISTENER
 
   // constructor and destructor
   //
   nsLDAPService();
 
   nsresult Init();
 
  protected:
   virtual ~nsLDAPService();
-  nsresult EstablishConnection(nsLDAPServiceEntry*, nsILDAPMessageListener*);
 
   // kinda like strtok_r, but with iterators.  for use by
   // createFilter
-  //
   char* NextToken(const char** aIter, const char** aIterEnd);
 
   // count how many tokens are in this string; for use by
   // createFilter; note that unlike with NextToken, these params
   // are copies, not references.
-  //
   uint32_t CountTokens(const char* aIter, const char* aIterEnd);
-
-  mozilla::Mutex mLock;  // Lock mechanism
-
-  // Hash table holding server entries
-  nsDataHashtable<nsStringHashKey, nsLDAPServiceEntry*> mServers;
-  // Hash table holding "reverse" lookups from connection to server
-  nsDataHashtable<nsVoidPtrHashKey, nsLDAPServiceEntry*> mConnections;
 };