joes 2004/07/29 09:22:32
Modified: build version_check.pl
glue/perl/docs Cookie.pod Request.pod
glue/perl/xsbuilder apreq_xs_tables.h
glue/perl/xsbuilder/Apache/Request Apache__Request.h
glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
Log:
Uniquify @keys = $req->param et al.
Revision Changes Path
1.18 +6 -0 httpd-apreq-2/build/version_check.pl
Index: version_check.pl
===================================================================
RCS file: /home/cvs/httpd-apreq-2/build/version_check.pl,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- version_check.pl 15 Jul 2004 16:00:52 -0000 1.17
+++ version_check.pl 29 Jul 2004 16:22:31 -0000 1.18
@@ -20,6 +20,11 @@
$Apache::Test::VERSION;
}
+sub tm_version {
+ require Test::More;
+ $Test::More::VERSION;
+}
+
sub mm_version {
require ExtUtils::MakeMaker;
$ExtUtils::MakeMaker::VERSION;
@@ -60,6 +65,7 @@
# mp2 does not contain "_" in its reported version number
mod_perl => { version => "1.9915", test => \&mp2_version },
"ExtUtils::MakeMaker" => { version => "6.15", test => \&mm_version },
+ "Test::More" => { version => "0.47", test => \&tm_version },
);
sub print_prereqs ($$) {
1.13 +2 -2 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Cookie.pod 25 Jul 2004 21:06:54 -0000 1.12
+++ Cookie.pod 29 Jul 2004 16:22:31 -0000 1.13
@@ -145,11 +145,11 @@
=for example_testing
ok @cookies == 2;
- ok $_ -> name eq "foo" for $cookie, @cookies;
+ is $_ -> name, "foo" for $cookie, @cookies;
ok $cookies[0]->value eq $cookie->value;
ok $cookies[0]->value == 1;
ok $cookies[1]->value == 3;
- ok "foo bar foo" eq "@names";
+ is "@names", "foo bar";
1.3 +84 -17 httpd-apreq-2/glue/perl/docs/Request.pod
Index: Request.pod
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/docs/Request.pod,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Request.pod 27 Jul 2004 16:10:21 -0000 1.2
+++ Request.pod 29 Jul 2004 16:22:31 -0000 1.3
@@ -2,39 +2,70 @@
Apache::Request - Methods for dealing with client request data
+
=for testing
+ use POSIX;
use Apache2;
use Apache::Request;
use Apache::Upload;
use APR::Pool;
- ok 1;
+ $r = APR::Pool->new;
+ $req = Apache::Request->new($r);
+ $u = Apache::Upload->new($r, name => "foo", file => __FILE__);
+ eval { POSIX::close(0); $req->parse };
+ $req->body->add($u);
+ $req->args->add(foo => 1);
+ $req->args->add(bar => 2);
+ $req->args->add(foo => 3);
+
+
+
=head1 SYNOPSIS
+
+=for example begin
+
use Apache::Request;
- my $req = Apache::Request->new($r);
+ $req = Apache::Request->new($r);
+ @foo = $req->param("foo");
+ $bar = $req->args("bar");
+
+=for example end
+
+=for example_testing
+ ok $req->isa("Apache::Request");
+ is "@foo", join " ", 1, 3, __FILE__;
+ is $bar, 2;
=head1 DESCRIPTION
-C<Apache::Request> adds methods for parsing B<GET> requests and B<POST>
-requests where I<Content-type> is one of I<application/x-www-form-urlencoded>
-or I<multipart/form-data>.
+The Apache::Request module provides methods for parsing GET and POST
parameters
+encoded with either I<application/x-www-form-urlencoded> or
I<multipart/form-data>.
+Although Apache::Request provides a few new APIs for accessing the parsed
data,
+it remains largely backwards-compatible with the original 1.X API. See the
+L<PORTING from 1.X> section below for a list of known issues.
+
+This manpage documents the Apache::Request package. Apache::Request::Table
+and Apache::Request::Error are also provided by this module, but are
+documented elsewhere. Please read the L<SEE ALSO> section below for a list
+of related manpages.
-=head1 Apache::Request METHODS
+=head1 Apache::Request
-The interface is designed to mimic CGI.pm 's routines for parsing
+The interface is designed to mimic the CGI.pm routines for parsing
query parameters. The main differences are
=over 4
=item * C<Apache::Request::new> takes an environment-specific
- object as (second) argument. Newer versions of CGI.pm also accept
+ object C<$r> as (second) argument. Newer versions of CGI.pm also
accept
this syntax within modperl.
=item * The query parameters are stored in APR::Table derived objects, and
@@ -53,19 +84,33 @@
Creates a new Apache::Request object.
- my $req = Apache::Request->new($r);
-With mod_perl2, the environment object $r must be an C<Apache::RequestRec>
+=for example begin
+
+ my $req = Apache::Request->new($r, POST_MAX => "1M");
+
+
+=for example end
+
+=for example_testing
+ ok ref $req;
+ ok $req->isa("Apache::Request");
+
+
+With mod_perl2, the environment object $r must be an Apache::RequestRec
object. In that case, all methods from Apache::RequestRec are inherited.
+In the (default) CGI environment, $r must be an APR::Pool object.
The following args are optional:
=over 4
+
=item * C<POST_MAX>, C<MAX_BODY>
Limit the size of POST data (in bytes).
+
=item * C<DISABLE_UPLOADS>
Disable file uploads.
@@ -77,19 +122,25 @@
that supports I<link(2)>, the TEMP_DIR should be located on the same
file system as the final destination file:
+=for example begin
+
use Apache::Upload;
my $req = Apache::Request->new($r, TEMP_DIR => "/home/httpd/tmp");
my $upload = $req->upload('file');
- $upload->link("/home/user/myfile") || warn "link failed: $!";
+ $upload->link("/home/user/myfile");
+
+=for example end
For more details on C<link>, see the L<Apache::Upload> manpage.
+
=item * C<HOOK_DATA>
Extra configuration info passed as the fourth argument
to an upload hook. See the description for the next item,
C<UPLOAD_HOOK>.
+
=item * C<UPLOAD_HOOK>
Sets up a callback to run whenever file upload data is read. This
@@ -97,6 +148,8 @@
Apache will automatically continue writing the original data to
$upload->fh after the hook exits.
+=for example begin
+
my $transparent_hook = sub {
my ($upload, $data, $data_len, $hook_data) = @_;
warn "$hook_data: got $data_len bytes for " . $upload->name;
@@ -107,6 +160,9 @@
UPLOAD_HOOK => $transparent_hook,
);
+=for example end
+
+
=back
@@ -136,6 +192,8 @@
Get the request parameters (using case-insensitive keys) by
mimicing the OO interface of C<CGI::param>.
+=for example begin
+
# similar to CGI.pm
my $foo_value = $req->param('foo');
@@ -148,9 +206,16 @@
# all (args + body) params
my $table = $req->param;
+=for example end
+
+=for example_testing
+ is $foo_value, 1;
+ is "@foo_values", join " ", 1, 3, __FILE__;
+ is "@param_names", "foo bar";
+
In list context, or when invoked with no arguments as
-C<< $req->param() >>, C<param> always induces libapreq2
-to read and parse all remaining data in the request body.
+C<< $req->param() >>, C<param> induces libapreq2 to read
+and parse all remaining data in the request body.
However, C<< scalar $req->param("foo") >> is lazy: libapreq2
will only read and parse more data if
@@ -158,8 +223,10 @@
2) no "foo" param appears in the previously parsed POST data.
In this circumstance libapreq2 will read and parse additional
-blocks of the incoming request body until it has found the
-the "foo" param or parsing is completed.
+blocks of the incoming request body until either
+
+ 1) it has found the the "foo" param, or
+ 2) parsing is completed.
Observe that C<< scalar $req->param("foo") >> will not raise
an exception if it can locate "foo" in the existing body or
@@ -355,8 +422,8 @@
=head1 SEE ALSO
-L<Apache::Cookie>, L<Apache::Upload>,
-L<Apache::Request::Table>, L<Apache::Request::Error>
+L<Apache::Request::Table>, L<Apache::Request::Error>, L<Apache::Upload>,
+L<Apache::Cookie>, L<APR::Table>.
1.30 +12 -4 httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_tables.h
Index: apreq_xs_tables.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_tables.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- apreq_xs_tables.h 24 Jul 2004 21:09:18 -0000 1.29
+++ apreq_xs_tables.h 29 Jul 2004 16:22:31 -0000 1.30
@@ -191,10 +191,18 @@
#define apreq_xs_do(attr) (items == 1 ? apreq_xs_table_keys \
: apreq_xs_##attr##_table_values)
-#define apreq_xs_push(attr,sv,d,key) do { \
- apr_table_t *t = apreq_xs_##attr##_sv2table(sv); \
- if (t) \
- apr_table_do(apreq_xs_do(attr), d, t, key, NULL); \
+#define apreq_xs_push(attr,sv,d,key) do { \
+ apr_table_t *t = apreq_xs_##attr##_sv2table(sv); \
+ if (t != NULL) { \
+ if (items == 1) { \
+ t = apr_table_copy(apreq_env_pool(env), t); \
+ apr_table_compress(t, APR_OVERLAP_TABLES_SET); \
+ apr_table_do(apreq_xs_table_keys, d, t, NULL); \
+ } \
+ else \
+ apr_table_do(apreq_xs_##attr##_table_values, d, \
+ t, key, NULL); \
+ } \
} while (0)
/**
1.50 +18 -8
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
Index: Apache__Request.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- Apache__Request.h 26 Jul 2004 21:08:04 -0000 1.49
+++ Apache__Request.h 29 Jul 2004 16:22:32 -0000 1.50
@@ -122,15 +122,25 @@
/* Too many GET macros :-( */
#define S2P(s) (s ? apreq_value_to_param(apreq_strtoval(s)) : NULL)
-#define apreq_xs_request_push(sv,d,key) do { \
- apreq_request_t *req = (apreq_request_t *)SvIVX(sv); \
- apr_status_t s; \
- apr_table_do(apreq_xs_do(request), d, req->args, key, NULL); \
- do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE); \
- while (s == APR_INCOMPLETE); \
- if (req->body) \
- apr_table_do(apreq_xs_do(request), d, req->body, key, NULL); \
+
+#define apreq_xs_request_push(sv,d,key) do { \
+ apreq_request_t *req = (apreq_request_t *)SvIVX(sv); \
+ if (items == 1) { \
+ apr_table_t *t = apreq_params(apreq_env_pool(req->env), req); \
+ apr_table_compress(t, APR_OVERLAP_TABLES_SET); \
+ apr_table_do(apreq_xs_table_keys, d, t, NULL); \
+ } \
+ else { \
+ apr_status_t s; \
+ apr_table_do(apreq_xs_do(request), d, req->args, key, NULL); \
+ do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE); \
+ while (s == APR_INCOMPLETE); \
+ if (req->body) \
+ apr_table_do(apreq_xs_request_table_values, d, \
+ req->body, key, NULL); \
+ } \
} while (0)
+
#define apreq_xs_request_args_push(sv,d,k) apreq_xs_push(request_args,sv,d,k)
#define apreq_xs_request_body_push(sv,d,k) apreq_xs_push(request_body,sv,d,k)
#define apreq_xs_table_push(sv,d,k) apreq_xs_push(table,sv,d,k)
1.32 +16 -28
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
Index: Apache__Upload.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Apache__Upload.h 26 Jul 2004 21:08:04 -0000 1.31
+++ Apache__Upload.h 29 Jul 2004 16:22:32 -0000 1.32
@@ -50,16 +50,24 @@
#define READ_BLOCK_SIZE (1024 * 256)
#define S2P(s) (s ? apreq_value_to_param(apreq_strtoval(s)) : NULL)
-#define apreq_xs_upload_do (items==1 ?
apreq_xs_request_upload_table_keys \
- : apreq_xs_request_upload_table_values)
#define apreq_xs_request_upload_push(sv,d,key) do {
\
- apreq_request_t *req = (apreq_request_t *)SvIVX(sv); \
- apr_status_t s; \
- do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE); \
- while (s == APR_INCOMPLETE); \
- if (req->body) \
- apr_table_do(apreq_xs_upload_do, d, req->body, key, NULL); \
+ apreq_request_t *req = (apreq_request_t *)SvIVX(sv);
\
+ if (items == 1) {
\
+ apr_table_t *t = apreq_uploads(apreq_env_pool(req->env), req);
\
+ if (t != NULL) {
\
+ apr_table_compress(t, APR_OVERLAP_TABLES_MERGE);
\
+ apr_table_do(apreq_xs_table_keys, d, t, key, NULL);
\
+ }
\
+ }
\
+ else {
\
+ apr_status_t s;
\
+ do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE);
\
+ while (s == APR_INCOMPLETE);
\
+ if (req->body)
\
+ apr_table_do(apreq_xs_request_upload_table_values, d,
\
+ req->body, key, NULL);
\
+ }
\
} while (0)
#define apreq_xs_upload_table_push(sv,d,k) apreq_xs_push(upload_table,sv,d,k)
@@ -77,26 +85,6 @@
#define apreq_upload_t apreq_param_t
#define apreq_xs_param2sv(ptr,class,parent) apreq_xs_2sv(ptr,class,parent)
#define apreq_xs_sv2param(sv) ((apreq_param_t *)SvIVX(SvRV(sv)))
-
-static int apreq_xs_request_upload_table_keys(void *data, const char *key,
- const char *val)
-{
-#ifdef USE_ITHREADS
- struct apreq_xs_do_arg *d = (struct apreq_xs_do_arg *)data;
- dTHXa(d->perl);
-#endif
-
- dSP;
- SV *sv;
-
- if (apreq_value_to_param(apreq_strtoval(val))->bb == NULL)
- return 1;
-
- sv = newSVpv(key,0);
- XPUSHs(sv_2mortal(sv));
- PUTBACK;
- return 1;
-}
#define UPLOAD_TABLE "Apache::Upload::Table"