Back to index

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

#include <WabObject.h>

Collaboration diagram for CWAB:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CWAB (nsIFileSpec *fileName)
 ~CWAB ()
PRBool Loaded (void)
HRESULT IterateWABContents (CWabIterator *pIter, int *pDone)
LPDISTLIST GetDistList (ULONG cbEid, LPENTRYID pEid)
void ReleaseDistList (LPDISTLIST pList)
LPMAILUSER GetUser (ULONG cbEid, LPENTRYID pEid)
void ReleaseUser (LPMAILUSER pUser)
LPSPropValue GetUserProperty (LPMAILUSER pUser, ULONG tag)
LPSPropValue GetListProperty (LPDISTLIST pList, ULONG tag)
void FreeProperty (LPSPropValue pVal)
void GetValueString (LPSPropValue pVal, nsString &val)
void CStrToUnicode (const char *pStr, nsString &result)
void FreeProws (LPSRowSet prows)

Private Attributes

PRUnicharm_pUniBuff
int m_uniBuffLen
PRBool m_bInitialized
HINSTANCE m_hinstWAB
LPWABOPEN m_lpfnWABOpen
LPADRBOOK m_lpAdrBook
LPWABOBJECT m_lpWABObject

Detailed Description

Definition at line 57 of file WabObject.h.


Constructor & Destructor Documentation

CWAB::CWAB ( nsIFileSpec fileName)

Definition at line 115 of file WabObject.cpp.

{
    // Here we load the WAB Object and initialize it
    m_pUniBuff = NULL;
       m_uniBuffLen = 0;

       m_bInitialized = PR_FALSE;
       m_lpAdrBook = NULL;
       m_lpWABObject = NULL;
       m_hinstWAB = NULL;

    {
        TCHAR  szWABDllPath[MAX_PATH];
        DWORD  dwType = 0;
        ULONG  cbData = sizeof(szWABDllPath);
        HKEY hKey = NULL;

        *szWABDllPath = '\0';
        
        // First we look under the default WAB DLL path location in the
        // Registry. 
        // WAB_DLL_PATH_KEY is defined in wabapi.h
        //
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
            RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);

        if(hKey) RegCloseKey(hKey);

        // if the Registry came up blank, we do a loadlibrary on the wab32.dll
        // WAB_DLL_NAME is defined in wabapi.h
        //
        m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
    }

    if(m_hinstWAB)
    {
        // if we loaded the dll, get the entry point 
        //
        m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");

        if(m_lpfnWABOpen)
        {
              char          fName[2] = {0, 0};
              char *        pPath = nsnull;
            HRESULT hr = E_FAIL;
            WAB_PARAM wp = {0};
            wp.cbSize = sizeof(WAB_PARAM);
            if (file != nsnull) {
              file->GetNativePath( &pPath);      
              wp.szFileName = (LPTSTR) pPath;
            }
            else
              wp.szFileName = (LPTSTR) fName;
        
            // if we choose not to pass in a WAB_PARAM object, 
            // the default WAB file will be opened up
            //
            hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);

            if(!hr)
                m_bInitialized = TRUE;
            
            if (pPath)
              nsCRT::free( pPath);
        }
    }

}

Definition at line 187 of file WabObject.cpp.

{
       if (m_pUniBuff)
              delete [] m_pUniBuff;

    if(m_bInitialized)
    {
        if(m_lpAdrBook)
            m_lpAdrBook->Release();

        if(m_lpWABObject)
            m_lpWABObject->Release();

        if(m_hinstWAB)
            FreeLibrary(m_hinstWAB);
    }
}

Member Function Documentation

void CWAB::CStrToUnicode ( const char *  pStr,
nsString result 
)

Definition at line 532 of file WabObject.cpp.

