joes 2004/07/24 17:30:49
Modified: build xsbuilder.pl
glue/perl/docs Cookie.pod
glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
glue/perl/xsbuilder/maps apreq_structures.map
apreq_types.map
Log:
Expose cookie->version and fix a bug in expires' argument checking (it missed
the items==2 assignment case).
Revision Changes Path
1.31 +17 -0 httpd-apreq-2/build/xsbuilder.pl
Index: xsbuilder.pl
===================================================================
RCS file: /home/cvs/httpd-apreq-2/build/xsbuilder.pl,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- xsbuilder.pl 20 Jul 2004 04:17:23 -0000 1.30
+++ xsbuilder.pl 25 Jul 2004 00:30:49 -0000 1.31
@@ -366,6 +366,19 @@
package My::TypeMap;
use base 'ExtUtils::XSBuilder::TypeMap';
+sub null_type {
+ my($self, $type) = @_;
+ my $t = $self->get->{$type};
+ my $class = $t -> {class} ;
+
+ if ($class =~ /APREQ_COOKIE_VERSION/) {
+ return 'APREQ_COOKIE_VERSION_DEFAULT';
+ }
+ else {
+ return $self->SUPER::null_type($type);
+ }
+}
+
# XXX this needs serious work
sub typemap_code
{
@@ -393,6 +406,10 @@
perl2c => 'apreq_xs_sv2(jar,sv)',
OUTPUT => '$arg =
apreq_xs_2sv($var,\"${ntype}\");',
c2perl => 'apreq_xs_2sv(ptr,\"$class\")',
+ },
+ T_APREQ_COOKIE_VERSION => {
+ INPUT => '$var =
((apreq_cookie_version_t)SvTRUE($arg))',
+ OUTPUT => '$arg = boolSV((bool)$var);',
},
T_HASHOBJ => {
INPUT => <<'EOT', # '$var =
modperl_hash_tied_object(aTHX_ \"${ntype}\", $arg)'
1.3 +119 -45 httpd-apreq-2/glue/perl/docs/Cookie.pod
Index: Cookie.pod
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/docs/Cookie.pod,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Cookie.pod 24 Jul 2004 21:09:18 -0000 1.2
+++ Cookie.pod 25 Jul 2004 00:30:49 -0000 1.3
@@ -1,9 +1,7 @@
=head1 NAME
-
Apache::Cookie - HTTP Cookies Class
-
=for testing
use Apache2;
use Apache::Cookie;
@@ -64,14 +62,14 @@
=head1 Apache::Cookie::Jar
-XXX Dump __PACKAGE__->env inheritance (doesn't work in CGI context) XXX
-=head2 new($env [,VALUE_CLASS => $cookie_class])
+
+=head2 new($env, %settings)
Class method that retrieves the parsed cookie jar from the current
-environment. The optional VALUE_CLASS => $cookie_class instructs
+environment. The optional VALUE_CLASS => $cookie_class setting instructs
the jar to bless any returned cookies into $cookie_class, instead
of Apache::Cookie. This feature could be most useful in situations
where C<Apache::Cookie::thaw> is unable to correctly interpret an incoming
@@ -96,7 +94,8 @@
-=head2 cookies($key)
+
+=head2 cookies(), cookies($key)
Retrieve cookies named $key with from the jar object. In scalar
context the first such cookie is returned, and in list context the
@@ -121,7 +120,6 @@
C<cookies> will croak if the parser failed to successfully parse the
"Cookie" header.
-
=for example begin
$j->cookies->add(Apache::Cookie->new($r, name => "foo", value => 3));
@@ -141,11 +139,12 @@
ok "foo bar foo" eq "@names";
-=head2 status
-Reports the final I<APR> status code of the cookie parser:
-APR_SUCCESS on success, error otherwise. May be reset
-to a new value by passing it as an additional argument.
+
+=head2 status(), status($set)
+
+Get or set the I<APR> status code of the cookie parser:
+APR_SUCCESS on success, error otherwise.
=for example begin
@@ -158,10 +157,14 @@
=for example end
=for example_testing
- @cookies = $j->cookies("foo");
ok $j->status == 0;
+ @cookies = $j->cookies("foo");
+ ok @cookies == 2;
-=head2 env
+
+
+
+=head2 env()
As a class method C<< Apache::Cookie::Jar->env >> returns
the environment class associated with Apache::Cookie::Jar.
@@ -185,9 +188,9 @@
-=head2 new
+=head2 new($env, %attributes)
-Just like CGI::Cookie::new, but requires an I<Apache> request object:
+Just like CGI::Cookie::new, but requires an environment argument $r:
=for example begin
@@ -203,47 +206,68 @@
=for example end
=for example_testing
- ok $cookie->name eq "foo";
- ok $cookie->value eq "bar";
- ok $cookie->domain eq ".capricorn.com";
- ok $cookie->path eq "/cgi-bin/database";
- ok $cookie->secure == 1;
+ ok $cookie->name eq "foo";
+ ok $cookie->value eq "bar";
+ ok $cookie->domain eq ".capricorn.com";
+ ok $cookie->path eq "/cgi-bin/database";
+ ok $cookie->secure == 1;
The C<-value> attribute may be either an arrayref, a hashref, or
an object with a C<freeze> method. The <freeze> method must serialize
the object in a manner compatible with the "value" portion of the
-Cookie specs. Specifically, it must take care to avoid header tokens [;,=]
+Cookie specs. Specifically, it must take care to avoid header tokens [;,]
and whitespace characters in its output.
-=head2 as_string
+
+
+=head2 as_string()
Format the cookie object as a string:
=for example begin
- print $cookie->as_string;
-
+ print $cookie->as_string;
-=end example begin
+=for example end
=for example_testing
- ok substr($_STDOUT_, 0, 8) eq "foo=bar;";
+ ok substr($_STDOUT_, 0, 8) eq "foo=bar;";
+
-=head2 name
+
+=head2 name()
Get the name of the cookie:
- my $name = $cookie->name;
+=for example begin
+ my $name = $cookie->name;
-=head2 value
+=for example end
+
+=for example_testing
+ ok $name eq "foo";
-Get the value of the cookie:
- my $value = $cookie->value;
- my @values = $cookie->value;
+
+
+=head2 value()
+
+Get the (unswizzled) value of the cookie:
+
+=for example begin
+
+ my $value = $cookie->value;
+ my @values = $cookie->value;
+
+=for example end
+
+=for example_testing
+ ok @values == 1;
+ ok $value eq "bar";
+ ok $values[0] eq "bar";
Note: if the cookie's value was serialized from an object possessing a
C<freeze> method, one way to reconstitute the object is by subclassing
@@ -264,7 +288,8 @@
-=head2 raw_value
+
+=head2 raw_value()
Gets the raw (opaque) value string as it appears in the incoming
"Cookie" header. The quote-operator for Apache::Cookie is
@@ -281,21 +306,27 @@
# run the example, don't just compile it
-=head2 bake
+
+
+=head2 bake()
Adds a I<Set-Cookie> header to the outgoing headers table.
$cookie->bake;
-=head2 bake2
+
+
+=head2 bake2()
Adds a I<Set-Cookie2> header to the outgoing headers table.
$cookie->bake2;
-=head2 domain
+
+
+=head2 domain, domain($set)
Get or set the domain for the cookie:
@@ -311,7 +342,9 @@
ok $cookie->domain eq ".cp.net";
-=head2 path
+
+
+=head2 path(), path($set)
Get or set the path for the cookie:
@@ -327,17 +360,49 @@
ok $cookie->path eq "/";
-=head2 expires
-Get or set the expire time for the cookie:
+
+=head2 version(), version($set)
+
+Get or set the cookie version for this cookie.
+Netscape spec cookies have version = 0;
+RFC-compliant cookies have version = 1.
+
+=for example begin
+
+ ok $cookie->version == 0;
+ $cookie->version(1);
+ ok $cookie->version == 1;
+
+=for example end
+
+=for example_testing
+ # run the example tests
+
+
+
+
+=head2 expires(), expires($set)
+
+Get or set the future expire time for the cookie. When
+assigning, the new value ($set) should match /^\+?(\d+)([YMDhms]?)$/
+$2 qualifies the number in $1 as representing "Y"ears, "M"onths,
+"D"ays, "h"ours, "m"inutes, or "s"econds (if the qualifier is
+omitted, the number is interpreted as representing seconds).
+As a special case, $set = "now" is equivalent to $set = "0".
=for example begin
- my $expires = $cookie->expires;
- $cookie->expires("+3h");
+ my $expires = $cookie->expires;
+ $cookie->expires("+3h"); # cookie is set to expire in 3 hours
=for example end
+=for example_testing
+ ok $cookie->expires == 3 * 3600;
+
+
+
=head2 secure
@@ -345,11 +410,18 @@
=for example begin
- my $secure = $cookie->secure;
- $cookie->secure(1);
+ $cookie->secure(1);
+ $is_secure = $cookie->secure;
+ $cookie->secure(0);
=for example end
+=for example_testing
+ ok $is_secure;
+ ok (not $cookie->secure);
+
+
+
=head2 fetch
@@ -365,14 +437,13 @@
=for example_testing
ok "foobarfoo" eq join "", keys %$cookies;
+ ok 123 == join "", map "$_", values %$cookies;
ok "barfoo" eq join "", sort keys %cookies; # %cookies lost original foo
cookie
ok 23 == join "", sort map "$_", values %cookies;
-
-
=head1 PORTING
Changes to the 1.X API:
@@ -394,10 +465,13 @@
+
=head1 SEE ALSO
CGI::Cookie(3), Apache::Cookie::Error(3), Apache::Cookie::Jar::Error(3),
Apache::Cookie::Table(3), Apache::Request(3), APR(3).
+
+
=head1 COPYRIGHT
1.32 +2 -1
httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h
Index: Apache__Cookie.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Apache__Cookie.h 24 Jul 2004 21:09:18 -0000 1.31
+++ Apache__Cookie.h 25 Jul 2004 00:30:49 -0000 1.32
@@ -134,7 +134,7 @@
dXSARGS;
apreq_cookie_t *c;
- if (items == 0 || items > 1 || !SvROK(ST(0)))
+ if (items == 0 || items > 2 || !SvROK(ST(0)))
Perl_croak(aTHX_ "Usage: $cookie->expires([$amount])");
c = apreq_xs_sv2(cookie,ST(0));
@@ -142,6 +142,7 @@
if (items > 1) {
const char *s = SvPV_nolen(ST(1));
apreq_cookie_expires(c, s);
+ XSRETURN(0);
}
if (c->max_age == -1)
1.10 +1 -1
httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map
Index: apreq_structures.map
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apreq_structures.map 24 Jul 2004 21:09:18 -0000 1.9
+++ apreq_structures.map 25 Jul 2004 00:30:49 -0000 1.10
@@ -23,7 +23,7 @@
</apreq_request_t>
<apreq_cookie_t MODULE=Apache::Cookie>
-! version
+ version
path
domain
port
1.7 +1 -0 httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_types.map
Index: apreq_types.map
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_types.map,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq_types.map 24 Jul 2004 21:09:18 -0000 1.6
+++ apreq_types.map 25 Jul 2004 00:30:49 -0000 1.7
@@ -9,6 +9,7 @@
void * | PTR
const void * | PTR
unsigned | UV
+apreq_cookie_version_t | APREQ_COOKIE_VERSION
#data structure stuff
struct apr_pool_t | APR::Pool | T_POOLOBJ