You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2001/12/27 06:45:09 UTC
cvs commit: httpd-apreq/c Makefile.noperl apache_cookie.c
joes 01/12/26 21:45:09
Modified: . ToDo libapreq.pod
Cookie Cookie.pm
Request Request.pm
c Makefile.noperl apache_cookie.c
Log:
Includes Maurice Aubrey's apache_cookie.c patch to ignore empty cookie
attributes; also replaces ap_getword calls with ap_getword_nulls for parsing
"&" separator. Both patches bring the behavior of Apache::Cookie closer to
that of CGI::Cookie, and hopefully improve the functionality of the C
interface as well.
ToDo updated to reflect current state of package; copious documentation
patches to prepare for a new release version.
Revision Changes Path
1.5 +0 -14 httpd-apreq/ToDo
Index: ToDo
===================================================================
RCS file: /home/cvs/httpd-apreq/ToDo,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ToDo 2001/01/10 01:06:19 1.4
+++ ToDo 2001/12/27 05:45:09 1.5
@@ -10,20 +10,6 @@
o should probably handle Apache::Request->param http://blah.com/?foo
like CGI.pm does (turn it into a param named "keywords")
-o Perl's FILE* typemap leaks!
-
o libapreq.so
o mmap upload files
-
-o investigate USE_MY_TMPNAME more
-
-o ApacheHTML?
-
-o for mod_dtcl, it may be good to allow a callback function for
- storing file uploads (since it is configurable to store the
- uploads in memory instead of to disk)
-
-o allow the directory for temporary files to be specified? we
- currently use tmpfile(), though, and we'd have to do a secure
- temp-file-creating function to do this.
1.5 +4 -4 httpd-apreq/libapreq.pod
Index: libapreq.pod
===================================================================
RCS file: /home/cvs/httpd-apreq/libapreq.pod,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- libapreq.pod 2001/03/15 03:04:11 1.4
+++ libapreq.pod 2001/12/27 05:45:09 1.5
@@ -63,12 +63,12 @@
Redirects upload data to be processed by the hook.
- req->hook_data = (void *) some_struct_pointer;
- req->upload_hook = (int(*)(void*,char*,int,const ApacheUpload*)) some_function;
+ req->hook_data = (void *) data;
+ req->upload_hook = (int(*)(void*,char*,int,ApacheUpload*)) func;
In this case
- some_function(req->hookdata,buffer,bufsize,upload);
+ func(req->hook_data,buffer,bufsize,upload);
will be called repeatedly during the file upload instead of writing the
data to a temp file.
@@ -339,5 +339,5 @@
=head1 AUTHOR
-Doug MacEachern
+Doug MacEachern, updated for v1.0 by Joe Schaefer
1.4 +18 -6 httpd-apreq/Cookie/Cookie.pm
Index: Cookie.pm
===================================================================
RCS file: /home/cvs/httpd-apreq/Cookie/Cookie.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Cookie.pm 2000/12/23 02:56:53 1.3
+++ Cookie.pm 2001/12/27 05:45:09 1.4
@@ -20,6 +20,7 @@
=head1 SYNOPSIS
use Apache::Cookie ();
+ my $r = Apache->request;
my $cookie = Apache::Cookie->new($r, ...);
=head1 DESCRIPTION
@@ -30,9 +31,10 @@
=head1 METHODS
-This interface is identical the to I<CGI::Cookie> interface with one
-exception noted below. Refer the to I<CGI::Cookie> documentation while
-these docs are "under construction."
+I<Apache::Cookie> does not export any symbols to the caller's namespace.
+Except for the request object passed to C<Apache::Cookie::new>, the OO
+interface is identical to I<CGI::Cookie>. Please consult the L<CGI::Cookie>
+documentation for more details.
=over 4
@@ -94,7 +96,7 @@
Get or set the values of the cookie:
- my $value = $cookie->value;
+ my $value = $cookie->value;
my @values = $cookie->value;
$cookie->value("string");
@@ -130,10 +132,20 @@
=back
+=head1 BUGS
+
+=over 4
+
+=item RFC 2964-5 are not fully implemented.
+
+=item C<value> should also accept a hash ref as argument.
+
+=back
+
=head1 SEE ALSO
-Apache(3), Apache::Request(3)
+Apache(3), Apache::Request(3), CGI::Cookie(3)
=head1 AUTHOR
-Doug MacEachern
+Doug MacEachern, updated for v1.0 by Joe Schaefer
1.19 +63 -13 httpd-apreq/Request/Request.pm
Index: Request.pm
===================================================================
RCS file: /home/cvs/httpd-apreq/Request/Request.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Request.pm 2001/06/15 16:40:33 1.18
+++ Request.pm 2001/12/27 05:45:09 1.19
@@ -45,6 +45,25 @@
=head1 Apache::Request METHODS
+The interface is designed to mimic CGI.pm 's routines for parsing
+query parameters. The main differences are
+
+=over 4
+
+=item * C<Apache::Request::new> takes an Apache object as (second) argument.
+
+
+=item * The query parameters are stored as Apache::Table objects,
+and are therefore parsed using case-insensitive keys.
+
+
+=item * C<-attr =E<gt> $val> -type arguments are not supported.
+
+
+=item * The query string is always parsed, even for POST requests.
+
+=back
+
=over 4
=head2 new
@@ -61,8 +80,8 @@
=item POST_MAX
-Limit the size of POST data. I<Apache::Request::parse> will return an
-error code if the size is exceeded:
+Limit the size of POST data (in bytes). I<Apache::Request::parse> will
+return an error code if the size is exceeded:
my $apr = Apache::Request->new($r, POST_MAX => 1024);
my $status = $apr->parse;
@@ -90,7 +109,7 @@
=item TEMP_DIR
Sets the directory where upload files are spooled. On a *nix-like
-that supports link(2), the TEMP_DIR should be placed on the same
+that supports link(2), the TEMP_DIR should be located on the same
file system as the final destination file:
my $apr = Apache::Request->new($r, TEMP_DIR => "/home/httpd/tmp");
@@ -99,8 +118,8 @@
=item HOOK_DATA
-Extra configuration info to be passed to and upload hook.
-See next item for details.
+Extra configuration info passed to an upload hook.
+See the description for the next item, I<UPLOAD_HOOK>.
=item UPLOAD_HOOK
@@ -165,18 +184,46 @@
}
=head2 param
+
+Get or set request parameters (using case-insensitive keys) by
+mimicing the OO interface of C<CGI::param>. Unlike the CGI.pm version,
+Apache::Request's param method is I<very> fast- it's now quicker than even
+mod_perl's native Apache->args method. However, CGI.pm's
+C<-attr =E<gt> $val> type arguments are not supported.
-Get or set request parameters:
+ # similar to CGI.pm
my $value = $apr->param('foo');
my @values = $apr->param('foo');
my @params = $apr->param;
+
+ # the following differ slightly from CGI.pm
+
+ # assigns multiple values to 'foo'
$apr->param('foo' => [qw(one two three)]);
+ # returns ref to underlying apache table object
+ my $table = $apr->param; # identical to $apr->parms - see below
+
+=head2 parms
+
+Get or set the underlying apache parameter table of the I<Apache::Request>
+object. When invoked without arguments, C<parms> returns a reference
+to an I<Apache::Table> object that is tied to the Apache::Request
+object's parameter table. If called with an Apache::Table reference
+as as argument, the Apache::Request object's parameter table is
+replaced by the argument's table.
+
+ # $apache_table references an Apache::Table object
+ $apr->parms($apache_table); # sets $apr's parameter table
+
+ # returns ref to Apache::Table object provided by $apache_table
+ my $table = $apr->parms;
+
=head2 upload
Returns a single I<Apache::Upload> object in a scalar context or
-all I<Apache::Upload> objects in an array context:
+all I<Apache::Upload> objects in a list context:
my $upload = $apr->upload;
my $fh = $upload->fh;
@@ -248,8 +295,9 @@
=head2 next
-As an alternative to using the I<Apache::Request> I<upload> method in
-an array context:
+Upload objects are implemented as a linked list by libapreq; the
+I<next> method provides an alternative to using the I<Apache::Request>
+I<upload> method in a list context:
for (my $upload = $apr->upload; $upload; $upload = $upload->next) {
...
@@ -263,11 +311,13 @@
=head2 tempname
-Provides the name of the spool file.
+Provides the name of the spool file. This method is reserved for
+debugging purposes, and is possibly subject to change in a future
+version of Apache::Request.
=head2 link
-To avoid recopying the spool file on a Unix-like system,
+To avoid recopying the spool file on a *nix-like system,
I<link> will create a hard link to it:
my $upload = $apr->upload('file');
@@ -281,7 +331,7 @@
=head1 SEE ALSO
-libapreq(3)
+libapreq(3), Apache::Table(3)
=head1 CREDITS
@@ -289,4 +339,4 @@
=head1 AUTHOR
-Doug MacEachern
+Doug MacEachern, updated for v1.0 by Joe Schaefer
1.2 +1 -1 httpd-apreq/c/Makefile.noperl
Index: Makefile.noperl
===================================================================
RCS file: /home/cvs/httpd-apreq/c/Makefile.noperl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Makefile.noperl 1999/01/27 01:33:20 1.1
+++ Makefile.noperl 2001/12/27 05:45:09 1.2
@@ -22,7 +22,7 @@
.c$(OBJ_EXT):
$(CCCMD) -c $(CFLAGS) -I$(INCDIR) $(DEFINE) $*.c
-OBJECT = apache_request$(OBJ_EXT) apache_cookie$(OBJ_EXT) multipart_buffer$(OBJ_EXT)
+OBJECT = apache_request$(OBJ_EXT) apache_cookie$(OBJ_EXT) apache_multipart_buffer$(OBJ_EXT)
LDFROM = $(OBJECT)
INST_STATIC = $(BASEEXT)$(LIB_EXT)
1.11 +25 -27 httpd-apreq/c/apache_cookie.c
Index: apache_cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq/c/apache_cookie.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- apache_cookie.c 2001/06/26 10:58:20 1.10
+++ apache_cookie.c 2001/12/27 05:45:09 1.11
@@ -62,16 +62,15 @@
char *expires;
expires = ApacheUtil_expires(c->r->pool, time_str, EXPIRES_COOKIE);
- if (expires) {
+ if (expires)
c->expires = expires;
- }
return c->expires;
}
#define cookie_get_set(thing,val) \
-retval = thing; \
-if(val) thing = ap_pstrdup(c->r->pool, val)
+ retval = thing; \
+ if(val) thing = ap_pstrdup(c->r->pool, val)
char *ApacheCookie_attr(ApacheCookie *c, char *key, char *val)
{
@@ -130,9 +129,9 @@
for(;;) {
char *key, *val;
key = va_arg(args, char *);
- if (key == NULL) {
+ if (key == NULL)
break;
- }
+
val = va_arg(args, char *);
(void)ApacheCookie_attr(c, key, val);
}
@@ -147,35 +146,36 @@
ApacheCookieJar *retval =
ap_make_array(r->pool, 1, sizeof(ApacheCookie *));
- if (!data) {
- if (!(data = ap_table_get(r->headers_in, "Cookie"))) {
+ if (!data)
+ if (!(data = ap_table_get(r->headers_in, "Cookie")))
return retval;
- }
- }
while (*data && (pair = ap_getword(r->pool, &data, ';'))) {
const char *key, *val;
ApacheCookie *c;
- while (ap_isspace(*data)) {
+ while (ap_isspace(*data))
++data;
- }
+
key = ap_getword(r->pool, &pair, '=');
ap_unescape_url((char *)key);
c = ApacheCookie_new(r, "-name", key, NULL);
- if (c->values) {
+
+ if (c->values)
c->values->nelts = 0;
- }
- else {
+ else
c->values = ap_make_array(r->pool, 4, sizeof(char *));
- }
- if (!*pair) {
+ if (!*pair)
ApacheCookieAdd(c, "");
- }
+
- while (*pair && (val = ap_getword(r->pool, &pair, '&'))) {
+ while (*pair && (val = ap_getword_nulls(r->pool, &pair, '&'))) {
ap_unescape_url((char *)val);
+#ifdef DEBUG
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
+ "[apache_cookie] added (%s)", val);
+#endif
ApacheCookieAdd(c, val);
}
ApacheCookieJarAdd(retval, c);
@@ -188,7 +188,7 @@
*(char **)ap_push_array(arr) = (char *)val
#define cookie_push_named(arr, name, val) \
- if(val) { \
+ if(val && strlen(val) > 0) { \
cookie_push_arr(arr, ap_pstrcat(p, name, "=", val, NULL)); \
}
@@ -198,6 +198,7 @@
char *end = result + strlen(result);
char *seek;
+ /* touchup result to ensure that special chars are escaped */
for ( seek = end-1; seek >= result; --seek) {
char *ptr, *replacement;
@@ -215,11 +216,9 @@
continue; /* next for() */
}
+ for (ptr = end; ptr > seek; --ptr)
+ ptr[2] = ptr[0];
- for (ptr = end; ptr > seek; --ptr) {
- ptr[2] = ptr[0];
- }
-
strncpy(seek, replacement, 3);
end += 2;
}
@@ -234,9 +233,8 @@
char *cookie, *retval;
int i;
- if (!c->name) {
+ if (!c->name)
return "";
- }
values = ap_make_array(p, 6, sizeof(char *));
cookie_push_named(values, "domain", c->domain);
@@ -250,7 +248,7 @@
for (i=0; i<c->values->nelts; i++) {
cookie = ap_pstrcat(p, cookie,
escape_url(p, ((char**)c->values->elts)[i]),
- (i < (c->values->nelts-1) ? "&" : NULL),
+ (i < (c->values->nelts -1) ? "&" : NULL),
NULL);
}