1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-15 14:05:03 -05:00

prefix changes curl_ to Curl_

made it work (partly) with persistant connections for HTTP/1.0 replies
moved the 'newurl' struct field for Location: to the connectdata struct
This commit is contained in:
Daniel Stenberg 2001-03-09 15:16:28 +00:00
parent beb8761b22
commit 781dd7a9bf

View File

@ -107,7 +107,7 @@
<butlerm@xmission.com>. */ <butlerm@xmission.com>. */
CURLcode static CURLcode static
_Transfer(struct connectdata *c_conn) Transfer(struct connectdata *c_conn)
{ {
ssize_t nread; /* number of bytes read */ ssize_t nread; /* number of bytes read */
int bytecount = 0; /* total number of bytes read */ int bytecount = 0; /* total number of bytes read */
@ -142,9 +142,6 @@ _Transfer(struct connectdata *c_conn)
char *buf; char *buf;
int maxfd; int maxfd;
if(!conn || (conn->handle != STRUCT_CONNECT))
return CURLE_BAD_FUNCTION_ARGUMENT;
data = conn->data; /* there's the root struct */ data = conn->data; /* there's the root struct */
buf = data->buffer; buf = data->buffer;
maxfd = (conn->sockfd>conn->writesockfd?conn->sockfd:conn->writesockfd)+1; maxfd = (conn->sockfd>conn->writesockfd?conn->sockfd:conn->writesockfd)+1;
@ -446,7 +443,7 @@ _Transfer(struct connectdata *c_conn)
ptr++; ptr++;
backup = *ptr; /* store the ending letter */ backup = *ptr; /* store the ending letter */
*ptr = '\0'; /* zero terminate */ *ptr = '\0'; /* zero terminate */
data->newurl = strdup(start); /* clone string */ conn->newurl = strdup(start); /* clone string */
*ptr = backup; /* restore ending letter */ *ptr = backup; /* restore ending letter */
} }
@ -490,9 +487,9 @@ _Transfer(struct connectdata *c_conn)
write a piece of the body */ write a piece of the body */
if(conn->protocol&PROT_HTTP) { if(conn->protocol&PROT_HTTP) {
/* HTTP-only checks */ /* HTTP-only checks */
if (data->newurl) { if (conn->newurl) {
/* abort after the headers if "follow Location" is set */ /* abort after the headers if "follow Location" is set */
infof (data, "Follow to new URL: %s\n", data->newurl); infof (data, "Follow to new URL: %s\n", conn->newurl);
return CURLE_OK; return CURLE_OK;
} }
else if (data->resume_from && else if (data->resume_from &&
@ -530,7 +527,8 @@ _Transfer(struct connectdata *c_conn)
} /* switch */ } /* switch */
} /* two valid time strings */ } /* two valid time strings */
} /* we have a time condition */ } /* we have a time condition */
if(!conn->bits.close && (httpversion == 1)) {
if(!conn->bits.close) {
/* If this is not the last request before a close, we must /* If this is not the last request before a close, we must
set the maximum download size to the size of the expected set the maximum download size to the size of the expected
document or else, we won't know when to stop reading! */ document or else, we won't know when to stop reading! */
@ -681,27 +679,27 @@ _Transfer(struct connectdata *c_conn)
return CURLE_OK; return CURLE_OK;
} }
CURLcode curl_transfer(CURL *curl) CURLcode Curl_perform(CURL *curl)
{ {
CURLcode res; CURLcode res;
struct UrlData *data = curl; struct UrlData *data = (struct UrlData *)curl;
struct connectdata *c_connect=NULL; struct connectdata *conn=NULL;
bool port=TRUE; /* allow data->use_port to set port to use */ 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, port); res = Curl_connect(data, &conn, port);
if(res == CURLE_OK) { if(res == CURLE_OK) {
res = curl_do(c_connect); res = Curl_do(conn);
if(res == CURLE_OK) { if(res == CURLE_OK) {
res = _Transfer(c_connect); /* now fetch that URL please */ res = Transfer(conn); /* now fetch that URL please */
if(res == CURLE_OK) if(res == CURLE_OK)
res = curl_done(c_connect); res = Curl_done(conn);
} }
if((res == CURLE_OK) && data->newurl) { if((res == CURLE_OK) && conn->newurl) {
/* Location: redirect /* Location: redirect
This is assumed to happen for HTTP(S) only! This is assumed to happen for HTTP(S) only!
@ -741,7 +739,7 @@ CURLcode curl_transfer(CURL *curl)
data->bits.http_set_referer = TRUE; /* might have been false */ data->bits.http_set_referer = TRUE; /* might have been false */
} }
if(2 != sscanf(data->newurl, "%15[^:]://%c", prot, &letter)) { if(2 != sscanf(conn->newurl, "%15[^:]://%c", prot, &letter)) {
/*** /***
*DANG* this is an RFC 2068 violation. The URL is supposed *DANG* this is an RFC 2068 violation. The URL is supposed
to be absolute and this doesn't seem to be that! to be absolute and this doesn't seem to be that!
@ -766,7 +764,7 @@ CURLcode curl_transfer(CURL *curl)
protsep+=2; /* pass the slashes */ protsep+=2; /* pass the slashes */
} }
if('/' != data->newurl[0]) { if('/' != conn->newurl[0]) {
/* First we need to find out if there's a ?-letter in the URL, /* First we need to find out if there's a ?-letter in the URL,
and cut it and the right-side of that off */ and cut it and the right-side of that off */
pathsep = strrchr(protsep, '?'); pathsep = strrchr(protsep, '?');
@ -789,14 +787,14 @@ CURLcode curl_transfer(CURL *curl)
newest=(char *)malloc( strlen(data->url) + newest=(char *)malloc( strlen(data->url) +
1 + /* possible slash */ 1 + /* possible slash */
strlen(data->newurl) + 1/* zero byte */); strlen(conn->newurl) + 1/* zero byte */);
if(!newest) if(!newest)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
sprintf(newest, "%s%s%s", data->url, ('/' == data->newurl[0])?"":"/", sprintf(newest, "%s%s%s", data->url, ('/' == conn->newurl[0])?"":"/",
data->newurl); conn->newurl);
free(data->newurl); free(conn->newurl);
data->newurl = newest; conn->newurl = newest;
} }
else { else {
/* This is an absolute URL, don't use the custom port number */ /* This is an absolute URL, don't use the custom port number */
@ -807,8 +805,8 @@ CURLcode curl_transfer(CURL *curl)
free(data->url); free(data->url);
/* TBD: set the URL with curl_setopt() */ /* TBD: set the URL with curl_setopt() */
data->url = data->newurl; data->url = conn->newurl;
data->newurl = NULL; /* don't show! */ conn->newurl = NULL; /* don't show! */
data->bits.urlstringalloc = TRUE; /* the URL is allocated */ data->bits.urlstringalloc = TRUE; /* the URL is allocated */
infof(data, "Follows Location: to new URL: '%s'\n", data->url); infof(data, "Follows Location: to new URL: '%s'\n", data->url);
@ -867,8 +865,10 @@ CURLcode curl_transfer(CURL *curl)
} while(1); /* loop if Location: */ } while(1); /* loop if Location: */
if(data->newurl) if(conn->newurl) {
free(data->newurl); free(conn->newurl);
conn->newurl = NULL;
}
return res; return res;
} }