urldata: use a curl_prot_t type for storing protocol bits

This internal-use-only storage type can be bumped to a curl_off_t once
we need to use bit 32 as the previous 'unsigned int' can no longer hold
them all then.

The websocket protocols take bit 30 and 31 so they are the last ones
that fit within 32 bits - but cannot properly be exported through APIs
since those use *signed* 32 bit types (long) in places.

Closes #9481
This commit is contained in:
Daniel Stenberg 2022-09-12 09:57:01 +02:00
parent 0f52dd5fd5
commit cd5ca80f00
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 38 additions and 19 deletions

View file

@ -148,12 +148,12 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
#define C_SSLVERSION_VALUE(x) (x & 0xffff)
#define C_SSLVERSION_MAX_VALUE(x) (x & 0xffff0000)
static CURLcode protocol2num(char *str, curl_off_t *val)
static CURLcode protocol2num(char *str, curl_prot_t *val)
{
bool found_comma = FALSE;
static struct scheme {
const char *name;
curl_off_t bit;
curl_prot_t bit;
} const protos[] = {
{ "dict", CURLPROTO_DICT },
{ "file", CURLPROTO_FILE },
@ -2649,31 +2649,35 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
transfer, which thus helps the app which takes URLs from users or other
external inputs and want to restrict what protocol(s) to deal
with. Defaults to CURLPROTO_ALL. */
data->set.allowed_protocols = (curl_off_t)va_arg(param, long);
data->set.allowed_protocols = (curl_prot_t)va_arg(param, long);
break;
case CURLOPT_REDIR_PROTOCOLS:
/* set the bitmask for the protocols that libcurl is allowed to follow to,
as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
to be set in both bitmasks to be allowed to get redirected to. */
data->set.redir_protocols = (curl_off_t)va_arg(param, long);
data->set.redir_protocols = (curl_prot_t)va_arg(param, long);
break;
case CURLOPT_PROTOCOLS_STR:
case CURLOPT_PROTOCOLS_STR: {
curl_prot_t prot;
argptr = va_arg(param, char *);
result = protocol2num(argptr, &bigsize);
result = protocol2num(argptr, &prot);
if(result)
return result;
data->set.allowed_protocols = bigsize;
data->set.allowed_protocols = prot;
break;
}
case CURLOPT_REDIR_PROTOCOLS_STR:
case CURLOPT_REDIR_PROTOCOLS_STR: {
curl_prot_t prot;
argptr = va_arg(param, char *);
result = protocol2num(argptr, &bigsize);
result = protocol2num(argptr, &prot);
if(result)
return result;
data->set.redir_protocols = bigsize;
data->set.redir_protocols = prot;
break;
}
case CURLOPT_DEFAULT_PROTOCOL:
/* Set the protocol to use when the URL doesn't include any protocol */