Skip to content
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

Add new curl constants from curl > 7.80 #10459

Merged
merged 12 commits into from
Jul 17, 2023
Merged

Conversation

nielsdos
Copy link
Member

Fixes GH-10454

@Girgias
Copy link
Member

Girgias commented Jan 27, 2023

Please add an entry in UPGRADING

@nielsdos
Copy link
Member Author

Added UPGRADING entry

UPGRADING Show resolved Hide resolved
@kocsismate kocsismate self-requested a review January 31, 2023 21:18
@kocsismate
Copy link
Member

FYI (I'm not sure you are aware of this): you can use php ./ext/curl/sync-constants.php to search for missing constants :)

@nielsdos
Copy link
Member Author

FYI (I'm not sure you are aware of this): you can use php ./ext/curl/sync-constants.php to search for missing constants :)

Thanks! I wasn't aware, I'm quite new to this part of PHP, I wanted to learn more about this part. I have some implementation work to do it seems, especially regarding that ssh host key function callback :)

Copy link
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but waiting @kocsismate green light on this

UPGRADING Outdated Show resolved Hide resolved
ext/curl/interface.c Show resolved Hide resolved
ext/curl/interface.c Outdated Show resolved Hide resolved
ext/curl/curl.stub.php Show resolved Hide resolved
ext/curl/curl.stub.php Show resolved Hide resolved
ext/curl/interface.c Outdated Show resolved Hide resolved
ext/curl/tests/curl_basic_026.phpt Outdated Show resolved Hide resolved
ext/curl/tests/curl_basic_026.phpt Outdated Show resolved Hide resolved
ext/curl/tests/curl_basic_026.phpt Outdated Show resolved Hide resolved
ext/curl/tests/curl_basic_026.phpt Outdated Show resolved Hide resolved
ext/curl/interface.c Show resolved Hide resolved
ext/curl/interface.c Outdated Show resolved Hide resolved
@adoy
Copy link
Member

adoy commented Feb 16, 2023

You'll also need to free ch->handlers.sshhostkey in _php_curl_reset_handlers, copy it in _php_setup_easy_copy_handlers, and also add handling in curl_get_gc.

@nielsdos
Copy link
Member Author

Thanks for the reviews. I pushed fixes (as separate commits to more easily make it reviewable), and I've also pushed a small cleanup commit because I was touching that code anyway.
One thing is uncertain for me: and that's the exception being thrown in the ssh hostkey function callback. I'm not sure if that's correct and I also don't know how to test that properly. Any pointers are appreciated, thanks :)

@adoy
Copy link
Member

adoy commented Feb 18, 2023

@nielsdos I'll have a look later this weekend.

ext/curl/tests/curl_basic_027.phpt Outdated Show resolved Hide resolved
ext/curl/interface.c Outdated Show resolved Hide resolved
if (retval_long == CURLKHMATCH_OK || retval_long == CURLKHMATCH_MISMATCH) {
rval = retval_long;
} else {
zend_value_error("The CURLOPT_SSH_HOSTKEYFUNCTION callback must return either CURLKHMATCH_OK or CURLKHMATCH_MISMATCH");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure a zend_value_error is allowed for a return value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I was wondering that too. My gut feeling says no. kocsismate talked about the requirements of the function and that is why I added the exception. Since the function only allows two possible return values I wonder what we should do if something is returned that isn't one of the allowed values...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the curl code and it looks like this :

rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp, keytype, remotekey, keylen);
if(rc!= CURLKHMATCH_OK) {

We could send a E_WARNING to the user saying that the return code was not one of the two allowed and that CURLKHMATCH_MISMATCH will be used. What do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sounds good. Thanks for the help.
I'll do that when I have time :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ValueError always refers to arguments, not return values. A simple TypeError or Error should be thrown instead. I don't like triggering a warning, because it's a programmatic error if an invalid value is returned, and we do not have to respect BC here. So let's be strict

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK got it! In case it's not a long, I'll use a TypeError. If it's a long but not one of the allowed values I'll use an Error (because the type is right this time).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I did some quick investigation, and I found one example where ValueError refers to a property (zend_value_error("SNMP::$max_oids must be greater than 0 or null");). But otherwise I couldn't find any example where a ValueError doesn't refer to arguments. However, if we think through... If TypeErrors are used for return values, why ValueErrors shouldn't... So I'm uncertain at this point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ValueError for a return value would be in violation of the documentation though:

A ValueError is thrown when the type of an argument is correct but the value of it is incorrect.

From: https://www.php.net/manual/en/class.valueerror.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah,I saw it, but in this case, the manual should be adjusted to the code :) btw I don't mind much what exception we end up with. cc @Girgias Do you have any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooops very late reply, I think a ValueError makes sense, and amend the documentation.
The other solution would be to make those cURL constants an Enum and enforce that return type but that sounds maybe like overengineering, especially if the enum values might get changed.

But possibly the one where a value of a different type is returned should use the more standard type error message, instead of the "must return X or Y"?

ext/curl/interface.c Outdated Show resolved Hide resolved
@nielsdos
Copy link
Member Author

Thanks for the review, I pushed the review fixes in a separate commit instead of force-pushing my changes for easier review. I can rebase when you want me to. :)

ext/curl/interface.c Outdated Show resolved Hide resolved
ext/curl/interface.c Outdated Show resolved Hide resolved
@nicolas-grekas
Copy link
Contributor

(rebase needed apparently)

@nielsdos
Copy link
Member Author

(rebase needed apparently)

Rebased.

@nielsdos
Copy link
Member Author

With the feature freeze creeping closer, I think I should finish this.
This was reviewed a whole while back, but that was before there were many new changes done to the code in response to review comments.
There's also the discussion that ended here: #10459 (comment) about the error type. What do we do with that?

@Girgias
Copy link
Member

Girgias commented Jul 16, 2023

With the feature freeze creeping closer, I think I should finish this. This was reviewed a whole while back, but that was before there were many new changes done to the code in response to review comments. There's also the discussion that ended here: #10459 (comment) about the error type. What do we do with that?

Let's switch the exception thrown to Error as this means we can always just change the type later on as it will be a subtype. Other than that I think good to ship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for CURLOPT_QUICK_EXIT
6 participants