CGI-Cookie-XS
view release on metacpan or search on metacpan
0.16 Sep 12 2008
* Fixed an issue in POD.
0.15 Sep 11 2008
* Some minor optimization (";" is never actually used to separate multiple values for a single key).
* Added Filter::Util::Call to the dependency list.
0.14 Sep 10 2008
* Carefully reviewed the old implementation and gave it a massive rewrite.
* Fixed the issue in #39120
* Fixed a lot of incompatibilities with the latest CGI::Cookie.
0.13 Arg 4 2008
* Fixed the module name in the test suite; we now use CGI::Cookie::XS, rather than Cookie::XS.
0.12 Arg 4 2008
* Fixed a typo in the POD.
0.11 Aug 4 2008
* Renamed the module to CGI::Cookie::XS.
0.10 Aug 4 2008
* Put a notice saying that Cookie::XS is deprecated; one should use CGI::Cookie::XS instead.
0.09 Mar 24 2008
* Enabled the tests in 99-pod-coverage.t.
0.08 Mar 20 2008
* Fixed the foo=ba=r bug reported by RT #34238.
* Fixed a stack overflow when input cookies are too big.
* Added a lot of stuff to the POD documentation.
* Cleaned up the XS code a bit.
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
inc/Module/Install/TestBase.pm
inc/Spiffy.pm
inc/Test/Base.pm
inc/Test/Base/Filter.pm
inc/Test/Builder.pm
inc/Test/Builder/Module.pm
inc/Test/More.pm
INLINE.h
lib/CGI/Cookie/XS.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
META.yml
README
t/TestCookie.pm
t/01-sanity.t
t/02-overflow.t
t/03-bug.t
t/99-pod-coverage.t
t/99-pod.t
util.c
XS.xs
---
abstract: 'HTTP Cookie parser in pure C'
author:
- 'Agent Zhang <agentzh@yahoo.cn>'
distribution_type: module
generated_by: 'Module::Install version 0.77'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: CGI-Cookie-XS
no_index:
directory:
- inc
- t
requires:
Filter::Util::Call: 0
perl: 5.6.1
resources:
license: http://dev.perl.org/licenses/
repository: http://github.com/agentzh/cookiexs/tree/master
Makefile.PL view on Meta::CPAN
use strict;
use lib '.';
use inc::Module::Install;
name ('CGI-Cookie-XS');
license ('perl');
author ('Agent Zhang <agentzh@yahoo.cn>');
perl_version ('5.006001');
all_from ('lib/CGI/Cookie/XS.pm');
repository ('http://github.com/agentzh/cookiexs/tree/master');
cc_inc_paths '.';
cc_files (glob("*.c"), (-e 'XS.c' ? () : 'XS.c'));
cc_optimize_flags '-g3';
can_cc or die "This module requires a C compiler";
#build_requires ('Test::More');
requires ('Filter::Util::Call');
use_test_base();
NAME
CGI::Cookie::XS - HTTP Cookie parser in pure C
VERSION
This document describes CGI::Cookie::XS 0.18 released on September 2,
2009.
SYNOPSIS
use CGI::Cookie::XS;
my $raw_cookie = 'foo=a%20phrase;weird; bar=yes%2C%20a%20phrase; baz=%5Ewibble&leiyh; qux=%27';
my $res = CGI::Cookie::XS->parse($raw_cookie);
# $res is something like:
# {
# 'bar' => [
# 'yes, a phrase'
# ],
# 'baz' => [
# '^wibble',
# 'leiyh'
# ],
# 'foo' => [
# 'a phrase'
# ],
# 'qux' => [
# '\''
# ]
# };
# or directly read raw cookies from the CGI environments:
$res = CGI::Cookie::XS->fetch;
DESCRIPTION
This module implements a very simple parser for cookies used in HTTP
applications. We've found CGI::Simple::Cookie and CGI::Cookie rather
slow according to the profiling results for our OpenResty project, hence
the rewrite in C.
This library is still in beta stage and the API is still in flux. We're
just following the "release early, releaes often" guideline. So please
check back often ;)
Special effort has been made to ensure this module works in the same way
as the latest CGI::Cookie (i.e., the pure Perl implementation). If you
find it doesn't, please let us know.
METHODS
We currently provide 2 static methods, "parse" and "fetch". They work
mostly the same way as those methods found in CGI::Cookie and
CGI::Simple::Cookie but with the exception that our version returns
plain Perl data structures rather than hashes of Perl objects (due to
performance considerations).
We'll implement some cookie dump methods in the near future.
"$ref = CGI::Cookie::XS->parse($raw_cookie)"
Parses $raw_cookie and returns the reference of a hash of arrays.
The keys of the hash are cookie variables' names while the values of
the hash are lists of cookie variable's values.
There is a length limit on the $raw_cookie. If $raw_cookie is longer
than 4 KB (i.e. 4 * 1024 bytes, excluding the trailing '\0'), the
overflowing part will be truncated.
Also note that, "fetch" does not assume any encoding on the cookie
values. It just decodes the encoded entries verbatim and treat them
as plain "binary" stuff.
"$ref = CGI::Cookie::XS->fetch()"
Reads the raw cookie from the "HTTP_COOKIE" and "COOKIE"
environments (which are usually set by HTTP servers like lighttd or
apache) and then parses the value using the "parse" method and
finally returns the results.
TODO
* Removing trailing spaces in cookie values.
SOURCE CONTROL
For the very latest version of this module, check out the source from
<http://github.com/agentzh/cookiexs/>
There is anonymous access to all. If you'd like a commit bit, please let
us know. :)
BUGS
There must be some serious bugs lurking somewhere. We haven't done
comprehensive testing for our code yet. It's a TODO.
Please report bugs or send wish-list to
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Cookie-XS>.
SEE ALSO
CGI::Cookie, CGI::Cookie::Simple.
AUTHOR
yuting "<yuting at alibaba-inc.com>"
agentzh "<agentzh at yahoo.cn>"
COPYRIGHT
Copyright (c) 2008 by Yahoo! China EEEE Works, Alibaba Inc.
Copyright (c) 2009 by Taobao Inc., Alibaba Group.
int i, value_flag;
char* p; /* moving first for look-ahead */
char* q; /* moving slower for tracking values */
char* decode;
AV *array = NULL;
HV *hash = NULL;
BOOL parsing_value = FALSE;
decode = (char *) malloc (COOKIE_LEN_LIMIT * sizeof(decode));
if (decode == NULL) {
croak("CGI::Cookie::XS::parse - Failed to malloc");
}
strncpy(Buffer, cs, COOKIE_LEN_LIMIT);
Buffer[COOKIE_LEN_LIMIT-1] = '\0';
hash = newHV();
p = Buffer;
DDD("before loop");
while (*p == ' ' || *p == '\t') p++; // remove leading spaces
q = p;
for (i = 0; str[i]; i++) {
*dest++ = (str[i] == '%' && (val = decode_hex_octet(str+i+1)) >= 0) ?
i+=2, val : str[i];
}
return 1;
}
MODULE = CGI::Cookie::XS PACKAGE = CGI::Cookie::XS
PROTOTYPES: DISABLE
SV *
_parse_cookie (cs)
char * cs
int
_decode_hex_str (str, out)
lib/CGI/Cookie/XS.pm view on Meta::CPAN
package CGI::Cookie::XS;
use strict;
use warnings;
our $VERSION;
use XSLoader;
BEGIN {
$VERSION = '0.18';
XSLoader::load(__PACKAGE__, $VERSION);
lib/CGI/Cookie/XS.pm view on Meta::CPAN
sub parse {
_parse_cookie($_[1]);
}
1;
__END__
=head1 NAME
CGI::Cookie::XS - HTTP Cookie parser in pure C
=head1 VERSION
This document describes CGI::Cookie::XS 0.18 released on September 2, 2009.
=head1 SYNOPSIS
use CGI::Cookie::XS;
my $raw_cookie = 'foo=a%20phrase;weird; bar=yes%2C%20a%20phrase; baz=%5Ewibble&leiyh; qux=%27';
my $res = CGI::Cookie::XS->parse($raw_cookie);
# $res is something like:
# {
# 'bar' => [
# 'yes, a phrase'
# ],
# 'baz' => [
# '^wibble',
# 'leiyh'
# ],
# 'foo' => [
# 'a phrase'
# ],
# 'qux' => [
# '\''
# ]
# };
# or directly read raw cookies from the CGI environments:
$res = CGI::Cookie::XS->fetch;
=head1 DESCRIPTION
This module implements a very simple parser for cookies used in HTTP applications. We've found L<CGI::Simple::Cookie> and L<CGI::Cookie> rather slow according to the profiling results for our L<OpenResty> project, hence the rewrite in C.
This library is still in B<beta> stage and the API is still in flux. We're just following the "release early, releaes often" guideline. So please check back often ;)
Special effort has been made to ensure this module works in the same way as the latest L<CGI::Cookie> (i.e., the pure Perl implementation). If you find it doesn't, please let us know.
=head1 METHODS
We currently provide 2 static methods, C<parse> and C<fetch>. They work mostly the same way as those methods found in L<CGI::Cookie> and L<CGI::Simple::Cookie> but with the exception that our version returns plain Perl data structures rather than has...
We'll implement some cookie dump methods in the near future.
=over
=item C<< $ref = CGI::Cookie::XS->parse($raw_cookie) >>
Parses C<$raw_cookie> and returns the reference of a hash of arrays. The keys
of the hash are cookie variables' names while the values of the hash are lists of cookie variable's values.
There is a length limit on the C<$raw_cookie>. If C<$raw_cookie> is longer than 4 KB (i.e. 4 * 1024 bytes, excluding the trailing '\0'), the overflowing part will be truncated.
Also note that, C<fetch> does not assume any encoding on the cookie values. It just decodes the encoded entries verbatim and treat them as plain "binary" stuff.
=item C<< $ref = CGI::Cookie::XS->fetch() >>
Reads the raw cookie from the C<HTTP_COOKIE> and C<COOKIE> environments
(which are usually set by HTTP servers like lighttd or apache) and then
parses the value using the C<parse> method and finally returns the
results.
=back
=head1 TODO
lib/CGI/Cookie/XS.pm view on Meta::CPAN
L<http://github.com/agentzh/cookiexs/>
There is anonymous access to all. If you'd like a commit bit, please let
us know. :)
=head1 BUGS
There must be some serious bugs lurking somewhere. We haven't done comprehensive testing for our code yet. It's a TODO.
Please report bugs or send wish-list to
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Cookie-XS>.
=head1 SEE ALSO
L<CGI::Cookie>, L<CGI::Cookie::Simple>.
=head1 AUTHOR
=over
=item yuting C<< <yuting at alibaba-inc.com> >>
=item agentzh C<< <agentzh at yahoo.cn> >>
=back
t/01-sanity.t view on Meta::CPAN
#use CGI::Cookie::XS;
use t::TestCookie;
plan tests => 1 * blocks();
#test 'CGI::Cookie';
no_diff;
run_tests;
__DATA__
=== TEST 1: complex cookie
--- cookie
foo=a%20phrase;haha; bar=yes%2C%20a%20phrase; baz=%5Ewibble&leiyh; qux=%27
--- out
t/02-overflow.t view on Meta::CPAN
use strict;
use warnings;
#use Smart::Comments;
use Test::More tests => 7;
BEGIN { use_ok('CGI::Cookie::XS'); }
my $COOKIE_LEN_LIMIT = 1024 * 4;
{
my $val_len = $COOKIE_LEN_LIMIT - 3;
my $cookie = 'a=' . ('a' x $val_len);
my $res = CGI::Cookie::XS->parse($cookie);
ok $res, 'res okay';
ok $res->{a}, 'var a parsed';
is $res->{a}->[0], 'a' x $val_len, "value okay for var a";
}
{
my $val_len = $COOKIE_LEN_LIMIT - 3;
my $cookie = 'a=' . ('a' x $COOKIE_LEN_LIMIT);
my $res = CGI::Cookie::XS->parse($cookie);
ok $res, 'res okay';
ok $res->{a}, 'var a parsed';
### Len: length($res->{a}->[0])
is $res->{a}->[0], 'a' x $val_len, "value okay for var a";
}
use t::TestCookie;
plan tests => 1 * blocks();
#test 'CGI::Cookie';
run_tests;
__DATA__
=== TEST 1: successive =
# http://rt.cpan.org/Public/Bug/Display.html?id=34238
--- cookie
foo=ba=r
--- out
$VAR1 = {
t/TestCookie.pm view on Meta::CPAN
use Test::Base -Base;
#use Smart::Comments;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
my $package = 'CGI::Cookie::XS';
sub test ($) {
$package = shift;
}
sub run_tests () {
eval "use $package;";
if ($@) { die $@ }
for my $block (blocks()) {
my $name = $block->name;
my $cookie = $block->cookie;
die "$name - No --- cookie specified" if !defined $cookie;
chomp $cookie;
### $cookie
my $res = $package->parse($cookie);
if ($package eq 'CGI::Cookie') {
for my $key (keys %$res) {
$res->{$key} = $res->{$key}->{value};
}
}
my $out = $block->out;
die "$name - No --- out specified" if !defined $out;
is Dumper($res), $out, "$name - out okay";
}
}
( run in 0.656 second using v1.01-cache-2.11-cpan-e9199f4ba4c )