joes 2004/07/16 18:09:39
Modified: . STATUS
src apreq.c
t cookie.c params.c
Log:
Eliminate tail-recursion from apreq_header_attribute. Also add
apreq_ua_cookie_version tests.
Revision Changes Path
1.69 +1 -2 httpd-apreq-2/STATUS
Index: STATUS
===================================================================
RCS file: /home/cvs/httpd-apreq-2/STATUS,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- STATUS 16 Jul 2004 17:12:36 -0000 1.68
+++ STATUS 17 Jul 2004 01:09:39 -0000 1.69
@@ -68,7 +68,6 @@
- apreq_quote()
- apreq_quote_once()
- apreq_escape()
- - apreq_ua_cookie_version()
- apreq_encode_param()
- CuTest needs va_arg to print comments for a failed unit test.
1.43 +45 -43 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- apreq.c 10 Jul 2004 14:42:30 -0000 1.42
+++ apreq.c 17 Jul 2004 01:09:39 -0000 1.43
@@ -778,61 +778,63 @@
const char *name, const apr_size_t nlen,
const char **val, apr_size_t *vlen)
{
- const char *loc = strchr(hdr, '='), *v;
+ const char *key, *v;
- if (loc == NULL)
- return APR_NOTFOUND;
+ while ((key = strchr(hdr, '=')) != NULL) {
- v = loc + 1;
- --loc;
+ v = key + 1;
+ --key;
- while (apr_isspace(*loc) && loc - hdr > nlen)
- --loc;
+ while (apr_isspace(*key) && key > hdr + nlen)
+ --key;
- loc -= nlen - 1;
+ key -= nlen - 1;
- while (apr_isspace(*v))
+ while (apr_isspace(*v))
++v;
- if (*v == '"') {
- ++v;
- /* value is inside quotes */
- for (*val = v; *v; ++v) {
- switch (*v) {
- case '"':
- goto finish;
- case '\\':
- if (v[1] != 0)
- ++v;
- default:
- break;
+ if (*v == '"') {
+ ++v;
+ /* value is inside quotes */
+ for (*val = v; *v; ++v) {
+ switch (*v) {
+ case '"':
+ goto finish;
+ case '\\':
+ if (v[1] != 0)
+ ++v;
+ default:
+ break;
+ }
}
}
- }
- else {
- /* value is not wrapped in quotes */
- for (*val = v; *v; ++v) {
- switch (*v) {
- case ' ':
- case ';':
- case ',':
- case '\t':
- case '\r':
- case '\n':
- goto finish;
- default:
- break;
+ else {
+ /* value is not wrapped in quotes */
+ for (*val = v; *v; ++v) {
+ switch (*v) {
+ case ' ':
+ case ';':
+ case ',':
+ case '\t':
+ case '\r':
+ case '\n':
+ goto finish;
+ default:
+ break;
+ }
}
}
- }
finish:
- if (strncasecmp(loc,name,nlen) != 0
- || (loc > hdr && apr_isalpha(loc[-1])))
- return apreq_header_attribute(v, name, nlen, val, vlen);
-
- *vlen = v - *val;
- return APR_SUCCESS;
-
+ if (strncasecmp(key, name, nlen) == 0
+ && (key == hdr || !apr_isalpha(key[-1])))
+ {
+ *vlen = v - *val;
+ return APR_SUCCESS;
+ }
+ else
+ hdr = v + 1;
+ }
+ return APR_NOTFOUND;
}
1.10 +11 -0 httpd-apreq-2/t/cookie.c
Index: cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/cookie.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- cookie.c 21 Jun 2004 17:51:03 -0000 1.9
+++ cookie.c 17 Jul 2004 01:09:39 -0000 1.10
@@ -104,6 +104,16 @@
}
+static void ua_version(CuTest *tc)
+{
+ apreq_cookie_version_t v;
+
+ v = apreq_ua_cookie_version(NULL);
+ CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_NETSCAPE, v);
+ v = apreq_ua_cookie_version("$Version=\"1\"");
+ CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_RFC, v);
+
+}
CuSuite *testcookie(void)
{
@@ -113,6 +123,7 @@
SUITE_ADD_TEST(suite, jar_table_get);
SUITE_ADD_TEST(suite, netscape_cookie);
SUITE_ADD_TEST(suite, rfc_cookie);
+ SUITE_ADD_TEST(suite, ua_version);
return suite;
}
1.14 +27 -0 httpd-apreq-2/t/params.c
Index: params.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/params.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- params.c 2 Jul 2004 01:45:20 -0000 1.13
+++ params.c 17 Jul 2004 01:09:39 -0000 1.14
@@ -80,6 +80,31 @@
}
+static void header_attributes(CuTest *tc)
+{
+ const char hdr[] = "text/plain; boundary=\"-foo-\", charset=ISO-8859-1";
+ const char *val;
+ apr_size_t vlen;
+ apr_status_t s;
+
+ s = apreq_header_attribute(hdr, "none", 4, &val, &vlen);
+ CuAssertIntEquals(tc, APR_NOTFOUND, s);
+
+ s = apreq_header_attribute(hdr, "set", 3, &val, &vlen);
+ CuAssertIntEquals(tc, APR_NOTFOUND, s);
+
+ s = apreq_header_attribute(hdr, "boundary", 8, &val, &vlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 5, vlen);
+ CuAssertStrNEquals(tc, "-foo-", val, 5);
+
+ s = apreq_header_attribute(hdr, "charset", 7, &val, &vlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 10, vlen);
+ CuAssertStrNEquals(tc, "ISO-8859-1", val, 10);
+
+}
+
CuSuite *testparam(void)
{
@@ -89,6 +114,8 @@
SUITE_ADD_TEST(suite, request_args_get);
SUITE_ADD_TEST(suite, params_as);
SUITE_ADD_TEST(suite, string_decoding_in_place);
+ SUITE_ADD_TEST(suite, header_attributes);
+
return suite;
}