Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsAbLDAPProcessReplicationData Class Reference

#include <nsAbLDAPReplicationData.h>

Inheritance diagram for nsAbLDAPProcessReplicationData:
Inheritance graph
[legend]
Collaboration diagram for nsAbLDAPProcessReplicationData:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIABLDAPPROCESSREPLICATIONDATA
NS_DECL_NSILDAPMESSAGELISTENER 
nsAbLDAPProcessReplicationData ()
virtual ~nsAbLDAPProcessReplicationData ()
void init (in nsIAbLDAPReplicationQuery query, in nsIWebProgressListener progressListener)
 this method initializes the implementation
void abort ()
 this method a aborts the ongoing processing
void populateAuthData ()
 this utility method populates authentication data from Dir Server
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.

Public Attributes

readonly attribute PRInt32 replicationState
 readonly attribute giving the current replication state
const long kIdle = 0
 replication states
const long kAnonymousBinding = 1
const long kAuthenticatedBinding = 2
const long kSyncServerBinding = 3
const long kSearchingAuthDN = 4
const long kDecidingProtocol = 5
const long kAuthenticating = 6
const long kReplicatingAll = 7
const long kSearchingRootDSE = 8
const long kFindingChanges = 9
const long kReplicatingChanges = 10
const long kReplicationDone = 11
readonly attribute PRInt32 protocolUsed
 readonly attribute giving the current protocol used
const long kDefaultDownloadAll = 0
 replication protocols
const long kChangeLogProtocol = 1
const long kLCUPProtocol = 2
const long kLastUpdatedTimeStampMethod = 3

Protected Member Functions

virtual nsresult OnLDAPBind (nsILDAPMessage *aMessage)
virtual nsresult OnLDAPSearchEntry (nsILDAPMessage *aMessage)
virtual nsresult OnLDAPSearchResult (nsILDAPMessage *aMessage)
nsresult OpenABForReplicatedDir (PRBool bCreate)
nsresult DeleteCard (nsString &aDn)
void Done (PRBool aSuccess)

Protected Attributes

nsCOMPtr
< nsIAbLDAPReplicationQuery
mQuery
nsCOMPtr< nsIWebProgressListenermListener
nsCOMPtr< nsIAddrDatabasemReplicationDB
nsCOMPtr< nsILocalFilemReplicationFile
nsCOMPtr< nsILocalFilemBackupReplicationFile
PRInt32 mState
PRInt32 mProtocol
PRInt32 mCount
PRBool mDBOpen
PRBool mInitialized
DIR_ServermDirServerInfo
nsCString mAuthDN
nsCString mAuthPswd
nsCOMPtr< nsIAbLDAPAttributeMapmAttrMap

Detailed Description

Definition at line 50 of file nsAbLDAPReplicationData.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsAbLDAPReplicationData.cpp.

{
  /* destructor code */
  if(mDBOpen && mReplicationDB) 
      mReplicationDB->Close(PR_FALSE);
}

Member Function Documentation

this method a aborts the ongoing processing

Definition at line 611 of file nsAbLDAPReplicationData.cpp.

{
    nsCOMPtr<nsIAbCard> cardToDelete;
    mReplicationDB->GetCardFromAttribute(nsnull, "_DN", NS_ConvertUCS2toUTF8(aDn).get(),
                                         PR_FALSE, getter_AddRefs(cardToDelete));
    return mReplicationDB->DeleteCard(cardToDelete, PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 594 of file nsAbLDAPReplicationData.cpp.

{
   if(!mInitialized) 
       return;

   mState = kReplicationDone;

   mQuery->Done(aSuccess);

   if(mListener)
       mListener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, aSuccess);

   // since this is called when all is done here, either on success, failure or abort
   // releas the query now.
   mQuery = nsnull;
}

Here is the caller graph for this function:

this method initializes the implementation

Reimplemented in nsAbLDAPProcessChangeLogData.

Definition at line 286 of file nsAbLDAPReplicationData.cpp.

{
    NS_ENSURE_ARG_POINTER(aMessage);
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;

    PRInt32 errCode;

    nsresult rv = aMessage->GetErrorCode(&errCode);
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        return rv;
    }

    if(errCode != nsILDAPErrors::SUCCESS) {
        Done(PR_FALSE);
        return NS_ERROR_FAILURE;
    }

    rv = OpenABForReplicatedDir(PR_TRUE);
    if(NS_FAILED(rv)) {
        // do not call done here since it is called by OpenABForReplicationDir
        return rv;
    }

    rv = mQuery->QueryAllEntries();
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        return rv;
    }

    mState = kReplicatingAll;

    if(mListener && NS_SUCCEEDED(rv))
        mListener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_START, PR_TRUE);

    return rv;
}

Here is the call 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?

Reimplemented in nsAbLDAPProcessChangeLogData.

Definition at line 325 of file nsAbLDAPReplicationData.cpp.

{
    NS_ENSURE_ARG_POINTER(aMessage);
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;
    // since this runs on the main thread and is single threaded, this will 
    // take care of entries returned by LDAP Connection thread after Abort.
    if(!mReplicationDB || !mDBOpen) 
        return NS_ERROR_FAILURE;

  nsresult rv = NS_OK;

  // Although we would may naturally create an nsIAbLDAPCard here, we don't
  // need to as we are writing this straight to the database, so just create
  // the database version instead.
  nsCOMPtr<nsIAbMDBCard> dbCard(do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv));
  if(NS_FAILED(rv)) {
    Abort();
    return rv;
  }

  nsCOMPtr<nsIAbCard> newCard(do_QueryInterface(dbCard, &rv));
  if(NS_FAILED(rv)) {
    Abort();
    return rv;
  }

    rv = mAttrMap->SetCardPropertiesFromLDAPMessage(aMessage, newCard);
    if (NS_FAILED(rv))
    {
        NS_WARNING("nsAbLDAPProcessReplicationData::OnLDAPSearchEntry"
           "No card properties could be set");
        // if some entries are bogus for us, continue with next one
        return NS_OK;
    }

#ifdef DEBUG_rdayal
        nsXPIDLString firstName;
        rv = card.GetFirstName(getter_Copies(firstName));
        NS_ENSURE_SUCCESS(rv,rv);
        nsXPIDLString lastName;
        rv = card.GetLastName(getter_Copies(lastName));
        NS_ENSURE_SUCCESS(rv,rv);
        nsCAutoString name;
        name.AssignWithConversion(firstName);
        name.Append("  ");
        name.AppendWithConversion(lastName);
        printf("\n LDAPReplication :: got card #: %d, name: %s \n", mCount, name.get());
#endif

    rv = mReplicationDB->CreateNewCardAndAddToDB(newCard, PR_FALSE);
    if(NS_FAILED(rv)) {
        Abort();
        return rv;
    }

    // now set the attribute for the DN of the entry in the card in the DB
    nsCAutoString authDN;
    rv = aMessage->GetDn(authDN);
    if(NS_SUCCEEDED(rv) && !authDN.IsEmpty())
    {
        dbCard->SetAbDatabase(mReplicationDB);
        dbCard->SetStringAttribute("_DN", NS_ConvertUTF8toUCS2(authDN).get());
    }

    newCard = do_QueryInterface(dbCard, &rv);
    if(NS_FAILED(rv)) {
        Abort();
        return rv;
    }

    rv = mReplicationDB->EditCard(newCard, PR_FALSE);
    if(NS_FAILED(rv)) {
        Abort();
        return rv;
    }
    

    mCount ++;

    if(!(mCount % 10))  // inform the listener every 10 entries
    {
        mListener->OnProgressChange(nsnull,nsnull,mCount, -1, mCount, -1);
        // in case if the LDAP Connection thread is starved and causes problem
        // uncomment this one and try.
        // PR_Sleep(PR_INTERVAL_NO_WAIT); // give others a chance
    }

    return rv;
}

Here is the call graph for this function:

Reimplemented in nsAbLDAPProcessChangeLogData.

Definition at line 417 of file nsAbLDAPReplicationData.cpp.

