]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
CURLOPT: bump `CURLFTP*` enums to `long`, drop casts
authorViktor Szakats <commit@vsz.me>
Tue, 1 Jul 2025 15:15:45 +0000 (17:15 +0200)
committerViktor Szakats <commit@vsz.me>
Mon, 28 Jul 2025 08:32:13 +0000 (10:32 +0200)
This patch bumps the size of these constants from `int` to `long`, while
keeping their actual values the same. It may cause incompatibilities in
user code, requiring the bump of holder variables and/or adding casts:

- CURLFTP_CREATE_DIR
- CURLFTP_CREATE_DIR_NONE
- CURLFTP_CREATE_DIR_RETRY
- CURLFTPAUTH_DEFAULT
- CURLFTPAUTH_SSL
- CURLFTPAUTH_TLS
- CURLFTPMETHOD_DEFAULT
- CURLFTPMETHOD_MULTICWD
- CURLFTPMETHOD_NOCWD
- CURLFTPMETHOD_SINGLECWD
- CURLFTPSSL_CCC_ACTIVE
- CURLFTPSSL_CCC_NONE
- CURLFTPSSL_CCC_PASSIVE

Also:
- keep existing casts within the documentation to make sure it applies
  to older curl versions as well.

Closes #17797

docs/libcurl/opts/CURLOPT_FTP_CREATE_MISSING_DIRS.md
include/curl/curl.h
lib/ftp.c
lib/setopt.c
src/config2setopts.c
src/tool_cfgable.h
src/tool_paramhlp.c
src/tool_paramhlp.h
tests/libtest/lib539.c
tests/libtest/lib661.c

index 055e496665248f11fc34b1625137669fd7a98482..ea7d49d7765b3f7e5b6b8ccdfa912b11a9cc4aa3 100644 (file)
@@ -21,11 +21,9 @@ CURLOPT_FTP_CREATE_MISSING_DIRS - create missing directories for FTP and SFTP
 ~~~c
 #include <curl/curl.h>
 
-typedef enum {
-  CURLFTP_CREATE_DIR_NONE,
-  CURLFTP_CREATE_DIR,
-  CURLFTP_CREATE_DIR_RETRY
-} curl_ftpcreatedir;
+#define CURLFTP_CREATE_DIR_NONE  0L
+#define CURLFTP_CREATE_DIR       1L
+#define CURLFTP_CREATE_DIR_RETRY 2L
 
 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FTP_CREATE_MISSING_DIRS,
                           long create);
