Fix bug # 164175: XPCom LDAP API extensions. OnLDAPInit() now passes relevant connection, and LDAP operations/connections accept closures. r=dmose sr=darin

This commit is contained in:
rjc%netscape.com 2002-09-04 01:28:36 +00:00
parent e48c896a05
commit ba0e03e53e
15 changed files with 90 additions and 32 deletions

View File

@ -51,6 +51,11 @@ interface nsILDAPConnection : nsISupports
* @exception NS_ERROR_OUT_OF_MEMORY
*/
readonly attribute wstring bindName;
/**
* private parameter (anything caller desires)
*/
attribute nsISupports closure;
/**
* Set up the connection. Note that init() must be called on a thread
@ -62,6 +67,7 @@ interface nsILDAPConnection : nsISupports
* @param aSSL use SSL on this connection?
* @param aBindName DN to bind as
* @param aMessageListener Callback for DNS resolution completion
* @param aClosure private parameter (anything caller desires)
*
* @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in
* @exception NS_ERROR_OUT_OF_MEMORY ran out of memory
@ -71,7 +77,8 @@ interface nsILDAPConnection : nsISupports
*/
void init(in string aHost, in short aPort, in boolean aSSL,
in wstring aBindName,
in nsILDAPMessageListener aMessageListener);
in nsILDAPMessageListener aMessageListener,
in nsISupports aClosure);
/**
* Get information about the last error that occured on this connection.

View File

@ -35,6 +35,8 @@
#include "nsISupports.idl"
#include "nsILDAPMessage.idl"
interface nsILDAPConnection;
/**
* A callback interface to be implemented by any objects that want to
* receive results from an nsILDAPOperation (ie nsILDAPMessages) as they
@ -58,7 +60,8 @@ interface nsILDAPMessageListener : nsISupports
* Reason for this is to allow us to do asynchronous DNS
* lookups, preresolving hostnames.
*
* @arg aConn The LDAP connection in question
* @arg aStatus The result from the LDAP connection init
*/
void onLDAPInit(in nsresult aStatus);
void onLDAPInit(in nsILDAPConnection aConn, in nsresult aStatus);
};

View File

