-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Conversation
Please add an entry in UPGRADING |
Added UPGRADING entry |
FYI (I'm not sure you are aware of this): you can use |
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 :) |
d6ed080
to
25b8c1b
Compare
There was a problem hiding this 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
You'll also need to free |
25b8c1b
to
40ab8cc
Compare
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. |
@nielsdos I'll have a look later this weekend. |
ext/curl/interface.c
Outdated
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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 TypeError
s are used for return values, why ValueError
s shouldn't... So I'm uncertain at this point.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"?
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. :) |
(rebase needed apparently) |
Rebased. |
With the feature freeze creeping closer, I think I should finish this. |
Let's switch the exception thrown to |
* Fix callback in test * Use appropriate error types * Check for long type * Get rid of else branch
Fixes GH-10454