Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CPalmSyncImp Class Reference

#include <PalmSyncImp.h>

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

List of all members.

Public Member Functions

STDMETHODIMP QueryInterface (const IID &aIid, void **aPpv)
 STDMETHODIMP_ (ULONG) AddRef()
 STDMETHODIMP_ (ULONG) Release()
STDMETHODIMP IsValid ()
 CPalmSyncImp ()
 ~CPalmSyncImp ()
STDMETHODIMP nsGetABList (BOOL aIsUnicode, short *aABListCount, lpnsMozABDesc *aABList, long **aABCatIndexList, BOOL **aDirFlags)
STDMETHODIMP nsSynchronizeAB (BOOL aIsUnicode, long aCategoryIndex, long aCategoryId, LPTSTR aABName, int aModRemoteRecCount, lpnsABCOMCardStruct aModRemoteRecList, int *aModMozRecCount, lpnsABCOMCardStruct *aModMozRecList)
STDMETHODIMP nsAddAllABRecords (BOOL aIsUnicode, BOOL replaceExisting, long aCategoryIndex, LPTSTR aABName, int aRemoteRecCount, lpnsABCOMCardStruct aRemoteRecList)
STDMETHODIMP nsGetAllABCards (BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName, int *aMozRecCount, lpnsABCOMCardStruct *aMozRecList)
STDMETHODIMP nsAckSyncDone (BOOL aIsSuccess, long aCatIndex, int aNewRecCount, unsigned long *aNewPalmRecIDList)
STDMETHODIMP nsUpdateABSyncInfo (BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName)
STDMETHODIMP nsDeleteAB (BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName, LPTSTR aABUrl)
STDMETHODIMP nsRenameAB (BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName, LPTSTR aABUrl)
STDMETHODIMP nsUseABHomeAddressForPalmAddress (BOOL *aUseHomeAddress)
STDMETHODIMP nsPreferABHomePhoneForPalmPhone (BOOL *aPreferHomePhone)
STDMETHODIMP nsGetABDeleted (LPTSTR aABName, BOOL *abDeleted)
virtual long QueryInterface ()=0
virtual long AddRef ()=0
virtual long Release ()=0

Static Public Member Functions

static PRBool GetBoolPref (const char *prefName, PRBool defaultVal)
static PRInt32 GetIntPref (const char *prefName, PRInt32 defaultVal)
static PRBool nsUseABHomeAddressForPalmAddress ()
static PRBool nsPreferABHomePhoneForPalmPhone ()

Private Member Functions

void CopyUnicodeString (LPTSTR *destStr, const nsAFlatString &srcStr)
void CopyCString (LPTSTR *destStr, const nsAFlatCString &srcStr)

Private Attributes

PRInt32 m_cRef
voidm_PalmHotSync

Detailed Description

Definition at line 50 of file PalmSyncImp.h.


Constructor & Destructor Documentation

Definition at line 68 of file PalmSyncImp.cpp.

: m_cRef(1),
  m_PalmHotSync(nsnull)
{
  if (!PALMSYNC)
    PALMSYNC = PR_NewLogModule("PALMSYNC");


}

Definition at line 78 of file PalmSyncImp.cpp.

{ 

}

Member Function Documentation

virtual long IUnknown::AddRef ( ) [pure virtual, inherited]

Here is the caller graph for this function:

void CPalmSyncImp::CopyCString ( LPTSTR destStr,
const nsAFlatCString srcStr 
) [private]

Definition at line 441 of file PalmSyncImp.cpp.

