Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
nsAbQueryLDAPMessageListener Class Reference
Inheritance diagram for nsAbQueryLDAPMessageListener:
Inheritance graph
[legend]
Collaboration diagram for nsAbQueryLDAPMessageListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSILDAPMESSAGELISTENER 
nsAbQueryLDAPMessageListener (nsAbLDAPDirectoryQuery *directoryQuery, nsILDAPURL *url, nsILDAPConnection *connection, nsIAbDirectoryQueryArguments *queryArguments, nsIAbDirectoryQueryResultListener *queryListener, PRInt32 resultLimit=-1, PRInt32 timeOut=0)
virtual ~nsAbQueryLDAPMessageListener ()
void onLDAPMessage (in nsILDAPMessage aMessage)
 Messages received are passed back via this function.
void onLDAPInit (in nsILDAPConnection aConn, in nsresult aStatus)
 Notify the listener that the Init has completed, passing in the results from the connection initialization.

Protected Member Functions

nsresult OnLDAPMessageBind (nsILDAPMessage *aMessage)
nsresult OnLDAPMessageSearchEntry (nsILDAPMessage *aMessage, nsIAbDirectoryQueryResult **result)
nsresult OnLDAPMessageSearchResult (nsILDAPMessage *aMessage, nsIAbDirectoryQueryResult **result)
nsresult QueryResultStatus (nsISupportsArray *properties, nsIAbDirectoryQueryResult **result, PRUint32 resultStatus)
nsresult Cancel ()
nsresult Initiate ()
nsresult DoSearch ()

Protected Attributes

nsAbLDAPDirectoryQuerymDirectoryQuery
PRInt32 mContextID
nsCOMPtr< nsILDAPURLmUrl
nsILDAPConnectionmConnection
nsCOMPtr
< nsIAbDirectoryQueryArguments
mQueryArguments
nsCOMPtr
< nsIAbDirectoryQueryResultListener
mQueryListener
PRInt32 mResultLimit
PRInt32 mTimeOut
PRBool mBound
PRBool mFinished
PRBool mInitialized
PRBool mCanceled
PRBool mWaitingForPrevQueryToFinish
nsCOMPtr< nsILDAPOperationmSearchOperation
PRLockmLock

Friends

class nsAbLDAPDirectoryQuery

Detailed Description

Definition at line 62 of file nsAbLDAPDirectoryQuery.cpp.


Constructor & Destructor Documentation

nsAbQueryLDAPMessageListener::nsAbQueryLDAPMessageListener ( nsAbLDAPDirectoryQuery directoryQuery,
nsILDAPURL url,
nsILDAPConnection connection,
nsIAbDirectoryQueryArguments queryArguments,
nsIAbDirectoryQueryResultListener queryListener,
PRInt32  resultLimit = -1,
PRInt32  timeOut = 0 
)

Definition at line 119 of file nsAbLDAPDirectoryQuery.cpp.

                         :
    mDirectoryQuery (directoryQuery),
    mUrl (url),
    mConnection (connection),
    mQueryArguments (queryArguments),
    mQueryListener (queryListener),
    mResultLimit (resultLimit),
    mTimeOut (timeOut),
    mBound (PR_FALSE),
    mFinished (PR_FALSE),
    mInitialized(PR_FALSE),
    mCanceled (PR_FALSE),
    mWaitingForPrevQueryToFinish(PR_FALSE),
    mLock(0)

{
}

Definition at line 144 of file nsAbLDAPDirectoryQuery.cpp.

Here is the call graph for this function:


Member Function Documentation

Definition at line 166 of file nsAbLDAPDirectoryQuery.cpp.

Here is the call graph for this function:

Definition at line 473 of file nsAbLDAPDirectoryQuery.cpp.

 {
   nsresult rv;
   mCanceled = mFinished = PR_FALSE;

    mSearchOperation = do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
           do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
    
    nsCOMPtr<nsILDAPMessageListener> proxyListener;
    rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsILDAPMessageListener),
                                                               this, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs(proxyListener));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = mSearchOperation->Init (mConnection, proxyListener, nsnull);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString dn;
    rv = mUrl->GetDn (dn);
    NS_ENSURE_SUCCESS(rv, rv);

    PRInt32 scope;
    rv = mUrl->GetScope (&scope);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString filter;
    rv = mUrl->GetFilter (filter);
    NS_ENSURE_SUCCESS(rv, rv);

    CharPtrArrayGuard attributes;
    rv = mUrl->GetAttributes (attributes.GetSizeAddr (), attributes.GetArrayAddr ());
    NS_ENSURE_SUCCESS(rv, rv);

    // I don't _think_ it's ever actually possible to get here without having
    // an nsAbLDAPDirectory object, but, just in case, I'll do a QI instead
    // of just static casts...
    nsCOMPtr<nsIAbLDAPDirectory> nsIAbDir = 
        do_QueryInterface(mDirectoryQuery, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    nsAbLDAPDirectory *dir = 
        NS_STATIC_CAST(nsAbLDAPDirectory *,
                       NS_STATIC_CAST(nsIAbLDAPDirectory *, nsIAbDir.get()));

    rv = mSearchOperation->SetServerControls(dir->mSearchServerControls.get());
    NS_ENSURE_SUCCESS(rv, rv);

    rv = mSearchOperation->SetClientControls(dir->mSearchClientControls.get());
    NS_ENSURE_SUCCESS(rv, rv);

    rv = mSearchOperation->SearchExt (dn, scope, filter,
            attributes.GetSize (), attributes.GetArray (),
            mTimeOut, mResultLimit);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 150 of file nsAbLDAPDirectoryQuery.cpp.

{
    if (mInitialized)
        return NS_OK;
                
    mLock = PR_NewLock ();
    if(!mLock)
    {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    mInitialized = PR_TRUE;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Notify the listener that the Init has completed, passing in the results from the connection initialization.

The Reason for this is to allow us to do asynchronous DNS lookups, preresolving hostnames.

  • aConn The LDAP connection in question
  • aStatus The result from the LDAP connection init

Messages received are passed back via this function.

  • aMessage The message that was returned, NULL if none was.

XXX semantics of NULL?

Definition at line 425 of file nsAbLDAPDirectoryQuery.cpp.

{
    if (mBound)
        return NS_OK;

    // see whether the bind actually succeeded
    //
    PRInt32 errCode;
    nsresult rv = aMessage->GetErrorCode(&errCode);
    NS_ENSURE_SUCCESS(rv, rv);

    if (errCode != nsILDAPErrors::SUCCESS) {

        // 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.
            //
            if (!mDirectoryQuery)
              return NS_ERROR_NULL_POINTER;

            rv = NS_CreateServicesFromCategory(
                "passwordmanager", mDirectoryQuery->mDirectoryUrl,
                "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.
            }
        } 

        // XXX this error should be propagated back to the UI somehow
        return NS_OK;
    }

    mBound = PR_TRUE;
    return DoSearch();
}

Here is the call graph for this function:

Definition at line 531 of file nsAbLDAPDirectoryQuery.cpp.

{
    nsresult rv;

    if (!mDirectoryQuery)
      return NS_ERROR_NULL_POINTER;
    // the address book fields that we'll be asking for
    CharPtrArrayGuard properties;
    rv = mQueryArguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr());
    NS_ENSURE_SUCCESS(rv, rv);

    // the map for translating between LDAP attrs <-> addrbook fields
    nsCOMPtr<nsISupports> iSupportsMap;
    rv = mQueryArguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap));
    NS_ENSURE_SUCCESS(rv, rv);
    nsCOMPtr<nsIAbLDAPAttributeMap> map = do_QueryInterface(iSupportsMap, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    // set up variables for handling the property values to be returned
    nsCOMPtr<nsISupportsArray> propertyValues;
    nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue;
    rv = NS_NewISupportsArray(getter_AddRefs(propertyValues));
    NS_ENSURE_SUCCESS(rv, rv);
        
    if (!strcmp(properties[0], "card:nsIAbCard")) {
        // Meta property
        nsCAutoString dn;
        rv = aMessage->GetDn (dn);
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbCard> card;
        rv = mDirectoryQuery->CreateCard (mUrl, dn.get(), getter_AddRefs (card));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = map->SetCardPropertiesFromLDAPMessage(aMessage, card);
        NS_ENSURE_SUCCESS(rv, rv);

        propertyValue = new nsAbDirectoryQueryPropertyValue(properties[0], card);
        if (!propertyValue) 
            return NS_ERROR_OUT_OF_MEMORY;

        rv = propertyValues->AppendElement(propertyValue);
        NS_ENSURE_SUCCESS(rv, rv);
    } else {

        for (PRUint32 i = 0; i < properties.GetSize(); i++)
            {
                // this is the precedence order list of attrs for this property
                CharPtrArrayGuard attrs;
                rv = map->GetAttributes(nsDependentCString(properties[i]),
                                        attrs.GetSizeAddr(),
                                        attrs.GetArrayAddr());

                // if there are no attrs for this property, just move on
                if (NS_FAILED(rv) || !strlen(attrs[0])) {
                    continue;
                }

                // iterate through list, until first property found
                for (PRUint32 j=0; j < attrs.GetSize(); j++) {

                    // try and get the values for this ldap attribute
                    PRUnicharPtrArrayGuard vals;
                    rv = aMessage->GetValues(attrs[j], vals.GetSizeAddr(),
                                             vals.GetArrayAddr());

                    if (NS_SUCCEEDED(rv) && vals.GetSize()) {
                        propertyValue = new nsAbDirectoryQueryPropertyValue(
                            properties[i], vals[0]);
                        if (!propertyValue) {
                            return NS_ERROR_OUT_OF_MEMORY;
                        }

                        (void)propertyValues->AppendElement (propertyValue);
                        break;
                    }
                }
            }
    }

    return QueryResultStatus (propertyValues, result, nsIAbDirectoryQueryResult::queryResultMatch);
}

Here is the call graph for this function:

Definition at line 614 of file nsAbLDAPDirectoryQuery.cpp.

Here is the call graph for this function:

Definition at line 629 of file nsAbLDAPDirectoryQuery.cpp.

{
    nsAbDirectoryQueryResult* _queryResult = new nsAbDirectoryQueryResult (
        mContextID,
        mQueryArguments,
        resultStatus,
        (resultStatus == nsIAbDirectoryQueryResult::queryResultMatch) ? properties : 0);

    if (!_queryResult)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_IF_ADDREF(*result = _queryResult);
    return NS_OK;
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsAbLDAPDirectoryQuery [friend]

Definition at line 89 of file nsAbLDAPDirectoryQuery.cpp.


Member Data Documentation

Definition at line 105 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 108 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 99 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 97 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 96 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 106 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 107 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 113 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 100 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 101 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 102 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 111 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 103 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 98 of file nsAbLDAPDirectoryQuery.cpp.

Definition at line 109 of file nsAbLDAPDirectoryQuery.cpp.


The documentation for this class was generated from the following file: