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

@ -54,13 +54,27 @@
#define PORT_MQTT 1883
#ifdef USE_WEBSOCKETS
/* CURLPROTO_GOPHERS (29) is the highest publicly used protocol bit number,
* the rest are internal information. If we use higher bits we only do this on
* platforms that have a >= 64 bit type and then we use such a type for the
* protocol fields in the protocol handler.
*/
#define CURLPROTO_WS (1<<30)
#define CURLPROTO_WSS (1LL<<31)
/* This type should be bumped to a curl_off_t once we need bit 32 or higher */
typedef unsigned int curl_prot_t;
#else
#define CURLPROTO_WS 0
#define CURLPROTO_WSS 0
typedef unsigned int curl_prot_t;
#endif
/* This mask is for all the old protocols that are provided and defined in the
public header and shall exclude protocols added since which are not exposed
in the API */
#define CURLPROTO_MASK (0x3ffffff)
#define DICT_MATCH "/MATCH:"
#define DICT_MATCH2 "/M:"
#define DICT_MATCH3 "/FIND:"
@ -787,10 +801,10 @@ struct Curl_handler {
void (*attach)(struct Curl_easy *data, struct connectdata *conn);
int defport; /* Default port. */
unsigned int protocol; /* See CURLPROTO_* - this needs to be the single
specific protocol bit */
unsigned int family; /* single bit for protocol family; basically the
non-TLS name of the protocol this is */
curl_prot_t protocol; /* See CURLPROTO_* - this needs to be the single
specific protocol bit */
curl_prot_t family; /* single bit for protocol family; basically the
non-TLS name of the protocol this is */
unsigned int flags; /* Extra particular characteristics, see PROTOPT_* */
};
@ -1345,7 +1359,7 @@ struct UrlState {
This is strdup()ed data. */
char *first_host;
int first_remote_port;
unsigned int first_remote_protocol;
curl_prot_t first_remote_protocol;
int retrycount; /* number of retries on a new connection */
struct Curl_ssl_session *session; /* array of 'max_ssl_sessions' size */
@ -1776,8 +1790,8 @@ struct UserDefined {
#ifdef ENABLE_IPV6
unsigned int scope_id; /* Scope id for IPv6 */
#endif
curl_off_t allowed_protocols;
curl_off_t redir_protocols;
curl_prot_t allowed_protocols;
curl_prot_t redir_protocols;
unsigned int mime_options; /* Mime option flags. */
#ifndef CURL_DISABLE_RTSP