{
  if (!destStr)
    return;

  // these strings are defined as wide in the idl, so we need to add up to 3
  // bytes of 0 byte padding at the end (if the string is an odd number of
  // bytes long, we need one null byte to pad out the last char to a wide char
  // and then  two more nulls as a wide null terminator. 
  PRInt32 length = sizeof(char) * (srcStr.Length()+3);
  *destStr = (LPTSTR) CoTaskMemAlloc(length);
  char *sp = (char *)*destStr;
  strncpy(sp, srcStr.get(), length-1); // this will null fill the end of destStr
  sp[length-1] = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CPalmSyncImp::CopyUnicodeString ( LPTSTR destStr,
const nsAFlatString srcStr 
) [private]

Definition at line 430 of file PalmSyncImp.cpp.

{
  if (!destStr)
    return;

  PRInt32 length = srcStr.Length()+1;
  *destStr = (LPTSTR) CoTaskMemAlloc(sizeof(PRUnichar) * length);
  wcsncpy(*destStr, srcStr.get(), length-1);
  (*destStr)[length-1] = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool CPalmSyncImp::GetBoolPref ( const char *  prefName,
PRBool  defaultVal 
) [static]

Definition at line 458 of file PalmSyncImp.cpp.

{
  PRBool boolVal = defaultVal;
  
  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
  if (prefBranch)
    prefBranch->GetBoolPref(prefName, &boolVal);
  return boolVal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 CPalmSyncImp::GetIntPref ( const char *  prefName,
PRInt32  defaultVal 
) [static]

Definition at line 468 of file PalmSyncImp.cpp.

{
  PRInt32 intVal = defaultVal;
  
  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
  if (prefBranch)
    prefBranch->GetIntPref(prefName, &intVal);
  return intVal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP CPalmSyncImp::IsValid ( )

Implements IPalmSync.

Definition at line 121 of file PalmSyncImp.cpp.

{
    return S_OK;
}
STDMETHODIMP CPalmSyncImp::nsAckSyncDone ( BOOL  aIsSuccess,
long  aCatIndex,
int  aNewRecCount,
unsigned long aNewPalmRecIDList 
)

Implements IPalmSync.

Definition at line 366 of file PalmSyncImp.cpp.

{
    nsAbPalmHotSync * tempPalmHotSync = (nsAbPalmHotSync *) m_PalmHotSync;
    if(tempPalmHotSync) {
        if(aNewRecCount && (aCatIndex > -1))
            tempPalmHotSync->Done(aIsSuccess, aCatIndex, aNewRecCount, aNewPalmRecIDList);
        delete tempPalmHotSync;
    }
    m_PalmHotSync = nsnull;

    return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsAddAllABRecords ( BOOL  aIsUnicode,
BOOL  replaceExisting,
long  aCategoryIndex,
LPTSTR  aABName,
int  aRemoteRecCount,
lpnsABCOMCardStruct  aRemoteRecList 
)

Implements IPalmSync.

Definition at line 316 of file PalmSyncImp.cpp.

{
    // since we are not returning any data we don't need to keep the nsAbPalmHotSync reference
    // in order to free the returned data in its destructor. Just create a local nsAbPalmHotSync var.
    nsAbPalmHotSync palmHotSync(aIsUnicode, aABName, (const char*)aABName, aCategoryIndex, -1);

    nsresult rv = palmHotSync.AddAllRecordsToAB(replaceExisting, aRemoteRecCount, aRemoteRecList);

    if (NS_FAILED(rv))
        return E_FAIL;

    return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsDeleteAB ( BOOL  aIsUnicode,
long  aCategoryIndex,
LPTSTR  aABName,
LPTSTR  aABUrl 
)

Implements IPalmSync.

Definition at line 401 of file PalmSyncImp.cpp.

{
  // This is an independent operation so use a local nsAbPalmHotSync var
  // (ie the callers don't need to call AckSyncdone after this is done).
  nsAbPalmHotSync palmHotSync(aIsUnicode, aABName, (const char*)aABName, aCategoryIndex, -1);

  nsresult rv = palmHotSync.DeleteAB(aCategoryIndex, (const char*)aABUrl);

  if (NS_FAILED(rv))
      return E_FAIL;

  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsGetABDeleted ( LPTSTR  aABName,
BOOL abDeleted 
)

Implements IPalmSync.

Definition at line 331 of file PalmSyncImp.cpp.

{
  nsCAutoString prefName("ldap_2.servers.");
  prefName.Append((const char *)aABName);
  prefName.Append(".position");
  PRInt32 position = GetIntPref(prefName.get(), -1);
  *abDeleted = (position == 0);
  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsGetABList ( BOOL  aIsUnicode,
short *  aABListCount,
lpnsMozABDesc aABList,
long **  aABCatIndexList,
BOOL **  aDirFlags 
)

Implements IPalmSync.

Definition at line 127 of file PalmSyncImp.cpp.

{
  if (!aABListCount || !aABList || !aABCatIndexList ||!aDirFlagsList)
        return E_FAIL;
  *aABListCount = 0;

  nsresult rv;
  nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
  if(NS_FAILED(rv)) return E_FAIL;

  // Parent nsIABDirectory is "moz-abdirectory://".
  nsCOMPtr <nsIRDFResource> resource;
  rv = rdfService->GetResource(NS_LITERAL_CSTRING("moz-abdirectory://"), getter_AddRefs(resource));
  if(NS_FAILED(rv)) return E_FAIL;

  nsCOMPtr <nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
  if(NS_FAILED(rv)) return E_FAIL;

  nsCOMPtr<nsISimpleEnumerator> subDirectories;
  if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories)
  {
    // Get the total number of addrbook.
    PRInt16 count=0;
    nsCOMPtr<nsISupports> item;
    PRBool hasMore;
    while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
    {
        if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item))))
        {
          nsCOMPtr <nsIAbDirectory> subDirectory = do_QueryInterface(item, &rv);
          if (NS_SUCCEEDED(rv))
          {
              nsCOMPtr <nsIAbDirectoryProperties> properties;
              nsXPIDLCString fileName;
              rv = subDirectory->GetDirectoryProperties(getter_AddRefs(properties));
              if(NS_FAILED(rv)) 
                continue;
              rv = properties->GetFileName(getter_Copies(fileName));
              if(NS_FAILED(rv)) 
                continue;
              PRUint32 dirType;
              rv = properties->GetDirType(&dirType);
              nsCAutoString prefName;
              subDirectory->GetDirPrefId(prefName);
              prefName.Append(".disablePalmSync");
              PRBool disableThisAB = GetBoolPref(prefName.get(), PR_FALSE);
              // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
              if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) && 
                   strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
                    (dirType != kPABDirectory && dirType != kMAPIDirectory))
                    continue;
          }
        }
        count++;
    }

    if (!count)
      return E_FAIL;  // should not happen but just in case.

    lpnsMozABDesc serverDescList = (lpnsMozABDesc) CoTaskMemAlloc(sizeof(nsMozABDesc) * count);
    BOOL *dirFlagsList = (BOOL *) CoTaskMemAlloc(sizeof(BOOL) * count);
    long *catIndexList = (long *) CoTaskMemAlloc(sizeof(long) * count);

    *aABListCount = count;
    *aABList = serverDescList;
    *aDirFlagsList = dirFlagsList;
    *aABCatIndexList = catIndexList;

    directory->GetChildNodes(getter_AddRefs(subDirectories)); // reset enumerator
    // For each valid addrbook collect info.
    while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
    {
      if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item))))
      {
        directory = do_QueryInterface(item, &rv);
        if (NS_SUCCEEDED(rv))
        {
          // We don't have to skip mailing list since there's no mailing lists at the top level.
          nsCOMPtr <nsIAbDirectoryProperties> properties;
          rv = directory->GetDirectoryProperties(getter_AddRefs(properties));
          if(NS_FAILED(rv)) return E_FAIL;

          nsXPIDLCString fileName, uri;
          nsAutoString description;
          PRUint32 dirType, palmSyncTimeStamp;
          PRInt32 palmCategoryIndex;

          rv = properties->GetDescription(description);
          if(NS_FAILED(rv)) return E_FAIL;
          rv = properties->GetFileName(getter_Copies(fileName));
          if(NS_FAILED(rv)) return E_FAIL;
          rv = properties->GetURI(getter_Copies(uri));
          if(NS_FAILED(rv)) return E_FAIL;
          rv = properties->GetDirType(&dirType);
          if(NS_FAILED(rv)) return E_FAIL;
          rv = properties->GetSyncTimeStamp(&palmSyncTimeStamp);
          if(NS_FAILED(rv)) return E_FAIL;
          rv = properties->GetCategoryId(&palmCategoryIndex);
          if(NS_FAILED(rv)) return E_FAIL;
          nsCAutoString prefName;
          directory->GetDirPrefId(prefName);
          prefName.Append(".disablePalmSync");
          PRBool disableThisAB = GetBoolPref(prefName.get(), PR_FALSE);
          // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
          if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) && 
               strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
                (dirType != kPABDirectory && dirType != kMAPIDirectory))
          {
            continue;
          }

          if(aIsUnicode) 
          {
            // convert uri to Unicode
            nsAutoString abUrl;
            rv = ConvertToUnicode("UTF-8", uri, abUrl);
            if (NS_FAILED(rv))
              break;
            // add to the list
            CopyUnicodeString(&(serverDescList->lpszABName), description);
            CopyUnicodeString(&(serverDescList->lpszABUrl), abUrl);
          }
          else {
            // we need to convert uri to Unicode and then to ASCII
            nsAutoString abUUrl;

            rv = ConvertToUnicode("UTF-8", uri, abUUrl);
            if (NS_FAILED(rv))
              break;

            CopyCString(&(serverDescList->lpszABName),
                        NS_ConvertUTF16toUTF8(description));
            CopyCString(&(serverDescList->lpszABUrl),
                        NS_ConvertUTF16toUTF8(abUUrl));
          }
          serverDescList++;

          PRUint32 dirFlag = 0;
          if (palmSyncTimeStamp <= 0)
            dirFlag |= kFirstTimeSyncDirFlag;
          // was this the pab?
          if (prefName.Equals("ldap_2.servers.pab.disablePalmSync"))
            dirFlag |= kIsPabDirFlag;
          *dirFlagsList = (BOOL) dirFlag;
          dirFlagsList++;

          *catIndexList = palmCategoryIndex;
          catIndexList++;
        }
      }
    }

    // assign member variables to the beginning of the list
    serverDescList = *aABList;
    dirFlagsList = *aDirFlagsList;
    catIndexList = *aABCatIndexList;

    if(NS_FAILED(rv))
      return E_FAIL;
  }
  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsGetAllABCards ( BOOL  aIsUnicode,
long  aCategoryIndex,
LPTSTR  aABName,
int aMozRecCount,
lpnsABCOMCardStruct aMozRecList 
)

