home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 October
/
Chip_2001-10_cd1.bin
/
zkuste
/
delphi
/
nastroje
/
d3456
/
KBMWABD.ZIP
/
WABD_Request.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-07-12
|
4KB
|
161 lines
unit WABD_Request;
interface
uses classes,sysutils,WABD_Cookies,WABD_Utils;
const
WABD_REQUESTTYPE_UNKNOWN=0;
WABD_REQUESTTYPE_HTML=1;
WABD_REQUESTTYPE_WML=30;
type
TWABD_ListAdder = procedure(AList:TObject; Value:string) of object;
TWABD_CustomRequest = class
protected
FLocalFilePath:string;
FHeaders : TStringList;
FQuery : TStringList;
FRequest : TStringList;
FCookies : TWABD_Cookies;
FSize : integer;
FDLLName : string;
FContentType:string;
FAuth : string;
FRemoteHost : string;
FRemoteAddr : string;
FRemoteUser : string;
FUserName : string;
FPassword : string;
FBrowser : integer;
FBrowserVersion : double;
FRequestType : integer;
procedure Parse; virtual; abstract;
public
constructor Create;
destructor Destroy; override;
procedure DetermineBrowser; virtual;
procedure DetermineRequestType; virtual;
property LocalFilePath:string read FLocalFilePath write FLocalFilePath;
property Headers:TStringList read FHeaders;
property Query:TStringList read FQuery;
property Request:TStringList read FRequest;
property Cookies:TWABD_Cookies read FCookies;
property DLLName:string read FDLLName;
property ContentType:string read FContentType;
property Size:integer read FSize;
property Auth:string read FAuth;
property RemoteUser:string read FRemoteUser;
property RemoteAddr:string read FRemoteAddr;
property RemoteHost:string read FRemoteHost;
property UserName:string read FUserName write FUserName;
property Password:string read FPassword write FPassword;
property Browser:integer read FBrowser;
property BrowserVersion:double read FBrowserVersion;
property RequestType:integer read FRequestType;
end;
var
WABD_DefaultRequestLocalFilePath:string;
implementation
constructor TWABD_CustomRequest.Create;
begin
inherited;
FHeaders:=TStringList.Create;
FQuery:=TStringList.Create;
FRequest:=TStringList.Create;
FCookies:=TWABD_Cookies.Create(TWABD_Cookie);
FLocalFilePath:=WABD_DefaultRequestLocalFilePath;
// Default we dont know Jack sh.. about what browser the user has.
FBrowser:=WABD_BrowserUnknown;
FBrowserVersion:=-1.0;
end;
destructor TWABD_CustomRequest.Destroy;
begin
FHeaders.Free;
FQuery.Free;
FRequest.Free;
FCookies.Free;
inherited;
end;
// Figure out browser from headerinfo.
procedure TWABD_CustomRequest.DetermineBrowser;
var
i:integer;
s,v:string;
p1,p2,p3:integer;
begin
s:=UpperCase(FHeaders.Text);
FBrowser:=WABD_BrowserUnknown;
// Look for MSIE.
p1:=pos('MSIE',s);
if p1>0 then FBrowser:=WABD_BrowserIExplorer
else
begin
p1:=pos('MOZILLA',s);
if p1>0 then FBrowser:=WABD_BrowserNetscape;
end;
// Not found browsertype?
if p1<=1 then exit;
// Look for version number start.
p2:=-1;
for i:=p1 to length(s) do
if (s[i]<'A') or (s[i]>'Z') then
begin
p2:=i+1;
break;
end;
if p2<=0 then exit;
// Look for version number end. V.V
p3:=length(s)+1;
for i:=p2 to length(s) do
if ((s[i]<'0') or (s[i]>'9')) and (s[i]<>'.') then
begin
p3:=i;
break;
end;
v:=copy(s,p2,p3-p2);
p2:=pos('.',v);
if p2>0 then v[p2]:=DecimalSeparator;
try
FBrowserVersion:=strtofloat(v);
except
end;
end;
// Figure what type of request.
procedure TWABD_CustomRequest.DetermineRequestType;
var
s:string;
begin
s:=LowerCase(FHeaders.Values['ACCEPT']);
FRequestType:=WABD_REQUESTTYPE_UNKNOWN;
if (pos('application/vnd.wap',s)>0) or (pos('text/vnd.wap.wml',s)>0) then
FRequestType:=WABD_REQUESTTYPE_WML
else
FRequestType:=WABD_REQUESTTYPE_HTML;
end;
initialization
WABD_DefaultRequestLocalFilePath:='.\';
end.