#1 2019-03-09 17:41:58

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

TCurlHttp access to curl.easy_setopt

Hi Guys,

Are any way to access internal record curl.easy_setopt... ?

I need this to set additional configuration to curl.


Perhaps by putting types and variables (TCurlOption, TCurlResult, curl, ...) in global scope.

Last edited by macfly (2019-03-11 14:42:20)

Offline

#2 2019-03-09 21:16:02

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

@ab, I share the propose. I plane to rewrite LDAP access from Synapse to curl, so also need low level curl definitions in the interface section

Last edited by mpv (2019-03-09 21:17:03)

Offline

#3 2019-03-11 14:41:11

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: TCurlHttp access to curl.easy_setopt

I share the propose with @mpv.

:-)

Offline

#4 2019-03-11 15:30:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TCurlHttp access to curl.easy_setopt

I am preparing to use the "multi" API of libcurl, so publishing low-level API is feasible all together.

Perhaps a separated SynLibCurl or SynCurl unit will be made available.

Offline

#5 2019-03-12 17:19:52

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: TCurlHttp access to curl.easy_setopt

Excellent news.

The idea of creating a unit separates is great.

The implementation of Curl in Mormot is the best that exists for delphi / Lazarus. It deserves a specific unit.

Offline

#6 2019-03-12 17:20:43

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

Great. Separate unit is good idea. SynCtrSock is big enought

Offline

#7 2019-08-28 16:31:47

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

I create a SynCurl unit and move there all curl low level API - see https://github.com/synopse/mORMot/pull/231  (@ab - please, merge if it compiles under Delphi )

Tested on both Windows & Linux with FPC compiler.

We switch to libcurl for accessing LDAP catalogues (instead of synApse 4) - in some catalogue configurations synapse does not work. Now I want to use libclurl for IMAP/POP/SMPT also

Last edited by mpv (2019-08-28 16:32:08)

Offline

#8 2019-09-02 09:36:53

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

@ab, please, can you merge a SynCurl into master? Or give me feedback if something wrong there.
This is just a copy-paste from SynCrtSock so I do not expect any regression.
It's critical for me to have a low level access to libcurl

Last edited by mpv (2019-09-02 09:37:34)

Offline

#9 2019-09-03 10:35:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TCurlHttp access to curl.easy_setopt

I have merged it, with some fixes for Delphi compatibility and mORMot-standard documentation.

See https://synopse.info/fossil/info/7ef7b6d394

Offline

#10 2019-09-03 12:53:23

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 105

Re: TCurlHttp access to curl.easy_setopt

  /// low-level libcurl library file name, depending on the running OS
  LIBCURL_DLL = {$ifdef Darwin} 'libcurl.dylib' {$else}
    {$ifdef Linux} 'libcurl.so' {$else} 'libcurl-x64.dll' {$endif}{$endif};

What about Win32 platform? Is it no longer supported?

Offline

#11 2019-09-03 13:18:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TCurlHttp access to curl.easy_setopt

@Zed
Nice catch.
This was a regression induced by the merge request.

Please check https://synopse.info/fossil/info/0a257a244c

Offline

#12 2019-09-03 13:33:11

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: TCurlHttp access to curl.easy_setopt

Thanks @mpv and @ab.

The ability to use CURL separately is a big feature.

Offline

#13 2019-09-04 09:24:09

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

@ab - thanks!
IMHO one of HUGE advantage of libcurl is diagnostic - calling `curl -v URL` from command line shows all network packages with very human friendly errors. Doing so we catch very unclear errors with certificates and LDAP catalogue configurations

A small code snippet for client authorization using LDAP (verified with very exotic ActiveDirectory configuration where SynApse don't work, also with OpenLDAP). Consider client pass password in base64
LDAP connection string stored in config, example: aLDAPCfg.URL = 'ldaps://mydomain.com:636/DC=mydomain,DC=com?cn?sub?(sAMAccountName=%)'

curlHandle := curl.easy_init;
    curlLdapURL := FormatUTF8(aLDAPCfg.URL, [aUserWODomain]);
    curl.easy_setopt(curlHandle,coURL,pointer(curlLdapURL));
    pwd := UTF8ToString(Base64ToBin(aPassWord));
    if (pwd = '') then begin
      Result := false;
      errReason := FormatUTF8('LDAP anonymous logon attempt for %', [aUserName]);
    end else begin
      curlUserPwd := FormatUTF8('%:%', [aUserName, pwd]);
      curl.easy_setopt(curlHandle, coUserPwd, pointer(curlUserPwd));
      if (aLDAPCfg.ignoreSSLCertificateErrors) then begin
        curl.easy_setopt(curlHandle, coSSLVerifyPeer, 0);
        curl.easy_setopt(curlHandle, coSSLVerifyHost, 0);
      end else if (aLDAPCfg.CAPath <> '') then
        curl.easy_setopt(curlHandle, coCAPath, pointer(aLDAPCfg.CAPath));
      curl.easy_setopt(curlHandle, coWriteFunction, @CurlWriteRawByteString);
      curl.easy_setopt(curlHandle, coFile, @curlRespBody);
      res := curl.easy_perform(curlHandle);
      Result := (res = crOK);
      if not Result then begin
        Result := false;
        errReason := FormatUTF8('LDAP libCurl error #%: %', [ord(res), curl.easy_strerror(res)]);
      end;
    end;
    curl.easy_cleanup(curlHandle);     

Last edited by mpv (2019-09-04 09:27:27)

Offline

#14 2019-09-04 11:39:44

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TCurlHttp access to curl.easy_setopt

Just one fix for FPC Win64 - pull #233

Offline

Board footer

Powered by FluxBB