Implements IPalmSync.

Definition at line 343 of file PalmSyncImp.cpp.

{
    // if sync is already going on wait for AckSyncDone to be called
    if(m_PalmHotSync)
        return E_FAIL;

    m_PalmHotSync = (nsAbPalmHotSync *) new nsAbPalmHotSync(aIsUnicode, aABName, (char*)aABName, aCategoryIndex, -1);
    if(!m_PalmHotSync)
        return E_FAIL;

    nsresult rv = ((nsAbPalmHotSync *)m_PalmHotSync)->Initialize();
    if (NS_SUCCEEDED(rv))
        rv = ((nsAbPalmHotSync *)m_PalmHotSync)->GetAllCards(aMozRecCount, aMozRecList);

    if (NS_FAILED(rv))
        return E_FAIL;

    return S_OK;
}
STDMETHODIMP CPalmSyncImp::nsPreferABHomePhoneForPalmPhone ( BOOL aPreferHomePhone)

Implements IPalmSync.

Definition at line 485 of file PalmSyncImp.cpp.

{
  *aPreferHomePhone = nsPreferABHomePhoneForPalmPhone();
  return S_OK;
}

Here is the call graph for this function:

Definition at line 503 of file PalmSyncImp.cpp.

{
  static PRBool gGotPhonePref = PR_FALSE;
  static PRBool gPreferHomePhone;
  if (!gGotPhonePref)
  {
    gPreferHomePhone = GetBoolPref("mail.palmsync.preferHomePhone", PR_TRUE);
    gGotPhonePref = PR_TRUE;
  }
  return gPreferHomePhone;
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP CPalmSyncImp::nsRenameAB ( BOOL  aIsUnicode,
long  aCategoryIndex,
LPTSTR  aABName,
LPTSTR  aABUrl 
)

Implements IPalmSync.

Definition at line 416 of file PalmSyncImp.cpp.

{
  // This is an independent operation so use a local nsAbPalmHotSync var
  // (ie the callers don't need to call AckSyncdone after this is done).
  nsAbPalmHotSync palmHotSync(aIsUnicode, aABName, (const char*)aABName, aCategoryIndex, -1);

  nsresult rv = palmHotSync.RenameAB(aCategoryIndex, (const char*)aABUrl);

  if (NS_FAILED(rv))
    return E_FAIL;

  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsSynchronizeAB ( BOOL  aIsUnicode,
long  aCategoryIndex,
long  aCategoryId,
LPTSTR  aABName,
int  aModRemoteRecCount,
lpnsABCOMCardStruct  aModRemoteRecList,
int aModMozRecCount,
lpnsABCOMCardStruct aModMozRecList 
)

Implements IPalmSync.

Definition at line 292 of file PalmSyncImp.cpp.

{
    // let the already continuing sync complete
    if(m_PalmHotSync)
        return E_FAIL;

    m_PalmHotSync = (nsAbPalmHotSync *) new nsAbPalmHotSync(aIsUnicode, aABName, (char*)aABName, aCategoryIndex, aCategoryId);
    if(!m_PalmHotSync)
        return E_FAIL;

    nsresult rv = ((nsAbPalmHotSync *)m_PalmHotSync)->Initialize();
    if (NS_SUCCEEDED(rv))
        rv = ((nsAbPalmHotSync *)m_PalmHotSync)->DoSyncAndGetUpdatedCards(aModRemoteRecCount, aModRemoteRecList, aModMozRecCount, aModMozRecList);

    if (NS_FAILED(rv))
        return E_FAIL;

    return S_OK;
}
STDMETHODIMP CPalmSyncImp::nsUpdateABSyncInfo ( BOOL  aIsUnicode,
long  aCategoryIndex,
LPTSTR  aABName 
)

Implements IPalmSync.

Definition at line 380 of file PalmSyncImp.cpp.

{
  nsresult rv;
  if(m_PalmHotSync)
    rv = ((nsAbPalmHotSync *)m_PalmHotSync)->UpdateSyncInfo(aCategoryIndex);
  else
  {
    // Launch another ABpalmHotSync session.
    nsAbPalmHotSync palmHotSync(aIsUnicode, aABName, (const char*)aABName, aCategoryIndex, -1);
    rv = palmHotSync.Initialize();
    if (NS_SUCCEEDED(rv))
      rv = palmHotSync.UpdateSyncInfo(aCategoryIndex);
  }

  if (NS_FAILED(rv))
    return E_FAIL;

  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CPalmSyncImp::nsUseABHomeAddressForPalmAddress ( BOOL aUseHomeAddress)

Implements IPalmSync.

Definition at line 479 of file PalmSyncImp.cpp.

{
  *aUseHomeAddress = nsUseABHomeAddressForPalmAddress();
  return S_OK;
}

Here is the call graph for this function:

Definition at line 491 of file PalmSyncImp.cpp.

{
  static PRBool gGotAddressPref = PR_FALSE;
  static PRBool gUseHomeAddress;
  if (!gGotAddressPref)
  {
    gUseHomeAddress = GetBoolPref("mail.palmsync.useHomeAddress", PR_TRUE);
    gGotAddressPref = PR_TRUE;
  }
  return gUseHomeAddress;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual long IUnknown::QueryInterface ( ) [pure virtual, inherited]

Here is the caller graph for this function:

STDMETHODIMP CPalmSyncImp::QueryInterface ( const IID &  aIid,
void **  aPpv 
)

Definition at line 83 of file PalmSyncImp.cpp.

{    
    if (aIid == IID_IUnknown)
    {
        *aPpv = static_cast<IPalmSync*>(this); 
    }
    else if (aIid == IID_IPalmSync)
    {
        *aPpv = static_cast<IPalmSync*>(this);
    }
    else
    {
        *aPpv = nsnull;
        return E_NOINTERFACE;
    }

    reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual long IUnknown::Release ( ) [pure virtual, inherited]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 103 of file PalmSyncImp.h.

Definition at line 104 of file PalmSyncImp.h.


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