#pragma once
#include "afxmt.h"



// CDnsFirewallThread
class CDnsMessageWB;
class CDnsStateThread;
class CDnsFirewallThread : public CWinThread
{
	DECLARE_DYNCREATE(CDnsFirewallThread)

public:
	CDnsFirewallThread();
	virtual ~CDnsFirewallThread();

public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();

protected:
	DECLARE_MESSAGE_MAP()
public:
    CDnsStateThread* m_pMainStateThread;
    virtual BOOL OnIdle(LONG lCount);
    int m_nThreadIndex;
    int m_nRetCode;
    CEvent m_oThreadInitEvent;
    HANDLE m_hIoCompletionPort;
    HANDLE m_aFileHandleArray[DNSFIREWALL_FILE_COUNT];
    FLOW_DATA m_aFowContextArray[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED_ENTRY m_aCompletionPortEntries[DNSFIREWALL_COMPLETION_ENTRIES_COUNT];
    OVERLAPPED m_aWaitUdpSetFilterOverlappedArray[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED m_aWaitFlowDoneOverlapedArray[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED m_aWaitUdpQuery2OverlappedArray[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED m_aWaitDnsQueryOverlapedArray[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED m_aWaitTcpResponceOverlapped[DNSFIREWALL_FILE_COUNT];
    OVERLAPPED m_aWaitTcpNewMessageOverlapped[DNSFIREWALL_FILE_COUNT];
    bool m_aAbortedQuery[DNSFIREWALL_FILE_COUNT];
    CDnsMessageWB* m_aDnsQueryMessage[DNSFIREWALL_FILE_COUNT];
    CDnsMessageWB* m_aZoneTransferMessage[DNSFIREWALL_FILE_COUNT];
    bool ReCreateZoneTransferMessage(
        HANDLE hFileHandle,
        PFLOW_DATA pFlowData,
        CDnsMessageWB* pZoneTransferMessage,
        DWORD* pErrorCode
        );
    void GetPtrAddressesInfo(
        CDnsMessageWB* pZoneTransferMessage,
        CDnsResorceRecord* pSourceRR,
        CString sTargetDName,
        int& rA4Count,
        int& rA4PrivateCount,
        int& rA6Count,
        int& rA6PrivateCount
        );
};


