]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: detect ECH support dynamically, not at build time
authorDaniel Stenberg <daniel@haxx.se>
Thu, 24 Oct 2024 13:49:51 +0000 (15:49 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 24 Oct 2024 14:10:39 +0000 (16:10 +0200)
Closes #15402

src/tool_cfgable.c
src/tool_cfgable.h
src/tool_getparam.c
src/tool_libinfo.c
src/tool_libinfo.h
src/tool_operate.c

index 48808adb2701bcd6e7680c758903c2d21a014742..d7ee7b1b224a9b3fe5dc8add68319fd884fa94df 100644 (file)
@@ -173,21 +173,14 @@ static void free_config_fields(struct OperationConfig *config)
   Curl_safefree(config->preproxy);
   Curl_safefree(config->proxy_service_name);
   Curl_safefree(config->service_name);
-
   Curl_safefree(config->ftp_account);
   Curl_safefree(config->ftp_alternative_to_user);
-
   Curl_safefree(config->aws_sigv4);
   Curl_safefree(config->proto_str);
   Curl_safefree(config->proto_redir_str);
-#ifdef USE_ECH
   Curl_safefree(config->ech);
-  config->ech = NULL;
   Curl_safefree(config->ech_config);
-  config->ech_config = NULL;
   Curl_safefree(config->ech_public);
-  config->ech_public = NULL;
-#endif
 }
 
 void config_free(struct OperationConfig *config)
index 257a8d2c666cca998b3dc77f5976fb7c09ab3313..46f47670d6ed612c42b61318d9ba81a6e5a1a835 100644 (file)
@@ -306,12 +306,9 @@ struct OperationConfig {
   bool rm_partial;                /* on error, remove partially written output
                                      files */
   bool skip_existing;
-#ifdef USE_ECH
   char *ech;                      /* Config set by --ech keywords */
   char *ech_config;               /* Config set by "--ech esl:" option */
   char *ech_public;               /* Config set by "--ech pn:" option */
-#endif
-
 };
 
 struct GlobalConfig {
index da42a4f62d839985f0c0ba2f2419e2989bb3da68..0ce790f30a15a8c7115c6ddb0ed6ff970a45679e 100644 (file)
@@ -1917,13 +1917,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
         err = PARAM_ENGINES_REQUESTED;
       }
       break;
-#ifndef USE_ECH
-    case C_ECH: /* --ech, not implemented by default */
-      err = PARAM_LIBCURL_DOESNT_SUPPORT;
-      break;
-#else
     case C_ECH: /* --ech */
-      if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) {
+      if(!feature_ech)
+        err = PARAM_LIBCURL_DOESNT_SUPPORT;
+      else if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) {
         /* a public_name */
         err = getstr(&config->ech_public, nextarg, DENY_BLANK);
       }
@@ -1967,7 +1964,6 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
       err = getstr(&config->ech, nextarg, DENY_BLANK);
     }
     break;
-#endif
     case C_CAPATH: /* --capath */
       err = getstr(&config->capath, nextarg, DENY_BLANK);
       break;
index 34b79f5eb76faf14c6fce7286828dff667b19231..f6053e84003ee9a39813f89e8a65594bb1dc376c 100644 (file)
@@ -83,6 +83,7 @@ bool feature_spnego = FALSE;
 bool feature_ssl = FALSE;
 bool feature_tls_srp = FALSE;
 bool feature_zstd = FALSE;
+bool feature_ech = FALSE;
 
 static struct feature_name_presentp {
   const char   *feature_name;
@@ -95,6 +96,7 @@ static struct feature_name_presentp {
   {"brotli",         &feature_brotli,     CURL_VERSION_BROTLI},
   {"CharConv",       NULL,                CURL_VERSION_CONV},
   {"Debug",          NULL,                CURL_VERSION_DEBUG},
+  {"ECH",            &feature_ech,        0},
   {"gsasl",          NULL,                CURL_VERSION_GSASL},
   {"GSS-API",        NULL,                CURL_VERSION_GSSAPI},
   {"HSTS",           &feature_hsts,       CURL_VERSION_HSTS},
index ad9c195dc056661b8257fe4bb53b898ea1ce6d75..0d176699e81d4613a654e85594fd8b30f11f8354 100644 (file)
@@ -61,6 +61,7 @@ extern bool feature_spnego;
 extern bool feature_ssl;
 extern bool feature_tls_srp;
 extern bool feature_zstd;
+extern bool feature_ech;
 
 CURLcode get_libcurl_info(void);
 const char *proto_token(const char *proto);
index fd10e39ba056f71810ecacd5c9d1bf0c5db53653..b98ec0139431bf098d055fc60914936ec0ec3112 100644 (file)
@@ -1734,15 +1734,15 @@ static CURLcode config2setopts(struct GlobalConfig *global,
   if(config->hsts)
     my_setopt_str(curl, CURLOPT_HSTS, config->hsts);
 
-#ifdef USE_ECH
-  /* only if enabled in configure */
-  if(config->ech) /* only if set (optional) */
-    my_setopt_str(curl, CURLOPT_ECH, config->ech);
-  if(config->ech_public) /* only if set (optional) */
-    my_setopt_str(curl, CURLOPT_ECH, config->ech_public);
-  if(config->ech_config) /* only if set (optional) */
-    my_setopt_str(curl, CURLOPT_ECH, config->ech_config);
-#endif
+  if(feature_ech) {
+    /* only if enabled in libcurl */
+    if(config->ech) /* only if set (optional) */
+      my_setopt_str(curl, CURLOPT_ECH, config->ech);
+    if(config->ech_public) /* only if set (optional) */
+      my_setopt_str(curl, CURLOPT_ECH, config->ech_public);
+    if(config->ech_config) /* only if set (optional) */
+      my_setopt_str(curl, CURLOPT_ECH, config->ech_config);
+  }
 
   /* new in 8.9.0 */
   if(config->ip_tos > 0 || config->vlan_priority > 0) {