Ipaddressfilter_src

csucdl 2009-02-05 07:10:57
#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)

...全文
118 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