X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_cookie.c;h=b767bbbb7e83d974b716ff19ed435068536c9150;hp=36fb1d4859c6e2abae4b0dd4712d330f26d4043c;hb=25f0c16244fc5f8b2c9d9bfddab8a541d2521789;hpb=809cfb73a233ce951274a5951b921d5f5feb6676 diff --git a/php_http_cookie.c b/php_http_cookie.c index 36fb1d4..b767bbb 100644 --- a/php_http_cookie.c +++ b/php_http_cookie.c @@ -136,30 +136,23 @@ 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; - - 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; - } /* check for extra */ if (allowed_extras) { char **ae = allowed_extras; + php_http_array_hashkey_stringify(key); 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 { zend_hash_update(&list->extras, key->str, key->len, (void *) &arg, sizeof(zval *), NULL); } + php_http_array_hashkey_stringfree(key); return; } } + php_http_array_hashkey_stringfree(key); } /* cookie */ @@ -168,7 +161,9 @@ static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long } else { zend_hash_update(&list->cookies, key->str, key->len, (void *) &arg, sizeof(zval *), NULL); } + return; } + zval_ptr_dtor(&arg); } PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras TSRMLS_DC) @@ -306,15 +301,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); } @@ -332,15 +323,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); } @@ -352,8 +339,8 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c } php_http_buffer_fix(&buf); - *str = PHP_HTTP_BUFFER_VAL(&buf); - *len = PHP_HTTP_BUFFER_LEN(&buf); + *str = buf.data; + *len = buf.used; } #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpCookie, method, 0, req_args) @@ -423,8 +410,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) @@ -510,14 +503,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); @@ -558,6 +551,15 @@ PHP_METHOD(HttpCookie, __construct) break; } } + + if (ae) { + char **ae_ptr; + + for (ae_ptr = ae; *ae_ptr; ++ae_ptr) { + efree(*ae_ptr); + } + efree(ae); + } } end_error_handling(); } } @@ -936,7 +938,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;