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.

242 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. localq.hxx
  5. Abstract:
  6. This module defines the RemoteQ class
  7. Author:
  8. Rohan Phillips ( Rohanp ) 11-Dec-1995
  9. Project:
  10. SMTP Server DLL
  11. Revision History:
  12. --*/
  13. #ifndef _REMOTE_QUEUE_HXX_
  14. #define _REMOTE_QUEUE_HXX_
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. /************************************************************
  19. * Symbolic Constants
  20. ************************************************************/
  21. #include "asynccon.hxx"
  22. #include <smtpevent.h>
  23. /************************************************************
  24. * Type Definitions
  25. ************************************************************/
  26. // X5 189659 intrumentation
  27. extern DWORD g_fCrashOnInvalidSMTPConn;
  28. BOOL AsyncCopyMailToDropDir(
  29. ISMTPConnection *pISMTPConnection,
  30. const char * DropDirectory,
  31. SMTP_SERVER_INSTANCE * pParentInst
  32. );
  33. #define DNS_RESOLVER_RECORD_VALID_SIGNATURE 'uRRD'
  34. #define DNS_RESOLVER_RECORD_INVALID_SIGNATURE 'fRRD'
  35. class DNS_RESOLVER_RECORD;
  36. //
  37. // A wrapper class for iterating through the hosts in the basic dns resolver record
  38. // returned by the dns resolution sink. The wrapper clubs together the index (of the
  39. // current destination host) with the resolver record, as they always are used in
  40. // conjunction.
  41. //
  42. class DNS_RESOLVER_RECORD
  43. {
  44. private:
  45. IDnsResolverRecord *pIDnsResolverRecord;
  46. DWORD iDnsResolverRecord;
  47. CTcpRegIpList *m_pTcpRegIpList;
  48. DWORD m_signature;
  49. public:
  50. DNS_RESOLVER_RECORD()
  51. : pIDnsResolverRecord(NULL),
  52. iDnsResolverRecord(0),
  53. m_pTcpRegIpList(NULL),
  54. m_signature(DNS_RESOLVER_RECORD_VALID_SIGNATURE)
  55. {
  56. TraceFunctEnterEx((LPARAM) this, "DNS_RESOLVER_RECORD::DNS_RESOLVER_RECORD");
  57. DebugTrace((LPARAM) this, "Creating DNS_RESOLVER_RECORD = 0x%08x", this);
  58. }
  59. ~DNS_RESOLVER_RECORD()
  60. {
  61. TraceFunctEnterEx((LPARAM) this, "DNS_RESOLVER_RECORD::~DNS_RESOLVER_RECORD");
  62. DebugTrace((LPARAM) this, "Destructing DNS_RESOLVER_RECORD = 0x%08x", this);
  63. if(pIDnsResolverRecord) {
  64. pIDnsResolverRecord->Release();
  65. pIDnsResolverRecord = NULL;
  66. }
  67. m_pTcpRegIpList = NULL;
  68. m_signature = DNS_RESOLVER_RECORD_INVALID_SIGNATURE;
  69. }
  70. void SetDnsResolverRecord(IDnsResolverRecord *pIDns) { pIDnsResolverRecord = pIDns; }
  71. IDnsResolverRecord *GetDnsResolverRecord() { return pIDnsResolverRecord; }
  72. void SetDnsList(CTcpRegIpList *pTcpRegIpList) { m_pTcpRegIpList = pTcpRegIpList; }
  73. CTcpRegIpList *GetDnsList() { return m_pTcpRegIpList; }
  74. void ResetCounter() { iDnsResolverRecord = 0; }
  75. HRESULT HrGetNextDestinationHost(LPSTR *ppszHostName, DWORD *pdwAddr)
  76. {
  77. _ASSERT(pIDnsResolverRecord && "Check with GetDnsResolverRecord first!");
  78. if(!pIDnsResolverRecord)
  79. return E_FAIL;
  80. return pIDnsResolverRecord->GetItem( iDnsResolverRecord++, ppszHostName, pdwAddr );
  81. }
  82. };
  83. class REMOTE_QUEUE : public PERSIST_QUEUE
  84. {
  85. public:
  86. REMOTE_QUEUE(SMTP_SERVER_INSTANCE * pSmtpInst) : PERSIST_QUEUE(pSmtpInst) {};
  87. virtual void BeforeDelete(void){DROP_COUNTER (GetParentInst(), RemoteQueueLength);}
  88. virtual BOOL ProcessQueueEvents(ISMTPConnection *pISMTPConnection);
  89. virtual BOOL InsertEntry(IN OUT PERSIST_QUEUE_ENTRY * pEntry, QUEUE_SIG Qsig = SIGNAL, QUEUE_POSITION Qpos = QUEUE_TAIL)
  90. {
  91. return PERSIST_QUEUE::InsertEntry (pEntry, Qsig, Qpos);
  92. }
  93. virtual PQUEUE_ENTRY PopQEntry(void)
  94. {
  95. //Decrement our counter
  96. DROP_COUNTER(GetParentInst(), RemoteQueueLength);
  97. return PERSIST_QUEUE::PopQEntry ();
  98. }
  99. virtual void DropRetryCounter(void) {DROP_COUNTER(GetParentInst(), RemoteRetryQueueLength);}
  100. virtual void BumpRetryCounter(void) {BUMP_COUNTER(GetParentInst(), RemoteRetryQueueLength);}
  101. virtual DWORD GetRetryMinutes(void) {return GetParentInst()->GetRemoteRetryMinutes();}
  102. BOOL MakeATQConnection(
  103. SMTPDNS_RECS * pDnsRec,
  104. SOCKET socket,
  105. DWORD IpAddress,
  106. ISMTPConnection *pISMTPConnection,
  107. DWORD Options,
  108. LPSTR pszSSLVerificationName,
  109. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD);
  110. void HandleFailedConnection (ISMTPConnection *pISMTPConnection,
  111. DWORD dwConnectionStatus = CONNECTION_STATUS_FAILED,
  112. DWORD dwConnectedIPAddress = 0);
  113. //
  114. // Used by HandleFailedConnection to report IP address to AQ
  115. //
  116. void ReportConnectedIPAddress(ISMTPConnection *pISMTPConnection,
  117. DWORD dwConnectedIPAddress);
  118. BOOL StartAsyncConnect(const char * HostName,
  119. ISMTPConnection *pISMTPConnection,
  120. DWORD DomainOptions,
  121. BOOL fUseSmartHostAfterFail);
  122. BOOL ConnectToNextResolverHost( CAsyncMx * pThisQ );
  123. BOOL CopyMailToDropDir(ISMTPConnection *pISMTPConnection, const char * DropDirectory);
  124. HANDLE CreateDropFile(const char * DropDir, char * szDropFile);
  125. BOOL ReStartAsyncConnections(
  126. SMTPDNS_RECS * pDnsRecs,
  127. ISMTPConnection * pISMTPConnection,
  128. DWORD DomainParams,
  129. LPSTR pszSSLVerificationName,
  130. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD);
  131. private:
  132. BOOL ConnectToResolverHost( const char * HostName,
  133. LPSTR MyFQDNName,
  134. ISMTPConnection *pISMTPConnection,
  135. DWORD DomainOptions,
  136. BOOL fUseSmartHostAfterFail,
  137. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD,
  138. PSMTPDNS_RECS pDnsRetryRec);
  139. BOOL BeginInitializeAsyncDnsQuery( LPSTR pszHostName,
  140. LPSTR pszFQDN,
  141. ISMTPConnection *pISMTPConnection,
  142. DWORD dwDnsFlags,
  143. DWORD DomainOptions,
  144. BOOL fUseSmartHostAfterFail,
  145. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD,
  146. const char * pszSSLVerificationName,
  147. PSMTPDNS_RECS pRetryDnsRec);
  148. BOOL BeginInitializeAsyncConnect( PSMTPDNS_RECS pDnsRec,
  149. ISMTPConnection *pISMTPConnection,
  150. DWORD DomainOptions,
  151. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD,
  152. const char * pszSSLVerificationName );
  153. BOOL CheckIfAllRcptsHandled( IMailMsgRecipients *pIMsgRecips, DWORD *RcptIndexList, DWORD NumRcpts );
  154. HRESULT SetAllRcptsHandled( IMailMsgRecipients *pIMsgRecips, DWORD *RcptIndexList, DWORD NumRcpts );
  155. };
  156. VOID InternetCompletion(PVOID pvContext, DWORD cbWritten,
  157. DWORD dwCompletionStatus, OVERLAPPED * lpo);
  158. BOOL DnsQueryAsync(
  159. SMTP_SERVER_INSTANCE *pServiceInstance,
  160. LPSTR pszHostName,
  161. LPSTR pszFQDN,
  162. ISMTPConnection *pISMTPConnection,
  163. DWORD dwDnsFlags,
  164. DWORD DomainOptions,
  165. BOOL fUseSmartHostAfterFail,
  166. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD,
  167. const char * pszSSLVerificationName,
  168. RETRYPARAMS *pRetryParams,
  169. BOOL fUdp);
  170. //
  171. // This function has been added to try catch X5 189572 where a NULL
  172. // ISMTPConnection causes us to crash in SMTP_CONNOUT::StartSession.
  173. // Unfortunately by then it is to late to figure out the cause of the
  174. // crash, so this code has been added in strategic places to cause a
  175. // crash at a point where we can diagnose the problem. Note that if
  176. // pISMTPConnection is NULL, we will ALWAYS crash, so this code does
  177. // not make the problem worse, it merely makes it occur earlier
  178. // during the outbound code-path at a point where it can be diagnosed.
  179. //
  180. // -- GPulla
  181. //
  182. inline void CrashOnInvalidSMTPConn(ISMTPConnection *pISMTPConnection)
  183. {
  184. int *p = NULL;
  185. if(g_fCrashOnInvalidSMTPConn && !pISMTPConnection)
  186. *p = 0;
  187. }
  188. #endif