joes 2004/06/29 11:34:49
Modified: . CHANGES STATUS
glue/perl/xsbuilder/Apache/Cookie Cookie_pod
glue/perl/xsbuilder/Apache/Request Request_pm Request_pod
glue/perl/xsbuilder/maps apreq_functions.map
apreq_structures.map
src apreq.c apreq.h apreq_cookie.c apreq_cookie.h
apreq_params.c apreq_params.h apreq_parsers.c
apreq_version.h
Log:
- Perl API [joes]
Added $jar->status, $req->args_status and $req->body_status to report
parsing errors.
- C API [joes]
Dropped status attribute of apreq_value_t. Added status field to
apreq_jar_t and added args_status field to apreq_request_t. Parsers
also must return their public status code when a NULL brigade is passed.
Revision Changes Path
1.46 +11 -0 httpd-apreq-2/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- CHANGES 28 Jun 2004 21:58:15 -0000 1.45
+++ CHANGES 29 Jun 2004 18:34:48 -0000 1.46
@@ -3,6 +3,17 @@
@section v2_04_dev Changes with libapreq2-2.04-dev
+- Perl API [joes]
+ Added $jar->status, $req->args_status and $req->body_status to report
+ parsing errors.
+
+- C API [joes]
+ Dropped status attribute of apreq_value_t. Added status field to
+ apreq_jar_t and added args_status field to apreq_request_t. Parsers
+ also must return their public status code when a NULL brigade is passed.
+ apreq_hook_disable_uploads() is also added.
+ .
+ This is an ABI change affecting all versions of libapreq2 prior to 2.0.12.
- Perl API [joes]
$upload->info returns a proper APR::Table object now. Also implemented
1.56 +1 -5 httpd-apreq-2/STATUS
Index: STATUS
===================================================================
RCS file: /home/cvs/httpd-apreq-2/STATUS,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- STATUS 23 Jun 2004 02:22:28 -0000 1.55
+++ STATUS 29 Jun 2004 18:34:48 -0000 1.56
@@ -62,10 +62,6 @@
- CuTest needs va_arg to print comments for a failed unit test.
- - Eliminate useless "status" field from apreq_value_t. The only
behavioral
- change required is the mfd parser - it should wait until the upload has
- finished before adding it to the r->body table.
-
- Add FAQ file.
- Fix perl glue for CGI environment on Win32. Add a note to
1.4 +1 -0
httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Cookie_pod
Index: Cookie_pod
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Cookie_pod,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Cookie_pod 29 Oct 2003 02:20:24 -0000 1.3
+++ Cookie_pod 29 Jun 2004 18:34:48 -0000 1.4
@@ -124,6 +124,7 @@
my $secure = $cookie->secure;
$cookie->secure(1);
+
=head1 CHANGES to the v1 API:
=over 4
1.14 +7 -1
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pm
Index: Request_pm
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Request_pm 27 Jun 2004 18:07:35 -0000 1.13
+++ Request_pm 29 Jun 2004 18:34:48 -0000 1.14
@@ -27,4 +27,10 @@
sub param;
*parms = *param;
-*params = *param;
\ No newline at end of file
+*params = *param;
+
+sub status {
+ my $req = shift;
+ return wantarray ? ($req->args_status, $req->body_status)
+ : $req->args_status || $req->body_status;
+}
\ No newline at end of file
1.16 +18 -0
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pod
Index: Request_pod
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pod,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Request_pod 28 Jun 2004 21:58:15 -0000 1.15
+++ Request_pod 29 Jun 2004 18:34:48 -0000 1.16
@@ -173,6 +173,24 @@
my $upload = $apr->upload($name);
+=head2 C<args_status()>
+
+Reports the final I<APR> status code of the query-string parser.
+APR_SUCCESS on success, error otherwise.
+
+=head2 C<body_status()>
+
+Reports the current I<APR> status code of the POST data parser.
+APR_SUCCESS when parser has completed, APR_INCOMPLETE if parser
+has more data to parse, error otherwise.
+
+=head2 C<status()>
+
+In scalar context, this returns C<args_status> if there was
+an error during the query-string parse, otherwise this returns
+C<body_status>. In list context this returns the list
+C<(args_status, body_status)>.
+
=head1 SUBCLASSING Apache::Request
If the instances of your subclass are hash references then you can actually
1.23 +1 -2
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apreq_functions.map 28 Jun 2004 21:58:15 -0000 1.22
+++ apreq_functions.map 29 Jun 2004 18:34:48 -0000 1.23
@@ -10,7 +10,7 @@
DEFINE_body | apreq_xs_body_get |
DEFINE_config | apreq_xs_request_config |
DEFINE_parse | apreq_xs_request_parse |
-apr_status_t:DEFINE_status |
apreq_env_read(apreq_xs_sv2(request,sv),APR_BLOCK_READ,0) | SV *:sv
+apr_status_t:DEFINE_body_status |
apreq_parse_request(apreq_xs_sv2(request,sv),NULL) | SV *:sv
MODULE=Apache::Request PACKAGE=Apache::Request::Table
PREFIX=Apache__Request__Table_
DEFINE_get | apreq_xs_table_get |
@@ -23,7 +23,6 @@
MODULE=Apache::Upload PACKAGE=Apache::Upload PREFIX=Apache__Upload_
const char *:DEFINE_name | apreq_param_name(apreq_xs_sv2param(sv)) |
SV *:sv
char *:DEFINE_filename | apreq_param_value(apreq_xs_sv2param(sv))
| SV *:sv
- apr_status_t:DEFINE_status | apreq_param_status(apreq_xs_sv2param(sv))
| SV *:sv
DEFINE_env | apreq_xs_upload_env |
DEFINE_link | apreq_xs_upload_link |
DEFINE_slurp | apreq_xs_upload_slurp |
1.8 +2 -0
httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map
Index: apreq_structures.map
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_structures.map,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- apreq_structures.map 14 Jun 2004 02:02:23 -0000 1.7
+++ apreq_structures.map 29 Jun 2004 18:34:48 -0000 1.8
@@ -19,6 +19,7 @@
! parser
! cfg
! env
+ args_status
</apreq_request_t>
<apreq_cookie_t MODULE=Apache::Cookie>
@@ -36,6 +37,7 @@
<apreq_jar_t MODULE=Apache::Cookie>
! cookies
! env
+ status
</apreq_jar_t>
1.39 +4 -11 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- apreq.c 21 Jun 2004 17:49:18 -0000 1.38
+++ apreq.c 29 Jun 2004 18:34:48 -0000 1.39
@@ -40,7 +40,6 @@
v->name = v->data + vlen + 1;
memcpy((char *)v->name, name, nlen);
((char *)v->name)[nlen] = 0;
- v->status = APR_SUCCESS;
return v;
}
@@ -493,7 +492,6 @@
rv = apr_palloc(p, len + sizeof *rv);
rv->name = 0;
rv->size = 0;
- rv->status = APR_SUCCESS;
rv->data[0] = 0;
if (n == 0)
@@ -518,10 +516,8 @@
case APREQ_JOIN_DECODE:
len = apreq_decode(d, a[0]->data, a[0]->size);
- if (len < 0) {
- rv->status = APR_BADCH;
- break;
- }
+ if (len < 0)
+ return NULL;
else
d += len;
@@ -531,10 +527,8 @@
len = apreq_decode(d, a[j]->data, a[j]->size);
- if (len < 0) {
- rv->status = APR_BADCH;
- break;
- }
+ if (len < 0)
+ return NULL;
else
d += len;
}
@@ -583,7 +577,6 @@
rv = apr_palloc(p, 3 * slen + sizeof *rv);
rv->name = NULL;
- rv->status = APR_SUCCESS;
rv->size = apreq_encode(rv->data, src, slen);
return rv->data;
}
1.44 +0 -1 httpd-apreq-2/src/apreq.h
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- apreq.h 23 Jun 2004 02:22:28 -0000 1.43
+++ apreq.h 29 Jun 2004 18:34:48 -0000 1.44
@@ -65,7 +65,6 @@
/** @brief libapreq's pre-extensible string type */
typedef struct apreq_value_t {
const char *name; /**< value's name */
- apr_status_t status; /**< APR status, usually APR_SUCCESS or
APR_INCOMPLETE*/
apr_size_t size; /**< Size of data.*/
char data[1]; /**< Actual data bytes.*/
} apreq_value_t;
1.24 +49 -16 httpd-apreq-2/src/apreq_cookie.c
Index: apreq_cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- apreq_cookie.c 9 Jun 2004 21:02:04 -0000 1.23
+++ apreq_cookie.c 29 Jun 2004 18:34:48 -0000 1.24
@@ -282,6 +282,7 @@
j = apr_palloc(p, sizeof *j);
j->env = env;
j->cookies = apr_table_make(p, APREQ_NELTS);
+ j->status = APR_SUCCESS;
}
origin = hdr;
@@ -316,51 +317,83 @@
case 0:
/* this is the normal exit point for apreq_jar */
+ if (c != NULL) {
+ apreq_log(APREQ_DEBUG j->status, env,
+ "adding cookie: %s => %s", c->v.name, c->v.data);
+ apreq_add_cookie(j, c);
+ }
return j;
case ',':
++hdr;
+ if (c != NULL) {
+ apreq_log(APREQ_DEBUG j->status, env,
+ "adding cookie: %s => %s", c->v.name, c->v.data);
+ apreq_add_cookie(j, c);
+ }
goto parse_cookie_header;
case '$':
if (c == NULL) {
- apreq_log(APREQ_ERROR APR_BADCH, env,
- "Saw attribute, expecting NAME=VALUE cookie pair: %s",
+ j->status = APR_BADCH;
+ apreq_log(APREQ_ERROR j->status, env,
+ "Saw RFC attribute, was expecting NAME=VALUE cookie
pair: %s",
hdr);
return j;
}
else if (version == NETSCAPE) {
- c->v.status = APR_EMISMATCH;
- apreq_log(APREQ_ERROR c->v.status, env,
- "Saw attribute in a Netscape Cookie header: %s",
+ j->status = APR_EMISMATCH;
+ apreq_log(APREQ_ERROR j->status, env,
+ "Saw RFC attribute in a Netscape Cookie header:
%s",
hdr);
return j;
}
status = get_pair(&hdr, &name, &nlen, &value, &vlen);
+ if (status != APR_SUCCESS) {
+ j->status = status;
+ apreq_log(APREQ_ERROR status, env,
+ "Bad RFC attribute: %s",
+ apr_pstrmemdup(p, name, hdr-name));
+ return j;
+ }
- if (status == APR_SUCCESS)
- apreq_cookie_attr(p, c, name, nlen, value, vlen);
- else {
- c->v.status = status;
- apreq_log(APREQ_WARN c->v.status, env,
- "Ignoring bad attribute pair: %s", hdr);
+ status = apreq_cookie_attr(p, c, name, nlen, value, vlen);
+ switch (status) {
+ case APR_ENOTIMPL:
+ apreq_log(APREQ_WARN status, env,
+ "Skipping unrecognized RFC attribute pair: %s",
+ apr_pstrmemdup(p, name, hdr-name));
+ /* fall through */
+ case APR_SUCCESS:
+ break;
+ default:
+ j->status = status;
+ apreq_log(APREQ_ERROR status, env,
+ "Bad RFC attribute pair: %s",
+ apr_pstrmemdup(p, name, hdr-name));
+ return j;
}
+
break;
default:
+ if (c != NULL) {
+ apreq_log(APREQ_DEBUG j->status, env,
+ "adding cookie: %s => %s", c->v.name, c->v.data);
+ apreq_add_cookie(j, c);
+ }
+
status = get_pair(&hdr, &name, &nlen, &value, &vlen);
if (status == APR_SUCCESS) {
c = apreq_make_cookie(p, name, nlen, value, vlen);
c->version = version;
- apreq_log(APREQ_DEBUG status, env,
- "adding cookie: %s => %s", c->v.name, c->v.data);
- apreq_add_cookie(j, c);
}
else {
- apreq_log(APREQ_WARN status, env,
- "Skipping bad NAME=VALUE pair: %s", hdr);
+ apreq_log(APREQ_WARN status, env,
+ "Skipping bad NAME=VALUE pair: %s",
+ apr_pstrmemdup(p, name, hdr-name));
}
}
}
1.25 +3 -2 httpd-apreq-2/src/apreq_cookie.h
Index: apreq_cookie.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- apreq_cookie.h 23 Jun 2004 02:22:28 -0000 1.24
+++ apreq_cookie.h 29 Jun 2004 18:34:48 -0000 1.25
@@ -42,8 +42,9 @@
/** @brief This is the container class for libapreq cookies. */
typedef struct apreq_jar_t {
- apr_table_t *cookies; /**< cookie table */
- void *env; /**< environment */
+ apr_table_t *cookies; /**< cookie table */
+ void *env; /**< environment */
+ apr_status_t status; /**< status of "Cookie" header parse */
} apreq_jar_t;
1.42 +12 -15 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.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- apreq_params.c 28 Jun 2004 04:50:14 -0000 1.41
+++ apreq_params.c 29 Jun 2004 18:34:48 -0000 1.42
@@ -41,7 +41,6 @@
v->name = v->data + vlen + 1;
memcpy((char *)v->name, name, nlen);
((char *)v->name)[nlen] = 0;
- v->status = APR_SUCCESS;
return param;
}
@@ -89,10 +88,13 @@
}
if (qs != NULL) {
- apr_status_t s = apreq_parse_query_string(p, req->args, qs);
- if (s != APR_SUCCESS)
- apreq_log(APREQ_ERROR s, env, "invalid query string: %s", qs);
+ req->args_status = apreq_parse_query_string(p, req->args, qs);
+ if (req->args_status != APR_SUCCESS)
+ apreq_log(APREQ_ERROR req->args_status, env,
+ "invalid query string: %s", qs);
}
+ else
+ req->args_status = APR_SUCCESS;
return req;
}
@@ -195,22 +197,18 @@
param->info = NULL;
param->bb = NULL;
- param->v.status = APR_SUCCESS;
param->v.name = NULL;
size = apreq_decode(param->v.data, word + nlen + 1, vlen);
- if (size < 0) {
- param->v.size = 0;
- param->v.status = APR_BADARG;
- return param;
- }
+ if (size < 0)
+ return NULL;
param->v.size = size;
param->v.name = param->v.data + size + 1;
if (apreq_decode(param->v.data + size + 1, word, nlen) < 0)
- param->v.status = APR_BADCH;
+ return NULL;
return param;
}
@@ -222,14 +220,13 @@
apreq_value_t *v;
apr_size_t nlen;
- if (param->v.name == NULL || param->v.status != APR_SUCCESS)
+ if (param->v.name == NULL)
return NULL;
nlen = strlen(param->v.name);
v = apr_palloc(pool, 3 * (nlen + param->v.size) + 2 + sizeof *v);
v->name = param->v.name;
- v->status = APR_SUCCESS;
v->size = apreq_encode(v->data, param->v.name, nlen);
v->data[v->size++] = '=';
v->size += apreq_encode(v->data + v->size, param->v.data, param->v.size);
@@ -265,8 +262,8 @@
vlen = qs - start - nlen - 1;
param = apreq_decode_param(pool, start, nlen, vlen);
- if (param->v.status != APR_SUCCESS)
- return param->v.status;
+ if (param == NULL)
+ return APR_EGENERAL;
apr_table_addn(t, param->v.name, param->v.data);
}
1.34 +7 -4 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.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- apreq_params.h 27 Jun 2004 18:07:35 -0000 1.33
+++ apreq_params.h 29 Jun 2004 18:34:48 -0000 1.34
@@ -46,7 +46,6 @@
#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)
#define apreq_param_brigade(p) ((p)->bb ? apreq_copy_brigade((p)->bb) : NULL)
/** creates a param from name/value information */
@@ -58,10 +57,11 @@
/** Structure which manages the request data. */
typedef struct apreq_request_t {
- apr_table_t *args; /**< parsed query_string */
+ apr_table_t *args; /**< parsed query-string */
apr_table_t *body; /**< parsed post data */
apreq_parser_t *parser; /**< active parser for this request */
void *env; /**< request environment */
+ apr_status_t args_status; /**< status of query-string parse */
} apreq_request_t;
@@ -212,6 +212,7 @@
APREQ_DECLARE(apreq_param_t *) apreq_upload(const apreq_request_t *req,
const char *key);
+#include "apreq.h"
/** Parser arguments. */
#define APREQ_PARSER_ARGS (apreq_parser_t *parser, \
@@ -276,6 +277,8 @@
* successful parse, so callers may need to clean up the brigade
* themselves (in particular, rejected buckets should not be
* passed back to the parser again).
+ * @remark bb == NULL is valid: the parser should return its
+ * public status: APR_INCOMPLETE, APR_SUCCESS, or an error code.
*/
#define APREQ_RUN_PARSER(psr,env,t,bb) (psr)->parser(psr,env,t,bb)
@@ -386,11 +389,11 @@
*
*/
APREQ_DECLARE_HOOK(apreq_hook_disable_uploads);
+
#ifdef __cplusplus
}
-#endif
-
+#endif
#endif /* APREQ_PARAMS_H */
1.52 +14 -14 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.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- apreq_parsers.c 27 Jun 2004 18:07:35 -0000 1.51
+++ apreq_parsers.c 29 Jun 2004 18:34:48 -0000 1.52
@@ -31,6 +31,16 @@
#define CRLF "\015\012"
#endif
+#define PARSER_STATUS_CHECK(PREFIX) do { \
+ if (ctx->status == PREFIX##_ERROR) \
+ return APR_EGENERAL; \
+ else if (ctx->status == PREFIX##_COMPLETE) \
+ return APR_SUCCESS; \
+ else if (bb == NULL) \
+ return APR_INCOMPLETE; \
+} while (0);
+
+
APREQ_DECLARE(apreq_parser_t *)
apreq_make_parser(apr_pool_t *pool,
const char *enctype,
@@ -179,7 +189,7 @@
v->data[off] = 0;
v->size = off;
apr_table_addn(t, v->name, v->data);
- return v->status = APR_SUCCESS;
+ return APR_SUCCESS;
}
struct url_ctx {
@@ -209,11 +219,7 @@
else
ctx = parser->ctx;
- if (ctx->status == URL_ERROR)
- return APR_EGENERAL;
- else if (ctx->status == URL_COMPLETE)
- return APR_SUCCESS;
-
+ PARSER_STATUS_CHECK(URL);
APR_BRIGADE_CONCAT(ctx->bb, bb);
parse_url_brigade:
@@ -359,7 +365,6 @@
apr_bucket_delete(f);
}
- v->status = APR_SUCCESS;
((char *)v->name)[nlen] = 0;
/* remove trailing (CR)LF from value */
@@ -403,11 +408,7 @@
else
ctx = parser->ctx;
- if (ctx->status == HDR_ERROR)
- return APR_EGENERAL;
- else if (ctx->status == HDR_COMPLETE)
- return APR_SUCCESS;
-
+ PARSER_STATUS_CHECK(HDR);
APR_BRIGADE_CONCAT(ctx->bb, bb);
parse_hdr_brigade:
@@ -849,6 +850,7 @@
return APR_SUCCESS;
}
+ PARSER_STATUS_CHECK(MFD);
APR_BRIGADE_CONCAT(ctx->in, bb);
mfd_parse_brigade:
@@ -983,7 +985,6 @@
param->info = ctx->info;
param->bb = apr_brigade_create(pool,
apr_bucket_alloc_create(pool));
- param->v.status = APR_INCOMPLETE;
arr = (apr_array_header_t *)apr_table_elts(t);
e.key = (char *)param->v.name;
e.val = param->v.data;
@@ -1030,7 +1031,6 @@
v = ¶m->v;
v->name = name;
- v->status = APR_SUCCESS;
apr_brigade_flatten(ctx->bb, v->data, &len);
v->size = len;
v->data[v->size] = 0;
1.16 +1 -1 httpd-apreq-2/src/apreq_version.h
Index: apreq_version.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_version.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- apreq_version.h 23 Jun 2004 02:22:28 -0000 1.15
+++ apreq_version.h 29 Jun 2004 18:34:48 -0000 1.16
@@ -61,7 +61,7 @@
#define APREQ_MINOR_VERSION 0
/** patch level */
-#define APREQ_PATCH_VERSION 11
+#define APREQ_PATCH_VERSION 12
/**
* This symbol is defined for internal, "development" copies of libapreq.