From: Viktor Szakats Date: Sun, 8 Sep 2024 10:26:45 +0000 (+0200) Subject: ipfs: add options to disable X-Git-Tag: curl-8_11_0~380 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce7d0d41378007eda676c83ad6b86c59870cc9f1;p=thirdparty%2Fcurl.git ipfs: add options to disable - CPPFLAGS: `-DCURL_DISABLE_IPFS` - configure: `--disable-ipfs` - cmake: `-DCURL_DISABLE_IPFS=ON` Fixes #14824 Closes #14827 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f6af21410..498e6cdf18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,6 +332,8 @@ option(CURL_DISABLE_PROGRESS_METER "Disable built-in progress meter" OFF) mark_as_advanced(CURL_DISABLE_PROGRESS_METER) option(CURL_DISABLE_PROXY "Disable proxy support" OFF) mark_as_advanced(CURL_DISABLE_PROXY) +option(CURL_DISABLE_IPFS "Disable IPFS" OFF) +mark_as_advanced(CURL_DISABLE_IPFS) option(CURL_DISABLE_RTSP "Disable RTSP" OFF) mark_as_advanced(CURL_DISABLE_SHA512_256) option(CURL_DISABLE_SHA512_256 "Disable SHA-512/256 hash algorithm" OFF) @@ -352,6 +354,7 @@ option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF) mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) if(CURL_DISABLE_HTTP) + set(CURL_DISABLE_IPFS ON) set(CURL_DISABLE_RTSP ON) set(CURL_DISABLE_ALTSVC ON) set(CURL_DISABLE_HSTS ON) @@ -371,6 +374,7 @@ if(HTTP_ONLY) set(CURL_DISABLE_LDAPS ON) set(CURL_DISABLE_MQTT ON) set(CURL_DISABLE_POP3 ON) + set(CURL_DISABLE_IPFS ON) set(CURL_DISABLE_RTSP ON) set(CURL_DISABLE_SMB ON) set(CURL_DISABLE_SMTP ON) @@ -1817,8 +1821,6 @@ endif() # Clear list and try to detect available protocols unset(_items) _add_if("HTTP" NOT CURL_DISABLE_HTTP) -_add_if("IPFS" NOT CURL_DISABLE_HTTP) -_add_if("IPNS" NOT CURL_DISABLE_HTTP) _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND _ssl_enabled) _add_if("FTP" NOT CURL_DISABLE_FTP) _add_if("FTPS" NOT CURL_DISABLE_FTP AND _ssl_enabled) @@ -1845,6 +1847,8 @@ _add_if("SMTP" NOT CURL_DISABLE_SMTP) _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND _ssl_enabled) _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH) _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH) +_add_if("IPFS" NOT CURL_DISABLE_IPFS) +_add_if("IPNS" NOT CURL_DISABLE_IPFS) _add_if("RTSP" NOT CURL_DISABLE_RTSP) _add_if("RTMP" USE_LIBRTMP) _add_if("MQTT" NOT CURL_DISABLE_MQTT) diff --git a/configure.ac b/configure.ac index d6605fbb7c..f922c28d51 100644 --- a/configure.ac +++ b/configure.ac @@ -168,6 +168,7 @@ curl_verbose_msg="enabled (--disable-verbose)" curl_sspi_msg="no (--enable-sspi)" curl_ldap_msg="no (--enable-ldap / --with-ldap-lib / --with-lber-lib)" curl_ldaps_msg="no (--enable-ldaps)" + curl_ipfs_msg="no (--enable-ipfs)" curl_rtsp_msg="no (--enable-rtsp)" curl_rtmp_msg="no (--with-librtmp)" curl_psl_msg="no (--with-libpsl)" @@ -640,8 +641,10 @@ AS_HELP_STRING([--disable-http],[Disable HTTP support]), AC_MSG_RESULT(no) AC_DEFINE(CURL_DISABLE_HTTP, 1, [to disable HTTP]) disable_http="yes" - AC_MSG_WARN([disable HTTP disables FTP over proxy and RTSP]) + AC_MSG_WARN([disable HTTP disables FTP over proxy, IPFS and RTSP]) AC_SUBST(CURL_DISABLE_HTTP, [1]) + AC_DEFINE(CURL_DISABLE_IPFS, 1, [to disable IPFS]) + AC_SUBST(CURL_DISABLE_IPFS, [1]) AC_DEFINE(CURL_DISABLE_RTSP, 1, [to disable RTSP]) AC_SUBST(CURL_DISABLE_RTSP, [1]) dnl toggle off alt-svc too when HTTP is disabled @@ -691,6 +694,32 @@ AS_HELP_STRING([--disable-file],[Disable FILE support]), esac ], AC_MSG_RESULT(yes) ) +AC_MSG_CHECKING([whether to support IPFS]) +AC_ARG_ENABLE(ipfs, +AS_HELP_STRING([--enable-ipfs],[Enable IPFS support]) +AS_HELP_STRING([--disable-ipfs],[Disable IPFS support]), +[ case "$enableval" in + no) + AC_MSG_RESULT(no) + AC_DEFINE(CURL_DISABLE_IPFS, 1, [to disable IPFS]) + AC_SUBST(CURL_DISABLE_IPFS, [1]) + ;; + *) + if test x$CURL_DISABLE_HTTP = x1; then + AC_MSG_ERROR(HTTP support needs to be enabled in order to enable IPFS support!) + else + AC_MSG_RESULT(yes) + curl_ipfs_msg="enabled" + fi + ;; + esac ], + if test "x$CURL_DISABLE_HTTP" != "x1"; then + AC_MSG_RESULT(yes) + curl_ipfs_msg="enabled" + else + AC_MSG_RESULT(no) + fi +) AC_MSG_CHECKING([whether to support ldap]) AC_ARG_ENABLE(ldap, AS_HELP_STRING([--enable-ldap],[Enable LDAP support]) @@ -5125,7 +5154,7 @@ AC_SUBST(SUPPORT_FEATURES) dnl For supported protocols in pkg-config file if test "x$CURL_DISABLE_HTTP" != "x1"; then - SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS HTTP IPFS IPNS" + SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS HTTP" if test "x$SSL_ENABLED" = "x1"; then SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS HTTPS" fi @@ -5202,6 +5231,9 @@ fi if test "x$USE_WOLFSSH" = "x1"; then SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SFTP" fi +if test "x$CURL_DISABLE_IPFS" != "x1"; then + SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS IPFS IPNS" +fi if test "x$CURL_DISABLE_RTSP" != "x1"; then SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS RTSP" fi @@ -5312,6 +5344,7 @@ AC_MSG_NOTICE([Configured to build curl/libcurl: ca fallback: ${with_ca_fallback} LDAP: ${curl_ldap_msg} LDAPS: ${curl_ldaps_msg} + IPFS/IPNS: ${curl_ipfs_msg} RTSP: ${curl_rtsp_msg} RTMP: ${curl_rtmp_msg} PSL: ${curl_psl_msg} diff --git a/docs/CURL-DISABLE.md b/docs/CURL-DISABLE.md index 6080851dd5..32ae025fc4 100644 --- a/docs/CURL-DISABLE.md +++ b/docs/CURL-DISABLE.md @@ -140,6 +140,11 @@ Disable the built-in progress meter Disable support for proxies +## `CURL_DISABLE_IPFS` + +Disable the IPFS/IPNS protocols. This affects the curl tool only, where +IPFS/IPNS protocol support is implemented. + ## `CURL_DISABLE_RTSP` Disable the RTSP protocol. diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 304e528a71..39609bc38a 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -131,6 +131,9 @@ /* disables proxies */ #cmakedefine CURL_DISABLE_PROXY 1 +/* disables IPFS from the curl tool */ +#cmakedefine CURL_DISABLE_IPFS 1 + /* disables RTSP */ #cmakedefine CURL_DISABLE_RTSP 1 diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c index 5564e250d3..48808adb27 100644 --- a/src/tool_cfgable.c +++ b/src/tool_cfgable.c @@ -110,7 +110,9 @@ static void free_config_fields(struct OperationConfig *config) config->url_get = NULL; config->url_out = NULL; +#ifndef CURL_DISABLE_IPFS Curl_safefree(config->ipfs_gateway); +#endif /* !CURL_DISABLE_IPFS */ Curl_safefree(config->doh_url); Curl_safefree(config->cipher_list); Curl_safefree(config->proxy_cipher_list); diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index 729cd5241a..d9099c329d 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -130,7 +130,9 @@ struct OperationConfig { struct getout *url_get; /* point to the node to fill in URL */ struct getout *url_out; /* point to the node to fill in outfile */ struct getout *url_ul; /* point to the node to fill in upload */ +#ifndef CURL_DISABLE_IPFS char *ipfs_gateway; +#endif /* !CURL_DISABLE_IPFS */ char *doh_url; char *cipher_list; char *proxy_cipher_list; diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 282f1893a4..7a38992a9e 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -171,7 +171,9 @@ static const struct LongShort aliases[]= { {"insecure", ARG_BOOL, 'k', C_INSECURE}, {"interface", ARG_STRG, ' ', C_INTERFACE}, {"ip-tos", ARG_STRG, ' ', C_IP_TOS}, +#ifndef CURL_DISABLE_IPFS {"ipfs-gateway", ARG_STRG, ' ', C_IPFS_GATEWAY}, +#endif /* !CURL_DISABLE_IPFS */ {"ipv4", ARG_NONE, '4', C_IPV4}, {"ipv6", ARG_NONE, '6', C_IPV6}, {"json", ARG_STRG, ' ', C_JSON}, @@ -1321,9 +1323,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ if(!err && (config->maxredirs < -1)) err = PARAM_BAD_NUMERIC; break; +#ifndef CURL_DISABLE_IPFS case C_IPFS_GATEWAY: /* --ipfs-gateway */ err = getstr(&config->ipfs_gateway, nextarg, DENY_BLANK); break; +#endif /* !CURL_DISABLE_IPFS */ case C_PROXY_NTLM: /* --proxy-ntlm */ if(!feature_ntlm) err = PARAM_LIBCURL_DOESNT_SUPPORT; diff --git a/src/tool_help.c b/src/tool_help.c index 8c655c4b2b..57b14a3b07 100644 --- a/src/tool_help.c +++ b/src/tool_help.c @@ -331,6 +331,7 @@ void tool_version_info(void) printf("Release-Date: %s\n", LIBCURL_TIMESTAMP); #endif if(built_in_protos[0]) { +#ifndef CURL_DISABLE_IPFS const char *insert = NULL; /* we have ipfs and ipns support if libcurl has http support */ for(builtin = built_in_protos; *builtin; ++builtin) { @@ -345,16 +346,19 @@ void tool_version_info(void) insert = *builtin; } } +#endif /* !CURL_DISABLE_IPFS */ printf("Protocols:"); for(builtin = built_in_protos; *builtin; ++builtin) { /* Special case: do not list rtmp?* protocols. They may only appear together with "rtmp" */ if(!curl_strnequal(*builtin, "rtmp", 4) || !builtin[0][4]) printf(" %s", *builtin); +#ifndef CURL_DISABLE_IPFS if(insert && insert == *builtin) { printf(" ipfs ipns"); insert = NULL; } +#endif /* !CURL_DISABLE_IPFS */ } puts(""); /* newline */ } diff --git a/src/tool_ipfs.c b/src/tool_ipfs.c index 09bff49067..46bd8e1463 100644 --- a/src/tool_ipfs.c +++ b/src/tool_ipfs.c @@ -23,6 +23,7 @@ ***************************************************************************/ #include "tool_setup.h" +#ifndef CURL_DISABLE_IPFS #include "curlx.h" #include "dynbuf.h" @@ -287,3 +288,4 @@ clean: } return result; } +#endif /* !CURL_DISABLE_IPFS */ diff --git a/src/tool_ipfs.h b/src/tool_ipfs.h index 9c8a83e3b3..31d8019fa2 100644 --- a/src/tool_ipfs.h +++ b/src/tool_ipfs.h @@ -25,9 +25,11 @@ ***************************************************************************/ #include "tool_setup.h" +#ifndef CURL_DISABLE_IPFS #define MAX_GATEWAY_URL_LEN 10000 CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, struct OperationConfig *config); #endif /* HEADER_CURL_TOOL_IPFS_H */ +#endif /* !CURL_DISABLE_IPFS */ diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c index 4bc22217f9..34b79f5eb7 100644 --- a/src/tool_libinfo.c +++ b/src/tool_libinfo.c @@ -49,8 +49,10 @@ const char *proto_rtsp = NULL; const char *proto_scp = NULL; const char *proto_sftp = NULL; const char *proto_tftp = NULL; +#ifndef CURL_DISABLE_IPFS const char *proto_ipfs = "ipfs"; const char *proto_ipns = "ipns"; +#endif /* !CURL_DISABLE_IPFS */ static struct proto_name_tokenp { const char *proto_name; diff --git a/src/tool_operate.c b/src/tool_operate.c index c8ea8ed458..b9b7bfdc38 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -793,6 +793,9 @@ static CURLcode url_proto(char **url, CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME) && !curl_url_get(uh, CURLUPART_SCHEME, &schemep, CURLU_DEFAULT_SCHEME)) { +#ifdef CURL_DISABLE_IPFS + (void)config; +#else if(curl_strequal(schemep, proto_ipfs) || curl_strequal(schemep, proto_ipns)) { result = ipfs_url_rewrite(uh, schemep, url, config); @@ -805,6 +808,7 @@ static CURLcode url_proto(char **url, config->synthetic_error = TRUE; } else +#endif /* !CURL_DISABLE_IPFS */ proto = proto_token(schemep); curl_free(schemep);