Ipaddressfilter_src
#if !defined(AFX_IPADDRESSFILTER_H__AC1B7F27_82E5_11D2_A28C_006067323266__INCLUDED_)
#define AFX_IPADDRESSFILTER_H__AC1B7F27_82E5_11D2_A28C_006067323266__INCLUDED_
// IPADDRESSFILTER.H - Header file for your Internet Server
// IP Address Sample Filter
#include "resource.h"
// The maximum number of addresses we will cache. If there will be a large number
// of simultaneous addresses, bump this value
#define MAX_CACHED_ADDRESSES 100
// The position after which we'll move a cache entry to the front of the list
#define LIST_REORDER_THRESHOLD 6
// The maximum length of an IP address
#define MAX_IP_ADDRESS 64
// This is the name of the file that contains the ip addresses.
// Wildcards can be used for the host part only (172.16.*.1 is not allowed).
//
// The format of the file is:
//
// 127.*
// 172.16.1.6
// 172.16.2.*
// 172.16.*
//
#define IP_LIST_FILE "c:\\winnt\\system32\\inetsrv\\ipaddressdb.txt"
// The html page showing access denied.
#define NO_ACCESS "C:\\InetPub\\wwwroot\\NoAccess.htm"
// Constants
#define ISWHITE(ch) ((ch) && ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r'))
// Cached ip address structure
typedef struct _IP_INFO
{
LIST_ENTRY ListEntry; // Double linked list entry
CHAR achIPAddress[MAX_IP_ADDRESS]; // ip address
} IP_INFO, *PIP_INFO;
class CIPAddressFilter : public CHttpFilter
{
public:
CIPAddressFilter();
~CIPAddressFilter();
// Overrides
// ClassWizard generated virtual function overrides
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//{{AFX_VIRTUAL(CIPAddressFilter)
public:
virtual BOOL GetFilterVersion(PHTTP_FILTER_VERSION pVer);
virtual DWORD OnUrlMap(CHttpFilterContext* pCtxt, PHTTP_FILTER_URL_MAP pMapInfo);
//}}AFX_VIRTUAL
// Implementation
protected:
BOOL Initialize();
static BOOL ValidateIPAddress(const CHAR* pszIPAddress, OUT BOOL* pfValid);
// Database routines
BOOL InitializeIPAddressDatabase();
static BOOL LookupIPAddressInDb(const CHAR* pszIPAddress, OUT BOOL* pfFound);
VOID TerminateIPAddressDatabase();
// Cache routines
BOOL InitializeCache();
static BOOL LookupIPAddressInCache(const CHAR* pszIPAddress, BOOL* pfFound);
static BOOL AddIPAddressToCache(const CHAR* pszIPAddress);
VOID TerminateCache();
protected:
BOOL m_fCacheInitialized; // Indicates whether the cache is initialized
static DWORD m_cCacheItems; // Number of items in the cache
static CHAR* m_pszIPAddressFile; // Buffer for ip addresses database
static LIST_ENTRY m_CacheListHead; // Circular double linked list of cached addresses
static CRITICAL_SECTION m_csCacheLock; // Critical section protects cache list
//{{AFX_MSG(CIPAddressFilter)
//}}AFX_MSG
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_IPADDRESSFILTER_H__AC1B7F27_82E5_11D2_A28C_006067323266__INCLUDED)