CURLcode res;
struct UrlData *data = curl;
struct connectdata *c_connect=NULL;
+ bool port=TRUE; /* allow data->use_port to set port to use */
Curl_pgrsStartNow(data);
do {
Curl_pgrsTime(data, TIMER_STARTSINGLE);
- res = curl_connect(curl, (CURLconnect **)&c_connect);
+ res = curl_connect(curl, (CURLconnect **)&c_connect, port);
if(res == CURLE_OK) {
res = curl_do(c_connect);
if(res == CURLE_OK) {
char prot[16]; /* URL protocol string storage */
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)) {
failf(data,"Maximum (%d) redirects followed", data->maxredirs);
#ifdef USE_OLD_DISCONNECT
if(!protsep)
protsep=data->url;
else {
- /* TBD: set the port with curl_setopt() */
- data->port=0; /* we got a full URL and then we should reset the
- port number here to re-initiate it later */
+ port=FALSE; /* we got a full URL and thus we should not obey the
+ port number that might have been set by the user
+ in data->use_port */
+
protsep+=2; /* pass the slashes */
}
data->newurl = newest;
}
else {
- /* This was an absolute URL, clear the port number! */
- /* TBD: set the port with curl_setopt() */
- data->port = 0;
+ /* This is an absolute URL, don't use the custom port number */
+ port = FALSE;
}
if(data->bits.urlstringalloc)
data->url = va_arg(param, char *);
break;
case CURLOPT_PORT:
- data->port = va_arg(param, long);
+ data->use_port = va_arg(param, long);
break;
case CURLOPT_POST:
/* Does this option serve a purpose anymore? */
memcpy((char *)&(conn->serv_addr.sin_addr),
conn->hp->h_addr, conn->hp->h_length);
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
/* IPv6-style */
struct addrinfo *ai;
}
-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 *buf;
*************************************************************/
if (strequal(conn->protostr, "HTTP")) {
- if(!data->port)
- data->port = PORT_HTTP;
- data->remote_port = PORT_HTTP;
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_HTTP;
+ conn->remote_port = PORT_HTTP;
conn->protocol |= PROT_HTTP;
conn->curl_do = Curl_http;
conn->curl_done = Curl_http_done;
}
else if (strequal(conn->protostr, "HTTPS")) {
#ifdef USE_SSLEAY
- if(!data->port)
- data->port = PORT_HTTPS;
- data->remote_port = PORT_HTTPS;
+
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_HTTPS;
+ conn->remote_port = PORT_HTTPS;
conn->protocol |= PROT_HTTP;
conn->protocol |= PROT_HTTPS;
#endif /* !USE_SSLEAY */
}
else if (strequal(conn->protostr, "GOPHER")) {
- if(!data->port)
- data->port = PORT_GOPHER;
- data->remote_port = PORT_GOPHER;
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_GOPHER;
+ conn->remote_port = PORT_GOPHER;
/* Skip /<item-type>/ in path if present */
if (isdigit((int)conn->path[1])) {
conn->ppath = strchr(&conn->path[1], '/');
}
else if(strequal(conn->protostr, "FTP")) {
char *type;
- if(!data->port)
- data->port = PORT_FTP;
- data->remote_port = PORT_FTP;
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_FTP;
+ conn->remote_port = PORT_FTP;
conn->protocol |= PROT_FTP;
if(data->bits.httpproxy &&
else if(strequal(conn->protostr, "TELNET")) {
/* telnet testing factory */
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_done = Curl_telnet_done;
-
}
else if (strequal(conn->protostr, "DICT")) {
conn->protocol |= PROT_DICT;
- if(!data->port)
- data->port = PORT_DICT;
- data->remote_port = PORT_DICT;
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_DICT;
+ conn->remote_port = PORT_DICT;
conn->curl_do = Curl_dict;
conn->curl_done = Curl_dict_done;
}
else if (strequal(conn->protostr, "LDAP")) {
conn->protocol |= PROT_LDAP;
- if(!data->port)
- data->port = PORT_LDAP;
- data->remote_port = PORT_LDAP;
+ conn->port = (data->use_port && allow_port)?data->use_port:PORT_LDAP;
+ conn->remote_port = PORT_LDAP;
conn->curl_do = Curl_ldap;
conn->curl_done = Curl_ldap_done;
}
if (tmp) {
*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
* re-use an already existing one or if we have to create a
if(!data->bits.httpproxy) {
/* 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. */
- 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 */
if(!conn->hp) {
*prox_portno = 0x0; /* cut off number from host name */
prox_portno ++;
/* now set the local port number */
- data->port = atoi(prox_portno);
+ conn->port = atoi(prox_portno);
}
else if(data->proxyport) {
/* None given in the proxy string, then get the default one if it is
given */
- data->port = data->proxyport;
+ conn->port = data->proxyport;
}
/* resolve proxy */
return CURLE_OK;
}
-CURLcode curl_connect(CURL *curl, CURLconnect **in_connect)
+CURLcode curl_connect(CURL *curl, CURLconnect **in_connect,
+ bool allow_port)
{
CURLcode code;
struct connectdata *conn;
/* call the stuff that needs to be called */
- code = _connect(curl, in_connect);
+ code = _connect(curl, in_connect, allow_port);
if(CURLE_OK != code) {
/* We're not allowed to return failure with memory left allocated