remade the port number stuff so that following locations work and doing
intermixed HTTP and FTP persistant connections also work!
This commit is contained in:
parent
a3ba6b7a6a
commit
d1cfbd51b5
@ -1065,7 +1065,7 @@ again:;
|
|||||||
he = conn->hp;
|
he = conn->hp;
|
||||||
#endif
|
#endif
|
||||||
connectport =
|
connectport =
|
||||||
(unsigned short)data->port; /* we connect to the proxy's port */
|
(unsigned short)conn->port; /* we connect to the proxy's port */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* normal, direct, ftp connection */
|
/* normal, direct, ftp connection */
|
||||||
|
@ -465,14 +465,14 @@ CURLcode Curl_http(struct connectdata *conn)
|
|||||||
/* if ptr_host is already set, it is OK since we only re-use connections
|
/* if ptr_host is already set, it is OK since we only re-use connections
|
||||||
to the very same host and port */
|
to the very same host and port */
|
||||||
|
|
||||||
if(((conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTPS)) ||
|
if(((conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTPS)) ||
|
||||||
(!(conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTP)) )
|
(!(conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTP)) )
|
||||||
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
|
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
|
||||||
the port number in the host string */
|
the port number in the host string */
|
||||||
conn->allocptr.host = aprintf("Host: %s\r\n", host);
|
conn->allocptr.host = aprintf("Host: %s\r\n", host);
|
||||||
else
|
else
|
||||||
conn->allocptr.host = aprintf("Host: %s:%d\r\n", host,
|
conn->allocptr.host = aprintf("Host: %s:%d\r\n", host,
|
||||||
data->remote_port);
|
conn->remote_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!checkheaders(data, "Pragma:"))
|
if(!checkheaders(data, "Pragma:"))
|
||||||
|
@ -632,12 +632,13 @@ CURLcode curl_transfer(CURL *curl)
|
|||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct UrlData *data = curl;
|
struct UrlData *data = curl;
|
||||||
struct connectdata *c_connect=NULL;
|
struct connectdata *c_connect=NULL;
|
||||||
|
bool port=TRUE; /* allow data->use_port to set port to use */
|
||||||
|
|
||||||
Curl_pgrsStartNow(data);
|
Curl_pgrsStartNow(data);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Curl_pgrsTime(data, TIMER_STARTSINGLE);
|
Curl_pgrsTime(data, TIMER_STARTSINGLE);
|
||||||
res = curl_connect(curl, (CURLconnect **)&c_connect);
|
res = curl_connect(curl, (CURLconnect **)&c_connect, port);
|
||||||
if(res == CURLE_OK) {
|
if(res == CURLE_OK) {
|
||||||
res = curl_do(c_connect);
|
res = curl_do(c_connect);
|
||||||
if(res == CURLE_OK) {
|
if(res == CURLE_OK) {
|
||||||
@ -654,6 +655,9 @@ CURLcode curl_transfer(CURL *curl)
|
|||||||
char prot[16]; /* URL protocol string storage */
|
char prot[16]; /* URL protocol string storage */
|
||||||
char letter; /* used for a silly sscanf */
|
char letter; /* used for a silly sscanf */
|
||||||
|
|
||||||
|
port=TRUE; /* by default we use the user set port number even after
|
||||||
|
a Location: */
|
||||||
|
|
||||||
if (data->maxredirs && (data->followlocation >= data->maxredirs)) {
|
if (data->maxredirs && (data->followlocation >= data->maxredirs)) {
|
||||||
failf(data,"Maximum (%d) redirects followed", data->maxredirs);
|
failf(data,"Maximum (%d) redirects followed", data->maxredirs);
|
||||||
#ifdef USE_OLD_DISCONNECT
|
#ifdef USE_OLD_DISCONNECT
|
||||||
@ -701,9 +705,10 @@ CURLcode curl_transfer(CURL *curl)
|
|||||||
if(!protsep)
|
if(!protsep)
|
||||||
protsep=data->url;
|
protsep=data->url;
|
||||||
else {
|
else {
|
||||||
/* TBD: set the port with curl_setopt() */
|
port=FALSE; /* we got a full URL and thus we should not obey the
|
||||||
data->port=0; /* we got a full URL and then we should reset the
|
port number that might have been set by the user
|
||||||
port number here to re-initiate it later */
|
in data->use_port */
|
||||||
|
|
||||||
protsep+=2; /* pass the slashes */
|
protsep+=2; /* pass the slashes */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,9 +745,8 @@ CURLcode curl_transfer(CURL *curl)
|
|||||||
data->newurl = newest;
|
data->newurl = newest;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* This was an absolute URL, clear the port number! */
|
/* This is an absolute URL, don't use the custom port number */
|
||||||
/* TBD: set the port with curl_setopt() */
|
port = FALSE;
|
||||||
data->port = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->bits.urlstringalloc)
|
if(data->bits.urlstringalloc)
|
||||||
|
62
lib/url.c
62
lib/url.c
@ -378,7 +378,7 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...)
|
|||||||
data->url = va_arg(param, char *);
|
data->url = va_arg(param, char *);
|
||||||
break;
|
break;
|
||||||
case CURLOPT_PORT:
|
case CURLOPT_PORT:
|
||||||
data->port = va_arg(param, long);
|
data->use_port = va_arg(param, long);
|
||||||
break;
|
break;
|
||||||
case CURLOPT_POST:
|
case CURLOPT_POST:
|
||||||
/* Does this option serve a purpose anymore? */
|
/* Does this option serve a purpose anymore? */
|
||||||
@ -704,7 +704,7 @@ static CURLcode ConnectPlease(struct UrlData *data,
|
|||||||
memcpy((char *)&(conn->serv_addr.sin_addr),
|
memcpy((char *)&(conn->serv_addr.sin_addr),
|
||||||
conn->hp->h_addr, conn->hp->h_length);
|
conn->hp->h_addr, conn->hp->h_length);
|
||||||
conn->serv_addr.sin_family = conn->hp->h_addrtype;
|
conn->serv_addr.sin_family = conn->hp->h_addrtype;
|
||||||
conn->serv_addr.sin_port = htons(data->port);
|
conn->serv_addr.sin_port = htons(conn->port);
|
||||||
#else
|
#else
|
||||||
/* IPv6-style */
|
/* IPv6-style */
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
@ -910,7 +910,9 @@ static CURLcode ConnectPlease(struct UrlData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
static CURLcode _connect(CURL *curl,
|
||||||
|
CURLconnect **in_connect,
|
||||||
|
bool allow_port) /* allow data->use_port ? */
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *buf;
|
char *buf;
|
||||||
@ -1275,9 +1277,8 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
*************************************************************/
|
*************************************************************/
|
||||||
|
|
||||||
if (strequal(conn->protostr, "HTTP")) {
|
if (strequal(conn->protostr, "HTTP")) {
|
||||||
if(!data->port)
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_HTTP;
|
||||||
data->port = PORT_HTTP;
|
conn->remote_port = PORT_HTTP;
|
||||||
data->remote_port = PORT_HTTP;
|
|
||||||
conn->protocol |= PROT_HTTP;
|
conn->protocol |= PROT_HTTP;
|
||||||
conn->curl_do = Curl_http;
|
conn->curl_do = Curl_http;
|
||||||
conn->curl_done = Curl_http_done;
|
conn->curl_done = Curl_http_done;
|
||||||
@ -1285,9 +1286,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
}
|
}
|
||||||
else if (strequal(conn->protostr, "HTTPS")) {
|
else if (strequal(conn->protostr, "HTTPS")) {
|
||||||
#ifdef USE_SSLEAY
|
#ifdef USE_SSLEAY
|
||||||
if(!data->port)
|
|
||||||
data->port = PORT_HTTPS;
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_HTTPS;
|
||||||
data->remote_port = PORT_HTTPS;
|
conn->remote_port = PORT_HTTPS;
|
||||||
conn->protocol |= PROT_HTTP;
|
conn->protocol |= PROT_HTTP;
|
||||||
conn->protocol |= PROT_HTTPS;
|
conn->protocol |= PROT_HTTPS;
|
||||||
|
|
||||||
@ -1302,9 +1303,8 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
#endif /* !USE_SSLEAY */
|
#endif /* !USE_SSLEAY */
|
||||||
}
|
}
|
||||||
else if (strequal(conn->protostr, "GOPHER")) {
|
else if (strequal(conn->protostr, "GOPHER")) {
|
||||||
if(!data->port)
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_GOPHER;
|
||||||
data->port = PORT_GOPHER;
|
conn->remote_port = PORT_GOPHER;
|
||||||
data->remote_port = PORT_GOPHER;
|
|
||||||
/* Skip /<item-type>/ in path if present */
|
/* Skip /<item-type>/ in path if present */
|
||||||
if (isdigit((int)conn->path[1])) {
|
if (isdigit((int)conn->path[1])) {
|
||||||
conn->ppath = strchr(&conn->path[1], '/');
|
conn->ppath = strchr(&conn->path[1], '/');
|
||||||
@ -1318,9 +1318,8 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
}
|
}
|
||||||
else if(strequal(conn->protostr, "FTP")) {
|
else if(strequal(conn->protostr, "FTP")) {
|
||||||
char *type;
|
char *type;
|
||||||
if(!data->port)
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_FTP;
|
||||||
data->port = PORT_FTP;
|
conn->remote_port = PORT_FTP;
|
||||||
data->remote_port = PORT_FTP;
|
|
||||||
conn->protocol |= PROT_FTP;
|
conn->protocol |= PROT_FTP;
|
||||||
|
|
||||||
if(data->bits.httpproxy &&
|
if(data->bits.httpproxy &&
|
||||||
@ -1368,27 +1367,23 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
else if(strequal(conn->protostr, "TELNET")) {
|
else if(strequal(conn->protostr, "TELNET")) {
|
||||||
/* telnet testing factory */
|
/* telnet testing factory */
|
||||||
conn->protocol |= PROT_TELNET;
|
conn->protocol |= PROT_TELNET;
|
||||||
if(!data->port)
|
|
||||||
data->port = PORT_TELNET;
|
|
||||||
data->remote_port = PORT_TELNET;
|
|
||||||
|
|
||||||
|
conn->port = (data->use_port && allow_port)?data->use_port: PORT_TELNET;
|
||||||
|
conn->remote_port = PORT_TELNET;
|
||||||
conn->curl_do = Curl_telnet;
|
conn->curl_do = Curl_telnet;
|
||||||
conn->curl_done = Curl_telnet_done;
|
conn->curl_done = Curl_telnet_done;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (strequal(conn->protostr, "DICT")) {
|
else if (strequal(conn->protostr, "DICT")) {
|
||||||
conn->protocol |= PROT_DICT;
|
conn->protocol |= PROT_DICT;
|
||||||
if(!data->port)
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_DICT;
|
||||||
data->port = PORT_DICT;
|
conn->remote_port = PORT_DICT;
|
||||||
data->remote_port = PORT_DICT;
|
|
||||||
conn->curl_do = Curl_dict;
|
conn->curl_do = Curl_dict;
|
||||||
conn->curl_done = Curl_dict_done;
|
conn->curl_done = Curl_dict_done;
|
||||||
}
|
}
|
||||||
else if (strequal(conn->protostr, "LDAP")) {
|
else if (strequal(conn->protostr, "LDAP")) {
|
||||||
conn->protocol |= PROT_LDAP;
|
conn->protocol |= PROT_LDAP;
|
||||||
if(!data->port)
|
conn->port = (data->use_port && allow_port)?data->use_port:PORT_LDAP;
|
||||||
data->port = PORT_LDAP;
|
conn->remote_port = PORT_LDAP;
|
||||||
data->remote_port = PORT_LDAP;
|
|
||||||
conn->curl_do = Curl_ldap;
|
conn->curl_do = Curl_ldap;
|
||||||
conn->curl_done = Curl_ldap_done;
|
conn->curl_done = Curl_ldap_done;
|
||||||
}
|
}
|
||||||
@ -1516,13 +1511,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
|
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
*tmp++ = '\0'; /* cut off the name there */
|
*tmp++ = '\0'; /* cut off the name there */
|
||||||
data->remote_port = atoi(tmp);
|
conn->remote_port = atoi(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the port-specifics to the connection struct */
|
|
||||||
conn->port = data->port;
|
|
||||||
conn->remote_port = data->remote_port;
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Check the current list of connections to see if we can
|
* Check the current list of connections to see if we can
|
||||||
* re-use an already existing one or if we have to create a
|
* re-use an already existing one or if we have to create a
|
||||||
@ -1564,7 +1555,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
if(!data->bits.httpproxy) {
|
if(!data->bits.httpproxy) {
|
||||||
/* If not connecting via a proxy, extract the port from the URL, if it is
|
/* If not connecting via a proxy, extract the port from the URL, if it is
|
||||||
* there, thus overriding any defaults that might have been set above. */
|
* there, thus overriding any defaults that might have been set above. */
|
||||||
data->port = data->remote_port; /* it is the same port */
|
conn->port = conn->remote_port; /* it is the same port */
|
||||||
|
|
||||||
/* Resolve target host right on */
|
/* Resolve target host right on */
|
||||||
if(!conn->hp) {
|
if(!conn->hp) {
|
||||||
@ -1621,12 +1612,12 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
*prox_portno = 0x0; /* cut off number from host name */
|
*prox_portno = 0x0; /* cut off number from host name */
|
||||||
prox_portno ++;
|
prox_portno ++;
|
||||||
/* now set the local port number */
|
/* now set the local port number */
|
||||||
data->port = atoi(prox_portno);
|
conn->port = atoi(prox_portno);
|
||||||
}
|
}
|
||||||
else if(data->proxyport) {
|
else if(data->proxyport) {
|
||||||
/* None given in the proxy string, then get the default one if it is
|
/* None given in the proxy string, then get the default one if it is
|
||||||
given */
|
given */
|
||||||
data->port = data->proxyport;
|
conn->port = data->proxyport;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resolve proxy */
|
/* resolve proxy */
|
||||||
@ -1741,13 +1732,14 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
|
CURLcode curl_connect(CURL *curl, CURLconnect **in_connect,
|
||||||
|
bool allow_port)
|
||||||
{
|
{
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
struct connectdata *conn;
|
struct connectdata *conn;
|
||||||
|
|
||||||
/* call the stuff that needs to be called */
|
/* call the stuff that needs to be called */
|
||||||
code = _connect(curl, in_connect);
|
code = _connect(curl, in_connect, allow_port);
|
||||||
|
|
||||||
if(CURLE_OK != code) {
|
if(CURLE_OK != code) {
|
||||||
/* We're not allowed to return failure with memory left allocated
|
/* We're not allowed to return failure with memory left allocated
|
||||||
|
@ -468,9 +468,7 @@ struct UrlData {
|
|||||||
FILE *writeheader; /* write the header to this is non-NULL */
|
FILE *writeheader; /* write the header to this is non-NULL */
|
||||||
char *url; /* what to get */
|
char *url; /* what to get */
|
||||||
char *freethis; /* if non-NULL, an allocated string for the URL */
|
char *freethis; /* if non-NULL, an allocated string for the URL */
|
||||||
long port; /* which port to use (if non-protocol bind) */
|
long use_port; /* which port to use (when not using default) */
|
||||||
unsigned short remote_port; /* what remote port to connect to, not the proxy
|
|
||||||
port! */
|
|
||||||
struct Configbits bits; /* new-style (v7) flag data */
|
struct Configbits bits; /* new-style (v7) flag data */
|
||||||
struct ssl_config_data ssl; /* this is for ssl-stuff */
|
struct ssl_config_data ssl; /* this is for ssl-stuff */
|
||||||
|
|
||||||
@ -697,15 +695,19 @@ CURLcode curl_write(CURLconnect *c_conn, char *buf, size_t amount,
|
|||||||
* this connect. This allows multiple connects from the same handle returned
|
* this connect. This allows multiple connects from the same handle returned
|
||||||
* by curl_open().
|
* by curl_open().
|
||||||
*
|
*
|
||||||
|
* By setting 'allow_port' to FALSE, the data->use_port will *NOT* be
|
||||||
|
* respected.
|
||||||
|
*
|
||||||
* EXAMPLE
|
* EXAMPLE
|
||||||
*
|
*
|
||||||
* CURLCode result;
|
* CURLCode result;
|
||||||
* CURL curl;
|
* CURL curl;
|
||||||
* CURLconnect connect;
|
* CURLconnect connect;
|
||||||
* result = curl_connect(curl, &connect);
|
* result = curl_connect(curl, &connect); */
|
||||||
*/
|
|
||||||
|
|
||||||
CURLcode curl_connect(CURL *curl, CURLconnect **in_connect);
|
CURLcode curl_connect(CURL *curl,
|
||||||
|
CURLconnect **in_connect,
|
||||||
|
bool allow_port);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NAME curl_do()
|
* NAME curl_do()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user