Source code of Windows XP (NT5)
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.

141 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. asyncmx.hxx
  5. Abstract:
  6. This file contains type definitions for async connections
  7. Author:
  8. Rohan Phillips (Rohanp) Feb-26-1998
  9. Revision History:
  10. --*/
  11. #ifndef _ASYNC_MX_HXX_
  12. #define _ASYNC_MX_HXX_
  13. #include "dnsreci.h"
  14. class SMTP_SERVER_INSTANCE;
  15. #define ASYNCMX_SIGNATURE 'uAMX'
  16. #define ASYNCMX_SIGNATURE_FREE 'fAMX'
  17. class DNS_RESOLVER_RECORD;
  18. typedef struct _MXINIT_STRUCT_
  19. {
  20. char * HostName;
  21. DWORD PortNum;
  22. DWORD TimeOut;
  23. USERCALLBACKFUNC CallBack;
  24. ISMTPConnection *pISMTPConnection;
  25. SMTP_SERVER_INSTANCE * pInstance;
  26. SMTPDNS_RECS * pDnsRec;
  27. DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD;
  28. }MXPARAMS, *PMXPARAMS;
  29. class CAsyncMx : public CAsyncConnection
  30. {
  31. private:
  32. DWORD m_Signature;
  33. DWORD NumMxRecords;
  34. DWORD m_CurrentMxRec;
  35. DWORD m_NextMxRecord;
  36. DWORD m_DomainOptions;
  37. BOOL m_fTriedOnFailHost;
  38. BOOL m_fLoopback;
  39. LIST_ENTRY * m_pNextIpAddress;
  40. SMTPDNS_RECS * m_pDnsRec;
  41. SMTP_SERVER_INSTANCE * pServiceInstance;
  42. ISMTPConnection *pSmtpConnection;
  43. DNS_RESOLVER_RECORD *m_pDNS_RESOLVER_RECORD;
  44. LPSTR m_pszSSLVerificationName;
  45. BOOL m_fInitCalled;
  46. public:
  47. //use CPool for better memory management
  48. static CPool Pool;
  49. // override the mem functions to use CPool functions
  50. void *operator new (size_t cSize)
  51. { return Pool.Alloc(); }
  52. void operator delete (void *pInstance)
  53. { Pool.Free(pInstance); }
  54. LIST_ENTRY m_ListEntry;
  55. CAsyncMx::CAsyncMx(PMXPARAMS Parameters);
  56. ~CAsyncMx();
  57. BOOL Init (LPSTR pszSSLVerificationName);
  58. LPSTR GetSSLVerificationName () { return m_pszSSLVerificationName; }
  59. LIST_ENTRY & QueryListEntry( VOID){ return ( m_ListEntry); }
  60. ISMTPConnection * GetSmtpConnectionObj(void) {return pSmtpConnection;}
  61. SMTP_SERVER_INSTANCE * GetParentInst(void) {return pServiceInstance;}
  62. BOOL GetTriedOnFailHost(void){return m_fTriedOnFailHost;}
  63. void SetTriedOnFailHost(void){ m_fTriedOnFailHost = TRUE;}
  64. void SetNumMxRecords(DWORD NumRecords) {NumMxRecords = NumRecords;}
  65. void SetDomainOptions(DWORD Options) {m_DomainOptions = Options;}
  66. DWORD GetDomainOptions (void) {return m_DomainOptions;}
  67. virtual void IncNextIpToTry (void);
  68. virtual BOOL MakeFirstAsyncConnect(void);
  69. virtual BOOL IsMoreIpAddresses(void) ;
  70. virtual BOOL CheckIpAddress(DWORD IpAddress, DWORD PortNum);
  71. BOOL ConnectToNextMxHost(void);
  72. BOOL OnConnect(BOOL fConnected);
  73. DWORD GetNextIpAddress(void);
  74. void SetDnsRecToNull(void) { m_pDnsRec = NULL;}
  75. SMTPDNS_RECS * GetDnsRec(void) {return m_pDnsRec;}
  76. virtual BOOL SetSocketOptions(void)
  77. {
  78. BOOL fRet = FALSE;
  79. int err;
  80. //Alway enable linger so sockets that connect to the server.
  81. //This will send a hard close to the server which will cause
  82. //the servers TCP/IP socket table to be flushed very early.
  83. //We should see very few, if any, sockets in the TIME_WAIT
  84. //state
  85. struct linger Linger;
  86. Linger.l_onoff = 1;
  87. Linger.l_linger = 0;
  88. err = setsockopt(GetSockethandle(), SOL_SOCKET, SO_LINGER, (const char FAR *)&Linger, sizeof(Linger));
  89. if (err == NO_ERROR)
  90. {
  91. fRet = TRUE;
  92. }
  93. return fRet;
  94. }
  95. void AckMessage(void);
  96. void IncRecordsTriedSofar(void){m_NextMxRecord++;}
  97. BOOL IsMoreMxRecords (void) {return ++m_NextMxRecord < NumMxRecords;}
  98. BOOL WasLoopback(void) {return m_fLoopback;}
  99. DNS_RESOLVER_RECORD *GetDnsResolverRecord() { return m_pDNS_RESOLVER_RECORD; }
  100. void SetDnsResolverRecord (DNS_RESOLVER_RECORD *pDNS_RESOLVER_RECORD)
  101. { m_pDNS_RESOLVER_RECORD = pDNS_RESOLVER_RECORD; }
  102. };
  103. #endif