1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Added tons of comments all over

This commit is contained in:
Daniel Stenberg 2001-05-12 16:11:14 +00:00
parent a50fac0e63
commit c7c942861a

View File

@ -158,8 +158,19 @@ compareheader(char *headerline, /* line to check */
return FALSE; /* no match */ return FALSE; /* no match */
} }
/* Parts of this function was written by the friendly Mark Butler /*
<butlerm@xmission.com>. */ * Transfer()
*
* This function is what performs the actual transfer. It is capable of
* doing both ways simultaneously.
* The transfer must already have been setup by a call to Curl_Transfer().
*
* Note that headers are created in a preallocated buffer of a default size.
* That buffer can be enlarged on demand, but it is never shrinken again.
*
* Parts of this function was once written by the friendly Mark Butler
* <butlerm@xmission.com>.
*/
CURLcode static CURLcode static
Transfer(struct connectdata *c_conn) Transfer(struct connectdata *c_conn)
@ -317,6 +328,10 @@ Transfer(struct connectdata *c_conn)
/* copy what is remaining into headerbuff */ /* copy what is remaining into headerbuff */
int str_length = (int)strlen(str); int str_length = (int)strlen(str);
/*
* We enlarge the header buffer if it seems to be too
* smallish
*/
if (hbuflen + (int)str_length >= data->headersize) { if (hbuflen + (int)str_length >= data->headersize) {
char *newbuff; char *newbuff;
long newsize=MAX((hbuflen+str_length)*3/2, long newsize=MAX((hbuflen+str_length)*3/2,
@ -339,6 +354,12 @@ Transfer(struct connectdata *c_conn)
str = end_ptr + 1; /* move just past new line */ str = end_ptr + 1; /* move just past new line */
/*
* We're about to copy a chunk of data to the end of the
* already received header. We make sure that the full string
* fit in the allocated header buffer, or else we enlarge
* it.
*/
if (hbuflen + (str - str_start) >= data->headersize) { if (hbuflen + (str - str_start) >= data->headersize) {
char *newbuff; char *newbuff;
long newsize=MAX((hbuflen+(str-str_start))*3/2, long newsize=MAX((hbuflen+(str-str_start))*3/2,
@ -362,23 +383,17 @@ Transfer(struct connectdata *c_conn)
p = data->headerbuff; p = data->headerbuff;
/* we now have a full line that p points to */ /****
if (('\n' == *p) || ('\r' == *p)) { * We now have a FULL header line that p points to
/* Zero-length line means end of header! */ *****/
#if 0
if (-1 != conn->size) /* if known */
conn->size += bytecount; /* we append the already read
size */
#endif
if (('\n' == *p) || ('\r' == *p)) {
/* Zero-length header line means end of headers! */
if ('\r' == *p) if ('\r' == *p)
p++; /* pass the \r byte */ p++; /* pass the \r byte */
if ('\n' == *p) if ('\n' == *p)
p++; /* pass the \n byte */ p++; /* pass the \n byte */
#if 0 /* headers are not included in the size */
Curl_pgrsSetDownloadSize(data, conn->size);
#endif
if(100 == httpcode) { if(100 == httpcode) {
/* /*
@ -409,7 +424,7 @@ Transfer(struct connectdata *c_conn)
if(!header) { if(!header) {
/* /*
* end-of-headers. * really end-of-headers.
* *
* If we requested a "no body", this is a good time to get * If we requested a "no body", this is a good time to get
* out and return home. * out and return home.
@ -442,6 +457,10 @@ Transfer(struct connectdata *c_conn)
continue; continue;
} }
/*
* Checks for special headers coming up.
*/
if (!headerline++) { if (!headerline++) {
/* This is the first header, it MUST be the error code line /* This is the first header, it MUST be the error code line
or else we consiser this to be the body right away! */ or else we consiser this to be the body right away! */
@ -585,6 +604,10 @@ Transfer(struct connectdata *c_conn)
*ptr = backup; /* restore ending letter */ *ptr = backup; /* restore ending letter */
} }
/*
* End of header-checks. Write them to the client.
*/
writetype = CLIENTWRITE_HEADER; writetype = CLIENTWRITE_HEADER;
if (data->bits.http_include_header) if (data->bits.http_include_header)
writetype |= CLIENTWRITE_BODY; writetype |= CLIENTWRITE_BODY;
@ -792,6 +815,12 @@ Transfer(struct connectdata *c_conn)
} }
} }
} }
/*
* The tranfer has been performed. Just make some general checks before
* returning.
*/
if(!(data->bits.no_body) && contentlength && if(!(data->bits.no_body) && contentlength &&
(bytecount != contentlength)) { (bytecount != contentlength)) {
failf(data, "transfer closed with %d bytes remaining to read", failf(data, "transfer closed with %d bytes remaining to read",