X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_cookie.c;h=5b78abbe0dd161d9595839f14d88bbff065b47f8;hb=729594cae203b09419d195ec0dabde0430c9f1cd;hp=d46f4146e9f8782ddecfdd6ed14b6bfb8702d00c;hpb=5d94cd9e46b7eb30149b4aebde1aa14fce2ced43;p=m6w6%2Fext-http diff --git a/php_http_cookie.c b/php_http_cookie.c index d46f414..5b78abb 100644 --- a/php_http_cookie.c +++ b/php_http_cookie.c @@ -136,22 +136,15 @@ static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long } else if _KEY_IS("httpOnly") { list->flags |= PHP_HTTP_COOKIE_HTTPONLY; } else { - char buf[0x20], *key_str; - int key_len; + char buf[0x20]; - if (key->type == HASH_KEY_IS_LONG) { - key_len = slprintf(buf, sizeof(buf) - 1, "%ld", key->num) + 1; - key_str = &buf[0]; - } else { - key_len = key->len; - key_str = key->str; - } + php_http_array_hashkey_stringify(key); /* check for extra */ if (allowed_extras) { char **ae = allowed_extras; for (; *ae; ++ae) { - if (!strncasecmp(key_str, *ae, key_len)) { + if (!strncasecmp(key->str, *ae, key->len)) { if (key->type == HASH_KEY_IS_LONG) { zend_hash_index_update(&list->extras, key->num, (void *) &arg, sizeof(zval *), NULL); } else { @@ -161,6 +154,7 @@ static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long } } } + php_http_array_hashkey_stringfree(key); /* cookie */ if (key->type == HASH_KEY_IS_LONG) { @@ -308,15 +302,11 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c FOREACH_HASH_KEYVAL(pos, &list->cookies, key, val) { zval *tmp = php_http_ztyp(IS_STRING, *val); - if (key.type == HASH_KEY_IS_STRING && key.len) { - append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); - } else if (key.type == HASH_KEY_IS_LONG) { - int enc_len; - char *enc_str = php_raw_url_encode(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &enc_len); - php_http_buffer_appendf(&buf, "%ld=%.*s; ", key.num, enc_len, enc_str); - efree(enc_str); - } + php_http_array_hashkey_stringify(&key); + append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); + php_http_array_hashkey_stringfree(&key); + zval_ptr_dtor(&tmp); } @@ -334,15 +324,11 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c FOREACH_HASH_KEYVAL(pos, &list->extras, key, val) { zval *tmp = php_http_ztyp(IS_STRING, *val); - if (key.type == HASH_KEY_IS_STRING && key.len) { - append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); - } else if (key.type == HASH_KEY_IS_LONG) { - int enc_len; - char *enc_str = php_raw_url_encode(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &enc_len); - php_http_buffer_appendf(&buf, "%ld=%.*s; ", key.num, enc_len, enc_str); - efree(enc_str); - } + php_http_array_hashkey_stringify(&key); + append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); + php_http_array_hashkey_stringfree(&key); + zval_ptr_dtor(&tmp); } @@ -425,8 +411,14 @@ PHP_HTTP_BEGIN_ARGS(getExtra, 1) PHP_HTTP_ARG_VAL(name, 0) PHP_HTTP_END_ARGS; -zend_class_entry *php_http_cookie_class_entry; -zend_function_entry php_http_cookie_method_entry[] = { +static zend_class_entry *php_http_cookie_class_entry; + +zend_class_entry *php_http_cookie_get_class_entry(void) +{ + return php_http_cookie_class_entry; +} + +static zend_function_entry php_http_cookie_method_entry[] = { PHP_HTTP_COOKIE_ME(__construct, ZEND_ACC_PUBLIC) PHP_HTTP_COOKIE_ME(getCookies, ZEND_ACC_PUBLIC) PHP_HTTP_COOKIE_ME(setCookies, ZEND_ACC_PUBLIC) @@ -471,7 +463,11 @@ zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_c o = ecalloc(sizeof(*o), 1); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); +#if PHP_VERSION_ID < 50339 + zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else object_properties_init((zend_object *) o, ce); +#endif if (list) { o->list = list; @@ -512,14 +508,14 @@ void php_http_cookie_object_free(void *object TSRMLS_DC) PHP_METHOD(HttpCookie, __construct) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { zval *zcookie = NULL; long flags = 0; HashTable *allowed_extras = NULL; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!lH", &zcookie, &flags, &allowed_extras)) { if (zcookie) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { char **ae = NULL; php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -938,7 +934,7 @@ PHP_METHOD(HttpCookie, toArray) PHP_MINIT_FUNCTION(http_cookie) { - PHP_HTTP_REGISTER_CLASS(http, Cookie, http_cookie, php_http_object_class_entry, 0); + PHP_HTTP_REGISTER_CLASS(http, Cookie, http_cookie, php_http_object_get_class_entry(), 0); php_http_cookie_class_entry->create_object = php_http_cookie_object_new; memcpy(&php_http_cookie_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); php_http_cookie_object_handlers.clone_obj = php_http_cookie_object_clone;