{
#ifdef DEBUG_rdayal
    printf("LDAP Replication : Got Results for Completion");
#endif

    NS_ENSURE_ARG_POINTER(aMessage);
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;

    PRInt32 errorCode;
    nsresult rv = aMessage->GetErrorCode(&errorCode);

    if(NS_SUCCEEDED(rv)) {
        // We are done with the LDAP search for all entries.
        if(errorCode == nsILDAPErrors::SUCCESS || errorCode == nsILDAPErrors::SIZELIMIT_EXCEEDED) {
            Done(PR_TRUE);
            if(mReplicationDB && mDBOpen) {
                rv = mReplicationDB->Close(PR_TRUE);
                NS_ASSERTION(NS_SUCCEEDED(rv), "Replication DB Close on Success failed");
                mDBOpen = PR_FALSE;
                // once we have saved the new replication file, delete the backup file
                if(mBackupReplicationFile)
                {
                    rv = mBackupReplicationFile->Remove(PR_FALSE);
                    NS_ASSERTION(NS_SUCCEEDED(rv), "Replication BackupFile Remove on Success failed");
                }
            }
            return NS_OK;
        }
    }

    // in case if GetErrorCode returned error or errorCode is not SUCCESS / SIZELIMIT_EXCEEDED
    if(mReplicationDB && mDBOpen) {
        // if error result is returned close the DB without saving ???
        // should we commit anyway ??? whatever is returned is not lost then !!
        rv = mReplicationDB->ForceClosed(); // force close since we need to delete the file.
        NS_ASSERTION(NS_SUCCEEDED(rv), "Replication DB ForceClosed on Failure failed");
        mDBOpen = PR_FALSE;
        // if error result is returned remove the replicated file
        if(mReplicationFile) {
            rv = mReplicationFile->Remove(PR_FALSE);
            NS_ASSERTION(NS_SUCCEEDED(rv), "Replication File Remove on Failure failed");
            if(NS_SUCCEEDED(rv)) {
                // now put back the backed up replicated file
                if(mBackupReplicationFile && mDirServerInfo->replInfo) 
                {
                    rv = mBackupReplicationFile->MoveToNative(nsnull, nsDependentCString(mDirServerInfo->replInfo->fileName));
                    NS_ASSERTION(NS_SUCCEEDED(rv), "Replication Backup File Move back on Failure failed");
                }
            }
        }
        Done(PR_FALSE);
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 475 of file nsAbLDAPReplicationData.cpp.

{
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_OK;

    nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        return rv;
    }

    if(!mDirServerInfo->replInfo->fileName) {
        Done(PR_FALSE);
        return NS_ERROR_FAILURE;
    }

    rv = abSession->GetUserProfileDirectory(getter_AddRefs(mReplicationFile));
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        return rv;
    }

    rv = mReplicationFile->AppendNative(nsDependentCString(mDirServerInfo->replInfo->fileName));
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        return rv;
    }

    // if the AB DB already exists backup existing one, 
    // in case if the user cancels or Abort put back the backed up file
    PRBool fileExists;
    rv = mReplicationFile->Exists(&fileExists);
    if(NS_SUCCEEDED(rv) && fileExists) {
        // create the backup file object same as the Replication file object.
        // we create a backup file here since we need to cleanup the existing file
        // for create and then commit so instead of deleting existing cards we just
        // clone the existing one for a much better performance - for Download All.
        // And also important in case if replication fails we donot lose user's existing 
        // replicated data for both Download all and Changelog.
        nsCOMPtr<nsIFile> clone;
        rv = mReplicationFile->Clone(getter_AddRefs(clone));
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }
        mBackupReplicationFile = do_QueryInterface(clone, &rv);
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }
        rv = mBackupReplicationFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777);
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }
        nsAutoString backupFileLeafName;
        rv = mBackupReplicationFile->GetLeafName(backupFileLeafName);
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }
        // remove the newly created unique backup file so that move and copy succeeds.
        rv = mBackupReplicationFile->Remove(PR_FALSE);
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }

        if(aCreate) {
            // set backup file to existing replication file for move
            mBackupReplicationFile->SetNativeLeafName(nsDependentCString(mDirServerInfo->replInfo->fileName));
            rv = mBackupReplicationFile->MoveTo(nsnull, backupFileLeafName);
            // set the backup file leaf name now
            if (NS_SUCCEEDED(rv))
                mBackupReplicationFile->SetLeafName(backupFileLeafName);
        }
        else {
            // set backup file to existing replication file for copy
            mBackupReplicationFile->SetNativeLeafName(nsDependentCString(mDirServerInfo->replInfo->fileName));
            // specify the parent here specifically, 
            // passing nsnull to copy to the same dir actually renames existing file
            // instead of making another copy of the existing file.
            nsCOMPtr<nsIFile> parent;
            rv = mBackupReplicationFile->GetParent(getter_AddRefs(parent));
            if (NS_SUCCEEDED(rv))
                rv = mBackupReplicationFile->CopyTo(parent, backupFileLeafName);
            // set the backup file leaf name now
            if (NS_SUCCEEDED(rv))
                mBackupReplicationFile->SetLeafName(backupFileLeafName);
        }
        if(NS_FAILED(rv))  {
            Done(PR_FALSE);
            return rv;
        }
    }

    nsCOMPtr<nsIAddrDatabase> addrDBFactory = 
             do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
    if(NS_FAILED(rv)) {
        if (mBackupReplicationFile)
            mBackupReplicationFile->Remove(PR_FALSE);
        Done(PR_FALSE);
        return rv;
    }
    
    rv = addrDBFactory->Open(mReplicationFile, aCreate, PR_TRUE, getter_AddRefs(mReplicationDB));
    if(NS_FAILED(rv)) {
        Done(PR_FALSE);
        if (mBackupReplicationFile)
            mBackupReplicationFile->Remove(PR_FALSE);
        return rv;
    }

    mDBOpen = PR_TRUE;  // replication DB is now Open
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

