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.

293 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. cdns.h
  5. Abstract:
  6. This module defines the DNS connection class.
  7. Author:
  8. Rohan Phillips ( Rohanp ) 07-May-1998
  9. Project:
  10. Revision History:
  11. --*/
  12. # ifndef _ADNS_CLIENT_HXX_
  13. # define _ADNS_CLIENT_HXX_
  14. #include <dnsapi.h>
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. //
  19. // Redefine the type to indicate that this is a call-back function
  20. //
  21. typedef ATQ_COMPLETION PFN_ATQ_COMPLETION;
  22. /************************************************************
  23. * Symbolic Constants
  24. ************************************************************/
  25. //
  26. // Valid & Invalid Signatures for Client Connection object
  27. // (Ims Connection USed/FRee)
  28. //
  29. # define DNS_CONNECTION_SIGNATURE_VALID 'DNSU'
  30. # define DNS_CONNECTION_SIGNATURE_FREE 'DNSF'
  31. //
  32. // POP3 requires a minimum of 10 minutes before a timeout
  33. // (SMTP doesn't specify, but might as well follow POP3)
  34. //
  35. # define MINIMUM_CONNECTION_IO_TIMEOUT (10 * 60) // 10 minutes
  36. //
  37. //
  38. #define DNS_TCP_DEFAULT_PACKET_LENGTH (0x4000)
  39. enum DNSLASTIOSTATE
  40. {
  41. DNS_READIO, DNS_WRITEIO
  42. };
  43. typedef struct _DNS_OVERLAPPED
  44. {
  45. OVERLAPPED Overlapped;
  46. DNSLASTIOSTATE LastIoState;
  47. } DNS_OVERLAPPED;
  48. /************************************************************
  49. * Type Definitions
  50. ************************************************************/
  51. /*++
  52. class CLIENT_CONNECTION
  53. This class is used for keeping track of individual client
  54. connections established with the server.
  55. It maintains the state of the connection being processed.
  56. In addition it also encapsulates data related to Asynchronous
  57. thread context used for processing the request.
  58. --*/
  59. class CAsyncDns
  60. {
  61. private:
  62. ULONG m_signature; // signature on object for sanity check
  63. LONG m_cPendingIoCount;
  64. LONG m_cThreadCount;
  65. DWORD m_cbReceived;
  66. DWORD m_BytesToRead;
  67. DWORD m_dwIpServer;
  68. DWORD m_LocalPref;
  69. DWORD m_Index;
  70. BOOL m_fUdp;
  71. BOOL m_fUsingMx;
  72. BOOL m_FirstRead;
  73. BOOL m_SeenLocal;
  74. PDNS_MESSAGE_BUFFER m_pMsgRecv;
  75. BYTE *m_pMsgRecvBuf;
  76. PDNS_MESSAGE_BUFFER m_pMsgSend;
  77. BYTE *m_pMsgSendBuf;
  78. WORD m_cbSendBufSize;
  79. SOCKADDR_IN m_RemoteAddress;
  80. PDNS_RECORD m_ppRecord;
  81. PDNS_RECORD * m_ppResponseRecords;
  82. PATQ_CONTEXT m_pAtqContext;
  83. SOCKET m_DnsSocket; // socket for this connection
  84. WCHAR m_wszHostName[MAX_PATH];
  85. DWORD m_Weight [100];
  86. DWORD m_Prefer [100];
  87. protected:
  88. DWORD m_dwFlags;
  89. char m_FQDNToDrop [MAX_PATH];
  90. char m_HostName [MAX_PATH];
  91. DWORD m_dwDiagnostic;
  92. PSMTPDNS_RECS m_AuxList;
  93. //
  94. // The overlapped structure for reads (one outstanding read at a time)
  95. // -- writes will dynamically allocate them
  96. //
  97. DNS_OVERLAPPED m_ReadOverlapped;
  98. DNS_OVERLAPPED m_WriteOverlapped;
  99. SOCKET QuerySocket( VOID) const
  100. { return ( m_DnsSocket); }
  101. PATQ_CONTEXT QueryAtqContext( VOID) const
  102. { return ( m_pAtqContext); }
  103. LPOVERLAPPED QueryAtqOverlapped( void ) const
  104. { return ( m_pAtqContext == NULL ? NULL : &m_pAtqContext->Overlapped ); }
  105. public:
  106. CAsyncDns();
  107. virtual ~CAsyncDns(VOID);
  108. DNS_STATUS DnsSendRecord();
  109. DNS_STATUS DnsParseMessage( IN PDNS_MESSAGE_BUFFER pMsg,
  110. IN WORD wMessageLength,
  111. OUT PDNS_RECORD * ppRecord);
  112. DNS_STATUS Dns_OpenTcpConnectionAndSend();
  113. DNS_STATUS Dns_Send( );
  114. DNS_STATUS SendPacket( void);
  115. DNS_STATUS Dns_QueryLib( DNS_NAME, WORD wQuestionType, DWORD dwFlags, char * MyFQDN, BOOL fUdp );
  116. SOCKET Dns_CreateSocket( IN INT SockType );
  117. //BOOL MakeDnsConnection(void);
  118. //
  119. // IsValid()
  120. // o Checks the signature of the object to determine
  121. //
  122. // Returns: TRUE on success and FALSE if invalid.
  123. //
  124. BOOL IsValid( VOID) const
  125. {
  126. return ( m_signature == DNS_CONNECTION_SIGNATURE_VALID);
  127. }
  128. //-------------------------------------------------------------------------
  129. // Virtual method that MUST be defined by derived classes.
  130. //
  131. // Processes a completed IO on the connection for the client.
  132. //
  133. // -- Calls and maybe called from the Atq functions.
  134. //
  135. virtual BOOL ProcessClient(
  136. IN DWORD cbWritten,
  137. IN DWORD dwCompletionStatus,
  138. IN OUT OVERLAPPED * lpo
  139. ) ;
  140. LONG IncPendingIoCount(void)
  141. {
  142. LONG RetVal;
  143. RetVal = InterlockedIncrement( &m_cPendingIoCount );
  144. return RetVal;
  145. }
  146. LONG DecPendingIoCount(void) { return InterlockedDecrement( &m_cPendingIoCount );}
  147. LONG IncThreadCount(void)
  148. {
  149. LONG RetVal;
  150. RetVal = InterlockedIncrement( &m_cThreadCount );
  151. return RetVal;
  152. }
  153. LONG DecThreadCount(void) { return InterlockedDecrement( &m_cThreadCount );}
  154. BOOL ReadFile(
  155. IN LPVOID pBuffer,
  156. IN DWORD cbSize /* = MAX_READ_BUFF_SIZE */
  157. );
  158. BOOL WriteFile(
  159. IN LPVOID pBuffer,
  160. IN DWORD cbSize /* = MAX_READ_BUFF_SIZE */
  161. );
  162. BOOL ProcessReadIO(IN DWORD InputBufferLen,
  163. IN DWORD dwCompletionStatus,
  164. IN OUT OVERLAPPED * lpo);
  165. void DisconnectClient(void);
  166. void ProcessMxRecord(PDNS_RECORD pnewRR);
  167. void ProcessARecord(PDNS_RECORD pnewRR);
  168. //
  169. // These functions need access to data declared in CAsyncSmtpDns but are called from
  170. // CAsyncDns. For example some of the retry logic (when DNS servers are down for
  171. // example) is handled by CAsyncDns. However to kick off a retry, we need to create a
  172. // new DNS query and pass it all the parameters of the old DNS query, and some of the
  173. // parameters are in CAsyncSmtpDns. So we declare these as virtual functions to be
  174. // overridden by CAsyncSmtpDns.
  175. //
  176. virtual void HandleCompletedData(DNS_STATUS dwDnsStatus) = 0;
  177. virtual BOOL RetryAsyncDnsQuery(BOOL fUdp) = 0;
  178. BOOL SortMxList(void);
  179. BOOL CheckList(void);
  180. void MarkDown(DWORD dwIpServer, DWORD dwError, BOOL fUdp);
  181. public:
  182. //
  183. // LIST_ENTRY object for storing client connections in a list.
  184. //
  185. LIST_ENTRY m_listEntry;
  186. LIST_ENTRY & QueryListEntry( VOID)
  187. { return ( m_listEntry); }
  188. };
  189. typedef CAsyncDns * PCAsyncDns;
  190. //
  191. // Auxiliary functions
  192. //
  193. INT ShutAndCloseSocket( IN SOCKET sock);
  194. # endif
  195. /************************ End of File ***********************/