use php_http_array_hashkey_string* where applicable
authorMichael Wallner <mike@php.net>
Thu, 5 Apr 2012 17:33:35 +0000 (17:33 +0000)
committerMichael Wallner <mike@php.net>
Thu, 5 Apr 2012 17:33:35 +0000 (17:33 +0000)
php_http_cookie.c
php_http_curl_client.c

index ef0947ea597d224863d1c4cd09edba79414fb377..6908d386247e4b09de79af5b3e4618beb8887ffe 100644 (file)
@@ -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);
        }
        
index ce47f6b2163fb8caa1be17cdb761fd1104fe14c1..7f4d005377065e3a7e922135732d27305c1ce0ad 100644 (file)
@@ -510,11 +510,13 @@ static STATUS set_options(php_http_client_t *h, HashTable *options)
                                zval **cookie_val;
 
                                FOREACH_KEYVAL(pos, zoption, cookie_key, cookie_val) {
-                                       if (cookie_key.type == HASH_KEY_IS_STRING) {
-                                               zval *val = php_http_ztyp(IS_STRING, *cookie_val);
-                                               php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
-                                               zval_ptr_dtor(&val);
-                                       }
+                                       zval *val = php_http_ztyp(IS_STRING, *cookie_val);
+
+                                       php_http_array_hashkey_stringify(&cookie_key);
+                                       php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
+                                       php_http_array_hashkey_stringfree(&cookie_key);
+
+                                       zval_ptr_dtor(&val);
                                }
 
                                php_http_buffer_fix(&curl->options.cookies);