mirror of
https://github.com/curl/curl.git
synced 2024-11-27 05:50:21 +08:00
Remove pointless storing of the protocol as a string within the connectdata
struct, and instead use the already stored string in the handler struct.
This commit is contained in:
parent
10a11e3abe
commit
91d05903b4
@ -200,7 +200,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the URL scheme ( either ldap or ldaps ) */
|
/* Get the URL scheme ( either ldap or ldaps ) */
|
||||||
if(Curl_raw_equal(conn->protostr, "LDAPS"))
|
if(conn->protocol & PROT_SSL)
|
||||||
ldap_ssl = 1;
|
ldap_ssl = 1;
|
||||||
infof(data, "LDAP local: trying to establish %s connection\n",
|
infof(data, "LDAP local: trying to establish %s connection\n",
|
||||||
ldap_ssl ? "encrypted" : "cleartext");
|
ldap_ssl ? "encrypted" : "cleartext");
|
||||||
|
51
lib/url.c
51
lib/url.c
@ -2752,7 +2752,7 @@ ConnectionExists(struct SessionHandle *data,
|
|||||||
it is a non-SSL protocol tunneled over the same http proxy name and
|
it is a non-SSL protocol tunneled over the same http proxy name and
|
||||||
port number */
|
port number */
|
||||||
|
|
||||||
if(Curl_raw_equal(needle->protostr, check->protostr) &&
|
if(Curl_raw_equal(needle->handler->scheme, check->handler->scheme) &&
|
||||||
Curl_raw_equal(needle->host.name, check->host.name) &&
|
Curl_raw_equal(needle->host.name, check->host.name) &&
|
||||||
(needle->remote_port == check->remote_port) ) {
|
(needle->remote_port == check->remote_port) ) {
|
||||||
if(needle->protocol & PROT_SSL) {
|
if(needle->protocol & PROT_SSL) {
|
||||||
@ -3256,7 +3256,8 @@ static struct connectdata *allocate_conn(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CURLcode findprotocol(struct SessionHandle *data,
|
static CURLcode findprotocol(struct SessionHandle *data,
|
||||||
struct connectdata *conn)
|
struct connectdata *conn,
|
||||||
|
const char *protostr)
|
||||||
{
|
{
|
||||||
const struct Curl_handler * const *pp;
|
const struct Curl_handler * const *pp;
|
||||||
const struct Curl_handler *p;
|
const struct Curl_handler *p;
|
||||||
@ -3265,7 +3266,7 @@ static CURLcode findprotocol(struct SessionHandle *data,
|
|||||||
variables based on the URL. Now that the handler may be changed later
|
variables based on the URL. Now that the handler may be changed later
|
||||||
when the protocol specific setup function is called. */
|
when the protocol specific setup function is called. */
|
||||||
for (pp = protocols; (p = *pp) != NULL; pp++) {
|
for (pp = protocols; (p = *pp) != NULL; pp++) {
|
||||||
if(Curl_raw_equal(p->scheme, conn->protostr)) {
|
if(Curl_raw_equal(p->scheme, protostr)) {
|
||||||
/* Protocol found in table. Check if allowed */
|
/* Protocol found in table. Check if allowed */
|
||||||
if(!(data->set.allowed_protocols & p->protocol))
|
if(!(data->set.allowed_protocols & p->protocol))
|
||||||
/* nope, get out */
|
/* nope, get out */
|
||||||
@ -3292,7 +3293,7 @@ static CURLcode findprotocol(struct SessionHandle *data,
|
|||||||
to anything since it is already assigned to a dummy-struct in the
|
to anything since it is already assigned to a dummy-struct in the
|
||||||
create_conn() function when the connectdata struct is allocated. */
|
create_conn() function when the connectdata struct is allocated. */
|
||||||
failf(data, "Protocol %s not supported or disabled in " LIBCURL_NAME,
|
failf(data, "Protocol %s not supported or disabled in " LIBCURL_NAME,
|
||||||
conn->protostr);
|
protostr);
|
||||||
|
|
||||||
return CURLE_UNSUPPORTED_PROTOCOL;
|
return CURLE_UNSUPPORTED_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -3307,6 +3308,8 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
char *path = data->state.path;
|
char *path = data->state.path;
|
||||||
int rc;
|
int rc;
|
||||||
|
char protobuf[16];
|
||||||
|
const char *protop;
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Parse the URL.
|
* Parse the URL.
|
||||||
@ -3317,8 +3320,8 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
* url ...
|
* url ...
|
||||||
************************************************************/
|
************************************************************/
|
||||||
if((2 == sscanf(data->change.url, "%15[^:]:%[^\n]",
|
if((2 == sscanf(data->change.url, "%15[^:]:%[^\n]",
|
||||||
conn->protostr,
|
protobuf, path)) &&
|
||||||
path)) && Curl_raw_equal(conn->protostr, "file")) {
|
Curl_raw_equal(protobuf, "file")) {
|
||||||
if(path[0] == '/' && path[1] == '/') {
|
if(path[0] == '/' && path[1] == '/') {
|
||||||
/* Allow omitted hostname (e.g. file:/<path>). This is not strictly
|
/* Allow omitted hostname (e.g. file:/<path>). This is not strictly
|
||||||
* speaking a valid file: URL by RFC 1738, but treating file:/<path> as
|
* speaking a valid file: URL by RFC 1738, but treating file:/<path> as
|
||||||
@ -3364,7 +3367,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(conn->protostr, "file"); /* store protocol string lowercase */
|
protop = "file"; /* protocol string */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* clear path */
|
/* clear path */
|
||||||
@ -3372,7 +3375,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
|
|
||||||
if(2 > sscanf(data->change.url,
|
if(2 > sscanf(data->change.url,
|
||||||
"%15[^\n:]://%[^\n/]%[^\n]",
|
"%15[^\n:]://%[^\n/]%[^\n]",
|
||||||
conn->protostr,
|
protobuf,
|
||||||
conn->host.name, path)) {
|
conn->host.name, path)) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3404,19 +3407,21 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
* lib/version.c too! */
|
* lib/version.c too! */
|
||||||
|
|
||||||
if(checkprefix("FTP.", conn->host.name))
|
if(checkprefix("FTP.", conn->host.name))
|
||||||
strcpy(conn->protostr, "ftp");
|
protop = "ftp";
|
||||||
else if(checkprefix("DICT.", conn->host.name))
|
else if(checkprefix("DICT.", conn->host.name))
|
||||||
strcpy(conn->protostr, "DICT");
|
protop = "DICT";
|
||||||
else if(checkprefix("LDAP.", conn->host.name))
|
else if(checkprefix("LDAP.", conn->host.name))
|
||||||
strcpy(conn->protostr, "LDAP");
|
protop = "LDAP";
|
||||||
else if(checkprefix("IMAP.", conn->host.name))
|
else if(checkprefix("IMAP.", conn->host.name))
|
||||||
strcpy(conn->protostr, "IMAP");
|
protop = "IMAP";
|
||||||
else {
|
else {
|
||||||
strcpy(conn->protostr, "http");
|
protop = "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->protocol |= PROT_MISSING; /* not given in URL */
|
conn->protocol |= PROT_MISSING; /* not given in URL */
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
protop = protobuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We search for '?' in the host name (but only on the right side of a
|
/* We search for '?' in the host name (but only on the right side of a
|
||||||
@ -3493,12 +3498,12 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* So if the URL was A://B/C,
|
* So if the URL was A://B/C,
|
||||||
* conn->protostr is A
|
* protop is A
|
||||||
* conn->host.name is B
|
* conn->host.name is B
|
||||||
* data->state.path is /C
|
* data->state.path is /C
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return findprotocol(data, conn);
|
return findprotocol(data, conn, protop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void llist_dtor(void *user, void *element)
|
static void llist_dtor(void *user, void *element)
|
||||||
@ -3685,7 +3690,7 @@ static char *detect_proxy(struct connectdata *conn)
|
|||||||
|
|
||||||
if(!check_noproxy(conn->host.name, no_proxy)) {
|
if(!check_noproxy(conn->host.name, no_proxy)) {
|
||||||
/* It was not listed as without proxy */
|
/* It was not listed as without proxy */
|
||||||
char *protop = conn->protostr;
|
const char *protop = conn->handler->scheme;
|
||||||
char *envp = proxy_env;
|
char *envp = proxy_env;
|
||||||
char *prox;
|
char *prox;
|
||||||
|
|
||||||
@ -4036,18 +4041,18 @@ static CURLcode parse_remote_port(struct SessionHandle *data,
|
|||||||
if(conn->bits.httpproxy) {
|
if(conn->bits.httpproxy) {
|
||||||
/* we need to create new URL with the new port number */
|
/* we need to create new URL with the new port number */
|
||||||
char *url;
|
char *url;
|
||||||
bool isftp = (bool)(Curl_raw_equal("ftp", conn->protostr) ||
|
/* FTPS connections have the FTP bit set too, so they match as well */
|
||||||
Curl_raw_equal("ftps", conn->protostr));
|
bool isftp = (bool)conn->protocol & PROT_FTP;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This synthesized URL isn't always right--suffixes like ;type=A
|
* This synthesized URL isn't always right--suffixes like ;type=A
|
||||||
* are stripped off. It would be better to work directly from the
|
* are stripped off. It would be better to work directly from the
|
||||||
* original URL and simply replace the port part of it.
|
* original URL and simply replace the port part of it.
|
||||||
*/
|
*/
|
||||||
url = aprintf("%s://%s%s%s:%d%s%s", conn->protostr,
|
url = aprintf("%s://%s%s%s:%d%s%s", conn->handler->scheme,
|
||||||
conn->bits.ipv6_ip?"[":"", conn->host.name,
|
conn->bits.ipv6_ip?"[":"", conn->host.name,
|
||||||
conn->bits.ipv6_ip?"]":"", conn->remote_port,
|
conn->bits.ipv6_ip?"]":"", conn->remote_port,
|
||||||
isftp?"/":"", data->state.path);
|
isftp?"/":"", data->state.path);
|
||||||
if(!url)
|
if(!url)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
@ -4456,7 +4461,7 @@ static CURLcode create_conn(struct SessionHandle *data,
|
|||||||
part added so that we have a valid URL. */
|
part added so that we have a valid URL. */
|
||||||
char *reurl;
|
char *reurl;
|
||||||
|
|
||||||
reurl = aprintf("%s://%s", conn->protostr, data->change.url);
|
reurl = aprintf("%s://%s", conn->handler->scheme, data->change.url);
|
||||||
|
|
||||||
if(!reurl) {
|
if(!reurl) {
|
||||||
Curl_safefree(proxy);
|
Curl_safefree(proxy);
|
||||||
|
@ -703,7 +703,6 @@ struct connectdata {
|
|||||||
|
|
||||||
unsigned int scope; /* address scope for IPv6 */
|
unsigned int scope; /* address scope for IPv6 */
|
||||||
|
|
||||||
char protostr[16]; /* store the protocol string in this buffer */
|
|
||||||
int socktype; /* SOCK_STREAM or SOCK_DGRAM */
|
int socktype; /* SOCK_STREAM or SOCK_DGRAM */
|
||||||
|
|
||||||
struct hostname host;
|
struct hostname host;
|
||||||
|
@ -50,7 +50,7 @@ http://www.haxx.se:999/523 http://%HOSTIP:%HTTPPORT
|
|||||||
^User-Agent:.*
|
^User-Agent:.*
|
||||||
</strip>
|
</strip>
|
||||||
<protocol>
|
<protocol>
|
||||||
GET http://www.haxx.se:19999/523 HTTP/1.1
|
GET HTTP://www.haxx.se:19999/523 HTTP/1.1
|
||||||
Authorization: Basic eHh4Onl5eQ==
|
Authorization: Basic eHh4Onl5eQ==
|
||||||
Host: www.haxx.se:19999
|
Host: www.haxx.se:19999
|
||||||
Accept: */*
|
Accept: */*
|
||||||
|
Loading…
Reference in New Issue
Block a user