index cb4e523c38b95c7559c45c2bcb416dbdf8a1dd4b..258cc28becff1eb46c9100a7163f2b39d186725e 100644 (file)
@@ -979,39 +979,44 @@ typedef enum {
 #endif /* !CURL_NO_OLDIES */
 
 /* parameter for the CURLOPT_FTP_SSL_CCC option */
+#define CURLFTPSSL_CCC_NONE    0L /* do not send CCC */
+#define CURLFTPSSL_CCC_PASSIVE 1L /* Let the server initiate the shutdown */
+#define CURLFTPSSL_CCC_ACTIVE  2L /* Initiate the shutdown */
+
 typedef enum {
-  CURLFTPSSL_CCC_NONE,    /* do not send CCC */
-  CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */
-  CURLFTPSSL_CCC_ACTIVE,  /* Initiate the shutdown */
-  CURLFTPSSL_CCC_LAST     /* not an option, never use */
+  CURLFTPSSL_CCC_LAST = 3 /* not an option, never use */
 } curl_ftpccc;
 
 /* parameter for the CURLOPT_FTPSSLAUTH option */
+#define CURLFTPAUTH_DEFAULT 0L /* let libcurl decide */
+#define CURLFTPAUTH_SSL     1L /* use "AUTH SSL" */
+#define CURLFTPAUTH_TLS     2L /* use "AUTH TLS" */
+
 typedef enum {
-  CURLFTPAUTH_DEFAULT, /* let libcurl decide */
-  CURLFTPAUTH_SSL,     /* use "AUTH SSL" */
-  CURLFTPAUTH_TLS,     /* use "AUTH TLS" */
-  CURLFTPAUTH_LAST /* not an option, never use */
+  CURLFTPAUTH_LAST = 3 /* not an option, never use */
 } curl_ftpauth;
 
 /* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */
+#define CURLFTP_CREATE_DIR_NONE  0L /* do NOT create missing dirs! */
+#define CURLFTP_CREATE_DIR       1L /* (FTP/SFTP) if CWD fails, try MKD and
+                                       then CWD again if MKD succeeded, for
+                                       SFTP this does similar magic */
+#define CURLFTP_CREATE_DIR_RETRY 2L /* (FTP only) if CWD fails, try MKD and
+                                       then CWD again even if MKD failed! */
+
 typedef enum {
-  CURLFTP_CREATE_DIR_NONE,  /* do NOT create missing dirs! */
-  CURLFTP_CREATE_DIR,       /* (FTP/SFTP) if CWD fails, try MKD and then CWD
-                               again if MKD succeeded, for SFTP this does
-                               similar magic */
-  CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD
-                               again even if MKD failed! */
-  CURLFTP_CREATE_DIR_LAST   /* not an option, never use */
+  CURLFTP_CREATE_DIR_LAST = 3 /* not an option, never use */
 } curl_ftpcreatedir;
 
 /* parameter for the CURLOPT_FTP_FILEMETHOD option */
+#define CURLFTPMETHOD_DEFAULT   0L /* let libcurl pick */
+#define CURLFTPMETHOD_MULTICWD  1L /* single CWD operation for each path
+                                      part */
+#define CURLFTPMETHOD_NOCWD     2L /* no CWD at all */
+#define CURLFTPMETHOD_SINGLECWD 3L /* one CWD to full dir, then work on file */
+
 typedef enum {
-  CURLFTPMETHOD_DEFAULT,   /* let libcurl pick */
-  CURLFTPMETHOD_MULTICWD,  /* single CWD operation for each path part */
-  CURLFTPMETHOD_NOCWD,     /* no CWD at all */
-  CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */
-  CURLFTPMETHOD_LAST       /* not an option, never use */
+  CURLFTPMETHOD_LAST = 4 /* not an option, never use */
 } curl_ftpmethod;
 
 /* bitmask defines for CURLOPT_HEADEROPT */
index c3de29f0c4a2ce104b87b5bbff916e166e820189..2fc76c8d08191e89a6d419e56666bf31f2ea0526 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2749,7 +2749,7 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data,
            requested. Try an FTPS connection now */
 
         ftpc->count3 = 0;
-        switch(data->set.ftpsslauth) {
+        switch((long)data->set.ftpsslauth) {
         case CURLFTPAUTH_DEFAULT:
         case CURLFTPAUTH_SSL:
           ftpc->count2 = 1; /* add one to get next */
@@ -2868,7 +2868,7 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data,
          * server, but we do not send one. Let's hope other servers do
          * the same... */
         result = Curl_ssl_cfilter_remove(data, FIRSTSOCKET,
-          (data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE));
+          (data->set.ftp_ccc == (unsigned char)CURLFTPSSL_CCC_ACTIVE));
 
         if(result)
           failf(data, "Failed to clear the command channel (CCC)");
index d39d574aa71d9ff5aea6e3b45ee57c20ab69ccfc..5464d07f794fcbb54cd16ac253ebe4ec4fdbba7f 100644 (file)
@@ -900,7 +900,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
      */
     if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
       return CURLE_BAD_FUNCTION_ARGUMENT;
-    data->set.ftpsslauth = (unsigned char)(curl_ftpauth)arg;
+    data->set.ftpsslauth = (unsigned char)arg;
     break;
   case CURLOPT_ACCEPTTIMEOUT_MS:
     /*
index 92a9b19e100a021f21792dc75b04449da7b23313..07a0976d307048a71873f8344e9602c3ccd9343c 100644 (file)
@@ -653,7 +653,7 @@ static CURLcode ftp_setopts(struct OperationConfig *config, CURL *curl)
 
   /* new in curl 7.16.1 */
   if(config->ftp_ssl_ccc)
-    my_setopt_enum(curl, CURLOPT_FTP_SSL_CCC, (long)config->ftp_ssl_ccc_mode);
+    my_setopt_enum(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
 
   my_setopt_str(curl, CURLOPT_FTP_ACCOUNT, config->ftp_account);
 
index bd32ab2d42a7d548216d00574b581772d25fbf8d..8c1dd8d269d65cf3639cac179032647686f262d6 100644 (file)
@@ -226,8 +226,8 @@ struct OperationConfig {
   unsigned long timecond;
   HttpReq httpreq;
   long proxyver;             /* set to CURLPROXY_HTTP* define */
-  int ftp_ssl_ccc_mode;
-  int ftp_filemethod;
+  long ftp_ssl_ccc_mode;
+  long ftp_filemethod;
   enum {
     CLOBBER_DEFAULT, /* Provides compatibility with previous versions of curl,
                         by using the default behavior for -o, -O, and -J.
index c037189610c26a56963338af24f45fab442b35f9..4c7c5a7906c2b0ffa6af6335aa33eaf5910463d5 100644 (file)
@@ -620,7 +620,7 @@ ParameterError add2list(struct curl_slist **list, const char *ptr)
   return PARAM_OK;
 }
 
-int ftpfilemethod(struct OperationConfig *config, const char *str)
+long ftpfilemethod(struct OperationConfig *config, const char *str)
 {
   if(curl_strequal("singlecwd", str))
     return CURLFTPMETHOD_SINGLECWD;
@@ -635,7 +635,7 @@ int ftpfilemethod(struct OperationConfig *config, const char *str)
   return CURLFTPMETHOD_MULTICWD;
 }
 
-int ftpcccmethod(struct OperationConfig *config, const char *str)
+long ftpcccmethod(struct OperationConfig *config, const char *str)
 {
   if(curl_strequal("passive", str))
     return CURLFTPSSL_CCC_PASSIVE;
index 0be9c8968cb9d8b054834007e1611f6294983eb1..16d4311524e2710955576620aec7ac08e90a63a3 100644 (file)
@@ -58,9 +58,9 @@ CURLcode get_args(struct OperationConfig *config, const size_t i);
 
 ParameterError add2list(struct curl_slist **list, const char *ptr);
 
-int ftpfilemethod(struct OperationConfig *config, const char *str);
+long ftpfilemethod(struct OperationConfig *config, const char *str);
 
-int ftpcccmethod(struct OperationConfig *config, const char *str);
+long ftpcccmethod(struct OperationConfig *config, const char *str);
 
 long delegation(struct OperationConfig *config, const char *str);
 
index f2c302cf4e455bdd2ce85960af388c6bb9c1882b..4b333807e3e4eec867b8ee5016a6b09fc61b6c2b 100644 (file)
@@ -49,7 +49,7 @@ static CURLcode test_lib539(char *URL)
    */
   test_setopt(curl, CURLOPT_URL, URL);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
+  test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_SINGLECWD);
 
   res = curl_easy_perform(curl);
   if(res == CURLE_OK) {
@@ -70,7 +70,7 @@ static CURLcode test_lib539(char *URL)
     }
 
     test_setopt(curl, CURLOPT_URL, libtest_arg2);
-    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
     test_setopt(curl, CURLOPT_QUOTE, slist);
 
     res = curl_easy_perform(curl);
index 84b867c6a138e69fc548f86c3b28137857a3ede6..8f14d27b6afd31fc0a78e079b588e957617c34a9 100644 (file)
@@ -50,7 +50,7 @@ static CURLcode test_lib661(char *URL)
    test_setopt(curl, CURLOPT_URL, newURL);
    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_SINGLECWD);
    res = curl_easy_perform(curl);
    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
      goto test_cleanup;
@@ -77,7 +77,7 @@ static CURLcode test_lib661(char *URL)
    test_setopt(curl, CURLOPT_URL, newURL);
    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
    res = curl_easy_perform(curl);
    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
      goto test_cleanup;
@@ -86,7 +86,7 @@ static CURLcode test_lib661(char *URL)
    curl_free(newURL);
    newURL = curl_maprintf("%s/folderB/661", URL);
    test_setopt(curl, CURLOPT_URL, newURL);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_SINGLECWD);
    res = curl_easy_perform(curl);
    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
      goto test_cleanup;
@@ -94,7 +94,7 @@ static CURLcode test_lib661(char *URL)
    curl_free(newURL);
    newURL = curl_maprintf("%s/folderA/661", URL);
    test_setopt(curl, CURLOPT_URL, newURL);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
    res = curl_easy_perform(curl);
    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
      goto test_cleanup;
@@ -119,7 +119,7 @@ static CURLcode test_lib661(char *URL)
    test_setopt(curl, CURLOPT_URL, URL);
    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    test_setopt(curl, CURLOPT_NOBODY, 1L);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
    test_setopt(curl, CURLOPT_QUOTE, slist);
    res = curl_easy_perform(curl);
    if(res)
@@ -138,7 +138,7 @@ static CURLcode test_lib661(char *URL)
    test_setopt(curl, CURLOPT_URL, URL);
    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    test_setopt(curl, CURLOPT_NOBODY, 1L);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_SINGLECWD);
    test_setopt(curl, CURLOPT_QUOTE, slist);
    res = curl_easy_perform(curl);
    if(res)
@@ -151,7 +151,7 @@ static CURLcode test_lib661(char *URL)
    test_setopt(curl, CURLOPT_URL, URL);
    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    test_setopt(curl, CURLOPT_NOBODY, 1L);
-   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
+   test_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
    test_setopt(curl, CURLOPT_QUOTE, slist);
    res = curl_easy_perform(curl);