Skip to content
Permalink
Browse files

introducing LIBCURLMULTI conditional

(raw API definition only - not yet used)
  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Mar 4, 2019
1 parent a594176 commit f8cdc9e4840d962713f3825e76635edfc8578799
Showing with 127 additions and 19 deletions.
  1. +1 −1 SynCommons.pas
  2. +116 −13 SynCrtSock.pas
  3. +9 −4 Synopse.inc
  4. +1 −1 SynopseCommit.inc
@@ -7692,7 +7692,7 @@ TTextWriterClass = class of TTextWriter;
TTextWriterOptions = set of TTextWriterOption;

/// may be used to allocate on stack a 8KB work buffer for a TTextWriter
// - via the CreateOwnedStream overloaded constructor
// - via the TTextWriter.CreateOwnedStream overloaded constructor
TTextWriterStackBuffer = array[0..8191] of AnsiChar;

/// simple writer to a Stream, specialized for the TEXT format
@@ -11324,6 +11324,7 @@ function TWinHTTPWebSocketClient.Send(aBufferType: WINHTTP_WEB_SOCKET_BUFFER_TYP
LIBCURL_DLL = {$IFDEF Darwin} 'libcurl.dylib' {$ELSE}
{$IFDEF LINUX} 'libcurl.so' {$ELSE} 'libcurl.dll' {$ENDIF}{$ENDIF};

{$Z4}
type
TCurlOption = (
coPort = 3,
@@ -11480,6 +11481,9 @@ function TWinHTTPWebSocketClient.Send(aBufferType: WINHTTP_WEB_SOCKET_BUFFER_TYP
ciEffectiveURL = 1048577,
ciContentType = 1048594,
ciPrivate = 1048597,
ciRedirectURL = 1048607,
ciPrimaryIP = 1048608,
ciLocalIP = 1048617,
ciResponseCode = 2097154,
ciHeaderSize = 2097163,
ciRequestSize = 2097164,
@@ -11491,6 +11495,8 @@ function TWinHTTPWebSocketClient.Send(aBufferType: WINHTTP_WEB_SOCKET_BUFFER_TYP
ciProxyAuthAvail = 2097176,
ciOS_Errno = 2097177,
ciNumConnects = 2097178,
ciPrimaryPort = 2097192,
ciLocalPort = 2097194,
ciTotalTime = 3145731,
ciNameLookupTime = 3145732,
ciConnectTime = 3145733,
@@ -11503,12 +11509,53 @@ function TWinHTTPWebSocketClient.Send(aBufferType: WINHTTP_WEB_SOCKET_BUFFER_TYP
ciContentLengthUpload = 3145744,
ciStartTransferTime = 3145745,
ciRedirectTime = 3145747,
ciAppConnectTime = 3145761,
ciSSLEngines = 4194331,
ciCookieList = 4194332
ciCookieList = 4194332,
ciCertInfo = 4194338,
ciSizeDownloadT = 6291464,
ciTotalTimeT = 6291506, // (6) can be used for calculation "Content download time"
ciNameLookupTimeT = 6291507, // (1) DNS lookup
ciConnectTimeT = 6291508, // (2) connect time
ciPreTransferTimeT = 6291509, // (4)
ciStartTransferTimeT = 6291510, // (5) Time to first byte
ciAppConnectTimeT = 6291512 // (3) SSL handshake
);
{$ifdef LIBCURLMULTI}
TCurlMultiCode = (
cmcCallMultiPerform = -1,
cmcOK = 0,
cmcBadHandle,
cmcBadEasyHandle,
cmcOutOfMemory,
cmcInternalError,
cmcBadSocket,
cmcUnknownOption,
cmcAddedAlready,
cmcRecursiveApiCall
);
TCurlMultiOption = (
cmoPipeLining = 3,
cmoMaxConnects = 6,
cmoMaxHostConnections = 7,
cmoMaxPipelineLength = 8,
cmoMaxTotalConnections = 13,
cmoSocketData = 10002,
cmoTimerData = 10005,
cmoPipeliningSiteBL = 10011,
cmoPipeliningServerBL = 10012,
cmoPushData = 10015,
cmoSocketFunction = 20001,
cmoTimerFunction = 20004,
cmoPushFunction = 20014,
cmoContentLengthPenaltySize = 30009,
cmoChunkLengthPenaltySize = 30010
);
{$endif LIBCURLMULTI}

TCurlVersion = (cvFirst,cvSecond,cvThird,cvFour);
TCurlGlobalInit = set of (giSSL,giWin32);
TCurlMsg = (cmNone, cmDone);
PAnsiCharArray = array[0..1023] of PAnsiChar;

TCurlVersionInfo = record
@@ -11528,13 +11575,46 @@ TCurlVersionInfo = record
PCurlVersionInfo = ^TCurlVersionInfo;

TCurl = type pointer;
TCurlList = type pointer;
TCurlSList = type pointer;
PCurlSList = ^TCurlSList;
PPCurlSListArray = ^PCurlSListArray;
PCurlSListArray = array[0..(MaxInt div SizeOf(PCurlSList))-1] of PCurlSList;
TCurlMulti = type pointer;
TCurlSocket = type TSocket;

PCurlCertInfo = ^TCurlCertInfo;
TCurlCertInfo = packed record
num_of_certs: integer;
{$ifdef CPUX64}_align: array[0..3] of byte;{$endif}
certinfo: PPCurlSListArray;
end;

PCurlMsgRec = ^TCurlMsgRec;
TCurlMsgRec = packed record
msg: TCurlMsg;
{$ifdef CPUX64}_align: array[0..3] of byte;{$endif}
easy_handle: TCurl;
data: packed record case byte of
0: (whatever: Pointer);
1: (result: TCurlResult);
end;
end;

PCurlWaitFD = ^TCurlWaitFD;
TCurlWaitFD = packed record
fd: TCurlSocket;
events: SmallInt;
revents: SmallInt;
{$ifdef CPUX64}_align: array[0..3] of byte;{$endif}
end;

curl_write_callback = function (buffer: PAnsiChar; size,nitems: integer;
outstream: pointer): integer; cdecl;
curl_read_callback = function (buffer: PAnsiChar; size,nitems: integer;
instream: pointer): integer; cdecl;

{$Z1}

var
curl: packed record
{$ifdef FPC}
@@ -11553,42 +11633,63 @@ TCurlVersionInfo = record
easy_duphandle: function(curl: TCurl): pointer; cdecl;
easy_reset: procedure(curl: TCurl); cdecl;
easy_strerror: function(code: TCurlResult): PAnsiChar; cdecl;
slist_append: function(list: TCurlList; s: PAnsiChar): TCurlList; cdecl;
slist_free_all: procedure(list: TCurlList); cdecl;
slist_append: function(list: TCurlSList; s: PAnsiChar): TCurlSList; cdecl;
slist_free_all: procedure(list: TCurlSList); cdecl;
{$ifdef LIBCURLMULTI} // https://curl.haxx.se/libcurl/c/libcurl-multi.html interface
multi_add_handle: function(mcurl: TCurlMulti; curl: TCurl): TCurlMultiCode; cdecl;
multi_assign: function(mcurl: TCurlMulti; socket: TCurlSocket; data: pointer): TCurlMultiCode; cdecl;
multi_cleanup: function(mcurl: TCurlMulti): TCurlMultiCode; cdecl;
multi_fdset: function(mcurl: TCurlMulti; read, write, exec: PFDSet; out max: integer): TCurlMultiCode; cdecl;
multi_info_read: function(mcurl: TCurlMulti; out msgsqueue: integer): PCurlMsgRec; cdecl;
multi_init: function: TCurlMulti; cdecl;
multi_perform: function(mcurl: TCurlMulti; out runningh: integer): TCurlMultiCode; cdecl;
multi_remove_handle: function(mcurl: TCurlMulti; curl: TCurl): TCurlMultiCode; cdecl;
multi_setopt: function(mcurl: TCurlMulti; option: TCurlMultiOption): TCurlMultiCode; cdecl varargs;
multi_socket_action: function(mcurl: TCurlMulti; socket: TCurlSocket; mask: Integer; out runningh: integer): TCurlMultiCode; cdecl;
multi_socket_all: function(mcurl: TCurlMulti; out runningh: integer): TCurlMultiCode; cdecl;
multi_strerror: function(code: TCurlMultiCode): PAnsiChar; cdecl;
multi_timeout: function(mcurl: TCurlMulti; out ms: integer): TCurlMultiCode; cdecl;
multi_wait: function(mcurl: TCurlMulti; fds: PCurlWaitFD; fdscount: cardinal; ms: integer; out ret: integer): TCurlMultiCode; cdecl;
{$endif LIBCURLMULTI}
info: TCurlVersionInfo;
infoText: string;
end;

procedure LibCurlInitialize;
var P: PPointer;
api: integer;
const NAMES: array[0..12] of string = (
const NAMES: array[0..{$ifdef LIBCURLMULTI}26{$else}12{$endif}] of string = (
'global_init','global_cleanup','version_info',
'easy_init','easy_setopt','easy_perform','easy_cleanup','easy_getinfo',
'easy_duphandle','easy_reset','easy_strerror',
'slist_append','slist_free_all');
'easy_duphandle','easy_reset','easy_strerror','slist_append','slist_free_all'
{$ifdef LIBCURLMULTI},
'multi_add_handle','multi_assign','multi_cleanup','multi_fdset',
'multi_info_read','multi_init','multi_perform','multi_remove_handle',
'multi_setopt','multi_socket_action','multi_socket_all','multi_strerror',
'multi_timeout','multi_wait'
{$endif LIBCURLMULTI} );
begin
EnterCriticalSection(SynSockCS);
try
if curl.Module=0 then
try
curl.Module := LoadLibrary(LIBCURL_DLL);
{$ifdef Darwin}
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl.3.dylib');
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl.4.dylib');
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl.3.dylib');
{$else}
{$ifdef LINUX}
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl.so.3');
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl.so.4');
// for latest Linux Mint and other similar distros
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl-gnutls.so.3');
curl.Module := LoadLibrary('libcurl.so.3');
// for latest Linux Mint and other similar distros
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl-gnutls.so.4');
if curl.Module=0 then
curl.Module := LoadLibrary('libcurl-gnutls.so.3');
{$endif}
{$endif}
if curl.Module=0 then
@@ -11684,6 +11785,8 @@ procedure TCurlHTTP.InternalCreateRequest(const method, aURL: SockString);
if IgnoreSSLCertificateErrors then begin
curl.easy_setopt(fHandle,coSSLVerifyPeer,0);
curl.easy_setopt(fHandle,coSSLVerifyHost,0);
//curl.easy_setopt(fHandle,coProxySSLVerifyPeer,0);
//curl.easy_setopt(fHandle,coProxySSLVerifyHost,0);
end else begin
// see https://curl.haxx.se/libcurl/c/simplessl.html
if fSSL.CertFile<>'' then begin
@@ -605,12 +605,12 @@
{$ifdef CPU64}
{$define NOSQLITE3STATIC}
{$endif}
{$endif}
{$endif FPC}

{$ifdef NOSQLITE3STATIC}
// our proprietary crypto expects a statically linked custom sqlite3.c
{$define NOSQLITE3ENCRYPT}
{$endif}
{$endif NOSQLITE3STATIC}

{$ifdef MSWINDOWS}
{$define USEWININET} // publish TWinINet/TWinHttp/TWinHttpAPI classes
@@ -623,6 +623,11 @@
{$define USELIBCURL}
// for Android, consider using https://github.com/gcesarmza/curl-android-ios
// static libraries and force USELIBCURL in the project conditionals
{$endif}
{$endif}
{$endif ANDROID}
{$endif MSWINDOWS}

{$ifdef USELIBCURL}
{.$define LIBCURLMULTI}
// enable https://curl.haxx.se/libcurl/c/libcurl-multi.html interface
{$endif USELIBCURL}

@@ -1 +1 @@
'1.18.5084'
'1.18.5085'

0 comments on commit f8cdc9e

Please sign in to comment.
You can’t perform that action at this time.