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

Some culpp options should be defined as this #151

Open
z16166 opened this issue Nov 29, 2022 · 1 comment
Open

Some culpp options should be defined as this #151

z16166 opened this issue Nov 29, 2022 · 1 comment

Comments

@z16166
Copy link

z16166 commented Nov 29, 2022

current definitions of curlpp options:

typedef curlpp::OptionTrait<std::string, CURLOPT_CAINFO> CaInfo;
typedef curlpp::OptionTrait<std::string, CURLOPT_CAPATH> CaPath;
typedef curlpp::OptionTrait<curlpp::types::SslCtxFunctionFunctor, CURLOPT_SSL_CTX_FUNCTION> SslCtxFunction;

But the above is not working if we want to use our own certificates in memory. That is, we want to do the following:
(please refer to https://curl.se/libcurl/c/cacertinmem.html and https://curl.se/libcurl/c/CURLOPT_SSL_CTX_FUNCTION.html)

curl_easy_setopt(ch, CURLOPT_CAINFO, NULL);
curl_easy_setopt(ch, CURLOPT_CAPATH, NULL);
curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);

Why it's not woking? Because NULL pointer is different with empty string, libcurl will report error if you pass it with CaInfo("") and CaPath(""). It just expects NULL pointer, not empty string.

I used the following to do it(be sure all pointers are valid during the life time of curlpp easy handle!):

typedef curlpp::OptionTrait<void *, CURLOPT_SSL_CTX_FUNCTION> SslCtxFunctionOpt;
typedef curlpp::OptionTrait<void *, CURLOPT_CAINFO> CaInfoOpt;
typedef curlpp::OptionTrait<void *, CURLOPT_CAPATH> CaPathOpt;

@sgallou
Copy link
Collaborator

sgallou commented Nov 29, 2022

Hi,

this seems to make sense, as seen by this related curl usage example.
But the solution you suggested changes Curlpp interface, and will break builds of other users.
(For CURLOPT_SSL_CTX_FUNCTION, I'm not sure that curlpp option need modification)

I suggest to add an NullableOptionTrait class and to add 2 news options, like :

typedef curlpp::NullableOptionTrait<std::string, CURLOPT_CAINFO> NullableCaInfoOpt;
typedef curlpp::NullableOptionTrait<std::string, CURLOPT_CAPATH> NullableCaPathOpt;

(declare CaInfoOpt and CaPathOpt as obsoletes)

NullableOptionTrait should be able to manage a null value (add en empty ctor and a reset/clear function).

Il you're OK to achieve this, please create a PR.

Thanks for your help,

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

No branches or pull requests

2 participants