embeddedmz / ftpclient-cpp

C++ client for making FTP requests
MIT License
211 stars 67 forks source link

Added support for specifying the user and password for the proxy server #32

Closed ksv87 closed 2 years ago

ksv87 commented 2 years ago

CURLOPT_PROXYUSERPWD is used

embeddedmz commented 2 years ago

Thank you for your PR. I will review it as soon as possible.

embeddedmz commented 2 years ago

@ksv87 In the method SetProxyUserPwd, can you please remove this line

if (strProxyUserPwd.empty()) return;

because if someone wants to clear the proxy credentials string, he will have no other way to do it than to create a new FTPClient object.

And in "FTPClient.cpp", line 904 can you please add a white space between the if and the condition.

Finally please add a call to ".c_str()" in front of "m_strproxyUserPwd" on the instruction located at line 905 because it is a nasty bug in C (since we call a C function) : the third argument of curl_easy_setopt is a variable argument list (like the second argument in "printf" function) and if you give it a C++ object or any other variable which type is not expected by the function, the behavior is undefined (beware with this function of curl because if the 3rd parameter type doesn't match to the variable expected by the constant defined as the 2nd parameter, you will also have undefined behavior : crashes, memory corruption etc...).

If you look at the documentation https://curl.se/libcurl/c/CURLOPT_PROXYUSERPWD.html you will see that the option "CURLOPT_PROXYUSERPWD" requires a "char*" as a paramter of the argument list. The C/C++ compiler cannot help because of the nature of the C variable arugment lists : the type can only be known at runtime (search for "how variable argument works in c" if you want to have more infos on that subject, when working with argument list on C or C++ projects, great care must be taken because the compiler won't help you. In C++ there are variadic templates but they are not easy to use and as C you can't rely on them to do stuff that depends on infos only known at runtime. In C# you have also variable argument lists but unlike C you will have an exception that will be thrown in case of error which is better).

ksv87 commented 2 years ago

thanks for the feedback. I have followed your recommendations.