mirror of https://gitlab.com/basile.b/dexed.git
remove workarounds bad SSl versions before fpc 3.2.0
This commit is contained in:
parent
4956f7c19b
commit
6a3f490b0c
|
@ -5,15 +5,12 @@ unit u_simpleget;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
classes, {$ifdef UNIX}libcurl,{$else} fphttpclient,{$endif} fpjson, jsonparser, jsonscanner;
|
classes, fpjson, jsonparser, jsonscanner, fphttpclient,
|
||||||
|
openssl, opensslsockets;
|
||||||
|
|
||||||
type
|
type
|
||||||
PStream = ^TStream;
|
PStream = ^TStream;
|
||||||
|
|
||||||
{$ifdef VER3_2_0}
|
|
||||||
{$Warning 'workarounds to avoid SSL context errors may be unecessary starting from FCL 3.2.0'}
|
|
||||||
{$endif}
|
|
||||||
|
|
||||||
// Get the content of 'url' in the string 'data'
|
// Get the content of 'url' in the string 'data'
|
||||||
function simpleGet(url: string; var data: string): boolean; overload;
|
function simpleGet(url: string; var data: string): boolean; overload;
|
||||||
// Get the content of 'url' in the stream 'data'
|
// Get the content of 'url' in the stream 'data'
|
||||||
|
@ -22,75 +19,12 @@ function simpleGet(url: string; data: TStream): boolean; overload;
|
||||||
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
||||||
|
|
||||||
const
|
const
|
||||||
{$ifdef windows} libcurlFname = 'libeay32.dll, ssleay32.dll'; {$endif}
|
simpleGetErrMsg = 'no network or incompatible libssl';
|
||||||
{$ifdef linux} libcurlFname = 'libcurl.so'; {$endif}
|
|
||||||
{$ifdef darwin} libcurlFname = 'libcurl.dylib'; {$endif}
|
|
||||||
simpleGetErrMsg = 'no network or ' + libcurlFname + ' not setup correctly';
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$ifdef UNIX}
|
|
||||||
var
|
|
||||||
fCurlHandle: CURL = nil;
|
|
||||||
|
|
||||||
function curlHandle(): CURL;
|
|
||||||
begin
|
|
||||||
if not assigned(fCurlHandle) then
|
|
||||||
begin
|
|
||||||
curl_global_init(CURL_GLOBAL_SSL or CURL_GLOBAL_ALL);
|
|
||||||
fCurlHandle := curl_easy_init();
|
|
||||||
end;
|
|
||||||
result := fCurlHandle;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function simpleGetClbckForStream(buffer:Pchar; size:PtrInt; nitems:PtrInt;
|
|
||||||
appender: PStream): PtrInt; cdecl;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
result := appender^.write(buffer^, size * nitems);
|
|
||||||
except
|
|
||||||
result := 0;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function simpleGetClbckForString(buffer:Pchar; size:PtrInt; nitems:PtrInt;
|
|
||||||
appender: PString): PtrInt; cdecl;
|
|
||||||
begin
|
|
||||||
result := size* nitems;
|
|
||||||
try
|
|
||||||
(appender^) += buffer;
|
|
||||||
except
|
|
||||||
result := 0;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
{$endif}
|
|
||||||
|
|
||||||
function simpleGet(url: string; var data: string): boolean; overload;
|
function simpleGet(url: string; var data: string): boolean; overload;
|
||||||
{$ifdef UNIX}
|
|
||||||
var
|
|
||||||
c: CURLcode;
|
|
||||||
h: CURL;
|
|
||||||
{$endif}
|
|
||||||
begin
|
begin
|
||||||
{$ifdef UNIX}
|
|
||||||
h := curlHandle();
|
|
||||||
if not assigned(h) then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_USERAGENT, ['curl-fclweb']);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_URL, [PChar(url)]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_WRITEDATA, [@data]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, [@simpleGetClbckForString]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_perform(h);
|
|
||||||
result := c = CURLcode.CURLE_OK;
|
|
||||||
{$else}
|
|
||||||
result := true;
|
result := true;
|
||||||
with TFPHTTPClient.Create(nil) do
|
with TFPHTTPClient.Create(nil) do
|
||||||
try
|
try
|
||||||
|
@ -103,35 +37,10 @@ begin
|
||||||
finally
|
finally
|
||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
{$endif}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function simpleGet(url: string; data: TStream): boolean; overload;
|
function simpleGet(url: string; data: TStream): boolean; overload;
|
||||||
{$ifdef UNIX}
|
|
||||||
var
|
|
||||||
c: CURLcode;
|
|
||||||
h: CURL;
|
|
||||||
{$endif}
|
|
||||||
begin
|
begin
|
||||||
{$ifdef UNIX}
|
|
||||||
h := curlHandle();
|
|
||||||
if not assigned(h) then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_USERAGENT, ['curl-fclweb']);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_URL, [PChar(url)]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_WRITEDATA, [@data]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, [@simpleGetClbckForStream]);
|
|
||||||
if c <> CURLcode.CURLE_OK then
|
|
||||||
exit(false);
|
|
||||||
c := curl_easy_perform(h);
|
|
||||||
result := c = CURLcode.CURLE_OK;
|
|
||||||
{$else}
|
|
||||||
result := true;
|
result := true;
|
||||||
with TFPHTTPClient.Create(nil) do
|
with TFPHTTPClient.Create(nil) do
|
||||||
try
|
try
|
||||||
|
@ -144,7 +53,6 @@ begin
|
||||||
finally
|
finally
|
||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
{$endif}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
||||||
|
@ -166,10 +74,10 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
{$IFDEF POSIX}
|
||||||
|
// openssl.DLLVersions[2] := '1.1.1';
|
||||||
|
{$ENDIF}
|
||||||
finalization
|
finalization
|
||||||
{$ifdef UNIX}
|
|
||||||
if assigned(fCurlHandle) then
|
|
||||||
curl_easy_cleanup(fCurlHandle);
|
|
||||||
{$endif}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue