list->path = NULL;
list->domain = NULL;
list->expires = -1;
+ list->max_age = -1;
list->flags = 0;
TSRMLS_SET_CTX(list->ts);
STR_SET(to->path, from->path ? estrdup(from->path) : NULL);
STR_SET(to->domain, from->domain ? estrdup(from->domain) : NULL);
to->expires = from->expires;
+ to->max_age = from->max_age;
to->flags = from->flags;
return to;
char *date = estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg));
list->expires = php_parse_date(date, NULL);
efree(date);
+ } else if _KEY_IS("max-age") {
+ list->max_age = strtol(Z_STRVAL_P(arg), NULL, 10);
} else if _KEY_IS("secure") {
list->flags |= PHP_HTTP_COOKIE_SECURE;
} else if _KEY_IS("httpOnly") {
add_assoc_long(&array, "flags", list->flags);
add_assoc_long(&array, "expires", (long) list->expires);
+ add_assoc_long(&array, "max-age", (long) list->max_age);
add_assoc_string(&array, "path", STR_PTR(list->path), 1);
add_assoc_string(&array, "domain", STR_PTR(list->domain), 1);
}
zval_ptr_dtor(&cpy);
}
}
+ if (SUCCESS == zend_hash_find(ht, "max-age", sizeof("max-age"), (void *) &tmp)) {
+ if (Z_TYPE_PP(tmp) == IS_LONG) {
+ list->max_age = Z_LVAL_PP(tmp);
+ } else {
+ long lval;
+
+ cpy = php_http_ztyp(IS_STRING, *tmp);
+ if (IS_LONG == is_numeric_string(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), &lval, NULL, 0)) {
+ list->max_age = lval;
+ }
+
+ zval_ptr_dtor(&cpy);
+ }
+ }
if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_STRING) {
list->path = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
}
php_http_buffer_appendf(&buf, "expires=%s; ", date);
efree(date);
}
+ if (list->max_age >= 0) {
+ php_http_buffer_appendf(&buf, "max-age=%ld; ", list->max_age);
+ }
FOREACH_HASH_KEYVAL(pos, &list->extras, key, val) {
zval *tmp = php_http_ztyp(IS_STRING, *val);
PHP_HTTP_EMPTY_ARGS(getDomain);
PHP_HTTP_EMPTY_ARGS(getPath);
PHP_HTTP_EMPTY_ARGS(getExpires);
+PHP_HTTP_EMPTY_ARGS(getMaxAge);
PHP_HTTP_EMPTY_ARGS(getFlags);
PHP_HTTP_EMPTY_ARGS(toString);
PHP_HTTP_BEGIN_ARGS(setExpires, 0)
PHP_HTTP_ARG_VAL(value, 0)
PHP_HTTP_END_ARGS;
+PHP_HTTP_BEGIN_ARGS(setMaxAge, 0)
+ PHP_HTTP_ARG_VAL(value, 0)
+PHP_HTTP_END_ARGS;
PHP_HTTP_BEGIN_ARGS(setFlags, 0)
PHP_HTTP_ARG_VAL(value, 0)
PHP_HTTP_END_ARGS;
PHP_HTTP_COOKIE_ME(setPath, ZEND_ACC_PUBLIC)
PHP_HTTP_COOKIE_ME(getExpires, ZEND_ACC_PUBLIC)
PHP_HTTP_COOKIE_ME(setExpires, ZEND_ACC_PUBLIC)
+ PHP_HTTP_COOKIE_ME(getMaxAge, ZEND_ACC_PUBLIC)
+ PHP_HTTP_COOKIE_ME(setMaxAge, ZEND_ACC_PUBLIC)
PHP_HTTP_COOKIE_ME(getFlags, ZEND_ACC_PUBLIC)
PHP_HTTP_COOKIE_ME(setFlags, ZEND_ACC_PUBLIC)
RETVAL_ZVAL(getThis(), 1, 0);
}
+PHP_METHOD(HttpCookie, getMaxAge)
+{
+ if (SUCCESS == zend_parse_parameters_none()) {
+ php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ RETURN_LONG(obj->list->max_age);
+ }
+ RETURN_FALSE;
+}
+
+PHP_METHOD(HttpCookie, setMaxAge)
+{
+ long ts = -1;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts)) {
+ php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ obj->list->max_age = ts;
+ }
+ RETVAL_ZVAL(getThis(), 1, 0);
+}
+
PHP_METHOD(HttpCookie, getFlags)
{
if (SUCCESS == zend_parse_parameters_none()) {
"flags" => 0,
"expires" => -1,
"path" => "",
- "domain" => ""
+ "domain" => "",
+ "max-age" => -1,
);
$this->assertEquals($a, $c->toArray());
$this->assertEquals($a, $o->toArray());
foreach (array($orig, $copy) as $c) {
$this->assertEquals("value", $c->getCookie("key"));
$this->assertEquals(-1, $c->getExpires());
+ $this->assertEquals(-1, $c->getMaxAge());
$this->assertEquals(0, $c->getFlags());
$this->assertEquals(null, $c->getPath());
$this->assertEquals(null, $c->getDomain());
"expires" => -1,
"path" => "",
"domain" => "",
+ "max-age" => -1,
),
$c->toArray()
);
);
}
+ function testMaxAge() {
+ $c = new http\Cookie("this=max-age; max-age=12345");
+ $this->assertEquals("max-age", $c->getCookie("this"));
+ $this->assertEquals(12345, $c->getMaxAge());
+ $o = clone $c;
+ $t = 54321;
+ $o->setMaxAge();
+ $this->assertEquals(-1, $o->getMaxAge());
+ $this->assertNotEquals(-1, $c->getMaxAge());
+ $o->setMaxAge($t);
+ $this->assertEquals($t, $o->getMaxAge());
+ $this->assertNotEquals($t, $c->getMaxAge());
+ $this->assertEquals(
+ "this=max-age; max-age=$t; ",
+ $o->toString()
+ );
+ }
+
function testPath() {
$c = new http\Cookie("this=has a path; path=/down; ");
$this->assertEquals("has a path", $c->getCookie("this"));