From: Viktor Szakats Date: Tue, 1 Jul 2025 15:15:45 +0000 (+0200) Subject: CURLOPT: bump `CURLFTP*` enums to `long`, drop casts X-Git-Tag: curl-8_16_0~367 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=430f9b03fd2b11804e6ae6147efaefb1f5a9916d;p=thirdparty%2Fcurl.git CURLOPT: bump `CURLFTP*` enums to `long`, drop casts 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 --- diff --git a/docs/libcurl/opts/CURLOPT_FTP_CREATE_MISSING_DIRS.md b/docs/libcurl/opts/CURLOPT_FTP_CREATE_MISSING_DIRS.md index 055e496665..ea7d49d776 100644 --- a/docs/libcurl/opts/CURLOPT_FTP_CREATE_MISSING_DIRS.md +++ b/docs/libcurl/opts/CURLOPT_FTP_CREATE_MISSING_DIRS.md @@ -21,11 +21,9 @@ CURLOPT_FTP_CREATE_MISSING_DIRS - create missing directories for FTP and SFTP ~~~c #include -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); diff --git a/include/curl/curl.h b/include/curl/curl.h index cb4e523c38..258cc28bec 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -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 */ diff --git a/lib/ftp.c b/lib/ftp.c index c3de29f0c4..2fc76c8d08 100644 --- 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)"); diff --git a/lib/setopt.c b/lib/setopt.c index d39d574aa7..5464d07f79 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -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: /* diff --git a/src/config2setopts.c b/src/config2setopts.c index 92a9b19e10..07a0976d30 100644 --- a/src/config2setopts.c +++ b/src/config2setopts.c @@ -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); diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index bd32ab2d42..8c1dd8d269 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -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. diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index c037189610..4c7c5a7906 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -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; diff --git a/src/tool_paramhlp.h b/src/tool_paramhlp.h index 0be9c8968c..16d4311524 100644 --- a/src/tool_paramhlp.h +++ b/src/tool_paramhlp.h @@ -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); diff --git a/tests/libtest/lib539.c b/tests/libtest/lib539.c index f2c302cf4e..4b333807e3 100644 --- a/tests/libtest/lib539.c +++ b/tests/libtest/lib539.c @@ -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); diff --git a/tests/libtest/lib661.c b/tests/libtest/lib661.c index 84b867c6a1..8f14d27b6a 100644 --- a/tests/libtest/lib661.c +++ b/tests/libtest/lib661.c @@ -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);