home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / remote.xp / xpstatus.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  34.8 KB  |  955 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  File Name
  4. //      XPSTATUS.CPP 
  5. //
  6. //  Description
  7. //      This file implements the methods for the IMAPIStatus interface.
  8. //
  9. //  Authors
  10. //      Irving De la Cruz
  11. //      Les Thaler
  12. //
  13. //  Revision: 1.7
  14. //
  15. // Written for Microsoft Windows Developer Support
  16. // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
  17. //
  18. #include "XPWDSR.H"
  19.  
  20. // Remark this line to turn verbose tracing OFF
  21. #define DO_INFO_TRACES
  22. #ifdef DO_INFO_TRACES
  23. #define InfoTrace(a)   TraceInfoMessage(a)
  24. #else
  25. #define InfoTrace(a)   
  26. #endif // DO_INFO_TRACES
  27.  
  28. ///////////////////////////////////////////////////////////////////////////////
  29. //    CMAPIStatus::CMAPIStatus()
  30. //
  31. //    Parameters
  32. //      pLogon          Parent logon session for this IMAPIStatus object
  33. //      pProfSectObj    Profile section object for this provider
  34. //
  35. //    Purpose
  36. //      Constructor of the object. Parameters are passed to initialize the
  37. //      data members with the appropiate values.
  38. //
  39. //    Return Value
  40. //      None
  41. //
  42. CMAPIStatus::CMAPIStatus (CXPLogon * pLogon, LPPROFSECT pProfSectObj)
  43.  
  44. {
  45.     InfoTrace ("CMAPIStatus: Constructor called");
  46.     m_cRef          = 1;
  47.     m_pLogon        = pLogon; // Don't AddRef() this object (to avoid circular reference)
  48.     m_pHeaderFolder = NULL;
  49.     m_pProfSectObj  = pProfSectObj;
  50.     if (m_pProfSectObj)
  51.     {
  52.         m_pProfSectObj->AddRef();
  53.     }
  54. }
  55.  
  56. ///////////////////////////////////////////////////////////////////////////////
  57. //    CMAPIStatus::~CMAPIStatus()
  58. //
  59. //    Parameters
  60. //      None
  61. //
  62. //    Purpose
  63. //      Destructor of CMAPIStatus
  64. //
  65. //    Return Value
  66. //      None
  67. //
  68. CMAPIStatus::~CMAPIStatus ()
  69. {
  70.     InfoTrace ("CMAPIStatus: Destructor called");
  71.     if (m_pProfSectObj)
  72.     {
  73.         m_pProfSectObj->Release();
  74.     }
  75.     if (m_pHeaderFolder && m_pHeaderFolder->m_cRef)
  76.     {
  77.         m_pHeaderFolder->Release();     // Release our instance of the folder
  78.     }
  79.     m_pHeaderFolder = NULL;
  80. }
  81.  
  82. ///////////////////////////////////////////////////////////////////////////////
  83. //    CMAPIStatus::QueryInterface()
  84. //
  85. //    Parameters
  86. //      { Refer to OLE Documentation on this method }
  87. //
  88. //    Purpose
  89. //      Returns a pointer to a interface requested if the interface is 
  90. //      supported and implemented by this object. If it is not supported, it 
  91. //      returns NULL
  92. //
  93. //    Return Value
  94. //      An HRESULT
  95. //
  96. STDMETHODIMP CMAPIStatus::QueryInterface (REFIID riid, LPVOID * ppvObj)
  97. {
  98.     HRESULT hResult = S_OK;
  99.     // OLE requires NULLing parameter
  100.     *ppvObj = NULL;
  101.     // If this is one of the supported IIDs return an interface pointer to it
  102.     if (riid == IID_IMAPIStatus || riid == IID_IMAPIProp || riid == IID_IUnknown)
  103.     {
  104.         *ppvObj = (LPVOID)this;
  105.         AddRef();
  106.     }
  107.     else
  108.     {
  109.         // The status object of a remote transport can return a folder object,
  110.         // if the IID requested is for a MAPI folder object. The object returned in
  111.         // this case is the folder that has the headers of messages available in
  112.         // the remote host. A remote client viewer application requests operations
  113.         // on those message by modifying the PR_MESSAGE_STATUS property in each
  114.         // row of the contents table of this folder and later calls the
  115.         // ValidateState method of this IMAPIStatus object
  116.         if (riid == IID_IMAPIFolder)
  117.         {
  118.             // If we already have a folder around, return the same object to the caller.
  119.             if (!m_pHeaderFolder)
  120.             {
  121.                 m_pHeaderFolder = new CMAPIFolder (this, m_pLogon);
  122.                 if (!m_pHeaderFolder)
  123.                 {
  124.                     TraceMessage("CMAPIStatus::QueryInterface: Unable to create remote viewer folder");
  125.                     hResult = E_OUTOFMEMORY;
  126.                 }
  127.             }
  128.             if (!hResult)
  129.             {
  130.                 m_pHeaderFolder->AddRef();      // One for the caller requesting it
  131.                 *ppvObj = (LPVOID)m_pHeaderFolder;
  132.             }
  133.         }
  134.         else
  135.         {
  136.             // This object does not support the interface requested
  137.             hResult = E_NOINTERFACE;
  138.         }
  139.     }
  140.     return hResult;
  141. }    
  142.  
  143. ///////////////////////////////////////////////////////////////////////////////
  144. // IMAPIProp virtual member functions
  145. //
  146.  
  147. ///////////////////////////////////////////////////////////////////////////////
  148. //    CMAPIStatus::GetLastError()
  149. //
  150. //    Parameters
  151. //      { Refer to MAPI Documentation on this method }
  152. //
  153. //    Purpose
  154. //      Called by a client to get a string from the transport describing the
  155. //      last error that occurred.
  156. //
  157. //    Return Value
  158. //      An HRESULT
  159. //
  160. STDMETHODIMP CMAPIStatus::GetLastError (HRESULT         hError,
  161.                                         ULONG           ulFlags,
  162.                                         LPMAPIERROR *   ppMAPIError)
  163. {
  164.     InfoTrace ("CMAPIStatus::GetLastError method called");
  165.     Validate_IMAPIProp_GetLastError (this, hError, ulFlags, ppMAPIError);
  166.     // Allocate and fill a MAPIERROR structure with the error passed in.
  167.     // Use the common helper function GetMAPIError
  168.     return GetMAPIError (ppMAPIError, ulFlags, hError, m_pLogon->GetInstance());
  169. }
  170.  
  171. ///////////////////////////////////////////////////////////////////////////////
  172. //    CMAPIStatus::SaveChanges()
  173. //
  174. //    Parameters
  175. //      { Refer to MAPI Documentation on this method }
  176. //
  177. //    Purpose
  178. //      Place holder. Replace this function with actual implementation 
  179. //      if needed.
  180. //
  181. //    Return Value
  182. //      S_OK always.
  183. //
  184. STDMETHODIMP CMAPIStatus::SaveChanges (ULONG ulFlags)
  185. {
  186.     InfoTrace ("CMAPIStatus::SaveChanges method called");
  187.     Validate_IMAPIProp_SaveChanges (this, ulFlags);
  188.     return S_OK;
  189. }
  190.  
  191. ///////////////////////////////////////////////////////////////////////////////
  192. //    CMAPIStatus::GetProps()
  193. //
  194. //    Parameters
  195. //      { Refer to MAPI Documentation on this method }
  196. //
  197. //    Purpose
  198. //      The caller specifies an array of tags, and this method returns a
  199. //      property value array for thoses tag, if found. The tags are the ones
  200. //      available in the transport ID array
  201. //
  202. //    Return Value
  203. //      An HRESULT
  204. //
  205. STDMETHODIMP CMAPIStatus::GetProps (LPSPropTagArray     pTags,
  206.                                     ULONG               ulFlags,
  207.                                     ULONG *             pcValues,
  208.                                     LPSPropValue *      ppPropArray)
  209. {
  210.     InfoTrace ("CMAPIStatus::GetProps method called");
  211.     Validate_IMAPIProp_GetProps (this, pTags, ulFlags, pcValues, ppPropArray);
  212.     
  213.     #ifdef DO_INFO_TRACES
  214.     if (!pTags)
  215.     {
  216.         TraceInfoMessage ("CMAPIStatus::GetProps: All properties requested");
  217.     }
  218.     else
  219.     {
  220.         TraceMessage ("CMAPIStatus::GetProps Properties requested..."); for (ULONG j=0; j<pTags->cValues; j++) { TraceProp (pTags->aulPropTag[j]); }
  221.     }
  222.     #endif // DO_INFO_TRACES
  223.  
  224.     BOOL fGetAllProps = pTags ? FALSE : TRUE;
  225.     if (!pTags)
  226.     {
  227.         pTags = (LPSPropTagArray)&sptStatusObj;
  228.     }
  229.     
  230.     *pcValues = pTags->cValues;
  231.     HRESULT hResult = gpfnAllocateBuffer (sizeof(SPropValue)*(*pcValues), (LPVOID *)ppPropArray);
  232.     if (hResult)
  233.     {
  234.         TraceResult ("CMAPIStatus::GetProps: Memory allocation failed", hResult);
  235.         return hResult;
  236.     }
  237.     if (fGetAllProps)
  238.     {
  239.         for (ULONG i=0; i<sptStatusObj.cValues; i++)
  240.         {
  241.             (*ppPropArray)[i].ulPropTag = sptStatusObj.aulPropTag[i];
  242.         }
  243.     }
  244.     else
  245.     {
  246.         // A client of the IMAPIProp::GetProps() method can pass PT_UNSPECIFIED in the
  247.         // tag of a property. Is the provider's responsiblity to return
  248.         // the proper type of the property.
  249.         for (ULONG k=0; k<pTags->cValues; k++)
  250.         {
  251.             for (ULONG i=0; i<sptStatusObj.cValues; i++)
  252.             {
  253.                 if (PROP_ID(pTags->aulPropTag[k]) == PROP_ID(sptStatusObj.aulPropTag[i]))
  254.                 {
  255.                     (*ppPropArray)[k].ulPropTag = sptStatusObj.aulPropTag[i];
  256.                 }
  257.                 else
  258.                 {
  259.                     (*ppPropArray)[k].ulPropTag = pTags->aulPropTag[k];
  260.                 }
  261.             }
  262.         }
  263.     }
  264.  
  265.     TCHAR szBuffer[128];
  266.     BOOL fGotErrors = FALSE;    
  267.     LPVOID pSrc, pDst;
  268.     ULONG cbSize;
  269.     for (ULONG i=0; i<*pcValues; i++)
  270.     {
  271.         hResult = S_OK;
  272.         switch ((*ppPropArray)[i].ulPropTag)
  273.         {
  274.             case PR_NULL :
  275.                 (*ppPropArray)[i].Value.err = S_OK;
  276.                 break;
  277.             case PR_RESOURCE_METHODS :
  278.                 (*ppPropArray)[i].Value.l = STATUS_SETTINGS_DIALOG |
  279.                                             STATUS_FLUSH_QUEUES |
  280.                                             STATUS_VALIDATE_STATE |
  281.                                             STATUS_CHANGE_PASSWORD;
  282.                 break;
  283.             case PR_RESOURCE_TYPE :
  284.                 (*ppPropArray)[i].Value.l = MAPI_TRANSPORT_PROVIDER;
  285.                 break;
  286.             case PR_RESOURCE_FLAGS :
  287.                 hResult = E_FAIL;
  288.                 if (m_pProfSectObj)
  289.                 {
  290.                     LPSPropValue pResFlags;
  291.                     SPropTagArray sptResFlags = { 1, { PR_RESOURCE_FLAGS } };
  292.                     ULONG cValues;
  293.                     hResult = m_pProfSectObj->GetProps (&sptResFlags, fMapiUnicode, &cValues, &pResFlags);
  294.                     if (SUCCEEDED(hResult))
  295.                     {
  296.                         if (PR_RESOURCE_FLAGS == pResFlags->ulPropTag)
  297.                         {
  298.                             (*ppPropArray)[i].Value.l = pResFlags->Value.l;
  299.                         }
  300.                         gpfnFreeBuffer (pResFlags);
  301.                     }
  302.                 }
  303.                 if (hResult)
  304.                 {
  305.                     (*ppPropArray)[i].Value.l = STATUS_PRIMARY_IDENTITY;
  306.                     hResult = S_OK;
  307.                 }
  308.                 break;
  309.             case PR_DISPLAY_NAME :
  310.                 wsprintf (szBuffer,
  311.                           TEXT("%s (%s)"),
  312.                           TRANSPORT_DISPLAY_NAME_STRING,
  313.                           m_pLogon->GetServerName());
  314.                 pSrc = (LPVOID)szBuffer;
  315.                 break;
  316.             case PR_PROVIDER_DLL_NAME :
  317.                 pSrc = (LPVOID)TRANSPORT_DLL_NAME_STRING;
  318.                 break;
  319.             case PR_PROVIDER_DISPLAY :
  320.                 pSrc = (LPVOID)TRANSPORT_DISPLAY_NAME_STRING;
  321.                 break;
  322.             case PR_IDENTITY_DISPLAY :
  323.                 pSrc = (LPVOID)m_pLogon->m_pIdentityProps[XPID_NAME].Value.LPSZ;
  324.                 break;
  325.             case PR_IDENTITY_ENTRYID :
  326.                 cbSize = m_pLogon->m_pIdentityProps[XPID_EID].Value.bin.cb;
  327.                 pSrc = (LPVOID)m_pLogon->m_pIdentityProps[XPID_EID].Value.bin.lpb;
  328.                 break;
  329.             case PR_IDENTITY_SEARCH_KEY :
  330.                 cbSize = m_pLogon->m_pIdentityProps[XPID_SEARCH_KEY].Value.bin.cb;
  331.                 pSrc = (LPVOID)m_pLogon->m_pIdentityProps[XPID_SEARCH_KEY].Value.bin.lpb;
  332.                 break;
  333.             case PR_STATUS_CODE :
  334.                 (*ppPropArray)[i].Value.l = (long)m_pLogon->GetTransportStatusCode();
  335.                 break;
  336.             case PR_STATUS_STRING :
  337.                 szBuffer[0] = 0;
  338.                 m_pLogon->LoadStatusString (szBuffer, sizeof(szBuffer) - 1);
  339.                 pSrc = (LPVOID)szBuffer;
  340.                 break;
  341.             case PR_CURRENT_VERSION :
  342.                 (*ppPropArray)[i].Value.li.LowPart = TRANSPORT_VERSION_MAJOR;
  343.                 (*ppPropArray)[i].Value.li.HighPart = TRANSPORT_VERSION_MINOR;
  344.                 break;
  345.             case PR_OBJECT_TYPE :
  346.                 (*ppPropArray)[i].Value.l = MAPI_STATUS;
  347.                 break;
  348.             default:
  349.                 hResult = MAPI_E_NOT_FOUND;
  350.                 #ifdef DO_INFO_TRACES
  351.                 TraceRaw ("CMAPIStatus::GetProps: Not Found - "); TraceProp ((*ppPropArray)[i].ulPropTag);
  352.                 #endif // #DO_INFO_TRACES
  353.                 break;
  354.         }
  355.         if (!hResult && 
  356.             (PROP_TYPE((*ppPropArray)[i].ulPropTag) == PT_BINARY ||
  357.              PROP_TYPE((*ppPropArray)[i].ulPropTag) == PT_TSTRING))
  358.         {
  359.             if (PROP_TYPE((*ppPropArray)[i].ulPropTag) == PT_TSTRING)
  360.             {
  361.                 cbSize = Cbtszsize ((LPTSTR)pSrc);
  362.             }
  363.             hResult = gpfnAllocateMore (cbSize, *ppPropArray, &pDst);
  364.             if (!hResult)
  365.             {
  366.                 CopyMemory (pDst, pSrc, cbSize);
  367.                 if (PROP_TYPE((*ppPropArray)[i].ulPropTag) == PT_BINARY)
  368.                 {
  369.                     (*ppPropArray)[i].Value.bin.cb  = cbSize;
  370.                     (*ppPropArray)[i].Value.bin.lpb = (LPBYTE)pDst;
  371.                 }
  372.                 else
  373.                 {
  374.                     (*ppPropArray)[i].Value.LPSZ = (LPTSTR)pDst;
  375.                 }
  376.             }
  377.         }
  378.         if (hResult)
  379.         {
  380.             (*ppPropArray)[i].ulPropTag = PROP_TAG(PT_ERROR, PROP_ID((*ppPropArray)[i].ulPropTag));
  381.             (*ppPropArray)[i].Value.err = hResult;
  382.             fGotErrors = TRUE;
  383.         }
  384.     }
  385.     if (fGotErrors)
  386.     {
  387.         hResult = MAPI_W_ERRORS_RETURNED;
  388.     }
  389.     return hResult;
  390. }
  391.  
  392. ///////////////////////////////////////////////////////////////////////////////
  393. //    CMAPIStatus::GetPropList()
  394. //
  395. //    Parameters
  396. //      { Refer to MAPI Documentation on this method }
  397. //
  398. //    Purpose
  399. //      Returns a tag array with the properties in the status row of this 
  400. //      transport. The caller is responsible for freeing the memory allocated
  401. //      for the tag array.
  402. //
  403. //    Return Value
  404. //      An HRESULT
  405. //
  406. STDMETHODIMP CMAPIStatus::GetPropList (ULONG                ulFlags,
  407.                                        LPSPropTagArray *    ppPropTagArray)
  408. {
  409.     InfoTrace ("CMAPIStatus::GetPropList method called");
  410.     Validate_IMAPIProp_GetPropList (this, ulFlags, ppPropTagArray);
  411.  
  412.     ULONG cbTagsArraySize = CbNewSPropTagArray(NUM_STATUS_OBJECT_PROPS);
  413.     // Allocate the required amount of memory
  414.     HRESULT hResult = gpfnAllocateBuffer (cbTagsArraySize, (LPVOID *)ppPropTagArray);
  415.     TraceResult ("CMAPIStatus::GetPropList: Memory allocation failed", hResult);
  416.     if (!hResult)
  417.     {
  418.         // Copy the contents of our property tag array into the buffer
  419.         CopyMemory (*ppPropTagArray, &sptStatusObj, cbTagsArraySize);
  420.     }
  421.     return hResult;
  422. }
  423.  
  424. ///////////////////////////////////////////////////////////////////////////////
  425. //    CMAPIStatus::OpenProperty()
  426. //
  427. //    Parameters
  428. //      { Refer to MAPI Documentation on this method }
  429. //
  430. //    Purpose
  431. //      Place holder. Replace this function with actual implementation 
  432. //      if needed.
  433. //
  434. //    Return Value
  435. //      MAPI_E_NO_SUPPORT always.
  436. //
  437. STDMETHODIMP CMAPIStatus::OpenProperty (ULONG           ulPropTag,
  438.                                         LPCIID          piid,
  439.                                         ULONG           ulInterfaceOptions,
  440.                                         ULONG           ulFlags,
  441.                                         LPUNKNOWN *     ppUnk)
  442. {
  443.     InfoTrace ("CMAPIStatus::OpenProperty method called");
  444.     Validate_IMAPIProp_OpenProperty (this, ulPropTag,  piid, ulInterfaceOptions, ulFlags, ppUnk);
  445.     return MAPI_E_NO_SUPPORT;
  446. }
  447.  
  448. ///////////////////////////////////////////////////////////////////////////////
  449. //    CMAPIStatus::SetProps()
  450. //
  451. //    Parameters
  452. //      { Refer to MAPI Documentation on this method }
  453. //
  454. //    Purpose
  455. //      Place holder. Replace this function with actual implementation 
  456. //      if needed.
  457. //
  458. //    Return Value
  459. //      MAPI_E_NO_SUPPORT always.
  460. //
  461. STDMETHODIMP CMAPIStatus::SetProps (ULONG                   cValues,
  462.                                     LPSPropValue            pPropArray,
  463.                                     LPSPropProblemArray *   ppProblems)
  464. {
  465.     InfoTrace ("CMAPIStatus::SetProps method called");
  466.     Validate_IMAPIProp_SetProps (this, cValues, pPropArray, ppProblems);
  467.     return MAPI_E_NO_SUPPORT;
  468. }
  469.  
  470. ///////////////////////////////////////////////////////////////////////////////
  471. //    CMAPIStatus::DeleteProps()
  472. //
  473. //    Parameters
  474. //      { Refer to MAPI Documentation on this method }
  475. //
  476. //    Purpose
  477. //      Place holder. Replace this function with actual implementation 
  478. //      if needed.
  479. //
  480. //    Return Value
  481. //      MAPI_E_NO_SUPPORT always.
  482. //
  483. STDMETHODIMP CMAPIStatus::DeleteProps (LPSPropTagArray          pPropTagArray,
  484.                                        LPSPropProblemArray *    ppProblems)
  485. {
  486.     InfoTrace ("CMAPIStatus::DeleteProps method called");
  487.     Validate_IMAPIProp_DeleteProps (this, pPropTagArray, ppProblems);
  488.     return MAPI_E_NO_SUPPORT;
  489. }
  490.  
  491. ///////////////////////////////////////////////////////////////////////////////
  492. //    CMAPIStatus::CopyTo()
  493. //
  494. //    Parameters
  495. //      { Refer to MAPI Documentation on this method }
  496. //
  497. //    Purpose
  498. //      Place holder. Replace this function with actual implementation 
  499. //      if needed.
  500. //
  501. //    Return Value
  502. //      MAPI_E_NO_SUPPORT always.
  503. //
  504. STDMETHODIMP CMAPIStatus::CopyTo (ULONG                   ciidExclude,
  505.                                   LPCIID                  rgiidExclude,
  506.                                   LPSPropTagArray         pExcludeProps,
  507.                                   ULONG                   ulUIParam,
  508.                                   LPMAPIPROGRESS          pProgress,
  509.                                   LPCIID                  pInterface,
  510.                                   LPVOID                  pDestObj,
  511.                                   ULONG                   ulFlags,
  512.                                   LPSPropProblemArray *   ppProblems)
  513. {
  514.     InfoTrace ("CMAPIStatus::CopyTo method called");
  515.     Validate_IMAPIProp_CopyTo (this,
  516.                                ciidExclude,
  517.                                rgiidExclude,
  518.                                pExcludeProps,
  519.                                ulUIParam,
  520.                                pProgress,
  521.                                pInterface,
  522.                                pDestObj,
  523.                                ulFlags,
  524.                                ppProblems);
  525.     return MAPI_E_NO_SUPPORT;
  526. }
  527.  
  528. ///////////////////////////////////////////////////////////////////////////////
  529. //    CMAPIStatus::CopyProps()
  530. //
  531. //    Parameters
  532. //      { Refer to MAPI Documentation on this method }
  533. //
  534. //    Purpose
  535. //      Place holder. Replace this function with actual implementation 
  536. //      if needed.
  537. //
  538. //    Return Value
  539. //      MAPI_E_NO_SUPPORT always.
  540. //
  541. STDMETHODIMP CMAPIStatus::CopyProps (LPSPropTagArray            pIncludeProps,
  542.                                      ULONG                      ulUIParam,
  543.                                      LPMAPIPROGRESS             pProgress,
  544.                                      LPCIID                     pInterface,
  545.                                      LPVOID                     pDestObj,
  546.                                      ULONG                      ulFlags,
  547.                                      LPSPropProblemArray *      ppProblems)
  548. {
  549.     InfoTrace ("CMAPIStatus::CopyProps method called");
  550.     Validate_IMAPIProp_CopyProps (this,
  551.                                   pIncludeProps,
  552.                                   ulUIParam,
  553.                                   pProgress,
  554.                                   pInterface,
  555.                                   pDestObj,
  556.                                   ulFlags,
  557.                                   ppProblems);
  558.     return MAPI_E_NO_SUPPORT;
  559. }
  560.  
  561. ///////////////////////////////////////////////////////////////////////////////
  562. //    CMAPIStatus::GetNamesFromIDs()
  563. //
  564. //    Parameters
  565. //      { Refer to MAPI Documentation on this method }
  566. //
  567. //    Purpose
  568. //      Place holder. Replace this function with actual implementation 
  569. //      if needed.
  570. //
  571. //    Return Value
  572. //      MAPI_E_NO_SUPPORT always.
  573. //
  574. STDMETHODIMP CMAPIStatus::GetNamesFromIDs (LPSPropTagArray *    ppPropTags,
  575.                                            LPGUID               pPropSetGuid,
  576.                                            ULONG                ulFlags,
  577.                                            ULONG *              pcPropNames,
  578.                                            LPMAPINAMEID **      pppPropNames)
  579. {
  580.     InfoTrace ("CMAPIStatus::GetNamesFromIDs method called");
  581.     Validate_IMAPIProp_GetNamesFromIDs (this,
  582.                                         ppPropTags,
  583.                                         pPropSetGuid,
  584.                                         ulFlags,
  585.                                         pcPropNames,
  586.                                         pppPropNames);
  587.     return MAPI_E_NO_SUPPORT;
  588. }
  589.  
  590. ///////////////////////////////////////////////////////////////////////////////
  591. //    CMAPIStatus::GetIDsFromNames()
  592. //
  593. //    Parameters
  594. //      { Refer to MAPI Documentation on this method }
  595. //
  596. //    Purpose
  597. //      Place holder. Replace this function with actual implementation 
  598. //      if needed.
  599. //
  600. //    Return Value
  601. //      MAPI_E_NO_SUPPORT always.
  602. //
  603. STDMETHODIMP CMAPIStatus::GetIDsFromNames (ULONG                cPropNames,
  604.                                            LPMAPINAMEID *       ppPropNames,
  605.                                            ULONG                ulFlags,
  606.                                            LPSPropTagArray *    ppPropTags)
  607. {
  608.     InfoTrace ("CMAPIStatus::GetIDsFromNames method called");
  609.     Validate_IMAPIProp_GetIDsFromNames (this,
  610.                                         cPropNames,
  611.                                         ppPropNames,
  612.                                         ulFlags,
  613.                                         ppPropTags);
  614.     return MAPI_E_NO_SUPPORT;
  615. }
  616.  
  617. ///////////////////////////////////////////////////////////////////////////////
  618. // IMAPIStatus virtual member functions implementation
  619. //
  620.  
  621. ///////////////////////////////////////////////////////////////////////////////
  622. //    CMAPIStatus::ValidateState()
  623. //
  624. //    Parameters
  625. //      { Refer to MAPI Documentation on this method }
  626. //
  627. //    Purpose
  628. //      This method is called by the REMOTE viewer UI to start the remote
  629. //      processing. We check the ulFlags bits to see what operation is being
  630. //      requested and do it. All the operation of this transport are
  631. //      ASYNCHRONOUS meaning, that the call returns to the client before the
  632. //      action is truly completed.
  633. //      To control this, we dynamically change PR_REMOTE_VALIDATE_OK on the
  634. //      status row so that the client calls us at intervals to check if we
  635. //      finished or not.
  636. //      When an action is requested, we change the internal state of the
  637. //      transport and we tell the spooler to FLUSH us, so that it can better
  638. //      manage interaction with multiple transport.
  639. //      This is the recommended way for remote transports to connect using
  640. //      shared resources such as COM port. In this transport, we do it this
  641. //      way for purposes of demonstration of how it should be done.
  642. //
  643. //    Return Value
  644. //      An HRESULT
  645. //
  646. STDMETHODIMP CMAPIStatus::ValidateState (ULONG ulUIParam, ULONG ulFlags)
  647. {   
  648.     InfoTrace ("CMAPIStatus::ValidateState method called");
  649.     Validate_IMAPIStatus_ValidateState (this, ulUIParam, ulFlags);
  650.     
  651.     // We only support this flags
  652.     if (ulFlags & ~(SHOW_XP_SESSION_UI |
  653.                     REFRESH_XP_HEADER_CACHE |
  654.                     PROCESS_XP_HEADER_CACHE |
  655.                     FORCE_XP_CONNECT |
  656.                     FORCE_XP_DISCONNECT |
  657.                     ABORT_XP_HEADER_OPERATION))
  658.     {
  659.         return MAPI_E_UNKNOWN_FLAGS;
  660.     }
  661.  
  662.     if (ulFlags & SHOW_XP_SESSION_UI)  
  663.     {
  664.         // We don't implement UI for processing the headers
  665.         return MAPI_E_NO_SUPPORT;
  666.     }
  667.     if (ulFlags & ABORT_XP_HEADER_OPERATION)
  668.     {
  669.         // If we are called to cancel an opertaion, if we can't cancel we will set a
  670.         // flag so that when the current operation finishes, we won't continue.
  671.         if (HEADERS_AND_DOWNLOAD == m_pLogon->GetTransportState())
  672.         {
  673.             m_pLogon->m_fCancelPending = TRUE;
  674.             return MAPI_E_BUSY;
  675.         }
  676.         // The cancel occured while we where flushing the inbound queue. We can
  677.         // cancel this by telling the spooler to stop flushing us. Note that at
  678.         // this point ALL the message have been downloaded to temporary files
  679.         // and are simply pending to be placed in the default inbox
  680.         if (DOWNLOADING_MESSAGES & m_pLogon->GetTransportStatusCode())
  681.         {
  682.             m_pLogon->RemoveStatusBits (DOWNLOADING_MESSAGES); // Tell the spooler to take us off from inbound flush
  683.             m_pLogon->AddStatusBits (STATUS_OFFLINE); // The transport is now OFF line
  684.             m_pLogon->UpdateStatus (TRUE, TRUE); // Set PR_REMOTE_VALIDATE_OK to TRUE
  685.             m_pLogon->SetTransportState (WAITING); // The transport is now IDLE
  686.         }
  687.         return S_OK;
  688.     }
  689.     HRESULT hResult = S_OK;
  690.     // The request is to process remote messages and upload any deferred messages
  691.     if (ulFlags & PROCESS_XP_HEADER_CACHE)
  692.     {
  693.         if (PENDING_RETURN_CODE == m_pLogon->GetTransportState())
  694.         {
  695.             // The transport had finished a request and is ready to return the results error (if any)
  696.             m_pLogon->SetTransportState (WAITING);
  697.             m_pLogon->UpdateStatus (TRUE, FALSE);
  698.             m_pLogon->UpdateProgress (-1, REMOTE_ACTION_IDLE); // Reset PR_REMOTE_PROGRESS_TEXT
  699.             return m_pLogon->m_hRemoteActionErr;
  700.         }
  701.         if (HEADERS_AND_DOWNLOAD == m_pLogon->GetTransportState())
  702.         {
  703.             // We are busy, poll me later
  704.             return MAPI_E_BUSY;
  705.         }
  706.  
  707.         // The MS Exchange viewer wants a remote transport to update the headers
  708.         // during this call with this flag, so we must update the headers.
  709.         // The MS Exchange remote viewer does not call this method with
  710.         // REFRESH_XP_HEADER_CACHE alone, any longer.
  711.         ulFlags |= REFRESH_XP_HEADER_CACHE;
  712.         m_pLogon->m_fCancelPending = FALSE;
  713.     }
  714.     // The request is to get remote headers
  715.     if (!hResult && (ulFlags & REFRESH_XP_HEADER_CACHE))
  716.     {
  717.         if (PENDING_RETURN_CODE == m_pLogon->GetTransportState())
  718.         {
  719.             m_pLogon->SetTransportState (WAITING);
  720.             m_pLogon->UpdateStatus (TRUE, FALSE);
  721.             m_pLogon->UpdateProgress (-1, REMOTE_ACTION_IDLE); // Reset PR_REMOTE_PROGRESS_TEXT
  722.             return m_pLogon->m_hRemoteActionErr;
  723.         }
  724.         if (HEADERS_AND_DOWNLOAD == m_pLogon->GetTransportState())
  725.         {
  726.             return MAPI_E_BUSY;
  727.         }
  728.         m_pLogon->m_fCancelPending = FALSE;
  729.  
  730.         // Fire up a request to the spooler to flush the INBOUD logic
  731.         // which in turn will also get new headers.
  732.         m_pLogon->SetTransportState (HEADERS_AND_DOWNLOAD);
  733.         m_pLogon->AddStatusBits (DOWNLOADING_MESSAGES);
  734.         m_pLogon->RemoveStatusBits (STATUS_OFFLINE);
  735.         m_pLogon->UpdateStatus (TRUE, FALSE);
  736.         return MAPI_E_BUSY;
  737.     }
  738.     return hResult;
  739. }
  740.  
  741. ///////////////////////////////////////////////////////////////////////////////
  742. //    CMAPIStatus::SettingsDialog()
  743. //
  744. //    Parameters
  745. //      { Refer to MAPI Documentation on this method }
  746. //
  747. //    Purpose
  748. //      Called by a client to display the configuration settings, if any, for
  749. //      a particular transport. This method could be used to display the 
  750. //      current setting in a READ-ONLY mode
  751. //
  752. //    Return Value
  753. //      An HRESULT
  754. //
  755. STDMETHODIMP CMAPIStatus::SettingsDialog (ULONG ulUIParam, ULONG ulFlags)
  756. {
  757.     InfoTrace ("CMAPIStatus::SettingsDialog method called");
  758.     Validate_IMAPIStatus_SettingsDialog (this, ulUIParam, ulFlags);
  759.     
  760.     ULONG ulPropCount;
  761.     LPSPropValue pProps = NULL;
  762.     LPPROFSECT pProfileObj = NULL;
  763.     HRESULT hResult = S_OK;
  764.     BOOL fChangeAccount = FALSE;
  765.     TCHAR szOldMailboxName[MAX_ALIAS_SIZE+1], szOldServer[MAX_STRING_SIZE+1];
  766.     CFGDLG CfgDialog = { 0 };
  767.  
  768.     PrivInitialize3DCtl (m_pLogon->GetInstance());
  769.     DWORD dwWait = WaitForSingleObject (m_pLogon->m_hUIMutex, 1000); // Wait for the MUTEX for 1 second
  770.     if (WAIT_TIMEOUT == dwWait)
  771.     {
  772.         PrivateMessageBox (IDS_MSG_CONFIG_UI_IN_USE, (HWND)ulUIParam);
  773.         PrivUninitialize3DCtl (m_pLogon->GetInstance());
  774.         return MAPI_E_BUSY;
  775.     }
  776.  
  777.     // Open the profile for our provider and get what ever is set there
  778.     hResult = OpenServiceProfileSection (m_pLogon->m_pSupObj, &pProfileObj, gpfnFreeBuffer);
  779.     if (hResult)
  780.     {
  781.         TraceResult ("CMAPIStatus::SettingsDialog: Failed to open the profile section", hResult);
  782.         goto ErrorExit;
  783.     }
  784.     
  785.     hResult = pProfileObj->GetProps ((LPSPropTagArray)&sptLogonProps,
  786.                                      fMapiUnicode,
  787.                                      &ulPropCount,
  788.                                      &pProps);
  789.     if (FAILED(hResult))
  790.     {
  791.         TraceResult ("CMAPIStatus::SettingsDialog: Failed to get profile section properties", hResult);
  792.         goto ErrorExit;
  793.     }
  794.  
  795.     lstrcpy (szOldMailboxName, pProps[MAILBOX_NAME].Value.LPSZ);
  796.     lstrcpy (szOldServer, pProps[SERVER_NAME].Value.LPSZ);
  797.  
  798.     // Fill in the logon UI structure
  799.     CfgDialog.hInst   = m_pLogon->GetInstance();
  800.     CfgDialog.hWnd    = (HWND)ulUIParam;
  801.     CfgDialog.ppProps = &pProps;
  802.     CfgDialog.pSupObj = m_pLogon->m_pSupObj;
  803.     CfgDialog.ulFlags = ulFlags;
  804.  
  805. ShowPropsAgain:
  806.     hResult = DoLogonDlg (&CfgDialog);
  807.     // If the dialog was displayed READ-only, we don't need to verify
  808.     // anything because the user didn't change anything and we are
  809.     // still runnig with the logon settings of the session.
  810.     if (hResult || (ulFlags & UI_READONLY))
  811.     {
  812.         goto ErrorExit;
  813.     }
  814.     if (!PingRemoteServer ((HWND)ulUIParam, pProps))
  815.     {
  816.         goto ShowPropsAgain;
  817.     }
  818.  
  819.     // We don't need to set the header file name back into the profile.
  820.     hResult = pProfileObj->SetProps (NUM_LOGON_PROPERTIES, pProps, NULL);
  821.     if (hResult)
  822.     {
  823.         TraceResult ("CMAPIStatus::SetttingsDialog: Failed to save the properties back into the profile", hResult);
  824.         goto ErrorExit;
  825.     }
  826.     if (lstrcmpi (szOldMailboxName, pProps[SERVER_NAME].Value.LPSZ))
  827.     {
  828.         m_pLogon->SetServerName (pProps[SERVER_NAME].Value.LPSZ);
  829.         fChangeAccount = TRUE;
  830.     }
  831.     // If the configuration changed, we need to change the download directory
  832.     // which is based on the mailbox name.
  833.     if (PR_SMP_MAILBOX_NAME == pProps[MAILBOX_NAME].ulPropTag &&
  834.         lstrcmpi (szOldMailboxName, pProps[MAILBOX_NAME].Value.LPSZ))
  835.     {
  836.         TCHAR szTmpDir[_MAX_PATH], szDownloadDir[_MAX_PATH];
  837.         GetTempPath (_MAX_PATH, szTmpDir);
  838.         lstrcat (szTmpDir, WINDS_DATA_DIRECTORY);
  839.         // Remove the download directory for the old mailbox
  840.         wsprintf (szDownloadDir, WINDS_DOWNLOAD_DIR_NAME_FORMAT, szTmpDir, szOldMailboxName);
  841.         RemoveDirectory (szDownloadDir);
  842.         // Create the download directory for the new mailbox
  843.         wsprintf (szDownloadDir, WINDS_DOWNLOAD_DIR_NAME_FORMAT, szTmpDir, pProps[MAILBOX_NAME].Value.LPSZ);
  844.         CreateDirectory (szDownloadDir, NULL);
  845.         fChangeAccount = TRUE;
  846.     }
  847.     if (fChangeAccount)
  848.     {
  849.         m_pLogon->SetAccountProps (pProps[MAILBOX_NAME].Value.LPSZ,
  850.                                    (DWORD)pProps[MAILBOX_ID].Value.l,
  851.                                    pProps[USER_NAME].Value.LPSZ,
  852.                                    pProps[PASSWORD].Value.LPSZ);
  853.     }
  854.  
  855.     // Reflect the new changes in the status row.
  856.     m_pLogon->InitializeStatusRow (STATUSROW_UPDATE);
  857.  
  858.     // If the user changed the upload time, reset the upload timer.
  859.     if (m_pLogon->SetUploadTime (pProps[UPLOAD_TIME].Value.ft))
  860.     {
  861.         m_pLogon->StopUploadTimer();
  862.         m_pLogon->InitializeTimer();
  863.         m_pLogon->StartUploadTimer();
  864.     }
  865.     
  866.  
  867. ErrorExit:
  868.     if (pProfileObj)
  869.     {
  870.         pProfileObj->Release();
  871.     }
  872.     gpfnFreeBuffer (pProps);
  873.     PrivUninitialize3DCtl (m_pLogon->GetInstance());
  874.     ReleaseMutex (m_pLogon->m_hUIMutex);
  875.     return hResult;
  876. }
  877.  
  878. ///////////////////////////////////////////////////////////////////////////////
  879. //    CMAPIStatus::ChangePassword()
  880. //
  881. //    Parameters
  882. //      { Refer to MAPI Documentation on this method }
  883. //
  884. //    Purpose
  885. //      Changes the password for the mailbox the service is logged in.
  886. //
  887. //    Return Value
  888. //      An HRESULT
  889. //
  890. STDMETHODIMP CMAPIStatus::ChangePassword (LPTSTR    pszOldPass,
  891.                                           LPTSTR    pszNewPass,
  892.                                           ULONG     ulFlags)
  893. {
  894.     InfoTrace ("CMAPIStatus::ChangePassword method called");
  895.     Validate_IMAPIStatus_ChangePassword (this, pszOldPass, pszNewPass, ulFlags);
  896.     HRESULT hResult = ChangeMBServerPassword (m_pLogon->GetServerName(),
  897.                                               m_pLogon->GetAccountName(),
  898.                                               pszOldPass,
  899.                                               pszNewPass);
  900.     if (hResult)
  901.     {
  902.         TraceResult ("CMAPIStatus::ChangePassword", hResult);
  903.         if (HRESULT_FROM_WIN32 (ERROR_INVALID_PASSWORD) == hResult)
  904.         {
  905.             hResult = E_ACCESSDENIED;
  906.         }
  907.     }
  908.     return hResult;
  909. }
  910.  
  911. ///////////////////////////////////////////////////////////////////////////////
  912. //    CMAPIStatus::FlushQueues()
  913. //
  914. //    Parameters
  915. //      { Refer to MAPI Documentation on this method }
  916. //
  917. //    Purpose
  918. //      Stub function that calls the IXPLogon object for this status object
  919. //      to actually flush any deferred messages.
  920. //      This only flushes messages deferred for delivery. It does not
  921. //      downloads any messages from the server.
  922. //
  923. //    Return Value
  924. //      S_OK always
  925. //
  926. STDMETHODIMP CMAPIStatus::FlushQueues (ULONG        ulUIParam,
  927.                                        ULONG        cbTargetTransport,
  928.                                        LPENTRYID    pTargetTransport,
  929.                                        ULONG        ulFlags)
  930. {
  931.     InfoTrace ("CMAPIStatus::FlushQueues method called");
  932.     Validate_IMAPIStatus_FlushQueues (this,
  933.                                       ulUIParam,
  934.                                       cbTargetTransport,
  935.                                       pTargetTransport,
  936.                                       ulFlags);
  937.     DWORD dwFlushBits = 0;
  938.     if (ulFlags & FLUSH_UPLOAD)
  939.     {
  940.         dwFlushBits |= UPLOADING_MESSAGES;
  941.     }
  942.     if (ulFlags & FLUSH_DOWNLOAD)
  943.     {
  944.         dwFlushBits |= DOWNLOADING_MESSAGES;
  945.     }
  946.     if (dwFlushBits)
  947.     {
  948.         m_pLogon->AddStatusBits (dwFlushBits);
  949.         m_pLogon->UpdateStatus();
  950.     }
  951.     return S_OK;
  952. }
  953.  
  954. // End of File for XPSTATUS.CPP
  955.