this utility method populates authentication data from Dir Server


Member Data Documentation

Definition at line 58 of file nsIAbLDAPReplicationData.idl.

Definition at line 59 of file nsIAbLDAPReplicationData.idl.

Definition at line 63 of file nsIAbLDAPReplicationData.idl.

Definition at line 79 of file nsIAbLDAPReplicationData.idl.

Definition at line 62 of file nsIAbLDAPReplicationData.idl.

replication protocols

Definition at line 78 of file nsIAbLDAPReplicationData.idl.

Definition at line 66 of file nsIAbLDAPReplicationData.idl.

replication states

Definition at line 57 of file nsIAbLDAPReplicationData.idl.

Definition at line 81 of file nsIAbLDAPReplicationData.idl.

Definition at line 80 of file nsIAbLDAPReplicationData.idl.

Definition at line 64 of file nsIAbLDAPReplicationData.idl.

Definition at line 67 of file nsIAbLDAPReplicationData.idl.

Definition at line 68 of file nsIAbLDAPReplicationData.idl.

Definition at line 61 of file nsIAbLDAPReplicationData.idl.

Definition at line 65 of file nsIAbLDAPReplicationData.idl.

Definition at line 60 of file nsIAbLDAPReplicationData.idl.

Definition at line 80 of file nsAbLDAPReplicationData.h.

Definition at line 78 of file nsAbLDAPReplicationData.h.

Definition at line 79 of file nsAbLDAPReplicationData.h.

Definition at line 68 of file nsAbLDAPReplicationData.h.

Definition at line 73 of file nsAbLDAPReplicationData.h.

Definition at line 74 of file nsAbLDAPReplicationData.h.

Definition at line 77 of file nsAbLDAPReplicationData.h.

Definition at line 75 of file nsAbLDAPReplicationData.h.

Definition at line 64 of file nsAbLDAPReplicationData.h.

Definition at line 72 of file nsAbLDAPReplicationData.h.

Definition at line 61 of file nsAbLDAPReplicationData.h.

Definition at line 66 of file nsAbLDAPReplicationData.h.

Definition at line 67 of file nsAbLDAPReplicationData.h.

Definition at line 71 of file nsAbLDAPReplicationData.h.

readonly attribute giving the current protocol used

Definition at line 73 of file nsIAbLDAPReplicationData.idl.

readonly attribute giving the current replication state

Definition at line 52 of file nsIAbLDAPReplicationData.idl.


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