5
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
8
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
* This software is licensed as described in the file COPYING, which
11
11
* you should have received as part of this distribution. The terms
18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: sendf.c,v 1.98 2005/04/07 15:27:14 bagder Exp $
21
* $Id: sendf.c,v 1.102 2006-05-05 10:24:27 bagder Exp $
22
22
***************************************************************************/
142
#ifdef CURL_DO_LINEEND_CONV
144
* convert_lineends() changes CRLF (\r\n) end-of-line markers to a single LF
145
* (\n), with special processing for CRLF sequences that are split between two
146
* blocks of data. Remaining, bare CRs are changed to LFs. The possibly new
147
* size of the data is returned.
149
static size_t convert_lineends(struct SessionHandle *data,
150
char *startPtr, size_t size)
152
char *inPtr, *outPtr;
155
if ((startPtr == NULL) || (size < 1)) {
159
if (data->state.prev_block_had_trailing_cr == TRUE) {
160
/* The previous block of incoming data
161
had a trailing CR, which was turned into a LF. */
162
if (*startPtr == '\n') {
163
/* This block of incoming data starts with the
164
previous block's LF so get rid of it */
165
memcpy(startPtr, startPtr+1, size-1);
167
/* and it wasn't a bare CR but a CRLF conversion instead */
168
data->state.crlf_conversions++;
170
data->state.prev_block_had_trailing_cr = FALSE; /* reset the flag */
173
/* find 1st CR, if any */
174
inPtr = outPtr = memchr(startPtr, '\r', size);
176
/* at least one CR, now look for CRLF */
177
while (inPtr < (startPtr+size-1)) {
178
/* note that it's size-1, so we'll never look past the last byte */
179
if (memcmp(inPtr, "\r\n", 2) == 0) {
180
/* CRLF found, bump past the CR and copy the NL */
183
/* keep track of how many CRLFs we converted */
184
data->state.crlf_conversions++;
187
if (*inPtr == '\r') {
188
/* lone CR, move LF instead */
192
/* not a CRLF nor a CR, just copy whatever it is */
198
} /* end of while loop */
200
if (inPtr < startPtr+size) {
201
/* handle last byte */
202
if (*inPtr == '\r') {
203
/* deal with a CR at the end of the buffer */
204
*outPtr = '\n'; /* copy a NL instead */
205
/* note that a CRLF might be split across two blocks */
206
data->state.prev_block_had_trailing_cr = TRUE;
215
if (outPtr < startPtr+size) {
216
/* tidy up by null terminating the now shorter data */
219
return(outPtr - startPtr);
223
#endif /* CURL_DO_LINEEND_CONV */
141
225
/* Curl_infof() is for info message along the way */
143
227
void Curl_infof(struct SessionHandle *data, const char *fmt, ...)
294
378
len = strlen(ptr);
296
380
if(type & CLIENTWRITE_BODY) {
297
wrote = data->set.fwrite(ptr, 1, len, data->set.out);
381
if(data->ftp_in_ascii_mode) {
382
#ifdef CURL_DOES_CONVERSIONS
383
/* convert from the network encoding */
385
rc = Curl_convert_from_network(data, ptr, len);
386
/* Curl_convert_from_network calls failf if unsuccessful */
389
#endif /* CURL_DOES_CONVERSIONS */
391
#ifdef CURL_DO_LINEEND_CONV
392
/* convert end-of-line markers */
393
len = convert_lineends(data, ptr, len);
394
#endif /* CURL_DO_LINEEND_CONV */
396
/* If the previous block of data ended with CR and this block of data is
397
just a NL, then the length might be zero */
399
wrote = data->set.fwrite(ptr, 1, len, data->set.out);
298
405
if(wrote != len) {
299
406
failf (data, "Failed writing body");
300
407
return CURLE_WRITE_ERROR;
303
411
if((type & CLIENTWRITE_HEADER) &&
304
412
(data->set.fwrite_header || data->set.writeheader) ) {
309
417
curl_write_callback writeit=
310
418
data->set.fwrite_header?data->set.fwrite_header:data->set.fwrite;
420
/* Note: The header is in the host encoding
421
regardless of the ftp transfer mode (ASCII/Image) */
312
423
wrote = writeit(ptr, 1, len, data->set.writeheader);
313
424
if(wrote != len) {
314
425
failf (data, "Failed writing header");
375
486
static const char * const s_infotype[CURLINFO_END] = {
376
487
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
489
#ifdef CURL_DOES_CONVERSIONS
493
case CURLINFO_HEADER_OUT:
494
/* assume output headers are ASCII */
495
/* copy the data into my buffer so the original is unchanged */
496
if (size > BUFSIZE) {
497
size = BUFSIZE; /* truncate if necessary */
500
memcpy(buf, ptr, size);
501
Curl_convert_from_network(data, buf, size);
502
/* Curl_convert_from_network calls failf if unsuccessful */
503
/* we might as well continue even if it fails... */
504
ptr = buf; /* switch pointer to use my buffer instead */
507
/* leave everything else as-is */
510
#endif /* CURL_DOES_CONVERSIONS */
378
512
if(data->set.fdebug)
379
513
return (*data->set.fdebug)(data, type, ptr, size,
380
514
data->set.debugdata);