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

The fread() callback pointer and associated pointer is now stored in the

connectdata struct instead, and is no longer modified within the 'set' struct
as previously (which was a really BAAAD thing).
This commit is contained in:
Daniel Stenberg 2002-12-09 15:37:54 +00:00
parent c65e088caf
commit 4bcc866c52
6 changed files with 241 additions and 237 deletions

View File

@ -1591,8 +1591,8 @@ CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
readthisamountnow = BUFSIZE; readthisamountnow = BUFSIZE;
actuallyread = actuallyread =
data->set.fread(data->state.buffer, 1, readthisamountnow, conn->fread(data->state.buffer, 1, readthisamountnow,
data->set.in); conn->fread_in);
passed += actuallyread; passed += actuallyread;
if(actuallyread != readthisamountnow) { if(actuallyread != readthisamountnow) {
@ -1623,7 +1623,7 @@ CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
} }
} }
/* Send everything on data->set.in to the socket */ /* Send everything on data->state.in to the socket */
if(data->set.ftp_append) { if(data->set.ftp_append) {
/* we append onto the file instead of rewriting it */ /* we append onto the file instead of rewriting it */
FTPSENDF(conn, "APPE %s", ftp->file); FTPSENDF(conn, "APPE %s", ftp->file);

View File

@ -126,8 +126,11 @@ send_buffer *add_buffer_init(void)
* add_buffer_send() sends a buffer and frees all associated memory. * add_buffer_send() sends a buffer and frees all associated memory.
*/ */
static static
CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in, CURLcode add_buffer_send(send_buffer *in,
long *bytes_written) int sockfd,
struct connectdata *conn,
long *bytes_written) /* add the number of sent
bytes to this counter */
{ {
ssize_t amount; ssize_t amount;
CURLcode res; CURLcode res;
@ -149,6 +152,8 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
/* this data _may_ contain binary stuff */ /* this data _may_ contain binary stuff */
Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr, amount); Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr, amount);
*bytes_written += amount;
if(amount != size) { if(amount != size) {
size -= amount; size -= amount;
ptr += amount; ptr += amount;
@ -162,8 +167,6 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
free(in->buffer); free(in->buffer);
free(in); free(in);
*bytes_written += amount;
return res; return res;
} }
@ -517,8 +520,9 @@ CURLcode Curl_http_done(struct connectdata *conn)
Curl_formclean(http->sendit); /* Now free that whole lot */ Curl_formclean(http->sendit); /* Now free that whole lot */
data->set.fread = http->storefread; /* restore */ /* set the proper values */
data->set.in = http->in; /* restore */ conn->fread = data->set.fread; /* restore */
conn->fread_in = data->set.in; /* restore */
} }
else if(HTTPREQ_PUT == data->set.httpreq) else if(HTTPREQ_PUT == data->set.httpreq)
conn->bytecount = http->readbytecount + http->writebytecount; conn->bytecount = http->readbytecount + http->writebytecount;
@ -923,13 +927,9 @@ CURLcode Curl_http(struct connectdata *conn)
return CURLE_HTTP_POST_ERROR; return CURLE_HTTP_POST_ERROR;
} }
http->storefread = data->set.fread; /* backup */ /* set the read function to read from the generated form data */
http->in = data->set.in; /* backup */ conn->fread = (curl_read_callback)Curl_FormReader;
conn->fread_in = &http->form;
data->set.fread = (curl_read_callback)
Curl_FormReader; /* set the read function to read from the
generated form data */
data->set.in = (FILE *)&http->form;
if(!conn->bits.upload_chunky) if(!conn->bits.upload_chunky)
/* only add Content-Length if not uploading chunked */ /* only add Content-Length if not uploading chunked */
@ -974,7 +974,7 @@ CURLcode Curl_http(struct connectdata *conn)
Curl_pgrsSetUploadSize(data, http->postsize); Curl_pgrsSetUploadSize(data, http->postsize);
/* fire away the whole request to the server */ /* fire away the whole request to the server */
result = add_buffer_send(conn->firstsocket, conn, req_buffer, result = add_buffer_send(req_buffer, conn->firstsocket, conn,
&data->info.request_size); &data->info.request_size);
if(result) if(result)
failf(data, "Failed sending POST request"); failf(data, "Failed sending POST request");
@ -1004,10 +1004,10 @@ CURLcode Curl_http(struct connectdata *conn)
Curl_pgrsSetUploadSize(data, data->set.infilesize); Curl_pgrsSetUploadSize(data, data->set.infilesize);
/* this sends the buffer and frees all the buffer resources */ /* this sends the buffer and frees all the buffer resources */
result = add_buffer_send(conn->firstsocket, conn, req_buffer, result = add_buffer_send(req_buffer, conn->firstsocket, conn,
&data->info.request_size); &data->info.request_size);
if(result) if(result)
failf(data, "Faied sending POST request"); failf(data, "Failed sending POST request");
else else
/* prepare for transfer */ /* prepare for transfer */
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
@ -1053,7 +1053,7 @@ CURLcode Curl_http(struct connectdata *conn)
data->set.postfields ); data->set.postfields );
/* issue the request */ /* issue the request */
result = add_buffer_send(conn->firstsocket, conn, req_buffer, result = add_buffer_send(req_buffer, conn->firstsocket, conn,
&data->info.request_size); &data->info.request_size);
if(result) if(result)
@ -1070,7 +1070,7 @@ CURLcode Curl_http(struct connectdata *conn)
add_buffer(req_buffer, "\r\n", 2); add_buffer(req_buffer, "\r\n", 2);
/* issue the request */ /* issue the request */
result = add_buffer_send(conn->firstsocket, conn, req_buffer, result = add_buffer_send(req_buffer, conn->firstsocket, conn,
&data->info.request_size); &data->info.request_size);
if(result) if(result)

