mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Fallback to libcurl.so.3 if loading libcurl.so.4 fails, fixes not working on older linux distributions
Also don't crash game if curl_global_init/curl_easy_init fails
This commit is contained in:
parent
918b86dc18
commit
71cb18ac53
31
src/Http.c
31
src/Http.c
@ -693,20 +693,28 @@ typedef struct curl_slist* (APIENTRY *FP_curl_slist_append)(struct curl_slist* l
|
|||||||
|
|
||||||
#if defined CC_BUILD_WIN
|
#if defined CC_BUILD_WIN
|
||||||
static const String curlLib = String_FromConst("libcurl.dll");
|
static const String curlLib = String_FromConst("libcurl.dll");
|
||||||
|
static const String curlAlt = String_FromConst("curl.dll");
|
||||||
#elif defined CC_BUILD_OSX
|
#elif defined CC_BUILD_OSX
|
||||||
static const String curlLib = String_FromConst("/usr/lib/libcurl.dylib");
|
static const String curlLib = String_FromConst("/usr/lib/libcurl.4.dylib");
|
||||||
|
static const String curlAlt = String_FromConst("/usr/lib/libcurl.dylib");
|
||||||
#elif defined CC_BUILD_OPENBSD
|
#elif defined CC_BUILD_OPENBSD
|
||||||
static const String curlLib = String_FromConst("libcurl.so.25.17");
|
static const String curlLib = String_FromConst("libcurl.so.25.17");
|
||||||
|
static const String curlAlt = String_FromConst("libcurl.so.25.16");
|
||||||
#else
|
#else
|
||||||
static const String curlLib = String_FromConst("libcurl.so.4");
|
static const String curlLib = String_FromConst("libcurl.so.4");
|
||||||
|
static const String curlAlt = String_FromConst("libcurl.so.3");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define QUOTE(x) #x
|
#define QUOTE(x) #x
|
||||||
#define LoadCurlFunc(sym) (_ ## sym = (FP_ ## sym)DynamicLib_Get2(lib, QUOTE(sym)))
|
#define LoadCurlFunc(sym) (_ ## sym = (FP_ ## sym)DynamicLib_Get2(lib, QUOTE(sym)))
|
||||||
static cc_bool LoadCurlFuncs(void) {
|
static cc_bool LoadCurlFuncs(void) {
|
||||||
void* lib = DynamicLib_Load2(&curlLib);
|
void* lib = DynamicLib_Load2(&curlLib);
|
||||||
if (!lib) { Logger_DynamicLibWarn("loading", &curlLib); return false; }
|
if (!lib) {
|
||||||
|
Logger_DynamicLibWarn("loading", &curlLib);
|
||||||
|
|
||||||
|
lib = DynamicLib_Load2(&curlAlt);
|
||||||
|
if (!lib) { Logger_DynamicLibWarn("loading", &curlAlt); return false; }
|
||||||
|
}
|
||||||
/* Non-essential function missing in older curl versions */
|
/* Non-essential function missing in older curl versions */
|
||||||
LoadCurlFunc(curl_easy_strerror);
|
LoadCurlFunc(curl_easy_strerror);
|
||||||
|
|
||||||
@ -718,7 +726,7 @@ static cc_bool LoadCurlFuncs(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CURL* curl;
|
static CURL* curl;
|
||||||
static cc_bool curlInited;
|
static cc_bool curlSupported;
|
||||||
|
|
||||||
cc_bool Http_DescribeError(cc_result res, String* dst) {
|
cc_bool Http_DescribeError(cc_result res, String* dst) {
|
||||||
const char* err;
|
const char* err;
|
||||||
@ -732,13 +740,16 @@ cc_bool Http_DescribeError(cc_result res, String* dst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Http_SysInit(void) {
|
static void Http_SysInit(void) {
|
||||||
if (!LoadCurlFuncs()) return;
|
static const String msg = String_FromConst("Failed to init libcurl. All HTTP requests will therefore fail.");
|
||||||
CURLcode res = _curl_global_init(CURL_GLOBAL_DEFAULT);
|
CURLcode res;
|
||||||
if (res) Logger_Abort2(res, "Failed to init curl");
|
|
||||||
|
if (!LoadCurlFuncs()) { Logger_WarnFunc(&msg); return; }
|
||||||
|
res = _curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
if (res) { Logger_SimpleWarn(res, "initing curl"); return; }
|
||||||
|
|
||||||
curl = _curl_easy_init();
|
curl = _curl_easy_init();
|
||||||
if (!curl) Logger_Abort("Failed to init easy curl");
|
if (!curl) { Logger_SimpleWarn(res, "initing curl_easy"); return; }
|
||||||
curlInited = true;
|
curlSupported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct curl_slist* headers_list;
|
static struct curl_slist* headers_list;
|
||||||
@ -793,7 +804,7 @@ static cc_result Http_SysDo(struct HttpRequest* req, String* url) {
|
|||||||
void* post_data = req->data;
|
void* post_data = req->data;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
||||||
if (!curlInited) {
|
if (!curlSupported) {
|
||||||
HttpRequest_Free(req);
|
HttpRequest_Free(req);
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@ -833,7 +844,7 @@ static cc_result Http_SysDo(struct HttpRequest* req, String* url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Http_SysFree(void) {
|
static void Http_SysFree(void) {
|
||||||
if (!curlInited) return;
|
if (!curlSupported) return;
|
||||||
_curl_easy_cleanup(curl);
|
_curl_easy_cleanup(curl);
|
||||||
_curl_global_cleanup();
|
_curl_global_cleanup();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user