-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/curl: Refactor cURL to only use FCC #13291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8aa8c07
854257f
85d1820
d3fb21c
1dfce9d
cf9228f
c3f60a2
51c8e21
fd4fafd
b9731c8
0994ee2
617b186
e8391d4
4b7230b
431d24a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
TODO Tests for multi handler
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,51 +372,36 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea | |
php_curl *parent; | ||
php_curlm *mh = (php_curlm *)userp; | ||
size_t rval = CURL_PUSH_DENY; | ||
php_curl_callback *t = mh->handlers.server_push; | ||
zval *pz_parent_ch = NULL; | ||
zval pz_ch; | ||
zval headers; | ||
zval retval; | ||
char *header; | ||
zend_result error; | ||
zend_fcall_info fci = empty_fcall_info; | ||
|
||
pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch); | ||
if (pz_parent_ch == NULL) { | ||
return rval; | ||
} | ||
|
||
if (UNEXPECTED(zend_fcall_info_init(&t->func_name, 0, &fci, &t->fci_cache, NULL, NULL) == FAILURE)) { | ||
php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION"); | ||
return rval; | ||
} | ||
|
||
parent = Z_CURL_P(pz_parent_ch); | ||
|
||
ch = init_curl_handle_into_zval(&pz_ch); | ||
ch->cp = easy; | ||
_php_setup_easy_copy_handlers(ch, parent); | ||
|
||
size_t i; | ||
array_init(&headers); | ||
for(i=0; i<num_headers; i++) { | ||
for (size_t i = 0; i < num_headers; i++) { | ||
char *header; | ||
header = curl_pushheader_bynum(push_headers, i); | ||
add_next_index_string(&headers, header); | ||
} | ||
|
||
ZEND_ASSERT(pz_parent_ch); | ||
zval call_args[3] = {*pz_parent_ch, pz_ch, headers}; | ||
|
||
fci.param_count = 3; | ||
fci.params = call_args; | ||
fci.retval = &retval; | ||
|
||
error = zend_call_function(&fci, &t->fci_cache); | ||
zend_call_known_fcc(&mh->handlers.server_push, &retval, /* param_count */ 3, call_args, /* named_params */ NULL); | ||
zval_ptr_dtor_nogc(&headers); | ||
|
||
if (error == FAILURE) { | ||
php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION"); | ||
} else if (!Z_ISUNDEF(retval)) { | ||
if (!Z_ISUNDEF(retval)) { | ||
if (CURL_PUSH_DENY != zval_get_long(&retval)) { | ||
rval = CURL_PUSH_OK; | ||
zend_llist_add_element(&mh->easyh, &pz_ch); | ||
|
@@ -458,21 +443,29 @@ static bool _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue | |
error = curl_multi_setopt(mh->multi, option, lval); | ||
break; | ||
} | ||
case CURLMOPT_PUSHFUNCTION: | ||
if (mh->handlers.server_push == NULL) { | ||
mh->handlers.server_push = ecalloc(1, sizeof(php_curl_callback)); | ||
} else if (!Z_ISUNDEF(mh->handlers.server_push->func_name)) { | ||
zval_ptr_dtor(&mh->handlers.server_push->func_name); | ||
mh->handlers.server_push->fci_cache = empty_fcall_info_cache; | ||
case CURLMOPT_PUSHFUNCTION: { | ||
/* See php_curl_set_callable_handler */ | ||
if (ZEND_FCC_INITIALIZED(mh->handlers.server_push)) { | ||
zend_fcc_dtor(&mh->handlers.server_push); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be set to the empty fcc? |
||
} | ||
|
||
ZVAL_COPY(&mh->handlers.server_push->func_name, zvalue); | ||
char *error_str = NULL; | ||
if (UNEXPECTED(!zend_is_callable_ex(zvalue, /* object */ NULL, /* check_flags */ 0, /* callable_name */ NULL, &mh->handlers.server_push, /* error */ &error_str))) { | ||
if (!EG(exception)) { | ||
zend_argument_type_error(2, "must be a valid callback for option CURLMOPT_PUSHFUNCTION, %s", error_str); | ||
} | ||
efree(error_str); | ||
return false; | ||
} | ||
zend_fcc_addref(&mh->handlers.server_push); | ||
|
||
error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHFUNCTION, _php_server_push_callback); | ||
if (error != CURLM_OK) { | ||
return false; | ||
} | ||
error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh); | ||
break; | ||
} | ||
default: | ||
zend_argument_value_error(2, "is not a valid cURL multi option"); | ||
error = CURLM_UNKNOWN_OPTION; | ||
|
@@ -548,9 +541,9 @@ static void curl_multi_free_obj(zend_object *object) | |
|
||
curl_multi_cleanup(mh->multi); | ||
zend_llist_clean(&mh->easyh); | ||
if (mh->handlers.server_push) { | ||
zval_ptr_dtor(&mh->handlers.server_push->func_name); | ||
efree(mh->handlers.server_push); | ||
|
||
if (ZEND_FCC_INITIALIZED(mh->handlers.server_push)) { | ||
zend_fcc_dtor(&mh->handlers.server_push); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other places you set it then to the empty fcc, did you forget to do that here? |
||
} | ||
|
||
zend_object_std_dtor(&mh->std); | ||
|
@@ -562,8 +555,8 @@ static HashTable *curl_multi_get_gc(zend_object *object, zval **table, int *n) | |
|
||
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create(); | ||
|
||
if (curl_multi->handlers.server_push) { | ||
zend_get_gc_buffer_add_zval(gc_buffer, &curl_multi->handlers.server_push->func_name); | ||
if (ZEND_FCC_INITIALIZED(curl_multi->handlers.server_push)) { | ||
zend_get_gc_buffer_add_fcc(gc_buffer, &curl_multi->handlers.server_push); | ||
} | ||
|
||
zend_llist_position pos; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
Test curl_multi_setopt() with options that take callabes | ||
--EXTENSIONS-- | ||
curl | ||
--FILE-- | ||
<?php | ||
|
||
$mh = curl_multi_init(); | ||
try { | ||
var_dump(curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, 'undefined')); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
TypeError: curl_multi_setopt(): Argument #2 ($option) must be a valid callback for option CURLMOPT_PUSHFUNCTION, function "undefined" not found or invalid function name |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.