joes 2004/07/05 13:59:00
Modified: . CHANGES
glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
glue/perl/xsbuilder/Apache/Request Apache__Request.h
glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
Upload_pod
Log:
Add exceptions to $upload->link, $upload->tempname, $upload->slurp,
and $cookie->set_attr. Return value of $upload->slurp is now the
upload length. Also document new $upload->io.
Revision Changes Path
1.52 +5 -0 httpd-apreq-2/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- CHANGES 5 Jul 2004 17:39:50 -0000 1.51
+++ CHANGES 5 Jul 2004 20:59:00 -0000 1.52
@@ -3,6 +3,11 @@
@section v2_04_dev Changes with libapreq2-2.04-dev
+- Perl API [joes]
+ Add exceptions to $upload->link, $upload->tempname, $upload->slurp,
+ and $cookie->set_attr. Return value of $upload->slurp is now the
+ upload length. Also document new $upload->io.
+
- C API [joes]
Restrict all apr_status_t codes to APR_SUCCESS, APR_INCOMPLETE,
APR_EGENERAL, APR_EINIT, APR_ENOTIMPL, since any others will
1.23 +14 -4
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Apache__Cookie.h 4 Jul 2004 17:44:34 -0000 1.22
+++ Apache__Cookie.h 5 Jul 2004 20:59:00 -0000 1.23
@@ -137,8 +137,9 @@
apr_pool_t *p;
apr_status_t status = APR_SUCCESS;
int j = 1;
- if (items == 0)
- XSRETURN_UNDEF;
+
+ if (items % 2 != 1 || ! SvROK(ST(0)))
+ Perl_croak(aTHX_ "usage: $cookie->set_attr(%attrs)");
c = apreq_xs_sv2(cookie,ST(0));
p = apreq_env_pool(apreq_xs_sv2env(SvRV(ST(0))));
@@ -147,9 +148,18 @@
STRLEN alen, vlen;
const char *attr = SvPVbyte(ST(j),alen),
*val = SvPVbyte(ST(j+1),vlen);
- status = apreq_cookie_attr(p, c, attr, alen, val, vlen);
- if (status != APR_SUCCESS)
+
+ switch (status = apreq_cookie_attr(p, c, attr, alen, val, vlen)) {
+ case APR_ENOTIMPL:
+ Perl_warn(aTHX_ "Skipping unrecognized cookie attribute %s",
attr);
+ case APR_SUCCESS:
break;
+ default:
+ if (GIMME_V == G_VOID)
+ apreq_xs_croak(aTHX_ newHV(), status,
"Apache::Cookie::set_attr",
+ "Apache::Cookie::Error");
+ XSRETURN_IV(status);
+ }
}
XSRETURN_IV(status);
}
1.38 +5 -2
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.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Apache__Request.h 5 Jul 2004 17:32:02 -0000 1.37
+++ Apache__Request.h 5 Jul 2004 20:59:00 -0000 1.38
@@ -181,7 +181,7 @@
}
else {
Perl_warn(aTHX_ "Apache::Request::config: "
- "Unrecognized attribute %s", attr);
+ "Unrecognized attribute %s, skipped", attr);
}
}
XSRETURN(0);
@@ -199,9 +199,12 @@
do s = apreq_env_read(req->env, APR_BLOCK_READ, READ_BLOCK_SIZE);
while (s == APR_INCOMPLETE);
- if (GIMME_V != G_VOID)
+
+ if (GIMME_V != GVOID)
XSRETURN_IV(s);
+
if (s != APR_SUCCESS)
apreq_xs_croak(aTHX_ newHV(), s, "Apache::Request::parse",
"Apache::Request::Error");
+
}
1.15 +55 -41
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Apache__Upload.h 4 Jul 2004 17:44:34 -0000 1.14
+++ Apache__Upload.h 5 Jul 2004 20:59:00 -0000 1.15
@@ -120,6 +120,7 @@
const char *name, *fname;
apr_bucket_brigade *bb;
apr_file_t *f;
+ apr_status_t s = APR_SUCCESS;
if (items != 2 || !SvROK(ST(0)))
Perl_croak(aTHX_ "Usage: $upload->link($name)");
@@ -134,32 +135,45 @@
f = apreq_brigade_spoolfile(bb);
if (f == NULL) {
apr_off_t len;
- apr_status_t s;
s = apr_file_open(&f, name, APR_CREATE | APR_EXCL | APR_WRITE |
APR_READ | APR_BINARY | APR_BUFFERED,
APR_OS_DEFAULT,
apreq_env_pool(env));
- if (s != APR_SUCCESS ||
- apreq_brigade_fwrite(f, &len, bb) != APR_SUCCESS)
- XSRETURN_UNDEF;
-
- XSRETURN_YES;
+ if (s == APR_SUCCESS) {
+ s = apreq_brigade_fwrite(f, &len, bb);
+ if (s != APR_SUCCESS) {
+ if (GIMME_V != G_VOID)
+ XSRETURN_UNDEF;
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::link",
+ "Apache::Upload::Error");
+ }
+ XSRETURN_YES;
+ }
+ else
+ goto link_error;
}
- if (apr_file_name_get(&fname, f) != APR_SUCCESS)
- XSRETURN_UNDEF;
+ s = apr_file_name_get(&fname, f);
+ if (s != APR_SUCCESS)
+ goto link_error;
if (PerlLIO_link(fname, name) >= 0)
XSRETURN_YES;
else {
- apr_status_t s = apr_file_copy(fname, name,
- APR_OS_DEFAULT,
- apreq_env_pool(env));
+ s = apr_file_copy(fname, name,
+ APR_OS_DEFAULT,
+ apreq_env_pool(env));
if (s == APR_SUCCESS)
XSRETURN_YES;
}
- XSRETURN_UNDEF;
+ link_error:
+ if (GIMME_V != G_VOID)
+ XSRETURN_UNDEF;
+
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::link",
+ "APR::Error");
+
}
@@ -185,7 +199,9 @@
s = apr_brigade_length(bb, 0, &len_off);
if (s != APR_SUCCESS)
- XSRETURN_IV(s);
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::slurp",
+ "Apache::Upload::Error");
+
len_size = len_off; /* max_body setting will be low enough to prevent
* overflow, but even if it wasn't the code below
will
@@ -198,7 +214,11 @@
SvCUR_set(ST(1), len_size);
SvPOK_only(ST(1));
s = apr_brigade_flatten(bb, data, &len_size);
- XSRETURN_IV(s);
+ if (s != APR_SUCCESS)
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::slurp",
+ "APR::Error");
+
+ XSRETURN_IV(len_size);
}
static XS(apreq_xs_upload_size)
@@ -221,11 +241,10 @@
s = apr_brigade_length(bb, 1, &len);
- if (s != APR_SUCCESS) {
- apreq_log(APREQ_ERROR s, env, "apreq_xs_upload_size:"
- "apr_brigade_length failed");
- Perl_croak(aTHX_ "$upload->size: can't get brigade length");
- }
+ if (s != APR_SUCCESS)
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::size",
+ "APR::Error");
+
XSRETURN_IV((IV)len);
}
@@ -308,8 +327,8 @@
s = apr_bucket_read(e, &data, &dlen, APR_BLOCK_READ);
if (s != APR_SUCCESS)
apreq_xs_croak(aTHX_ newHV(), s,
- "Apache::Request::Upload::Brigade::READ "
- "apr_bucket_read failed", "APR::Error");
+ "Apache::Request::Upload::Brigade::READ",
+ "APR::Error");
want = dlen;
end = APR_BUCKET_NEXT(e);
}
@@ -321,8 +340,8 @@
s = apr_brigade_length(bb, 1, &len);
if (s != APR_SUCCESS)
apreq_xs_croak(aTHX_ newHV(), s,
- "Apache::Request::Upload::Brigade::READ "
- "apr_brigade_length failed", "APR::Error");
+ "Apache::Request::Upload::Brigade::READ",
+ "APR::Error");
want = len;
case APR_SUCCESS:
@@ -330,8 +349,8 @@
default:
apreq_xs_croak(aTHX_ newHV(), s,
- "Apache::Request::Upload::Brigade::READ "
- "apr_brigade_partition failed", "APR::Error");
+ "Apache::Request::Upload::Brigade::READ",
+ "APR::Error");
}
}
@@ -346,8 +365,7 @@
s = apr_bucket_read(e, &data, &dlen, APR_BLOCK_READ);
if (s != APR_SUCCESS)
apreq_xs_croak(aTHX_ newHV(), s,
- "Apache::Request::Upload::Brigade::READ "
- "apr_bucket_read failed", "APR::Error");
+ "Apache::Request::Upload::Brigade::READ",
"APR::Error");
memcpy(buf, data, dlen);
buf += dlen;
apr_bucket_delete(e);
@@ -388,8 +406,8 @@
s = apr_bucket_read(e, &data, &dlen, APR_BLOCK_READ);
if (s != APR_SUCCESS)
apreq_xs_croak(aTHX_ newHV(), s,
- "Apache::Request::Upload::Brigade::READLINE "
- "apr_bucket_read failed", "APR::Error");
+ "Apache::Request::Upload::Brigade::READLINE",
+ "APR::Error");
eol = memchr(data, '\012', dlen); /* look for LF (linefeed) */
@@ -445,20 +463,15 @@
s = apreq_file_mktemp(&file, apreq_env_pool(env), tmpdir);
- if (s != APR_SUCCESS) {
- apreq_log(APREQ_ERROR s, env, "apreq_xs_upload_tempname: "
- "apreq_file_mktemp failed");
- Perl_croak(aTHX_ "$upload->tempname: can't make tempfile");
- }
+ if (s != APR_SUCCESS)
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::tempname",
+ "Apache::Upload::Error");
s = apreq_brigade_fwrite(file, &len, bb);
- if (s != APR_SUCCESS) {
- apreq_log(APREQ_ERROR s, env, "apreq_xs_upload_tempname: "
- "apreq_brigade_fwrite failed");
- Perl_croak(aTHX_ "$upload->tempname: "
- "can't write brigade to tempfile");
- }
+ if (s != APR_SUCCESS)
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::tempname",
+ "Apache::Upload::Error");
last = apr_bucket_file_create(file, len, 0, bb->p, bb->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, last);
@@ -466,7 +479,8 @@
s = apr_file_name_get(&path, file);
if (s != APR_SUCCESS)
- XSRETURN_UNDEF;
+ apreq_xs_croak(aTHX_ newHV(), s, "Apache::Upload::tempname",
+ "APR::Error");
ST(0) = sv_2mortal(newSVpvn(path, strlen(path)));
XSRETURN(1);
1.4 +11 -5
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pod
Index: Upload_pod
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pod,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Upload_pod 29 Jun 2004 22:45:30 -0000 1.3
+++ Upload_pod 5 Jul 2004 20:59:00 -0000 1.4
@@ -36,6 +36,14 @@
Create an I<APR::PerlIO> filehandle from which the upload's contents
may be read.
+=head2 C<io>
+
+Creates a tied IO handle. This method is much more efficient
+than C<fh>, but the handle itself is not seekable. The handle
+is tied to an Apache::Upload::Brigade object, which is a subclass
+of APR::Brigade. Use the brigade API on the tied object if you
+want to manipulate the IO stream beyond simply reading from it.
+
=head2 C<bb([$new_brigade])>
Returns an I<APR::Brigade> which represents the upload's contents.
@@ -97,13 +105,11 @@
=head2 C<slurp($contents)>
Reads the full contents of a file upload into the scalar argument.
-The return value is currently an I<APR> status code (0 on success,
-error otherwise), but this may change in a future release (to bring
-this function in line with similar read-type functions in mp2).
+The return value is the length of the file.
# print out the upload file
- my $contents;
- print $contents if $upload->slurp($contents) == 0;
+ $upload->slurp(my $contents);
+ print $contents;
=head2 C<tempname()>