From: Daniel Stenberg Date: Tue, 25 Feb 2025 16:33:17 +0000 (+0100) Subject: curl.h: change some enums to defines with L suffix X-Git-Tag: curl-8_13_0~348 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ec00372a1fc7f27cd3a6c43e29007400acfe2b6;p=thirdparty%2Fcurl.git curl.h: change some enums to defines with L suffix To help applications do the right thing easier, change some enum values into defines with L suffixes so that they get the corect type (long) easier when used with curl_easy_setopt(). This also fixes a few of our own libtests. To reduce the risk that this change breaks the compile for any existing users, the previously provided enums are still provided, but the values to use are not defined by the enums. This change "magically" fixes a few RTSP test failures we have had on 64-bit platforms because those options were not see using longs properly. Closes #16482 --- diff --git a/include/curl/curl.h b/include/curl/curl.h index b72d031700..99c57f2169 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -2302,32 +2302,33 @@ enum { /* * Public API enums for RTSP requests */ -enum { - CURL_RTSPREQ_NONE, /* first in list */ - CURL_RTSPREQ_OPTIONS, - CURL_RTSPREQ_DESCRIBE, - CURL_RTSPREQ_ANNOUNCE, - CURL_RTSPREQ_SETUP, - CURL_RTSPREQ_PLAY, - CURL_RTSPREQ_PAUSE, - CURL_RTSPREQ_TEARDOWN, - CURL_RTSPREQ_GET_PARAMETER, - CURL_RTSPREQ_SET_PARAMETER, - CURL_RTSPREQ_RECORD, - CURL_RTSPREQ_RECEIVE, - CURL_RTSPREQ_LAST /* last in list */ -}; + +#define CURL_RTSPREQ_NONE 0L +#define CURL_RTSPREQ_OPTIONS 1L +#define CURL_RTSPREQ_DESCRIBE 2L +#define CURL_RTSPREQ_ANNOUNCE 3L +#define CURL_RTSPREQ_SETUP 4L +#define CURL_RTSPREQ_PLAY 5L +#define CURL_RTSPREQ_PAUSE 6L +#define CURL_RTSPREQ_TEARDOWN 7L +#define CURL_RTSPREQ_GET_PARAMETER 8L +#define CURL_RTSPREQ_SET_PARAMETER 9L +#define CURL_RTSPREQ_RECORD 10L +#define CURL_RTSPREQ_RECEIVE 11L +#define CURL_RTSPREQ_LAST 12L /* not used */ /* These enums are for use with the CURLOPT_NETRC option. */ +#define CURL_NETRC_IGNORED 0L /* The .netrc will never be read. + This is the default. */ +#define CURL_NETRC_OPTIONAL 1L /* A user:password in the URL will be preferred + to one in the .netrc. */ +#define CURL_NETRC_REQUIRED 2L /* A user:password in the URL will be ignored. + Unless one is set programmatically, the + .netrc will be queried. */ enum CURL_NETRC_OPTION { - CURL_NETRC_IGNORED, /* The .netrc will never be read. - * This is the default. */ - CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred - * to one in the .netrc. */ - CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. - * Unless one is set programmatically, the .netrc - * will be queried. */ - CURL_NETRC_LAST + /* we set a single member here, just to make sure we still provide the enum, + but the values to use are defined above with L suffixes */ + CURL_NETRC_LAST = 3 }; #define CURL_SSLVERSION_DEFAULT 0 @@ -2351,10 +2352,13 @@ enum CURL_NETRC_OPTION { /* never use, keep last */ #define CURL_SSLVERSION_MAX_LAST (CURL_SSLVERSION_LAST << 16) +#define CURL_TLSAUTH_NONE 0L +#define CURL_TLSAUTH_SRP 1L + enum CURL_TLSAUTH { - CURL_TLSAUTH_NONE, - CURL_TLSAUTH_SRP, - CURL_TLSAUTH_LAST /* never use, keep last */ + /* we set a single member here, just to make sure we still provide the enum, + but the values to use are defined above with L suffixes */ + CURL_TLSAUTH_LAST = 2 }; /* symbols to use with CURLOPT_POSTREDIR. @@ -2369,14 +2373,16 @@ enum CURL_TLSAUTH { #define CURL_REDIR_POST_ALL \ (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) -typedef enum { - CURL_TIMECOND_NONE, - - CURL_TIMECOND_IFMODSINCE, - CURL_TIMECOND_IFUNMODSINCE, - CURL_TIMECOND_LASTMOD, +#define CURL_TIMECOND_NONE 0L +#define CURL_TIMECOND_IFMODSINCE 1L +#define CURL_TIMECOND_IFUNMODSINCE 2L +#define CURL_TIMECOND_LASTMOD 3L - CURL_TIMECOND_LAST +typedef enum { + /* we set a single member here, just to make sure we still provide + the enum typedef, but the values to use are defined above with L + suffixes */ + CURL_TIMECOND_LAST = 4 } curl_TimeCond; /* Special size_t value signaling a null-terminated string. */ diff --git a/lib/setopt.c b/lib/setopt.c index 9c64406401..ef05cfb6ef 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -438,7 +438,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, */ if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST)) return CURLE_BAD_FUNCTION_ARGUMENT; - data->set.timecondition = (unsigned char)(curl_TimeCond)arg; + data->set.timecondition = (unsigned char)arg; break; case CURLOPT_TIMEVALUE: /* diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index 11f14d7715..950ef3862f 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -200,7 +200,7 @@ struct OperationConfig { long expect100timeout_ms; long happy_eyeballs_timeout_ms; /* happy eyeballs timeout in milliseconds. 0 is valid. default: CURL_HET_DEFAULT. */ - curl_TimeCond timecond; + unsigned long timecond; HttpReq httpreq; int proxyver; /* set to CURLPROXY_HTTP* define */ int ftp_ssl_ccc_mode; diff --git a/src/tool_operate.c b/src/tool_operate.c index 95a1d0e1e2..1c8f787f64 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1397,7 +1397,7 @@ static CURLcode config2setopts(struct GlobalConfig *global, my_setopt(curl, CURLOPT_COOKIESESSION, config->cookiesession ? 1L : 0L); - my_setopt_enum(curl, CURLOPT_TIMECONDITION, (long)config->timecond); + my_setopt_enum(curl, CURLOPT_TIMECONDITION, config->timecond); my_setopt(curl, CURLOPT_TIMEVALUE_LARGE, config->condtime); my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest); customrequest_helper(config, config->httpreq, config->customrequest);