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 2003/06/27 13:41:07 UTC
cvs commit: httpd-apreq-2/t parsers.c
joes 2003/06/27 04:41:07
Modified: glue/perl/t/response/TestApReq request.pm
glue/perl/xsbuilder apreq_xs_postperl.h
glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
glue/perl/xsbuilder/Apache/Request Apache__Request.h
glue/perl/xsbuilder/maps apreq_functions.map
src apreq.c apreq.h apreq_params.c apreq_params.h
apreq_parsers.c apreq_parsers.h
t parsers.c
Log:
Add name, info, value, & link to upload API.
Revision Changes Path
1.4 +18 -14 httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm
Index: request.pm
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- request.pm 24 Jun 2003 22:27:44 -0000 1.3
+++ request.pm 27 Jun 2003 11:41:05 -0000 1.4
@@ -6,6 +6,10 @@
use Apache::RequestRec;
use Apache::RequestIO;
use Apache::Request ();
+use Apache::Connection;
+use APR::Brigade;
+use APR::Bucket;
+use Apache::Filter;
sub handler {
my $r = shift;
@@ -13,35 +17,35 @@
$req->content_type('text/plain');
- my $test = $req->param('test');
- my $value = $req->param('value');
-
- my $f = $r->input_filters;
+ my $test = $req->args('test');
my $method = $r->method;
- my $bb = APR::Brigade->new($r->pool,
- $r->connection->bucket_alloc);
- my $len = 0;
- # ~ $apr->parse ???
if ($method eq "POST") {
- do {
+ # ~ $apr->parse ???
+ my $f = $r->input_filters;
+ my $bb = APR::Brigade->new($r->pool,
+ $r->connection->bucket_alloc);
+ while ($f->get_brigade($bb,0,0,8000) == 0) {
+ last if $bb->last->is_eos;
$bb->destroy;
- $f->get_brigade($bb, 0, 0, 8000);
- } while $bb->last && !$bb->last->is_eos;
+ }
+ $bb->destroy;
}
if ($test eq 'param') {
+ my $value = $req->param('value');
$req->print($value);
}
elsif ($test eq 'upload') {
my ($upload) = values %{$req->upload};
- $bb = $upload->bb;
- my $b = $bb->first;
- while ($b = $bb->first) {
+# unlink("/tmp/foo");
+ my $bb = $upload->bb;
+ while (my $b = $bb->first) {
$b->read(my $buffer);
$r->print($buffer);
$b->remove;
}
+# $upload->link("/tmp/foo");
}
return 0;
1.11 +6 -6 httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h
Index: apreq_xs_postperl.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- apreq_xs_postperl.h 24 Jun 2003 22:27:44 -0000 1.10
+++ apreq_xs_postperl.h 27 Jun 2003 11:41:05 -0000 1.11
@@ -72,10 +72,9 @@
* and produces a pointer to the underlying C environment.
*/
APR_INLINE
-static void *apreq_xs_perl2env(SV *sv, const char *name)
+static void *apreq_xs_perl2env(SV *sv)
{
MAGIC *mg;
- sv = apreq_xs_find_obj(sv, name);
if (sv != NULL && (mg = mg_find(sv, PERL_MAGIC_ext)))
return mg->mg_ptr;
return NULL;
@@ -122,7 +121,7 @@
#define apreq_xs_2sv(t,class) apreq_xs_c2perl(aTHX_ t, env, class)
#define apreq_xs_sv2(type,sv)((apreq_##type##_t *)apreq_xs_perl2c(sv, #type))
-#define apreq_xs_sv2env(type,sv) apreq_xs_perl2env(sv,#type)
+#define apreq_xs_sv2env(sv) apreq_xs_perl2env(sv)
/** Converts apreq_env to a Perl package, which forms the
* base class for Apache::Request and Apache::Cookie::Jar objects.
@@ -145,7 +144,8 @@
XSRETURN(0); \
\
if (SvROK(ST(0))) { \
- void *env = apreq_xs_sv2env(type, ST(0)); \
+ SV *sv = apreq_xs_find_obj(ST(0), #type); \
+ void *env = apreq_xs_sv2env(sv); \
\
if (env) \
ST(0) = sv_setref_pv(newSV(0), class, env); \
@@ -287,8 +287,8 @@
dXSARGS; \
const char *key = NULL; \
\
- if (items == 1 || items == 2) { \
- void *env = apreq_xs_sv2env(attr, ST(0)); \
+ if (items == 1 || items == 2 && SvROK(ST(0))) { \
+ void *env = apreq_xs_##attr##_sv2env(ST(0)); \
struct apreq_xs_do_arg d = { env, aTHX }; \
apreq_##type##_t *RETVAL; \
if (items == 2) \
1.8 +6 -3 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Apache__Cookie.h 24 Jun 2003 22:27:44 -0000 1.7
+++ Apache__Cookie.h 27 Jun 2003 11:41:05 -0000 1.8
@@ -2,7 +2,7 @@
#define apreq_xs_jar2env(j) j->env
#define apreq_xs_cookie2sv(c,class) apreq_xs_2sv(c,class)
-//#define apreq_xs_jar2sv(j,class) apreq_xs_
+#define apreq_xs_sv2cookie(sv) ((apreq_cookie_t *)SvIVX(SvRV(sv)))
APREQ_XS_DEFINE_ENV(cookie);
APREQ_XS_DEFINE_ENV(jar);
@@ -15,6 +15,9 @@
#define apreq_xs_table_push(sv,d,key) apreq_xs_push(table,sv,d,key)
#define apreq_xs_jar_sv2table(sv) (apreq_xs_sv2(jar, sv)->cookies)
#define apreq_xs_table_sv2table(sv) apreq_xs_sv2table(sv)
+#define apreq_xs_jar_sv2env(sv) apreq_xs_sv2(jar,sv)->env
+#define apreq_xs_table_sv2env(sv) apreq_xs_sv2env(SvRV(sv))
+
#define apreq_xs_jar_cookie(sv,k) \
S2C(apr_table_get(apreq_xs_jar_sv2table(sv),k))
#define apreq_xs_table_cookie(sv,k) \
@@ -56,7 +59,7 @@
c = apreq_xs_sv2(cookie,ST(0));
if (items > 1) {
- apr_pool_t *p = apreq_env_pool(apreq_xs_sv2env(cookie,ST(0)));
+ apr_pool_t *p = apreq_env_pool(apreq_xs_sv2env(ST(0)));
const char *s = SvPV_nolen(ST(1));
apreq_cookie_expires(p, c, s);
}
@@ -82,7 +85,7 @@
XSRETURN_UNDEF;
c = apreq_value_to_cookie(apreq_xs_sv2(cookie,ST(0)));
- p = apreq_env_pool(apreq_xs_sv2env(cookie,ST(0)));
+ p = apreq_env_pool(apreq_xs_sv2env(ST(0)));
for (j = 1; j + 1 < items; j += 2) {
status = apreq_cookie_attr(p, c, SvPV_nolen(ST(j)),
1.9 +50 -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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Apache__Request.h 24 Jun 2003 22:27:44 -0000 1.8
+++ Apache__Request.h 27 Jun 2003 11:41:06 -0000 1.9
@@ -1,4 +1,4 @@
-#define apreq_xs_param2rv(ptr, class) sv_setref_pv(newSV(0), class, ptr)
+#define apreq_xs_param2rv(ptr, class) apreq_xs_2sv(ptr,class)
#define apreq_xs_rv2param(sv) ((apreq_param_t *)SvIVX(SvRV(sv)))
@@ -18,7 +18,7 @@
/* Too many GET macros :-( */
-#define S2P(s) apreq_value_to_param(apreq_strtoval(s))
+#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_xs_sv2(request,sv); \
apr_table_do(apreq_xs_do(request), &d, req->args, key, NULL); \
@@ -45,6 +45,13 @@
apreq_xs_sv2(request,sv))
#define apreq_xs_upload_table_sv2table(sv) apreq_xs_sv2table(sv)
+#define apreq_xs_request_sv2env(sv) apreq_xs_sv2(request,sv)->env
+#define apreq_xs_args_sv2env(sv) apreq_xs_sv2(request,sv)->env
+#define apreq_xs_body_sv2env(sv) apreq_xs_sv2(request,sv)->env
+#define apreq_xs_upload_sv2env(sv) apreq_xs_sv2(request,sv)->env
+#define apreq_xs_table_sv2env(sv) apreq_xs_sv2env(SvRV(sv))
+#define apreq_xs_upload_table_sv2env(sv) apreq_xs_sv2env(SvRV(sv))
+
#define apreq_xs_request_param(sv,k) apreq_param(apreq_xs_sv2(request,sv),k)
#define apreq_xs_args_param(sv,k) \
S2P(apr_table_get(apreq_xs_args_sv2table(sv),k))
@@ -73,3 +80,44 @@
#define UPLOAD_PKG "Apache::Upload"
APREQ_XS_DEFINE_GET(upload, UPLOAD_TABLE, param, UPLOAD_PKG, RETVAL->bb);
APREQ_XS_DEFINE_GET(upload_table, UPLOAD_TABLE, param, UPLOAD_PKG, 1);
+
+
+APR_INLINE
+static XS(apreq_xs_upload_link)
+{
+ dXSARGS;
+ MAGIC *mg;
+ void *env;
+ apr_status_t s;
+ const char *name, *fname;
+ apr_bucket_brigade *bb;
+ apr_file_t *f;
+
+ if (items != 2 || !SvROK(ST(0)))
+ Perl_croak(aTHX_ "Usage: $upload->link($name)");
+
+ if (!(mg = mg_find(SvRV(ST(0)), PERL_MAGIC_ext)))
+ Perl_croak(aTHX_ "$upload->link($name): can't find env");
+
+ env = mg->mg_ptr;
+ bb = apreq_xs_rv2param(ST(0))->bb;
+ name = SvPV_nolen(ST(1));
+
+ f = apreq_brigade_spoolfile(bb);
+ if (f == NULL) {
+ apr_off_t len;
+ s = apr_file_open(&f, name, APR_CREATE | APR_EXCL | APR_WRITE | APR_READ
+ | APR_BINARY, APR_OS_DEFAULT, apreq_env_pool(env));
+ if (s != APR_SUCCESS)
+ XSRETURN_IV(s);
+ s = apreq_brigade_fwrite(f, &len, bb);
+ XSRETURN_IV(s);
+ }
+ s = apr_file_name_get(&fname, f);
+ if (s != APR_SUCCESS)
+ XSRETURN_IV(s);
+
+ s = PerlLIO_link(fname, name);
+ XSRETURN_IV(s ? APR_EGENERAL : APR_SUCCESS);
+}
+
1.9 +8 -4 httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map
Index: apreq_functions.map
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apreq_functions.map 24 Jun 2003 22:27:44 -0000 1.8
+++ apreq_functions.map 27 Jun 2003 11:41:06 -0000 1.9
@@ -17,8 +17,12 @@
DEFINE_FETCH | apreq_xs_table_get |
MODULE=Apache::Request PACKAGE=Apache::Upload PREFIX=Apache__Upload_
-apr_bucket_brigade *:DEFINE_bb | apreq_param_brigade(apreq_xs_sv2(param,sv)) | SV *:sv
-apr_table_t *:DEFINE_info | apreq_param_info(apreq_xs_sv2(param,sv)) | SV *:sv
+ apr_bucket_brigade *:DEFINE_bb | apreq_param_brigade(apreq_xs_rv2param(sv)) | SV *:sv
+ apr_table_t *:DEFINE_info | apreq_param_info(apreq_xs_rv2param(sv)) | SV *:sv
+ DEFINE_link | apreq_xs_upload_link |
+ const char *:DEFINE_name | apreq_param_name(apreq_xs_rv2param(sv)) | SV *:sv
+ char *:DEFINE_value | apreq_param_value(apreq_xs_rv2param(sv)) | SV *:sv
+ apr_status_t:DEFINE_status | apreq_param_status(apreq_xs_rv2param(sv)) | SV *:sv
MODULE=Apache::Request PACKAGE=Apache::Upload::Table PREFIX=Apache__Upload__Table_
DEFINE_get | apreq_xs_upload_table_get |
@@ -33,8 +37,8 @@
DEFINE_env | apreq_xs_cookie_env |
const char *:DEFINE_name | apreq_cookie_name(c) | apreq_cookie_t *:c
const char *:DEFINE_value| apreq_cookie_value(c) | apreq_cookie_t *:c
- apr_status_t:DEFINE_bake | apreq_cookie_bake (apreq_xs_sv2(cookie,c), apreq_xs_sv2env(cookie,c)) | SV *:c
- apr_status_t:DEFINE_bake2| apreq_cookie_bake2(apreq_xs_sv2(cookie,c), apreq_xs_sv2env(cookie,c)) | SV *:c
+ apr_status_t:DEFINE_bake | apreq_cookie_bake (apreq_xs_sv2cookie(c), apreq_xs_sv2env(c)) | SV *:c
+ apr_status_t:DEFINE_bake2| apreq_cookie_bake2(apreq_xs_sv2cookie(c), apreq_xs_sv2env(c)) | SV *:c
MODULE=Apache::Cookie PACKAGE=Apache::Cookie::Jar PREFIX=Apache__Cookie__Jar_
DEFINE_new | apreq_xs_jar |
1.21 +120 -0 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- apreq.c 18 Jun 2003 02:08:43 -0000 1.20
+++ apreq.c 27 Jun 2003 11:41:06 -0000 1.21
@@ -615,3 +615,123 @@
return rv->data;
}
+
+APR_INLINE
+static apr_status_t apreq_fwritev(apr_file_t *f, struct iovec *v,
+ int *nelts, apr_size_t *bytes_written)
+{
+ apr_size_t len, bytes_avail = 0;
+ int n = *nelts;
+ apr_status_t s = apr_file_writev(f, v, n, &len);
+
+ *bytes_written = len;
+
+ if (s != APR_SUCCESS)
+ return s;
+
+ while (--n >= 0)
+ bytes_avail += v[n].iov_len;
+
+
+ if (bytes_avail > len) {
+ /* incomplete write: must shift v */
+ n = 0;
+ while (v[n].iov_len <= len) {
+ len -= v[n].iov_len;
+ ++n;
+ }
+ v[n].iov_len -= len;
+ v[n].iov_base = (char *)(v[n].iov_base) + len;
+
+ if (n > 0) {
+ struct iovec *dest = v;
+ do {
+ *dest++ = v[n++];
+ } while (n < *nelts);
+ *nelts = dest - v;
+ }
+ else {
+ s = apreq_fwritev(f, v, nelts, &len);
+ *bytes_written += len;
+ }
+ }
+ else
+ *nelts = 0;
+
+ return s;
+}
+
+
+APREQ_DECLARE(apr_status_t) apreq_brigade_fwrite(apr_file_t *f,
+ apr_off_t *wlen,
+ apr_bucket_brigade *bb)
+{
+ struct iovec v[APREQ_NELTS];
+ apr_status_t s;
+ apr_bucket *e;
+ int n = 0;
+ *wlen = 0;
+
+ APR_BRIGADE_FOREACH(e,bb) {
+ apr_size_t len;
+ if (n == APREQ_NELTS) {
+ s = apreq_fwritev(f, v, &n, &len);
+ if (s != APR_SUCCESS)
+ return s;
+ *wlen += len;
+ }
+ s = apr_bucket_read(e, (const char **)&(v[n].iov_base),
+ &len, APR_BLOCK_READ);
+ if (s != APR_SUCCESS)
+ return s;
+
+ v[n++].iov_len = len;
+ }
+
+ while (n > 0) {
+ apr_size_t len;
+ s = apreq_fwritev(f, v, &n, &len);
+ if (s != APR_SUCCESS)
+ return s;
+ *wlen += len;
+ }
+ return APR_SUCCESS;
+}
+
+APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
+ apr_pool_t *pool,
+ const char *path)
+{
+ apr_status_t rc = APR_SUCCESS;
+ char *tmpl;
+ if (path) {
+ rc = apr_filepath_merge(&tmpl, path, "apreqXXXXXX",
+ APR_FILEPATH_NOTRELATIVE, pool);
+ if (rc != APR_SUCCESS)
+ return rc;
+ }
+ else {
+ char *tn = tempnam(NULL, "apreq");
+ if (tn == NULL)
+ return APR_EGENERAL;
+ tmpl = apr_pstrcat(pool, tn, "XXXXXX", NULL);
+ free(tn);
+ }
+
+ return apr_file_mktemp(fp, tmpl,
+ APR_CREATE | APR_READ | APR_WRITE
+ | APR_EXCL | APR_DELONCLOSE | APR_BINARY, pool);
+}
+
+/* circumvents linker issue (perl's CCFLAGS != apr's CCFLAGS) on linux */
+APREQ_DECLARE(apr_file_t *)apreq_brigade_spoolfile(apr_bucket_brigade *bb)
+{
+ apr_bucket *last = APR_BRIGADE_LAST(bb);
+ apr_bucket_file *f;
+ if (APR_BUCKET_IS_FILE(last)) {
+ f = last->data;
+ return f->fd;
+ }
+ else
+ return NULL;
+}
1.25 +12 -0 httpd-apreq-2/src/apreq.h
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- apreq.h 18 Jun 2003 02:08:43 -0000 1.24
+++ apreq.h 27 Jun 2003 11:41:06 -0000 1.25
@@ -56,6 +56,8 @@
#define APREQ_H
#include "apr_tables.h"
+#include "apr_file_io.h"
+#include "apr_buckets.h"
#include <stddef.h>
#ifndef apr_table_nelts
@@ -319,6 +321,16 @@
*/
APREQ_DECLARE(apr_int64_t) apreq_atoi64t(const char *s);
+
+APREQ_DECLARE(apr_status_t) apreq_brigade_fwrite(apr_file_t *f,
+ apr_off_t *wlen,
+ apr_bucket_brigade *bb);
+
+APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
+ apr_pool_t *pool,
+ const char *path);
+
+APREQ_DECLARE(apr_file_t *) apreq_brigade_spoolfile(apr_bucket_brigade *bb);
/** @} */
1.23 +2 -2 httpd-apreq-2/src/apreq_params.c
Index: apreq_params.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apreq_params.c 26 Jun 2003 12:49:46 -0000 1.22
+++ apreq_params.c 27 Jun 2003 11:41:06 -0000 1.23
@@ -88,12 +88,11 @@
return param;
}
-APR_INLINE APREQ_DECLARE(apr_bucket_brigade *)
+APREQ_DECLARE(apr_bucket_brigade *)
apreq_param_brigade(const apreq_param_t *param)
{
apr_bucket_brigade *bb;
apr_bucket *e;
-
if (param->bb == NULL)
return NULL;
@@ -105,6 +104,7 @@
}
return bb;
}
+
APREQ_DECLARE(apreq_request_t *) apreq_request(void *env, const char *qs)
1.20 +2 -2 httpd-apreq-2/src/apreq_params.h
Index: apreq_params.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- apreq_params.h 26 Jun 2003 12:49:46 -0000 1.19
+++ apreq_params.h 27 Jun 2003 11:41:06 -0000 1.20
@@ -90,9 +90,10 @@
#define apreq_param_name(p) ((p)->v.name)
#define apreq_param_value(p) ((p)->v.data)
#define apreq_param_info(p) ((p)->info)
+#define apreq_param_status(p) ((p)->v.status)
/** returns a copy of param->bb */
-APR_INLINE APREQ_DECLARE(apr_bucket_brigade *)
+APREQ_DECLARE(apr_bucket_brigade *)
apreq_param_brigade(const apreq_param_t *param);
APREQ_DECLARE(apreq_param_t *) apreq_make_param(apr_pool_t *p,
@@ -189,7 +190,6 @@
APREQ_DECLARE(apreq_param_t *) apreq_upload(const apreq_request_t *req,
const char *key);
-
/** @} */
1.28 +21 -116 httpd-apreq-2/src/apreq_parsers.c
Index: apreq_parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- apreq_parsers.c 24 Jun 2003 22:27:44 -0000 1.27
+++ apreq_parsers.c 27 Jun 2003 11:41:06 -0000 1.28
@@ -681,88 +681,21 @@
return APR_INCOMPLETE;
}
-APR_INLINE
-static apr_status_t mfd_fwritev(apr_file_t *f, struct iovec *v,
- int *nelts, apr_size_t *bytes_written)
-{
- apr_size_t len, bytes_avail = 0;
- int n = *nelts;
- apr_status_t s = apr_file_writev(f, v, n, &len);
-
- *bytes_written = len;
-
- if (s != APR_SUCCESS)
- return s;
-
- while (--n >= 0)
- bytes_avail += v[n].iov_len;
- if (bytes_avail > len) {
- /* incomplete write: must shift v */
- n = 0;
- while (v[n].iov_len <= len) {
- len -= v[n].iov_len;
- ++n;
- }
- v[n].iov_len -= len;
- v[n].iov_base = (char *)(v[n].iov_base) + len;
-
- if (n > 0) {
- struct iovec *dest = v;
- do {
- *dest++ = v[n++];
- } while (n < *nelts);
- *nelts = dest - v;
- }
- else {
- s = mfd_fwritev(f, v, nelts, &len);
- *bytes_written += len;
- }
- }
-
- return s;
-}
-
-
-APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
- apr_pool_t *pool,
- const apreq_cfg_t *cfg)
-{
- apr_status_t rc = APR_SUCCESS;
- char *path = NULL;
-
- if (cfg && cfg->temp_dir) {
- rc = apr_filepath_merge(&path, cfg->temp_dir, "apreqXXXXXX",
- APR_FILEPATH_NOTRELATIVE, pool);
- if (rc != APR_SUCCESS)
- return rc;
- }
- else {
- char *tmp = tempnam(NULL, "apreq");
- if (tmp == NULL)
- return APR_EGENERAL;
- path = apr_pstrcat(pool, tmp, "XXXXXX", NULL);
- free(tmp);
- }
-
- return apr_file_mktemp(fp, path,
- APR_CREATE | APR_READ | APR_WRITE
- | APR_EXCL | APR_DELONCLOSE | APR_BINARY, pool);
-}
-
#define MAX_FILE_BUCKET_LENGTH ( 1 << ( 6 * sizeof(apr_size_t) ) )
-APR_INLINE
-static apr_status_t mfd_bb_concat(apr_pool_t *pool, const apreq_cfg_t *cfg,
- apr_bucket_brigade *out,
- apr_bucket_brigade *in)
+static apr_status_t apreq_bb_concat(apr_pool_t *pool,
+ const apreq_cfg_t *cfg,
+ apr_bucket_brigade *out,
+ apr_bucket_brigade *in)
{
apr_bucket *last = APR_BRIGADE_LAST(out);
apr_status_t s;
struct iovec v[APREQ_NELTS];
apr_bucket_file *f;
apr_bucket *e;
+ apr_off_t wlen;
int n = 0;
if (! APR_BUCKET_IS_FILE(last)) {
@@ -778,18 +711,19 @@
return APR_SUCCESS;
}
- s = apreq_file_mktemp(&file, pool, cfg);
+ s = apreq_file_mktemp(&file, pool, cfg ? cfg->temp_dir : NULL);
if (s != APR_SUCCESS)
return s;
- bb = apr_brigade_create(pool, out->bucket_alloc);
- e = apr_bucket_file_create(file, len, 0, pool, out->bucket_alloc);
- APR_BRIGADE_INSERT_HEAD(bb, e);
- s = mfd_bb_concat(pool, cfg, bb, out);
+ s = apreq_brigade_fwrite(file, &wlen, out);
+
if (s != APR_SUCCESS)
return s;
- APR_BRIGADE_CONCAT(out, bb);
- last = APR_BRIGADE_LAST(out);
+
+ /* assert (wlen == len); */
+
+ last = apr_bucket_file_create(file, wlen, 0, pool, out->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(out, last);
}
f = last->data;
@@ -801,40 +735,11 @@
e->start = last->length;
last = e;
}
-
- e = APR_BRIGADE_FIRST(in);
-
- while (!APR_BRIGADE_EMPTY(in)) {
- apr_size_t len;
-
- if (e == APR_BRIGADE_SENTINEL(in) || n == APREQ_NELTS) {
- int nvec = n;
- s = mfd_fwritev(f->fd, v, &nvec, &len);
- if (s != APR_SUCCESS)
- return s;
-
- /* nvec now holds the actual number written */
- n -= nvec;
-
- while (nvec-- > 0) {
- apr_bucket *first = APR_BRIGADE_FIRST(in);
- apr_bucket_delete(first);
- }
-
- last->length += len;
- }
- else {
- s = apr_bucket_read(e, (const char **)&(v[n].iov_base),
- &len, APR_NONBLOCK_READ);
- if (s != APR_SUCCESS)
- return s;
-
- v[n++].iov_len = len;
- e = APR_BUCKET_NEXT(e);
- }
- }
-
- return APR_SUCCESS;
+ s = apreq_brigade_fwrite(f->fd, &wlen, in);
+ if (s != APR_SUCCESS)
+ return s;
+ last->length += wlen;
+ return apr_brigade_destroy(in);
}
@@ -1115,7 +1020,7 @@
if (s != APR_INCOMPLETE && s != APR_SUCCESS)
return s;
}
- return mfd_bb_concat(pool, cfg, param->bb, ctx->bb);
+ return apreq_bb_concat(pool, cfg, param->bb, ctx->bb);
case APR_SUCCESS:
if (parser->hook) {
@@ -1128,8 +1033,8 @@
return s;
}
- param->v.status = mfd_bb_concat(pool, cfg,
- param->bb, ctx->bb);
+ param->v.status = apreq_bb_concat(pool, cfg,
+ param->bb, ctx->bb);
if (param->v.status != APR_SUCCESS)
return s;
1.16 +0 -4 httpd-apreq-2/src/apreq_parsers.h
Index: apreq_parsers.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- apreq_parsers.h 24 Jun 2003 22:27:44 -0000 1.15
+++ apreq_parsers.h 27 Jun 2003 11:41:06 -0000 1.16
@@ -84,10 +84,6 @@
APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env, apreq_hook_t *hook);
-APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
- apr_pool_t *pool,
- const apreq_cfg_t *cfg);
-
/** @} */
#ifdef __cplusplus
}
1.5 +1 -1 httpd-apreq-2/t/parsers.c
Index: parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/parsers.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- parsers.c 20 May 2003 20:27:32 -0000 1.4
+++ parsers.c 27 Jun 2003 11:41:07 -0000 1.5
@@ -134,7 +134,7 @@
CuAssertIntEquals(tc, APR_SUCCESS, rv);
CuAssertPtrNotNull(tc, req->body);
CuAssertIntEquals(tc, 2, apr_table_nelts(req->body));
- return;
+
val = apr_table_get(req->body,"field1");
CuAssertStrEquals(tc, "Joe owes =80100.", val);
t = apreq_value_to_param(apreq_strtoval(val))->info;