@@ -97,26 +97,14 @@ static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
97
97
# define php_curl_ret (__ret ) RETVAL_FALSE; return;
98
98
#endif
99
99
100
- static int php_curl_option_str (php_curl * ch , zend_long option , const char * str , const size_t len , zend_bool make_copy )
100
+ static int php_curl_option_str (php_curl * ch , zend_long option , const char * str , const size_t len )
101
101
{
102
- CURLcode error = CURLE_OK ;
103
-
104
102
if (strlen (str ) != len ) {
105
103
zend_value_error ("%s(): cURL option must not contain any null bytes" , get_active_function_name ());
106
104
return FAILURE ;
107
105
}
108
106
109
- if (make_copy ) {
110
- char * copystr ;
111
-
112
- /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */
113
- copystr = estrndup (str , len );
114
- error = curl_easy_setopt (ch -> cp , option , copystr );
115
- zend_llist_add_element (& ch -> to_free -> str , & copystr );
116
- } else {
117
- error = curl_easy_setopt (ch -> cp , option , str );
118
- }
119
-
107
+ CURLcode error = curl_easy_setopt (ch -> cp , option , str );
120
108
SAVE_CURL_ERROR (ch , error );
121
109
122
110
return error == CURLE_OK ? SUCCESS : FAILURE ;
@@ -136,11 +124,11 @@ static int php_curl_option_url(php_curl *ch, const char *url, const size_t len)
136
124
memmove (_tmp , "file:///" , sizeof ("file:///" ) - 1 );
137
125
memmove (_tmp + sizeof ("file:///" ) - 1 , url + sizeof ("file://" ) - 1 , len - sizeof ("file://" ) + 1 );
138
126
139
- return php_curl_option_str (ch , CURLOPT_URL , _tmp , len + 1 , 0 );
127
+ return php_curl_option_str (ch , CURLOPT_URL , _tmp , len + 1 );
140
128
}
141
129
#endif
142
130
143
- return php_curl_option_str (ch , CURLOPT_URL , url , len , 0 );
131
+ return php_curl_option_str (ch , CURLOPT_URL , url , len );
144
132
}
145
133
/* }}} */
146
134
@@ -1291,6 +1279,7 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
1291
1279
#endif
1292
1280
1293
1281
zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .std_err );
1282
+ zend_get_gc_buffer_add_zval (gc_buffer , & curl -> private_data );
1294
1283
1295
1284
zend_get_gc_buffer_use (gc_buffer , table , n );
1296
1285
@@ -1634,13 +1623,6 @@ static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, v
1634
1623
}
1635
1624
/* }}} */
1636
1625
1637
- /* {{{ curl_free_string */
1638
- static void curl_free_string (void * * string )
1639
- {
1640
- efree ((char * )* string );
1641
- }
1642
- /* }}} */
1643
-
1644
1626
/* {{{ curl_free_post */
1645
1627
static void curl_free_post (void * * post )
1646
1628
{
@@ -1755,7 +1737,6 @@ void init_curl_handle(php_curl *ch)
1755
1737
1756
1738
memset (& ch -> err , 0 , sizeof (struct _php_curl_error ));
1757
1739
1758
- zend_llist_init (& ch -> to_free -> str , sizeof (char * ), (llist_dtor_func_t )curl_free_string , 0 );
1759
1740
zend_llist_init (& ch -> to_free -> post , sizeof (struct HttpPost * ), (llist_dtor_func_t )curl_free_post , 0 );
1760
1741
zend_llist_init (& ch -> to_free -> stream , sizeof (struct mime_data_cb_arg * ), (llist_dtor_func_t )curl_free_cb_arg , 0 );
1761
1742
@@ -1925,6 +1906,8 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1925
1906
curl_easy_setopt (ch -> cp , CURLOPT_FNMATCH_DATA , (void * ) ch );
1926
1907
}
1927
1908
1909
+ ZVAL_COPY (& ch -> private_data , & source -> private_data );
1910
+
1928
1911
efree (ch -> to_free -> slist );
1929
1912
efree (ch -> to_free );
1930
1913
ch -> to_free = source -> to_free ;
@@ -2447,7 +2430,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
2447
2430
{
2448
2431
zend_string * tmp_str ;
2449
2432
zend_string * str = zval_get_tmp_string (zvalue , & tmp_str );
2450
- int ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ), 0 );
2433
+ int ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ));
2451
2434
zend_tmp_string_release (tmp_str );
2452
2435
return ret ;
2453
2436
}
@@ -2474,7 +2457,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
2474
2457
} else {
2475
2458
zend_string * tmp_str ;
2476
2459
zend_string * str = zval_get_tmp_string (zvalue , & tmp_str );
2477
- int ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ), 0 );
2460
+ int ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ));
2478
2461
zend_tmp_string_release (tmp_str );
2479
2462
return ret ;
2480
2463
}
@@ -2484,11 +2467,9 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
2484
2467
/* Curl private option */
2485
2468
case CURLOPT_PRIVATE :
2486
2469
{
2487
- zend_string * tmp_str ;
2488
- zend_string * str = zval_get_tmp_string (zvalue , & tmp_str );
2489
- int ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ), 1 );
2490
- zend_tmp_string_release (tmp_str );
2491
- return ret ;
2470
+ zval_ptr_dtor (& ch -> private_data );
2471
+ ZVAL_COPY (& ch -> private_data , zvalue );
2472
+ return SUCCESS ;
2492
2473
}
2493
2474
2494
2475
/* Curl url option */
@@ -2794,7 +2775,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
2794
2775
return FAILURE ;
2795
2776
}
2796
2777
2797
- ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ), 0 );
2778
+ ret = php_curl_option_str (ch , option , ZSTR_VAL (str ), ZSTR_LEN (str ));
2798
2779
zend_tmp_string_release (tmp_str );
2799
2780
return ret ;
2800
2781
}
@@ -3160,6 +3141,13 @@ PHP_FUNCTION(curl_getinfo)
3160
3141
}
3161
3142
break ;
3162
3143
}
3144
+ case CURLINFO_PRIVATE :
3145
+ if (!Z_ISUNDEF (ch -> private_data )) {
3146
+ RETURN_COPY (& ch -> private_data );
3147
+ } else {
3148
+ RETURN_FALSE ;
3149
+ }
3150
+ break ;
3163
3151
default : {
3164
3152
int type = CURLINFO_TYPEMASK & option ;
3165
3153
switch (type ) {
@@ -3323,7 +3311,6 @@ static void curl_free_obj(zend_object *object)
3323
3311
3324
3312
/* cURL destructors should be invoked only by last curl handle */
3325
3313
if (-- (* ch -> clone ) == 0 ) {
3326
- zend_llist_clean (& ch -> to_free -> str );
3327
3314
zend_llist_clean (& ch -> to_free -> post );
3328
3315
zend_llist_clean (& ch -> to_free -> stream );
3329
3316
zend_hash_destroy (ch -> to_free -> slist );
@@ -3360,6 +3347,7 @@ static void curl_free_obj(zend_object *object)
3360
3347
}
3361
3348
3362
3349
zval_ptr_dtor (& ch -> postfields );
3350
+ zval_ptr_dtor (& ch -> private_data );
3363
3351
3364
3352
if (ch -> share ) {
3365
3353
OBJ_RELEASE (& ch -> share -> std );
0 commit comments