| 1 | package Cookies::Roundtrip; | ||
| 2 | |||
| 3 | # NOTE: HTTP::Cookies and HTTP::CookieJar and | ||
| 4 | # Firefox::Marionette::Cookie | ||
| 5 | # have expires or expiry fields. | ||
| 6 | # some can be undef which has a special meaning: | ||
| 7 | # they are session cookies (which are deleted when session/browser/tab is closed). | ||
| 8 | # THEY ALL store expiry as unix epoch seconds. | ||
| 9 | # BUT SetCookie needs a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. | ||
| 10 | # use this: HTTP::Date::time2isoz(epochsecs) | ||
| 11 | |||
| 12 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | our $VERSION = '0.01'; | ||
| 16 | |||
| 17 | 1 | ▶ | use HTTP::Cookies; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | ▶ | use HTTP::CookieJar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 0 | ▶ | use Firefox::Marionette::Cookie; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 20 | use HTTP::Date qw(str2time parse_date time2str); | ||
| 21 | use HTTP::Response; | ||
| 22 | use HTTP::Request; | ||
| 23 | use DateTime; | ||
| 24 | use HTTP::Headers::Util qw/join_header_words/; | ||
| 25 | use Data::Compare; | ||
| 26 | use Devel::StackTrace; # until the module is stable | ||
| 27 | |||
| 28 | use Data::Roundtrip qw/perl2dump no-unicode-escape-permanently/; | ||
| 29 | |||
| 30 | use Exporter; # you need to import 'import' if you don't define it further down | ||
| 31 | # the EXPORT_OK and EXPORT_TAGS is code by [kcott] @ Perlmongs.org, thanks! | ||
| 32 | # see https://perlmonks.org/?node_id=11115288 | ||
| 33 | our (@EXPORT_OK, %EXPORT_TAGS); | ||
| 34 | # For all the EXPORT subs and tags see the BEGIN{} block at the end | ||
| 35 | |||
| 36 | sub lwpuseragent_get_cookies { | ||
| 37 | my ($ua, $verbosity) = @_; | ||
| 38 | #$verbosity //= 0; | ||
| 39 | #my $parent = ( caller(1) )[3] || "N/A"; | ||
| 40 | #my $whoami = ( caller(0) )[3]; | ||
| 41 | return $ua->cookie_jar | ||
| 42 | } | ||
| 43 | |||
| 44 | # Save cookies of LWP::UserAgent (they are HTTP::CookieJar) | ||
| 45 | # into a file. The file will be empty if no cookies. | ||
| 46 | # It returns 1 on failure, 0 on success. | ||
| 47 | sub lwpuseragent_save_cookies_to_file { | ||
| 48 | my ($ua, $filename, $skip_discard, $verbosity) = @_; | ||
| 49 | $verbosity //= 0; | ||
| 50 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 51 | my $whoami = ( caller(0) )[3]; | ||
| 52 | |||
| 53 | # LWP::UserAgent supports both HTTP::Cookies and HTTP::CookieJar | ||
| 54 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 55 | # we need to find the class of the cookie jar of mech | ||
| 56 | # this is probably unsupported but there is no other way: | ||
| 57 | my $cookie_jar_class = $ua->{'cookie_jar_class'}; | ||
| 58 | |||
| 59 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 60 | if( httpcookies2file( | ||
| 61 | defined($ua->cookie_jar) ? $ua->cookie_jar : $cookie_jar_class->new(), | ||
| 62 | $filename, $skip_discard, $verbosity | ||
| 63 | ) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed.\n"; return 1 } | ||
| 64 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 65 | if( httpcookiejar2file( | ||
| 66 | defined($ua->cookie_jar) ? $ua->cookie_jar : $cookie_jar_class->new(), | ||
| 67 | $filename, $skip_discard, $verbosity | ||
| 68 | ) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed.\n"; return 1 } | ||
| 69 | } else { | ||
| 70 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 71 | return 0 | ||
| 72 | } | ||
| 73 | |||
| 74 | return 0 # success | ||
| 75 | } | ||
| 76 | |||
| 77 | # Convenience method to load any kind of cookies | ||
| 78 | # or a cookies file, into the LWP::UserAgent | ||
| 79 | # it returns the $ua's cookie_jar on success or undef on failure | ||
| 80 | sub lwpuseragent_load_cookies { | ||
| 81 | my ($ua, $cookies_or_file_etc, $verbosity) = @_; | ||
| 82 | $verbosity //= 0; | ||
| 83 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 84 | my $whoami = ( caller(0) )[3]; | ||
| 85 | |||
| 86 | my $r = ref($cookies_or_file_etc); | ||
| 87 | if( $r eq 'HTTP::Cookies' ){ | ||
| 88 | my $ret = lwpuseragent_load_httpcookies($ua, $cookies_or_file_etc, $verbosity); | ||
| 89 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'lwpuseragent_load_httpcookies()'." has failed.\n"; return undef } | ||
| 90 | return $ret; | ||
| 91 | } elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ | ||
| 92 | my $ret = lwpuseragent_load_httpcookiejar($ua, $cookies_or_file_etc, $verbosity); | ||
| 93 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'lwpuseragent_load_httpcookiejar()'." has failed.\n"; return undef } | ||
| 94 | return $ret; | ||
| 95 | } elsif( $r eq 'ARRAY' ){ | ||
| 96 | # an ARRAY_REF of cookie which can be strings as come from a server as Set-Cookie headers | ||
| 97 | # or can be an ARRAY of Firefox::Marionette::Cookie | ||
| 98 | my $ret; | ||
| 99 | if( (scalar(@$cookies_or_file_etc) > 0) | ||
| 100 | && (ref($cookies_or_file_etc->[0])eq'Firefox::Marionette::Cookie') | ||
| 101 | ){ | ||
| 102 | $ret = lwpuseragent_load_firefoxmarionettecookies($ua, $cookies_or_file_etc, $verbosity); | ||
| 103 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'lwpuseragent_load_firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 104 | } else { | ||
| 105 | $ret = lwpuseragent_load_setcookies($ua, $cookies_or_file_etc, $verbosity); | ||
| 106 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'lwpuseragent_load_setcookies()'." has failed.\n"; return undef } | ||
| 107 | } | ||
| 108 | return $ret; | ||
| 109 | } elsif( $r eq '' ){ | ||
| 110 | # scalar means a filename | ||
| 111 | my $ret = lwpuseragent_load_cookies_from_file($ua, $cookies_or_file_etc, $verbosity); | ||
| 112 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'lwpuseragent_load_cookies_from_file()'." has failed.\n"; return undef } | ||
| 113 | return $ret; | ||
| 114 | } | ||
| 115 | # error! | ||
| 116 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$r' is not known. Known cookies types are 'HTTP::Cookies', 'HTTP::CookieJar', 'HTTP::CookieJar::LWP', array of SetCookie strings, array of 'Firefox::Marionette::Cookie' or you can specify a filename as a string.\n"; | ||
| 117 | return undef | ||
| 118 | } | ||
| 119 | |||
| 120 | # It loads cookies from specified file which needs | ||
| 121 | # to have this header: | ||
| 122 | # #LWP-Cookies-ZZZ.ZZZ | ||
| 123 | # and then followed by 'Set-Cookie: blahblah' lines, | ||
| 124 | # into the specified LWP::UserAgent object, appending | ||
| 125 | # cookies to it if already some there. | ||
| 126 | # It takes in the $ua, $filename and, optionally $verbosity (integer), | ||
| 127 | # and returns back the $ua's cookie jar (as HTTP::CookieJar object) | ||
| 128 | # It returns undef on failure. | ||
| 129 | sub lwpuseragent_load_cookies_from_file { | ||
| 130 | my ($ua, $filename, $skip_discard, $verbosity) = @_; | ||
| 131 | $skip_discard //= 0; | ||
| 132 | $verbosity //= 0; | ||
| 133 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 134 | my $whoami = ( caller(0) )[3]; | ||
| 135 | |||
| 136 | # LWP::UserAgent supports both HTTP::Cookies and HTTP::CookieJar | ||
| 137 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 138 | # we need to find the class of the cookie jar of mech | ||
| 139 | # this is probably unsupported but there is no other way: | ||
| 140 | my $cookie_jar_class = $ua->{'cookie_jar_class'}; | ||
| 141 | |||
| 142 | my $old_num_cookies = 0; | ||
| 143 | my $ua_cookies; | ||
| 144 | if( ! defined($ua_cookies=$ua->cookie_jar) ){ | ||
| 145 | # there is no cookiejar in $ua, make one and insert it into mech | ||
| 146 | if( ! defined($ua_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to $cookie_jar_class".'->new()'." has failed.\n"; return undef } | ||
| 147 | $ua->cookie_jar($ua_cookies); | ||
| 148 | } else { | ||
| 149 | $old_num_cookies = count_cookies($ua_cookies, $skip_discard, $verbosity); | ||
| 150 | if( ! defined $old_num_cookies ){ print STDERR as_string_httpcookies($ua_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_cookies()'." has failed for above cookies object/0.\n"; return undef } | ||
| 151 | } | ||
| 152 | |||
| 153 | my $read_num_cookies = 0; | ||
| 154 | # by now $ua has a cookie_jar (fresh or already there) | ||
| 155 | # and this is the cookie jar we supply to the sub below | ||
| 156 | # to load the input cookies (which are of type HTTP::Cookies) | ||
| 157 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 158 | # this is the same as the format of the cookies file | ||
| 159 | if( ! defined file2httpcookies($filename, $ua_cookies, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 160 | $read_num_cookies = count_httpcookies($ua_cookies, $skip_discard, $verbosity); | ||
| 161 | if( ! defined $read_num_cookies ){ print STDERR as_string_httpcookies($ua_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_httpcookies()'." has failed for above cookies object/1.\n"; return undef } | ||
| 162 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 163 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 164 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 165 | # convert to cookiejar and insert straight into the mech | ||
| 166 | if( ! defined httpcookies2httpcookiejar($httpcookies, $ua_cookies, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed for above HTTP::Cookies object (which was read from cookie file '$filename').\n"; return undef } | ||
| 167 | $read_num_cookies = count_httpcookiejar($ua_cookies); | ||
| 168 | if( ! defined $read_num_cookies ){ print STDERR as_string_httpcookiejar($ua_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_httpcookiejar()'." has failed for above cookies object/2.\n"; return undef } | ||
| 169 | } else { | ||
| 170 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 171 | return undef | ||
| 172 | } | ||
| 173 | |||
| 174 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ${read_num_cookies} cookies into the specified LWP::UserAgent object. It now has ".count_cookies($ua->cookie_jar, $skip_discard, $verbosity)." cookies.\n" } | ||
| 175 | |||
| 176 | return $ua->cookie_jar; | ||
| 177 | } | ||
| 178 | |||
| 179 | # It loads the specified HTTP::Cookies object | ||
| 180 | # into the specified LWP::UserAgent object, appending | ||
| 181 | # cookies to it if already some there. | ||
| 182 | # It takes in the $ua, $httpcookies and, optionally $verbosity (integer), | ||
| 183 | # and returns back the $ua's cookie jar (as HTTP::CookieJar object) | ||
| 184 | # It returns undef on failure. | ||
| 185 | sub lwpuseragent_load_setcookies { | ||
| 186 | my ($ua, $setcookies, $verbosity) = @_; | ||
| 187 | $verbosity //= 0; | ||
| 188 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 189 | my $whoami = ( caller(0) )[3]; | ||
| 190 | |||
| 191 | my $httpcookiejar; | ||
| 192 | if( ! defined($httpcookiejar=$ua->cookie_jar) ){ | ||
| 193 | # there is no cookiejar in $ua, make one and insert it into ua | ||
| 194 | if( ! defined($httpcookiejar=HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 195 | $ua->cookie_jar($httpcookiejar); | ||
| 196 | } | ||
| 197 | # by now $ua has a cookie_jar (fresh or already there) | ||
| 198 | # and this is the cookie jar we supply to the sub below | ||
| 199 | # to load the input cookies | ||
| 200 | if( ! defined setcookies2httpcookiejar($setcookies, $httpcookiejar, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2httpcookiejar()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 201 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_setcookies($setcookies)." cookies in the input Set-Cookies and loaded them into the LWP::UserAgent. It now has ".count_httpcookiejar($ua->cookie_jar)." cookies.\n" } | ||
| 202 | return $ua->cookie_jar; | ||
| 203 | } | ||
| 204 | |||
| 205 | # It loads the specified ARRAY of Firefox::Marionette::Cookie | ||
| 206 | # into the specified LWP::UserAgent object, appending | ||
| 207 | # cookies to it if already some there. | ||
| 208 | # It takes in the $ua, $httpcookies and, optionally $verbosity (integer), | ||
| 209 | # and returns back the $ua's cookie jar (as HTTP::CookieJar object) | ||
| 210 | # It returns undef on failure. | ||
| 211 | sub lwpuseragent_load_firefoxmarionettecookies { | ||
| 212 | my ($ua, $firefoxmarionettecookies, $verbosity) = @_; | ||
| 213 | $verbosity //= 0; | ||
| 214 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 215 | my $whoami = ( caller(0) )[3]; | ||
| 216 | |||
| 217 | my $httpcookiejar; | ||
| 218 | if( ! defined($httpcookiejar=$ua->cookie_jar) ){ | ||
| 219 | # there is no cookiejar in $ua, make one and insert it into ua | ||
| 220 | if( ! defined($httpcookiejar=HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 221 | $ua->cookie_jar($httpcookiejar); | ||
| 222 | } | ||
| 223 | # by now $ua has a cookie_jar (fresh or already there) | ||
| 224 | # and this is the cookie jar we supply to the sub below | ||
| 225 | # to load the input cookies | ||
| 226 | if( ! defined firefoxmarionettecookies2httpcookiejar($firefoxmarionettecookies, $httpcookiejar, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_firefoxmarionettecookies($firefoxmarionettecookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionettecookies2httpcookiejar()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 227 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_firefoxmarionettecookies($firefoxmarionettecookies)." cookies in the input Set-Cookies and loaded them into the LWP::UserAgent. It now has ".count_httpcookiejar($ua->cookie_jar)." cookies.\n" } | ||
| 228 | return $ua->cookie_jar; | ||
| 229 | } | ||
| 230 | |||
| 231 | # It loads the specified HTTP::Cookies object | ||
| 232 | # into the specified LWP::UserAgent object, appending | ||
| 233 | # cookies to it if already some there. | ||
| 234 | # It takes in the $ua, $httpcookies and, optionally $verbosity (integer), | ||
| 235 | # and returns back the $ua's cookie jar (as HTTP::CookieJar object) | ||
| 236 | # It returns undef on failure. | ||
| 237 | sub lwpuseragent_load_httpcookies { | ||
| 238 | my ($ua, $httpcookies, $skip_discard, $verbosity) = @_; | ||
| 239 | $skip_discard //= 0; | ||
| 240 | $verbosity //= 0; | ||
| 241 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 242 | my $whoami = ( caller(0) )[3]; | ||
| 243 | |||
| 244 | # LWP::UserAgent supports both HTTP::Cookies and HTTP::CookieJar | ||
| 245 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 246 | # we need to find the class of the cookie jar of mech | ||
| 247 | # this is probably unsupported but there is no other way: | ||
| 248 | my $cookie_jar_class = $ua->{'cookie_jar_class'}; | ||
| 249 | |||
| 250 | my $ua_cookies; | ||
| 251 | if( ! defined($ua_cookies=$ua->cookie_jar) ){ | ||
| 252 | # there is no cookiejar in $ua, make one and insert it into mech | ||
| 253 | if( ! defined($ua_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 254 | $ua->cookie_jar($ua_cookies); | ||
| 255 | } | ||
| 256 | |||
| 257 | # by now $ua has a cookie_jar (fresh or already there) | ||
| 258 | # and this is the cookie jar we supply to the sub below | ||
| 259 | # to load the input cookies | ||
| 260 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 261 | # we have the same class of cookiejar, we need to merge | ||
| 262 | if( ! defined merge_httpcookies($httpcookies, $ua_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'merge_httpcookies()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 263 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 264 | # we have a cookies entering a cookiejar in mech, need to convert | ||
| 265 | if( ! defined httpcookies2httpcookiejar($httpcookies, $ua_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 266 | } else { | ||
| 267 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 268 | return undef | ||
| 269 | } | ||
| 270 | |||
| 271 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_httpcookies($httpcookies, $skip_discard, $verbosity)." cookies in the input HTTP::Cookies and loaded them into the LWP::UserAgent. It now has ".count_cookies($ua->cookie_jar, $skip_discard, $verbosity)." cookies.\n" } | ||
| 272 | return $ua->cookie_jar; | ||
| 273 | } | ||
| 274 | |||
| 275 | # It loads the specified HTTP::CookieJar object | ||
| 276 | # into the specified LWP::UserAgent object, appending | ||
| 277 | # cookies to it if already some there. | ||
| 278 | # It takes in the $ua, $httpcookiejar and, optionally $verbosity (integer), | ||
| 279 | # and returns back the $ua's cookie jar (as HTTP::CookieJar object) | ||
| 280 | # If the $ua has no cookie jar then the supplied cookie jar will be | ||
| 281 | # first cloned and then set into $ua. | ||
| 282 | # So the input $httpcookiejar will be independent of the one in $ua. | ||
| 283 | # It returns undef on failure. | ||
| 284 | sub lwpuseragent_load_httpcookiejar { | ||
| 285 | my ($ua, $httpcookiejar, $skip_discard, $verbosity) = @_; | ||
| 286 | $skip_discard //= 0; | ||
| 287 | $verbosity //= 0; | ||
| 288 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 289 | my $whoami = ( caller(0) )[3]; | ||
| 290 | |||
| 291 | # LWP::UserAgent supports both HTTP::Cookies and HTTP::CookieJar | ||
| 292 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 293 | # we need to find the class of the cookie jar of mech | ||
| 294 | # this is probably unsupported but there is no other way: | ||
| 295 | my $cookie_jar_class = $ua->{'cookie_jar_class'}; | ||
| 296 | |||
| 297 | my $ua_cookies; | ||
| 298 | if( ! defined($ua_cookies=$ua->cookie_jar) ){ | ||
| 299 | # there is no cookiejar in $ua, make one and insert it into mech | ||
| 300 | if( ! defined($ua_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 301 | $ua->cookie_jar($ua_cookies); | ||
| 302 | } | ||
| 303 | |||
| 304 | # by now $ua has a cookie_jar (fresh or already there) | ||
| 305 | # and this is the cookie jar we supply to the sub below | ||
| 306 | # to load the input cookies | ||
| 307 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 308 | # we have a cookiejar entering a cookies in mech, need to convert | ||
| 309 | if( ! defined httpcookiejar2httpcookies($httpcookiejar, $ua_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2httpcookies()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 310 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 311 | # we have the same class of cookiejar, we need to merge | ||
| 312 | if( ! defined merge_httpcookiejar($httpcookiejar, $ua_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'merge_httpcookiejar()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 313 | } else { | ||
| 314 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 315 | return undef | ||
| 316 | } | ||
| 317 | |||
| 318 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_cookies($httpcookiejar, $skip_discard, $verbosity)." cookies in the input HTTP::Cookies and loaded them into the LWP::UserAgent. It now has ".count_cookies($ua->cookie_jar, $skip_discard, $verbosity)." cookies.\n" } | ||
| 319 | |||
| 320 | return $ua->cookie_jar; | ||
| 321 | } | ||
| 322 | |||
| 323 | ## Firefox::Marionette browser related subs | ||
| 324 | sub firefoxmarionette_get_cookies { | ||
| 325 | my ($ffmar, $verbosity) = @_; | ||
| 326 | #$verbosity //= 0; | ||
| 327 | #my $parent = ( caller(1) )[3] || "N/A"; | ||
| 328 | #my $whoami = ( caller(0) )[3]; | ||
| 329 | return [ $ffmar->cookies() ] | ||
| 330 | } | ||
| 331 | |||
| 332 | # Save cookies of LWP::UserAgent (they are HTTP::CookieJar) | ||
| 333 | # into a file. The file will be empty if no cookies. | ||
| 334 | # It returns 1 on failure, 0 on success. | ||
| 335 | sub firefoxmarionette_save_cookies_to_file { | ||
| 336 | my ($ffmar, $filename, $skip_discard, $verbosity) = @_; | ||
| 337 | $verbosity //= 0; | ||
| 338 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 339 | my $whoami = ( caller(0) )[3]; | ||
| 340 | |||
| 341 | my $cookies = firefoxmarionette_get_cookies($ffmar); | ||
| 342 | if( ! defined $cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return 1 } | ||
| 343 | if( firefoxmarionettecookies2file($cookies, $filename, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed.\n"; return 1 } | ||
| 344 | |||
| 345 | return 0 # success | ||
| 346 | } | ||
| 347 | |||
| 348 | # Convenience method to load any kind of cookies | ||
| 349 | # or a cookies file, into the LWP::UserAgent | ||
| 350 | # it returns the $ffmar's cookies on success or undef on failure | ||
| 351 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 352 | # of the cookie domain. However, some sites redirect you if you | ||
| 353 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 354 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 355 | # it may take you to cy.abc.com) | ||
| 356 | # So, parameter $visit_cookie_domain_first controls this | ||
| 357 | # if it is undef, then no visit is made, | ||
| 358 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 359 | # if non-empty string it visits that URL instead, this is the most safe. | ||
| 360 | sub firefoxmarionette_load_cookies { | ||
| 361 | my ($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 362 | $verbosity //= 0; | ||
| 363 | $skip_discard //= 0; | ||
| 364 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 365 | my $whoami = ( caller(0) )[3]; | ||
| 366 | |||
| 367 | my $r = ref($cookies_or_file_etc); | ||
| 368 | if( $r eq 'HTTP::Cookies' ){ | ||
| 369 | my $ret = firefoxmarionette_load_httpcookies($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 370 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_httpcookies()'." has failed.\n"; return undef } | ||
| 371 | return $ret; | ||
| 372 | } elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ | ||
| 373 | my $ret = firefoxmarionette_load_httpcookiejar($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 374 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_httpcookiejar()'." has failed.\n"; return undef } | ||
| 375 | return $ret; | ||
| 376 | } elsif( $r eq 'ARRAY' ){ | ||
| 377 | # an ARRAY_REF of cookie which can be strings as come from a server as Set-Cookie headers | ||
| 378 | # or can be an ARRAY of Firefox::Marionette::Cookie | ||
| 379 | my $ret; | ||
| 380 | if( (scalar(@$cookies_or_file_etc) > 0) | ||
| 381 | && (ref($cookies_or_file_etc->[0])eq'Firefox::Marionette::Cookie') | ||
| 382 | ){ | ||
| 383 | $ret = firefoxmarionette_load_firefoxmarionettecookies( | ||
| 384 | $ffmar, | ||
| 385 | $cookies_or_file_etc, | ||
| 386 | $visit_cookie_domain_first, | ||
| 387 | $skip_discard, $verbosity | ||
| 388 | ); | ||
| 389 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 390 | } else { | ||
| 391 | $ret = firefoxmarionette_load_setcookies($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 392 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_setcookies()'." has failed.\n"; return undef } | ||
| 393 | } | ||
| 394 | return $ret; | ||
| 395 | } elsif( $r eq '' ){ | ||
| 396 | # scalar means a filename | ||
| 397 | my $ret = firefoxmarionette_load_cookies_from_file($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 398 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_cookies_from_file()'." has failed.\n"; return undef } | ||
| 399 | return $ret; | ||
| 400 | } | ||
| 401 | # error! | ||
| 402 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$r' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 403 | return undef | ||
| 404 | } | ||
| 405 | |||
| 406 | # It loads cookies from specified file which needs | ||
| 407 | # to have this header: | ||
| 408 | # #LWP-Cookies-ZZZ.ZZZ | ||
| 409 | # and then followed by 'Set-Cookie: blahblah' lines, | ||
| 410 | # into the specified LWP::UserAgent object, appending | ||
| 411 | # cookies to it if already some there. | ||
| 412 | # It takes in the $ffmar, $filename and, optionally $verbosity (integer), | ||
| 413 | # and returns back the $ffmar's cookie jar (as HTTP::CookieJar object) | ||
| 414 | # It returns undef on failure. | ||
| 415 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 416 | # of the cookie domain. However, some sites redirect you if you | ||
| 417 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 418 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 419 | # it may take you to cy.abc.com) | ||
| 420 | # So, parameter $visit_cookie_domain_first controls this | ||
| 421 | # if it is undef, then no visit is made, | ||
| 422 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 423 | # if non-empty string it visits that URL instead, this is the most safe. | ||
| 424 | sub firefoxmarionette_load_cookies_from_file { | ||
| 425 | my ($ffmar, $filename, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 426 | $skip_discard //= 0; | ||
| 427 | $verbosity //= 0; | ||
| 428 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 429 | my $whoami = ( caller(0) )[3]; | ||
| 430 | |||
| 431 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 432 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 433 | my $read_num_cookies = count_cookies($httpcookies, $skip_discard, $verbosity); | ||
| 434 | my $new_ffmar_cookies = httpcookies2firefoxmarionettecookies($httpcookies, undef, $skip_discard, $verbosity); | ||
| 435 | if( ! defined $new_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2firefoxmarionettecookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 436 | |||
| 437 | if( ! defined firefoxmarionette_load_firefoxmarionettecookies( | ||
| 438 | $ffmar, | ||
| 439 | $new_ffmar_cookies, | ||
| 440 | $visit_cookie_domain_first, | ||
| 441 | $skip_discard, | ||
| 442 | $verbosity | ||
| 443 | ) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 444 | |||
| 445 | my $now_ffmar_cookies = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 446 | if( ! defined $now_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return undef } | ||
| 447 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ${read_num_cookies} cookies into the specified Firefox::Marionette object. It now has ".count_cookies($now_ffmar_cookies, $skip_discard, $verbosity)." cookies.\n" } | ||
| 448 | |||
| 449 | return $now_ffmar_cookies; | ||
| 450 | } | ||
| 451 | |||
| 452 | # It loads the specified HTTP::Cookies object | ||
| 453 | # into the specified LWP::UserAgent object, appending | ||
| 454 | # cookies to it if already some there. | ||
| 455 | # It takes in the $ffmar, $httpcookies and, optionally $verbosity (integer), | ||
| 456 | # and returns back the $ffmar's cookie jar (as HTTP::CookieJar object) | ||
| 457 | # It returns undef on failure. | ||
| 458 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 459 | # of the cookie domain. However, some sites redirect you if you | ||
| 460 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 461 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 462 | # it may take you to cy.abc.com) | ||
| 463 | # So, parameter $visit_cookie_domain_first controls this | ||
| 464 | # if it is undef, then no visit is made, | ||
| 465 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 466 | # if non-empty string it visits that URL instead, this is the most safe. | ||
| 467 | sub firefoxmarionette_load_setcookies { | ||
| 468 | my ($ffmar, $setcookies, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 469 | $verbosity //= 0; | ||
| 470 | $skip_discard //= 0; | ||
| 471 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 472 | my $whoami = ( caller(0) )[3]; | ||
| 473 | |||
| 474 | my $firefoxmarionettecookies = setcookies2firefoxmarionettecookies($setcookies, undef, $verbosity); | ||
| 475 | if( ! defined $firefoxmarionettecookies ){ print STDERR "--begin cookies:\n".as_string_cookies($setcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2firefoxmarionettecookies()'." has failed for above SetCookies.\n"; return undef } | ||
| 476 | if( ! defined firefoxmarionette_load_firefoxmarionettecookies( | ||
| 477 | $ffmar, | ||
| 478 | $firefoxmarionettecookies, | ||
| 479 | $visit_cookie_domain_first, | ||
| 480 | $skip_discard, | ||
| 481 | $verbosity | ||
| 482 | ) ){ print STDERR "--begin cookies:\n".as_string_cookies($setcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_firefoxmarionettecookies()'." has failed for above array of Firefox::Marionette::Cookie objects.\n"; return undef } | ||
| 483 | |||
| 484 | my $now_ffmar_cookies = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 485 | if( ! defined $now_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return undef } | ||
| 486 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ".count_cookies($setcookies, $skip_discard, $verbosity)." cookies into the specified Firefox::Marionette object. It now has ".count_cookies($now_ffmar_cookies, $skip_discard, $verbosity)." cookies.\n" } | ||
| 487 | |||
| 488 | return $now_ffmar_cookies; | ||
| 489 | } | ||
| 490 | |||
| 491 | # It loads the specified ARRAY of Firefox::Marionette::Cookie | ||
| 492 | # OR JUST A SINGLE Firefox::Marionette::Cookie object | ||
| 493 | # into the specified Firefox::Marionette browser object, appending | ||
| 494 | # cookies to it if already some there. | ||
| 495 | # It takes in the $ffmar, $firefoxmarionettecookies and, optionally $verbosity (integer), | ||
| 496 | # and returns back the $ffmar's cookie jar (as array of Firefox::Marionette::Cookie objects) | ||
| 497 | # It returns undef on failure. | ||
| 498 | # NOTE: if you have not visited a url then you can not add cookies!!!! (for firefox-marionette/firefox) | ||
| 499 | # if you have visited a url then you can add only cookies whose domain is the same as the | ||
| 500 | # current url!!! Otherwise you get error about cookie-averse document etc. | ||
| 501 | # see | ||
| 502 | # https://stackoverflow.com/questions/48352380/org-openqa-selenium-invalidcookiedomainexception-document-is-cookie-averse-usin | ||
| 503 | # So, we have an extra flag to visit the page of each cookie domain before loading it | ||
| 504 | # set $visit_cookie_domain_first to false in order not to visit (that means you are sure | ||
| 505 | # you are there already, otherwise this call will fail). | ||
| 506 | # Default is to visit first. | ||
| 507 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 508 | # of the cookie domain. However, some sites redirect you if you | ||
| 509 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 510 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 511 | # it may take you to cy.abc.com) | ||
| 512 | # So, parameter $visit_cookie_domain_first controls this | ||
| 513 | # if it is undef, then no visit is made, | ||
| 514 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 515 | # if non-empty string (and starts with https?://) it visits that URL instead, this is the most safe. | ||
| 516 | # BUT if you have a lot of cookies you need to load each with its own calculated url | ||
| 517 | # This is so stupid and will probably fail. | ||
| 518 | # Perhaps we can skip cookies which are failing to load and not dump core... | ||
| 519 | sub firefoxmarionette_load_firefoxmarionettecookies { | ||
| 520 | my ($ffmar, $firefoxmarionettecookies, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 521 | $verbosity //= 0; | ||
| 522 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 523 | my $whoami = ( caller(0) )[3]; | ||
| 524 | |||
| 525 | for my $acookie ( | ||
| 526 | (ref($firefoxmarionettecookies) eq 'Firefox::Marionette::Cookie') | ||
| 527 | ? [ $firefoxmarionettecookies ] | ||
| 528 | : @$firefoxmarionettecookies | ||
| 529 | ){ | ||
| 530 | my $domain = $acookie->domain; | ||
| 531 | if( ! defined($domain) || ($domain=~/^\s*$/) ){ print STDERR "--begin cookie:\n".as_string_cookies($acookie)."\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, above cookie has no domain!\n"; return undef } | ||
| 532 | my $rr; | ||
| 533 | if( defined $visit_cookie_domain_first ){ | ||
| 534 | my $url; | ||
| 535 | if( $visit_cookie_domain_first eq '' ){ | ||
| 536 | # visit the domain site as it is | ||
| 537 | $url = eval { | ||
| 538 | my $uri = URI->new(); | ||
| 539 | $uri->scheme('https'); # i guess ... this can be a huge bug | ||
| 540 | # there may be a path else use some imaginary path | ||
| 541 | # hoping it will not redirect us OUTSIDE the domain, inside the domain is ok, cookie will be set. | ||
| 542 | $uri->path(defined($acookie->path)?$acookie->path:'a/b/c'); | ||
| 543 | $uri->host($domain); | ||
| 544 | $uri->as_string; | ||
| 545 | }; | ||
| 546 | if( $@ || ! $url ){ print STDERR "--begin cookie:\n".as_string_cookies($acookie)."\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, failed to create a URL from above cookie's domain".($@?": $@":".")."\n"; return undef } | ||
| 547 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): visiting cookie's domain ($domain) to url ($url) before loading above cookie...\n" } | ||
| 548 | } elsif( $visit_cookie_domain_first =~ m!^https?\://!i ){ | ||
| 549 | # we have a user-specified full url, hopefully, check it is valid | ||
| 550 | # and go there instead of the domain, this is much preferred | ||
| 551 | $url = eval { | ||
| 552 | my $uri = URI->new($visit_cookie_domain_first); | ||
| 553 | $uri->as_string; | ||
| 554 | }; | ||
| 555 | if( $@ || ! $url ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, failed to create a URL from specified url parameter '${visit_cookie_domain_first}'".($@?": $@":".")."\n"; return undef } | ||
| 556 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): visiting cookie's domain ($domain) to url ($url) before loading above cookie...\n" } | ||
| 557 | } else { print STDERR "${whoami}, line ".__LINE__." (via $parent): error, parameter 'visit_cookie_domain_first' was not understood ($visit_cookie_domain_first).\n"; return undef } | ||
| 558 | $rr = eval { $ffmar->go($url) }; | ||
| 559 | if( $@ || ! $rr ){ print STDERR "--begin cookie:\n".as_string_cookies($acookie)."\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'Firefox::Marionette::go()'." has failed for above cookie and url ($url). Warning: this error can be because we failed to visit the url, is the network connected?".($@?": $@":".")."\n"; return undef } | ||
| 560 | } | ||
| 561 | $rr = eval { $ffmar->add_cookie($acookie) }; | ||
| 562 | if( $@ || ! $rr ){ | ||
| 563 | print STDERR "--begin cookie:\n".as_string_cookies($acookie)."\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'Firefox::Marionette::add_cookie()'." has failed for above cookie but will continue with the others".($@?": $@":".")."\n"; | ||
| 564 | # ignoring errors! | ||
| 565 | #return undef | ||
| 566 | } | ||
| 567 | } | ||
| 568 | my $now_ffmar_cookies = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 569 | if( ! defined $now_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return undef } | ||
| 570 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ".count_cookies($firefoxmarionettecookies, $skip_discard, $verbosity)." cookies into the specified Firefox::Marionette object. It now has ".count_cookies($now_ffmar_cookies, $skip_discard, $verbosity)." cookies.\n" } | ||
| 571 | |||
| 572 | return $now_ffmar_cookies; | ||
| 573 | } | ||
| 574 | |||
| 575 | # It loads the specified HTTP::Cookies object | ||
| 576 | # into the specified LWP::UserAgent object, appending | ||
| 577 | # cookies to it if already some there. | ||
| 578 | # It takes in the $ffmar, $httpcookies and, optionally $verbosity (integer), | ||
| 579 | # and returns back the $ffmar's cookie jar (as array of Firefox::Marionette::Cookie object) | ||
| 580 | # It returns undef on failure. | ||
| 581 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 582 | # of the cookie domain. However, some sites redirect you if you | ||
| 583 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 584 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 585 | # it may take you to cy.abc.com) | ||
| 586 | # So, parameter $visit_cookie_domain_first controls this | ||
| 587 | # if it is undef, then no visit is made, | ||
| 588 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 589 | # if non-empty string it visits that URL instead, this is the most safe. | ||
| 590 | sub firefoxmarionette_load_httpcookies { | ||
| 591 | my ($ffmar, $httpcookies, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 592 | $skip_discard //= 0; | ||
| 593 | $verbosity //= 0; | ||
| 594 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 595 | my $whoami = ( caller(0) )[3]; | ||
| 596 | |||
| 597 | my $firefoxmarionettecookies = httpcookies2firefoxmarionettecookies($httpcookies, undef, $verbosity); | ||
| 598 | if( ! defined $firefoxmarionettecookies ){ print STDERR "--begin cookies:\n".as_string_cookies($httpcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2firefoxmarionettecookies()'." has failed for above HTTP::Cookies.\n"; return undef } | ||
| 599 | if( ! defined firefoxmarionette_load_firefoxmarionettecookies( | ||
| 600 | $ffmar, | ||
| 601 | $firefoxmarionettecookies, | ||
| 602 | $visit_cookie_domain_first, | ||
| 603 | $skip_discard, | ||
| 604 | $verbosity | ||
| 605 | ) ){ print STDERR "--begin cookies:\n".as_string_cookies($httpcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_firefoxmarionettecookies()'." has failed for above array of Firefox::Marionette::Cookie objects.\n"; return undef } | ||
| 606 | |||
| 607 | my $now_ffmar_cookies = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 608 | if( ! defined $now_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return undef } | ||
| 609 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ".count_cookies($httpcookies, $skip_discard, $verbosity)." cookies into the specified Firefox::Marionette object. It now has ".count_cookies($now_ffmar_cookies, $skip_discard, $verbosity)." cookies.\n" } | ||
| 610 | |||
| 611 | return $now_ffmar_cookies; | ||
| 612 | } | ||
| 613 | |||
| 614 | # It loads the specified HTTP::CookieJar object | ||
| 615 | # into the specified LWP::UserAgent object, appending | ||
| 616 | # cookies to it if already some there. | ||
| 617 | # It takes in the $ffmar, $httpcookiejar and, optionally $verbosity (integer), | ||
| 618 | # and returns back the $ffmar's cookie jar (as HTTP::CookieJar object) | ||
| 619 | # If the $ffmar has no cookie jar then the supplied cookie jar will be | ||
| 620 | # first cloned and then into $ffmar. | ||
| 621 | # So the input $httpcookiejar will be independent of the one in $ffmar. | ||
| 622 | # It returns undef on failure. | ||
| 623 | # NOTE: firefox marionette will not load cookies unless we visit the site | ||
| 624 | # of the cookie domain. However, some sites redirect you if you | ||
| 625 | # do not ask for a full-path endpoint URL (e.g. www.abc.com/a/b/c | ||
| 626 | # instead of cookie domain www.abc.com. If you visit www.abc.com | ||
| 627 | # it may take you to cy.abc.com) | ||
| 628 | # So, parameter $visit_cookie_domain_first controls this | ||
| 629 | # if it is undef, then no visit is made, | ||
| 630 | # if '' (empty string) then it goes to the domain https://www.abc.com above | ||
| 631 | # if non-empty string it visits that URL instead, this is the most safe. | ||
| 632 | sub firefoxmarionette_load_httpcookiejar { | ||
| 633 | my ($ffmar, $httpcookiejar, $visit_cookie_domain_first, $skip_discard, $verbosity) = @_; | ||
| 634 | $skip_discard //= 0; | ||
| 635 | $verbosity //= 0; | ||
| 636 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 637 | my $whoami = ( caller(0) )[3]; | ||
| 638 | |||
| 639 | my $firefoxmarionettecookies = httpcookiejar2firefoxmarionettecookies($httpcookiejar, undef, $verbosity); | ||
| 640 | if( ! defined $firefoxmarionettecookies ){ print STDERR "--begin cookies:\n".as_string_cookies($httpcookiejar)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2firefoxmarionettecookies()'." has failed for above HTTP::Cookies.\n"; return undef } | ||
| 641 | if( ! defined firefoxmarionette_load_firefoxmarionettecookies( | ||
| 642 | $ffmar, | ||
| 643 | $firefoxmarionettecookies, | ||
| 644 | $visit_cookie_domain_first, | ||
| 645 | $skip_discard, | ||
| 646 | $verbosity | ||
| 647 | ) ){ print STDERR "--begin cookies:\n".as_string_cookies($httpcookiejar)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_load_firefoxmarionettecookies()'." has failed for above array of Firefox::Marionette::Cookie objects.\n"; return undef } | ||
| 648 | |||
| 649 | my $now_ffmar_cookies = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 650 | if( ! defined $now_ffmar_cookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionette_get_cookies()'." has failed.\n"; return undef } | ||
| 651 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ".count_cookies($httpcookiejar)." cookies into the specified Firefox::Marionette object. It now has ".count_cookies($now_ffmar_cookies)." cookies.\n" } | ||
| 652 | |||
| 653 | return $now_ffmar_cookies; | ||
| 654 | } | ||
| 655 | |||
| 656 | ## WWW::Mechanize browser related subs | ||
| 657 | |||
| 658 | sub wwwmechanize_get_cookies { | ||
| 659 | my ($mech, $verbosity) = @_; | ||
| 660 | #$verbosity //= 0; | ||
| 661 | #my $parent = ( caller(1) )[3] || "N/A"; | ||
| 662 | #my $whoami = ( caller(0) )[3]; | ||
| 663 | return $mech->cookie_jar | ||
| 664 | } | ||
| 665 | |||
| 666 | # Save cookies of WWW::Mechanize::ANY (they are HTTP::Cookies) | ||
| 667 | # into a file. The file will be empty if no cookies. | ||
| 668 | # It returns 1 on failure, 0 on success. | ||
| 669 | sub wwwmechanize_save_cookies_to_file { | ||
| 670 | my ($mech, $filename, $skip_discard, $verbosity) = @_; | ||
| 671 | $verbosity //= 0; | ||
| 672 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 673 | my $whoami = ( caller(0) )[3]; | ||
| 674 | |||
| 675 | # WWW::Mechanize::* supports both HTTP::Cookies and HTTP::CookieJar | ||
| 676 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 677 | # we need to find the class of the cookie jar of mech | ||
| 678 | # this is probably unsupported but there is no other way: | ||
| 679 | my $cookie_jar_class = $mech->{'cookie_jar_class'}; | ||
| 680 | |||
| 681 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 682 | if( httpcookies2file( | ||
| 683 | defined($mech->cookie_jar) ? $mech->cookie_jar : $cookie_jar_class->new(), | ||
| 684 | $filename, $skip_discard, $verbosity | ||
| 685 | ) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed.\n"; return 1 } | ||
| 686 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 687 | if( httpcookiejar2file( | ||
| 688 | defined($mech->cookie_jar) ? $mech->cookie_jar : $cookie_jar_class->new(), | ||
| 689 | $filename, $skip_discard, $verbosity | ||
| 690 | ) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed.\n"; return 1 } | ||
| 691 | } else { | ||
| 692 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 693 | return 0 | ||
| 694 | } | ||
| 695 | |||
| 696 | return 0 # success | ||
| 697 | } | ||
| 698 | |||
| 699 | # Convenience method to load any kind of cookies | ||
| 700 | # or a cookies file, into the WWW::Mechanize::ANY | ||
| 701 | # it returns the $mech's cookie_jar on success or undef on failure | ||
| 702 | sub wwwmechanize_load_cookies { | ||
| 703 | my ($mech, $cookies_or_file_etc, $verbosity) = @_; | ||
| 704 | $verbosity //= 0; | ||
| 705 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 706 | my $whoami = ( caller(0) )[3]; | ||
| 707 | |||
| 708 | my $r = ref($cookies_or_file_etc); | ||
| 709 | if( $r eq 'HTTP::Cookies' ){ | ||
| 710 | my $ret = wwwmechanize_load_httpcookies($mech, $cookies_or_file_etc, $verbosity); | ||
| 711 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'wwwmechanize_load_httpcookies()'." has failed.\n"; return undef } | ||
| 712 | return $ret; | ||
| 713 | } elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ | ||
| 714 | my $ret = wwwmechanize_load_httpcookiejar($mech, $cookies_or_file_etc, $verbosity); | ||
| 715 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'wwwmechanize_load_httpcookiejar()'." has failed.\n"; return undef } | ||
| 716 | return $ret; | ||
| 717 | } elsif( $r eq 'ARRAY' ){ | ||
| 718 | # an ARRAY_REF of cookie which can be strings as come from a server as Set-Cookie headers | ||
| 719 | # or can be an ARRAY of Firefox::Marionette::Cookie | ||
| 720 | my $ret; | ||
| 721 | if( (scalar(@$cookies_or_file_etc) > 0) | ||
| 722 | && (ref($cookies_or_file_etc->[0])eq'Firefox::Marionette::Cookie') | ||
| 723 | ){ | ||
| 724 | $ret = wwwmechanize_load_firefoxmarionettecookies($mech, $cookies_or_file_etc, $verbosity); | ||
| 725 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'wwwmechanize_load_firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 726 | } else { | ||
| 727 | $ret = wwwmechanize_load_setcookies($mech, $cookies_or_file_etc, $verbosity); | ||
| 728 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'wwwmechanize_load_setcookies()'." has failed.\n"; return undef } | ||
| 729 | } | ||
| 730 | return $ret; | ||
| 731 | } elsif( $r eq '' ){ | ||
| 732 | # scalar means a filename | ||
| 733 | my $ret = wwwmechanize_load_cookies_from_file($mech, $cookies_or_file_etc, $verbosity); | ||
| 734 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'wwwmechanize_load_cookies_from_file()'." has failed.\n"; return undef } | ||
| 735 | return $ret; | ||
| 736 | } | ||
| 737 | # error! | ||
| 738 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$r' is not known. Known cookies types are 'HTTP::Cookies', 'HTTP::CookieJar', 'HTTP::CookieJar::LWP', array of SetCookie strings, array of 'Firefox::Marionette::Cookie' or you can specify a filename as a string.\n"; | ||
| 739 | return undef | ||
| 740 | } | ||
| 741 | |||
| 742 | # It loads cookies from specified file which needs | ||
| 743 | # to have this header: | ||
| 744 | # #LWP-Cookies-ZZZ.ZZZ | ||
| 745 | # and then followed by 'Set-Cookie: blahblah' lines, | ||
| 746 | # into the specified WWW::Mechanize::ANY object, appending | ||
| 747 | # cookies to it if already some there. | ||
| 748 | # It takes in the $mech, $filename and, optionally $verbosity (integer), | ||
| 749 | # and returns back the $mech's cookie jar (as HTTP::Cookies object) | ||
| 750 | # It returns undef on failure. | ||
| 751 | sub wwwmechanize_load_cookies_from_file { | ||
| 752 | my ($mech, $filename, $skip_discard, $verbosity) = @_; | ||
| 753 | $skip_discard //= 0; | ||
| 754 | $verbosity //= 0; | ||
| 755 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 756 | my $whoami = ( caller(0) )[3]; | ||
| 757 | |||
| 758 | # WWW::Mechanize::* supports both HTTP::Cookies and HTTP::CookieJar | ||
| 759 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 760 | # we need to find the class of the cookie jar of mech | ||
| 761 | # this is probably unsupported but there is no other way: | ||
| 762 | my $cookie_jar_class = $mech->{'cookie_jar_class'}; | ||
| 763 | |||
| 764 | my $old_num_cookies = 0; | ||
| 765 | my $mech_cookies; | ||
| 766 | if( ! defined($mech_cookies=$mech->cookie_jar) ){ | ||
| 767 | # there is no cookiejar in $mech, make one and insert it into mech | ||
| 768 | if( ! defined($mech_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to $cookie_jar_class".'->new()'." has failed.\n"; return undef } | ||
| 769 | $mech->cookie_jar($mech_cookies); | ||
| 770 | } else { | ||
| 771 | $old_num_cookies = count_cookies($mech_cookies); | ||
| 772 | if( ! defined $old_num_cookies ){ print STDERR as_string_httpcookies($mech_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_cookies()'." has failed for above cookies object/0.\n"; return undef } | ||
| 773 | } | ||
| 774 | |||
| 775 | my $read_num_cookies = 0; | ||
| 776 | # by now $mech has a cookie_jar (fresh or already there) | ||
| 777 | # and this is the cookie jar we supply to the sub below | ||
| 778 | # to load the input cookies (which are of type HTTP::Cookies) | ||
| 779 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 780 | # this is the same as the format of the cookies file | ||
| 781 | if( ! defined file2httpcookies($filename, $mech_cookies, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 782 | $read_num_cookies = count_httpcookies($mech_cookies, $skip_discard, $verbosity); | ||
| 783 | if( ! defined $read_num_cookies ){ print STDERR as_string_httpcookies($mech_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_httpcookies()'." has failed for above cookies object/1.\n"; return undef } | ||
| 784 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 785 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 786 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed for cookies file '$filename'.\n"; return undef } | ||
| 787 | # convert to cookiejar and insert straight into the mech | ||
| 788 | if( ! defined httpcookies2httpcookiejar($httpcookies, $mech_cookies, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed for above HTTP::Cookies object (which was read from cookie file '$filename').\n"; return undef } | ||
| 789 | $read_num_cookies = count_httpcookiejar($mech_cookies); | ||
| 790 | if( ! defined $read_num_cookies ){ print STDERR as_string_httpcookiejar($mech_cookies)."\n${whoami}, line ".__LINE__." (via $parent): error, call to ".'count_httpcookiejar()'." has failed for above cookies object/2.\n"; return undef } | ||
| 791 | } else { | ||
| 792 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 793 | return undef | ||
| 794 | } | ||
| 795 | |||
| 796 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): loaded ${read_num_cookies} cookies into the specified WWW::Mechanize::ANY object. It now has ".count_cookies($mech->cookie_jar)." cookies.\n" } | ||
| 797 | |||
| 798 | return $mech->cookie_jar; | ||
| 799 | } | ||
| 800 | |||
| 801 | # It loads the specified HTTP::Cookies object | ||
| 802 | # into the specified WWW::Mechanize::ANY object, appending | ||
| 803 | # cookies to it if already some there. | ||
| 804 | # It takes in the $mech, $httpcookies and, optionally $verbosity (integer), | ||
| 805 | # and returns back the $mech's cookie jar (as HTTP::Cookies object) | ||
| 806 | # It returns undef on failure. | ||
| 807 | sub wwwmechanize_load_setcookies { | ||
| 808 | my ($mech, $setcookies, $verbosity) = @_; | ||
| 809 | $verbosity //= 0; | ||
| 810 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 811 | my $whoami = ( caller(0) )[3]; | ||
| 812 | |||
| 813 | my $httpcookies; | ||
| 814 | if( ! defined($httpcookies=$mech->cookie_jar) ){ | ||
| 815 | # there is no cookiejar in $mech, make one and insert it into mech | ||
| 816 | if( ! defined($httpcookies=HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 817 | $mech->cookie_jar($httpcookies); | ||
| 818 | } | ||
| 819 | |||
| 820 | # by now $mech has a cookie_jar (fresh or already there) | ||
| 821 | # and this is the cookie jar we supply to the sub below | ||
| 822 | # to load the input cookies | ||
| 823 | if( ! defined setcookies2httpcookies($setcookies, $httpcookies, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2httpcookies()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 824 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_setcookies($setcookies)." cookies in the input Set-Cookies and loaded them into the WWW::Mechanize::ANY. It now has ".count_httpcookies($mech->cookie_jar, undef, $verbosity)." cookies.\n" } | ||
| 825 | return $mech->cookie_jar; | ||
| 826 | } | ||
| 827 | |||
| 828 | # It loads the specified ARRAY of Firefox::Marionette::Cookie | ||
| 829 | # into the specified LWP::UserAgent object, appending | ||
| 830 | # cookies to it if already some there. | ||
| 831 | # It takes in the $mech, $httpcookies and, optionally $verbosity (integer), | ||
| 832 | # and returns back the $mech's cookie jar (as HTTP::CookieJar object) | ||
| 833 | # It returns undef on failure. | ||
| 834 | sub wwwmechanize_load_firefoxmarionettecookies { | ||
| 835 | my ($mech, $firefoxmarionettecookies, $verbosity) = @_; | ||
| 836 | $verbosity //= 0; | ||
| 837 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 838 | my $whoami = ( caller(0) )[3]; | ||
| 839 | |||
| 840 | my $httpcookies; | ||
| 841 | if( ! defined($httpcookies=$mech->cookie_jar) ){ | ||
| 842 | # there is no cookiejar in $mech, make one and insert it into mech | ||
| 843 | if( ! defined($httpcookies=HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 844 | $mech->cookie_jar($httpcookies); | ||
| 845 | } | ||
| 846 | |||
| 847 | # by now $mech has a cookie_jar (fresh or already there) | ||
| 848 | # and this is the cookie jar we supply to the sub below | ||
| 849 | # to load the input cookies | ||
| 850 | if( ! defined firefoxmarionettecookies2httpcookies($firefoxmarionettecookies, $httpcookies, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_firefoxmarionettecookies($firefoxmarionettecookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionettecookies2httpcookies()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 851 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_firefoxmarionettecookies($firefoxmarionettecookies)." cookies in the input Set-Cookies and loaded them into the WWW::Mechanize::ANY. It now has ".count_httpcookies($mech->cookie_jar, undef, $verbosity)." cookies.\n" } | ||
| 852 | return $mech->cookie_jar; | ||
| 853 | } | ||
| 854 | |||
| 855 | # It loads the specified HTTP::Cookies object | ||
| 856 | # into the specified WWW::Mechanize::ANY object, appending | ||
| 857 | # cookies to it if already some there. | ||
| 858 | # It takes in the $mech, $httpcookies and, optionally $verbosity (integer), | ||
| 859 | # and returns back the $mech's cookie jar (as HTTP::Cookies object) | ||
| 860 | # It returns undef on failure. | ||
| 861 | sub wwwmechanize_load_httpcookies { | ||
| 862 | my ($mech, $httpcookies, $skip_discard, $verbosity) = @_; | ||
| 863 | $skip_discard //= 0; | ||
| 864 | $verbosity //= 0; | ||
| 865 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 866 | my $whoami = ( caller(0) )[3]; | ||
| 867 | |||
| 868 | # WWW::Mechanize::* supports both HTTP::Cookies and HTTP::CookieJar | ||
| 869 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 870 | # we need to find the class of the cookie jar of mech | ||
| 871 | # this is probably unsupported but there is no other way: | ||
| 872 | my $cookie_jar_class = $mech->{'cookie_jar_class'}; | ||
| 873 | |||
| 874 | my $mech_cookies; | ||
| 875 | if( ! defined($mech_cookies=$mech->cookie_jar) ){ | ||
| 876 | # there is no cookiejar in $mech, make one and insert it into mech | ||
| 877 | if( ! defined($mech_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 878 | $mech->cookie_jar($mech_cookies); | ||
| 879 | } | ||
| 880 | |||
| 881 | # by now $mech has a cookie_jar (fresh or already there) | ||
| 882 | # and this is the cookie jar we supply to the sub below | ||
| 883 | # to load the input cookies | ||
| 884 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 885 | # we have the same class of cookiejar, we need to merge | ||
| 886 | if( ! defined merge_httpcookies($httpcookies, $mech_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'merge_httpcookies()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 887 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 888 | # we have a cookies entering a cookiejar in mech, need to convert | ||
| 889 | if( ! defined httpcookies2httpcookiejar($httpcookies, $mech_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 890 | } else { | ||
| 891 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 892 | return undef | ||
| 893 | } | ||
| 894 | |||
| 895 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_httpcookies($httpcookies, $skip_discard, $verbosity)." cookies in the input HTTP::Cookies and loaded them into the WWW::Mechanize::ANY. It now has ".count_cookies($mech->cookie_jar)." cookies.\n" } | ||
| 896 | return $mech->cookie_jar; | ||
| 897 | } | ||
| 898 | |||
| 899 | # It loads the specified HTTP::CookieJar object | ||
| 900 | # into the specified WWW::Mechanize::ANY object, appending | ||
| 901 | # cookies to it if already some there. | ||
| 902 | # It takes in the $mech, $httpcookiejar and, optionally $verbosity (integer), | ||
| 903 | # and returns back the $mech's cookie jar (as HTTP::CookieJar object) | ||
| 904 | # If the $mech has no cookie jar then the supplied cookie jar will be | ||
| 905 | # first cloned and then set into $mech. | ||
| 906 | # So the input $httpcookiejar will be independent of the one in $mech. | ||
| 907 | # It returns undef on failure. | ||
| 908 | sub wwwmechanize_load_httpcookiejar { | ||
| 909 | my ($mech, $httpcookiejar, $skip_discard, $verbosity) = @_; | ||
| 910 | $skip_discard //= 0; | ||
| 911 | $verbosity //= 0; | ||
| 912 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 913 | my $whoami = ( caller(0) )[3]; | ||
| 914 | |||
| 915 | # WWW::Mechanize::* supports both HTTP::Cookies and HTTP::CookieJar | ||
| 916 | # cookie jars (depending on the 'cookie_jar_class' param to their constructor) | ||
| 917 | # we need to find the class of the cookie jar of mech | ||
| 918 | # this is probably unsupported but there is no other way: | ||
| 919 | my $cookie_jar_class = $mech->{'cookie_jar_class'}; | ||
| 920 | |||
| 921 | my $mech_cookies; | ||
| 922 | if( ! defined($mech_cookies=$mech->cookie_jar) ){ | ||
| 923 | # there is no cookiejar in $mech, make one and insert it into mech | ||
| 924 | if( ! defined($mech_cookies=$cookie_jar_class->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 925 | $mech->cookie_jar($mech_cookies); | ||
| 926 | } | ||
| 927 | |||
| 928 | # by now $mech has a cookie_jar (fresh or already there) | ||
| 929 | # and this is the cookie jar we supply to the sub below | ||
| 930 | # to load the input cookies | ||
| 931 | if( $cookie_jar_class eq 'HTTP::Cookies' ){ | ||
| 932 | # we have a cookiejar entering a cookies in mech, need to convert | ||
| 933 | if( ! defined httpcookiejar2httpcookies($httpcookiejar, $mech_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2httpcookies()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 934 | } elsif( ($cookie_jar_class eq 'HTTP::CookieJar') || ($cookie_jar_class eq 'HTTP::CookieJar::LWP') ){ | ||
| 935 | # we have the same class of cookiejar, we need to merge | ||
| 936 | if( ! defined merge_httpcookiejar($httpcookiejar, $mech_cookies, $skip_discard, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'merge_httpcookiejar()'." has failed for above HTTP::CookieJar object (which was supplied by the user as input parameter).\n"; return undef } | ||
| 937 | } else { | ||
| 938 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$cookie_jar_class' is not known. Known cookies types are 'HTTP::Cookies' and 'HTTP::CookieJar'.\n"; | ||
| 939 | return undef | ||
| 940 | } | ||
| 941 | |||
| 942 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_cookies($httpcookiejar)." cookies in the input HTTP::Cookies and loaded them into the WWW::Mechanize::ANY. It now has ".count_cookies($mech->cookie_jar)." cookies.\n" } | ||
| 943 | |||
| 944 | return $mech->cookie_jar; | ||
| 945 | } | ||
| 946 | |||
| 947 | # It creates a new firefoxmarionettecookie (Firefox::Marionette::Cookie) (not ARRAY of them) | ||
| 948 | # and returns it given a hash of constructor parameters | ||
| 949 | sub new_firefoxmarionettecookie { | ||
| 950 | my ($params, $skip_discard, $verbosity) = @_; | ||
| 951 | $skip_discard //= 0; | ||
| 952 | $verbosity //= 0; | ||
| 953 | |||
| 954 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 955 | my $whoami = ( caller(0) )[3]; | ||
| 956 | |||
| 957 | # make sure about some details | ||
| 958 | # 1. value must be stringified, e.g. value => 123 will cause problems that it is not a string | ||
| 959 | $params->{'value'} = "".$params->{'value'}; | ||
| 960 | # 2. expiry must be a number and positive integer | ||
| 961 | if( exists($params->{'expiry'}) && defined($params->{'expiry'}) ){ | ||
| 962 | $params->{'expiry'} = 1 + $params->{'expiry'} - 1; | ||
| 963 | if( $params->{'expiry'} <= 0 ){ $params->{'expiry'} = 1 } # because FF::Mar does not like 0 | ||
| 964 | } | ||
| 965 | # 3. domain can start with a dot, remove it | ||
| 966 | $params->{'domain'} =~ s/^\.//; | ||
| 967 | my $ret = Firefox::Marionette::Cookie->new(%$params); | ||
| 968 | if( ! defined $ret ){ print STDERR perl2dump($params)."${whoami}, line ".__LINE__." (via $parent): error, call to ".'Firefox::Marionette::Cookie->new()'." has failed for above parameters.\n"; return undef } | ||
| 969 | return $ret; | ||
| 970 | } | ||
| 971 | # It creates a new firefoxmarionettecookies (ARRAY of Firefox::Marionette::Cookie) | ||
| 972 | # and returns it given an array with constructor parameters for each cookie, as a hash | ||
| 973 | sub new_firefoxmarionettecookies { | ||
| 974 | my ($params, $skip_discard, $verbosity) = @_; | ||
| 975 | $skip_discard //= 0; | ||
| 976 | $verbosity //= 0; | ||
| 977 | |||
| 978 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 979 | my $whoami = ( caller(0) )[3]; | ||
| 980 | |||
| 981 | my @ret; | ||
| 982 | for my $aparam (@$params){ | ||
| 983 | my $rr = new_firefoxmarionettecookie($aparam, $skip_discard, $verbosity); | ||
| 984 | if( ! defined $rr ){ print STDERR perl2dump($aparam)."${whoami}, line ".__LINE__." (via $parent): error, call to ".'new_firefoxmarionettecookie()'." has failed for above parameters.\n"; return undef } | ||
| 985 | push @ret, $rr; | ||
| 986 | } | ||
| 987 | return \@ret; | ||
| 988 | } | ||
| 989 | # convenience method for saving any cookie type to a file. | ||
| 990 | # It takes in the $cookies, $filename and, optionally $verbosity (integer), | ||
| 991 | # optionally $skip_discard (default=0), | ||
| 992 | # and returns 0 on success or 1 on failure. | ||
| 993 | # NOTE: Firefox::Marionette::Cookie(s) will be saved as Set Cookies | ||
| 994 | # NOTE: We also support a single Firefox::Marionette::Cookie (as well as an ARRAY of them) | ||
| 995 | sub cookies2file { | ||
| 996 | my ($cookies, $filename, $skip_discard, $verbosity) = @_; | ||
| 997 | $skip_discard //= 0; | ||
| 998 | $verbosity //= 0; | ||
| 999 | |||
| 1000 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1001 | my $whoami = ( caller(0) )[3]; | ||
| 1002 | |||
| 1003 | my $r = ref($cookies); | ||
| 1004 | |||
| 1005 | if( $r eq 'ARRAY' ){ | ||
| 1006 | return setcookies2file($cookies, $filename, $skip_discard, $verbosity) | ||
| 1007 | if scalar(@$cookies) == 0 | ||
| 1008 | ; | ||
| 1009 | if( ref($cookies->[0]) eq 'Firefox::Marionette::Cookie' ){ return firefoxmarionettecookies2file($cookies, $filename, $skip_discard, $verbosity) } | ||
| 1010 | else { | ||
| 1011 | return setcookies2file($cookies, $filename, $skip_discard, $verbosity); | ||
| 1012 | } | ||
| 1013 | } elsif( $r eq 'Firefox::Marionette::Cookie' ){ return firefoxmarionettecookies2file([$cookies], $filename, $skip_discard, $verbosity) } | ||
| 1014 | elsif( $r eq 'HTTP::Cookies' ){ return httpcookies2file($cookies, $filename, $skip_discard, $verbosity) } | ||
| 1015 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return httpcookiejar2file($cookies, $filename, $skip_discard, $verbosity) } | ||
| 1016 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, don't know how to handle type '$r'.\n"; | ||
| 1017 | return 1 # failed | ||
| 1018 | } | ||
| 1019 | # It saves HTTP::CookieJar into a file. | ||
| 1020 | # NOTE: all our 2file methods save to HTTP::Cookies format. So this one too! | ||
| 1021 | # It takes in the $filename and, optionally $verbosity (integer), | ||
| 1022 | # optionally $skip_discard (default=0), | ||
| 1023 | # and returns 0 on success or 1 on failure. | ||
| 1024 | sub httpcookiejar2file { | ||
| 1025 | my ($httpcookiejar, $filename, $skip_discard, $verbosity) = @_; | ||
| 1026 | $skip_discard //= 0; | ||
| 1027 | $verbosity //= 0; | ||
| 1028 | |||
| 1029 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1030 | my $whoami = ( caller(0) )[3]; | ||
| 1031 | # first convert to httpcookies, and save that into its own format | ||
| 1032 | my $httpcookies = httpcookiejar2httpcookies($httpcookiejar, undef, $skip_discard, $verbosity); | ||
| 1033 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2httpcookies()'." has failed.\n"; return 1 } | ||
| 1034 | # now save HTTP::Cookies to file | ||
| 1035 | if( httpcookies2file($httpcookies, $filename, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed for file '$filename'.\n"; return 1 } | ||
| 1036 | return 0 # success | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | # It reads HTTP::CookieJar cookies from a file. | ||
| 1040 | # NOTE: all our 2file methods save to this format. | ||
| 1041 | # It takes in the $filename, optionally a HTTP::CookieJar object to append to, | ||
| 1042 | # or a fresh one will be created, and, optionally $verbosity (integer), | ||
| 1043 | # and returns back the cookies read as HTTP::Cookies on succes. | ||
| 1044 | # It returns undef on failure. | ||
| 1045 | sub file2httpcookiejar { | ||
| 1046 | my ($filename, $httpcookiejar, $skip_discard, $verbosity) = @_; | ||
| 1047 | $skip_discard //= 0; | ||
| 1048 | $verbosity //= 0; | ||
| 1049 | |||
| 1050 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1051 | my $whoami = ( caller(0) )[3]; | ||
| 1052 | |||
| 1053 | if( ! defined $httpcookiejar ){ | ||
| 1054 | if( ! defined($httpcookiejar = HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | # read the file as HTTP::Cookies | ||
| 1058 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 1059 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed.\n"; return undef } | ||
| 1060 | if( ! defined httpcookies2httpcookiejar($httpcookies, $httpcookiejar, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed.\n"; return undef } | ||
| 1061 | # print only the fresh loaded cookies, so httpcookies: | ||
| 1062 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies\n\n"."${whoami}, line ".__LINE__." (via $parent): above cookies have successfully been read from file '$filename'.\n" } | ||
| 1063 | return $httpcookiejar; | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | # It reads HTTP::Cookies from a file. | ||
| 1067 | # It takes in the $filename and, optionally a HTTP::Cookies | ||
| 1068 | # object to append to (or a fresh one will be created), | ||
| 1069 | # and optionally verbosity (integer), | ||
| 1070 | # and returns back the cookies read as HTTP::Cookies on succes. | ||
| 1071 | # It returns undef on failure. | ||
| 1072 | sub file2httpcookies { | ||
| 1073 | my ($filename, $httpcookies, $verbosity) = @_; | ||
| 1074 | $verbosity //= 0; | ||
| 1075 | |||
| 1076 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1077 | my $whoami = ( caller(0) )[3]; | ||
| 1078 | |||
| 1079 | if( ! defined $httpcookies ){ | ||
| 1080 | if( ! defined($httpcookies = HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 1081 | } | ||
| 1082 | my $ret = eval { $httpcookies->load($filename) }; | ||
| 1083 | if( $@ || ! defined($ret) || ($ret!=1) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, failed to load cookies from file '$filename'".(defined($@)?" with this exception: $@":".").")\n"; return undef } | ||
| 1084 | # if we are appending then the following is wrong because it lists ALL cookies already in store | ||
| 1085 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies\n\n"."${whoami}, line ".__LINE__." (via $parent): cookies have successfully been read from file '$filename' and ALL cookies in store are now as above.\n"; } | ||
| 1086 | return $httpcookies; | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | # It saves HTTP::Cookies into a file. | ||
| 1090 | # It takes in the $filename and, optionally $verbosity (integer), | ||
| 1091 | # optionally $skip_discard (default=0), | ||
| 1092 | # and returns 0 on success or 1 on failure. | ||
| 1093 | sub httpcookies2file { | ||
| 1094 | my ($httpcookies, $filename, $skip_discard, $verbosity) = @_; | ||
| 1095 | $skip_discard //= 0; | ||
| 1096 | $verbosity //= 0; | ||
| 1097 | |||
| 1098 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1099 | my $whoami = ( caller(0) )[3]; | ||
| 1100 | # ignore_discard : from what i understood, means to ignore the discard flag, i.e. print even discarded | ||
| 1101 | my $ret = eval { $httpcookies->save(file=>$filename, ignore_discard=>!$skip_discard) }; | ||
| 1102 | if( ! defined($ret) || ($ret!=1) || $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::save()'." has failed".(defined($@)?" with this exception: $@":".").")\n"; return 1 } | ||
| 1103 | return 0 # success | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | # It saves File::Marionette::Cookie into a file AS HTTP::Cookies | ||
| 1107 | # NOTE: all our 2file methods save to HTTP::Cookies format. So this one too! | ||
| 1108 | # It takes in the $filename and, optionally $verbosity (integer), | ||
| 1109 | # optionally $skip_discard (default=0), | ||
| 1110 | # and returns 0 on success or 1 on failure. | ||
| 1111 | sub firefoxmarionettecookies2file { | ||
| 1112 | my ($firefoxmarionettecookies, $filename, $skip_discard, $verbosity) = @_; | ||
| 1113 | $skip_discard //= 0; | ||
| 1114 | $verbosity //= 0; | ||
| 1115 | |||
| 1116 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1117 | my $whoami = ( caller(0) )[3]; | ||
| 1118 | # first convert to httpcookies, and save that into its own format | ||
| 1119 | my $httpcookies = firefoxmarionettecookies2httpcookies($firefoxmarionettecookies, undef, $skip_discard, $verbosity); | ||
| 1120 | if( ! defined $httpcookies ){ print STDERR "--begin array of File::Marionette::Cookie:\n".as_string_firefoxmarionettecookies($firefoxmarionettecookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionettecookies2httpcookies()'." has failed for above array of File::Marionette::Cookie.\n"; return 1 } | ||
| 1121 | # now save HTTP::Cookies to file | ||
| 1122 | if( httpcookies2file($httpcookies, $filename, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed for file '$filename'.\n"; return 1 } | ||
| 1123 | return 0 # success | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | # It reads array of Firefox::Marionette::Cookie cookies from file, | ||
| 1127 | # which are actually saved in HTTP::Cookies format. | ||
| 1128 | # NOTE: all our 2file methods save to this format. | ||
| 1129 | # It takes in the $filename, optionally a HTTP::CookieJar object to append to, | ||
| 1130 | # or a fresh one will be created, and, optionally $verbosity (integer), | ||
| 1131 | # and returns back the cookies read as array of Firefox::Marionette::Cookie on succes. | ||
| 1132 | # It returns undef on failure. | ||
| 1133 | sub file2firefoxmarionettecookies { | ||
| 1134 | my ($filename, $firefoxmarionettecookies, $skip_discard, $verbosity) = @_; | ||
| 1135 | $skip_discard //= 0; | ||
| 1136 | $verbosity //= 0; | ||
| 1137 | |||
| 1138 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1139 | my $whoami = ( caller(0) )[3]; | ||
| 1140 | |||
| 1141 | if( ! defined $firefoxmarionettecookies ){ $firefoxmarionettecookies = [] } | ||
| 1142 | |||
| 1143 | # read the file which is in HTTP::Cookies format | ||
| 1144 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 1145 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed.\n"; return undef } | ||
| 1146 | if( ! defined httpcookies2firefoxmarionettecookies($httpcookies, $firefoxmarionettecookies, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 1147 | # print only the fresh loaded cookies, so httpcookies: | ||
| 1148 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".as_string_firefoxmarionettecookies($firefoxmarionettecookies)."\n--end cookies\n\n"."${whoami}, line ".__LINE__." (via $parent): above cookies have successfully been read from file '$filename'.\n" } | ||
| 1149 | return $firefoxmarionettecookies; | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | # It saves File::Marionette::Cookie into a file AS HTTP::Cookies | ||
| 1153 | # NOTE: all our 2file methods save to HTTP::Cookies format. So this one too! | ||
| 1154 | # It takes in the $filename and, optionally $verbosity (integer), | ||
| 1155 | # optionally $skip_discard (default=0), | ||
| 1156 | # and returns 0 on success or 1 on failure. | ||
| 1157 | sub setcookies2file { | ||
| 1158 | my ($setcookies, $filename, $skip_discard, $verbosity) = @_; | ||
| 1159 | $skip_discard //= 0; | ||
| 1160 | $verbosity //= 0; | ||
| 1161 | |||
| 1162 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1163 | my $whoami = ( caller(0) )[3]; | ||
| 1164 | # first convert to httpcookies, and save that into its own format | ||
| 1165 | my $httpcookies = setcookies2httpcookies($setcookies, undef, $skip_discard, $verbosity); | ||
| 1166 | if( ! defined $httpcookies ){ print STDERR "--begin array of File::Marionette::Cookie:\n".as_string_setcookies($setcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2httpcookies()'." has failed for above array of File::Marionette::Cookie.\n"; return 1 } | ||
| 1167 | # now save HTTP::Cookies to file | ||
| 1168 | if( httpcookies2file($httpcookies, $filename, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2file()'." has failed for file '$filename'.\n"; return 1 } | ||
| 1169 | return 0 # success | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | # It reads array of Set Cookie cookies from file, | ||
| 1173 | # which are actually saved in HTTP::Cookies format. | ||
| 1174 | # NOTE: all our 2file methods save to this format. | ||
| 1175 | # It takes in the $filename, optionally a HTTP::CookieJar object to append to, | ||
| 1176 | # or a fresh one will be created, and, optionally $verbosity (integer), | ||
| 1177 | # and returns back the cookies read as array of Firefox::Marionette::Cookie on succes. | ||
| 1178 | # It returns undef on failure. | ||
| 1179 | sub file2setcookies { | ||
| 1180 | my ($filename, $setcookies, $skip_discard, $verbosity) = @_; | ||
| 1181 | $skip_discard //= 0; | ||
| 1182 | $verbosity //= 0; | ||
| 1183 | |||
| 1184 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1185 | my $whoami = ( caller(0) )[3]; | ||
| 1186 | |||
| 1187 | if( ! defined $setcookies ){ $setcookies = [] } | ||
| 1188 | |||
| 1189 | # read the file which is in HTTP::Cookies format | ||
| 1190 | my $httpcookies = file2httpcookies($filename, undef, $verbosity); | ||
| 1191 | if( ! defined $httpcookies ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'file2httpcookies()'." has failed.\n"; return undef } | ||
| 1192 | if( ! defined httpcookies2setcookies($httpcookies, $setcookies, $skip_discard, $verbosity) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2setcookies()'." has failed.\n"; return undef } | ||
| 1193 | # print only the fresh loaded cookies, so httpcookies: | ||
| 1194 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".as_string_setcookies($setcookies)."\n--end cookies\n\n"."${whoami}, line ".__LINE__." (via $parent): above cookies have successfully been read from file '$filename'.\n" } | ||
| 1195 | return $setcookies; | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | # It converts HTTP::Cookies object to HTTP::CookieJar object. | ||
| 1199 | # It takes in the $httpcookies object and, optionally | ||
| 1200 | # $httpcookiejar (as a HTTP::CookieJar object) to append cookies in, | ||
| 1201 | # and returns back a fresh HTTP::CookieJar object or the | ||
| 1202 | # user-supplied HTTP::CookieJar object, with all the cookies loaded. | ||
| 1203 | # It returns undef on failure. | ||
| 1204 | # WARNING: httpcookies allows for domains to start with a dot (.) | ||
| 1205 | # httpcookiejar strips the leading dot in _parse_cookies() | ||
| 1206 | # WE WILL RISK AND REINSTATE THE LEADING DOT in httpcookiejar's domain | ||
| 1207 | sub httpcookies2httpcookiejar { | ||
| 1208 | my ($httpcookies, $httpcookiejar, $skip_discard, $verbosity) = @_; | ||
| 1209 | $skip_discard //= 0; | ||
| 1210 | $verbosity //= 0; | ||
| 1211 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1212 | my $whoami = ( caller(0) )[3]; | ||
| 1213 | if( ! defined $httpcookiejar ){ | ||
| 1214 | if( ! defined($httpcookiejar = HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1215 | } | ||
| 1216 | |||
| 1217 | # for better control we will loop through the cookies, pre-process, | ||
| 1218 | # convert to string and load into the HTTP::CookieJar. | ||
| 1219 | # The alternative is to convert to string (with httpcookies2setcookies()) | ||
| 1220 | # and load into HTTP::CookieJar but we will not be able to preprocess which is essential | ||
| 1221 | |||
| 1222 | # below code shamelessly borrowed from HTTP::Cookies::as_string() : | ||
| 1223 | # https://metacpan.org/dist/HTTP-Cookies/source/lib/HTTP/Cookies.pm#L568 | ||
| 1224 | # NOTE: It adds extra quotes, e.g. in path="/" or expires="xyz" | ||
| 1225 | # we have code to remove these but ... | ||
| 1226 | $httpcookies->scan(sub { | ||
| 1227 | my($version,$key,$val,$_path,$domain,$port, | ||
| 1228 | $path_spec,$secure,$_expires,$discard,$rest) = @_; | ||
| 1229 | return if $discard && $skip_discard; | ||
| 1230 | my @h = ($key, $val); | ||
| 1231 | |||
| 1232 | my $path = $_path; if( defined $path ){ $path =~ s/^"//; $path =~ s/"$// } else { $path = '' } | ||
| 1233 | # this can be undef, what do we do? set it to 10 years from now | ||
| 1234 | # it needs a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. | ||
| 1235 | my $expires = $_expires; | ||
| 1236 | if( defined $_expires ){ | ||
| 1237 | $expires = $_expires; | ||
| 1238 | $expires =~ s/^"//; | ||
| 1239 | $expires =~ s/"$//; | ||
| 1240 | } else { | ||
| 1241 | # No, leave undef expires as it is, it means session cookies | ||
| 1242 | # #$expires = HTTP::Date::time2isoz(time()+365*24*60*60*10); | ||
| 1243 | # # no, make it a bit more random! | ||
| 1244 | # #$expires = time() + 315334161 + int(rand(6000)); #315360000; | ||
| 1245 | # $expires = 0; | ||
| 1246 | # print STDERR "${whoami}, line ".__LINE__." (via $parent): warning, HTTP::Cookies cookie field 'expires' is undefined and setting it to something large ($expires) ...\n"; | ||
| 1247 | } | ||
| 1248 | push(@h, "path", $path); | ||
| 1249 | push(@h, "domain" => $domain); | ||
| 1250 | push(@h, "port" => $port) if defined $port; | ||
| 1251 | push(@h, "path_spec" => undef) if $path_spec; | ||
| 1252 | # if this is present then it is secure, there is no value | ||
| 1253 | if( $secure ){ push @h, "secure" } | ||
| 1254 | #push(@h, "secure" => undef) if $secure; | ||
| 1255 | # NOTE: this can be undef and we set it to +10 years but it is optional, i don't think so | ||
| 1256 | push(@h, "expires" => HTTP::Date::time2isoz($expires)) if $expires; | ||
| 1257 | #push(@h, "expires" => $expires); | ||
| 1258 | push(@h, "discard" => undef) if $discard; | ||
| 1259 | my $k; | ||
| 1260 | for $k (sort keys %$rest) { | ||
| 1261 | push(@h, $k, $rest->{$k}); | ||
| 1262 | } | ||
| 1263 | push(@h, "version" => $version); | ||
| 1264 | my $cookstr = HTTP::Headers::Util::join_header_words(\@h); | ||
| 1265 | |||
| 1266 | # and yet again we suffer from the quotes, perhaps HTTP::CookieJar::load_cookies() | ||
| 1267 | # assumes no quotes?! | ||
| 1268 | # this is for the key and value | ||
| 1269 | $cookstr =~ s/^(.+?)=\\"(.+?)\\";/$1=$2;/g; | ||
| 1270 | if( $cookstr =~ s/^(.+?)="(.+?)";/<%%___123_keyval_7851__%%>/ ){ | ||
| 1271 | my $kk = $1; my $vv = $2; | ||
| 1272 | $kk =~ s/\\"/"/g; | ||
| 1273 | $vv =~ s/\\"/"/g; | ||
| 1274 | $cookstr =~ s/<%%___123_keyval_7851__%%>/${kk}=${vv};/; | ||
| 1275 | } | ||
| 1276 | $cookstr =~ s/\bpath="([^"]*)";/path=$1;/; | ||
| 1277 | $cookstr =~ s/\bpath="([^"]*)";/path=$1;/; | ||
| 1278 | $cookstr =~ s/\bexpires="([^"]*)";/expires=$1;/; | ||
| 1279 | |||
| 1280 | # now load it, BUT!: | ||
| 1281 | # create a new jar because we need to process the cookie added | ||
| 1282 | # if appending, it will be lost in that madness | ||
| 1283 | my $htc = HTTP::CookieJar->new(); | ||
| 1284 | if( ! defined $htc ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1285 | if( ! defined $htc->load_cookies($cookstr) ){ print STDERR "--begin cookie:\n".$cookstr."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->load_cookies()'." has failed for above cookie (which was produced by the HTTP::Cookies object supplied by the user as input parameter).\n"; return undef } | ||
| 1286 | # delete httponly. Note: there is only 1 cookie in here now, this is guaranteed, so [0] is OK! | ||
| 1287 | my $v = $htc->{store}; | ||
| 1288 | for (1..3){ # go does 3 levels from 'store'->domain->path->key | ||
| 1289 | $v = $v->{ (keys %$v)[0] } | ||
| 1290 | } | ||
| 1291 | delete $v->{'httponly'}; | ||
| 1292 | # leading dot in domain? the HTTP::CookieJar will have removed it. | ||
| 1293 | # Reinstate it. No leave it, we can't do this everywhere | ||
| 1294 | #if( $domain =~ /^\./ ){ $v->{domain} = '.' . $v->{domain} } | ||
| 1295 | # and append the result to the $httpcookiejar, which is returned | ||
| 1296 | if( ! defined merge_httpcookiejar($htc, $httpcookiejar, $verbosity) ){ print STDERR "$0 : error, call to ".'merge_httpcookiejar()'." has failed.\n"; return undef } | ||
| 1297 | }); | ||
| 1298 | |||
| 1299 | return $httpcookiejar; | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | # It converts HTTP::Cookies object to an ARRAY of Firefox::Marionette::Cookie | ||
| 1303 | # It takes in the $httpcookies object and, optionally | ||
| 1304 | # $firefoxmarionettecookies (as an ARRAY) to append cookies in, | ||
| 1305 | # and returns back a fresh ARRAY of Firefox::Marionette::Cookie or the | ||
| 1306 | # user-supplied ARRAY of Firefox::Marionette::Cookie, with all the cookies loaded. | ||
| 1307 | # It returns undef on failure. | ||
| 1308 | # WARNING: httpcookies allows for domains to start with a dot (.) | ||
| 1309 | sub httpcookies2firefoxmarionettecookies { | ||
| 1310 | my ($httpcookies, $firefoxmarionettecookies, $skip_discard, $verbosity) = @_; | ||
| 1311 | $skip_discard //= 0; | ||
| 1312 | $verbosity //= 0; | ||
| 1313 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1314 | my $whoami = ( caller(0) )[3]; | ||
| 1315 | if( ! defined $firefoxmarionettecookies ){ $firefoxmarionettecookies = [] } | ||
| 1316 | |||
| 1317 | # for better control we will loop through the cookies, pre-process, | ||
| 1318 | # convert to string and load into the HTTP::CookieJar. | ||
| 1319 | # The alternative is to convert to string (with httpcookies2setcookies()) | ||
| 1320 | # and load into the ARRAY of Firefox::Marionette::Cookie | ||
| 1321 | # but we will not be able to preprocess which is essential | ||
| 1322 | |||
| 1323 | # below code shamelessly borrowed from HTTP::Cookies::as_string() : | ||
| 1324 | # https://metacpan.org/dist/HTTP-Cookies/source/lib/HTTP/Cookies.pm#L568 | ||
| 1325 | # NOTE: It adds extra quotes, e.g. in path="/" or expires="xyz" | ||
| 1326 | # we have code to remove these but ... | ||
| 1327 | $httpcookies->scan(sub { | ||
| 1328 | my($version,$key,$val,$_path,$domain,$port, | ||
| 1329 | $path_spec,$secure,$_expires,$discard,$rest) = @_; | ||
| 1330 | return if $discard && $skip_discard; | ||
| 1331 | my @h = ($key, $val); | ||
| 1332 | |||
| 1333 | my $path = $_path; if( defined $path ){ $path =~ s/^"//; $path =~ s/"$// } else { $path = '' } | ||
| 1334 | # this can be undef, what do we do? set it to 10 years from now | ||
| 1335 | # it needs a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. | ||
| 1336 | my $expires = $_expires; | ||
| 1337 | if( defined $_expires ){ | ||
| 1338 | $expires = $_expires; | ||
| 1339 | $expires =~ s/^"//; | ||
| 1340 | $expires =~ s/"$// | ||
| 1341 | } else { | ||
| 1342 | # No, leave undef expires as it is, it means session cookies | ||
| 1343 | # #$expires = HTTP::Date::time2isoz(time()+365*24*60*60*10); | ||
| 1344 | # # no, make it a bit more random! | ||
| 1345 | # #$expires = time() + 315334161 + int(rand(6000)); #315360000; | ||
| 1346 | # $expires = 0; | ||
| 1347 | # print STDERR "${whoami}, line ".__LINE__." (via $parent): warning, HTTP::Cookies cookie field 'expires' is undefined and setting it to something large ($expires) ...\n"; | ||
| 1348 | } | ||
| 1349 | |||
| 1350 | # quotes? | ||
| 1351 | $key =~ s/"//g; | ||
| 1352 | |||
| 1353 | my %ffparams = ( | ||
| 1354 | "name" => $key, | ||
| 1355 | "value" => $val, | ||
| 1356 | "path" => $path, | ||
| 1357 | "domain" => $domain, | ||
| 1358 | "secure" => (defined($secure) && ($secure==1)) ? 1 : 0, | ||
| 1359 | "expiry" => $expires, | ||
| 1360 | "same_site" => 'None', # None, Lax, Strict | ||
| 1361 | "http_only" => 0, | ||
| 1362 | ); | ||
| 1363 | my $ff = new_firefoxmarionettecookie(\%ffparams, $skip_discard, $verbosity); | ||
| 1364 | if( ! defined $ff ){ print STDERR "--begin input HTTP::Cookies:\n".$httpcookies."\n--end cookies.\n--begin ".'Firefox::Marionette::Cookie->new()'." parameters:\n".perl2dump(\%ffparams)."--end parameters.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'Firefox::Marionette::Cookie->new()'." has failed for above parameters produced by one item in the input HTTP::Cookies object.\n"; return undef } | ||
| 1365 | if( ! defined merge_firefoxmarionettecookies($ff, $firefoxmarionettecookies, $verbosity) ){ print STDERR "$0 : error, call to ".'merge_firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 1366 | }); | ||
| 1367 | return $firefoxmarionettecookies; | ||
| 1368 | } | ||
| 1369 | |||
| 1370 | # we also support a single Firefox::Marionette::Cookie object as well as an array of them | ||
| 1371 | sub clone_cookies { | ||
| 1372 | my ($w, $verbosity) = @_; | ||
| 1373 | $verbosity //= 0; | ||
| 1374 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1375 | my $whoami = ( caller(0) )[3]; | ||
| 1376 | |||
| 1377 | my $r = ref($w); | ||
| 1378 | if( $r eq 'ARRAY' ){ | ||
| 1379 | return [] if scalar(@$w) == 0; | ||
| 1380 | if( ref($w->[0]) eq 'Firefox::Marionette::Cookie' ){ return clone_firefoxmarionettecookies($w, $verbosity) } | ||
| 1381 | else { | ||
| 1382 | return clone_setcookies($w, $verbosity) | ||
| 1383 | } | ||
| 1384 | } elsif( $r eq 'Firefox::Marionette::Cookie' ){ return clone_firefoxmarionettecookie($w, $verbosity) } | ||
| 1385 | elsif( $r eq 'HTTP::Cookies' ){ return clone_httpcookies($w, $verbosity) } | ||
| 1386 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return clone_httpcookiejar($w, $verbosity) } | ||
| 1387 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, don't know how to handle type '$r'.\n"; | ||
| 1388 | return undef # failed | ||
| 1389 | } | ||
| 1390 | sub clone_httpcookiejar { | ||
| 1391 | my ($httpcookiejar, $verbosity) = @_; | ||
| 1392 | $verbosity //= 0; | ||
| 1393 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1394 | my $whoami = ( caller(0) )[3]; | ||
| 1395 | |||
| 1396 | my $ret = HTTP::CookieJar->new(); | ||
| 1397 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1398 | |||
| 1399 | # this is not necessary as the code in HTTP::CookieJar::dump_cookies currently stands | ||
| 1400 | # but you never know when someone throws a die in there! | ||
| 1401 | my @cooks = eval { $httpcookiejar->dump_cookies() }; | ||
| 1402 | if( $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->dump_cookies()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 1403 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): found ".scalar(@cooks)." cookies in the input cookiejar and loading them ...\n" } | ||
| 1404 | $ret->load_cookies(@cooks); | ||
| 1405 | return $ret; | ||
| 1406 | } | ||
| 1407 | # just a single Firefox::Marionette::Cookie object | ||
| 1408 | sub clone_firefoxmarionettecookie { | ||
| 1409 | my ($firefoxmarionettecookie, $verbosity) = @_; | ||
| 1410 | $verbosity //= 0; | ||
| 1411 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1412 | my $whoami = ( caller(0) )[3]; | ||
| 1413 | |||
| 1414 | my %cparams = ( map { $_ => $firefoxmarionettecookie->$_->() } | ||
| 1415 | ('path', 'domain', 'secure', 'name', 'value', 'http_only', 'same_site', 'expiry') | ||
| 1416 | ); | ||
| 1417 | my $ret = new_firefoxmarionettecookie(\%cparams, undef, $verbosity); | ||
| 1418 | if( ! defined $ret ){ print STDERR perl2dump(\%cparams)."${whoami}, line ".__LINE__." (via $parent): error, call to ".'new_firefoxmarionettecookie()'." has failed for above parameters.\n"; return undef } | ||
| 1419 | if( $verbosity > 0 ){ print STDOUT "--begin cookie:\n".as_string_cookies($ret)."--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): cloned Firefox::Marionette::Cookie as above.\n" } | ||
| 1420 | return $ret; | ||
| 1421 | } | ||
| 1422 | # an ARRAY of Firefox::Marionette::Cookie objects | ||
| 1423 | sub clone_firefoxmarionettecookies { | ||
| 1424 | my ($firefoxmarionettecookies, $verbosity) = @_; | ||
| 1425 | $verbosity //= 0; | ||
| 1426 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1427 | my $whoami = ( caller(0) )[3]; | ||
| 1428 | |||
| 1429 | my @ret; | ||
| 1430 | for my $acookie (@$firefoxmarionettecookies){ | ||
| 1431 | my $a_cloned_cookie = clone_firefoxmarionettecookie($acookie, $verbosity); | ||
| 1432 | if( ! defined $a_cloned_cookie ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'clone_firefoxmarionettecookie()'." has failed.\n"; return undef } | ||
| 1433 | push @ret, $a_cloned_cookie; | ||
| 1434 | } | ||
| 1435 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".as_string_cookies(\@ret)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): cloned an ARRAY of Firefox::Marionette::Cookie objects as above.\n" } | ||
| 1436 | return \@ret; | ||
| 1437 | } | ||
| 1438 | |||
| 1439 | sub clone_httpcookies { | ||
| 1440 | my ($httpcookies, $skip_discard, $verbosity) = @_; | ||
| 1441 | $skip_discard //= 0; | ||
| 1442 | $verbosity //= 0; | ||
| 1443 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1444 | my $whoami = ( caller(0) )[3]; | ||
| 1445 | |||
| 1446 | my $ret = HTTP::Cookies->new(); | ||
| 1447 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 1448 | |||
| 1449 | my $rrr = eval { | ||
| 1450 | $httpcookies->scan( | ||
| 1451 | sub { | ||
| 1452 | my($version, | ||
| 1453 | $key,$val,$path,$domain,$port, | ||
| 1454 | $path_spec,$secure,$expires,$discard,$rest | ||
| 1455 | ) = @_; | ||
| 1456 | return if $discard && $skip_discard; | ||
| 1457 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 1458 | # requires $maxage! ouch! | ||
| 1459 | my $maxage = $expires - time(); | ||
| 1460 | my $rr = eval { $ret->set_cookie( | ||
| 1461 | $version,$key,$val,$path,$domain, | ||
| 1462 | $port,$path_spec,$secure,$maxage,$discard, | ||
| 1463 | $rest # << a hashref | ||
| 1464 | ) }; | ||
| 1465 | if( ! defined($rr) || $@ ){ die 'scan()'." callback : error, call to ".'HTTP::Cookies->set_cookie()'." has failed for these values: $version,$key,$val,$path,$domain,$port,$path_spec,$secure,$maxage,$discard,$rest".(defined($@)?" with this exception: $@":".").").\n"; } | ||
| 1466 | } | ||
| 1467 | ); 1 | ||
| 1468 | }; | ||
| 1469 | if( ! defined($rrr) || ($rrr!=1) || $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::scan()'." has failed with this exception: $@\n"; return undef } | ||
| 1470 | return $ret; | ||
| 1471 | } | ||
| 1472 | sub clone_setcookies { return [ @{ $_[0] } ] } | ||
| 1473 | |||
| 1474 | # Convenience method to merge two cookiejars (of the same type atm) | ||
| 1475 | # It returns the merged cookiejar of the two input cookies on succes, | ||
| 1476 | # It returns undef on failure | ||
| 1477 | # $skip_discard may not apply to all cookiejar types | ||
| 1478 | sub merge_cookies { | ||
| 1479 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 1480 | $verbosity //= 0; | ||
| 1481 | $skip_discard //=0; | ||
| 1482 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1483 | my $whoami = ( caller(0) )[3]; | ||
| 1484 | my $r = ref($obj1); | ||
| 1485 | if( $r ne ref($obj2) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of the same type/class. The first one is '$r' but the second is '".ref($obj2)."'.\n"; return undef } | ||
| 1486 | |||
| 1487 | if( $r eq 'ARRAY' ){ | ||
| 1488 | return [ @$obj1 ] if scalar(@$obj2) == 0; | ||
| 1489 | return [ @$obj2 ] if scalar(@$obj1) == 0; | ||
| 1490 | if( ref($obj1->[0]) eq 'Firefox::Marionette::Cookie' ){ return merge_firefoxmarionettecookies($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 1491 | else { | ||
| 1492 | return merge_setcookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 1493 | } | ||
| 1494 | } elsif( $r eq 'HTTP::Cookies' ){ return merge_httpcookies($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 1495 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return merge_httpcookiejar($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 1496 | print STDERR 'merge_cookies()'.", line ".__LINE__." : error, don't know how to handle type '$r'.\n"; | ||
| 1497 | return undef # failed | ||
| 1498 | } | ||
| 1499 | # It appends httpcookies_src into httpcookies_dst | ||
| 1500 | # and returns httpcookies_dst. | ||
| 1501 | sub merge_httpcookies { | ||
| 1502 | my ($httpcookies_src, $httpcookies_dst, $skip_discard, $verbosity) = @_; | ||
| 1503 | $skip_discard //= 0; | ||
| 1504 | $verbosity //= 0; | ||
| 1505 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1506 | my $whoami = ( caller(0) )[3]; | ||
| 1507 | |||
| 1508 | my $rrr = eval { | ||
| 1509 | $httpcookies_src->scan( | ||
| 1510 | sub { | ||
| 1511 | my($version, | ||
| 1512 | $key,$val,$path,$domain,$port, | ||
| 1513 | $path_spec,$secure,$expires,$discard,$rest | ||
| 1514 | ) = @_; | ||
| 1515 | return if $discard && $skip_discard; | ||
| 1516 | my $rr = eval { $httpcookies_dst->set_cookie( | ||
| 1517 | $version,$key,$val,$path,$domain,$port, | ||
| 1518 | $path_spec,$secure,$expires,$discard, | ||
| 1519 | $rest # <<< hashref | ||
| 1520 | ) }; | ||
| 1521 | if( ! defined($rr) || $@ ){ die 'scan()'." callback : error, call to ".'HTTP::Cookies->set_cookie()'." has failed for these values: $version,$key,$val,$path,$domain,$port,$path_spec,$secure,$expires,$discard,$rest\n"; } | ||
| 1522 | } | ||
| 1523 | ); 1 | ||
| 1524 | }; | ||
| 1525 | if( ! defined($rrr) || ($rrr!=1) || $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::scan()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 1526 | return $httpcookies_dst; | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | # It appends httpcookies_src into httpcookies_dst | ||
| 1530 | # and returns httpcookies_dst. | ||
| 1531 | sub merge_httpcookiejar { | ||
| 1532 | my ($httpcookiejar_src, $httpcookiejar_dst, $skip_discard, $verbosity) = @_; | ||
| 1533 | $verbosity //= 0; | ||
| 1534 | $skip_discard //= 0; | ||
| 1535 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1536 | my $whoami = ( caller(0) )[3]; | ||
| 1537 | |||
| 1538 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($httpcookiejar_src)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($httpcookiejar_dst)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 1539 | |||
| 1540 | my @cooks = eval { $httpcookiejar_src->dump_cookies() }; | ||
| 1541 | if( $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->dump_cookies()'." has failed".(defined($@)?"".(defined($@)?" with this exception: $@":".").").\n":".").")\n"; return undef } | ||
| 1542 | my $ret = eval { $httpcookiejar_dst->load_cookies(@cooks) }; | ||
| 1543 | if( ! defined($ret) || $@ ){ print STDERR "--begin cookies:\n@cooks\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar::load_cookies()'." has failed for above cookies: $@\n"; print Devel::StackTrace->new->as_string; return undef } | ||
| 1544 | return $httpcookiejar_dst; | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | # makes them unique! | ||
| 1548 | # it removes duplicate cookie strings | ||
| 1549 | sub merge_setcookies { | ||
| 1550 | return [ keys %{ { map { $_ => 1 } @{ $_[0] }, @{ $_[1] } } } ] | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | # we are appending $src into @$dst | ||
| 1554 | # only uniqune cookie names+path+domain will be there. | ||
| 1555 | # the ones in src will overwrite same in @$dst | ||
| 1556 | # we can have $src to be a single Firefox::Marionette::Cookie | ||
| 1557 | # BUT $dst must be an ARRAY (to store Firefox::Marionette::Cookie) | ||
| 1558 | sub merge_firefoxmarionettecookies { | ||
| 1559 | my ($src, $dst) = @_; | ||
| 1560 | |||
| 1561 | my @src = (ref($src) eq 'ARRAY') ? @$src : ($src); | ||
| 1562 | |||
| 1563 | my $shrimp = [ values %{ { map { join('!!!', $_->name(), $_->path(), $_->domain()) => $_ } @$dst, @src } } ]; | ||
| 1564 | |||
| 1565 | # we need to keep the arrayref, so empty the array and push the shrimps in | ||
| 1566 | $#$dst = -1; | ||
| 1567 | push @$dst, @$shrimp; | ||
| 1568 | return $dst; # return but also in @$dst | ||
| 1569 | } | ||
| 1570 | |||
| 1571 | # Insert an array of Set-Cookie strings into an | ||
| 1572 | # optionally, user-supplied or fresh HTTP::CookieJar | ||
| 1573 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 1574 | # $httpcookiejar is optional, if given, then cookies | ||
| 1575 | # will be appended in it and return it. Else | ||
| 1576 | # a fresh HTTP::CookieJar will be created, loaded and returned. | ||
| 1577 | # It returns undef on failure. | ||
| 1578 | sub setcookies2httpcookiejar { | ||
| 1579 | my ($setcookies, $httpcookiejar, $verbosity) = @_; | ||
| 1580 | $verbosity //= 0; | ||
| 1581 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1582 | my $whoami = ( caller(0) )[3]; | ||
| 1583 | if( ! defined $httpcookiejar ){ | ||
| 1584 | if( ! defined($httpcookiejar = HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1585 | } | ||
| 1586 | $httpcookiejar->load_cookies(@$setcookies); | ||
| 1587 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_setcookies($setcookies)." Set-Cookies into HTTP::CookieJar which now has ".count_httpcookiejar($httpcookiejar)." cookies.\n" } | ||
| 1588 | return $httpcookiejar; | ||
| 1589 | } | ||
| 1590 | |||
| 1591 | # Insert an array of Set-Cookie strings into an | ||
| 1592 | # optionally, user-supplied (appending) | ||
| 1593 | # or fresh Firefox::Marionette::Cookies | ||
| 1594 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 1595 | # $httpcookiejar is optional, if given, then cookies | ||
| 1596 | # will be appended in it and return it. Else | ||
| 1597 | # a fresh HTTP::CookieJar will be created, loaded and returned. | ||
| 1598 | # It returns undef on failure. | ||
| 1599 | sub setcookies2firefoxmarionettecookies { | ||
| 1600 | my ($setcookies, $firefoxmarionettecookies, $verbosity) = @_; | ||
| 1601 | $verbosity //= 0; | ||
| 1602 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1603 | my $whoami = ( caller(0) )[3]; | ||
| 1604 | if( ! defined $firefoxmarionettecookies ){ $firefoxmarionettecookies = [] } | ||
| 1605 | |||
| 1606 | # this creates a lot of failed tests and discards cookies for strange reasons, | ||
| 1607 | # DO NOT USE | ||
| 1608 | # make sure your setcookies have their Domain starting with a dot! | ||
| 1609 | # my $httpcookies = setcookies2httpcookies($setcookies, undef, $verbosity); | ||
| 1610 | # if( ! defined $httpcookies ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2httpcookies()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 1611 | # # and now convert to ff | ||
| 1612 | # if( ! defined httpcookies2firefoxmarionettecookies($httpcookies, $firefoxmarionettecookies, undef, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n--begin HTTP::Cookies :\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2firefoxmarionettecookies()'." has failed for above intermediate cookie. The input cookie is also above.\n"; return undef } | ||
| 1613 | |||
| 1614 | # USE THIS: | ||
| 1615 | my $httpcookiejar = setcookies2httpcookiejar($setcookies, undef, $verbosity); | ||
| 1616 | if( ! defined $httpcookiejar ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookies2httpcookiejar()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 1617 | # and now convert to ff | ||
| 1618 | if( ! defined httpcookiejar2firefoxmarionettecookies($httpcookiejar, $firefoxmarionettecookies, undef, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n--begin HTTP::Cookies :\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2firefoxmarionettecookies()'." has failed for above intermediate cookie. The input cookie is also above.\n"; return undef } | ||
| 1619 | |||
| 1620 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_setcookies($setcookies)." Set-Cookies into an array of Firefox::Marionette::Cookie which now has ".count_firefoxmarionettecookies($firefoxmarionettecookies)." cookies.\n" } | ||
| 1621 | return $firefoxmarionettecookies; | ||
| 1622 | } | ||
| 1623 | |||
| 1624 | # Single Set Cookie to Firefox::Marionette::Cookie | ||
| 1625 | # into a fresh or user-supplied (overwrite its contents) | ||
| 1626 | # Firefox::Marionette::Cookie. | ||
| 1627 | sub setcookie2firefoxmarionettecookie { | ||
| 1628 | my ($setcookie, $firefoxmarionettecookie, $verbosity) = @_; | ||
| 1629 | $verbosity //= 0; | ||
| 1630 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1631 | my $whoami = ( caller(0) )[3]; | ||
| 1632 | |||
| 1633 | die "fix me it is not a string but ".ref($setcookie) unless ref($setcookie)eq''; | ||
| 1634 | |||
| 1635 | my $parsed_setcookie_hash = setcookie2hash($setcookie, $verbosity); | ||
| 1636 | if( ! defined $parsed_setcookie_hash ){ print STDERR "--begin SetCookie:\n${setcookie}\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookie2hash()'." has failed for above SetCookie string.\n"; return undef } | ||
| 1637 | |||
| 1638 | my %ffcookpar = (%$parsed_setcookie_hash); | ||
| 1639 | if( ! exists($ffcookpar{'http_only'}) ){ $ffcookpar{'http_only'} = 0 } | ||
| 1640 | if( ! exists($ffcookpar{'same_site'}) ){ $ffcookpar{'same_site'} = 'None' } | ||
| 1641 | |||
| 1642 | if( ! defined $firefoxmarionettecookie ){ | ||
| 1643 | if( ! defined($firefoxmarionettecookie=new_firefoxmarionettecookie(\%ffcookpar, undef, $verbosity)) ){ print STDERR perl2dump(\%ffcookpar)."${whoami}, line ".__LINE__." (via $parent): error, call to ".'new_firefoxmarionettecookie()'." has failed for above Set Cookie data (1 cookie).\n"; return undef } | ||
| 1644 | } else { | ||
| 1645 | for (keys %ffcookpar){ | ||
| 1646 | # don't like this but ... | ||
| 1647 | if( exists $firefoxmarionettecookie->{$_} ){ | ||
| 1648 | $firefoxmarionettecookie->{$_} = $ffcookpar{$_} | ||
| 1649 | } | ||
| 1650 | } | ||
| 1651 | } | ||
| 1652 | if( $verbosity > 0 ){ print STDOUT "--begin Set Cookie:\n".perl2dump($setcookie)."\n--end Set Cookie.\n--begin Firefox::Marionette::Cookie:\n".perl2dump($firefoxmarionettecookie)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): done converted Set Cookies to Firefox::Marionette::Cookies.\n" } | ||
| 1653 | return $firefoxmarionettecookie; | ||
| 1654 | } | ||
| 1655 | |||
| 1656 | # not all input parameters will be passed on to the calling subs | ||
| 1657 | # The return will be undef on failure or an integer (>=0) on success | ||
| 1658 | sub count_cookies { | ||
| 1659 | my ($w, $skip_discard, $verbosity) = @_; | ||
| 1660 | $skip_discard //= 0; | ||
| 1661 | $verbosity //= 0; | ||
| 1662 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1663 | my $whoami = ( caller(0) )[3]; | ||
| 1664 | |||
| 1665 | my $r = ref($w); | ||
| 1666 | if( $r eq 'ARRAY' ){ | ||
| 1667 | # actually here we can just do return scalar(@$w) | ||
| 1668 | return 0 if scalar(@$w) == 0; | ||
| 1669 | if( ref($w->[0]) eq 'Firefox::Marionette::Cookie' ){ return count_firefoxmarionettecookies($w, $skip_discard, $verbosity) } | ||
| 1670 | else { | ||
| 1671 | return count_setcookies($w, $skip_discard, $verbosity) | ||
| 1672 | } | ||
| 1673 | } elsif( $r eq 'Firefox::Marionette::Cookie' ){ return 1 } | ||
| 1674 | elsif( $r eq 'HTTP::Cookies' ){ return count_httpcookies($w, $skip_discard, $verbosity) } | ||
| 1675 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return count_httpcookiejar($w, $skip_discard, $verbosity) } | ||
| 1676 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, input cookies type '$r' is not known. Known cookies types are 'HTTP::Cookies', 'HTTP::CookieJar', 'HTTP::CookieJar::LWP', array of SetCookie strings, array of 'Firefox::Marionette::Cookie'.\n"; | ||
| 1677 | print Devel::StackTrace->new->as_string; | ||
| 1678 | return undef # failure | ||
| 1679 | } | ||
| 1680 | sub count_httpcookies { | ||
| 1681 | my ($httpcookies, $skip_discard, $verbosity) = @_; | ||
| 1682 | $skip_discard //= 0; | ||
| 1683 | $verbosity //= 0; | ||
| 1684 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1685 | my $whoami = ( caller(0) )[3]; | ||
| 1686 | |||
| 1687 | return 0 unless defined $httpcookies; | ||
| 1688 | |||
| 1689 | my $count = 0; | ||
| 1690 | my $ret = eval { | ||
| 1691 | $httpcookies->scan( | ||
| 1692 | sub { | ||
| 1693 | my($version,$key,$val,$path,$domain,$port, | ||
| 1694 | $path_spec,$secure,$expires,$discard,$rest | ||
| 1695 | ) = @_; | ||
| 1696 | return if $discard && $skip_discard; | ||
| 1697 | $count++; | ||
| 1698 | } | ||
| 1699 | ); 1 | ||
| 1700 | }; # eval | ||
| 1701 | if( ! defined($ret) || ($ret!=1) || $@ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->scan()'." has failed".(defined($@)?"".(defined($@)?" with this exception: $@":".").").\n":".").")\n"; return undef } | ||
| 1702 | return $count; | ||
| 1703 | } | ||
| 1704 | |||
| 1705 | sub count_httpcookiejar { return scalar $_[0]->_all_cookies } | ||
| 1706 | |||
| 1707 | sub count_setcookies { return scalar @{ $_[0] } } | ||
| 1708 | |||
| 1709 | sub count_firefoxmarionettecookies { | ||
| 1710 | return 0 unless defined $_[0]; | ||
| 1711 | return scalar @{ $_[0] } | ||
| 1712 | } | ||
| 1713 | |||
| 1714 | # a SetCookie string converted to an array which can then | ||
| 1715 | # be passed into HTTP::Cookies::set_cookie | ||
| 1716 | sub setcookie2httpcookies_set_cookie_array { | ||
| 1717 | my ($setcookie, $verbosity) = @_; | ||
| 1718 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1719 | my $whoami = ( caller(0) )[3]; | ||
| 1720 | |||
| 1721 | my $parsed_setcookie = setcookie2hash($setcookie, $verbosity); | ||
| 1722 | if( ! defined $parsed_setcookie ){ print STDERR "--begin SetCookie:\n${setcookie}\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookie2hash()'." has failed for above SetCookie string.\n"; return undef } | ||
| 1723 | |||
| 1724 | my @parsed_setcookie = map { | ||
| 1725 | exists($parsed_setcookie->{$_}) ? $parsed_setcookie->{$_} : undef | ||
| 1726 | } ( | ||
| 1727 | 'version', | ||
| 1728 | 'name', 'value', 'path', 'domain', 'port', | ||
| 1729 | 'path_spec', 'secure', 'max-age', 'discard', 'rest' | ||
| 1730 | ); | ||
| 1731 | |||
| 1732 | return \@parsed_setcookie; | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | # a SetCookie string converted to a hash, keyed on the attributes | ||
| 1736 | sub setcookie2hash { | ||
| 1737 | my ($setcookie, $verbosity) = @_; | ||
| 1738 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1739 | my $whoami = ( caller(0) )[3]; | ||
| 1740 | |||
| 1741 | my $new_setcookie = $setcookie; | ||
| 1742 | if( $new_setcookie !~ /;\s*Domain=(\..*?)\s*;/i ){ | ||
| 1743 | if( $verbosity > 0 ){ print STDERR "--begin SetCookie:\n${setcookie}\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, above SetCookie does not contain a Domain field or Domain does not start with a dot (.). I AM FIXING IT.\n" } | ||
| 1744 | $new_setcookie =~ s/(;\s*)Domain=(.+?)(\s*;)/${1}Domain=.${2}${3}/; | ||
| 1745 | } | ||
| 1746 | $new_setcookie =~ /;\s*Domain=(.*?)\s*;/i; | ||
| 1747 | |||
| 1748 | my $parsed_setcookie = HTTP::CookieJar::_parse_cookie($new_setcookie); | ||
| 1749 | |||
| 1750 | # from HTTP/Cookies.pm, set_cookie signature: | ||
| 1751 | # my($version, | ||
| 1752 | # $key, $val, $path, $domain, $port, | ||
| 1753 | # $path_spec, $secure, $maxage, $discard, $rest) = @_; | ||
| 1754 | |||
| 1755 | # it expects a max-age but we could have expires | ||
| 1756 | # and expires can be an epoch or a string date | ||
| 1757 | if( exists $parsed_setcookie->{'expires'} ){ | ||
| 1758 | if( ! defined $parsed_setcookie->{'expires'} ){ $parsed_setcookie->{'max-age'} = undef } | ||
| 1759 | elsif( $parsed_setcookie->{'expires'}=~ /^\d+$/ ){ | ||
| 1760 | $parsed_setcookie->{'max-age'} = $parsed_setcookie->{'expires'} - DateTime->now()->epoch(); | ||
| 1761 | } else { | ||
| 1762 | $parsed_setcookie->{'max-age'} = HTTP::Date::str2time($parsed_setcookie->{'expires'}) - DateTime->now()->epoch(); | ||
| 1763 | } | ||
| 1764 | delete $parsed_setcookie->{'expires'}; # does not care if you do | ||
| 1765 | } | ||
| 1766 | if( ! exists($parsed_setcookie->{'secure'}) || ! defined($parsed_setcookie->{'secure'}) ){ | ||
| 1767 | $parsed_setcookie->{'secure'} = 0; | ||
| 1768 | } | ||
| 1769 | |||
| 1770 | return $parsed_setcookie; | ||
| 1771 | } | ||
| 1772 | |||
| 1773 | |||
| 1774 | # Convert an array of Set-Cookie strings into a fresh | ||
| 1775 | # or user-supplied (this is appending) HTTP::Cookies object | ||
| 1776 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 1777 | # $httpcookiejar is optional, if given, then cookies | ||
| 1778 | # will be appended in it and return it. Else | ||
| 1779 | # a fresh HTTP::Cookies will be created, loaded and returned. | ||
| 1780 | # It returns undef on failure. | ||
| 1781 | sub setcookies2httpcookies { | ||
| 1782 | my ($setcookies, $httpcookies, $verbosity) = @_; | ||
| 1783 | $verbosity //= 0; | ||
| 1784 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1785 | my $whoami = ( caller(0) )[3]; | ||
| 1786 | if( ! defined $httpcookies ){ | ||
| 1787 | if( ! defined($httpcookies = HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 1788 | } | ||
| 1789 | for my $asc (@$setcookies){ | ||
| 1790 | if( $verbosity > 1 ){ | ||
| 1791 | my $parsed_setcookie_hash = setcookie2hash($asc, $verbosity); | ||
| 1792 | if( ! defined $parsed_setcookie_hash ){ print STDERR "--begin SetCookie:\n${asc}\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookie2hash()'." has failed for above SetCookie string.\n"; return undef } | ||
| 1793 | print STDOUT perl2dump($parsed_setcookie_hash)."${whoami}, line ".__LINE__." (via $parent): parse this SetCookie into the above hash: ${asc}\n"; | ||
| 1794 | } | ||
| 1795 | |||
| 1796 | my $parsed_setcookie_array = setcookie2httpcookies_set_cookie_array($asc, $verbosity); | ||
| 1797 | if( ! defined $parsed_setcookie_array ){ print STDERR "--begin SetCookie:\n${asc}\n--end cookie.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'setcookie2httpcookies_set_cookie_array()'." has failed for above SetCookie string.\n"; return undef } | ||
| 1798 | |||
| 1799 | # from HTTP/Cookies.pm, set_cookie signature: | ||
| 1800 | # my($version, | ||
| 1801 | # $key, $val, $path, $domain, $port, | ||
| 1802 | # $path_spec, $secure, $maxage, $discard, $rest) = @_; | ||
| 1803 | |||
| 1804 | $httpcookies->set_cookie(@$parsed_setcookie_array); | ||
| 1805 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserting 1 Set-Cookies into HTTP::Cookies which now has ".count_httpcookies($httpcookies, undef, $verbosity)." cookies.\n" } | ||
| 1806 | |||
| 1807 | # this way is bogus, what with response and request and url and all | ||
| 1808 | # my $response = HTTP::Response->new(200); | ||
| 1809 | # my $request = HTTP::Request->new(GET => $url); | ||
| 1810 | # $response->request($request); | ||
| 1811 | # $response->header('Set-Cookie2', $newasc); # TODO: does it push multiple Cookie headers or overrides? | ||
| 1812 | # if( ! defined $httpcookies->extract_cookies($response) ){ print STDERR "--begin cookies:\n".as_string_setcookies($setcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->extract_cookies()'." has failed for above Set-Cookies.\n"; return undef } | ||
| 1813 | # if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserting 1 Set-Cookies into HTTP::Cookies which now has ".count_httpcookies($httpcookies, undef, $verbosity)." cookies.\n" } | ||
| 1814 | } | ||
| 1815 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): done all, inserted ".count_setcookies($setcookies)." Set-Cookies into HTTP::Cookies which now has ".count_httpcookies($httpcookies, undef, $verbosity)." cookies.\n" } | ||
| 1816 | return $httpcookies; | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | # Array of Firefox::Marionette::Cookie to array of cookies. | ||
| 1820 | # Each of the output cookie resembles a Set-Cookie header and, | ||
| 1821 | # logically, it can be loaded by any cookies container. | ||
| 1822 | # It converts the specified Array of Firefox::Marionette::Cookie object into | ||
| 1823 | # an array of cookies which can then be loaded into other exotic | ||
| 1824 | # cookie containers. | ||
| 1825 | # It returns the cookies as ARRAY_REF. | ||
| 1826 | # for Set-Cookie format see: | ||
| 1827 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie | ||
| 1828 | sub firefoxmarionettecookies2setcookies { | ||
| 1829 | my ($firefoxmarionettecookies, $setcookies, $skip_discard, $verbosity) = @_; | ||
| 1830 | $skip_discard //= 0; | ||
| 1831 | $verbosity //= 0; | ||
| 1832 | |||
| 1833 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1834 | my $whoami = ( caller(0) )[3]; | ||
| 1835 | |||
| 1836 | if( ! defined $setcookies ){ $setcookies = [] } | ||
| 1837 | |||
| 1838 | for my $afc (@$firefoxmarionettecookies){ | ||
| 1839 | my @h = ($afc->name, $afc->value); | ||
| 1840 | push @h, 'path', $afc->path; | ||
| 1841 | push @h, 'domain', $afc->domain; | ||
| 1842 | # no port in F:M:C | ||
| 1843 | # boolean, it can be present or not present, it has no value like secure=... | ||
| 1844 | push(@h, 'secure') if $afc->secure; | ||
| 1845 | if( defined $afc->expiry ){ | ||
| 1846 | # we can have expires as Date or max-age as epoch | ||
| 1847 | push @h, 'expires', HTTP::Date::time2isoz($afc->expiry) | ||
| 1848 | } | ||
| 1849 | # SameSite can be one of: Lax, None, Strict | ||
| 1850 | if( $afc->same_site !~ /^(None|Lax|Strict)$/ ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, field 'same_site' (".$afc->same_site.") is not one of: 'Lax', 'None', 'Strict'.\n"; return undef } | ||
| 1851 | push @h, 'SameSite', $afc->same_site; | ||
| 1852 | # boolean, it can be present or not present, it has no value like secure=... | ||
| 1853 | push(@h, 'HttpOnly') if $afc->http_only; | ||
| 1854 | |||
| 1855 | my $cookstr = HTTP::Headers::Util::join_header_words(\@h); | ||
| 1856 | |||
| 1857 | # and yet again we suffer from the quotes, perhaps HTTP::CookieJar::load_cookies() | ||
| 1858 | # assumes no quotes?! | ||
| 1859 | $cookstr =~ s/\bpath="([^"]*)";/path=$1;/; | ||
| 1860 | $cookstr =~ s/\bexpires="([^"]*)";/expires=$1;/; | ||
| 1861 | #push(@$setcookies, "Set-Cookie3: " . $cookstr); # this is for a header? | ||
| 1862 | push(@$setcookies, $cookstr); | ||
| 1863 | } | ||
| 1864 | return $setcookies; | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | # Convert an array of Firefox::Marionette::Cookie objects into | ||
| 1868 | # a fresh or user-supplied (this is appending) | ||
| 1869 | # HTTP::CookieJar and return it. Optionally specifying $verbosity (as integer). | ||
| 1870 | # $httpcookiejar is optional, if given, then cookies | ||
| 1871 | # will be appended in it and return it. Else | ||
| 1872 | # a fresh HTTP::CookieJar will be created, loaded and returned. | ||
| 1873 | # It returns undef on failure. | ||
| 1874 | sub firefoxmarionettecookies2httpcookiejar { | ||
| 1875 | my ($firefoxmarionettecookies, $httpcookiejar, $skip_discard, $verbosity) = @_; | ||
| 1876 | $skip_discard //= 0; | ||
| 1877 | $verbosity //= 0; | ||
| 1878 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1879 | my $whoami = ( caller(0) )[3]; | ||
| 1880 | if( ! defined $httpcookiejar ){ | ||
| 1881 | if( ! defined($httpcookiejar = HTTP::CookieJar->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1882 | } | ||
| 1883 | # my $httpcookies = firefoxmarionettecookies2httpcookies($firefoxmarionettecookies, undef, $skip_discard, $verbosity); | ||
| 1884 | # if( ! defined $httpcookies ){ print STDERR "--begin Firefox::Marionette::Cookie:\n".as_string_firefoxmarionettecookies($firefoxmarionettecookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'firefoxmarionettecookies2httpcookies()'." has failed for above Firefox::Marionette::Cookie data.\n"; return undef } | ||
| 1885 | # if( ! defined httpcookies2httpcookiejar($httpcookies, $httpcookiejar, $verbosity) ){ print STDERR "--begin Set-Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2httpcookiejar()'." has failed for above Set-Cookies array (which was supplied by the user as input parameter).\n"; return undef } | ||
| 1886 | # if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_firefoxmarionettecookies($firefoxmarionettecookies)." Firefox::Marionette::Cookie(s) into HTTP::CookieJar which now has ".count_httpcookiejar($httpcookiejar, undef, $verbosity)." cookies.\n" } | ||
| 1887 | |||
| 1888 | for my $c ( | ||
| 1889 | ref($firefoxmarionettecookies)eq'ARRAY' | ||
| 1890 | ? @$firefoxmarionettecookies | ||
| 1891 | : ($firefoxmarionettecookies) # it can be a single cookie not an ARRAY of Firefox::Marionette::Cookie | ||
| 1892 | ){ | ||
| 1893 | my $path = $c->path; if( defined $path ){ $path =~ s/^"//; $path =~ s/"$// } else { $path = '' } | ||
| 1894 | my $value = $c->value; if( defined $value ){ $value =~ s/^"//; $value =~ s/"$// } else { $value = '' } | ||
| 1895 | my $expires = $c->expiry; | ||
| 1896 | if( defined $expires ){ | ||
| 1897 | $expires =~ s/^"//; | ||
| 1898 | $expires =~ s/"$// | ||
| 1899 | } else { | ||
| 1900 | # No, leave undef expires as it is, it means session cookies | ||
| 1901 | # # no, make it a bit more random! | ||
| 1902 | # #$expires = time() + 315334161 + int(rand(6000)); #315360000; | ||
| 1903 | # $expires = 0; | ||
| 1904 | # print STDERR "${whoami}, line ".__LINE__." (via $parent): warning, HTTP::Cookies cookie field 'expires' is undefined and setting it to something large ($expires) ...\n"; | ||
| 1905 | } | ||
| 1906 | my @h = ($c->name, $value); | ||
| 1907 | push(@h, "path", $path); | ||
| 1908 | push(@h, "domain" => $c->domain); | ||
| 1909 | push(@h, "expires" => $expires); # derived from $c->expiry | ||
| 1910 | push(@h, "secure" => $c->secure) if $c->secure; | ||
| 1911 | #push(@h, "port" => $c->port) if $c->port; | ||
| 1912 | #push(@h, "path_spec" => undef) if $c->path_spec; | ||
| 1913 | #push(@h, "discard" => undef) if $discard; | ||
| 1914 | #push(@h, "version" => $version); | ||
| 1915 | my $cookstr = HTTP::Headers::Util::join_header_words(\@h); | ||
| 1916 | |||
| 1917 | # and yet again we suffer from the quotes, perhaps HTTP::CookieJar::load_cookies() | ||
| 1918 | # assumes no quotes?! | ||
| 1919 | $cookstr =~ s/\bpath="([^"]*)";/path=$1;/; | ||
| 1920 | $cookstr =~ s/\bexpires="([^"]*)";/expires=$1;/; | ||
| 1921 | |||
| 1922 | # now load it, BUT!: | ||
| 1923 | # create a new jar because we need to process the cookie added | ||
| 1924 | # if appending, it will be lost in that madness | ||
| 1925 | my $htc = HTTP::CookieJar->new(); | ||
| 1926 | if( ! defined $htc ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->new()'." has failed.\n"; return undef } | ||
| 1927 | if( ! defined $htc->load_cookies($cookstr) ){ print STDERR "--begin cookie:\n".$cookstr."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::CookieJar->load_cookies()'." has failed for above cookie (which was produced by the HTTP::Cookies object supplied by the user as input parameter).\n"; return undef } | ||
| 1928 | # delete httponly. Note: there is only 1 cookie in here now, this is guaranteed, so [0] is OK! | ||
| 1929 | my $v = $htc->{store}; | ||
| 1930 | for (1..3){ # go does 3 levels from 'store'->domain->path->key | ||
| 1931 | $v = $v->{ (keys %$v)[0] } | ||
| 1932 | } | ||
| 1933 | delete $v->{'httponly'}; | ||
| 1934 | # leading dot in domain? the HTTP::CookieJar will have removed it. | ||
| 1935 | # Reinstate it. No leave it, we can't do this everywhere | ||
| 1936 | #if( $domain =~ /^\./ ){ $v->{domain} = '.' . $v->{domain} } | ||
| 1937 | # and append the result to the $httpcookiejar, which is returned | ||
| 1938 | if( ! defined merge_httpcookiejar($htc, $httpcookiejar, $verbosity) ){ print STDERR "$0 : error, call to ".'merge_httpcookiejar()'." has failed.\n"; return undef } | ||
| 1939 | } | ||
| 1940 | return $httpcookiejar; | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | # convert a HTTP::CookieJar into a fresh | ||
| 1944 | # or user-supplied (this means appending) HTTP::Cookies | ||
| 1945 | # optionally, user-supplied or fresh HTTP::CookieJar | ||
| 1946 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 1947 | # $httpcookiejar is optional, if given, then cookies | ||
| 1948 | # will be appended in it and return it. Else | ||
| 1949 | # a fresh HTTP::CookieJar will be created, loaded and returned. | ||
| 1950 | # It returns undef on failure. | ||
| 1951 | # NOTE: if expiry is <0 then the cookie will not show!!!!! | ||
| 1952 | sub httpcookiejar2httpcookies { | ||
| 1953 | my ($httpcookiejar, $httpcookies, $skip_discard, $verbosity) = @_; | ||
| 1954 | $skip_discard //= 0; # not used atm | ||
| 1955 | $verbosity //= 0; | ||
| 1956 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 1957 | my $whoami = ( caller(0) )[3]; | ||
| 1958 | if( ! defined $httpcookies ){ | ||
| 1959 | if( ! defined($httpcookies = HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | for my $c ($httpcookiejar->_all_cookies){ | ||
| 1963 | # signature of httpcookies->set_cookie() is this: | ||
| 1964 | #my($version, | ||
| 1965 | # $key, $val, $path, $domain, $port, | ||
| 1966 | # $path_spec, $secure, $maxage, $discard, $rest) = @_; | ||
| 1967 | # requires $maxage! ouch! | ||
| 1968 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 1969 | # requires $maxage! ouch! | ||
| 1970 | my $maxage = (exists($c->{'expires'}) && defined($c->{'expires'}) && ($c->{'expires'}>0) ) | ||
| 1971 | ? ($c->{'expires'} - time()) | ||
| 1972 | : undef | ||
| 1973 | ; | ||
| 1974 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): max-age calculated from 'expires' : ".(defined($maxage)?$maxage:"<NA>").".\n" } | ||
| 1975 | |||
| 1976 | my $path = $c->{'path'}; if( defined $path ){ $path =~ s/^"//; $path =~ s/"$// } else { $path = '' } | ||
| 1977 | my $value = $c->{'value'}; if( defined $value ){ $value =~ s/^"//; $value =~ s/"$// } else { $value = '' } | ||
| 1978 | my @params = ( | ||
| 1979 | undef, # $version? | ||
| 1980 | $c->{'name'}, # corresponds to $key | ||
| 1981 | $value,# $value without quotes | ||
| 1982 | $path, # $path without quotes | ||
| 1983 | $c->{'domain'}, # $domain | ||
| 1984 | undef, # no port | ||
| 1985 | # path_spec is boolean, 1 if path exists (I think!) | ||
| 1986 | defined($path) && ($path ne '') ? 1 : 0, | ||
| 1987 | # $secure | ||
| 1988 | exists($c->{'secure'}) ? $c->{'secure'} : undef, | ||
| 1989 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 1990 | # requires $maxage! ouch! | ||
| 1991 | $maxage, # derived from Expires | ||
| 1992 | exists($c->{'discard'}) ? $c->{'discard'} : undef, | ||
| 1993 | # rest is added below | ||
| 1994 | ); | ||
| 1995 | my %rest; | ||
| 1996 | # the $rest as a HASH_REF | ||
| 1997 | for ('httponly','hostonly','creation_time','last_access_time'){ | ||
| 1998 | next unless exists($c->{$_}) && defined($c->{$_}); | ||
| 1999 | $rest{$_} = $c->{$_}; | ||
| 2000 | } | ||
| 2001 | push @params, \%rest; | ||
| 2002 | my $ret = eval { $httpcookies->set_cookie(@params) }; | ||
| 2003 | if( ! defined($ret) || $@ ){ print STDERR "--begin cookies:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::CookieJar object".(defined($@)?" with this exception: $@":".").").\n"; print Devel::StackTrace->new->as_string; return undef } | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | # NOTE: if expires is <0 then the cookie will not show!!!!! | ||
| 2007 | |||
| 2008 | return $httpcookies; | ||
| 2009 | |||
| 2010 | if( 0 ){ | ||
| 2011 | # special case when _all_cookies returns nothing but {store} | ||
| 2012 | my $c = $httpcookiejar->{'store'}; | ||
| 2013 | my @k = keys %$c; | ||
| 2014 | for my $dK (@k){ | ||
| 2015 | $c = $c->{$dK}; # ->{'store'}{domain} | ||
| 2016 | @k = keys %$c; | ||
| 2017 | if( 0 == scalar @k ){ | ||
| 2018 | # special case, we have empty cookie content but we do have a domain and path | ||
| 2019 | # just set it empty except domain | ||
| 2020 | my @params = (undef) x 10; $params[4] = $dK; | ||
| 2021 | if( ! defined $httpcookies->set_cookie(@params) ){ print STDERR "--begin cookies:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::CookieJar object.\n"; return undef } | ||
| 2022 | # the result is nothing in its 'COOKIES' anyway | ||
| 2023 | next | ||
| 2024 | } | ||
| 2025 | for my $pK (@k){ | ||
| 2026 | $c = $c->{$pK}; # ->{'store'}{domain}->{path} | ||
| 2027 | @k = keys %$c; | ||
| 2028 | if( 0 == scalar @k ){ | ||
| 2029 | # special case, we have empty cookie content but we do have a domain and path | ||
| 2030 | # just set it empty except domain and path | ||
| 2031 | my @params = (undef) x 10; $params[4] = $dK; $params[3] = $pK; | ||
| 2032 | if( ! defined $httpcookies->set_cookie(@params) ){ print STDERR "--begin cookies:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::CookieJar object.\n"; return undef } | ||
| 2033 | # the result is nothing in its 'COOKIES' anyway | ||
| 2034 | next | ||
| 2035 | } | ||
| 2036 | for my $nK (@k){ | ||
| 2037 | $c = $c->{$nK}; # ->{'store'}{domain}->{path}->{name} | ||
| 2038 | my @k = keys %$c; | ||
| 2039 | if( 0 == scalar @k ){ | ||
| 2040 | # special case, we have empty cookie content but we do have a domain and path | ||
| 2041 | # just set it empty except domain and path and name | ||
| 2042 | my @params = (undef) x 10; $params[4] = $dK; $params[3] = $pK; $params[1] = $nK; | ||
| 2043 | if( ! defined $httpcookies->set_cookie(@params) ){ print STDERR "--begin cookies:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::CookieJar object.\n"; return undef } | ||
| 2044 | # the result is nothing in its 'COOKIES' anyway | ||
| 2045 | next | ||
| 2046 | } | ||
| 2047 | # cookie has some values | ||
| 2048 | #for my $c ($httpcookiejar->_all_cookies){ | ||
| 2049 | # signature of httpcookies->set_cookie() is this: | ||
| 2050 | #my($version, | ||
| 2051 | # $key, $val, $path, $domain, $port, | ||
| 2052 | # $path_spec, $secure, $maxage, $discard, $rest) = @_; | ||
| 2053 | # requires $maxage! ouch! | ||
| 2054 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 2055 | # requires $maxage! ouch! | ||
| 2056 | my $maxage = (exists($c->{'expires'}) && defined($c->{'expires'}) && ($c->{'expires'}>0) ) | ||
| 2057 | ? ($c->{'expires'} - time()) | ||
| 2058 | : undef | ||
| 2059 | ; | ||
| 2060 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): max-age calculated from expiry : ".(defined($maxage)?$maxage:"<NA>").".\n" } | ||
| 2061 | my @params = ( | ||
| 2062 | undef, # $version? | ||
| 2063 | $c->{'name'}, # corresponds to $key | ||
| 2064 | $c->{'value'},# $value | ||
| 2065 | $c->{'path'}, # $path | ||
| 2066 | $c->{'domain'}, # $domain | ||
| 2067 | undef, # no port | ||
| 2068 | # path_spec is boolean, 1 if path exists (I think!) | ||
| 2069 | exists($c->{'path'}) && defined($c->{'path'}) && ($c->{'path'}ne'') ? 1 : 0, | ||
| 2070 | exists($c->{'secure'}) ? $c->{'secure'} : undef, # $secure | ||
| 2071 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 2072 | # requires $maxage! ouch! | ||
| 2073 | $maxage, # derived from Expires | ||
| 2074 | exists($c->{'discard'}) ? $c->{'discard'} : undef, | ||
| 2075 | ); | ||
| 2076 | my %rest; | ||
| 2077 | # the $rest as a HASH_REF | ||
| 2078 | for ('httponly','hostonly','creation_time','last_access_time'){ | ||
| 2079 | next unless exists($c->{$_}) && defined($c->{$_}); | ||
| 2080 | $rest{$_} = $c->{$_}; | ||
| 2081 | } | ||
| 2082 | push @params, \%rest; | ||
| 2083 | if( ! defined $httpcookies->set_cookie(@params) ){ print STDERR "--begin cookies:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::CookieJar object.\n"; return undef } | ||
| 2084 | } # for name | ||
| 2085 | } # for path | ||
| 2086 | } # for domain | ||
| 2087 | } | ||
| 2088 | |||
| 2089 | } | ||
| 2090 | |||
| 2091 | # convert an array or a single Firefox::Marionette::Cookie into a fresh | ||
| 2092 | # or user-supplied (this means appending) HTTP::Cookies | ||
| 2093 | # optionally, user-supplied or fresh HTTP::Cookies | ||
| 2094 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 2095 | # $httpcookiejar is optional, if given, then cookies | ||
| 2096 | # will be appended in it and return it. Else | ||
| 2097 | # a fresh HTTP::Cookies will be created, loaded and returned. | ||
| 2098 | # It returns undef on failure. | ||
| 2099 | sub firefoxmarionettecookies2httpcookies { | ||
| 2100 | my ($firefoxmarionettecookies, $httpcookies, $skip_discard, $verbosity) = @_; | ||
| 2101 | $skip_discard //= 0; | ||
| 2102 | $verbosity //= 0; | ||
| 2103 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2104 | my $whoami = ( caller(0) )[3]; | ||
| 2105 | if( ! defined $httpcookies ){ | ||
| 2106 | if( ! defined($httpcookies = HTTP::Cookies->new()) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies->new()'." has failed.\n"; return undef } | ||
| 2107 | } | ||
| 2108 | |||
| 2109 | for my $c ( | ||
| 2110 | ref($firefoxmarionettecookies)eq'ARRAY' | ||
| 2111 | ? @$firefoxmarionettecookies | ||
| 2112 | : ($firefoxmarionettecookies) # it can be a single cookie not an ARRAY of Firefox::Marionette::Cookie | ||
| 2113 | ){ | ||
| 2114 | # signature of httpcookies->set_cookie() is this: | ||
| 2115 | #my($version, | ||
| 2116 | # $key, $val, $path, $domain, $port, | ||
| 2117 | # $path_spec, $secure, $maxage, $discard, $rest) = @_; | ||
| 2118 | # requires $maxage! ouch! | ||
| 2119 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 2120 | # requires $maxage! ouch! | ||
| 2121 | my $maxage = (exists($c->{'expiry'}) && defined($c->{'expiry'}) && ($c->{'expiry'}>0) ) | ||
| 2122 | ? ($c->{'expiry'} - time()) | ||
| 2123 | : undef | ||
| 2124 | ; | ||
| 2125 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): max-age calculated from expiry : ".(defined($maxage)?$maxage:"<NA>").".\n" } | ||
| 2126 | next if $skip_discard && (!defined($maxage) || ($maxage < 0)); | ||
| 2127 | my $path = $c->{'path'}; if( defined $path ){ $path =~ s/^"//; $path =~ s/"$// } else { $path = '' } | ||
| 2128 | my $value = $c->{'value'}; if( defined $value ){ $value =~ s/^"//; $value =~ s/"$// } else { $value = '' } | ||
| 2129 | my @params = ( | ||
| 2130 | undef, # $version? | ||
| 2131 | $c->{'name'}, # corresponds to $key | ||
| 2132 | $value,# $value without quotes | ||
| 2133 | $path, # $path without quotes | ||
| 2134 | $c->{'domain'}, # $domain | ||
| 2135 | undef, # no port | ||
| 2136 | # path_spec is boolean, 1 if path exists (I think!) | ||
| 2137 | defined($path) && ($path ne '') ? 1 : 0, | ||
| 2138 | # $secure | ||
| 2139 | exists($c->{'secure'}) ? $c->{'secure'} : undef, | ||
| 2140 | # HTTP::Cookies::scan() provides $expires, but HTTP::Cookies::set_cookie() | ||
| 2141 | # requires $maxage! ouch! | ||
| 2142 | $maxage, # derived from Expires | ||
| 2143 | exists($c->{'discard'}) ? $c->{'discard'} : undef, | ||
| 2144 | # rest is added below | ||
| 2145 | ); | ||
| 2146 | my %rest; | ||
| 2147 | # the $rest as a HASH_REF | ||
| 2148 | for ('http_only','same_site'){ | ||
| 2149 | next unless exists($c->{$_}) && defined($c->{$_}); | ||
| 2150 | $rest{$_} = $c->{$_}; | ||
| 2151 | } | ||
| 2152 | push @params, \%rest; | ||
| 2153 | my $ret = eval { $httpcookies->set_cookie(@params) }; | ||
| 2154 | if( ! defined($ret) || $@ ){ print STDERR "--begin cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies->set_cookie()'." has failed for above HTTP::Cookies object".(defined($@)?" with this exception: $@":".").").\n"; print Devel::StackTrace->new->as_string; return undef } | ||
| 2155 | } | ||
| 2156 | return $httpcookies; | ||
| 2157 | } | ||
| 2158 | |||
| 2159 | # HTTP::Cookies to array of cookies. | ||
| 2160 | # Each of the output cookie resembles a Set-Cookie header and, | ||
| 2161 | # logically, it can be loaded by any cookies container. | ||
| 2162 | # It converts the specified HTTP::Cookies object into | ||
| 2163 | # an array of cookies which can then be loaded into other exotic | ||
| 2164 | # cookie containers. | ||
| 2165 | # It returns the cookies as ARRAY_REF. | ||
| 2166 | sub httpcookies2setcookies { | ||
| 2167 | my ($httpcookies, $setcookies, $skip_discard, $verbosity) = @_; | ||
| 2168 | $skip_discard //= 0; | ||
| 2169 | $verbosity //= 0; | ||
| 2170 | |||
| 2171 | if( ! defined $setcookies ){ $setcookies = [] } | ||
| 2172 | |||
| 2173 | # below code shamelessly borrowed from HTTP::Cookies::as_string() : | ||
| 2174 | # https://metacpan.org/dist/HTTP-Cookies/source/lib/HTTP/Cookies.pm#L568 | ||
| 2175 | # NOTE: It adds extra quotes, e.g. in path="/" or expires="xyz" | ||
| 2176 | # we have code to remove these but ... | ||
| 2177 | $httpcookies->scan(sub { | ||
| 2178 | my($version,$key,$val,$path,$domain,$port, | ||
| 2179 | $path_spec,$secure,$expires,$discard,$rest) = @_; | ||
| 2180 | return if $discard && $skip_discard; | ||
| 2181 | my @h = ($key, $val); | ||
| 2182 | push(@h, "path", $path); | ||
| 2183 | push(@h, "domain" => $domain); | ||
| 2184 | push(@h, "port" => $port) if defined $port; | ||
| 2185 | push(@h, "path_spec" => undef) if $path_spec; | ||
| 2186 | push(@h, "secure" => undef) if $secure; | ||
| 2187 | # Set Cookie requires actual date as a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. | ||
| 2188 | push(@h, "expires" => HTTP::Date::time2isoz($expires)) if $expires; | ||
| 2189 | push(@h, "discard" => undef) if $discard; | ||
| 2190 | my $k; | ||
| 2191 | for $k (sort keys %$rest) { | ||
| 2192 | push(@h, $k, $rest->{$k}); | ||
| 2193 | } | ||
| 2194 | push(@h, "version" => $version); | ||
| 2195 | #push(@$setcookies, "Set-Cookie3: " . HTTP::Headers::Util::join_header_words(\@h)); | ||
| 2196 | push(@$setcookies, HTTP::Headers::Util::join_header_words(\@h)); | ||
| 2197 | }); | ||
| 2198 | return $setcookies | ||
| 2199 | } | ||
| 2200 | |||
| 2201 | # HTTP::CookieJar to array of cookies. | ||
| 2202 | # Each of the output cookie resembles a Set-Cookie header and, | ||
| 2203 | # logically, it can be loaded by any cookies container. | ||
| 2204 | # It converts the specified HTTP::CookieJar object into | ||
| 2205 | # an array of cookies which can then be loaded into other exotic | ||
| 2206 | # cookie containers. | ||
| 2207 | # It returns the cookies as ARRAY_REF. | ||
| 2208 | sub httpcookiejar2setcookies { | ||
| 2209 | my ($httpcookiejar, $setcookies, $verbosity) = @_; | ||
| 2210 | $verbosity //= 0; | ||
| 2211 | #my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2212 | #my $whoami = ( caller(0) )[3]; | ||
| 2213 | my @ret = $httpcookiejar->dump_cookies; | ||
| 2214 | if( ! defined $setcookies ){ return \@ret } | ||
| 2215 | push @$setcookies, @ret; | ||
| 2216 | return $setcookies; | ||
| 2217 | } | ||
| 2218 | |||
| 2219 | # Insert all cookies from a HTTP::CookieJar into an | ||
| 2220 | # optionally, user-supplied (appending) | ||
| 2221 | # or fresh Array of Firefox::Marionette::Cookie | ||
| 2222 | # and return it. Optionally specifying $verbosity (as integer). | ||
| 2223 | # $firefoxmarionettecookies is optional, if given, then cookies | ||
| 2224 | # will be appended in it and return it. Else | ||
| 2225 | # a fresh array of Firefox::Marionette::Cookie | ||
| 2226 | # will be created, loaded and returned. | ||
| 2227 | # It returns undef on failure. | ||
| 2228 | sub httpcookiejar2firefoxmarionettecookies { | ||
| 2229 | my ($httpcookiejar, $firefoxmarionettecookies, $verbosity) = @_; | ||
| 2230 | $verbosity //= 0; | ||
| 2231 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2232 | my $whoami = ( caller(0) )[3]; | ||
| 2233 | |||
| 2234 | if( ! defined $firefoxmarionettecookies ){ $firefoxmarionettecookies = [] } | ||
| 2235 | |||
| 2236 | my $httpcookies = httpcookiejar2httpcookies($httpcookiejar, undef, $verbosity); | ||
| 2237 | if( ! defined $httpcookies ){ print STDERR "--begin HTTP::CookieJar:\n".as_string_httpcookiejar($httpcookiejar)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookiejar2httpcookies()'." has failed.\n"; return undef } | ||
| 2238 | |||
| 2239 | if( ! defined httpcookies2firefoxmarionettecookies($httpcookies, $firefoxmarionettecookies, $verbosity) ){ print STDERR "--begin HTTP::Cookies:\n".as_string_httpcookies($httpcookies)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): error, call to ".'httpcookies2firefoxmarionettecookies()'." has failed.\n"; return undef } | ||
| 2240 | |||
| 2241 | if( $verbosity > 0 ){ print STDOUT "${whoami}, line ".__LINE__." (via $parent): inserted ".count_httpcookiejar($httpcookiejar, undef, $verbosity)." HTTP::CookieJar into an array of Firefox::Marionette::Cookie which now has ".count_firefoxmarionettecookies($firefoxmarionettecookies)." cookies.\n" } | ||
| 2242 | return $firefoxmarionettecookies; | ||
| 2243 | } | ||
| 2244 | |||
| 2245 | sub as_string_cookies { | ||
| 2246 | my ($w, $skip_discard, $verbosity) = @_; | ||
| 2247 | $skip_discard //= 0; | ||
| 2248 | $verbosity //= 0; | ||
| 2249 | |||
| 2250 | my $r = ref($w); | ||
| 2251 | if( $r eq 'ARRAY' ){ | ||
| 2252 | return 'Empty array of some kind of cookies' if scalar(@$w) == 0; | ||
| 2253 | if( ref($w->[0]) eq 'Firefox::Marionette::Cookie' ){ return as_string_firefoxmarionettecookies($w, $skip_discard, $verbosity) } | ||
| 2254 | else { | ||
| 2255 | return as_string_setcookies($w, $skip_discard, $verbosity) | ||
| 2256 | } | ||
| 2257 | } elsif( $r eq 'Firefox::Marionette::Cookie' ){ return as_string_firefoxmarionettecookie($w, $skip_discard, $verbosity) } | ||
| 2258 | elsif( $r eq 'HTTP::Cookies' ){ return as_string_httpcookies($w, $skip_discard, $verbosity) } | ||
| 2259 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return as_string_httpcookiejar($w, $skip_discard, $verbosity) } | ||
| 2260 | print STDERR 'as_string_cookies()'.", line ".__LINE__." : error, don't know how to handle type '$r'.\n"; | ||
| 2261 | return undef # failed | ||
| 2262 | } | ||
| 2263 | sub as_string_firefoxmarionettecookies { | ||
| 2264 | my ($w, $skip_discard, $verbosity) = @_; | ||
| 2265 | $skip_discard //= 0; | ||
| 2266 | $verbosity //= 0; | ||
| 2267 | my $ret = ""; | ||
| 2268 | for my $aw (@$w){ | ||
| 2269 | $ret .= as_string_firefoxmarionettecookie($aw, $skip_discard, $verbosity); | ||
| 2270 | } | ||
| 2271 | return $ret; | ||
| 2272 | } | ||
| 2273 | sub as_string_firefoxmarionettecookie { | ||
| 2274 | my ($w, $skip_discard, $verbosity) = @_; | ||
| 2275 | $skip_discard //= 0; | ||
| 2276 | $verbosity //= 0; | ||
| 2277 | |||
| 2278 | return ref($w).":\n" | ||
| 2279 | . "====begin cookie====\n" | ||
| 2280 | . " name='".$w->name."'\n" | ||
| 2281 | . " value='".$w->value."'\n" | ||
| 2282 | . " path='".$w->path."'\n" | ||
| 2283 | . " secure='".(defined($w->secure)?($w->secure?"1":"0"):"<undef>")."'\n" | ||
| 2284 | . " domain='".$w->domain."'\n" | ||
| 2285 | . " expiry='".(defined($w->expiry)?$w->expiry:"<undef>")."'\n" | ||
| 2286 | # must be one of None|Lax|Strict | ||
| 2287 | . " same_site='".(defined($w->same_site)?$w->same_site:"<undef>")."'\n" | ||
| 2288 | . " http_only='".(defined($w->http_only)?($w->http_only?"1":"0"):"<undef>")."'\n" | ||
| 2289 | ; | ||
| 2290 | } | ||
| 2291 | sub as_string_setcookies { return ref($_[0]).":\n".join("\n", @{ $_[0] }) } | ||
| 2292 | sub as_string_httpcookiejar { return ref($_[0]).":\n".join("\n", $_[0]->dump_cookies) } | ||
| 2293 | sub as_string_httpcookies { | ||
| 2294 | my ($httpcookies, $skip_discard, $verbosity) = @_; | ||
| 2295 | $skip_discard //= 0; | ||
| 2296 | $verbosity //= 0; | ||
| 2297 | my $ret = ref($httpcookies).":\n"; | ||
| 2298 | my $rrr = eval { $httpcookies->scan(sub { | ||
| 2299 | my($version,$key,$val,$path,$domain,$port, | ||
| 2300 | $path_spec,$secure,$expires,$discard,$rest) = @_; | ||
| 2301 | return if $discard && $skip_discard; | ||
| 2302 | $ret .= "====begin cookie====\n"; | ||
| 2303 | $ret .= " key='$key', value='$val'\n"; | ||
| 2304 | $ret .= " path='$path'\n"; | ||
| 2305 | $ret .= " domain='$domain'\n"; | ||
| 2306 | $ret .= " version='$version'\n"; | ||
| 2307 | $ret .= " path_spec='".(defined($path_spec)?$path_spec:"<undef>")."'\n"; | ||
| 2308 | $ret .= " port='".(defined($port)?$port:"<undef>")."'\n"; | ||
| 2309 | # $secure ? "1":"0" has been tested for secure being a string '1'/'0' | ||
| 2310 | # an int 1/0 or a bool (1==1/1!=1) and works ok | ||
| 2311 | $ret .= " secure='".(defined($secure)?($secure?"1":"0"):"<undef>")."'\n"; | ||
| 2312 | $ret .= " expires='".(defined($expires)?$expires:"<undef>")."'\n"; | ||
| 2313 | $ret .= " discard='".(defined($discard)?($discard?"1":"0"):"<undef>")."'\n"; | ||
| 2314 | $ret .= " rest=(".perl2dump($rest,{terse=>1}).")\n"; | ||
| 2315 | $ret .= "====end cookie====\n"; | ||
| 2316 | }); 1 }; | ||
| 2317 | if( ! defined($rrr) || ($rrr!=1) || $@ ){ print STDERR 'as_string_httpcookies()'.", line ".__LINE__." : error, call to ".'HTTP::Cookies::scan()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 2318 | return $ret; | ||
| 2319 | } | ||
| 2320 | |||
| 2321 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2322 | # are equal. It returns 0 if they are different. | ||
| 2323 | # It returns undef on failure. | ||
| 2324 | sub cookies_are_equal { | ||
| 2325 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2326 | $verbosity //= 0; | ||
| 2327 | $skip_discard //=0; | ||
| 2328 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2329 | my $whoami = ( caller(0) )[3]; | ||
| 2330 | my $r = ref($obj1); | ||
| 2331 | if( $r ne ref($obj2) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of the same type/class. The first one is '$r' but the second is '".ref($obj2)."'.\n"; return undef } | ||
| 2332 | |||
| 2333 | if( $r eq 'ARRAY' ){ | ||
| 2334 | my $N = scalar(@$obj1); | ||
| 2335 | return 0 unless $N == scalar(@$obj2); | ||
| 2336 | return 1 if $N == 0; | ||
| 2337 | if( ref($obj1->[0]) eq 'Firefox::Marionette::Cookie' ){ | ||
| 2338 | # this returns undef on failure, so ok with what we return here | ||
| 2339 | return cookies_are_equal_firefoxmarionettecookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 2340 | } else { | ||
| 2341 | return cookies_are_equal_setcookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 2342 | } | ||
| 2343 | } elsif( $r eq 'Firefox::Marionette::Cookie' ){ return cookies_are_equal_firefoxmarionettecookie($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 2344 | elsif( $r eq 'HTTP::Cookies' ){ return cookies_are_equal_httpcookies($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 2345 | elsif( ($r eq 'HTTP::CookieJar') || ($r eq 'HTTP::CookieJar::LWP') ){ return cookies_are_equal_httpcookiejar($obj1, $obj2, $skip_discard, $verbosity) } | ||
| 2346 | print STDERR "${whoami}, line ".__LINE__." (via $parent): error, don't know how to handle type '$r'.\n"; | ||
| 2347 | return undef | ||
| 2348 | } | ||
| 2349 | |||
| 2350 | # TODO: cookies_diff? | ||
| 2351 | |||
| 2352 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2353 | # are equal. It returns 0 if they are different. | ||
| 2354 | # It returns undef on failure. | ||
| 2355 | sub cookies_are_equal_setcookies { | ||
| 2356 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2357 | $verbosity //= 0; | ||
| 2358 | $skip_discard //=0; | ||
| 2359 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2360 | my $whoami = ( caller(0) )[3]; | ||
| 2361 | my $r = ref($obj1); | ||
| 2362 | |||
| 2363 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 2364 | |||
| 2365 | if( $r ne 'ARRAY' ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be ARRAY_REF but the first one is '$r'.\n"; return undef } | ||
| 2366 | if( $r ne ref($obj2) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of the same type/class. The first one is '$r' but the second is '".ref($obj2)."'.\n"; return undef } | ||
| 2367 | |||
| 2368 | die "not implemented" | ||
| 2369 | } | ||
| 2370 | |||
| 2371 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2372 | # are equal. It returns 0 if they are different. | ||
| 2373 | # It returns undef on failure. | ||
| 2374 | sub cookies_are_equal_firefoxmarionettecookie { | ||
| 2375 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2376 | $verbosity //= 0; | ||
| 2377 | $skip_discard //=0; | ||
| 2378 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2379 | my $whoami = ( caller(0) )[3]; | ||
| 2380 | my $r = ref($obj1); | ||
| 2381 | |||
| 2382 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 2383 | |||
| 2384 | my $same = 1; | ||
| 2385 | { | ||
| 2386 | no strict 'refs'; | ||
| 2387 | for my $k ('path', 'domain', 'secure', 'name', 'value', 'http_only', 'same_site', 'expiry'){ | ||
| 2388 | my $v1 = $obj1->$k(); my $v2 = $obj2->$k(); | ||
| 2389 | if( (! defined($v1)) && (! defined($v2)) ){ return 1 } # same but both undef | ||
| 2390 | if( defined($v1) ^ defined($v2) ){ return 0 } # not same, one is undef | ||
| 2391 | if( $v1 ne $v2 ){ return 0 } # not same | ||
| 2392 | } | ||
| 2393 | } | ||
| 2394 | return 1 # same | ||
| 2395 | } | ||
| 2396 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2397 | # are equal. It returns 0 if they are different. | ||
| 2398 | # It returns undef on failure. | ||
| 2399 | # NOTE: the container of the cookies is an ARRAY | ||
| 2400 | # so order of cookies is important, so we need | ||
| 2401 | # to discard order by using a hash. | ||
| 2402 | sub cookies_are_equal_firefoxmarionettecookies { | ||
| 2403 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2404 | $verbosity //= 0; | ||
| 2405 | $skip_discard //=0; | ||
| 2406 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2407 | my $whoami = ( caller(0) )[3]; | ||
| 2408 | my $r = ref($obj1); | ||
| 2409 | |||
| 2410 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 2411 | |||
| 2412 | return 1 if $obj1 == $obj2; # both refer to the same array object | ||
| 2413 | my $N = scalar(@$obj1); | ||
| 2414 | return 0 if $N != scalar(@$obj2); # different number of items | ||
| 2415 | |||
| 2416 | # in need to discard order. It think the best way is to convert | ||
| 2417 | # to httpcookies and compare that. | ||
| 2418 | my $httpcookies1 = firefoxmarionettecookies2httpcookies($obj1, undef, $skip_discard, $verbosity); | ||
| 2419 | if( ! defined $httpcookies1 ){ print STDERR "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n${whoami}, line ".__LINE__." (via $parent): error, failed to convert 1st cookies to httpcookies, see above.\n"; return undef } | ||
| 2420 | my $httpcookies2 = firefoxmarionettecookies2httpcookies($obj2, undef, $skip_discard, $verbosity); | ||
| 2421 | if( ! defined $httpcookies2 ){ print STDERR "--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n\n${whoami}, line ".__LINE__." (via $parent): error, failed to convert 2nd cookies to httpcookies, see above.\n"; return undef } | ||
| 2422 | |||
| 2423 | my $ret = cookies_are_equal_httpcookies($httpcookies1, $httpcookies2, $skip_discard, $verbosity); | ||
| 2424 | if( ! defined $ret ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, call to ".'cookies_are_equal_httpcookies()'." has failed.\n"; return undef } | ||
| 2425 | return $ret; | ||
| 2426 | } | ||
| 2427 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2428 | # are equal. It returns 0 if they are different. | ||
| 2429 | # It returns undef on failure. | ||
| 2430 | sub cookies_are_equal_httpcookies { | ||
| 2431 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2432 | $verbosity //= 0; | ||
| 2433 | $skip_discard //=0; | ||
| 2434 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2435 | my $whoami = ( caller(0) )[3]; | ||
| 2436 | my $r = ref($obj1); | ||
| 2437 | |||
| 2438 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n".__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 2439 | |||
| 2440 | if( $r ne 'HTTP::Cookies' ){ print STDERR __PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of class 'HTTP::Cookies' but the first one is '$r'.\n"; return undef } | ||
| 2441 | if( $r ne ref($obj2) ){ print STDERR __PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of the same type/class. The first one is '$r' but the second is '".ref($obj2)."'.\n"; return undef } | ||
| 2442 | |||
| 2443 | # loop over all cookies in $obj1 and check if each is present+equal in $obj2, unless $discard'ed | ||
| 2444 | # loop over all cookies in $obj2 and check if each is present+equal in $obj1, unless $discard'ed | ||
| 2445 | # return 1 if all conditions met, 0 if not. The latter means not equal. | ||
| 2446 | my $rrr = _cookies_are_equal_httpcookies_comparator($obj1, $obj2, $skip_discard, $verbosity); | ||
| 2447 | if( ! defined($rrr) || $@ ){ print STDERR __PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::scan()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 2448 | if( $rrr == 0 ){ return 0 } # not equal | ||
| 2449 | |||
| 2450 | $rrr = _cookies_are_equal_httpcookies_comparator($obj2, $obj1, $skip_discard, $verbosity); | ||
| 2451 | if( ! defined($rrr) || $@ ){ print STDERR __PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::scan()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 2452 | |||
| 2453 | return $rrr; # 1 if equals | ||
| 2454 | } | ||
| 2455 | |||
| 2456 | sub _cookies_are_equal_httpcookies_comparator { | ||
| 2457 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2458 | $verbosity //= 0; | ||
| 2459 | $skip_discard //=0; | ||
| 2460 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2461 | my $whoami = ( caller(0) )[3]; | ||
| 2462 | |||
| 2463 | my $rrr = eval { | ||
| 2464 | my $eqs = 1; | ||
| 2465 | $obj1->scan( | ||
| 2466 | sub { | ||
| 2467 | no autovivification; # hopefully locally | ||
| 2468 | # if one not equal, then we are done, so shortcircuit this here: | ||
| 2469 | return unless $eqs; | ||
| 2470 | my($version, | ||
| 2471 | $key,$val,$path,$domain,$port, | ||
| 2472 | $path_spec,$secure,$expires,$discard,$rest) = @_; | ||
| 2473 | |||
| 2474 | return if $discard && $skip_discard; # it is discarded, it is as if a match is found; | ||
| 2475 | |||
| 2476 | # hopefully no autovivify will work locally | ||
| 2477 | my $p; | ||
| 2478 | my @fixdomains = ($domain, '.'.$domain, $domain); | ||
| 2479 | $fixdomains[2] =~ s/^\.//; | ||
| 2480 | # check the stupid domain having a dot in front or not! | ||
| 2481 | FIX: | ||
| 2482 | for my $fixdomain (@fixdomains){ | ||
| 2483 | if( defined $obj2->{COOKIES}{$fixdomain}{$path}{$key} ){ | ||
| 2484 | $p = $obj2->{COOKIES}{$fixdomain}{$path}{$key}; | ||
| 2485 | last FIX; | ||
| 2486 | } | ||
| 2487 | } | ||
| 2488 | if( ! defined $p ){ | ||
| 2489 | # failed ! | ||
| 2490 | if( $verbosity > 1 ){ print STDOUT "obj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($obj2->{COOKIES}).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because item '{COOKIES}{$domain}{$path}{$key}' does not exist in second object (see above).\n" } | ||
| 2491 | $eqs = 0; return; | ||
| 2492 | } | ||
| 2493 | |||
| 2494 | if( $verbosity > 1 ){ print STDOUT "obj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($obj2->{COOKIES}).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): comparing above cookies ...\n" } | ||
| 2495 | |||
| 2496 | # ->{COOKIES}{$domain}{$path}{$key} holds an array as: | ||
| 2497 | # ($version, $val, $port, $path_spec, $secure, $expires, $discard); | ||
| 2498 | # how do the contents compare? | ||
| 2499 | |||
| 2500 | my $i = 0; | ||
| 2501 | #if( (defined($version) xor defined($p->[$i])) | ||
| 2502 | # || (defined($version) and ($version ne $p->[$i])) | ||
| 2503 | #){ | ||
| 2504 | # if( $verbosity > 1 ){ print STDOUT "differ on version:\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'version' in obj1 is '".(defined($version)?$version:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2505 | # $eqs = 0; return | ||
| 2506 | #} | ||
| 2507 | |||
| 2508 | $i++; | ||
| 2509 | if( (defined($val) xor defined($p->[$i])) | ||
| 2510 | || (defined($val) and ($val ne $p->[$i])) | ||
| 2511 | ){ | ||
| 2512 | if( $verbosity > 1 ){ print STDOUT "differ on value:\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'val' (i=$i) in obj1 is '".(defined($val)?$val:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2513 | $eqs = 0; return | ||
| 2514 | } | ||
| 2515 | |||
| 2516 | $i++; | ||
| 2517 | if( (defined($port) xor defined($p->[$i])) | ||
| 2518 | || (defined($port) and ($port ne $p->[$i])) | ||
| 2519 | ){ | ||
| 2520 | if( $verbosity > 1 ){ print STDOUT "differ on port:\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'port' (i=$i) in obj1 is '".(defined($port)?$port:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2521 | $eqs = 0; return | ||
| 2522 | } | ||
| 2523 | |||
| 2524 | $i++; | ||
| 2525 | #if( (defined($path_spec) xor defined($p->[$i])) | ||
| 2526 | # || (defined($path_spec) and ($path_spec ne $p->[$i])) | ||
| 2527 | #){ | ||
| 2528 | # if( $verbosity > 1 ){ print STDOUT "differ on path_spec:\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'path_spec' (i=$i) in obj1 is '".(defined($path_spec)?$path_spec:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2529 | # $eqs = 0; return | ||
| 2530 | #} | ||
| 2531 | |||
| 2532 | # this sometimes is undef or '' | ||
| 2533 | $i++; | ||
| 2534 | if( (defined($secure) xor defined($p->[$i])) | ||
| 2535 | || (defined($secure) and ( ($secure?"1":"0") ne ($p->[$i]?"1":"0") )) | ||
| 2536 | ){ | ||
| 2537 | if( defined($secure) ){ | ||
| 2538 | if( (defined($p->[$i]) && ($secure ne $p->[$i])) | ||
| 2539 | || (defined($p->[$i]) && ('' ne $p->[$i])) | ||
| 2540 | ){ | ||
| 2541 | if( $verbosity > 1 ){ print STDOUT "differ on secure ('$secure' and '".$p->[$i]."'):\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'secure' (i=$i) in obj1 is '".(defined($secure)?$secure:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2542 | $eqs = 0; return | ||
| 2543 | } | ||
| 2544 | } else { | ||
| 2545 | if( defined($p->[$i]) && ($p->[$i] ne '') ){ | ||
| 2546 | if( $verbosity > 1 ){ print STDOUT "differ on secure:\nobj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'secure' (i=$i) in obj1 is '".(defined($secure)?$secure:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2547 | $eqs = 0; return | ||
| 2548 | } | ||
| 2549 | } | ||
| 2550 | } | ||
| 2551 | |||
| 2552 | $i++; | ||
| 2553 | if( (defined($expires) xor defined($p->[$i])) | ||
| 2554 | || (defined($expires) and ($expires ne $p->[$i])) | ||
| 2555 | ){ | ||
| 2556 | if( $verbosity > 1 ){ print STDOUT "obj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'expires' (i=$i) in obj1 is '".(defined($expires)?$expires:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2557 | $eqs = 0; return | ||
| 2558 | } | ||
| 2559 | |||
| 2560 | # discard is checked above and forget it. | ||
| 2561 | $i++; | ||
| 2562 | #if( (defined($discard) xor defined($p->[$i])) | ||
| 2563 | # || (defined($discard) and ( ($discard?"1":"0") ne ($p->[$i]?"1":"0") )) | ||
| 2564 | #){ | ||
| 2565 | # if( $verbosity > 1 ){ print STDOUT "obj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($p).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): not equal because key 'discard' (i=$i) in obj1 is '".(defined($discard)?$discard:"<undef>")."' and in obj2 is '".(defined($p->[$i])?$p->[$i]:"<undef>")."'. See above obj2.\n" } | ||
| 2566 | # $eqs = 0; return | ||
| 2567 | #} | ||
| 2568 | |||
| 2569 | # we don't care about the $rest | ||
| 2570 | |||
| 2571 | if( $verbosity > 1 ){ print STDOUT "obj1: ".join("|", map { defined($_)?$_:"<undef>" } @_)."\nobj2:".perl2dump($obj2->{COOKIES}).__PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): above (single) cookies are equal ...\n" } | ||
| 2572 | |||
| 2573 | # still the same! | ||
| 2574 | } | ||
| 2575 | ); $eqs; | ||
| 2576 | }; | ||
| 2577 | if( ! defined($rrr) || $@ ){ print STDERR __PACKAGE__."::${whoami}, line ".__LINE__." (via $parent): error, call to ".'HTTP::Cookies::scan()'." has failed".(defined($@)?" with this exception: $@":".").").\n"; return undef } | ||
| 2578 | return $rrr # 1 if equals | ||
| 2579 | } | ||
| 2580 | |||
| 2581 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2582 | # are equal. It returns 0 if they are different. | ||
| 2583 | # It returns undef on failure. | ||
| 2584 | sub cookies_are_equal_httpcookies_bad { | ||
| 2585 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2586 | $verbosity //= 0; | ||
| 2587 | $skip_discard //=0; | ||
| 2588 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2589 | my $whoami = ( caller(0) )[3]; | ||
| 2590 | my $r = ref($obj1); | ||
| 2591 | |||
| 2592 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): called with above data ...\n" } | ||
| 2593 | |||
| 2594 | if( $r ne 'HTTP::Cookies' ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of class 'HTTP::Cookies' but the first one is '$r'.\n"; return undef } | ||
| 2595 | if( $r ne ref($obj2) ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of the same type/class. The first one is '$r' but the second is '".ref($obj2)."'.\n"; return undef } | ||
| 2596 | |||
| 2597 | # convert them to strings but because we don't know the order, hash them. | ||
| 2598 | my $s1 = $obj1->as_string($skip_discard); $s1 =~ s/\R+$//; | ||
| 2599 | my $s2 = $obj2->as_string($skip_discard); $s2 =~ s/\R+$//; | ||
| 2600 | # this stupid adds the rest... we need to remove them | ||
| 2601 | my %s1 = ( map { s/(?:^|\n)Set-Cookie3:\s*//; $_ => 1 } map { | ||
| 2602 | s/\s*creation_time=.+?(?:;|$)//; | ||
| 2603 | s/\s*last_access_time=.+?(?:;|$)//; | ||
| 2604 | s/\s*discard(?:;|$)//; | ||
| 2605 | s/\s*version=.+?(?:;|$)//; | ||
| 2606 | $_ | ||
| 2607 | } split /\n/, $s1 ); | ||
| 2608 | my %s2 = ( map { s/(?:^|\n)Set-Cookie3:\s*//; $_ => 1 } map { | ||
| 2609 | s/\s*creation_time=.+?(?:;|$)//; | ||
| 2610 | s/\s*last_access_time=.+?(?:;|$)//; | ||
| 2611 | s/\s*discard(?:;|$)//; | ||
| 2612 | s/\s*version=.+?(?:;|$)//; | ||
| 2613 | $_ | ||
| 2614 | } split /\n/, $s2 ); | ||
| 2615 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies HASH:\n".perl2dump(\%s1)."\n--end cookies.\n\n--begin 2nd cookies HASH:\n".perl2dump(\%s2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): comparing above hashes ...\n" } | ||
| 2616 | |||
| 2617 | for my $k (keys %s1){ | ||
| 2618 | if( ! exists($s2{$k}) ){ | ||
| 2619 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".join("\n", keys %s2)."\n--end cookies.\n${whoami}, line ".__LINE__." (via $parent): the following cookie from 1st cookies object does not exist in the 2nd cookies object which is above: $k\n" } | ||
| 2620 | return 0 | ||
| 2621 | } | ||
| 2622 | delete $s2{$k}; | ||
| 2623 | } | ||
| 2624 | # now do it the other way | ||
| 2625 | for my $k (keys %s2){ | ||
| 2626 | if( ! exists($s1{$k}) ){ | ||
| 2627 | if( $verbosity > 0 ){ print STDOUT "--begin cookies:\n".join("\n", keys %s1)."\n--end cookies.\n${whoami}, line ".__LINE__." (via $parent): cookie from 2nd cookies object does not exist in the 1st cookies object, see above: $k\n" } | ||
| 2628 | return 0 | ||
| 2629 | } | ||
| 2630 | } | ||
| 2631 | |||
| 2632 | return 1; # they are equal | ||
| 2633 | } | ||
| 2634 | |||
| 2635 | # It returns 1 if the two input objects (which must be of the same type) | ||
| 2636 | # are equal. It returns 0 if they are different. | ||
| 2637 | # It returns undef on failure. | ||
| 2638 | sub cookies_are_equal_httpcookiejar { | ||
| 2639 | my ($obj1, $obj2, $skip_discard, $verbosity) = @_; | ||
| 2640 | $verbosity //= 0; | ||
| 2641 | $skip_discard //=0; | ||
| 2642 | my $parent = ( caller(1) )[3] || "N/A"; | ||
| 2643 | my $whoami = ( caller(0) )[3]; | ||
| 2644 | my $r1 = ref($obj1); | ||
| 2645 | my $r2 = ref($obj2); | ||
| 2646 | if( ($r1 ne 'HTTP::CookieJar') && ($r1 ne 'HTTP::CookieJar::LWP') ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of class 'HTTP::CookieJar' or 'HTTP::CookieJar::LWP' but the first one is '$r1' (and the second is is '$r2').\n"; return undef } | ||
| 2647 | if( ($r2 ne 'HTTP::CookieJar') && ($r2 ne 'HTTP::CookieJar::LWP') ){ print STDERR "${whoami}, line ".__LINE__." (via $parent): error, the two input cookies must be of class 'HTTP::CookieJar' or ' but the second one is '$r2'.\n"; return undef } | ||
| 2648 | # ok, we do not need to compare them r1/r2 because they can be | ||
| 2649 | # one 'HTTP::CookieJar' and the other 'HTTP::CookieJar::LWP' | ||
| 2650 | # but that's hopefully OK | ||
| 2651 | if( $verbosity > 0 ){ print STDOUT "--begin 1st cookies:\n".as_string_cookies($obj1)."\n--end cookies.\n\n--begin 2nd cookies:\n".as_string_cookies($obj2)."\n--end cookies.\n"."${whoami}, line ".__LINE__." (via $parent): comparing above two 'HTTP::CookieJar' objects.\n" } | ||
| 2652 | |||
| 2653 | #print "ALL COOKIES1 ".perl2dump([$obj1->_all_cookies])."ALL COOKIES2 ".perl2dump([$obj2->_all_cookies]); | ||
| 2654 | #print "STORE1 ".perl2dump($obj1->{store})."STORE2 ".perl2dump($obj2->{store}); | ||
| 2655 | |||
| 2656 | # _all_cookies flattens 'store' hash and returns an array | ||
| 2657 | # whose items are in random order (values of hash) | ||
| 2658 | # and sometimes the comparison fails, so key it on domain/path/name/value | ||
| 2659 | return Data::Compare::Compare( | ||
| 2660 | { map { join('|', map { defined $_ ? $_ : '<undef>' } @{$_}{qw/domain path name value/}) => $_ } $obj1->_all_cookies }, | ||
| 2661 | { map { join('|', map { defined $_ ? $_ : '<undef>' } @{$_}{qw/domain path name value/}) => $_ } $obj2->_all_cookies }, | ||
| 2662 | ) ? 1 : 0; | ||
| 2663 | #return Compare([$obj1->_all_cookies], [$obj2->_all_cookies]) ? 1 : 0; | ||
| 2664 | #return Compare([$obj1->{'store'}], [$obj2->{'store'}]) ? 1 : 0; | ||
| 2665 | } | ||
| 2666 | |||
| 2667 | ###################################################### | ||
| 2668 | # exporter private things | ||
| 2669 | ###################################################### | ||
| 2670 | sub import { | ||
| 2671 | # what comes here is (package, param1, param2...) = @_ | ||
| 2672 | # for something like | ||
| 2673 | # use Cookies::Roundtrip qw/param1 params2 .../; | ||
| 2674 | # we are looking for a param, eq to 'xyz' | ||
| 2675 | # the rest we must pass to the Exporter::import() but in a tricky way | ||
| 2676 | # so as it injects all these subs in the proper namespace. | ||
| 2677 | # that call is at the end, but with our parameter removed from the list | ||
| 2678 | for(my $i=@_;$i-->1;){ | ||
| 2679 | #if( $_[$i] eq 'xyz' ){ | ||
| 2680 | # splice @_, $i, 1; # remove it from the list | ||
| 2681 | # do whatever this requires | ||
| 2682 | #} elsif( ... | ||
| 2683 | } | ||
| 2684 | # now let Exporter handle the rest of the params if any | ||
| 2685 | # from ikegami at https://www.perlmonks.org/?node_id=1214104 | ||
| 2686 | goto &Exporter::import; | ||
| 2687 | } | ||
| 2688 | BEGIN { | ||
| 2689 | # group various subs for importing them with tags | ||
| 2690 | my @_lwpuseragent = qw/lwpuseragent_save_cookies_to_file lwpuseragent_load_cookies lwpuseragent_load_cookies_from_file lwpuseragent_load_setcookies lwpuseragent_load_httpcookies lwpuseragent_load_httpcookiejar lwpuseragent_get_cookies/; | ||
| 2691 | my @_wwwmechanize = qw/wwwmechanize_save_cookies_to_file wwwmechanize_load_cookies wwwmechanize_load_cookies_from_file wwwmechanize_load_setcookies wwwmechanize_load_httpcookies wwwmechanize_load_httpcookiejar wwwmechanize_get_cookies/; | ||
| 2692 | my @_firefoxmarionette = qw/firefoxmarionette_save_cookies_to_file firefoxmarionette_load_cookies firefoxmarionette_load_cookies_from_file firefoxmarionette_load_setcookies firefoxmarionette_load_httpcookies firefoxmarionette_load_httpcookiejar firefoxmarionette_get_cookies/; | ||
| 2693 | my @_clone = qw/clone_httpcookiejar clone_httpcookies clone_setcookies clone_cookies/; | ||
| 2694 | my @_merge = qw/merge_httpcookies merge_httpcookiejar merge_setcookies merge_firefoxmarionettecookies merge_cookies/; | ||
| 2695 | my @_count = qw/count_httpcookies count_httpcookiejar count_setcookies count_firefoxmarionettecookies count_cookies/; | ||
| 2696 | my @_equal = qw/cookies_are_equal cookies_are_equal_httpcookies cookies_are_equal_httpcookiejar cookies_are_equal_setcookies cookies_are_equal_firefoxmarionettecookie cookies_are_equal_firefoxmarionettecookies/; | ||
| 2697 | my @_setcookies2 = qw/setcookies2httpcookiejar setcookies2httpcookies/; | ||
| 2698 | my @_httpcookies2 = qw/httpcookies2setcookies httpcookies2file httpcookies2httpcookiejar httpcookies2firefoxmarionettecookies/; | ||
| 2699 | my @_httpcookiejar2 = qw/httpcookiejar2file httpcookiejar2httpcookies httpcookiejar2setcookies httpcookiejar2firefoxmarionettecookies/; | ||
| 2700 | my @_firefoxmarionettecookies2 = qw/firefoxmarionettecookies2file firefoxmarionettecookies2httpcookies firefoxmarionettecookies2httpcookiejar firefoxmarionettecookies2setcookies/; | ||
| 2701 | my @_new = qw/new_firefoxmarionettecookie new_firefoxmarionettecookies/; | ||
| 2702 | my @_file = qw/file2httpcookiejar httpcookiejar2file file2httpcookies httpcookies2file firefoxmarionettecookies2file file2firefoxmarionettecookies setcookies2file file2setcookies lwpuseragent_save_cookies_to_file lwpuseragent_load_cookies_from_file wwwmechanize_save_cookies_to_file wwwmechanize_load_cookies_from_file cookies2file/; | ||
| 2703 | my @_as_string = qw/as_string_httpcookiejar as_string_httpcookies as_string_setcookies as_string_cookies as_string_firefoxmarionettecookies/; | ||
| 2704 | @EXPORT_OK = qw/ | ||
| 2705 | as_string_httpcookiejar as_string_httpcookies as_string_setcookies as_string_firefoxmarionettecookies as_string_cookies | ||
| 2706 | cookies_are_equal cookies_are_equal_httpcookies cookies_are_equal_httpcookiejar cookies_are_equal_setcookies cookies_are_equal_firefoxmarionettecookie cookies_are_equal_firefoxmarionettecookies | ||
| 2707 | file2httpcookiejar httpcookiejar2file file2httpcookies httpcookies2file lwpuseragent_save_cookies_to_file lwpuseragent_load_cookies_from_file wwwmechanize_save_cookies_to_file wwwmechanize_load_cookies_from_file firefoxmarionettecookies2file file2firefoxmarionettecookies firefoxmarionettecookies2file setcookies2file file2setcookies cookies2file | ||
| 2708 | firefoxmarionettecookies2setcookies | ||
| 2709 | firefoxmarionettecookies2httpcookiejar | ||
| 2710 | firefoxmarionettecookies2httpcookie | ||
| 2711 | httpcookies2httpcookiejar | ||
| 2712 | lwpuseragent_get_cookies | ||
| 2713 | lwpuseragent_load_cookies | ||
| 2714 | lwpuseragent_load_setcookies | ||
| 2715 | lwpuseragent_load_httpcookies | ||
| 2716 | lwpuseragent_load_httpcookiejar | ||
| 2717 | new_firefoxmarionettecookie new_firefoxmarionettecookies | ||
| 2718 | wwwmechanize_get_cookies | ||
| 2719 | wwwmechanize_load_cookies | ||
| 2720 | wwwmechanize_load_setcookies | ||
| 2721 | wwwmechanize_load_httpcookies | ||
| 2722 | wwwmechanize_load_httpcookiejar | ||
| 2723 | firefoxmarionette_save_cookies_to_file | ||
| 2724 | firefoxmarionette_load_cookies | ||
| 2725 | firefoxmarionette_load_cookies_from_file | ||
| 2726 | firefoxmarionette_load_setcookies | ||
| 2727 | firefoxmarionette_load_httpcookies | ||
| 2728 | firefoxmarionette_load_httpcookiejar | ||
| 2729 | firefoxmarionette_get_cookies | ||
| 2730 | clone_httpcookiejar clone_httpcookies clone_setcookies clone_firefoxmarionettecookie clone_firefoxmarionettecookies clone_cookies | ||
| 2731 | merge_httpcookies merge_httpcookiejar merge_setcookies merge_firefoxmarionettecookies merge_cookies | ||
| 2732 | count_httpcookies count_httpcookiejar count_setcookies count_firefoxmarionettecookies count_cookies | ||
| 2733 | setcookies2httpcookiejar | ||
| 2734 | setcookies2httpcookies | ||
| 2735 | setcookies2firefoxmarionettecookies | ||
| 2736 | httpcookiejar2httpcookies | ||
| 2737 | httpcookies2setcookies | ||
| 2738 | httpcookiejar2setcookies | ||
| 2739 | httpcookies2firefoxmarionettecookies | ||
| 2740 | httpcookiejar2firefoxmarionettecookies | ||
| 2741 | firefoxmarionettecookies2httpcookies | ||
| 2742 | firefoxmarionettecookies2httpcookiejar | ||
| 2743 | firefoxmarionettecookies2setcookies | ||
| 2744 | /; | ||
| 2745 | %EXPORT_TAGS = ( | ||
| 2746 | lwpuseragent => [@_lwpuseragent], | ||
| 2747 | wwwmechanize => [@_wwwmechanize], | ||
| 2748 | firefoxmarionette => [@_firefoxmarionette], | ||
| 2749 | clone => [@_clone], | ||
| 2750 | merge => [@_merge], | ||
| 2751 | count => [@_count], | ||
| 2752 | equal => [@_equal], | ||
| 2753 | new => [@_new], | ||
| 2754 | setcookies2 => [@_setcookies2], | ||
| 2755 | httpcookies2 => [@_httpcookies2], | ||
| 2756 | httpcookiejar2 => [@_httpcookiejar2], | ||
| 2757 | firefoxmarionettecookies2 => [@_firefoxmarionettecookies2], | ||
| 2758 | file => [@_file], | ||
| 2759 | as_string => [@_as_string], | ||
| 2760 | all => [@EXPORT_OK], | ||
| 2761 | ); | ||
| 2762 | } # end BEGIN | ||
| 2763 | |||
| 2764 | ########## only pod below | ||
| 2765 | =pod | ||
| 2766 | |||
| 2767 | =head1 NAME | ||
| 2768 | |||
| 2769 | Cookies::Roundtrip - Convert between different HTTP Cookie formats, well, at least we tried! | ||
| 2770 | |||
| 2771 | =head1 VERSION | ||
| 2772 | |||
| 2773 | Version 0.01 | ||
| 2774 | |||
| 2775 | =head1 SYNOPSIS | ||
| 2776 | |||
| 2777 | This module provides functionality for converting between some of the | ||
| 2778 | various HTTP Cookie formats. I<Roundtrip> is a bit of a wish really | ||
| 2779 | as there can be unsupported fields in the various Cookie formats. | ||
| 2780 | |||
| 2781 | Anyway! Here we try to convert between L<HTTP::Cookies>, L<HTTP::CookieJar>, | ||
| 2782 | single L<Firefox::Marionette::Cookie> or an ARRAY of L<Firefox::Marionette::Cookie>, | ||
| 2783 | an ARRAY of C<Set-Cookie> header strings, | ||
| 2784 | which cover L<WWW::Mechanize> (and subclasses), L<LWP::UserAgent> (and subclasses) | ||
| 2785 | and L<Firefox::Marionette>. Note that L<WWW::Mechanize> (and subclasses) | ||
| 2786 | and L<LWP::UserAgent> (and subclasses) support both | ||
| 2787 | L<HTTP::Cookies>, L<HTTP::CookieJar> and this is controlled during construction. | ||
| 2788 | |||
| 2789 | Example usage: | ||
| 2790 | |||
| 2791 | use Cookies::Roundtrip qw/:all/; | ||
| 2792 | use HTTP::Cookies; | ||
| 2793 | use HTTP::CookieJar; | ||
| 2794 | |||
| 2795 | # Skip discarded (expired etc.) cookies? | ||
| 2796 | my $skip_discard = 1; # or 0 | ||
| 2797 | # Verbosity level | ||
| 2798 | my $VERBOSITY = 1; # 0 to ... | ||
| 2799 | |||
| 2800 | # from this HTTP::CookieJar cookie ... | ||
| 2801 | my $hcj = HTTP::CookieJar->new; | ||
| 2802 | $hc->add(...); | ||
| 2803 | # ... convert to HTTP::Cookies | ||
| 2804 | my $hc = httpcookiejar2httpcookies($hcj, undef, $skip_discard, $VERBOSITY); | ||
| 2805 | # ... or supply the HTTP::Cookies object ($hc) to append to as sub parameter | ||
| 2806 | httpcookiejar2httpcookies($hcj, $hc, $skip_discard, $VERBOSITY) or die; | ||
| 2807 | |||
| 2808 | # and back ... | ||
| 2809 | my $hcj2 = httpcookies2httpcookiejar($hc, undef, $skip_discard, $VERBOSITY); | ||
| 2810 | |||
| 2811 | # From LWP::UserAgent | ||
| 2812 | my $ua = LWP::UserAgent->new(cookie_jar_class=>'HTTP::CookieJar'); | ||
| 2813 | ... | ||
| 2814 | # extract them from LWP::UserAgent object | ||
| 2815 | $hcj = lwpuseragent_get_cookies($ua, $VERBOSITY); | ||
| 2816 | print "got ".count_cookies($hcj)." cookies\n"; | ||
| 2817 | # ... or load them into the LWP::UserAgent object | ||
| 2818 | # note that the 2nd param ($hcj) can be a filename to load from file | ||
| 2819 | # or any other Cookie object whose class we support | ||
| 2820 | lwpuseragent_load_cookies($ua, $hcj, $VERBOSITY); | ||
| 2821 | |||
| 2822 | # write to files | ||
| 2823 | wwwmechanize_save_cookies_to_file($mech, 'out.cookies', $skip_discard, $VERBOSITY); | ||
| 2824 | lwpuseragent_save_cookies_to_file($ua, 'out.cookies', $skip_discard, $VERBOSITY); | ||
| 2825 | firefoxmarionette_save_cookies_to_file($ffm, 'out.cookies', $skip_discard, $VERBOSITY); | ||
| 2826 | # or load from files | ||
| 2827 | wwwmechanize_load_cookies_from_file($mech, 'my.cookies', $skip_discard, $VERBOSITY); | ||
| 2828 | wwwmechanize_load_cookies_from_file($ua, 'my.cookies', $skip_discard, $VERBOSITY); | ||
| 2829 | wwwmechanize_load_cookies_from_file($ffm, 'my.cookies', $skip_discard, $VERBOSITY); | ||
| 2830 | # write cookie to file | ||
| 2831 | httpcookies2file($hc, 'out.cookies', $skip_discard, $VERBOSITY); | ||
| 2832 | httpcookiejar2file($hcj, 'out.cookies', $skip_discard, $VERBOSITY); | ||
| 2833 | # read cookies from file | ||
| 2834 | $hc = file2httpcookies('my.cookies', undef, $VERBOSITY); | ||
| 2835 | # or append them to existing cookies object | ||
| 2836 | file2httpcookies('my.cookies', $hc, $VERBOSITY); | ||
| 2837 | |||
| 2838 | # count cookies of any Cookies object whose class we support | ||
| 2839 | count_cookies($cookies_obj, $skip_discard, $VERBOSITY); | ||
| 2840 | # clone cookies of any Cookies object whose class we support | ||
| 2841 | my $newcook = clone_cookies($cookies_obj, $VERBOSITY); | ||
| 2842 | # merge Cookie objects OF THE SAME class | ||
| 2843 | $newcook = merge_cookies($cook1, $cook2, $skip_discard, $VERBOSITY); | ||
| 2844 | |||
| 2845 | # compare Cookie objects OF THE SAME class (we support) for equality | ||
| 2846 | my $yes = cookies_are_equal($cook1, $cook2, $skip_discard, $VERBOSITY); # 1 or 0 or undef | ||
| 2847 | |||
| 2848 | # stringify any Cookies object whose class we support | ||
| 2849 | print as_string_cookies($cook, $skip_discard, $VERBOSITY); | ||
| 2850 | |||
| 2851 | |||
| 2852 | =head1 EXPORT | ||
| 2853 | |||
| 2854 | By default no symbols are exported. You need to manually import any | ||
| 2855 | symbol you wish to use. | ||
| 2856 | However, for your convenience the following export tags are available | ||
| 2857 | for importing symbols in groups. | ||
| 2858 | |||
| 2859 | Note that the C<:all> tag will import all the exportable symbols. | ||
| 2860 | |||
| 2861 | =over 4 | ||
| 2862 | |||
| 2863 | =item * C<:all> : everything | ||
| 2864 | |||
| 2865 | =item * C<:lwpuseragent> : C<lwpuseragent_save_cookies_to_file>, C<lwpuseragent_load_cookies>, C<lwpuseragent_load_cookies_from_file>, C<lwpuseragent_load_setcookies>, C<lwpuseragent_load_httpcookies>, C<lwpuseragent_load_httpcookiejar>, C<lwpuseragent_get_cookies> | ||
| 2866 | |||
| 2867 | =item * C<:wwwmechanize> : C<wwwmechanize_save_cookies_to_file>, C<wwwmechanize_load_cookies>, C<wwwmechanize_load_cookies_from_file>, C<wwwmechanize_load_setcookies>, C<wwwmechanize_load_httpcookies>, C<wwwmechanize_load_httpcookiejar>, C<wwwmechanize_get_cookies> | ||
| 2868 | |||
| 2869 | =item * C<:firefoxmarionette> : C<firefoxmarionettecookies2file>, C<firefoxmarionettecookies2httpcookies>, C<firefoxmarionettecookies2httpcookiejar>, C<firefoxmarionettecookies2setcookies>, | ||
| 2870 | |||
| 2871 | =item * C<:clone> : C<clone_httpcookiejar>, C<clone_httpcookies>, C<clone_setcookies>, C<clone_cookies> | ||
| 2872 | |||
| 2873 | =item * C<:merge> : C<merge_httpcookies>, C<merge_httpcookiejar>, C<merge_setcookies>, C<merge_firefoxmarionettecookies>, C<merge_cookies> | ||
| 2874 | |||
| 2875 | =item * C<:count> : C<count_httpcookies>, C<count_httpcookiejar>, C<count_setcookies>, C<count_firefoxmarionettecookies>, C<count_cookies> | ||
| 2876 | |||
| 2877 | =item * C<:equal> : C<cookies_are_equal>, C<cookies_are_equal_httpcookies>, C<cookies_are_equal_httpcookiejar>, C<cookies_are_equal_setcookies>, C<cookies_are_equal_firefoxmarionettecookie>, C<cookies_are_equal_firefoxmarionettecookies> | ||
| 2878 | |||
| 2879 | =item * C<:setcookies2> : C<setcookies2httpcookiejar>, C<setcookies2httpcookies> | ||
| 2880 | |||
| 2881 | =item * C<:httpcookies2> : C<httpcookies2setcookies>, C<httpcookies2file>, C<httpcookies2httpcookiejar>, C<httpcookies2firefoxmarionettecookies> | ||
| 2882 | |||
| 2883 | =item * C<:httpcookiejar2> : C<httpcookies2setcookies>, C<httpcookies2file>, C<httpcookies2httpcookiejar>, C<httpcookies2firefoxmarionettecookies> | ||
| 2884 | |||
| 2885 | =item * C<:firefoxmarionettecookies2> : C<firefoxmarionettecookies2file>, C<firefoxmarionettecookies2httpcookies>, C<firefoxmarionettecookies2httpcookiejar>, C<firefoxmarionettecookies2setcookies> | ||
| 2886 | |||
| 2887 | =item * C<:new> : C<new_firefoxmarionettecookie>, C<new_firefoxmarionettecookies> | ||
| 2888 | |||
| 2889 | =item * C<:file> : C<file2httpcookiejar>, C<httpcookiejar2file>, C<file2httpcookies>, C<httpcookies2file>, C<firefoxmarionettecookies2file>, C<file2firefoxmarionettecookies>, C<setcookies2file>, C<file2setcookies>, C<lwpuseragent_save_cookies_to_file>, C<lwpuseragent_load_cookies_from_file>, C<wwwmechanize_save_cookies_to_file>, C<wwwmechanize_load_cookies_from_file>, C<cookies2file> | ||
| 2890 | |||
| 2891 | =item * C<:as_string> : C<as_string_httpcookiejar>, C<as_string_httpcookies>, C<as_string_setcookies>, C<as_string_cookies>, C<as_string_firefoxmarionettecookies> | ||
| 2892 | |||
| 2893 | =back | ||
| 2894 | |||
| 2895 | =head1 SUBROUTINES | ||
| 2896 | |||
| 2897 | Below, C<$skip_discard> is a flag | ||
| 2898 | dictating whether | ||
| 2899 | to skip discarded cookies during the operation (value | ||
| 2900 | of C<1>) or not (value of C<0>). | ||
| 2901 | |||
| 2902 | C<$verbosity> denotes the verbosity level | ||
| 2903 | as an integer. C<0> being mute. | ||
| 2904 | |||
| 2905 | |||
| 2906 | =head2 C<lwpuseragent_get_cookies> | ||
| 2907 | |||
| 2908 | my $ret = lwpuseragent_get_cookies($ua, $verbosity); | ||
| 2909 | |||
| 2910 | Arguments: | ||
| 2911 | |||
| 2912 | =over 4 | ||
| 2913 | |||
| 2914 | =item * C<$ua> | ||
| 2915 | |||
| 2916 | =item * C<$verbosity> | ||
| 2917 | |||
| 2918 | =back | ||
| 2919 | |||
| 2920 | Return value: | ||
| 2921 | |||
| 2922 | =over 4 | ||
| 2923 | |||
| 2924 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 2925 | |||
| 2926 | =back | ||
| 2927 | |||
| 2928 | It returns the cookies of the specified L<LWP::UserAgent> object. | ||
| 2929 | |||
| 2930 | =head2 C<lwpuseragent_save_cookies_to_file> | ||
| 2931 | |||
| 2932 | my $ret = lwpuseragent_save_cookies_to_file($ua, $filename, $skip_discard, $verbosity); | ||
| 2933 | |||
| 2934 | Arguments: | ||
| 2935 | |||
| 2936 | =over 4 | ||
| 2937 | |||
| 2938 | =item * C<$ua> | ||
| 2939 | |||
| 2940 | =item * C<$filename> | ||
| 2941 | |||
| 2942 | =item * C<$skip_discard> | ||
| 2943 | |||
| 2944 | =item * C<$verbosity> | ||
| 2945 | |||
| 2946 | =back | ||
| 2947 | |||
| 2948 | Return value: | ||
| 2949 | |||
| 2950 | =over 4 | ||
| 2951 | |||
| 2952 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 2953 | |||
| 2954 | =back | ||
| 2955 | |||
| 2956 | It saves the cookies held in specified L<LWP::UserAgent> object to | ||
| 2957 | specified file. It returns (C<$ret>) C<1> on failure or C<0> on success. | ||
| 2958 | |||
| 2959 | |||
| 2960 | =head2 C<lwpuseragent_load_cookies> | ||
| 2961 | |||
| 2962 | my $ret = lwpuseragent_load_cookies($ua, $cookies_or_file_etc, $verbosity); | ||
| 2963 | |||
| 2964 | Arguments: | ||
| 2965 | |||
| 2966 | =over 4 | ||
| 2967 | |||
| 2968 | =item * C<$ua> | ||
| 2969 | |||
| 2970 | =item * C<$cookies_or_file_etc> | ||
| 2971 | |||
| 2972 | =item * C<$verbosity> | ||
| 2973 | |||
| 2974 | =back | ||
| 2975 | |||
| 2976 | Return value: | ||
| 2977 | |||
| 2978 | =over 4 | ||
| 2979 | |||
| 2980 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 2981 | |||
| 2982 | =back | ||
| 2983 | |||
| 2984 | This is a generic function to load any type of cookies | ||
| 2985 | into the specifed L<LWP::UserAgent> object. Cookies | ||
| 2986 | can be in a file (C<$cookies_or_file_etc> is a scalar holding the filename), | ||
| 2987 | or a Cookies object we support or an ARRAY_REF of C<SetCookie> strings | ||
| 2988 | or an ARRAY_REF of L<Firefox::Marionette::Cookie> objects. | ||
| 2989 | |||
| 2990 | =head2 C<lwpuseragent_load_cookies_from_file> | ||
| 2991 | |||
| 2992 | my $ret = lwpuseragent_load_cookies_from_file($ua, $filename, $skip_discard, $verbosity); | ||
| 2993 | |||
| 2994 | Arguments: | ||
| 2995 | |||
| 2996 | =over 4 | ||
| 2997 | |||
| 2998 | =item * C<$ua> | ||
| 2999 | |||
| 3000 | =item * C<$filename> | ||
| 3001 | |||
| 3002 | =item * C<$skip_discard> | ||
| 3003 | |||
| 3004 | =item * C<$verbosity> | ||
| 3005 | |||
| 3006 | =back | ||
| 3007 | |||
| 3008 | Return value: | ||
| 3009 | |||
| 3010 | =over 4 | ||
| 3011 | |||
| 3012 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3013 | |||
| 3014 | =back | ||
| 3015 | |||
| 3016 | It loads cookies from file into the specifed L<LWP::UserAgent> object. | ||
| 3017 | L<lwpuseragent_load_cookies> will do the same job when specified | ||
| 3018 | with a filename. | ||
| 3019 | |||
| 3020 | It returns C<undef> on failure or | ||
| 3021 | the cookies read from file as a Cookies object on success. | ||
| 3022 | Note that L<LWP::UserAgent> supports both L<HTTP::Cookies> and | ||
| 3023 | L<HTTP::CookieJar>, the class of the returned object will | ||
| 3024 | be one of these, depending what the specified L<LWP::UserAgent> | ||
| 3025 | object was instructed to hold, by using | ||
| 3026 | |||
| 3027 | my $ua = LWP::UserAgent->new(cookie_jar_class=>'HTTP::CookieJar'); | ||
| 3028 | |||
| 3029 | |||
| 3030 | =head2 C<lwpuseragent_load_setcookies> | ||
| 3031 | |||
| 3032 | my $ret = lwpuseragent_load_setcookies($ua, $setcookies, $verbosity); | ||
| 3033 | |||
| 3034 | Arguments: | ||
| 3035 | |||
| 3036 | =over 4 | ||
| 3037 | |||
| 3038 | =item * C<$ua> | ||
| 3039 | |||
| 3040 | =item * C<$setcookies> | ||
| 3041 | |||
| 3042 | =item * C<$verbosity> | ||
| 3043 | |||
| 3044 | =back | ||
| 3045 | |||
| 3046 | Return value: | ||
| 3047 | |||
| 3048 | =over 4 | ||
| 3049 | |||
| 3050 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3051 | |||
| 3052 | =back | ||
| 3053 | |||
| 3054 | =for comment | ||
| 3055 | add here description | ||
| 3056 | |||
| 3057 | =head2 C<lwpuseragent_load_firefoxmarionettecookies> | ||
| 3058 | |||
| 3059 | my $ret = lwpuseragent_load_firefoxmarionettecookies($ua, $firefoxmarionettecookies, $verbosity); | ||
| 3060 | |||
| 3061 | Arguments: | ||
| 3062 | |||
| 3063 | =over 4 | ||
| 3064 | |||
| 3065 | =item * C<$ua> | ||
| 3066 | |||
| 3067 | =item * C<$firefoxmarionettecookies> | ||
| 3068 | |||
| 3069 | =item * C<$verbosity> | ||
| 3070 | |||
| 3071 | =back | ||
| 3072 | |||
| 3073 | Return value: | ||
| 3074 | |||
| 3075 | =over 4 | ||
| 3076 | |||
| 3077 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3078 | |||
| 3079 | =back | ||
| 3080 | |||
| 3081 | =for comment | ||
| 3082 | add here description | ||
| 3083 | |||
| 3084 | =head2 C<lwpuseragent_load_httpcookies> | ||
| 3085 | |||
| 3086 | my $ret = lwpuseragent_load_httpcookies($ua, $httpcookies, $skip_discard, $verbosity); | ||
| 3087 | |||
| 3088 | Arguments: | ||
| 3089 | |||
| 3090 | =over 4 | ||
| 3091 | |||
| 3092 | =item * C<$ua> | ||
| 3093 | |||
| 3094 | =item * C<$httpcookies> | ||
| 3095 | |||
| 3096 | =item * C<$skip_discard> | ||
| 3097 | |||
| 3098 | =item * C<$verbosity> | ||
| 3099 | |||
| 3100 | =back | ||
| 3101 | |||
| 3102 | Return value: | ||
| 3103 | |||
| 3104 | =over 4 | ||
| 3105 | |||
| 3106 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3107 | |||
| 3108 | =back | ||
| 3109 | |||
| 3110 | =for comment | ||
| 3111 | add here description | ||
| 3112 | |||
| 3113 | =head2 C<lwpuseragent_load_httpcookiejar> | ||
| 3114 | |||
| 3115 | my $ret = lwpuseragent_load_httpcookiejar($ua, $httpcookiejar, $skip_discard, $verbosity); | ||
| 3116 | |||
| 3117 | Arguments: | ||
| 3118 | |||
| 3119 | =over 4 | ||
| 3120 | |||
| 3121 | =item * C<$ua> | ||
| 3122 | |||
| 3123 | =item * C<$httpcookiejar> | ||
| 3124 | |||
| 3125 | =item * C<$skip_discard> | ||
| 3126 | |||
| 3127 | =item * C<$verbosity> | ||
| 3128 | |||
| 3129 | =back | ||
| 3130 | |||
| 3131 | Return value: | ||
| 3132 | |||
| 3133 | =over 4 | ||
| 3134 | |||
| 3135 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3136 | |||
| 3137 | =back | ||
| 3138 | |||
| 3139 | =for comment | ||
| 3140 | add here description | ||
| 3141 | |||
| 3142 | =head2 C<firefoxmarionette_get_cookies> | ||
| 3143 | |||
| 3144 | my $ret = firefoxmarionette_get_cookies($ffmar, $verbosity); | ||
| 3145 | |||
| 3146 | Arguments: | ||
| 3147 | |||
| 3148 | =over 4 | ||
| 3149 | |||
| 3150 | =item * C<$ffmar> | ||
| 3151 | |||
| 3152 | =item * C<$verbosity> | ||
| 3153 | |||
| 3154 | =back | ||
| 3155 | |||
| 3156 | Return value: | ||
| 3157 | |||
| 3158 | =over 4 | ||
| 3159 | |||
| 3160 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3161 | |||
| 3162 | =back | ||
| 3163 | |||
| 3164 | =for comment | ||
| 3165 | add here description | ||
| 3166 | |||
| 3167 | =head2 C<firefoxmarionette_save_cookies_to_file> | ||
| 3168 | |||
| 3169 | my $ret = firefoxmarionette_save_cookies_to_file($ffmar, $filename, $skip_discard, $verbosity); | ||
| 3170 | |||
| 3171 | Arguments: | ||
| 3172 | |||
| 3173 | =over 4 | ||
| 3174 | |||
| 3175 | =item * C<$ffmar> | ||
| 3176 | |||
| 3177 | =item * C<$filename> | ||
| 3178 | |||
| 3179 | =item * C<$skip_discard> | ||
| 3180 | |||
| 3181 | =item * C<$verbosity> | ||
| 3182 | |||
| 3183 | =back | ||
| 3184 | |||
| 3185 | Return value: | ||
| 3186 | |||
| 3187 | =over 4 | ||
| 3188 | |||
| 3189 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3190 | |||
| 3191 | =back | ||
| 3192 | |||
| 3193 | =for comment | ||
| 3194 | add here description | ||
| 3195 | |||
| 3196 | =head2 C<firefoxmarionette_load_cookies> | ||
| 3197 | |||
| 3198 | my $ret = firefoxmarionette_load_cookies($ffmar, $cookies_or_file_etc, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3199 | |||
| 3200 | Arguments: | ||
| 3201 | |||
| 3202 | =over 4 | ||
| 3203 | |||
| 3204 | =item * C<$ffmar> | ||
| 3205 | |||
| 3206 | =item * C<$cookies_or_file_etc> | ||
| 3207 | |||
| 3208 | =item * C<$visit_cookie_domain_first> | ||
| 3209 | |||
| 3210 | =item * C<$skip_discard> | ||
| 3211 | |||
| 3212 | =item * C<$verbosity> | ||
| 3213 | |||
| 3214 | =back | ||
| 3215 | |||
| 3216 | Return value: | ||
| 3217 | |||
| 3218 | =over 4 | ||
| 3219 | |||
| 3220 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3221 | |||
| 3222 | =back | ||
| 3223 | |||
| 3224 | =for comment | ||
| 3225 | add here description | ||
| 3226 | |||
| 3227 | =head2 C<firefoxmarionette_load_cookies_from_file> | ||
| 3228 | |||
| 3229 | my $ret = firefoxmarionette_load_cookies_from_file($ffmar, $filename, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3230 | |||
| 3231 | Arguments: | ||
| 3232 | |||
| 3233 | =over 4 | ||
| 3234 | |||
| 3235 | =item * C<$ffmar> | ||
| 3236 | |||
| 3237 | =item * C<$filename> | ||
| 3238 | |||
| 3239 | =item * C<$visit_cookie_domain_first> | ||
| 3240 | |||
| 3241 | =item * C<$skip_discard> | ||
| 3242 | |||
| 3243 | =item * C<$verbosity> | ||
| 3244 | |||
| 3245 | =back | ||
| 3246 | |||
| 3247 | Return value: | ||
| 3248 | |||
| 3249 | =over 4 | ||
| 3250 | |||
| 3251 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3252 | |||
| 3253 | =back | ||
| 3254 | |||
| 3255 | =for comment | ||
| 3256 | add here description | ||
| 3257 | |||
| 3258 | =head2 C<firefoxmarionette_load_setcookies> | ||
| 3259 | |||
| 3260 | my $ret = firefoxmarionette_load_setcookies($ffmar, $setcookies, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3261 | |||
| 3262 | Arguments: | ||
| 3263 | |||
| 3264 | =over 4 | ||
| 3265 | |||
| 3266 | =item * C<$ffmar> | ||
| 3267 | |||
| 3268 | =item * C<$setcookies> | ||
| 3269 | |||
| 3270 | =item * C<$visit_cookie_domain_first> | ||
| 3271 | |||
| 3272 | =item * C<$skip_discard> | ||
| 3273 | |||
| 3274 | =item * C<$verbosity> | ||
| 3275 | |||
| 3276 | =back | ||
| 3277 | |||
| 3278 | Return value: | ||
| 3279 | |||
| 3280 | =over 4 | ||
| 3281 | |||
| 3282 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3283 | |||
| 3284 | =back | ||
| 3285 | |||
| 3286 | =for comment | ||
| 3287 | add here description | ||
| 3288 | |||
| 3289 | =head2 C<firefoxmarionette_load_firefoxmarionettecookies> | ||
| 3290 | |||
| 3291 | my $ret = firefoxmarionette_load_firefoxmarionettecookies($ffmar, $firefoxmarionettecookies, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3292 | |||
| 3293 | Arguments: | ||
| 3294 | |||
| 3295 | =over 4 | ||
| 3296 | |||
| 3297 | =item * C<$ffmar> | ||
| 3298 | |||
| 3299 | =item * C<$firefoxmarionettecookies> | ||
| 3300 | |||
| 3301 | =item * C<$visit_cookie_domain_first> | ||
| 3302 | |||
| 3303 | =item * C<$skip_discard> | ||
| 3304 | |||
| 3305 | =item * C<$verbosity> | ||
| 3306 | |||
| 3307 | =back | ||
| 3308 | |||
| 3309 | Return value: | ||
| 3310 | |||
| 3311 | =over 4 | ||
| 3312 | |||
| 3313 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3314 | |||
| 3315 | =back | ||
| 3316 | |||
| 3317 | =for comment | ||
| 3318 | add here description | ||
| 3319 | |||
| 3320 | =head2 C<firefoxmarionette_load_httpcookies> | ||
| 3321 | |||
| 3322 | my $ret = firefoxmarionette_load_httpcookies($ffmar, $httpcookies, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3323 | |||
| 3324 | Arguments: | ||
| 3325 | |||
| 3326 | =over 4 | ||
| 3327 | |||
| 3328 | =item * C<$ffmar> | ||
| 3329 | |||
| 3330 | =item * C<$httpcookies> | ||
| 3331 | |||
| 3332 | =item * C<$visit_cookie_domain_first> | ||
| 3333 | |||
| 3334 | =item * C<$skip_discard> | ||
| 3335 | |||
| 3336 | =item * C<$verbosity> | ||
| 3337 | |||
| 3338 | =back | ||
| 3339 | |||
| 3340 | Return value: | ||
| 3341 | |||
| 3342 | =over 4 | ||
| 3343 | |||
| 3344 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3345 | |||
| 3346 | =back | ||
| 3347 | |||
| 3348 | =for comment | ||
| 3349 | add here description | ||
| 3350 | |||
| 3351 | =head2 C<firefoxmarionette_load_httpcookiejar> | ||
| 3352 | |||
| 3353 | my $ret = firefoxmarionette_load_httpcookiejar($ffmar, $httpcookiejar, $visit_cookie_domain_first, $skip_discard, $verbosity); | ||
| 3354 | |||
| 3355 | Arguments: | ||
| 3356 | |||
| 3357 | =over 4 | ||
| 3358 | |||
| 3359 | =item * C<$ffmar> | ||
| 3360 | |||
| 3361 | =item * C<$httpcookiejar> | ||
| 3362 | |||
| 3363 | =item * C<$visit_cookie_domain_first> | ||
| 3364 | |||
| 3365 | =item * C<$skip_discard> | ||
| 3366 | |||
| 3367 | =item * C<$verbosity> | ||
| 3368 | |||
| 3369 | =back | ||
| 3370 | |||
| 3371 | Return value: | ||
| 3372 | |||
| 3373 | =over 4 | ||
| 3374 | |||
| 3375 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3376 | |||
| 3377 | =back | ||
| 3378 | |||
| 3379 | =for comment | ||
| 3380 | add here description | ||
| 3381 | |||
| 3382 | =head2 C<wwwmechanize_get_cookies> | ||
| 3383 | |||
| 3384 | my $ret = wwwmechanize_get_cookies($mech, $verbosity); | ||
| 3385 | |||
| 3386 | Arguments: | ||
| 3387 | |||
| 3388 | =over 4 | ||
| 3389 | |||
| 3390 | =item * C<$mech> | ||
| 3391 | |||
| 3392 | =item * C<$verbosity> | ||
| 3393 | |||
| 3394 | =back | ||
| 3395 | |||
| 3396 | Return value: | ||
| 3397 | |||
| 3398 | =over 4 | ||
| 3399 | |||
| 3400 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3401 | |||
| 3402 | =back | ||
| 3403 | |||
| 3404 | =for comment | ||
| 3405 | add here description | ||
| 3406 | |||
| 3407 | =head2 C<wwwmechanize_save_cookies_to_file> | ||
| 3408 | |||
| 3409 | my $ret = wwwmechanize_save_cookies_to_file($mech, $filename, $skip_discard, $verbosity); | ||
| 3410 | |||
| 3411 | Arguments: | ||
| 3412 | |||
| 3413 | =over 4 | ||
| 3414 | |||
| 3415 | =item * C<$mech> | ||
| 3416 | |||
| 3417 | =item * C<$filename> | ||
| 3418 | |||
| 3419 | =item * C<$skip_discard> | ||
| 3420 | |||
| 3421 | =item * C<$verbosity> | ||
| 3422 | |||
| 3423 | =back | ||
| 3424 | |||
| 3425 | Return value: | ||
| 3426 | |||
| 3427 | =over 4 | ||
| 3428 | |||
| 3429 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3430 | |||
| 3431 | =back | ||
| 3432 | |||
| 3433 | =for comment | ||
| 3434 | add here description | ||
| 3435 | |||
| 3436 | =head2 C<wwwmechanize_load_cookies> | ||
| 3437 | |||
| 3438 | my $ret = wwwmechanize_load_cookies($mech, $cookies_or_file_etc, $verbosity); | ||
| 3439 | |||
| 3440 | Arguments: | ||
| 3441 | |||
| 3442 | =over 4 | ||
| 3443 | |||
| 3444 | =item * C<$mech> | ||
| 3445 | |||
| 3446 | =item * C<$cookies_or_file_etc> | ||
| 3447 | |||
| 3448 | =item * C<$verbosity> | ||
| 3449 | |||
| 3450 | =back | ||
| 3451 | |||
| 3452 | Return value: | ||
| 3453 | |||
| 3454 | =over 4 | ||
| 3455 | |||
| 3456 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3457 | |||
| 3458 | =back | ||
| 3459 | |||
| 3460 | =for comment | ||
| 3461 | add here description | ||
| 3462 | |||
| 3463 | =head2 C<wwwmechanize_load_cookies_from_file> | ||
| 3464 | |||
| 3465 | my $ret = wwwmechanize_load_cookies_from_file($mech, $filename, $skip_discard, $verbosity); | ||
| 3466 | |||
| 3467 | Arguments: | ||
| 3468 | |||
| 3469 | =over 4 | ||
| 3470 | |||
| 3471 | =item * C<$mech> | ||
| 3472 | |||
| 3473 | =item * C<$filename> | ||
| 3474 | |||
| 3475 | =item * C<$skip_discard> | ||
| 3476 | |||
| 3477 | =item * C<$verbosity> | ||
| 3478 | |||
| 3479 | =back | ||
| 3480 | |||
| 3481 | Return value: | ||
| 3482 | |||
| 3483 | =over 4 | ||
| 3484 | |||
| 3485 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3486 | |||
| 3487 | =back | ||
| 3488 | |||
| 3489 | =for comment | ||
| 3490 | add here description | ||
| 3491 | |||
| 3492 | =head2 C<wwwmechanize_load_setcookies> | ||
| 3493 | |||
| 3494 | my $ret = wwwmechanize_load_setcookies($mech, $setcookies, $verbosity); | ||
| 3495 | |||
| 3496 | Arguments: | ||
| 3497 | |||
| 3498 | =over 4 | ||
| 3499 | |||
| 3500 | =item * C<$mech> | ||
| 3501 | |||
| 3502 | =item * C<$setcookies> | ||
| 3503 | |||
| 3504 | =item * C<$verbosity> | ||
| 3505 | |||
| 3506 | =back | ||
| 3507 | |||
| 3508 | Return value: | ||
| 3509 | |||
| 3510 | =over 4 | ||
| 3511 | |||
| 3512 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3513 | |||
| 3514 | =back | ||
| 3515 | |||
| 3516 | =for comment | ||
| 3517 | add here description | ||
| 3518 | |||
| 3519 | =head2 C<wwwmechanize_load_firefoxmarionettecookies> | ||
| 3520 | |||
| 3521 | my $ret = wwwmechanize_load_firefoxmarionettecookies($mech, $firefoxmarionettecookies, $verbosity); | ||
| 3522 | |||
| 3523 | Arguments: | ||
| 3524 | |||
| 3525 | =over 4 | ||
| 3526 | |||
| 3527 | =item * C<$mech> | ||
| 3528 | |||
| 3529 | =item * C<$firefoxmarionettecookies> | ||
| 3530 | |||
| 3531 | =item * C<$verbosity> | ||
| 3532 | |||
| 3533 | =back | ||
| 3534 | |||
| 3535 | Return value: | ||
| 3536 | |||
| 3537 | =over 4 | ||
| 3538 | |||
| 3539 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3540 | |||
| 3541 | =back | ||
| 3542 | |||
| 3543 | =for comment | ||
| 3544 | add here description | ||
| 3545 | |||
| 3546 | =head2 C<wwwmechanize_load_httpcookies> | ||
| 3547 | |||
| 3548 | my $ret = wwwmechanize_load_httpcookies($mech, $httpcookies, $skip_discard, $verbosity); | ||
| 3549 | |||
| 3550 | Arguments: | ||
| 3551 | |||
| 3552 | =over 4 | ||
| 3553 | |||
| 3554 | =item * C<$mech> | ||
| 3555 | |||
| 3556 | =item * C<$httpcookies> | ||
| 3557 | |||
| 3558 | =item * C<$skip_discard> | ||
| 3559 | |||
| 3560 | =item * C<$verbosity> | ||
| 3561 | |||
| 3562 | =back | ||
| 3563 | |||
| 3564 | Return value: | ||
| 3565 | |||
| 3566 | =over 4 | ||
| 3567 | |||
| 3568 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3569 | |||
| 3570 | =back | ||
| 3571 | |||
| 3572 | =for comment | ||
| 3573 | add here description | ||
| 3574 | |||
| 3575 | =head2 C<wwwmechanize_load_httpcookiejar> | ||
| 3576 | |||
| 3577 | my $ret = wwwmechanize_load_httpcookiejar($mech, $httpcookiejar, $skip_discard, $verbosity); | ||
| 3578 | |||
| 3579 | Arguments: | ||
| 3580 | |||
| 3581 | =over 4 | ||
| 3582 | |||
| 3583 | =item * C<$mech> | ||
| 3584 | |||
| 3585 | =item * C<$httpcookiejar> | ||
| 3586 | |||
| 3587 | =item * C<$skip_discard> | ||
| 3588 | |||
| 3589 | =item * C<$verbosity> | ||
| 3590 | |||
| 3591 | =back | ||
| 3592 | |||
| 3593 | Return value: | ||
| 3594 | |||
| 3595 | =over 4 | ||
| 3596 | |||
| 3597 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3598 | |||
| 3599 | =back | ||
| 3600 | |||
| 3601 | =for comment | ||
| 3602 | add here description | ||
| 3603 | |||
| 3604 | =head2 C<new_firefoxmarionettecookie> | ||
| 3605 | |||
| 3606 | my $ret = new_firefoxmarionettecookie($params, $skip_discard, $verbosity); | ||
| 3607 | |||
| 3608 | Arguments: | ||
| 3609 | |||
| 3610 | =over 4 | ||
| 3611 | |||
| 3612 | =item * C<$params> | ||
| 3613 | |||
| 3614 | =item * C<$skip_discard> | ||
| 3615 | |||
| 3616 | =item * C<$verbosity> | ||
| 3617 | |||
| 3618 | =back | ||
| 3619 | |||
| 3620 | Return value: | ||
| 3621 | |||
| 3622 | =over 4 | ||
| 3623 | |||
| 3624 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3625 | |||
| 3626 | =back | ||
| 3627 | |||
| 3628 | =for comment | ||
| 3629 | add here description | ||
| 3630 | |||
| 3631 | =head2 C<new_firefoxmarionettecookies> | ||
| 3632 | |||
| 3633 | my $ret = new_firefoxmarionettecookies($params, $skip_discard, $verbosity); | ||
| 3634 | |||
| 3635 | Arguments: | ||
| 3636 | |||
| 3637 | =over 4 | ||
| 3638 | |||
| 3639 | =item * C<$params> | ||
| 3640 | |||
| 3641 | =item * C<$skip_discard> | ||
| 3642 | |||
| 3643 | =item * C<$verbosity> | ||
| 3644 | |||
| 3645 | =back | ||
| 3646 | |||
| 3647 | Return value: | ||
| 3648 | |||
| 3649 | =over 4 | ||
| 3650 | |||
| 3651 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3652 | |||
| 3653 | =back | ||
| 3654 | |||
| 3655 | =for comment | ||
| 3656 | add here description | ||
| 3657 | |||
| 3658 | =head2 C<cookies2file> | ||
| 3659 | |||
| 3660 | my $ret = cookies2file($cookies, $filename, $skip_discard, $verbosity); | ||
| 3661 | |||
| 3662 | Arguments: | ||
| 3663 | |||
| 3664 | =over 4 | ||
| 3665 | |||
| 3666 | =item * C<$cookies> | ||
| 3667 | |||
| 3668 | =item * C<$filename> | ||
| 3669 | |||
| 3670 | =item * C<$skip_discard> | ||
| 3671 | |||
| 3672 | =item * C<$verbosity> | ||
| 3673 | |||
| 3674 | =back | ||
| 3675 | |||
| 3676 | Return value: | ||
| 3677 | |||
| 3678 | =over 4 | ||
| 3679 | |||
| 3680 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3681 | |||
| 3682 | =back | ||
| 3683 | |||
| 3684 | =for comment | ||
| 3685 | add here description | ||
| 3686 | |||
| 3687 | =head2 C<httpcookiejar2file> | ||
| 3688 | |||
| 3689 | my $ret = httpcookiejar2file($httpcookiejar, $filename, $skip_discard, $verbosity); | ||
| 3690 | |||
| 3691 | Arguments: | ||
| 3692 | |||
| 3693 | =over 4 | ||
| 3694 | |||
| 3695 | =item * C<$httpcookiejar> | ||
| 3696 | |||
| 3697 | =item * C<$filename> | ||
| 3698 | |||
| 3699 | =item * C<$skip_discard> | ||
| 3700 | |||
| 3701 | =item * C<$verbosity> | ||
| 3702 | |||
| 3703 | =back | ||
| 3704 | |||
| 3705 | Return value: | ||
| 3706 | |||
| 3707 | =over 4 | ||
| 3708 | |||
| 3709 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3710 | |||
| 3711 | =back | ||
| 3712 | |||
| 3713 | =for comment | ||
| 3714 | add here description | ||
| 3715 | |||
| 3716 | =head2 C<file2httpcookiejar> | ||
| 3717 | |||
| 3718 | my $ret = file2httpcookiejar($filename, $httpcookiejar, $skip_discard, $verbosity); | ||
| 3719 | |||
| 3720 | Arguments: | ||
| 3721 | |||
| 3722 | =over 4 | ||
| 3723 | |||
| 3724 | =item * C<$filename> | ||
| 3725 | |||
| 3726 | =item * C<$httpcookiejar> | ||
| 3727 | |||
| 3728 | =item * C<$skip_discard> | ||
| 3729 | |||
| 3730 | =item * C<$verbosity> | ||
| 3731 | |||
| 3732 | =back | ||
| 3733 | |||
| 3734 | Return value: | ||
| 3735 | |||
| 3736 | =over 4 | ||
| 3737 | |||
| 3738 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3739 | |||
| 3740 | =back | ||
| 3741 | |||
| 3742 | =for comment | ||
| 3743 | add here description | ||
| 3744 | |||
| 3745 | =head2 C<file2httpcookies> | ||
| 3746 | |||
| 3747 | my $ret = file2httpcookies($filename, $httpcookies, $verbosity); | ||
| 3748 | |||
| 3749 | Arguments: | ||
| 3750 | |||
| 3751 | =over 4 | ||
| 3752 | |||
| 3753 | =item * C<$filename> | ||
| 3754 | |||
| 3755 | =item * C<$httpcookies> | ||
| 3756 | |||
| 3757 | =item * C<$verbosity> | ||
| 3758 | |||
| 3759 | =back | ||
| 3760 | |||
| 3761 | Return value: | ||
| 3762 | |||
| 3763 | =over 4 | ||
| 3764 | |||
| 3765 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3766 | |||
| 3767 | =back | ||
| 3768 | |||
| 3769 | =for comment | ||
| 3770 | add here description | ||
| 3771 | |||
| 3772 | =head2 C<httpcookies2file> | ||
| 3773 | |||
| 3774 | my $ret = httpcookies2file($httpcookies, $filename, $skip_discard, $verbosity); | ||
| 3775 | |||
| 3776 | Arguments: | ||
| 3777 | |||
| 3778 | =over 4 | ||
| 3779 | |||
| 3780 | =item * C<$httpcookies> | ||
| 3781 | |||
| 3782 | =item * C<$filename> | ||
| 3783 | |||
| 3784 | =item * C<$skip_discard> | ||
| 3785 | |||
| 3786 | =item * C<$verbosity> | ||
| 3787 | |||
| 3788 | =back | ||
| 3789 | |||
| 3790 | Return value: | ||
| 3791 | |||
| 3792 | =over 4 | ||
| 3793 | |||
| 3794 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3795 | |||
| 3796 | =back | ||
| 3797 | |||
| 3798 | =for comment | ||
| 3799 | add here description | ||
| 3800 | |||
| 3801 | =head2 C<firefoxmarionettecookies2file> | ||
| 3802 | |||
| 3803 | my $ret = firefoxmarionettecookies2file($firefoxmarionettecookies, $filename, $skip_discard, $verbosity); | ||
| 3804 | |||
| 3805 | Arguments: | ||
| 3806 | |||
| 3807 | =over 4 | ||
| 3808 | |||
| 3809 | =item * C<$firefoxmarionettecookies> | ||
| 3810 | |||
| 3811 | =item * C<$filename> | ||
| 3812 | |||
| 3813 | =item * C<$skip_discard> | ||
| 3814 | |||
| 3815 | =item * C<$verbosity> | ||
| 3816 | |||
| 3817 | =back | ||
| 3818 | |||
| 3819 | Return value: | ||
| 3820 | |||
| 3821 | =over 4 | ||
| 3822 | |||
| 3823 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3824 | |||
| 3825 | =back | ||
| 3826 | |||
| 3827 | =for comment | ||
| 3828 | add here description | ||
| 3829 | |||
| 3830 | =head2 C<file2firefoxmarionettecookies> | ||
| 3831 | |||
| 3832 | my $ret = file2firefoxmarionettecookies($filename, $firefoxmarionettecookies, $skip_discard, $verbosity); | ||
| 3833 | |||
| 3834 | Arguments: | ||
| 3835 | |||
| 3836 | =over 4 | ||
| 3837 | |||
| 3838 | =item * C<$filename> | ||
| 3839 | |||
| 3840 | =item * C<$firefoxmarionettecookies> | ||
| 3841 | |||
| 3842 | =item * C<$skip_discard> | ||
| 3843 | |||
| 3844 | =item * C<$verbosity> | ||
| 3845 | |||
| 3846 | =back | ||
| 3847 | |||
| 3848 | Return value: | ||
| 3849 | |||
| 3850 | =over 4 | ||
| 3851 | |||
| 3852 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3853 | |||
| 3854 | =back | ||
| 3855 | |||
| 3856 | =for comment | ||
| 3857 | add here description | ||
| 3858 | |||
| 3859 | =head2 C<setcookies2file> | ||
| 3860 | |||
| 3861 | my $ret = setcookies2file($setcookies, $filename, $skip_discard, $verbosity); | ||
| 3862 | |||
| 3863 | Arguments: | ||
| 3864 | |||
| 3865 | =over 4 | ||
| 3866 | |||
| 3867 | =item * C<$setcookies> | ||
| 3868 | |||
| 3869 | =item * C<$filename> | ||
| 3870 | |||
| 3871 | =item * C<$skip_discard> | ||
| 3872 | |||
| 3873 | =item * C<$verbosity> | ||
| 3874 | |||
| 3875 | =back | ||
| 3876 | |||
| 3877 | Return value: | ||
| 3878 | |||
| 3879 | =over 4 | ||
| 3880 | |||
| 3881 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3882 | |||
| 3883 | =back | ||
| 3884 | |||
| 3885 | =for comment | ||
| 3886 | add here description | ||
| 3887 | |||
| 3888 | =head2 C<file2setcookies> | ||
| 3889 | |||
| 3890 | my $ret = file2setcookies($filename, $setcookies, $skip_discard, $verbosity); | ||
| 3891 | |||
| 3892 | Arguments: | ||
| 3893 | |||
| 3894 | =over 4 | ||
| 3895 | |||
| 3896 | =item * C<$filename> | ||
| 3897 | |||
| 3898 | =item * C<$setcookies> | ||
| 3899 | |||
| 3900 | =item * C<$skip_discard> | ||
| 3901 | |||
| 3902 | =item * C<$verbosity> | ||
| 3903 | |||
| 3904 | =back | ||
| 3905 | |||
| 3906 | Return value: | ||
| 3907 | |||
| 3908 | =over 4 | ||
| 3909 | |||
| 3910 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3911 | |||
| 3912 | =back | ||
| 3913 | |||
| 3914 | =for comment | ||
| 3915 | add here description | ||
| 3916 | |||
| 3917 | =head2 C<httpcookies2httpcookiejar> | ||
| 3918 | |||
| 3919 | my $ret = httpcookies2httpcookiejar($httpcookies, $httpcookiejar, $skip_discard, $verbosity); | ||
| 3920 | |||
| 3921 | Arguments: | ||
| 3922 | |||
| 3923 | =over 4 | ||
| 3924 | |||
| 3925 | =item * C<$httpcookies> | ||
| 3926 | |||
| 3927 | =item * C<$httpcookiejar> | ||
| 3928 | |||
| 3929 | =item * C<$skip_discard> | ||
| 3930 | |||
| 3931 | =item * C<$verbosity> | ||
| 3932 | |||
| 3933 | =back | ||
| 3934 | |||
| 3935 | Return value: | ||
| 3936 | |||
| 3937 | =over 4 | ||
| 3938 | |||
| 3939 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3940 | |||
| 3941 | =back | ||
| 3942 | |||
| 3943 | =for comment | ||
| 3944 | add here description | ||
| 3945 | |||
| 3946 | =head2 C<httpcookies2firefoxmarionettecookies> | ||
| 3947 | |||
| 3948 | my $ret = httpcookies2firefoxmarionettecookies($httpcookies, $firefoxmarionettecookies, $skip_discard, $verbosity); | ||
| 3949 | |||
| 3950 | Arguments: | ||
| 3951 | |||
| 3952 | =over 4 | ||
| 3953 | |||
| 3954 | =item * C<$httpcookies> | ||
| 3955 | |||
| 3956 | =item * C<$firefoxmarionettecookies> | ||
| 3957 | |||
| 3958 | =item * C<$skip_discard> | ||
| 3959 | |||
| 3960 | =item * C<$verbosity> | ||
| 3961 | |||
| 3962 | =back | ||
| 3963 | |||
| 3964 | Return value: | ||
| 3965 | |||
| 3966 | =over 4 | ||
| 3967 | |||
| 3968 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3969 | |||
| 3970 | =back | ||
| 3971 | |||
| 3972 | =for comment | ||
| 3973 | add here description | ||
| 3974 | |||
| 3975 | =head2 C<clone_cookies> | ||
| 3976 | |||
| 3977 | my $ret = clone_cookies($w, $verbosity); | ||
| 3978 | |||
| 3979 | Arguments: | ||
| 3980 | |||
| 3981 | =over 4 | ||
| 3982 | |||
| 3983 | =item * C<$w> | ||
| 3984 | |||
| 3985 | =item * C<$verbosity> | ||
| 3986 | |||
| 3987 | =back | ||
| 3988 | |||
| 3989 | Return value: | ||
| 3990 | |||
| 3991 | =over 4 | ||
| 3992 | |||
| 3993 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 3994 | |||
| 3995 | =back | ||
| 3996 | |||
| 3997 | =for comment | ||
| 3998 | add here description | ||
| 3999 | |||
| 4000 | =head2 C<clone_httpcookiejar> | ||
| 4001 | |||
| 4002 | my $ret = clone_httpcookiejar($httpcookiejar, $verbosity); | ||
| 4003 | |||
| 4004 | Arguments: | ||
| 4005 | |||
| 4006 | =over 4 | ||
| 4007 | |||
| 4008 | =item * C<$httpcookiejar> | ||
| 4009 | |||
| 4010 | =item * C<$verbosity> | ||
| 4011 | |||
| 4012 | =back | ||
| 4013 | |||
| 4014 | Return value: | ||
| 4015 | |||
| 4016 | =over 4 | ||
| 4017 | |||
| 4018 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4019 | |||
| 4020 | =back | ||
| 4021 | |||
| 4022 | =for comment | ||
| 4023 | add here description | ||
| 4024 | |||
| 4025 | =head2 C<clone_firefoxmarionettecookie> | ||
| 4026 | |||
| 4027 | my $ret = clone_firefoxmarionettecookie($firefoxmarionettecookie, $verbosity); | ||
| 4028 | |||
| 4029 | Arguments: | ||
| 4030 | |||
| 4031 | =over 4 | ||
| 4032 | |||
| 4033 | =item * C<$firefoxmarionettecookie> | ||
| 4034 | |||
| 4035 | =item * C<$verbosity> | ||
| 4036 | |||
| 4037 | =back | ||
| 4038 | |||
| 4039 | Return value: | ||
| 4040 | |||
| 4041 | =over 4 | ||
| 4042 | |||
| 4043 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4044 | |||
| 4045 | =back | ||
| 4046 | |||
| 4047 | =for comment | ||
| 4048 | add here description | ||
| 4049 | |||
| 4050 | =head2 C<clone_firefoxmarionettecookies> | ||
| 4051 | |||
| 4052 | my $ret = clone_firefoxmarionettecookies($firefoxmarionettecookies, $verbosity); | ||
| 4053 | |||
| 4054 | Arguments: | ||
| 4055 | |||
| 4056 | =over 4 | ||
| 4057 | |||
| 4058 | =item * C<$firefoxmarionettecookies> | ||
| 4059 | |||
| 4060 | =item * C<$verbosity> | ||
| 4061 | |||
| 4062 | =back | ||
| 4063 | |||
| 4064 | Return value: | ||
| 4065 | |||
| 4066 | =over 4 | ||
| 4067 | |||
| 4068 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4069 | |||
| 4070 | =back | ||
| 4071 | |||
| 4072 | =for comment | ||
| 4073 | add here description | ||
| 4074 | |||
| 4075 | =head2 C<clone_httpcookies> | ||
| 4076 | |||
| 4077 | my $ret = clone_httpcookies($httpcookies, $skip_discard, $verbosity); | ||
| 4078 | |||
| 4079 | Arguments: | ||
| 4080 | |||
| 4081 | =over 4 | ||
| 4082 | |||
| 4083 | =item * C<$httpcookies> | ||
| 4084 | |||
| 4085 | =item * C<$skip_discard> | ||
| 4086 | |||
| 4087 | =item * C<$verbosity> | ||
| 4088 | |||
| 4089 | =back | ||
| 4090 | |||
| 4091 | Return value: | ||
| 4092 | |||
| 4093 | =over 4 | ||
| 4094 | |||
| 4095 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4096 | |||
| 4097 | =back | ||
| 4098 | |||
| 4099 | =for comment | ||
| 4100 | add here description | ||
| 4101 | |||
| 4102 | =head2 C<merge_cookies> | ||
| 4103 | |||
| 4104 | my $ret = merge_cookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4105 | |||
| 4106 | Arguments: | ||
| 4107 | |||
| 4108 | =over 4 | ||
| 4109 | |||
| 4110 | =item * C<$obj1> | ||
| 4111 | |||
| 4112 | =item * C<$obj2> | ||
| 4113 | |||
| 4114 | =item * C<$skip_discard> | ||
| 4115 | |||
| 4116 | =item * C<$verbosity> | ||
| 4117 | |||
| 4118 | =back | ||
| 4119 | |||
| 4120 | Return value: | ||
| 4121 | |||
| 4122 | =over 4 | ||
| 4123 | |||
| 4124 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4125 | |||
| 4126 | =back | ||
| 4127 | |||
| 4128 | =for comment | ||
| 4129 | add here description | ||
| 4130 | |||
| 4131 | =head2 C<merge_httpcookies> | ||
| 4132 | |||
| 4133 | my $ret = merge_httpcookies($httpcookies_src, $httpcookies_dst, $skip_discard, $verbosity); | ||
| 4134 | |||
| 4135 | Arguments: | ||
| 4136 | |||
| 4137 | =over 4 | ||
| 4138 | |||
| 4139 | =item * C<$httpcookies_src> | ||
| 4140 | |||
| 4141 | =item * C<$httpcookies_dst> | ||
| 4142 | |||
| 4143 | =item * C<$skip_discard> | ||
| 4144 | |||
| 4145 | =item * C<$verbosity> | ||
| 4146 | |||
| 4147 | =back | ||
| 4148 | |||
| 4149 | Return value: | ||
| 4150 | |||
| 4151 | =over 4 | ||
| 4152 | |||
| 4153 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4154 | |||
| 4155 | =back | ||
| 4156 | |||
| 4157 | =for comment | ||
| 4158 | add here description | ||
| 4159 | |||
| 4160 | =head2 C<merge_httpcookiejar> | ||
| 4161 | |||
| 4162 | my $ret = merge_httpcookiejar($httpcookiejar_src, $httpcookiejar_dst, $skip_discard, $verbosity); | ||
| 4163 | |||
| 4164 | Arguments: | ||
| 4165 | |||
| 4166 | =over 4 | ||
| 4167 | |||
| 4168 | =item * C<$httpcookiejar_src> | ||
| 4169 | |||
| 4170 | =item * C<$httpcookiejar_dst> | ||
| 4171 | |||
| 4172 | =item * C<$skip_discard> | ||
| 4173 | |||
| 4174 | =item * C<$verbosity> | ||
| 4175 | |||
| 4176 | =back | ||
| 4177 | |||
| 4178 | Return value: | ||
| 4179 | |||
| 4180 | =over 4 | ||
| 4181 | |||
| 4182 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4183 | |||
| 4184 | =back | ||
| 4185 | |||
| 4186 | =for comment | ||
| 4187 | add here description | ||
| 4188 | |||
| 4189 | =head2 C<merge_firefoxmarionettecookies> | ||
| 4190 | |||
| 4191 | my $ret = merge_firefoxmarionettecookies($src, $dst); | ||
| 4192 | |||
| 4193 | Arguments: | ||
| 4194 | |||
| 4195 | =over 4 | ||
| 4196 | |||
| 4197 | =item * C<$src> | ||
| 4198 | |||
| 4199 | =item * C<$dst> | ||
| 4200 | |||
| 4201 | =back | ||
| 4202 | |||
| 4203 | Return value: | ||
| 4204 | |||
| 4205 | =over 4 | ||
| 4206 | |||
| 4207 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4208 | |||
| 4209 | =back | ||
| 4210 | |||
| 4211 | =for comment | ||
| 4212 | add here description | ||
| 4213 | |||
| 4214 | =head2 C<setcookies2httpcookiejar> | ||
| 4215 | |||
| 4216 | my $ret = setcookies2httpcookiejar($setcookies, $httpcookiejar, $verbosity); | ||
| 4217 | |||
| 4218 | Arguments: | ||
| 4219 | |||
| 4220 | =over 4 | ||
| 4221 | |||
| 4222 | =item * C<$setcookies> | ||
| 4223 | |||
| 4224 | =item * C<$httpcookiejar> | ||
| 4225 | |||
| 4226 | =item * C<$verbosity> | ||
| 4227 | |||
| 4228 | =back | ||
| 4229 | |||
| 4230 | Return value: | ||
| 4231 | |||
| 4232 | =over 4 | ||
| 4233 | |||
| 4234 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4235 | |||
| 4236 | =back | ||
| 4237 | |||
| 4238 | =for comment | ||
| 4239 | add here description | ||
| 4240 | |||
| 4241 | =head2 C<setcookies2firefoxmarionettecookies> | ||
| 4242 | |||
| 4243 | my $ret = setcookies2firefoxmarionettecookies($setcookies, $firefoxmarionettecookies, $verbosity); | ||
| 4244 | |||
| 4245 | Arguments: | ||
| 4246 | |||
| 4247 | =over 4 | ||
| 4248 | |||
| 4249 | =item * C<$setcookies> | ||
| 4250 | |||
| 4251 | =item * C<$firefoxmarionettecookies> | ||
| 4252 | |||
| 4253 | =item * C<$verbosity> | ||
| 4254 | |||
| 4255 | =back | ||
| 4256 | |||
| 4257 | Return value: | ||
| 4258 | |||
| 4259 | =over 4 | ||
| 4260 | |||
| 4261 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4262 | |||
| 4263 | =back | ||
| 4264 | |||
| 4265 | =for comment | ||
| 4266 | add here description | ||
| 4267 | |||
| 4268 | =head2 C<setcookie2firefoxmarionettecookie> | ||
| 4269 | |||
| 4270 | my $ret = setcookie2firefoxmarionettecookie($setcookie, $firefoxmarionettecookie, $verbosity); | ||
| 4271 | |||
| 4272 | Arguments: | ||
| 4273 | |||
| 4274 | =over 4 | ||
| 4275 | |||
| 4276 | =item * C<$setcookie> | ||
| 4277 | |||
| 4278 | =item * C<$firefoxmarionettecookie> | ||
| 4279 | |||
| 4280 | =item * C<$verbosity> | ||
| 4281 | |||
| 4282 | =back | ||
| 4283 | |||
| 4284 | Return value: | ||
| 4285 | |||
| 4286 | =over 4 | ||
| 4287 | |||
| 4288 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4289 | |||
| 4290 | =back | ||
| 4291 | |||
| 4292 | =for comment | ||
| 4293 | add here description | ||
| 4294 | |||
| 4295 | =head2 C<count_cookies> | ||
| 4296 | |||
| 4297 | my $ret = count_cookies($w, $skip_discard, $verbosity); | ||
| 4298 | |||
| 4299 | Arguments: | ||
| 4300 | |||
| 4301 | =over 4 | ||
| 4302 | |||
| 4303 | =item * C<$w> | ||
| 4304 | |||
| 4305 | =item * C<$skip_discard> | ||
| 4306 | |||
| 4307 | =item * C<$verbosity> | ||
| 4308 | |||
| 4309 | =back | ||
| 4310 | |||
| 4311 | Return value: | ||
| 4312 | |||
| 4313 | =over 4 | ||
| 4314 | |||
| 4315 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4316 | |||
| 4317 | =back | ||
| 4318 | |||
| 4319 | =for comment | ||
| 4320 | add here description | ||
| 4321 | |||
| 4322 | =head2 C<count_httpcookies> | ||
| 4323 | |||
| 4324 | my $ret = count_httpcookies($httpcookies, $skip_discard, $verbosity); | ||
| 4325 | |||
| 4326 | Arguments: | ||
| 4327 | |||
| 4328 | =over 4 | ||
| 4329 | |||
| 4330 | =item * C<$httpcookies> | ||
| 4331 | |||
| 4332 | =item * C<$skip_discard> | ||
| 4333 | |||
| 4334 | =item * C<$verbosity> | ||
| 4335 | |||
| 4336 | =back | ||
| 4337 | |||
| 4338 | Return value: | ||
| 4339 | |||
| 4340 | =over 4 | ||
| 4341 | |||
| 4342 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4343 | |||
| 4344 | =back | ||
| 4345 | |||
| 4346 | =for comment | ||
| 4347 | add here description | ||
| 4348 | |||
| 4349 | =head2 C<setcookie2httpcookies_set_cookie_array> | ||
| 4350 | |||
| 4351 | my $ret = setcookie2httpcookies_set_cookie_array($setcookie, $verbosity); | ||
| 4352 | |||
| 4353 | Arguments: | ||
| 4354 | |||
| 4355 | =over 4 | ||
| 4356 | |||
| 4357 | =item * C<$setcookie> | ||
| 4358 | |||
| 4359 | =item * C<$verbosity> | ||
| 4360 | |||
| 4361 | =back | ||
| 4362 | |||
| 4363 | Return value: | ||
| 4364 | |||
| 4365 | =over 4 | ||
| 4366 | |||
| 4367 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4368 | |||
| 4369 | =back | ||
| 4370 | |||
| 4371 | =for comment | ||
| 4372 | add here description | ||
| 4373 | |||
| 4374 | =head2 C<setcookie2hash> | ||
| 4375 | |||
| 4376 | my $ret = setcookie2hash($setcookie, $verbosity); | ||
| 4377 | |||
| 4378 | Arguments: | ||
| 4379 | |||
| 4380 | =over 4 | ||
| 4381 | |||
| 4382 | =item * C<$setcookie> | ||
| 4383 | |||
| 4384 | =item * C<$verbosity> | ||
| 4385 | |||
| 4386 | =back | ||
| 4387 | |||
| 4388 | Return value: | ||
| 4389 | |||
| 4390 | =over 4 | ||
| 4391 | |||
| 4392 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4393 | |||
| 4394 | =back | ||
| 4395 | |||
| 4396 | =for comment | ||
| 4397 | add here description | ||
| 4398 | |||
| 4399 | =head2 C<setcookies2httpcookies> | ||
| 4400 | |||
| 4401 | my $ret = setcookies2httpcookies($setcookies, $httpcookies, $verbosity); | ||
| 4402 | |||
| 4403 | Arguments: | ||
| 4404 | |||
| 4405 | =over 4 | ||
| 4406 | |||
| 4407 | =item * C<$setcookies> | ||
| 4408 | |||
| 4409 | =item * C<$httpcookies> | ||
| 4410 | |||
| 4411 | =item * C<$verbosity> | ||
| 4412 | |||
| 4413 | =back | ||
| 4414 | |||
| 4415 | Return value: | ||
| 4416 | |||
| 4417 | =over 4 | ||
| 4418 | |||
| 4419 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4420 | |||
| 4421 | =back | ||
| 4422 | |||
| 4423 | =for comment | ||
| 4424 | add here description | ||
| 4425 | |||
| 4426 | =head2 C<firefoxmarionettecookies2setcookies> | ||
| 4427 | |||
| 4428 | my $ret = firefoxmarionettecookies2setcookies($firefoxmarionettecookies, $setcookies, $skip_discard, $verbosity); | ||
| 4429 | |||
| 4430 | Arguments: | ||
| 4431 | |||
| 4432 | =over 4 | ||
| 4433 | |||
| 4434 | =item * C<$firefoxmarionettecookies> | ||
| 4435 | |||
| 4436 | =item * C<$setcookies> | ||
| 4437 | |||
| 4438 | =item * C<$skip_discard> | ||
| 4439 | |||
| 4440 | =item * C<$verbosity> | ||
| 4441 | |||
| 4442 | =back | ||
| 4443 | |||
| 4444 | Return value: | ||
| 4445 | |||
| 4446 | =over 4 | ||
| 4447 | |||
| 4448 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4449 | |||
| 4450 | =back | ||
| 4451 | |||
| 4452 | =for comment | ||
| 4453 | add here description | ||
| 4454 | |||
| 4455 | =head2 C<firefoxmarionettecookies2httpcookiejar> | ||
| 4456 | |||
| 4457 | my $ret = firefoxmarionettecookies2httpcookiejar($firefoxmarionettecookies, $httpcookiejar, $skip_discard, $verbosity); | ||
| 4458 | |||
| 4459 | Arguments: | ||
| 4460 | |||
| 4461 | =over 4 | ||
| 4462 | |||
| 4463 | =item * C<$firefoxmarionettecookies> | ||
| 4464 | |||
| 4465 | =item * C<$httpcookiejar> | ||
| 4466 | |||
| 4467 | =item * C<$skip_discard> | ||
| 4468 | |||
| 4469 | =item * C<$verbosity> | ||
| 4470 | |||
| 4471 | =back | ||
| 4472 | |||
| 4473 | Return value: | ||
| 4474 | |||
| 4475 | =over 4 | ||
| 4476 | |||
| 4477 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4478 | |||
| 4479 | =back | ||
| 4480 | |||
| 4481 | =for comment | ||
| 4482 | add here description | ||
| 4483 | |||
| 4484 | =head2 C<httpcookiejar2httpcookies> | ||
| 4485 | |||
| 4486 | my $ret = httpcookiejar2httpcookies($httpcookiejar, $httpcookies, $skip_discard, $verbosity); | ||
| 4487 | |||
| 4488 | Arguments: | ||
| 4489 | |||
| 4490 | =over 4 | ||
| 4491 | |||
| 4492 | =item * C<$httpcookiejar> | ||
| 4493 | |||
| 4494 | =item * C<$httpcookies> | ||
| 4495 | |||
| 4496 | =item * C<$skip_discard> | ||
| 4497 | |||
| 4498 | =item * C<$verbosity> | ||
| 4499 | |||
| 4500 | =back | ||
| 4501 | |||
| 4502 | Return value: | ||
| 4503 | |||
| 4504 | =over 4 | ||
| 4505 | |||
| 4506 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4507 | |||
| 4508 | =back | ||
| 4509 | |||
| 4510 | =for comment | ||
| 4511 | add here description | ||
| 4512 | |||
| 4513 | =head2 C<firefoxmarionettecookies2httpcookies> | ||
| 4514 | |||
| 4515 | my $ret = firefoxmarionettecookies2httpcookies($firefoxmarionettecookies, $httpcookies, $skip_discard, $verbosity); | ||
| 4516 | |||
| 4517 | Arguments: | ||
| 4518 | |||
| 4519 | =over 4 | ||
| 4520 | |||
| 4521 | =item * C<$firefoxmarionettecookies> | ||
| 4522 | |||
| 4523 | =item * C<$httpcookies> | ||
| 4524 | |||
| 4525 | =item * C<$skip_discard> | ||
| 4526 | |||
| 4527 | =item * C<$verbosity> | ||
| 4528 | |||
| 4529 | =back | ||
| 4530 | |||
| 4531 | Return value: | ||
| 4532 | |||
| 4533 | =over 4 | ||
| 4534 | |||
| 4535 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4536 | |||
| 4537 | =back | ||
| 4538 | |||
| 4539 | =for comment | ||
| 4540 | add here description | ||
| 4541 | |||
| 4542 | =head2 C<httpcookies2setcookies> | ||
| 4543 | |||
| 4544 | my $ret = httpcookies2setcookies($httpcookies, $setcookies, $skip_discard, $verbosity); | ||
| 4545 | |||
| 4546 | Arguments: | ||
| 4547 | |||
| 4548 | =over 4 | ||
| 4549 | |||
| 4550 | =item * C<$httpcookies> | ||
| 4551 | |||
| 4552 | =item * C<$setcookies> | ||
| 4553 | |||
| 4554 | =item * C<$skip_discard> | ||
| 4555 | |||
| 4556 | =item * C<$verbosity> | ||
| 4557 | |||
| 4558 | =back | ||
| 4559 | |||
| 4560 | Return value: | ||
| 4561 | |||
| 4562 | =over 4 | ||
| 4563 | |||
| 4564 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4565 | |||
| 4566 | =back | ||
| 4567 | |||
| 4568 | =for comment | ||
| 4569 | add here description | ||
| 4570 | |||
| 4571 | =head2 C<httpcookiejar2setcookies> | ||
| 4572 | |||
| 4573 | my $ret = httpcookiejar2setcookies($httpcookiejar, $setcookies, $verbosity); | ||
| 4574 | |||
| 4575 | Arguments: | ||
| 4576 | |||
| 4577 | =over 4 | ||
| 4578 | |||
| 4579 | =item * C<$httpcookiejar> | ||
| 4580 | |||
| 4581 | =item * C<$setcookies> | ||
| 4582 | |||
| 4583 | =item * C<$verbosity> | ||
| 4584 | |||
| 4585 | =back | ||
| 4586 | |||
| 4587 | Return value: | ||
| 4588 | |||
| 4589 | =over 4 | ||
| 4590 | |||
| 4591 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4592 | |||
| 4593 | =back | ||
| 4594 | |||
| 4595 | =for comment | ||
| 4596 | add here description | ||
| 4597 | |||
| 4598 | =head2 C<httpcookiejar2firefoxmarionettecookies> | ||
| 4599 | |||
| 4600 | my $ret = httpcookiejar2firefoxmarionettecookies($httpcookiejar, $firefoxmarionettecookies, $verbosity); | ||
| 4601 | |||
| 4602 | Arguments: | ||
| 4603 | |||
| 4604 | =over 4 | ||
| 4605 | |||
| 4606 | =item * C<$httpcookiejar> | ||
| 4607 | |||
| 4608 | =item * C<$firefoxmarionettecookies> | ||
| 4609 | |||
| 4610 | =item * C<$verbosity> | ||
| 4611 | |||
| 4612 | =back | ||
| 4613 | |||
| 4614 | Return value: | ||
| 4615 | |||
| 4616 | =over 4 | ||
| 4617 | |||
| 4618 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4619 | |||
| 4620 | =back | ||
| 4621 | |||
| 4622 | =for comment | ||
| 4623 | add here description | ||
| 4624 | |||
| 4625 | =head2 C<as_string_cookies> | ||
| 4626 | |||
| 4627 | my $ret = as_string_cookies($w, $skip_discard, $verbosity); | ||
| 4628 | |||
| 4629 | Arguments: | ||
| 4630 | |||
| 4631 | =over 4 | ||
| 4632 | |||
| 4633 | =item * C<$w> | ||
| 4634 | |||
| 4635 | =item * C<$skip_discard> | ||
| 4636 | |||
| 4637 | =item * C<$verbosity> | ||
| 4638 | |||
| 4639 | =back | ||
| 4640 | |||
| 4641 | Return value: | ||
| 4642 | |||
| 4643 | =over 4 | ||
| 4644 | |||
| 4645 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4646 | |||
| 4647 | =back | ||
| 4648 | |||
| 4649 | =for comment | ||
| 4650 | add here description | ||
| 4651 | |||
| 4652 | =head2 C<as_string_firefoxmarionettecookies> | ||
| 4653 | |||
| 4654 | my $ret = as_string_firefoxmarionettecookies($w, $skip_discard, $verbosity); | ||
| 4655 | |||
| 4656 | Arguments: | ||
| 4657 | |||
| 4658 | =over 4 | ||
| 4659 | |||
| 4660 | =item * C<$w> | ||
| 4661 | |||
| 4662 | =item * C<$skip_discard> | ||
| 4663 | |||
| 4664 | =item * C<$verbosity> | ||
| 4665 | |||
| 4666 | =back | ||
| 4667 | |||
| 4668 | Return value: | ||
| 4669 | |||
| 4670 | =over 4 | ||
| 4671 | |||
| 4672 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4673 | |||
| 4674 | =back | ||
| 4675 | |||
| 4676 | =for comment | ||
| 4677 | add here description | ||
| 4678 | |||
| 4679 | =head2 C<as_string_firefoxmarionettecookie> | ||
| 4680 | |||
| 4681 | my $ret = as_string_firefoxmarionettecookie($w, $skip_discard, $verbosity); | ||
| 4682 | |||
| 4683 | Arguments: | ||
| 4684 | |||
| 4685 | =over 4 | ||
| 4686 | |||
| 4687 | =item * C<$w> | ||
| 4688 | |||
| 4689 | =item * C<$skip_discard> | ||
| 4690 | |||
| 4691 | =item * C<$verbosity> | ||
| 4692 | |||
| 4693 | =back | ||
| 4694 | |||
| 4695 | Return value: | ||
| 4696 | |||
| 4697 | =over 4 | ||
| 4698 | |||
| 4699 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4700 | |||
| 4701 | =back | ||
| 4702 | |||
| 4703 | =for comment | ||
| 4704 | add here description | ||
| 4705 | |||
| 4706 | =head2 C<as_string_httpcookies> | ||
| 4707 | |||
| 4708 | my $ret = as_string_httpcookies($httpcookies, $skip_discard, $verbosity); | ||
| 4709 | |||
| 4710 | Arguments: | ||
| 4711 | |||
| 4712 | =over 4 | ||
| 4713 | |||
| 4714 | =item * C<$httpcookies> | ||
| 4715 | |||
| 4716 | =item * C<$skip_discard> | ||
| 4717 | |||
| 4718 | =item * C<$verbosity> | ||
| 4719 | |||
| 4720 | =back | ||
| 4721 | |||
| 4722 | Return value: | ||
| 4723 | |||
| 4724 | =over 4 | ||
| 4725 | |||
| 4726 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4727 | |||
| 4728 | =back | ||
| 4729 | |||
| 4730 | =for comment | ||
| 4731 | add here description | ||
| 4732 | |||
| 4733 | =head2 C<cookies_are_equal> | ||
| 4734 | |||
| 4735 | my $ret = cookies_are_equal($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4736 | |||
| 4737 | Arguments: | ||
| 4738 | |||
| 4739 | =over 4 | ||
| 4740 | |||
| 4741 | =item * C<$obj1> | ||
| 4742 | |||
| 4743 | =item * C<$obj2> | ||
| 4744 | |||
| 4745 | =item * C<$skip_discard> | ||
| 4746 | |||
| 4747 | =item * C<$verbosity> | ||
| 4748 | |||
| 4749 | =back | ||
| 4750 | |||
| 4751 | Return value: | ||
| 4752 | |||
| 4753 | =over 4 | ||
| 4754 | |||
| 4755 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4756 | |||
| 4757 | =back | ||
| 4758 | |||
| 4759 | =for comment | ||
| 4760 | add here description | ||
| 4761 | |||
| 4762 | =head2 C<cookies_are_equal_setcookies> | ||
| 4763 | |||
| 4764 | my $ret = cookies_are_equal_setcookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4765 | |||
| 4766 | Arguments: | ||
| 4767 | |||
| 4768 | =over 4 | ||
| 4769 | |||
| 4770 | =item * C<$obj1> | ||
| 4771 | |||
| 4772 | =item * C<$obj2> | ||
| 4773 | |||
| 4774 | =item * C<$skip_discard> | ||
| 4775 | |||
| 4776 | =item * C<$verbosity> | ||
| 4777 | |||
| 4778 | =back | ||
| 4779 | |||
| 4780 | Return value: | ||
| 4781 | |||
| 4782 | =over 4 | ||
| 4783 | |||
| 4784 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4785 | |||
| 4786 | =back | ||
| 4787 | |||
| 4788 | =for comment | ||
| 4789 | add here description | ||
| 4790 | |||
| 4791 | =head2 C<cookies_are_equal_firefoxmarionettecookie> | ||
| 4792 | |||
| 4793 | my $ret = cookies_are_equal_firefoxmarionettecookie($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4794 | |||
| 4795 | Arguments: | ||
| 4796 | |||
| 4797 | =over 4 | ||
| 4798 | |||
| 4799 | =item * C<$obj1> | ||
| 4800 | |||
| 4801 | =item * C<$obj2> | ||
| 4802 | |||
| 4803 | =item * C<$skip_discard> | ||
| 4804 | |||
| 4805 | =item * C<$verbosity> | ||
| 4806 | |||
| 4807 | =back | ||
| 4808 | |||
| 4809 | Return value: | ||
| 4810 | |||
| 4811 | =over 4 | ||
| 4812 | |||
| 4813 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4814 | |||
| 4815 | =back | ||
| 4816 | |||
| 4817 | =for comment | ||
| 4818 | add here description | ||
| 4819 | |||
| 4820 | =head2 C<cookies_are_equal_firefoxmarionettecookies> | ||
| 4821 | |||
| 4822 | my $ret = cookies_are_equal_firefoxmarionettecookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4823 | |||
| 4824 | Arguments: | ||
| 4825 | |||
| 4826 | =over 4 | ||
| 4827 | |||
| 4828 | =item * C<$obj1> | ||
| 4829 | |||
| 4830 | =item * C<$obj2> | ||
| 4831 | |||
| 4832 | =item * C<$skip_discard> | ||
| 4833 | |||
| 4834 | =item * C<$verbosity> | ||
| 4835 | |||
| 4836 | =back | ||
| 4837 | |||
| 4838 | Return value: | ||
| 4839 | |||
| 4840 | =over 4 | ||
| 4841 | |||
| 4842 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4843 | |||
| 4844 | =back | ||
| 4845 | |||
| 4846 | =for comment | ||
| 4847 | add here description | ||
| 4848 | |||
| 4849 | =head2 C<cookies_are_equal_httpcookies> | ||
| 4850 | |||
| 4851 | my $ret = cookies_are_equal_httpcookies($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4852 | |||
| 4853 | Arguments: | ||
| 4854 | |||
| 4855 | =over 4 | ||
| 4856 | |||
| 4857 | =item * C<$obj1> | ||
| 4858 | |||
| 4859 | =item * C<$obj2> | ||
| 4860 | |||
| 4861 | =item * C<$skip_discard> | ||
| 4862 | |||
| 4863 | =item * C<$verbosity> | ||
| 4864 | |||
| 4865 | =back | ||
| 4866 | |||
| 4867 | Return value: | ||
| 4868 | |||
| 4869 | =over 4 | ||
| 4870 | |||
| 4871 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4872 | |||
| 4873 | =back | ||
| 4874 | |||
| 4875 | =for comment | ||
| 4876 | add here description | ||
| 4877 | |||
| 4878 | =head2 C<cookies_are_equal_httpcookies_bad> | ||
| 4879 | |||
| 4880 | my $ret = cookies_are_equal_httpcookies_bad($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4881 | |||
| 4882 | Arguments: | ||
| 4883 | |||
| 4884 | =over 4 | ||
| 4885 | |||
| 4886 | =item * C<$obj1> | ||
| 4887 | |||
| 4888 | =item * C<$obj2> | ||
| 4889 | |||
| 4890 | =item * C<$skip_discard> | ||
| 4891 | |||
| 4892 | =item * C<$verbosity> | ||
| 4893 | |||
| 4894 | =back | ||
| 4895 | |||
| 4896 | Return value: | ||
| 4897 | |||
| 4898 | =over 4 | ||
| 4899 | |||
| 4900 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4901 | |||
| 4902 | =back | ||
| 4903 | |||
| 4904 | =for comment | ||
| 4905 | add here description | ||
| 4906 | |||
| 4907 | =head2 C<cookies_are_equal_httpcookiejar> | ||
| 4908 | |||
| 4909 | my $ret = cookies_are_equal_httpcookiejar($obj1, $obj2, $skip_discard, $verbosity); | ||
| 4910 | |||
| 4911 | Arguments: | ||
| 4912 | |||
| 4913 | =over 4 | ||
| 4914 | |||
| 4915 | =item * C<$obj1> | ||
| 4916 | |||
| 4917 | =item * C<$obj2> | ||
| 4918 | |||
| 4919 | =item * C<$skip_discard> | ||
| 4920 | |||
| 4921 | =item * C<$verbosity> | ||
| 4922 | |||
| 4923 | =back | ||
| 4924 | |||
| 4925 | Return value: | ||
| 4926 | |||
| 4927 | =over 4 | ||
| 4928 | |||
| 4929 | =item * C<$ret> : a cookie object on success or C<undef> on failure. | ||
| 4930 | |||
| 4931 | =back | ||
| 4932 | |||
| 4933 | =for comment | ||
| 4934 | add here description | ||
| 4935 | |||
| 4936 | |||
| 4937 | =head1 CAVEATS | ||
| 4938 | |||
| 4939 | Converting between Perl Cookie classes is a futile task. | ||
| 4940 | Those who implemented a second Perl Cookie class are | ||
| 4941 | doing a dis-service to the community. | ||
| 4942 | |||
| 4943 | This module can fail at any time. If it does, please | ||
| 4944 | provide the details AND the remedy. | ||
| 4945 | |||
| 4946 | |||
| 4947 | =head1 AUTHOR | ||
| 4948 | |||
| 4949 | Andreas Hadjiprocopis, C<< <bliako at cpan.org> >> | ||
| 4950 | |||
| 4951 | =head1 BUGS | ||
| 4952 | |||
| 4953 | Please report any bugs or feature requests to C<bug-cookies-roundtrip at rt.cpan.org>, or through | ||
| 4954 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cookies-Roundtrip>. I will be notified, and then you'll | ||
| 4955 | automatically be notified of progress on your bug as I make changes. | ||
| 4956 | |||
| 4957 | |||
| 4958 | |||
| 4959 | |||
| 4960 | =head1 SUPPORT | ||
| 4961 | |||
| 4962 | You can find documentation for this module with the perldoc command. | ||
| 4963 | |||
| 4964 | perldoc Cookies::Roundtrip | ||
| 4965 | |||
| 4966 | |||
| 4967 | You can also look for information at: | ||
| 4968 | |||
| 4969 | =over 4 | ||
| 4970 | |||
| 4971 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 4972 | |||
| 4973 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Cookies-Roundtrip> | ||
| 4974 | |||
| 4975 | =item * CPAN Ratings | ||
| 4976 | |||
| 4977 | L<https://cpanratings.perl.org/d/Cookies-Roundtrip> | ||
| 4978 | |||
| 4979 | =item * Search CPAN | ||
| 4980 | |||
| 4981 | L<https://metacpan.org/release/Cookies-Roundtrip> | ||
| 4982 | |||
| 4983 | =back | ||
| 4984 | |||
| 4985 | |||
| 4986 | =head1 ACKNOWLEDGEMENTS | ||
| 4987 | |||
| 4988 | |||
| 4989 | =head1 LICENSE AND COPYRIGHT | ||
| 4990 | |||
| 4991 | This software is Copyright (c) 2025 by Andreas Hadjiprocopis. | ||
| 4992 | |||
| 4993 | This is free software, licensed under: | ||
| 4994 | |||
| 4995 | The Artistic License 2.0 (GPL Compatible) | ||
| 4996 | |||
| 4997 | |||
| 4998 | =cut | ||
| 4999 | |||
| 5000 | 1; # End of Cookies::Roundtrip | ||
| 5001 | |||