{
       result.Truncate( 0);
       int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
       if (wLen >= m_uniBuffLen) {
              if (m_pUniBuff)
                     delete [] m_pUniBuff;
              m_pUniBuff = new PRUnichar[wLen + 64];
              m_uniBuffLen = wLen + 64;
       }
       if (wLen) {
              MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
              result = m_pUniBuff;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CWAB::FreeProperty ( LPSPropValue  pVal) [inline]

Definition at line 74 of file WabObject.h.

{ if (pVal) m_lpWABObject->FreeBuffer( pVal);}

Here is the caller graph for this function:

void CWAB::FreeProws ( LPSRowSet  prows)

Definition at line 433 of file WabObject.cpp.

{
       ULONG         irow;
       if (!prows)
              return;
       for (irow = 0; irow < prows->cRows; ++irow)
              m_lpWABObject->FreeBuffer(prows->aRow[irow].lpProps);
       m_lpWABObject->FreeBuffer(prows);
}

Here is the caller graph for this function:

LPDISTLIST CWAB::GetDistList ( ULONG  cbEid,
LPENTRYID  pEid 
)

Definition at line 444 of file WabObject.cpp.

{
       if (!m_bInitialized || !m_lpAdrBook)
              return( NULL);
       
       LPDISTLIST    lpDistList = NULL;
       ULONG         ulObjType;

       m_lpAdrBook->OpenEntry( cbEid, pEid, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpDistList);
       return( lpDistList);
}
LPSPropValue CWAB::GetListProperty ( LPDISTLIST  pList,
ULONG  tag 
)

Definition at line 456 of file WabObject.cpp.

{
       if (!pUser)
              return( NULL);

       int    sz = CbNewSPropTagArray( 1);
       SPropTagArray *pTag = (SPropTagArray *) new char[sz];
       pTag->cValues = 1;
       pTag->aulPropTag[0] = tag;
       LPSPropValue  lpProp = NULL;
       ULONG  cValues = 0;
       HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
       delete [] pTag;
       if (HR_FAILED( hr) || (cValues != 1)) {
              if (lpProp)
                     m_lpWABObject->FreeBuffer( lpProp);
              return( NULL);
       }
       return( lpProp);
}
LPMAILUSER CWAB::GetUser ( ULONG  cbEid,
LPENTRYID  pEid 
)

Definition at line 477 of file WabObject.cpp.

{
       if (!m_bInitialized || !m_lpAdrBook)
              return( NULL);
       
       LPMAILUSER    lpMailUser = NULL;
       ULONG         ulObjType;

       m_lpAdrBook->OpenEntry( cbEid, pEid, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpMailUser);
       return( lpMailUser);
}

Here is the caller graph for this function:

LPSPropValue CWAB::GetUserProperty ( LPMAILUSER  pUser,
ULONG  tag 
)

Definition at line 489 of file WabObject.cpp.

{
       if (!pUser)
              return( NULL);

       ULONG  uTag = tag;
       /* 
              Getting Unicode does not help with getting the right
              international charset.  Windoze bloze.
       */
       /*
       if (PROP_TYPE( uTag) == PT_STRING8) {
              uTag = CHANGE_PROP_TYPE( tag, PT_UNICODE);
       }
       */

       int    sz = CbNewSPropTagArray( 1);
       SPropTagArray *pTag = (SPropTagArray *) new char[sz];
       pTag->cValues = 1;
       pTag->aulPropTag[0] = uTag;
       LPSPropValue  lpProp = NULL;
       ULONG  cValues = 0;
       HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
       if (HR_FAILED( hr) || (cValues != 1)) {
              if (lpProp)
                     m_lpWABObject->FreeBuffer( lpProp);
              lpProp = NULL;
              if (uTag != tag) {
                     pTag->cValues = 1;
                     pTag->aulPropTag[0] = tag;
                     cValues = 0;
                     hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
                     if (HR_FAILED( hr) || (cValues != 1)) {
                            if (lpProp)
                                   m_lpWABObject->FreeBuffer( lpProp);
                            lpProp = NULL;
                     }
              }
       }
       delete [] pTag;
       return( lpProp);
}

Here is the caller graph for this function:

void CWAB::GetValueString ( LPSPropValue  pVal,
nsString val 
)

Definition at line 549 of file WabObject.cpp.

{
       val.Truncate( 0);
       
       if (!pVal)
              return;

    switch( PROP_TYPE( pVal->ulPropTag)) {
       case PT_STRING8: {
                     CStrToUnicode( (const char *) (pVal->Value.lpszA), val);
              }
        break;
              case PT_UNICODE:
                     val = (PRUnichar *) (pVal->Value.lpszW);
              break;
              case PT_MV_STRING8: {
                     nsString      tmp;
            ULONG    j;
            for(j = 0; j < pVal->Value.MVszA.cValues; j++) {
                            CStrToUnicode( (const char *) (pVal->Value.MVszA.lppszA[j]), tmp);
                val += tmp;
                val.AppendWithConversion(TR_OUTPUT_EOL);
            }
        }
        break;
              case PT_MV_UNICODE: {
            ULONG    j;
            for(j = 0; j < pVal->Value.MVszW.cValues; j++) {
                val += (PRUnichar *) (pVal->Value.MVszW.lppszW[j]);
                val.AppendWithConversion(TR_OUTPUT_EOL);
            }
        }
        break;

              case PT_I2:
              case PT_LONG:
              case PT_R4:
              case PT_DOUBLE:
              case PT_BOOLEAN: {    
                     /*
                     TCHAR sz[256];
            wsprintf(sz,"%d", pVal->Value.l);
            val = sz;
                     */
        }
        break;

              case PT_BINARY:
              break;

              default:
        break;
    }

       val.Trim( kWhitespace, PR_TRUE, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT CWAB::IterateWABContents ( CWabIterator pIter,
int pDone 
)

Definition at line 206 of file WabObject.cpp.

{
  if (!m_bInitialized || !m_lpAdrBook)
    return( E_FAIL);
  
  ULONG                     ulObjType =   0;
  LPMAPITABLE        lpAB =  NULL;
  ULONG                     cRows =       0;
  LPSRowSet          lpRowAB = NULL;
  LPABCONT           lpContainer = NULL;
  int                       cNumRows = 0;
  nsresult                  keepGoing;
  
  HRESULT                   hr = E_FAIL;
  
  ULONG                     lpcbEID = 0;
  LPENTRYID          lpEID = NULL;
  ULONG                     rowCount = 0;
  ULONG                     curCount = 0;
  
  nsString           uniStr;
  
  // Get the entryid of the root PAB container
  //
  hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
  
  if (HR_FAILED( hr))
    goto exit;
  
  ulObjType = 0;
  
  // Open the root PAB container
  // This is where all the WAB contents reside
  //
  hr = m_lpAdrBook->OpenEntry(lpcbEID,
    (LPENTRYID)lpEID,
    NULL,
    0,
    &ulObjType,
    (LPUNKNOWN *)&lpContainer);
  
  m_lpWABObject->FreeBuffer(lpEID);
  
  lpEID = NULL;
  
  if(HR_FAILED(hr))
    goto exit;
  
  // Get a contents table of all the contents in the
  // WABs root container
  //
  hr = lpContainer->GetContentsTable( 0,
    &lpAB);
  
  if(HR_FAILED(hr))
    goto exit;
  
  hr = lpAB->GetRowCount( 0, &rowCount);
  if (HR_FAILED(hr))
    rowCount = 100;
  if (rowCount == 0)
    rowCount = 1;
  
  // Order the columns in the ContentsTable to conform to the
  // ones we want - which are mainly DisplayName, EntryID and
  // ObjectType
  // The table is gauranteed to set the columns in the order 
  // requested
  //
  hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
  
  if(HR_FAILED(hr))
    goto exit;
  
  
  // Reset to the beginning of the table
  //
  hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  
  if(HR_FAILED(hr))
    goto exit;
  
  // Read all the rows of the table one by one
  //
  
  do {
    
    hr = lpAB->QueryRows(1, 0, &lpRowAB);
    
    if(HR_FAILED(hr))
      break;
    
    if(lpRowAB)
    {
      cNumRows = lpRowAB->cRows;
      
      if (cNumRows)
      {
        LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
        LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
        ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
        
        // There are 2 kinds of objects - the MAPI_MAILUSER contact object
        // and the MAPI_DISTLIST contact object
        // For the purposes of this sample, we will only consider MAILUSER
        // objects
        //
        if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
        {
          // We will now take the entry-id of each object and cache it
          // on the listview item representing that object. This enables
          // us to uniquely identify the object later if we need to
          //
          CStrToUnicode( lpsz, uniStr);
          keepGoing = pIter->EnumUser( uniStr.get(), lpEID, cbEID);
          curCount++;
          if (pDone) {
            *pDone = (curCount * 100) / rowCount;
            if (*pDone > 100)
              *pDone = 100;
          }
        }
      }
      FreeProws(lpRowAB );         
    }
    
    
  } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) )  ;
  
  hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  
  if(HR_FAILED(hr))
    goto exit;
  
  // Read all the rows of the table one by one
  //
  keepGoing = TRUE;
  do {
    
    hr = lpAB->QueryRows(1, 0, &lpRowAB);
    
    if(HR_FAILED(hr))
      break;
    
    if(lpRowAB)
    {
      cNumRows = lpRowAB->cRows;
      
      if (cNumRows)
      {
        LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
        LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
        ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
        
        // There are 2 kinds of objects - the MAPI_MAILUSER contact object
        // and the MAPI_DISTLIST contact object
        // For the purposes of this sample, we will only consider MAILUSER
        // objects
        //
        if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_DISTLIST)
        {
          LPABCONT distListContainer = NULL;
          // We will now take the entry-id of each object and cache it
          // on the listview item representing that object. This enables
          // us to uniquely identify the object later if we need to
          //
          hr = m_lpAdrBook->OpenEntry(cbEID, lpEID, NULL,
            0,&ulObjType,(LPUNKNOWN *)&distListContainer);
          
          LPMAPITABLE              distListTable =  NULL;


          // Get a contents table of the dist list
          //
          hr = distListContainer->GetContentsTable( 0, &distListTable);
          if (lpAB) 
          {
            hr = distListTable->GetRowCount( 0, &rowCount);
            if (HR_FAILED(hr))
              rowCount = 100;
            if (rowCount == 0)
              rowCount = 1;
  
            // Order the columns in the ContentsTable to conform to the
            // ones we want - which are mainly DisplayName, EntryID and
            // ObjectType
            // The table is gauranteed to set the columns in the order 
            // requested
            //
            hr = distListTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
            CStrToUnicode( lpsz, uniStr);
            keepGoing = pIter->EnumList( uniStr.get(), lpEID, cbEID, distListTable);
            curCount++;
            if (pDone) {
              *pDone = (curCount * 100) / rowCount;
              if (*pDone > 100)
                *pDone = 100;
            }
          }
          if (distListContainer)
            distListContainer->Release();
          if (distListTable)
            distListTable->Release();
        }
      }
      FreeProws(lpRowAB );         
    }
    
  } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) )  ;
  
  
exit:
  
  if ( lpContainer )
    lpContainer->Release();
  
  if ( lpAB )
    lpAB->Release();
  
  return hr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool CWAB::Loaded ( void  ) [inline]

Definition at line 63 of file WabObject.h.

{ return( m_bInitialized);}

Here is the caller graph for this function:

void CWAB::ReleaseDistList ( LPDISTLIST  pList) [inline]

Definition at line 69 of file WabObject.h.

{ if (pList) pList->Release();}
void CWAB::ReleaseUser ( LPMAILUSER  pUser) [inline]

Definition at line 71 of file WabObject.h.

{ if (pUser) pUser->Release();}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 86 of file WabObject.h.

Definition at line 87 of file WabObject.h.

LPADRBOOK CWAB::m_lpAdrBook [private]

Definition at line 89 of file WabObject.h.

LPWABOPEN CWAB::m_lpfnWABOpen [private]

Definition at line 88 of file WabObject.h.

LPWABOBJECT CWAB::m_lpWABObject [private]

Definition at line 90 of file WabObject.h.

Definition at line 84 of file WabObject.h.

Definition at line 85 of file WabObject.h.


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