DELPHI如何 编写 IIS的ISAPI过滤
我想写一个过滤网站非法关键字的过滤器(DLL),参考网上的代码如下,应该在下面打星号的地方写替换函数但是不知道怎么写,比如我想把非法字符"黄色"替换成"#"。希望朋友们能提供代码例子,谢谢
library Project1;
uses
SysUtils,
Classes,
Windows,
Isapi4 in 'Isapi4.pas',
func in 'func.pas',
{$R *.res}
exports
GetFilterVersion,
HttpFilterProc,
TerminateFilter;
begin
end.
##################################################
unit func;
interface
uses Windows, Classes, SysUtils,Dialogs,Isapi4, CVCode,DB, ADODB, ActiveX, SyncObjs;
function HttpFilterProc(var pfc: THTTP_FILTER_CONTEXT; Notificationtype: DWORD;
pvNotification: Pointer): DWORD; stdcall;
function GetFilterVersion(var Ver: THTTP_FILTER_VERSION): BOOL; stdcall;
function TerminateFilter(dwFlags: DWORD): BOOL; stdcall;
function exec(tmp:pchar):pchar;
implementation
function GetFilterVersion(var Ver: THTTP_FILTER_VERSION): BOOL;
begin
{$IFDEF DEBUG}
OutputDebugString('Call GetFilterVersion ...');
{$ENDIF}
OutputDebugString('Initialization ThreadLimit Filter...');
// Sets the filter version number.
Ver.dwFilterVersion := HTTP_FILTER_REVISION;
// Sets the filter description.
Ver.lpszFilterDesc := 'File access control filter.';
// Registers for the notifications.
Ver.dwFlags := SF_NOTIFY_ORDER_DEFAULT
or SF_NOTIFY_NONSECURE_PORT
or SF_NOTIFY_PREPROC_HEADERS
or SF_NOTIFY_AUTHENTICATION
or SF_NOTIFY_END_OF_REQUEST
or SF_NOTIFY_END_OF_NET_SESSION;
Result := TRUE;
end;
function HttpFilterProc (var pfc : THTTP_FILTER_CONTEXT;Notificationtype : DWORD ; pvNotification : Pointer) : DWORD ; stdcall ;
var
p : PHTTP_FILTER_RAW_DATA ;
i : integer ;
pc : pchar ;
// OnSendRawData _处理SF_NOTIFY_SEND_RAW_DATA 消息
function OnSendRawData : DWORD ;
begin
try
p := PHTTP_FILTER_RAW_DATA (pvNotification) ;
pc := p^.pvInData ;
if p^.cbInBuffer > 2 then
if (pc[0] = 'H') and (pc[1] = 'T') and (pc[2] = 'T') and (pc[3] = 'P') and (pc[4] = '/') then
pfc.pFilterContext:= pointer (0) ;
case integer(pfc.pFilterContext) of
0 , 3 : //check header , check MIME
begin
pfc.pFilterContext:= pointer(2) ;
i := 0 ;
while i < p^.cbInBuffer-4 -1 do
begin
if(pc[i] = '/') and (pc[i+1]='h') and (pc[i+2]='t') and (pc[i+3]='m') then
begin
pfc. pFilterContext:=pointer(1);
break ;
end ;
inc(i) ;
end ; // endof while
end ; // case 0
1 : // HTML data
begin
pfc. pFilterContext := pointer(1); // convert pc
**************************
**************************
替换关键字函数 不知道怎么写????????????????
**************************
**************************
end ;
end ; // end of case
result := SF_STATUS_REQ_NEXT_NOTIFICATION ;// return success ( always but exception) , call next filter(if exists)
except
Result := SF_STATUS_REQ_ERROR ;
end ;
end ; // func OnSendrawdata
begin
try
case NotificationType of
$80: // SF_NOTIFY_END_OF_REQUEST
begin
pfc. pFilterContext := pointer (0) ;
Result := SF_STATUS_REQ_NEXT_NOTIFICATION ;
end ;
SF_NOTIFY_SEND_RAW_DATA:
Result := OnSendRawData ;
else
Result := SF_STATUS_REQ_NEXT_NOTIFICATION ;
end ;
except
on E: Exception do
begin
result := SF_STATUS_REQ_NEXT_NOTIFICATION ;
end ;
end ;
end ;
function TerminateFilter(dwFlags: DWORD): BOOL;
begin
Result := TRUE;
end;
end.