View File

@ -275,7 +275,8 @@ int cert_stuff(struct connectdata *conn,
if (SSL_CTX_use_PrivateKey_file(conn->ssl.ctx, if (SSL_CTX_use_PrivateKey_file(conn->ssl.ctx,
key_file, key_file,
file_type) != 1) { file_type) != 1) {
failf(data, "unable to set private key file\n"); failf(data, "unable to set private key file: '%s' type %s\n",
key_file, key_type?key_type:"PEM");
return 0; return 0;
} }
break; break;

View File

@ -597,7 +597,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
else if(checkprefix("Last-Modified:", k->p) && else if(checkprefix("Last-Modified:", k->p) &&
(data->set.timecondition || data->set.get_filetime) ) { (data->set.timecondition || data->set.get_filetime) ) {
time_t secs=time(NULL); time_t secs=time(NULL);
k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"), k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
&secs); &secs);
if(data->set.get_filetime) if(data->set.get_filetime)
data->info.filetime = k->timeofdoc; data->info.filetime = k->timeofdoc;
@ -793,8 +793,8 @@ k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
} }
if(k->badheader < HEADER_ALLBAD) { if(k->badheader < HEADER_ALLBAD) {
/* This switch handles various content encodings. If there's an /* This switch handles various content encodings. If there's an
error here, be sure to check over the almost identical code in error here, be sure to check over the almost identical code
http_chunk.c. 08/29/02 jhrg */ in http_chunk.c. 08/29/02 jhrg */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
switch (k->content_encoding) { switch (k->content_encoding) {
case IDENTITY: case IDENTITY:
@ -874,8 +874,8 @@ k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
conn->upload_fromhere += 10; /* 32bit hex + CRLF */ conn->upload_fromhere += 10; /* 32bit hex + CRLF */
} }
nread = data->set.fread(conn->upload_fromhere, 1, nread = conn->fread(conn->upload_fromhere, 1,
buffersize, data->set.in); buffersize, conn->fread_in);
if(conn->bits.upload_chunky) { if(conn->bits.upload_chunky) {
/* if chunked Transfer-Encoding */ /* if chunked Transfer-Encoding */
@ -944,12 +944,12 @@ k->timeofdoc = curl_getdate(k->p+strlen("Last-Modified:"),
that instead of reading more data */ that instead of reading more data */
} }
/* write to socket */ /* write to socket (send away data) */
result = Curl_write(conn, result = Curl_write(conn,
conn->writesockfd, conn->writesockfd, /* socket to send to */
conn->upload_fromhere, conn->upload_fromhere, /* buffer pointer */
conn->upload_present, conn->upload_present, /* buffer size */
&bytes_written); &bytes_written); /* actually send away */
if(result) if(result)
return result; return result;
else if(conn->upload_present != bytes_written) { else if(conn->upload_present != bytes_written) {

View File

@ -1789,6 +1789,9 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* else, no chunky upload */ /* else, no chunky upload */
FALSE; FALSE;
conn->fread = data->set.fread;
conn->fread_in = data->set.in;
/*********************************************************** /***********************************************************
* We need to allocate memory to store the path in. We get the size of the * We need to allocate memory to store the path in. We get the size of the
* full URL to be sure, and we need to make it at least 256 bytes since * full URL to be sure, and we need to make it at least 256 bytes since

View File

@ -164,9 +164,6 @@ struct HTTP {
/* For FORM posting */ /* For FORM posting */
struct Form form; struct Form form;
curl_read_callback storefread;
FILE *in;
struct Curl_chunker chunk; struct Curl_chunker chunk;
}; };
@ -458,6 +455,9 @@ struct connectdata {
and the 'upload_present' contains the number of bytes available at this and the 'upload_present' contains the number of bytes available at this
position */ position */
char *upload_fromhere; char *upload_fromhere;
curl_read_callback fread; /* function that reads the input */
void *fread_in; /* pointer to pass to the fread() above */
}; };
/* The end of connectdata. 08/27/02 jhrg */ /* The end of connectdata. 08/27/02 jhrg */
@ -633,7 +633,7 @@ struct UserDefined {
bool free_referer; /* set TRUE if 'referer' points to a string we bool free_referer; /* set TRUE if 'referer' points to a string we
allocated */ allocated */
char *useragent; /* User-Agent string */ char *useragent; /* User-Agent string */
char *encoding; /* Accept-Encoding string 08/28/02 jhrg */ char *encoding; /* Accept-Encoding string */
char *postfields; /* if POST, set the fields' values here */ char *postfields; /* if POST, set the fields' values here */
size_t postfieldsize; /* if POST, this might have a size to use instead of size_t postfieldsize; /* if POST, this might have a size to use instead of
strlen(), and then the data *may* be binary (contain strlen(), and then the data *may* be binary (contain