joes 2004/06/09 14:02:05
Modified: glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
src apreq_cookie.c apreq_cookie.h apreq_version.h
t cookie.c
Log:
Objectify cookie API.
Revision Changes Path
1.19 +1 -1
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Apache__Cookie.h 28 Feb 2004 07:48:14 -0000 1.18
+++ Apache__Cookie.h 9 Jun 2004 21:02:04 -0000 1.19
@@ -95,7 +95,7 @@
if (c->max_age == -1)
XSRETURN_UNDEF;
- if (c->version == NETSCAPE) {
+ if (c->version == APREQ_COOKIE_VERSION_NETSCAPE) {
char expires[APR_RFC822_DATE_LEN] = {0};
apr_rfc822_date(expires, c->max_age + apr_time_now());
expires[7] = '-';
1.23 +21 -19 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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apreq_cookie.c 28 Feb 2004 07:48:14 -0000 1.22
+++ apreq_cookie.c 9 Jun 2004 21:02:04 -0000 1.23
@@ -19,6 +19,9 @@
#include "apr_strings.h"
#include "apr_lib.h"
+#define RFC APREQ_COOKIE_VERSION_RFC
+#define NETSCAPE APREQ_COOKIE_VERSION_NETSCAPE
+#define DEFAULT APREQ_COOKIE_VERSION_DEFAULT
APREQ_DECLARE(apreq_cookie_t *) apreq_cookie(const apreq_jar_t *jar,
const char *name)
@@ -29,8 +32,8 @@
return apreq_value_to_cookie(apreq_char_to_value(val));
}
-APREQ_DECLARE(void) apreq_add_cookie(apreq_jar_t *jar,
- const apreq_cookie_t *c)
+APREQ_DECLARE(void) apreq_jar_add(apreq_jar_t *jar,
+ const apreq_cookie_t *c)
{
apr_table_addn(jar->cookies,
c->v.name,c->v.data);
@@ -65,7 +68,7 @@
apreq_jar_t *j = apreq_jar(env, NULL);
if (j == NULL || apreq_jar_nelts(j) == 0)
- return APREQ_COOKIE_VERSION;
+ return NETSCAPE;
else if (apr_table_do(has_rfc_cookie, NULL, j->cookies) == 1)
return NETSCAPE;
@@ -148,7 +151,7 @@
return APR_ENOTIMPL;
}
-APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(apr_pool_t *p,
+APREQ_DECLARE(apreq_cookie_t *) apreq_cookie_make(apr_pool_t *p,
const char *name, const apr_size_t nlen,
const char *value, const apr_size_t vlen)
{
@@ -160,7 +163,7 @@
memcpy(v->data, value, vlen);
v->data[vlen] = 0;
- c->version = APREQ_COOKIE_VERSION;
+ c->version = DEFAULT;
/* session cookie is the default */
c->max_age = -1;
@@ -367,8 +370,8 @@
}
-APREQ_DECLARE(int) apreq_serialize_cookie(char *buf, apr_size_t len,
- const apreq_cookie_t *c)
+APREQ_DECLARE(int) apreq_cookie_serialize(const apreq_cookie_t *c,
+ char *buf, apr_size_t len)
{
/* The format string must be large enough to accomodate all
* of the cookie attributes. The current attributes sum to
@@ -440,14 +443,13 @@
}
-APREQ_DECLARE(char*) apreq_cookie_as_string(apr_pool_t *p,
- const apreq_cookie_t *c)
-
+APREQ_DECLARE(char*) apreq_cookie_as_string(const apreq_cookie_t *c,
+ apr_pool_t *p)
{
- char s[APREQ_COOKIE_LENGTH];
- int n = apreq_serialize_cookie(s, APREQ_COOKIE_LENGTH, c);
+ char s[APREQ_COOKIE_MAX_LENGTH];
+ int n = apreq_serialize_cookie(s, APREQ_COOKIE_MAX_LENGTH, c);
- if (n < APREQ_COOKIE_LENGTH)
+ if (n < APREQ_COOKIE_MAX_LENGTH)
return apr_pstrmemdup(p, s, n);
else
return NULL;
@@ -456,12 +458,12 @@
APREQ_DECLARE(apr_status_t) apreq_cookie_bake(const apreq_cookie_t *c,
void *env)
{
- char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
+ char *s = apreq_cookie_as_string(c,apreq_env_pool(env));
if (s == NULL) {
apreq_log(APREQ_ERROR APR_ENAMETOOLONG, env,
- "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d",
- APREQ_COOKIE_LENGTH);
+ "Serialized cookie exceeds APREQ_COOKIE_MAX_LENGTH = %d",
+ APREQ_COOKIE_MAX_LENGTH);
return APR_ENAMETOOLONG;
}
@@ -471,12 +473,12 @@
APREQ_DECLARE(apr_status_t) apreq_cookie_bake2(const apreq_cookie_t *c,
void *env)
{
- char *s = apreq_cookie_as_string(apreq_env_pool(env),c);
+ char *s = apreq_cookie_as_string(c,apreq_env_pool(env));
if ( s == NULL ) {
apreq_log(APREQ_ERROR APR_ENAMETOOLONG, env,
- "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d",
- APREQ_COOKIE_LENGTH);
+ "Serialized cookie exceeds APREQ_COOKIE_MAX_LENGTH = %d",
+ APREQ_COOKIE_MAX_LENGTH);
return APR_ENAMETOOLONG;
}
else if ( c->version == NETSCAPE ) {
1.22 +45 -19 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- apreq_cookie.h 4 Jun 2004 22:02:11 -0000 1.21
+++ apreq_cookie.h 9 Jun 2004 21:02:05 -0000 1.22
@@ -42,10 +42,26 @@
void *env; /**< environment */
} apreq_jar_t;
-typedef enum { NETSCAPE, RFC } apreq_cookie_version_t;
-#define APREQ_COOKIE_VERSION NETSCAPE
-#define APREQ_COOKIE_LENGTH 4096
+/**
+ * Cookie Version. libapreq does not distinguish between
+ * rfc2109 and its successor rfc2965; both are referred to
+ * as APREQ_COOKIE_VERSION_RFC. Users can distinguish between
+ * them in their outgoing cookies by using apreq_cookie_bake()
+ * for sending rfc2109 cookies, or apreq_cookie_bake2() for rfc2965.
+ * The original Netscape cookie spec is still preferred for its
+ * greater portability, it is named APREQ_COOKIE_VERSION_NETSCAPE.
+ *
+ */
+typedef enum { APREQ_COOKIE_VERSION_NETSCAPE,
+ APREQ_COOKIE_VERSION_RFC } apreq_cookie_version_t;
+
+
+/** Default version, used when creating a new cookie. See
apreq_cookie_make().*/
+#define APREQ_COOKIE_VERSION_DEFAULT APREQ_COOKIE_VERSION_NETSCAPE
+
+/** Maximum length of a single Set-Cookie(2) header */
+#define APREQ_COOKIE_MAX_LENGTH 4096
/** cookie XXX ... */
typedef struct apreq_cookie_t {
@@ -90,9 +106,11 @@
* @param c The cookie to add.
*/
-APREQ_DECLARE(void) apreq_add_cookie(apreq_jar_t *jar,
+APREQ_DECLARE(void) apreq_jar_add(apreq_jar_t *jar,
const apreq_cookie_t *c);
+#define apreq_add_cookie(j,c) apreq_jar_add(j,c)
+
/**
* Parse the incoming "Cookie:" headers into a cookie jar.
*
@@ -113,18 +131,19 @@
/**
* Returns a new cookie, made from the argument list.
- * The cookie is allocated from the ctx pool.
*
- * @param ctx The current context.
+ * @param pool Pool which allocates the cookie.
* @param name The cookie's name.
* @param nlen Length of name.
* @param value The cookie's value.
* @param vlen Length of value.
*/
-APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(apr_pool_t *pool,
+APREQ_DECLARE(apreq_cookie_t *) apreq_cookie_make(apr_pool_t *pool,
const char *name, const apr_size_t nlen,
const char *value, const apr_size_t vlen);
+#define apreq_make_cookie(p,n,nl,v,vl) apreq_cookie_make(p,n,nl,v,vl)
+
/**
* Sets the associated cookie attribute.
* @param p Pool for allocating the new attribute.
@@ -149,8 +168,9 @@
* @param c The cookie.
* @param p The pool.
*/
-APREQ_DECLARE(char*) apreq_cookie_as_string(apr_pool_t *p,
- const apreq_cookie_t *c);
+APREQ_DECLARE(char*) apreq_cookie_as_string(const apreq_cookie_t *c,
+ apr_pool_t *p);
+
/**
* Same functionality as apreq_cookie_as_string. Stores the string
@@ -163,18 +183,21 @@
* @param len Size of buf's storage area.
*/
-APREQ_DECLARE(int) apreq_serialize_cookie(char *buf, apr_size_t len,
- const apreq_cookie_t *c);
+APREQ_DECLARE(int) apreq_cookie_serialize(const apreq_cookie_t *c,
+ char *buf, apr_size_t len);
+
+#define apreq_serialize_cookie(buf,len,c) apreq_cookie_serialize(c,buf,len)
/**
- * Get/set the "expires" string. For NETSCAPE cookies, this returns
- * the date (properly formatted) when the cookie is to expire.
- * For RFC cookies, this function returns NULL.
+ * Set the Cookie's expiration date.
*
* @param c The cookie.
- * @param time_str If NULL, return the current expiry date. Otherwise
- * replace with this value instead. The time_str should be in a format
- * that apreq_atoi64t() can understand, namely /[+-]?\d+\s*[YMDhms]/.
+ * @param time_str If NULL, the Cookie's expiration date is unset,
+ * making it a session cookie. This means no "expires" or "max-age"
+ * attribute will appear in the cookie's serialized form. If time_str
+ * is not NULL, the expiration date will be reset to the offset (from now)
+ * represented by time_str. The time_str should be in a format that
+ * apreq_atoi64t() can understand, namely /[+-]?\d+\s*[YMDhms]/.
*/
APREQ_DECLARE(void) apreq_cookie_expires(apreq_cookie_t *c,
const char *time_str);
@@ -198,8 +221,11 @@
void *env);
/**
- *
- *
+ * Looks for the presence of a "Cookie2" header to determine whether
+ * or not the current User-Agent supports rfc2965.
+ * @param env The current environment.
+ * @return APREQ_COOKIE_VERSION_RFC if rfc2965 is supported,
+ * APREQ_COOKIE_VERSION_NETSCAPE otherwise.
*/
APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(void *env);
1.10 +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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apreq_version.h 4 Jun 2004 22:02:11 -0000 1.9
+++ apreq_version.h 9 Jun 2004 21:02:05 -0000 1.10
@@ -60,7 +60,7 @@
#define APREQ_MINOR_VERSION 0
/** patch level */
-#define APREQ_PATCH_VERSION 6
+#define APREQ_PATCH_VERSION 7
/**
* This symbol is defined for internal, "development" copies of libapreq.
1.8 +10 -10 httpd-apreq-2/t/cookie.c
Index: cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/cookie.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- cookie.c 28 Feb 2004 07:48:15 -0000 1.7
+++ cookie.c 9 Jun 2004 21:02:05 -0000 1.8
@@ -56,24 +56,24 @@
static void netscape_cookie(CuTest *tc)
{
apreq_cookie_t *c;
- apreq_cookie_version_t version = NETSCAPE;
+ apreq_cookie_version_t version = APREQ_COOKIE_VERSION_NETSCAPE;
c = apreq_cookie(j,"foo");
CuAssertStrEquals(tc,"bar",apreq_cookie_value(c));
CuAssertIntEquals(tc, version,c->version);
- CuAssertStrEquals(tc,"foo=bar", apreq_cookie_as_string(p,c));
+ CuAssertStrEquals(tc,"foo=bar", apreq_cookie_as_string(c,p));
c->domain = apr_pstrdup(p, "example.com");
CuAssertStrEquals(tc,"foo=bar; domain=example.com",
- apreq_cookie_as_string(p,c));
+ apreq_cookie_as_string(c,p));
c->path = apr_pstrdup(p, "/quux");
CuAssertStrEquals(tc, "foo=bar; path=/quux; domain=example.com",
- apreq_cookie_as_string(p,c));
+ apreq_cookie_as_string(c,p));
apreq_cookie_expires(c, "+1y");
CuAssertStrEquals(tc,apr_pstrcat(p,
"foo=bar; path=/quux; domain=example.com;
expires=",
- apreq_expires(p,"+1y",NSCOOKIE), NULL),
apreq_cookie_as_string(p,c));
+ apreq_expires(p,"+1y",NSCOOKIE), NULL),
apreq_cookie_as_string(c,p));
}
@@ -83,23 +83,23 @@
long expires;
CuAssertStrEquals(tc,"out",apreq_cookie_value(c));
- c->version = RFC;
+ c->version = APREQ_COOKIE_VERSION_RFC;
- CuAssertStrEquals(tc,"rfc=out; Version=1", apreq_cookie_as_string(p,c));
+ CuAssertStrEquals(tc,"rfc=out; Version=1", apreq_cookie_as_string(c,p));
c->domain = apr_pstrdup(p, "example.com");
CuAssertStrEquals(tc,"rfc=out; Version=1; domain=example.com",
- apreq_cookie_as_string(p,c));
+ apreq_cookie_as_string(c,p));
c->path = apr_pstrdup(p, "/quux");
CuAssertStrEquals(tc,
"rfc=out; Version=1; path=/quux; domain=example.com",
- apreq_cookie_as_string(p,c));
+ apreq_cookie_as_string(c,p));
apreq_cookie_expires(c, "+3m");
expires = apreq_atoi64t("+3m");
CuAssertStrEquals(tc,apr_psprintf(p,
"rfc=out; Version=1; path=/quux; domain=example.com; max-age=%ld",
- expires), apreq_cookie_as_string(p,c));
+ expires), apreq_cookie_as_string(c,p));
}