mirror of https://gitlab.com/basile.b/dexed.git
fix simple get not working with libcurl under win
This commit is contained in:
parent
0be7e09a42
commit
832bd27976
|
@ -59,7 +59,8 @@ immutable Resource[] oldResources =
|
||||||
version(Windows)
|
version(Windows)
|
||||||
immutable Resource[] systemRelResources =
|
immutable Resource[] systemRelResources =
|
||||||
[
|
[
|
||||||
Resource(cast(ImpType) import("libcurl.dll"), "libcurl.dll", Kind.exe)
|
Resource(cast(ImpType) import("libeay32.dll"), "libeay32.dll", Kind.exe),
|
||||||
|
Resource(cast(ImpType) import("ssleay32.dll"), "ssleay32.dll", Kind.exe),
|
||||||
];
|
];
|
||||||
else
|
else
|
||||||
immutable Resource[] systemRelResources = [];
|
immutable Resource[] systemRelResources = [];
|
||||||
|
|
|
@ -5,7 +5,7 @@ unit u_simpleget;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
classes, libcurl, fpjson, jsonparser, jsonscanner;
|
classes, {$ifdef posix}libcurl,{$else} fphttpclient,{$endif} fpjson, jsonparser, jsonscanner;
|
||||||
|
|
||||||
type
|
type
|
||||||
PStream = ^TStream;
|
PStream = ^TStream;
|
||||||
|
@ -18,13 +18,14 @@ 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 = 'libcurl.dll'; {$endif}
|
{$ifdef windows} libcurlFname = 'libeay32.dll, ssleay32.dll'; {$endif}
|
||||||
{$ifdef linux} libcurlFname = 'libcurl.so'; {$endif}
|
{$ifdef linux} libcurlFname = 'libcurl.so'; {$endif}
|
||||||
{$ifdef darwin} libcurlFname = 'libcurl.dylib'; {$endif}
|
{$ifdef darwin} libcurlFname = 'libcurl.dylib'; {$endif}
|
||||||
simpleGetErrMsg = 'no network or ' + libcurlFname + ' not setup correctly';
|
simpleGetErrMsg = 'no network or ' + libcurlFname + ' not setup correctly';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
{$ifdef posix}
|
||||||
var
|
var
|
||||||
fCurlHandle: CURL = nil;
|
fCurlHandle: CURL = nil;
|
||||||
|
|
||||||
|
@ -58,12 +59,16 @@ begin
|
||||||
result := 0;
|
result := 0;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
function simpleGet(url: string; var data: string): boolean; overload;
|
function simpleGet(url: string; var data: string): boolean; overload;
|
||||||
|
{$ifdef posix}
|
||||||
var
|
var
|
||||||
c: CURLcode;
|
c: CURLcode;
|
||||||
h: CURL;
|
h: CURL;
|
||||||
|
{$endif}
|
||||||
begin
|
begin
|
||||||
|
{$ifdef posix}
|
||||||
h := curlHandle();
|
h := curlHandle();
|
||||||
if not assigned(h) then
|
if not assigned(h) then
|
||||||
exit(false);
|
exit(false);
|
||||||
|
@ -81,13 +86,30 @@ begin
|
||||||
exit(false);
|
exit(false);
|
||||||
c := curl_easy_perform(h);
|
c := curl_easy_perform(h);
|
||||||
result := c = CURLcode.CURLE_OK;
|
result := c = CURLcode.CURLE_OK;
|
||||||
|
{$else}
|
||||||
|
result := true;
|
||||||
|
with TFPHTTPClient.Create(nil) do
|
||||||
|
try
|
||||||
|
try
|
||||||
|
AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
|
||||||
|
data := get(url);
|
||||||
|
except
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
free;
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function simpleGet(url: string; data: TStream): boolean; overload;
|
function simpleGet(url: string; data: TStream): boolean; overload;
|
||||||
|
{$ifdef posix}
|
||||||
var
|
var
|
||||||
c: CURLcode;
|
c: CURLcode;
|
||||||
h: CURL;
|
h: CURL;
|
||||||
|
{$endif}
|
||||||
begin
|
begin
|
||||||
|
{$ifdef posix}
|
||||||
h := curlHandle();
|
h := curlHandle();
|
||||||
if not assigned(h) then
|
if not assigned(h) then
|
||||||
exit(false);
|
exit(false);
|
||||||
|
@ -105,6 +127,20 @@ begin
|
||||||
exit(false);
|
exit(false);
|
||||||
c := curl_easy_perform(h);
|
c := curl_easy_perform(h);
|
||||||
result := c = CURLcode.CURLE_OK;
|
result := c = CURLcode.CURLE_OK;
|
||||||
|
{$else}
|
||||||
|
result := true;
|
||||||
|
with TFPHTTPClient.Create(nil) do
|
||||||
|
try
|
||||||
|
try
|
||||||
|
AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
|
||||||
|
get(url, data);
|
||||||
|
except
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
free;
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
function simpleGet(url: string; var data: TJSONData): boolean; overload;
|
||||||
|
@ -127,7 +163,9 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
|
{$ifdef posix}
|
||||||
if assigned(fCurlHandle) then
|
if assigned(fCurlHandle) then
|
||||||
curl_easy_cleanup(fCurlHandle);
|
curl_easy_cleanup(fCurlHandle);
|
||||||
|
{$endif}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue