Skip to content

ext/curl: Various minor clean-up refactorings #18042

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

Merged
merged 1 commit into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
{
php_curl *ch = (php_curl *)ctx;
php_curl_read *read_handler = ch->handlers.read;
int length = 0;
size_t length = 0;

switch (read_handler->method) {
case PHP_CURL_DIRECT:
Expand Down Expand Up @@ -1184,15 +1184,14 @@ static void create_certinfo(struct curl_certinfo *ci, zval *listcode)

array_init(&certhash);
for (slist = ci->certinfo[i]; slist; slist = slist->next) {
int len;
char s[64];
char *tmp;
strncpy(s, slist->data, sizeof(s));
s[sizeof(s)-1] = '\0';
tmp = memchr(s, ':', sizeof(s));
if(tmp) {
*tmp = '\0';
len = strlen(s);
size_t len = strlen(s);
add_assoc_string(&certhash, s, &slist->data[len+1]);
} else {
php_error_docref(NULL, E_WARNING, "Could not extract hash key from certificate info");
Expand Down Expand Up @@ -1445,7 +1444,6 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
zval *prop, rv;
char *type = NULL, *filename = NULL;
struct mime_data_cb_arg *cb_arg;
php_stream *stream;
php_stream_statbuf ssb;
size_t filesize = -1;
curl_seek_callback seekfunc = seek_cb;
Expand Down Expand Up @@ -1475,6 +1473,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
zval_ptr_dtor(&ch->postfields);
ZVAL_COPY(&ch->postfields, zpostfields);

php_stream *stream;
if ((stream = php_stream_open_wrapper(ZSTR_VAL(postval), "rb", STREAM_MUST_SEEK, NULL))) {
if (!stream->readfilters.head && !php_stream_stat(stream, &ssb)) {
filesize = ssb.sb.st_size;
Expand Down Expand Up @@ -2409,7 +2408,7 @@ PHP_FUNCTION(curl_setopt_array)
ch = Z_CURL_P(zid);

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
if (string_key) {
if (UNEXPECTED(string_key)) {
zend_argument_value_error(2, "contains an invalid cURL option");
RETURN_THROWS();
}
Expand Down
8 changes: 2 additions & 6 deletions ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea
php_curl *ch;
php_curl *parent;
php_curlm *mh = (php_curlm *)userp;
size_t rval = CURL_PUSH_DENY;
int rval = CURL_PUSH_DENY;
zval *pz_parent_ch = NULL;
zval pz_ch;
zval headers;
Expand Down Expand Up @@ -524,11 +524,7 @@ PHP_FUNCTION(curl_multi_setopt)

mh = Z_CURL_MULTI_P(z_mh);

if (_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(_php_curl_multi_setopt(mh, options, zvalue, return_value));
}
/* }}} */

Expand Down
8 changes: 2 additions & 6 deletions ext/curl/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PHP_FUNCTION(curl_share_close)
}
/* }}} */

static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, const zval *zvalue) /* {{{ */
{
CURLSHcode error = CURLSHE_OK;

Expand Down Expand Up @@ -91,11 +91,7 @@ PHP_FUNCTION(curl_share_setopt)

sh = Z_CURL_SHARE_P(z_sh);

if (_php_curl_share_setopt(sh, options, zvalue, return_value)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_BOOL(_php_curl_share_setopt(sh, options, zvalue));
}
/* }}} */

Expand Down
Loading