@ -66,6 +66,11 @@ interface nsILDAPOperation : nsISupports
*/
readonly attribute long messageID;
/**
* private parameter (anything caller desires)
*/
attribute nsISupports closure;
/**
* No time and/or size limit specified
*/
@ -80,12 +85,14 @@ interface nsILDAPOperation : nsISupports
*
* @param aConnection connection this operation should use
* @param aMessageListener interface used to call back the results.
* @param aClosure private parameter (anything caller desires)
*
* @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in
* @exception NS_ERROR_UNEXPECTED failed to get connection handle
*/
void init(in nsILDAPConnection aConnection,
in nsILDAPMessageListener aMessageListener);
in nsILDAPMessageListener aMessageListener,
in nsISupports aClosure);
/**
* Asynchronously authenticate to the LDAP server.

View File

@ -171,7 +171,8 @@ nsLDAPConnection::Release(void)
NS_IMETHODIMP
nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, PRBool aSSL,
const PRUnichar *aBindName,
nsILDAPMessageListener *aMessageListener)
nsILDAPMessageListener *aMessageListener,
nsISupports *aClosure)
{
nsCOMPtr<nsIDNSListener> selfProxy;
nsresult rv;
@ -199,6 +200,8 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, PRBool aSSL,
mBindName = 0;
}
mClosure = aClosure;
// Save the port number for later use, once the DNS server(s) has
// resolved the host part.
//
@ -286,6 +289,23 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, PRBool aSSL,
return NS_OK;
}
NS_IMETHODIMP
nsLDAPConnection::GetClosure(nsISupports **_retval)
{
if (!_retval) {
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IF_ADDREF(*_retval = mClosure);
return NS_OK;
}
NS_IMETHODIMP
nsLDAPConnection::SetClosure(nsISupports *aClosure)
{
mClosure = aClosure;
return NS_OK;
}
// who we're binding as
//
// readonly attribute wstring bindName
@ -1041,7 +1061,7 @@ nsLDAPConnection::OnStopLookup(nsISupports *aContext,
// Call the listener, and then we can release our reference to it.
//
mInitListener->OnLDAPInit(rv);
mInitListener->OnLDAPInit(this, rv);
mInitListener = 0;
return rv;

View File

@ -125,6 +125,7 @@ class nsLDAPConnection : public nsILDAPConnection,
nsCString mResolvedIP; // Preresolved list of host IPs
nsCOMPtr<nsILDAPMessageListener> mInitListener; // Init callback
nsCOMPtr<nsIRequest> mDNSRequest; // The "active" DNS request
nsCOMPtr<nsISupports> mClosure; // private parameter (anything caller desires)
nsresult mDNSStatus; // The status of DNS lookup (rv cache)
PRBool mDNSFinished; // Flag if DNS lookup has finished
};

View File

@ -61,7 +61,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsLDAPOperation, nsILDAPOperation);
*/
NS_IMETHODIMP
nsLDAPOperation::Init(nsILDAPConnection *aConnection,
nsILDAPMessageListener *aMessageListener)
nsILDAPMessageListener *aMessageListener,
nsISupports *aClosure)
{
if (!aConnection) {
return NS_ERROR_ILLEGAL_VALUE;
@ -76,6 +77,7 @@ nsLDAPOperation::Init(nsILDAPConnection *aConnection,
//
mConnection = aConnection;
mMessageListener = aMessageListener;
mClosure = aClosure;
// cache the connection handle
//
@ -85,6 +87,23 @@ nsLDAPOperation::Init(nsILDAPConnection *aConnection,
return NS_OK;
}
NS_IMETHODIMP
nsLDAPOperation::GetClosure(nsISupports **_retval)
{
if (!_retval) {
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IF_ADDREF(*_retval = mClosure);
return NS_OK;
}
NS_IMETHODIMP
nsLDAPOperation::SetClosure(nsISupports *aClosure)
{
mClosure = aClosure;
return NS_OK;
}
NS_IMETHODIMP
nsLDAPOperation::GetConnection(nsILDAPConnection* *aConnection)
{

View File

@ -83,7 +83,7 @@ class nsLDAPOperation : public nsILDAPOperation
nsCOMPtr<nsILDAPMessageListener> mMessageListener; // results go here
nsCOMPtr<nsISupports> mClosure; // private parameter (anything caller desires)
nsCOMPtr<nsILDAPConnection> mConnection; // connection this op is on
LDAP *mConnectionHandle; // cache connection handle

View File

@ -697,10 +697,10 @@ nsLDAPService::OnLDAPMessage(nsILDAPMessage *aMessage)
return NS_OK;
}
// void onLDAPInit (in nsresult aStatus); */
// void onLDAPInit (in nsILDAPConnection aConn, in nsresult aStatus); */
//
NS_IMETHODIMP
nsLDAPService::OnLDAPInit(nsresult aStatus)
nsLDAPService::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -771,7 +771,7 @@ nsLDAPService::EstablishConnection(nsLDAPServiceEntry *aEntry,
//
rv = conn->Init(host.get(), port,
(options & nsILDAPURL::OPT_SECURE) ? PR_TRUE : PR_FALSE,
nsnull, this);
nsnull, this, nsnull);
if (NS_FAILED(rv)) {
switch (rv) {
// Only pass along errors we are aware of
@ -840,7 +840,7 @@ nsLDAPService::EstablishConnection(nsLDAPServiceEntry *aEntry,
return NS_ERROR_FAILURE;
}
rv = operation->Init(conn, this);
rv = operation->Init(conn, this, nsnull);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED; // this should never happen
}

View File

@ -1034,7 +1034,7 @@ nsLDAPMessageRDFDelegateFactory.prototype =
}
getTargetsBoundCallback.prototype.onLDAPInit =
function(aStatus) {
function(aConn, aStatus) {
if (DEBUG) {
dump("getTargetsBoundCallback.onLDAPInit()" +
" called with status of " + aStatus + "\n\n");
@ -1279,7 +1279,7 @@ nsLDAPMessageRDFDelegateFactory.prototype =
["@mozilla.org/network/ldap-connection;1"].
createInstance(Components.interfaces.nsILDAPConnection);
connection.init(queryURL.host, queryURL.port, null,
generateGetTargetsBoundCallback())
generateGetTargetsBoundCallback(), null)
// XXXdmose - in this case, we almost certainly shouldn't be
// falling through to an error case, but instead returning

View File

@ -128,7 +128,7 @@ nsLDAPSyncQuery::OnLDAPMessage(nsILDAPMessage *aMessage)
// void onLDAPInit (in nsresult aStatus);
//
NS_IMETHODIMP
nsLDAPSyncQuery::OnLDAPInit(nsresult aStatus)
nsLDAPSyncQuery::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus)
{
nsresult rv; // temp for xpcom return values
nsCOMPtr<nsILDAPMessageListener> selfProxy;
@ -156,7 +156,7 @@ nsLDAPSyncQuery::OnLDAPInit(nsresult aStatus)
// our OnLDAPMessage accepts all result callbacks
//
rv = mOperation->Init(mConnection, selfProxy);
rv = mOperation->Init(mConnection, selfProxy, nsnull);
if (NS_FAILED(rv)) {
FinishLDAPQuery();
return NS_ERROR_UNEXPECTED; // this should never happen
@ -299,7 +299,7 @@ nsLDAPSyncQuery::StartLDAPSearch()
// initialize the LDAP operation object
//
rv = mOperation->Init(mConnection, selfProxy);
rv = mOperation->Init(mConnection, selfProxy, nsnull);
if (NS_FAILED(rv)) {
NS_ERROR("nsLDAPSyncQuery::StartLDAPSearch(): couldn't "
"initialize LDAP operation");
@ -425,7 +425,7 @@ nsresult nsLDAPSyncQuery::InitConnection()
rv = mConnection->Init(host.get(), port,
(options & nsILDAPURL::OPT_SECURE)
? PR_TRUE : PR_FALSE, 0, selfProxy);
? PR_TRUE : PR_FALSE, 0, selfProxy, nsnull);
if (NS_FAILED(rv)) {
FinishLDAPQuery();
return NS_ERROR_UNEXPECTED; // this should never happen

View File

@ -247,7 +247,7 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPMessage(nsILDAPMessage *aMessa
return rv;
}
NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPInit(nsresult aStatus)
NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus)
{
nsresult rv;
nsXPIDLString passwd;
@ -397,7 +397,7 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPInit(nsresult aStatus)
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(proxyListener));
rv = ldapOperation->Init(mConnection, proxyListener);
rv = ldapOperation->Init(mConnection, proxyListener, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
// Bind
@ -460,7 +460,7 @@ nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageBind (nsILDAPMessage *aMessa
this, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs(proxyListener));
NS_ENSURE_SUCCESS(rv, rv);
rv = mSearchOperation->Init (mConnection, proxyListener);
rv = mSearchOperation->Init (mConnection, proxyListener, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString dn;
@ -791,7 +791,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(nsIAbDirectoryQueryArguments* argu
// Now lets initialize the LDAP connection properly. We'll kick
// off the bind operation in the callback function, |OnLDAPInit()|.
rv = ldapConnection->Init(host.get(), port, options, mLogin.get(),
messageListener);
messageListener, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
return rv;

View File

@ -113,7 +113,7 @@ NS_IMETHODIMP nsAbLDAPProcessReplicationData::GetProtocolUsed(PRInt32 *aProtocol
return NS_OK;
}
NS_IMETHODIMP nsAbLDAPProcessReplicationData::OnLDAPInit(nsresult aStatus)
NS_IMETHODIMP nsAbLDAPProcessReplicationData::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus)
{
if(!mInitialized)
return NS_ERROR_NOT_INITIALIZED;
@ -149,7 +149,7 @@ NS_IMETHODIMP nsAbLDAPProcessReplicationData::OnLDAPInit(nsresult aStatus)
return rv;
}
rv = operation->Init(connection, listener);
rv = operation->Init(connection, listener, nsnull);
if(NS_FAILED(rv)) {
Done(PR_FALSE);
return rv;

View File

@ -168,7 +168,7 @@ NS_IMETHODIMP nsAbLDAPReplicationQuery::ConnectToLDAPServer(nsILDAPURL *aURL, co
return mConnection->Init(host.get(), port,
(options & nsILDAPURL::OPT_SECURE) ? PR_TRUE
: PR_FALSE, PromiseFlatString(aAuthDN).get(),
listener);
listener, nsnull);
}
NS_IMETHODIMP nsAbLDAPReplicationQuery::Init(const nsACString & aPrefName, nsIWebProgressListener *aProgressListener)

View File

@ -93,7 +93,8 @@ function search()
gLdapServerURL.options,
null,
getProxyOnUIThread(new boundListener(),
Components.interfaces.nsILDAPMessageListener));
Components.interfaces.nsILDAPMessageListener),
null);
} catch (ex) {
window.close();
@ -215,7 +216,7 @@ boundListener.prototype.onLDAPMessage =
}
boundListener.prototype.onLDAPInit =
function(aStatus) {
function(aConn, aStatus) {
kickOffBind();
}
@ -266,7 +267,7 @@ ldapMessageListener.prototype.onLDAPMessage =
}
ldapMessageListener.prototype.onLDAPInit =
function(aStatus) {
function(aConn, aStatus) {
}

View File

@ -435,7 +435,7 @@ nsLDAPAutoCompleteSession::OnLDAPMessage(nsILDAPMessage *aMessage)
// void onLDAPInit (in nsresult aStatus);
//
NS_IMETHODIMP
nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
nsLDAPAutoCompleteSession::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus)
{
nsresult rv; // temp for xpcom return values
nsCOMPtr<nsILDAPMessageListener> selfProxy;
@ -586,7 +586,7 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
// our OnLDAPMessage accepts all result callbacks
//
rv = mOperation->Init(mConnection, selfProxy);
rv = mOperation->Init(mConnection, selfProxy, nsnull);
if (NS_FAILED(rv)) {
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
UNBOUND);
@ -696,7 +696,7 @@ nsLDAPAutoCompleteSession::OnLDAPBind(nsILDAPMessage *aMessage)
("nsLDAPAutoCompleteSession::OnLDAPBind(): auth error;"
" calling OnLDAPInit() again"));
return OnLDAPInit(NS_OK);
return OnLDAPInit(nsnull, NS_OK);
}
// reset to the default state
@ -871,7 +871,7 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
// initialize the LDAP operation object
//
rv = mOperation->Init(mConnection, selfProxy);
rv = mOperation->Init(mConnection, selfProxy, nsnull);
if (NS_FAILED(rv)) {
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
"initialize LDAP operation");
@ -1141,7 +1141,7 @@ nsLDAPAutoCompleteSession::InitConnection()
rv = mConnection->Init(host.get(), port,
(options & nsILDAPURL::OPT_SECURE) ? PR_TRUE
: PR_FALSE, NS_ConvertUTF8toUCS2(mLogin).get(),
selfProxy);
selfProxy, nsnull);
if NS_FAILED(rv) {
switch (rv) {