# // *************** Rule validation for the path restriction *************** \\
# Path restriction rules:
# 1. Path defaults to '/' if it is blank
# 2. Path must start with a slash
# 3. Path must end with a slash
# 3. Path must head match the called path
# Rule #1
if (not $cookie{'path'}) {
$cookie{'path'} = '/';
}
# Rule #2
if (not $cookie{'path'} =~ m/^\//) { # if the first character of the path restriction isn't a
slash
$cookie{'path'} = '/' . $cookie{'path'}; # make it so
}
# Rule #3
if (not $cookie{'path'} =~ m/\/$/) { # if the last character of the path restriction isn't a
slash
$cookie{'path'} .= '/'; # make it so
}
# Rule #4
if (not $path =~ m/^$cookie{'path'}/) {
$cookie{'path'} = '/';
}
# \\ *************** Rule validation for the path restriction *************** //
# // *************** Rule validation for the domain restriction *************** \\
# Domain restriction rules:
# 1. Domian *is* the host if it is blank
# 2. Domain must start with a period
# 3. Domain must have two periods
# 4. Domain must tail match the host
# Rule #1
if (not $cookie{'domain'}) {
$cookie{'domain'} = $host; # default domain if none specified
}
# Rule #2
if (not $cookie{'domain'} =~ m/^\./) { # if the first character of the domain restriction isn't
a period
$cookie{'domain'} = '.' . $cookie{'domain'}; # make it so
}
# Rule #3
if (periodCount($cookie{'domain'}) < 2) {
$cookie{'domain'} = $host;
}
# Rule #4
if (not $host =~ m/$cookie{'domain'}$/) {
$cookie{'domain'} = $host;
}
# \\ *************** Rule validation for the domain restriction *************** //
return %cookie;
}
sub assembleCookie {
# Legal hash items: name, value, domain, path, expires, secure
my $cookieObject = shift;
my ($i, $cookieText);
$cookieText = "$$cookieObject{'name'}=$$cookieObject{'value'}; domain=$$cookieObject{'domain'};
path=$$cookieObject{'path'}";
foreach $i ('expires', 'secure') {
if ($$cookieObject{$i}) {
$cookieText .= "; $i=$$cookieObject{$i}";
}
}
return $cookieText;
}
sub parseStoredCookie {
# returns hash of: $hash{'name'}
# $hash{'value'}
# $hash{'expires'}
# $hash{'expiresEpoch'}
# $hash{'domain'}
# $hash{'path'}
# $hash{'secure'}
=9= |