]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ipfs: add options to disable
authorViktor Szakats <commit@vsz.me>
Sun, 8 Sep 2024 10:26:45 +0000 (12:26 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 21 Sep 2024 10:08:32 +0000 (12:08 +0200)
- CPPFLAGS: `-DCURL_DISABLE_IPFS`
- configure: `--disable-ipfs`
- cmake: `-DCURL_DISABLE_IPFS=ON`

Fixes #14824
Closes #14827

12 files changed:
CMakeLists.txt
configure.ac
docs/CURL-DISABLE.md
lib/curl_config.h.cmake
src/tool_cfgable.c
src/tool_cfgable.h
src/tool_getparam.c
src/tool_help.c
src/tool_ipfs.c
src/tool_ipfs.h
src/tool_libinfo.c
src/tool_operate.c

index 7f6af21410c778e996969ccbb33460ea918712ea..498e6cdf189c9147fb64c0220425b271df143582 100644 (file)
@@ -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)
index d6605fbb7c6c0f8d6fa7284fe6357e1f3348035b..f922c28d51c67154d428b9c72ee49db3e65b72d8 100644 (file)
@@ -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}
index 6080851dd5e280b861ff73f632183f7e09d3489b..32ae025fc4a146b623ad8e7ef27280d9f96ad6ba 100644 (file)
@@ -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.
index 304e528a71fd702c8f0a8ef6ba61bb59ea4557bb..39609bc38ae7cca0b045ec3f3d6b3cc996daf2e9 100644 (file)
 /* 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
 
index 5564e250d33782047237cea48880b32ab3853b05..48808adb2701bcd6e7680c758903c2d21a014742 100644 (file)
@@ -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);
index 729cd5241a620c842b32d9b303ed9eaf0426acd5..d9099c329ddb251ba74965e8754d1a23f7e19a48 100644 (file)
@@ -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;
index 282f1893a40cffe87ef517cb7041a1125f1ed67b..7a38992a9e86a31e2d95384f4b828e4fb0cd665b 100644 (file)
@@ -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;
index 8c655c4b2b22994a59932edae99de6c1eff862b8..57b14a3b07fa0be2d042bb4e8ab0ad4daf028a1b 100644 (file)
@@ -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 */
   }
index 09bff49067a270c7411c72a2798a43b47e66b6a1..46bd8e146306f7bc91a8035a3ef439f040db6b7a 100644 (file)
@@ -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 */
index 9c8a83e3b34ac0c0e0bca81002c606d6f4fc2f02..31d8019fa2b839a5daebe29ed49d1a8e3a492a23 100644 (file)
  ***************************************************************************/
 #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 */
index 4bc22217f9dce5e0a3de0e0746d97c6e3c345a6b..34b79f5eb76faf14c6fce7286828dff667b19231 100644 (file)
@@ -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;
index c8ea8ed4588d899686f2784030e20ada6b55a5f1..b9b7bfdc382390542a6d5c4b286e6b424684ea3f 100644 (file)
@@ -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);