Jump to content

libcURL UDF - the multiprotocol file transfer library


smartee
 Share

Recommended Posts

On 4/8/2021 at 11:11 AM, KnutJ said:

i cannot figure out which value / BitMask i have to set for LibCurl to understand waht i want. was unable to find the original "option to bitmask" thingy in the UDF and/or http://curl.se

You can find any and all of the option values in the curl.h source file.  If you do a search of the curl.h file for "CURLSSLOPT_NATIVE_CA", you will see that it is defined as:

#define CURLSSLOPT_NATIVE_CA (1<<4)

That would translate to AutoIt as:

Const $CURLSSLOPT_NATIVE_CA = BitShift(1, -4)

 

A simple script will show you that the value is:

Const $CURLSSLOPT_NATIVE_CA = BitShift(1, -4)

ConsoleWrite("Decimal = " & $CURLSSLOPT_NATIVE_CA & @CRLF)
ConsoleWrite("Hex     = " & StringFormat("0x%x", $CURLSSLOPT_NATIVE_CA)  & @CRLF)

Console:

Decimal = 16
Hex     = 0x10

 

Edited by TheXman
Link to comment
Share on other sites

Thank you TheXman,

i am not that good in finding / reading C-header-Information -> therefore wasn't able to retrieve the Info and translate it to AutoIt.
If i understand that correctly: Adding the Constant to the correct UDF i should be able to set the easy curl option by use of the constant when using the current .dll provided by the original LibcURL.dll ?

This is what i am going to try - and report here - as soon as I got the time to do so.

Thanks a ton !

rsRVpv.gif

Link to comment
Share on other sites

9 hours ago, KnutJ said:

If i understand that correctly: Adding the Constant to the correct UDF i should be able to set the easy curl option by use of the constant when using the current .dll provided by the original LibcURL.dll ?

I'm not sure what you mean by "when using the current .dll provided by the original LibcURL.dll".  If the libcurl.dll that you are referring to is v7.71.0 or above and it was built to use OpenSSL, then yes.

Edited by TheXman
Link to comment
Share on other sites

  • 2 months later...
Func _curl_easy_setopt($handle, $option, $parameter)
    If $g_hDll_libcurl == -1 Then Return SetError(1, @extended, -1)
    Local $asTypes[4] = ["long", "ptr", "ptr", "int64"]
    If IsString($parameter) Then ; ..ok, it's a string. But it only takes the string from a pointer. Ok, let's make one.
        Local $tCURLSTRUCTstr = DllStructCreate("char[" & StringLen($parameter) + 1 & "]")
        DllStructSetData($tCURLSTRUCTstr, 1, $parameter)
        $parameter = DllStructGetPtr($tCURLSTRUCTstr)
    EndIf
    Local $aRes = DllCall($g_hDll_libcurl, "int:cdecl", "curl_easy_setopt", "ptr", $handle, "int", $option, $asTypes[Int($option / 10000)], $parameter)
    If @error Then Return SetError(2, @extended, -1)
    Return $aRes[0]
EndFunc   ;==>_curl_easy_setopt

..so many years and only now I decide to use this UDF. Shame on me. This is awesome.
But like many starting to use this UDF, I too scratched my head asking my self: "self, how do we pass a string ???". Well, search and read prior solutions, even the supplied help file if needed. 

After finding the solution I thought that changing the function a tiny bit would make it simpler to use, so, with this version you can pass a string to it if that is what is needed.

PS: I know nothing, nothing I said !. I hope this helps. 

PS2: I also changed:

Func _curl_easy_init($sDllFullpath = "libcurl.dll")
    If $g_hDll_libcurl == -1 Then __cURL_DllOpen($sDllFullpath)
    If $g_hDll_libcurl == -1 Then Return SetError(1, @extended, -1)
    Local $aRes = DllCall($g_hDll_libcurl, "ptr:cdecl", "curl_easy_init")
    If @error Then Return SetError(2, @extended, -1)
    Return $aRes[0]
EndFunc   ;==>_curl_easy_init
Func __cURL_DllOpen($sDllFullpath = "libcurl.dll")
    If $g_hDll_libcurl <> -1 Then Return SetError(0, 1, 1)
    $g_hDll_libcurl = DllOpen($sDllFullpath)
    If $g_hDll_libcurl == -1 Then Return SetError(1, @extended, 0)
    OnAutoItExitRegister("__cURL_DllClose")
    Return 1
EndFunc   ;==>__cURL_DllOpen

that way one can tell the function where to find the DLL.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...