diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-09-21 13:45:24 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-09-21 23:30:16 +0200 |
commit | 6434a73984b2527194d6409021693c7032d17570 (patch) | |
tree | 0e13b44283e01d45f2889dd8565e0ea25d4dfcd1 | |
parent | 2e645e21de1b3faef108569a8819778b6755c2f0 (diff) | |
download | curl-6434a73984b2527194d6409021693c7032d17570.tar.gz |
Curl_handler: add 'family' to each protocol
Makes get_protocol_family() faster and it moves the knowledge about the
"families" to each protocol handler, where it belongs.
Closes #5986
-rw-r--r-- | lib/curl_rtmp.c | 8 | ||||
-rw-r--r-- | lib/dict.c | 3 | ||||
-rw-r--r-- | lib/file.c | 1 | ||||
-rw-r--r-- | lib/ftp.c | 2 | ||||
-rw-r--r-- | lib/gopher.c | 1 | ||||
-rw-r--r-- | lib/http.c | 2 | ||||
-rw-r--r-- | lib/http2.c | 2 | ||||
-rw-r--r-- | lib/imap.c | 2 | ||||
-rw-r--r-- | lib/ldap.c | 2 | ||||
-rw-r--r-- | lib/mqtt.c | 1 | ||||
-rw-r--r-- | lib/openldap.c | 4 | ||||
-rw-r--r-- | lib/pop3.c | 2 | ||||
-rw-r--r-- | lib/rtsp.c | 1 | ||||
-rw-r--r-- | lib/smb.c | 2 | ||||
-rw-r--r-- | lib/smtp.c | 2 | ||||
-rw-r--r-- | lib/telnet.c | 1 | ||||
-rw-r--r-- | lib/tftp.c | 1 | ||||
-rw-r--r-- | lib/url.c | 134 | ||||
-rw-r--r-- | lib/urldata.h | 2 | ||||
-rw-r--r-- | lib/vquic/ngtcp2.c | 1 | ||||
-rw-r--r-- | lib/vquic/quiche.c | 1 | ||||
-rw-r--r-- | lib/vssh/libssh.c | 2 | ||||
-rw-r--r-- | lib/vssh/libssh2.c | 2 |
23 files changed, 63 insertions, 116 deletions
diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index df8f2b1d9..32f11130a 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2012 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2010, Howard Chu, <hyc@highlandsun.com> * * This software is licensed as described in the file COPYING, which @@ -79,6 +79,7 @@ const struct Curl_handler Curl_handler_rtmp = { ZERO_NULL, /* connection_check */ PORT_RTMP, /* defport */ CURLPROTO_RTMP, /* protocol */ + CURLPROTO_RTMP, /* family */ PROTOPT_NONE /* flags*/ }; @@ -100,6 +101,7 @@ const struct Curl_handler Curl_handler_rtmpt = { ZERO_NULL, /* connection_check */ PORT_RTMPT, /* defport */ CURLPROTO_RTMPT, /* protocol */ + CURLPROTO_RTMPT, /* family */ PROTOPT_NONE /* flags*/ }; @@ -121,6 +123,7 @@ const struct Curl_handler Curl_handler_rtmpe = { ZERO_NULL, /* connection_check */ PORT_RTMP, /* defport */ CURLPROTO_RTMPE, /* protocol */ + CURLPROTO_RTMPE, /* family */ PROTOPT_NONE /* flags*/ }; @@ -142,6 +145,7 @@ const struct Curl_handler Curl_handler_rtmpte = { ZERO_NULL, /* connection_check */ PORT_RTMPT, /* defport */ CURLPROTO_RTMPTE, /* protocol */ + CURLPROTO_RTMPTE, /* family */ PROTOPT_NONE /* flags*/ }; @@ -163,6 +167,7 @@ const struct Curl_handler Curl_handler_rtmps = { ZERO_NULL, /* connection_check */ PORT_RTMPS, /* defport */ CURLPROTO_RTMPS, /* protocol */ + CURLPROTO_RTMP, /* family */ PROTOPT_NONE /* flags*/ }; @@ -184,6 +189,7 @@ const struct Curl_handler Curl_handler_rtmpts = { ZERO_NULL, /* connection_check */ PORT_RTMPS, /* defport */ CURLPROTO_RTMPTS, /* protocol */ + CURLPROTO_RTMPT, /* family */ PROTOPT_NONE /* flags*/ }; diff --git a/lib/dict.c b/lib/dict.c index f529b48f7..b6676aa84 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -90,7 +90,8 @@ const struct Curl_handler Curl_handler_dict = { ZERO_NULL, /* connection_check */ PORT_DICT, /* defport */ CURLPROTO_DICT, /* protocol */ - PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */ + CURLPROTO_DICT, /* family */ + PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */ }; static char *unescape_word(struct Curl_easy *data, const char *inputbuff) diff --git a/lib/file.c b/lib/file.c index cd3e49c33..c5ef6a195 100644 --- a/lib/file.c +++ b/lib/file.c @@ -112,6 +112,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* connection_check */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ + CURLPROTO_FILE, /* family */ PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */ }; @@ -170,6 +170,7 @@ const struct Curl_handler Curl_handler_ftp = { ZERO_NULL, /* connection_check */ PORT_FTP, /* defport */ CURLPROTO_FTP, /* protocol */ + CURLPROTO_FTP, /* family */ PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP | PROTOPT_WILDCARD /* flags */ @@ -199,6 +200,7 @@ const struct Curl_handler Curl_handler_ftps = { ZERO_NULL, /* connection_check */ PORT_FTPS, /* defport */ CURLPROTO_FTPS, /* protocol */ + CURLPROTO_FTP, /* family */ PROTOPT_SSL | PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD /* flags */ }; diff --git a/lib/gopher.c b/lib/gopher.c index b4811b289..4f5ba99bb 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -71,6 +71,7 @@ const struct Curl_handler Curl_handler_gopher = { ZERO_NULL, /* connection_check */ PORT_GOPHER, /* defport */ CURLPROTO_GOPHER, /* protocol */ + CURLPROTO_GOPHER, /* family */ PROTOPT_NONE /* flags */ }; diff --git a/lib/http.c b/lib/http.c index 8fcdd436d..748750ebb 100644 --- a/lib/http.c +++ b/lib/http.c @@ -125,6 +125,7 @@ const struct Curl_handler Curl_handler_http = { ZERO_NULL, /* connection_check */ PORT_HTTP, /* defport */ CURLPROTO_HTTP, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_CREDSPERREQUEST | /* flags */ PROTOPT_USERPWDCTRL }; @@ -151,6 +152,7 @@ const struct Curl_handler Curl_handler_https = { ZERO_NULL, /* connection_check */ PORT_HTTPS, /* defport */ CURLPROTO_HTTPS, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN_NPN | /* flags */ PROTOPT_USERPWDCTRL }; diff --git a/lib/http2.c b/lib/http2.c index f045d588f..925d9828b 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -300,6 +300,7 @@ static const struct Curl_handler Curl_handler_http2 = { http2_conncheck, /* connection_check */ PORT_HTTP, /* defport */ CURLPROTO_HTTP, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_STREAM /* flags */ }; @@ -321,6 +322,7 @@ static const struct Curl_handler Curl_handler_http2_ssl = { http2_conncheck, /* connection_check */ PORT_HTTP, /* defport */ CURLPROTO_HTTPS, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_STREAM /* flags */ }; diff --git a/lib/imap.c b/lib/imap.c index 39aa0af33..b9b14d10e 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -132,6 +132,7 @@ const struct Curl_handler Curl_handler_imap = { ZERO_NULL, /* connection_check */ PORT_IMAP, /* defport */ CURLPROTO_IMAP, /* protocol */ + CURLPROTO_IMAP, /* family */ PROTOPT_CLOSEACTION| /* flags */ PROTOPT_URLOPTIONS }; @@ -159,6 +160,7 @@ const struct Curl_handler Curl_handler_imaps = { ZERO_NULL, /* connection_check */ PORT_IMAPS, /* defport */ CURLPROTO_IMAPS, /* protocol */ + CURLPROTO_IMAP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ PROTOPT_URLOPTIONS }; diff --git a/lib/ldap.c b/lib/ldap.c index 512def659..eca7fac30 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -150,6 +150,7 @@ const struct Curl_handler Curl_handler_ldap = { ZERO_NULL, /* connection_check */ PORT_LDAP, /* defport */ CURLPROTO_LDAP, /* protocol */ + CURLPROTO_LDAP, /* family */ PROTOPT_NONE /* flags */ }; @@ -176,6 +177,7 @@ const struct Curl_handler Curl_handler_ldaps = { ZERO_NULL, /* connection_check */ PORT_LDAPS, /* defport */ CURLPROTO_LDAPS, /* protocol */ + CURLPROTO_LDAP, /* family */ PROTOPT_SSL /* flags */ }; #endif diff --git a/lib/mqtt.c b/lib/mqtt.c index b3b2b8c93..c0e9a2b75 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -86,6 +86,7 @@ const struct Curl_handler Curl_handler_mqtt = { ZERO_NULL, /* connection_check */ PORT_MQTT, /* defport */ CURLPROTO_MQTT, /* protocol */ + CURLPROTO_MQTT, /* family */ PROTOPT_NONE /* flags */ }; diff --git a/lib/openldap.c b/lib/openldap.c index 782d6a08e..2aff4f603 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -107,6 +107,7 @@ const struct Curl_handler Curl_handler_ldap = { ZERO_NULL, /* connection_check */ PORT_LDAP, /* defport */ CURLPROTO_LDAP, /* protocol */ + CURLPROTO_LDAP, /* family */ PROTOPT_NONE /* flags */ }; @@ -132,7 +133,8 @@ const struct Curl_handler Curl_handler_ldaps = { ZERO_NULL, /* readwrite */ ZERO_NULL, /* connection_check */ PORT_LDAPS, /* defport */ - CURLPROTO_LDAP, /* protocol */ + CURLPROTO_LDAPS, /* protocol */ + CURLPROTO_LDAP, /* family */ PROTOPT_SSL /* flags */ }; #endif diff --git a/lib/pop3.c b/lib/pop3.c index 9ff5c78fd..be2748472 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -128,6 +128,7 @@ const struct Curl_handler Curl_handler_pop3 = { ZERO_NULL, /* connection_check */ PORT_POP3, /* defport */ CURLPROTO_POP3, /* protocol */ + CURLPROTO_POP3, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ PROTOPT_URLOPTIONS }; @@ -155,6 +156,7 @@ const struct Curl_handler Curl_handler_pop3s = { ZERO_NULL, /* connection_check */ PORT_POP3S, /* defport */ CURLPROTO_POP3S, /* protocol */ + CURLPROTO_POP3, /* family */ PROTOPT_CLOSEACTION | PROTOPT_SSL | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ }; diff --git a/lib/rtsp.c b/lib/rtsp.c index dbd7dc6a6..46c3c4f8f 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -106,6 +106,7 @@ const struct Curl_handler Curl_handler_rtsp = { rtsp_conncheck, /* connection_check */ PORT_RTSP, /* defport */ CURLPROTO_RTSP, /* protocol */ + CURLPROTO_RTSP, /* family */ PROTOPT_NONE /* flags */ }; @@ -86,6 +86,7 @@ const struct Curl_handler Curl_handler_smb = { ZERO_NULL, /* connection_check */ PORT_SMB, /* defport */ CURLPROTO_SMB, /* protocol */ + CURLPROTO_SMB, /* family */ PROTOPT_NONE /* flags */ }; @@ -111,6 +112,7 @@ const struct Curl_handler Curl_handler_smbs = { ZERO_NULL, /* connection_check */ PORT_SMBS, /* defport */ CURLPROTO_SMBS, /* protocol */ + CURLPROTO_SMB, /* family */ PROTOPT_SSL /* flags */ }; #endif diff --git a/lib/smtp.c b/lib/smtp.c index aea41bb4e..c2d632322 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -133,6 +133,7 @@ const struct Curl_handler Curl_handler_smtp = { ZERO_NULL, /* connection_check */ PORT_SMTP, /* defport */ CURLPROTO_SMTP, /* protocol */ + CURLPROTO_SMTP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ PROTOPT_URLOPTIONS }; @@ -160,6 +161,7 @@ const struct Curl_handler Curl_handler_smtps = { ZERO_NULL, /* connection_check */ PORT_SMTPS, /* defport */ CURLPROTO_SMTPS, /* protocol */ + CURLPROTO_SMTP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_SSL | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ }; diff --git a/lib/telnet.c b/lib/telnet.c index ec780dfa1..754febe27 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -188,6 +188,7 @@ const struct Curl_handler Curl_handler_telnet = { ZERO_NULL, /* connection_check */ PORT_TELNET, /* defport */ CURLPROTO_TELNET, /* protocol */ + CURLPROTO_TELNET, /* family */ PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */ }; diff --git a/lib/tftp.c b/lib/tftp.c index 378d95608..1d3b8e825 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -183,6 +183,7 @@ const struct Curl_handler Curl_handler_tftp = { ZERO_NULL, /* connection_check */ PORT_TFTP, /* defport */ CURLPROTO_TFTP, /* protocol */ + CURLPROTO_TFTP, /* family */ PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */ }; @@ -130,7 +130,6 @@ bool curl_win32_idn_to_ascii(const char *in, char **out); #include "memdebug.h" static void conn_free(struct connectdata *conn); -static unsigned int get_protocol_family(unsigned int protocol); /* Some parts of the code (e.g. chunked encoding) assume this buffer has at * more than just a few bytes to play with. Don't let it become too small or @@ -140,6 +139,24 @@ static unsigned int get_protocol_family(unsigned int protocol); # error READBUFFER_SIZE is too small #endif +/* +* get_protocol_family() +* +* This is used to return the protocol family for a given protocol. +* +* Parameters: +* +* 'h' [in] - struct Curl_handler pointer. +* +* Returns the family as a single bit protocol identifier. +*/ +static unsigned int get_protocol_family(const struct Curl_handler *h) +{ + DEBUGASSERT(h); + DEBUGASSERT(h->family); + return h->family; +} + /* * Protocol table. Schemes (roughly) in 2019 popularity order: @@ -273,6 +290,7 @@ static const struct Curl_handler Curl_handler_dummy = { ZERO_NULL, /* connection_check */ 0, /* defport */ 0, /* protocol */ + 0, /* family */ PROTOPT_NONE /* flags */ }; @@ -1173,7 +1191,7 @@ ConnectionExists(struct Curl_easy *data, if((needle->handler->flags&PROTOPT_SSL) != (check->handler->flags&PROTOPT_SSL)) /* don't do mixed SSL and non-SSL connections */ - if(get_protocol_family(check->handler->protocol) != + if(get_protocol_family(check->handler) != needle->handler->protocol || !check->bits.tls_upgraded) /* except protocols that have been upgraded via TLS */ continue; @@ -1278,7 +1296,7 @@ ConnectionExists(struct Curl_easy *data, is allowed to be upgraded via TLS */ if((strcasecompare(needle->handler->scheme, check->handler->scheme) || - (get_protocol_family(check->handler->protocol) == + (get_protocol_family(check->handler) == needle->handler->protocol && check->bits.tls_upgraded)) && (!needle->bits.conn_to_host || strcasecompare( needle->conn_to_host.name, check->conn_to_host.name)) && @@ -4028,113 +4046,3 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn) return CURLE_OK; } - -/* -* get_protocol_family() -* -* This is used to return the protocol family for a given protocol. -* -* Parameters: -* -* protocol [in] - A single bit protocol identifier such as HTTP or HTTPS. -* -* Returns the family as a single bit protocol identifier. -*/ - -static unsigned int get_protocol_family(unsigned int protocol) -{ - unsigned int family; - - switch(protocol) { - case CURLPROTO_HTTP: - case CURLPROTO_HTTPS: - family = CURLPROTO_HTTP; - break; - - case CURLPROTO_FTP: - case CURLPROTO_FTPS: - family = CURLPROTO_FTP; - break; - - case CURLPROTO_SCP: - family = CURLPROTO_SCP; - break; - - case CURLPROTO_SFTP: - family = CURLPROTO_SFTP; - break; - - case CURLPROTO_TELNET: - family = CURLPROTO_TELNET; - break; - - case CURLPROTO_LDAP: - case CURLPROTO_LDAPS: - family = CURLPROTO_LDAP; - break; - - case CURLPROTO_DICT: - family = CURLPROTO_DICT; - break; - - case CURLPROTO_FILE: - family = CURLPROTO_FILE; - break; - - case CURLPROTO_TFTP: - family = CURLPROTO_TFTP; - break; - - case CURLPROTO_IMAP: - case CURLPROTO_IMAPS: - family = CURLPROTO_IMAP; - break; - - case CURLPROTO_POP3: - case CURLPROTO_POP3S: - family = CURLPROTO_POP3; - break; - - case CURLPROTO_SMTP: - case CURLPROTO_SMTPS: - family = CURLPROTO_SMTP; - break; - - case CURLPROTO_RTSP: - family = CURLPROTO_RTSP; - break; - - case CURLPROTO_RTMP: - case CURLPROTO_RTMPS: - family = CURLPROTO_RTMP; - break; - - case CURLPROTO_RTMPT: - case CURLPROTO_RTMPTS: - family = CURLPROTO_RTMPT; - break; - - case CURLPROTO_RTMPE: - family = CURLPROTO_RTMPE; - break; - - case CURLPROTO_RTMPTE: - family = CURLPROTO_RTMPTE; - break; - - case CURLPROTO_GOPHER: - family = CURLPROTO_GOPHER; - break; - - case CURLPROTO_SMB: - case CURLPROTO_SMBS: - family = CURLPROTO_SMB; - break; - - default: - family = 0; - break; - } - - return family; -} diff --git a/lib/urldata.h b/lib/urldata.h index 81cb5fe57..7bb172493 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -739,6 +739,8 @@ struct Curl_handler { long 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 */ unsigned int flags; /* Extra particular characteristics, see PROTOPT_* */ }; diff --git a/lib/vquic/ngtcp2.c b/lib/vquic/ngtcp2.c index 82a8a3ee5..98efdf143 100644 --- a/lib/vquic/ngtcp2.c +++ b/lib/vquic/ngtcp2.c @@ -954,6 +954,7 @@ static const struct Curl_handler Curl_handler_http3 = { ng_conncheck, /* connection_check */ PORT_HTTP, /* defport */ CURLPROTO_HTTPS, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_STREAM /* flags */ }; diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c index fd9cb8bd3..f52e9da32 100644 --- a/lib/vquic/quiche.c +++ b/lib/vquic/quiche.c @@ -154,6 +154,7 @@ static const struct Curl_handler Curl_handler_http3 = { quiche_conncheck, /* connection_check */ PORT_HTTP, /* defport */ CURLPROTO_HTTPS, /* protocol */ + CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_STREAM /* flags */ }; diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 8d1cfd0f1..acdb4e753 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -158,6 +158,7 @@ const struct Curl_handler Curl_handler_scp = { ZERO_NULL, /* connection_check */ PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ + CURLPROTO_SCP, /* family */ PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ }; @@ -183,6 +184,7 @@ const struct Curl_handler Curl_handler_sftp = { ZERO_NULL, /* connection_check */ PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ + CURLPROTO_SFTP, /* family */ PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ }; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index d769bcc6f..c90d6367f 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -150,6 +150,7 @@ const struct Curl_handler Curl_handler_scp = { ZERO_NULL, /* connection_check */ PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ + CURLPROTO_SCP, /* family */ PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ }; @@ -177,6 +178,7 @@ const struct Curl_handler Curl_handler_sftp = { ZERO_NULL, /* connection_check */ PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ + CURLPROTO_SFTP, /* family */ PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ }; |