您现在的位置:首页 >> 网络通讯 >> 网络通讯 >> 内容

用Delphi编写ISAPI过滤器详解之汉字内码(3)

时间:2011/9/3 15:13:14 点击:

function HttpFilterProc(var pfc:THTTP_FILTER_CONTEXT;

Notificationtype:DWORD;pvNotification:Pointer):DWORD;stdcall;

var

p:PHTTP_FILTER_RAW_DATA;

i:integer;

pc:pchar;

begin

if Notificationtype=$80then

//是SF_NOTIFY_END_OF_REQUEST将pFilterContext复位

begin

pfc.pFilterContext:=nil;

end

else

begin

p:=PHTTP_FILTER_RAW_DATA(pvNotification);

pc:=p^.pvInData;

case integer(pfc.pFilterContext) of

0://第一次调用,要检查MIME

begin

pfc.pFilterContext:=pointer(2);

i:=0;

while i<p^.cbInBuffer-4-1do

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);

//是HTML

break;

end;

inc(i);

end;//endofwhile

end;

1://HTML数据

begin

pfc.pFilterContext:=pointer(3);

//将pc转换内码

gb2big(pc,p^.cbInBuffer);

end;

3://http1.1100contimue

begin

pfc.pFilterContext:=pointer(1);

end;

end;//endofcase

end;

//总是返回成功,并且如果有其他过滤器的话,还将继续调用

result:=SF_STATUS_REQ_NEXT_NOTIFICATION;

end;

  下面是完整的程序文件(gb2bigfiler.dpr),其中的u_gb2big_tab单元完成GB码到BIG5,码的转换,这里不再细述,有兴趣的读者可以到后文提到的笔者的站点去下载源码。

library gb2bigfiler;

uses

SysUtils,math,Classes,windows,

isapi2,//delphi中ISAPI过滤器单元

u_gb2big_tab;//包含将GB码转换成BIG5码的过程gb2big

上一页1234下一页

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号