Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.2 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: dcontext.cpp
  5. //
  6. // Description: Implementation of delivery context class.
  7. //
  8. // Author: mikeswa
  9. //
  10. // Copyright (C) 1997 Microsoft Corporation
  11. //
  12. //-----------------------------------------------------------------------------
  13. #include "aqprecmp.h"
  14. #include "dcontext.h"
  15. CDeliveryContext::CDeliveryContext()
  16. {
  17. m_dwSignature = DELIVERY_CONTEXT_FREE;
  18. m_pmsgref = NULL;
  19. m_pmbmap = NULL;
  20. m_cRecips = 0;
  21. m_rgdwRecips = NULL;
  22. m_pdmrq = NULL;
  23. }
  24. void CDeliveryContext::Recycle()
  25. {
  26. if (m_pmsgref)
  27. m_pmsgref->Release();
  28. if (m_pmbmap)
  29. delete m_pmbmap;
  30. if (m_rgdwRecips)
  31. FreePv(m_rgdwRecips);
  32. if (m_pdmrq)
  33. m_pdmrq->Release();
  34. m_dwSignature = DELIVERY_CONTEXT_FREE;
  35. m_pmsgref = NULL;
  36. m_pmbmap = NULL;
  37. m_cRecips = 0;
  38. m_rgdwRecips = NULL;
  39. m_pdmrq = NULL;
  40. }
  41. //---[ CDeliveryContext::CDeliveryContext ]------------------------------------
  42. //
  43. //
  44. // Description:
  45. // Constructor for CDeliveryContext. Should be created by a CMsgRef on
  46. // Prepare delivery.
  47. //
  48. // $$REVIEW: We may wish to include the ability to define rgdwRecips
  49. // as a CPool buffer. If so, we will need to add a flag telling how to
  50. // get rid of it.
  51. // Parameters:
  52. // pmsgref MsgRef that generated this context
  53. // pmbmap Bitmap of domains that delivery is being attempted on
  54. // cRecips Number of Recipients we are attempting delivery to
  55. // rgdwRecips Array of recip indexes. This allows the delivery context
  56. // to handle deleting the buffer.
  57. // dwStartDomain The first domain in context
  58. // pdmrq Retry interface for this delivery attempt
  59. // Returns:
  60. // -
  61. //
  62. //-----------------------------------------------------------------------------
  63. CDeliveryContext::CDeliveryContext(CMsgRef *pmsgref, CMsgBitMap *pmbmap,
  64. DWORD cRecips, DWORD *rgdwRecips,
  65. DWORD dwStartDomain,
  66. CDestMsgRetryQueue *pdmrq)
  67. {
  68. m_dwSignature = DELIVERY_CONTEXT_FREE; //so init succeeds
  69. Init(pmsgref, pmbmap, cRecips, rgdwRecips, dwStartDomain, pdmrq);
  70. }
  71. void CDeliveryContext::Init(CMsgRef *pmsgref, CMsgBitMap *pmbmap,
  72. DWORD cRecips, DWORD *rgdwRecips, DWORD dwStartDomain,
  73. CDestMsgRetryQueue *pdmrq)
  74. {
  75. _ASSERT(pmsgref);
  76. _ASSERT(pmbmap);
  77. _ASSERT(cRecips);
  78. _ASSERT(rgdwRecips);
  79. _ASSERT(DELIVERY_CONTEXT_FREE == m_dwSignature);
  80. m_dwSignature = DELIVERY_CONTEXT_SIG;
  81. m_pmsgref = pmsgref;
  82. m_pmbmap = pmbmap;
  83. m_cRecips = cRecips;
  84. m_rgdwRecips = rgdwRecips;
  85. m_dwStartDomain = dwStartDomain;
  86. m_pdmrq = pdmrq;
  87. if (m_pdmrq)
  88. m_pdmrq->AddRef();
  89. };
  90. //---[ CDeliveryContext::~CDeliveryContext ]-----------------------------------
  91. //
  92. //
  93. // Description:
  94. // Destructor for CDeliveryContext. The buffer used to pass recipients to
  95. // the SMTP stack will be freed here.
  96. // Parameters:
  97. // -
  98. // Returns:
  99. // -
  100. //
  101. //-----------------------------------------------------------------------------
  102. CDeliveryContext::~CDeliveryContext()
  103. {
  104. if (m_pmsgref)
  105. m_pmsgref->Release();
  106. if (m_pmbmap)
  107. delete m_pmbmap;
  108. if (m_rgdwRecips)
  109. FreePv(m_rgdwRecips);
  110. if (m_pdmrq)
  111. m_pdmrq->Release();
  112. m_dwSignature = DELIVERY_CONTEXT_FREE;
  113. };
  114. //---[ CDeliveryContext::HrAckMessage ]----------------------------------------
  115. //
  116. //
  117. // Description:
  118. // Ack (non)delivery of message
  119. // Parameters:
  120. // pMsgAck Ptr to MessageAck structure
  121. // Returns:
  122. // S_OK on success
  123. //
  124. //-----------------------------------------------------------------------------
  125. HRESULT CDeliveryContext::HrAckMessage(IN MessageAck *pMsgAck)
  126. {
  127. HRESULT hr = S_OK;
  128. _ASSERT(m_pmsgref);
  129. _ASSERT(DELIVERY_CONTEXT_SIG == m_dwSignature);
  130. hr = m_pmsgref->HrAckMessage(this, pMsgAck);
  131. return hr;
  132. }
  133. //---[ CDeliveryContext::FVerifyHandle ]---------------------------------------
  134. //
  135. //
  136. // Description:
  137. // Used to perform simple validation that the data being passed is
  138. // actually a delivery context. This should not AV if the handle is bad
  139. // (as long as the actual function call can be made).
  140. //
  141. // Parameters:
  142. // -
  143. // Returns:
  144. // True is the this ptr looks like a valid CDeliveryContext.
  145. //
  146. //-----------------------------------------------------------------------------
  147. CDeliveryContext::FVerifyHandle(IMailMsgProperties *pIMailMsgPropeties)
  148. {
  149. _ASSERT((DELIVERY_CONTEXT_SIG == m_dwSignature) && "bogus delivery context");
  150. register BOOL fResult = TRUE;
  151. if (NULL == m_pmsgref)
  152. fResult = FALSE;
  153. else if (NULL == m_pmbmap)
  154. fResult = FALSE;
  155. if (fResult)
  156. {
  157. if (!m_pmsgref->fIsMyMailMsg(pIMailMsgPropeties))
  158. {
  159. _ASSERT(0 && "Wrong message acked on connection");
  160. fResult = FALSE;
  161. }
  162. }
  163. return fResult;
  164. };