| 1 | |||||||||||||||||||||||||||||
| 2 | package HTTP::Cookies::Find; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use base 'HTTP::Cookies'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Config::IniFiles; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Data::Dumper; # for debugging only | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use HTTP::Cookies::Mozilla; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use HTTP::Cookies::Netscape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use User; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | our | ||||||||||||||||||||||||||||
| 20 | 4 | $VERSION = 1.416; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 NAME | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | HTTP::Cookies::Find - Locate cookies for the current user on the local machine. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | use HTTP::Cookies::Find; | ||||||||||||||||||||||||||||
| 29 | my $oCookies = HTTP::Cookies::Find->new('domain.com'); | ||||||||||||||||||||||||||||
| 30 | my @asMsg = HTTP::Cookies::Find::errors; | ||||||||||||||||||||||||||||
| 31 | # Now $oCookies is a subclass of HTTP::Cookies | ||||||||||||||||||||||||||||
| 32 | # and @asMsg is an array of error messages | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Call in array context to find cookies from multiple | ||||||||||||||||||||||||||||
| 35 | # browsers/versions: | ||||||||||||||||||||||||||||
| 36 | my @aoCookies = HTTP::Cookies::Find->new('domain.com'); | ||||||||||||||||||||||||||||
| 37 | # Now @aoCookies is an array of HTTP::Cookies objects | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Looks in various normal places for HTTP cookie files. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =over | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item new | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Returns a list of cookie jars of type HTTP::Cookies::[vendor], | ||||||||||||||||||||||||||||
| 50 | for all vendor browsers found on the system. | ||||||||||||||||||||||||||||
| 51 | If called in scalar context, returns one cookie jar for the "first" vendor browser found on the system. | ||||||||||||||||||||||||||||
| 52 | The returned cookie objects are not tied to the cookie files on disk; | ||||||||||||||||||||||||||||
| 53 | the returned cookie objects are read-only copies of the found cookies. | ||||||||||||||||||||||||||||
| 54 | If no argument is given, the returned cookie objects contain read-only copies of ALL cookies. | ||||||||||||||||||||||||||||
| 55 | If an argument is given, the returned cookie objects contain read-only copies of only those cookies whose hostname "matches" the argument. | ||||||||||||||||||||||||||||
| 56 | Here "matches" means case-insensitive pattern match; | ||||||||||||||||||||||||||||
| 57 | you can pass a qr{} regexp as well as a plain string for matching. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | ############################################# main pod documentation end ## | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 4 | ▶ | use constant DEBUG_NEW => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 4 | ▶ | use constant DEBUG_GET => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # We use global variables so that the callback function can see them: | ||||||||||||||||||||||||||||
| 67 | 4 | ▶ | use vars qw( $sUser $sHostGlobal $oReal ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 4 | my @asError; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _add_error | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 2 | ▶ | push @asError, shift; | ||||||||||||||||||||||||||
|
Subroutine
_add_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | } # _add_error | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub new | ||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=39 SCAR=67.8
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | $sHostGlobal = shift || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 80 | 1 | my @aoRet; | |||||||||||||||||||||||||||
| 81 | 1 | ▶ | if ($^O =~ m!win32!i) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | WIN32_MSIE: | ||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | # Massage the hostname in an attempt to make it match MS' highlevel | ||||||||||||||||||||||||||||
| 86 | # naming scheme: | ||||||||||||||||||||||||||||
| 87 | 0 | my $sHost = $sHostGlobal; | |||||||||||||||||||||||||||
| 88 | 0 | $sHost =~ s!\.(com|edu|gov|net|org)\Z!!; # delete USA domain | |||||||||||||||||||||||||||
| 89 | 0 | $sHost =~ s!\.[a-z][a-z]\.[a-z][a-z]\Z!!; # delete intl domain | |||||||||||||||||||||||||||
| 90 | # We only look at cookies for the logged-in user: | ||||||||||||||||||||||||||||
| 91 | 0 | $sUser = lc User->Login; | |||||||||||||||||||||||||||
| 92 | 0 | print STDERR " + Finding cookies for user $sUser with host matching ($sHost)...\n" if DEBUG_NEW; | |||||||||||||||||||||||||||
| 93 | 0 | my ($sDir, %hsRegistry); | |||||||||||||||||||||||||||
| 94 | 0 | eval q{require HTTP::Cookies::Microsoft}; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 0 | _add_error qq{ EEE can not load module HTTP::Cookies::Microsoft: $@\n}; | |||||||||||||||||||||||||||
| 98 | 0 | last WIN32_MSIE; | |||||||||||||||||||||||||||
| 99 | } # if | ||||||||||||||||||||||||||||
| 100 | 0 | eval q{use Win32::TieRegistry( | |||||||||||||||||||||||||||
| 101 | Delimiter => '/', | ||||||||||||||||||||||||||||
| 102 | TiedHash => \%hsRegistry, | ||||||||||||||||||||||||||||
| 103 | )}; | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 0 | _add_error qq{ EEE can not load module Win32::TieRegistry: $@\n}; | |||||||||||||||||||||||||||
| 107 | 0 | last WIN32_MSIE; | |||||||||||||||||||||||||||
| 108 | } # if | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $sDir = $hsRegistry{"CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies"} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hsRegistry{'CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies'} || ''
MC/DC0%0/1
$hsRegistry{'CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies'} || ''
$hsRegistry{'CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies'}
Truth table0%0/2
A
A= $hsRegistry{'CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies'}
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($sDir eq '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||
| 112 | 0 | _add_error qq{ EEE can not find registry entry for MSIE cookies\n}; | |||||||||||||||||||||||||||
| 113 | 0 | last WIN32_MSIE; | |||||||||||||||||||||||||||
| 114 | } # if | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | unless (-d $sDir) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 0 | ; _add_error qq{ EEE registry entry for MSIE cookies is $sDir but that directory does not exist.\n} | |||||||||||||||||||||||||||
| 118 | ; last WIN32_MSIE | ||||||||||||||||||||||||||||
| 119 | 0 | } # unless | |||||||||||||||||||||||||||
| 120 | # index.dat is for XP; Low/index.dat is for Vista: | ||||||||||||||||||||||||||||
| 121 | 0 | foreach my $sFnameBase (qw( index.dat Low/index.dat )) | |||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | 0 | my $sFnameCookies = "$sDir\\$sFnameBase"; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (-f $sFnameCookies) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 0 | _get_cookies($sFnameCookies, 'HTTP::Cookies::Microsoft'); | |||||||||||||||||||||||||||
| 127 | 0 | last WIN32_MSIE; | |||||||||||||||||||||||||||
| 128 | } # if | ||||||||||||||||||||||||||||
| 129 | } # foreach | ||||||||||||||||||||||||||||
| 130 | } # end of WIN32_MSIE block | ||||||||||||||||||||||||||||
| 131 | # At this point, $oReal contains MSIE cookies (or undef). | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return $oReal if ! wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | push @aoRet, $oReal; | |||||||||||||||||||||||||||
| 136 | } # if found MSIE cookies | ||||||||||||||||||||||||||||
| 137 | # If wantarray, or the MSIE cookie search failed, go on and look | ||||||||||||||||||||||||||||
| 138 | # for Netscape cookies: | ||||||||||||||||||||||||||||
| 139 | WIN32_NETSCAPE: | ||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | 0 | $oReal = undef; | |||||||||||||||||||||||||||
| 142 | 0 | my $sDirWin = $ENV{WINDIR}; | |||||||||||||||||||||||||||
| 143 | 0 | my $sFnameWinIni = catfile($sDirWin, 'win.ini'); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (! -f $sFnameWinIni) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | 0 | _add_error qq{ EEE Windows ini file $sFnameWinIni does not exist\n}; | |||||||||||||||||||||||||||
| 147 | 0 | last WIN32_NETSCAPE; | |||||||||||||||||||||||||||
| 148 | } # if | ||||||||||||||||||||||||||||
| 149 | 0 | my $oIniWin = new Config::IniFiles( | |||||||||||||||||||||||||||
| 150 | -file => $sFnameWinIni, | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if (! ref($oIniWin)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||
| 154 | 0 | _add_error qq{ EEE can not parse $sFnameWinIni\n}; | |||||||||||||||||||||||||||
| 155 | 0 | last WIN32_NETSCAPE; | |||||||||||||||||||||||||||
| 156 | } # if | ||||||||||||||||||||||||||||
| 157 | 0 | my $sFnameNSIni = $oIniWin->val('Netscape', 'ini'); | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | if (! defined $sFnameNSIni) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | 0 | _add_error qq{ EEE Netscape / Mozilla is not installed\n}; | |||||||||||||||||||||||||||
| 161 | 0 | last WIN32_NETSCAPE; | |||||||||||||||||||||||||||
| 162 | } # if | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if (! -f $sFnameNSIni) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 0 | _add_error qq{ EEE Netscape ini file $sFnameNSIni does not exist\n}; | |||||||||||||||||||||||||||
| 166 | 0 | last WIN32_NETSCAPE; | |||||||||||||||||||||||||||
| 167 | } # if | ||||||||||||||||||||||||||||
| 168 | 0 | my $oIniNS = Config::IniFiles->new( | |||||||||||||||||||||||||||
| 169 | -file => $sFnameNSIni, | ||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (! ref($oIniNS)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 0 | _add_error qq{ EEE can not parse $sFnameNSIni\n}; | |||||||||||||||||||||||||||
| 174 | 0 | last WIN32_NETSCAPE; | |||||||||||||||||||||||||||
| 175 | } # if | ||||||||||||||||||||||||||||
| 176 | 0 | my $sFnameCookies = $oIniNS->val('Cookies', 'Cookie File'); | |||||||||||||||||||||||||||
| 177 | 0 | _get_cookies($sFnameCookies, 'HTTP::Cookies::Netscape'); | |||||||||||||||||||||||||||
| 178 | } # end of WIN32_NETSCAPE block | ||||||||||||||||||||||||||||
| 179 | # At this point, $oReal contains Netscape cookies (or undef). | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return $oReal if ! wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | push @aoRet, $oReal; | |||||||||||||||||||||||||||
| 184 | } # if found Netscape cookies | ||||||||||||||||||||||||||||
| 185 | # If wantarray, or the previous cookie searches failed, go on and | ||||||||||||||||||||||||||||
| 186 | # look for FireFox cookies: | ||||||||||||||||||||||||||||
| 187 | WIN32_FIREFOX: | ||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||
| 189 | 0 | $oReal = undef; | |||||||||||||||||||||||||||
| 190 | 0 | my $sProfileDir = "$ENV{APPDATA}/Mozilla/Firefox/Profiles"; | |||||||||||||||||||||||||||
| 191 | 0 | ▶ | if (! opendir (DIR, $sProfileDir)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||
| 193 | 0 | _add_error qq{ EEE Can't open Mozilla profile directory ( $sProfileDir ): $! }; | |||||||||||||||||||||||||||
| 194 | 0 | last WIN32_FIREFOX; | |||||||||||||||||||||||||||
| 195 | } # if | ||||||||||||||||||||||||||||
| 196 | 0 | my $bMozFound; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | while ( my $test = readdir( DIR ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( -d "$sProfileDir/$test" && -f "$sProfileDir/$test/cookies.txt" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d "$sProfileDir/$test" and -f "$sProfileDir/$test/cookies.txt"
MC/DC0%0/2
-d "$sProfileDir/$test" and -f "$sProfileDir/$test/cookies.txt"
-d "$sProfileDir/$test"
-f "$sProfileDir/$test/cookies.txt"
Truth table0%0/3
A and B
A= -d "$sProfileDir/$test"B= -f "$sProfileDir/$test/cookies.txt"
| |||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||
| 201 | 0 | $bMozFound = 1; | |||||||||||||||||||||||||||
| 202 | 0 | my $sFnameCookies = "$sProfileDir/$test/cookies.txt"; | |||||||||||||||||||||||||||
| 203 | 0 | _get_cookies($sFnameCookies, 'HTTP::Cookies::Mozilla'); | |||||||||||||||||||||||||||
| 204 | } # if | ||||||||||||||||||||||||||||
| 205 | } # while | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | closedir DIR or warn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ( ! $bMozFound ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||
| 209 | 0 | _add_error qq{ EEE No Mozilla cookie files found under $sProfileDir\\* } | |||||||||||||||||||||||||||
| 210 | } # if | ||||||||||||||||||||||||||||
| 211 | } # end of WIN32_FIREFOX block | ||||||||||||||||||||||||||||
| 212 | # At this point, $oReal contains Netscape cookies (or undef): | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return $oReal if ! wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | push @aoRet, $oReal; | |||||||||||||||||||||||||||
| 217 | } # if found Mozilla cookies | ||||||||||||||||||||||||||||
| 218 | # No more places to look, fall through and return what we've | ||||||||||||||||||||||||||||
| 219 | # found. | ||||||||||||||||||||||||||||
| 220 | } # if MSWin32 | ||||||||||||||||||||||||||||
| 221 | ▶ | elsif ( | |||||||||||||||||||||||||||
|
Condition33%1/3
$^O =~ /solaris/i or $^O =~ /linux/i
MC/DC0%0/2
$^O =~ /solaris/i or $^O =~ /linux/i
$^O =~ /solaris/i
$^O =~ /linux/i
Truth table33%1/3
A or B
A= $^O =~ /solaris/iB= $^O =~ /linux/i
| |||||||||||||||||||||||||||||
| 222 | ($^O =~ m!solaris!i) | ||||||||||||||||||||||||||||
| 223 | || | ||||||||||||||||||||||||||||
| 224 | ($^O =~ m!linux!i) | ||||||||||||||||||||||||||||
| 225 | ) | ||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||
| 227 | # Unix-like operating systems. | ||||||||||||||||||||||||||||
| 228 | 1 | $oReal = undef; | |||||||||||||||||||||||||||
| 229 | UNIX_NETSCAPE4: | ||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||
| 231 | 1 | ; my $sFname = catfile(home(), '.netscape', 'cookies') | |||||||||||||||||||||||||||
| 232 | 1 | ; print STDERR " + try $sFname...\n" if DEBUG_NEW | |||||||||||||||||||||||||||
| 233 | 1 | ; _get_cookies($sFname, 'HTTP::Cookies::Netscape') | |||||||||||||||||||||||||||
| 234 | 1 | ▶ | ; last UNIX_NETSCAPE4 unless ref($oReal) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | ; push @aoRet, $oReal | |||||||||||||||||||||||||||
| 236 | } # end of UNIX_NETSCAPE4 block | ||||||||||||||||||||||||||||
| 237 | # At this point, $oReal contains Netscape 7 cookies (or undef). | ||||||||||||||||||||||||||||
| 238 | 1 | ▶ | ; if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | ; return $oReal if ! wantarray | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | ; push @aoRet, $oReal | |||||||||||||||||||||||||||
| 242 | } # if found any cookies | ||||||||||||||||||||||||||||
| 243 | UNIX_NETSCAPE7: | ||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||
| 245 | 1 | ; | |||||||||||||||||||||||||||
| 246 | } # end of UNIX_NETSCAPE7 block | ||||||||||||||||||||||||||||
| 247 | # At this point, $oReal contains Netscape 7 cookies (or undef). | ||||||||||||||||||||||||||||
| 248 | 1 | ▶ | ; if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||
| 250 | 0 | ▶ | ; return $oReal if ! wantarray | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 0 | ; push @aoRet, $oReal | |||||||||||||||||||||||||||
| 252 | } # if found any cookies | ||||||||||||||||||||||||||||
| 253 | UNIX_MOZILLA: | ||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||
| 255 | 1 | ▶ | ; eval q{use HTTP::Cookies::Mozilla} | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 256 | 1 | ; my $sAppregFname = catfile(home(), '.mozilla', 'appreg') | |||||||||||||||||||||||||||
| 257 | # ; print STDERR " + try to read appreg ==$sAppregFname==\n" | ||||||||||||||||||||||||||||
| 258 | 1 | ▶ | ; if (! -f $sAppregFname) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||
| 260 | 1 | ; _add_error qq{ EEE Mozilla file $sAppregFname does not exist\n}; | |||||||||||||||||||||||||||
| 261 | ; last UNIX_MOZILLA | ||||||||||||||||||||||||||||
| 262 | 1 | } # if | |||||||||||||||||||||||||||
| 263 | 0 | ; my $sAppreg | |||||||||||||||||||||||||||
| 264 | 0 | ; eval { $sAppreg = read_file($sAppregFname, binmode => ':raw') } | |||||||||||||||||||||||||||
| 265 | 0 | ▶ | ; $sAppreg ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$sAppreg ||= ""
MC/DC0%0/1
$sAppreg ||= ""
$sAppreg
Truth table0%0/2
A
A= $sAppreg
| |||||||||||||||||||||||||||||
| 266 | 0 | ; my ($sDir) = ($sAppreg =~ m!(.mozilla/.+?\.slt)\b!) | |||||||||||||||||||||||||||
| 267 | # ; print STDERR " + found slt ==$sDir==\n" | ||||||||||||||||||||||||||||
| 268 | 0 | ; my $sFname = catfile(home(), $sDir, 'cookies.txt') | |||||||||||||||||||||||||||
| 269 | # ; print STDERR " + try to read cookies ==$sFname==\n" | ||||||||||||||||||||||||||||
| 270 | 0 | ; _get_cookies($sFname, 'HTTP::Cookies::Mozilla') | |||||||||||||||||||||||||||
| 271 | } # end of UNIX_MOZILLA block | ||||||||||||||||||||||||||||
| 272 | # At this point, $oReal contains Mozilla cookies (or undef). | ||||||||||||||||||||||||||||
| 273 | # ; print STDERR " + After mozilla cookie check, oReal is ==$oReal==\n" | ||||||||||||||||||||||||||||
| 274 | 1 | ▶ | ; if (ref($oReal)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | ; return $oReal if ! wantarray | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | # ; print STDERR " + wantarray, keep looking\n" | ||||||||||||||||||||||||||||
| 278 | 0 | ; push @aoRet, $oReal | |||||||||||||||||||||||||||
| 279 | } # if found Mozilla cookies | ||||||||||||||||||||||||||||
| 280 | } # if Unix | ||||||||||||||||||||||||||||
| 281 | else | ||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | # Future expansion: implement Netscape / other OS combinations | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | 1 | ▶ | return wantarray ? @aoRet : $oReal; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | } # new | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =item errors | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | If anything went wrong while finding cookies, | ||||||||||||||||||||||||||||
| 291 | errors() will return a list of string(s) describing the error(s). | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | sub errors | ||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||
| 297 | 1 | ▶ | return @asError; | ||||||||||||||||||||||||||
|
Subroutine
errors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 298 | } # errors | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | sub _get_cookies | ||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||
| 302 | # Required arg1 = cookies filename: | ||||||||||||||||||||||||||||
| 303 | 1 | ▶ | my $sFnameCookies = shift; | ||||||||||||||||||||||||||
|
Subroutine
_get_cookies: called CC=8 SCAR=34.4
| |||||||||||||||||||||||||||||
| 304 | # Required arg2 = cookies object type: | ||||||||||||||||||||||||||||
| 305 | 1 | my $sClass = shift; | |||||||||||||||||||||||||||
| 306 | 1 | ▶ | my $rcCallback = ($sClass =~ m!Microsoft!) ? \&_callback_msie | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 307 | : ($sClass =~ m!Netscape!) ? \&_callback_mozilla | ||||||||||||||||||||||||||||
| 308 | : ($sClass =~ m!Mozilla!) ? \&_callback_mozilla | ||||||||||||||||||||||||||||
| 309 | : \&_callback_mozilla; | ||||||||||||||||||||||||||||
| 310 | # Our return value is an object of type HTTP::Cookies. | ||||||||||||||||||||||||||||
| 311 | 1 | print STDERR " + _get_cookies($sFnameCookies,$sClass)\n" if DEBUG_GET; | |||||||||||||||||||||||||||
| 312 | 1 | ▶ | if (! -f $sFnameCookies) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||
| 314 | 1 | _add_error qq{ EEE cookies file $sFnameCookies does not exist\n}; | |||||||||||||||||||||||||||
| 315 | 1 | return undef; | |||||||||||||||||||||||||||
| 316 | } # if | ||||||||||||||||||||||||||||
| 317 | # Because $oReal is a global variable, force creation of a new | ||||||||||||||||||||||||||||
| 318 | # object into a new variable: | ||||||||||||||||||||||||||||
| 319 | 0 | my $oRealNS = $sClass->new; | |||||||||||||||||||||||||||
| 320 | 0 | ▶ | unless (ref $oRealNS) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||
| 322 | 0 | _add_error qq{ EEE can not create an empty $sClass object.\n}; | |||||||||||||||||||||||||||
| 323 | 0 | return undef; | |||||||||||||||||||||||||||
| 324 | } # unless | ||||||||||||||||||||||||||||
| 325 | 0 | print STDERR " + created oRealNS ==$oRealNS==...\n" if DEBUG_GET; | |||||||||||||||||||||||||||
| 326 | 0 | $oReal = $oRealNS; | |||||||||||||||||||||||||||
| 327 | # This is a dummy object that we use to find the appropriate | ||||||||||||||||||||||||||||
| 328 | # cookies: | ||||||||||||||||||||||||||||
| 329 | 0 | my $oDummy = $sClass->new( | |||||||||||||||||||||||||||
| 330 | File => $sFnameCookies, | ||||||||||||||||||||||||||||
| 331 | 'delayload' => 1, | ||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | unless (ref $oDummy) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 0 | _add_error qq{ EEE can not create an empty $sClass object.\n}; | |||||||||||||||||||||||||||
| 336 | 0 | return undef; | |||||||||||||||||||||||||||
| 337 | } # unless | ||||||||||||||||||||||||||||
| 338 | 0 | print STDERR " + created oDummy ==$oDummy==...\n" if DEBUG_GET; | |||||||||||||||||||||||||||
| 339 | 0 | ▶ | $oDummy->scan($rcCallback) if ref($oDummy); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | print STDERR " + return oReal ==$oReal==...\n" if DEBUG_GET; | |||||||||||||||||||||||||||
| 341 | 0 | return $oReal; | |||||||||||||||||||||||||||
| 342 | } # _get_cookies | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | sub _callback_msie | ||||||||||||||||||||||||||||
| 346 | { | ||||||||||||||||||||||||||||
| 347 | 0 | ▶ | my ($version, | ||||||||||||||||||||||||||
|
Subroutine
_callback_msie: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 348 | $key, $val, | ||||||||||||||||||||||||||||
| 349 | $path, $domain, $port, $path_spec, | ||||||||||||||||||||||||||||
| 350 | $secure, $expires, $discard, $hash) = @_; | ||||||||||||||||||||||||||||
| 351 | # All we care about at this level is the filename, which is in the | ||||||||||||||||||||||||||||
| 352 | # $val slot: | ||||||||||||||||||||||||||||
| 353 | 0 | print STDERR " + consider cookie, val==$val==\n" if (DEBUG_NEW); | |||||||||||||||||||||||||||
| 354 | 0 | ▶ | return unless ($val =~ m!\@.*$sHostGlobal!i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 0 | print STDERR " + matches host ($sHostGlobal)\n" if (1 < DEBUG_NEW); | |||||||||||||||||||||||||||
| 356 | 0 | ▶ | return unless ($val =~ m!\\$sUser\@!); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 0 | print STDERR " + matches user ($sUser)\n" if (1 < DEBUG_NEW); | |||||||||||||||||||||||||||
| 358 | # This cookie file matches the user and host. Add it to the cookies | ||||||||||||||||||||||||||||
| 359 | # we'll keep: | ||||||||||||||||||||||||||||
| 360 | 0 | $oReal->load_cookie($val); | |||||||||||||||||||||||||||
| 361 | } # _callback_msie | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | sub _callback_mozilla | ||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||
| 365 | # print STDERR " + _callback got a cookie: ", Dumper(\@_); | ||||||||||||||||||||||||||||
| 366 | # return; | ||||||||||||||||||||||||||||
| 367 | # my ($version, | ||||||||||||||||||||||||||||
| 368 | # $key, $val, | ||||||||||||||||||||||||||||
| 369 | # $path, $domain, $port, $path_spec, | ||||||||||||||||||||||||||||
| 370 | # $secure, $expires, $discard, $hash) = @_; | ||||||||||||||||||||||||||||
| 371 | 0 | ▶ | my $sDomain = $_[4]; | ||||||||||||||||||||||||||
|
Subroutine
_callback_mozilla: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 372 | 0 | print STDERR " + consider cookie from domain ($sDomain), want host ($sHostGlobal)...\n" if DEBUG_NEW; | |||||||||||||||||||||||||||
| 373 | 0 | ▶ | return if (($sHostGlobal ne '') && ($sDomain !~ m!$sHostGlobal!i)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$HTTP::Cookies::Find::sHostGlobal ne "" and not $sDomain =~ /$HTTP::Cookies::Find::sHostGlobal/i
MC/DC0%0/2
$HTTP::Cookies::Find::sHostGlobal ne "" and not $sDomain =~ /$HTTP::Cookies::Find::sHostGlobal/i
$HTTP::Cookies::Find::sHostGlobal ne ""
not $sDomain =~ /$HTTP::Cookies::Find::sHostGlobal/i
Truth table0%0/3
A and not(B)
A= $HTTP::Cookies::Find::sHostGlobal ne ""B= not $sDomain =~ /$HTTP::Cookies::Find::sHostGlobal/i
| |||||||||||||||||||||||||||||
| 374 | 0 | print STDERR " + domain ($sDomain) matches host ($sHostGlobal)\n" if DEBUG_NEW; | |||||||||||||||||||||||||||
| 375 | 0 | $oReal->set_cookie(@_); | |||||||||||||||||||||||||||
| 376 | } # _callback_mozilla | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 4 | 1; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | __END__ | ||||||||||||||||||||||||||||