home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 October
/
Chip_2001-10_cd1.bin
/
zkuste
/
delphi
/
nastroje
/
d3456
/
KBMWABD.ZIP
/
WABD_Cookies.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-07-09
|
4KB
|
131 lines
unit WABD_Cookies;
interface
uses classes,sysutils,WABD_Utils;
type
TWABD_Cookie = class(TCollectionItem)
private
FName: string;
FValue: string;
FPath: string;
FDomain: string;
FExpires: TDateTime;
FSecure: Boolean;
protected
function GetHeaderValue:string;
public
constructor Create(Collection: TCollection); override;
procedure AssignTo(Dest: TPersistent); override;
property Name: string read FName write FName;
property Value: string read FValue write FValue;
property Domain: string read FDomain write FDomain;
property Path: string read FPath write FPath;
property Expires: TDateTime read FExpires write FExpires;
property Secure: Boolean read FSecure write FSecure;
property HeaderValue: string read GetHeaderValue;
end;
TWABD_Cookies = class(TCollection)
protected
function GetCookie(Index:Integer):TWABD_Cookie;
procedure SetCookie(Index:Integer; Cookie:TWABD_Cookie);
public
constructor Create(ItemClass:TCollectionItemClass);
function Add(AName,AValue:string):TWABD_Cookie;
function GetCookieByName(AName:string):TWABD_Cookie;
property Items[Index: Integer]:TWABD_Cookie read GetCookie write SetCookie; default;
end;
implementation
// ************************************************************************
// TWABD_Cookie/TWABD_Cookies
// ************************************************************************
uses WABD_HTMLRequest;
constructor TWABD_Cookie.Create(Collection: TCollection);
begin
inherited Create(Collection);
FExpires:=-1;
end;
procedure TWABD_Cookie.AssignTo(Dest: TPersistent);
begin
if Dest is TWABD_Cookie then
with TWABD_Cookie(Dest) do
begin
Name :=Self.FName;
Value :=Self.FValue;
Domain :=Self.FDomain;
Path :=Self.FPath;
Expires:=Self.FExpires;
Secure :=Self.FSecure;
end
else
inherited AssignTo(Dest);
end;
function TWABD_Cookie.GetHeaderValue: string;
begin
Result:=Format('%s=%s',[FName, WABD_EncodeEscapes(FValue)]);
if Domain<>'' then
Result:=Result+Format('; domain=%s', [Domain]);
if Path<>'' then
Result:=Result+Format('; path=%s', [Path]);
if Expires>-1 then
Result:=Result+Format(FormatDateTime('"; expires=%s," dd "%s" yyyy hh:mm:ss "GMT"',Expires),
[DayName(Expires), MonthName(Expires)]);
if Secure then Result:=Result + '; secure';
end;
constructor TWABD_Cookies.Create(ItemClass:TCollectionItemClass);
begin
inherited Create(ItemClass);
end;
function TWABD_Cookies.Add(AName,AValue:string): TWABD_Cookie;
begin
Result:=GetCookieByName(AName);
if Result=nil then
Result:=TWABD_Cookie(inherited Add);
if Result<>nil then
begin
Result.Name:=AName;
Result.Value:=AValue;
end;
end;
function TWABD_Cookies.GetCookieByName(AName:string):TWABD_Cookie;
var
i:integer;
c:TWABD_Cookie;
begin
Result:=nil;
for i:=0 to Count-1 do
begin
c:=TWABD_Cookie(Inherited Items[i]);
if c.FName = AName then
begin
Result:=c;
break;
end;
end;
end;
function TWABD_Cookies.GetCookie(Index:Integer):TWABD_Cookie;
begin
Result:=TWABD_Cookie(inherited Items[Index]);
end;
procedure TWABD_Cookies.SetCookie(Index:Integer; Cookie:TWABD_Cookie);
begin
Items[Index].Assign(Cookie);
end;
end.