From c177be0dd83c61491b28f46d8a02edec9a8033e4 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 19 Sep 2025 09:15:17 +0500 Subject: [PATCH] engine: move our HTTP client to http subfolder, prepare for curl integration --- .../{net_http.c => http/net_http_xash.c} | 0 engine/wscript | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+) rename engine/common/{net_http.c => http/net_http_xash.c} (100%) diff --git a/engine/common/net_http.c b/engine/common/http/net_http_xash.c similarity index 100% rename from engine/common/net_http.c rename to engine/common/http/net_http_xash.c diff --git a/engine/wscript b/engine/wscript index e894a639..cdf76280 100644 --- a/engine/wscript +++ b/engine/wscript @@ -33,6 +33,15 @@ int main(int argc, char **argv) } ''' +CURL_CHECK_FRAGMENT=''' +#include +int main(int argc, char **argv) +{ + CURL *easy = curl_easy_init(); + return 0; +} +''' + def options(opt): grp = opt.add_option_group('Engine options') @@ -60,6 +69,9 @@ def options(opt): grp.add_option('--enable-ffmpeg-dlopen', action = 'store_true', dest = 'FFMPEG_DLOPEN', default = False, help = 'load ffmpeg libraries in runtime [default: %(default)s]') + grp.add_option('--disable-curl', action = 'store_false', dest = 'CURL', default = False, + help = 'enable curl-based HTTP downloader [default: %(default)s]') + opt.load('sdl2') def find_sdl(conf): @@ -163,6 +175,19 @@ def configure(conf): conf.define('HAVE_FFMPEG', True) conf.define_cond('XASH_FFMPEG_DLOPEN', conf.options.FFMPEG_DLOPEN) + if conf.options.CURL: + pkgconf_args = '--cflags --libs' + features = 'c cprogram' + + # TODO: when dlopen curl is implemented, we might not need this check + # as we can safely bundle curl headers as curl never breaks API/ABI + conf.check_cfg(package='libcurl', uselib_store='CURL', args=pkgconf_args) + + conf.check(features=features, fragment=CURL_CHECK_FRAGMENT, use='CURL', msg='Checking for curl sanity') + + conf.env.CURL=True + conf.define('HAVE_CURL', True) + conf.define_cond('XASH_STATIC_LIBS', conf.env.STATIC_LINKING) conf.define_cond('XASH_CUSTOM_SWAP', conf.options.CUSTOM_SWAP) conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', not have_async_resolve) @@ -199,6 +224,12 @@ def build(bld): if bld.get_define('XASH_STATIC_LIBS'): source += ['platform/misc/lib_static.c'] + if bld.get_define('HAVE_CURL'): + source += ['common/http/net_http_curl.c'] + libs += ['CURL'] + else: + source += ['common/http/net_http_xash.c'] + if bld.env.DEST_OS == 'win32': libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32'] elif bld.env.DEST_OS == 'nswitch':