From 55b8ceac18339c7b7d95c9033667cd7431eb2fa7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Mar 2001 23:28:22 +0000 Subject: chunked transfer encoding support --- lib/http_chunks.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 lib/http_chunks.c (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c new file mode 100644 index 000000000..d22de18d1 --- /dev/null +++ b/lib/http_chunks.c @@ -0,0 +1,188 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2001, Daniel Stenberg, , et al. + * + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + *****************************************************************************/ +#include "setup.h" + +/* -- WIN32 approved -- */ +#include +#include +#include +#include +#include + +#include "urldata.h" /* it includes http_chunks.h */ +#include "sendf.h" /* for the client write stuff */ + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + +/* The last #include file should be: */ +#ifdef MALLOCDEBUG +#include "memdebug.h" +#endif + +/* + * Chunk format (simplified): + * + * [ chunk extension ] CRLF + * + * + * Highlights from RFC2616 section 3.6 say: + + The chunked encoding modifies the body of a message in order to + transfer it as a series of chunks, each with its own size indicator, + followed by an OPTIONAL trailer containing entity-header fields. This + allows dynamically produced content to be transferred along with the + information necessary for the recipient to verify that it has + received the full message. + + Chunked-Body = *chunk + last-chunk + trailer + CRLF + + chunk = chunk-size [ chunk-extension ] CRLF + chunk-data CRLF + chunk-size = 1*HEX + last-chunk = 1*("0") [ chunk-extension ] CRLF + + chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) + chunk-ext-name = token + chunk-ext-val = token | quoted-string + chunk-data = chunk-size(OCTET) + trailer = *(entity-header CRLF) + + The chunk-size field is a string of hex digits indicating the size of + the chunk. The chunked encoding is ended by any chunk whose size is + zero, followed by the trailer, which is terminated by an empty line. + + */ + + +void Curl_httpchunk_init(struct connectdata *conn) +{ + struct Curl_chunker *chunk = &conn->proto.http->chunk; + chunk->hexindex=0; /* start at 0 */ + chunk->state = CHUNK_HEX; /* we get hex first! */ +} + +/* + * chunk_read() returns a 0 for normal operations, or a positive return code + * for errors. A negative number means this sequence of chunks is complete, + * and that many ~bytes were NOT used at the end of the buffer passed in. + * The 'wrote' argument is set to tell the caller how many bytes we actually + * passed to the client (for byte-counting and whatever). + * + * The states and the state-machine is further explained in the header file. + */ +CHUNKcode Curl_httpchunk_read(struct connectdata *conn, + char *datap, + ssize_t length, + ssize_t *wrote) +{ + CURLcode result; + struct Curl_chunker *ch = &conn->proto.http->chunk; + int piece; + *wrote = 0; /* nothing yet */ + + while(length) { + switch(ch->state) { + case CHUNK_HEX: + if(isxdigit((int)*datap)) { + if(ch->hexindex < MAXNUM_SIZE) { + ch->hexbuffer[ch->hexindex] = *datap; + datap++; + length--; + ch->hexindex++; + } + else { + return 1; /* longer hex than we support */ + } + } + else { + /* length and datap are unmodified */ + ch->hexbuffer[ch->hexindex]=0; + ch->datasize=strtoul(ch->hexbuffer, NULL, 16); + ch->state = CHUNK_POSTHEX; + } + break; + + case CHUNK_POSTHEX: + /* just a lame state waiting for CRLF to arrive */ + if(*datap == '\r') + ch->state = CHUNK_CR; + length--; + datap++; + break; + + case CHUNK_CR: + /* waiting for the LF */ + if(*datap == '\n') { + /* we're now expecting data to come, unless size was zero! */ + if(0 == ch->datasize) { + ch->state = CHUNK_STOP; /* stop reading! */ + if(1 == length) { + /* This was the final byte, return right now */ + return ~0; + } + } + else + ch->state = CHUNK_DATA; + } + else + /* previously we got a fake CR, go back to CR waiting! */ + ch->state = CHUNK_CR; + datap++; + length--; + break; + + case CHUNK_DATA: + /* we get pure and fine data + + We expect another 'datasize' of data. We have 'length' right now, + it can be more or less than 'datasize'. Get the smallest piece. + */ + piece = (ch->datasize >= length)?length:ch->datasize; + + /* Write the data portion available */ + result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, piece); + if(result) + return CHUNKE_WRITE_ERROR; + *wrote += piece; + + ch->datasize -= piece; /* decrease amount left to expect */ + datap += piece; /* move read pointer forward */ + length -= piece; /* decrease space left in this round */ + + if(0 == ch->datasize) + /* end of data this round, go back to get a new size */ + Curl_httpchunk_init(conn); + + break; + case CHUNK_STOP: + return ~length; /* return the data size left */ + default: + return CHUNKE_STATE_ERROR; + } + } + return CHUNKE_OK; +} -- cgit v1.2.1 From a23db7b7c7a183cbab8eadc59d73aaa159d301de Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Mar 2001 23:51:41 +0000 Subject: "Transfer-Encoding: chunked" support added --- lib/http_chunks.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index d22de18d1..bbc208e21 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -82,15 +82,15 @@ void Curl_httpchunk_init(struct connectdata *conn) { struct Curl_chunker *chunk = &conn->proto.http->chunk; chunk->hexindex=0; /* start at 0 */ + chunk->dataleft=0; /* no data left yet! */ chunk->state = CHUNK_HEX; /* we get hex first! */ } /* - * chunk_read() returns a 0 for normal operations, or a positive return code - * for errors. A negative number means this sequence of chunks is complete, - * and that many ~bytes were NOT used at the end of the buffer passed in. - * The 'wrote' argument is set to tell the caller how many bytes we actually - * passed to the client (for byte-counting and whatever). + * chunk_read() returns a OK for normal operations, or a positive return code + * for errors. STOP means this sequence of chunks is complete. The 'wrote' + * argument is set to tell the caller how many bytes we actually passed to the + * client (for byte-counting and whatever). * * The states and the state-machine is further explained in the header file. */ @@ -142,7 +142,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, ch->state = CHUNK_STOP; /* stop reading! */ if(1 == length) { /* This was the final byte, return right now */ - return ~0; + return CHUNKE_STOP; } } else @@ -179,7 +179,10 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_STOP: - return ~length; /* return the data size left */ + /* If we arrive here, there is data left in the end of the buffer + even if there's no more chunks to read */ + ch->dataleft = length; + return CHUNKE_STOP; /* return stop */ default: return CHUNKE_STATE_ERROR; } -- cgit v1.2.1 From d95fa648e9da36386c452c624b080bb97cf7c4b4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Mar 2001 15:20:35 +0000 Subject: made it return illegal hex in case no hexadecimal digit was read when at least one was expected --- lib/http_chunks.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index bbc208e21..c11003354 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -115,10 +115,15 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, ch->hexindex++; } else { - return 1; /* longer hex than we support */ + return CHUNKE_TOO_LONG_HEX; /* longer hex than we support */ } } else { + if(0 == ch->hexindex) { + /* This is illegal data, we received junk where we expected + a hexadecimal digit. */ + return CHUNKE_ILLEGAL_HEX; + } /* length and datap are unmodified */ ch->hexbuffer[ch->hexindex]=0; ch->datasize=strtoul(ch->hexbuffer, NULL, 16); @@ -127,7 +132,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_POSTHEX: - /* just a lame state waiting for CRLF to arrive */ + /* In this state, we're waiting for CRLF to arrive. We support + this to allow so called chunk-extensions to show up here + before the CRLF comes. */ if(*datap == '\r') ch->state = CHUNK_CR; length--; -- cgit v1.2.1 From 195233ed5c6aa8c325424072df7ea24074e7feff Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 13 Mar 2001 22:16:42 +0000 Subject: updated the chunked state-machine to deal with the trailing CRLF that comes after the data part --- lib/http_chunks.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index c11003354..89c860918 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -181,17 +181,43 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, length -= piece; /* decrease space left in this round */ if(0 == ch->datasize) - /* end of data this round, go back to get a new size */ - Curl_httpchunk_init(conn); + /* end of data this round, we now expect a trailing CRLF */ + ch->state = CHUNK_POSTCR; + break; + + case CHUNK_POSTCR: + if(*datap == '\r') { + ch->state = CHUNK_POSTLF; + datap++; + length--; + } + else + return CHUNKE_BAD_CHUNK; + break; + case CHUNK_POSTLF: + if(*datap == '\n') { + /* + * The last one before we go back to hex state and start all + * over. + */ + Curl_httpchunk_init(conn); + datap++; + length--; + } + else + return CHUNKE_BAD_CHUNK; break; + case CHUNK_STOP: /* If we arrive here, there is data left in the end of the buffer even if there's no more chunks to read */ ch->dataleft = length; return CHUNKE_STOP; /* return stop */ +#if 0 default: return CHUNKE_STATE_ERROR; +#endif } } return CHUNKE_OK; -- cgit v1.2.1 From 147de35d412db25b82ef465bee1433daad7cc303 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 13 Mar 2001 23:29:53 +0000 Subject: re-added the default switch for weird states --- lib/http_chunks.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 89c860918..d4badeb90 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -214,10 +214,8 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, even if there's no more chunks to read */ ch->dataleft = length; return CHUNKE_STOP; /* return stop */ -#if 0 default: return CHUNKE_STATE_ERROR; -#endif } } return CHUNKE_OK; -- cgit v1.2.1 From 0c063f85fcfb644af0d0d24fc53b38a9e447f3a6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 14 Aug 2001 08:29:09 +0000 Subject: Curl_httpchunk_read now takes size_t size arguments instead of the previous ssize_t --- lib/http_chunks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index d4badeb90..1a34f5ec6 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -96,8 +96,8 @@ void Curl_httpchunk_init(struct connectdata *conn) */ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, - ssize_t length, - ssize_t *wrote) + size_t length, + size_t *wrote) { CURLcode result; struct Curl_chunker *ch = &conn->proto.http->chunk; -- cgit v1.2.1 From 144459d36402875864c941c21c02bb81e1165ce5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 3 Sep 2001 12:51:23 +0000 Subject: corrected the comment to be valid chunk format --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 1a34f5ec6..02d7f3788 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -44,7 +44,7 @@ * Chunk format (simplified): * * [ chunk extension ] CRLF - * + * CRLF * * Highlights from RFC2616 section 3.6 say: -- cgit v1.2.1 From 6147879837a53d22c9be04e7a4fc315a297ba2b3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 7 Sep 2001 04:01:32 +0000 Subject: Added formatting sections for emacs and vim --- lib/http_chunks.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 02d7f3788..9cb2aa473 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -220,3 +220,11 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } return CHUNKE_OK; } + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker + * vim<600: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From 8e91d5de8e4e17ce3d4936cc91171d09726e7bb3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 11 Oct 2001 09:32:19 +0000 Subject: looks nicer and is better compatible with older vim versions --- lib/http_chunks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 9cb2aa473..17540796c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -225,6 +225,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, * local variables: * eval: (load-file "../curl-mode.el") * end: - * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker - * vim<600: et sw=2 ts=2 sts=2 tw=78 + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 */ -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 17540796c..a49e405e7 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2001, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From 08ef208fb78fb2eabc5cec08c23e74e251eac898 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 Jun 2002 11:13:01 +0000 Subject: added disable-[protocol] support, largely provided by Miklos Nemeth --- lib/http_chunks.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index a49e405e7..939e86a91 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -22,6 +22,7 @@ *****************************************************************************/ #include "setup.h" +#ifndef CURL_DISABLE_HTTP /* -- WIN32 approved -- */ #include #include @@ -228,3 +229,4 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, * vim600: fdm=marker * vim: et sw=2 ts=2 sts=2 tw=78 */ +#endif /* CURL_DISABLE_HTTP */ -- cgit v1.2.1 From 64bbe9dfafc6693a96b742f3133c636385835a19 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 2 Sep 2002 22:31:18 +0000 Subject: James Gallagher's Content-Encoding work --- lib/http_chunks.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 939e86a91..784d231fe 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -33,6 +33,8 @@ #include "urldata.h" /* it includes http_chunks.h */ #include "sendf.h" /* for the client write stuff */ +#include "content_encoding.h" /* 08/29/02 jhrg */ + #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -172,7 +174,32 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, piece = (ch->datasize >= length)?length:ch->datasize; /* Write the data portion available */ - result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, piece); + /* Added content-encoding here; untested but almost identical to the + tested code in transfer.c. 08/29/02 jhrg */ +#ifdef HAVE_LIBZ + switch (conn->keep.content_encoding) { + case IDENTITY: +#endif + result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, + piece); +#ifdef HAVE_LIBZ + break; + + case DEFLATE: + result = Curl_unencode_deflate_write(conn->data, &conn->keep, piece); + break; + + case GZIP: + case COMPRESS: + default: + failf (conn->data, + "Unrecognized content encoding type. " + "libcurl understands `identity' and `deflate' " + "content encodings."); + return CHUNKE_BAD_ENCODING; + } +#endif + if(result) return CHUNKE_WRITE_ERROR; *wrote += piece; -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/http_chunks.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 784d231fe..6d2a640dd 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" #ifndef CURL_DISABLE_HTTP -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 6d2a640dd..b949a8c26 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/http_chunks.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index b949a8c26..60f0aa2cd 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -248,12 +248,4 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } return CHUNKE_OK; } - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ #endif /* CURL_DISABLE_HTTP */ -- cgit v1.2.1 From 019c4088cfcca0d2b7c5cc4f52ca5dac0c616089 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Apr 2003 08:49:20 +0000 Subject: Dan Fandrich's gzip patch applied --- lib/http_chunks.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 60f0aa2cd..6fea493ac 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -190,6 +190,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case GZIP: + result = Curl_unencode_gzip_write(conn->data, &conn->keep, piece); + break; + case COMPRESS: default: failf (conn->data, -- cgit v1.2.1 From 7b51b2f12834f09763d4e53cd1737d450d46cd9c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Apr 2003 16:23:43 +0000 Subject: Nic Hines fixed this bug when deflate or gzip contents were downloaded using chunked encoding. --- lib/http_chunks.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 6fea493ac..ca9b55366 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -186,10 +186,14 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case DEFLATE: + /* update conn->keep.str to point to the chunk data. */ + conn->keep.str = datap; result = Curl_unencode_deflate_write(conn->data, &conn->keep, piece); break; case GZIP: + /* update conn->keep.str to point to the chunk data. */ + conn->keep.str = datap; result = Curl_unencode_gzip_write(conn->data, &conn->keep, piece); break; -- cgit v1.2.1 From a84b0fbd527ee9ca79661ba1a4d2768fd356334f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 22 Apr 2003 22:33:39 +0000 Subject: Dan Fandrich corrected the error messages on "bad encoding". --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index ca9b55366..90f891f31 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -201,7 +201,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, default: failf (conn->data, "Unrecognized content encoding type. " - "libcurl understands `identity' and `deflate' " + "libcurl understands `identity', `deflate' and `gzip' " "content encodings."); return CHUNKE_BAD_ENCODING; } -- cgit v1.2.1 From 308bc9d919d57388f269c473778ea7f6a331d1c5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 26 Jun 2003 11:22:12 +0000 Subject: use CURLDEBUG instead of MALLOCDEBUG for preprocessor conditions --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 90f891f31..b0309fec8 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -39,7 +39,7 @@ #include /* The last #include file should be: */ -#ifdef MALLOCDEBUG +#ifdef CURLDEBUG #include "memdebug.h" #endif -- cgit v1.2.1 From f72ba7f79d3eb261f922d24072409ee300402059 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 3 Aug 2003 22:18:14 +0000 Subject: Mark Fletcher provided an excellent bug report that identified a problem with FOLLOWLOCATION and chunked transfer-encoding, as libcurl would not properly ignore the body contents of 3XX response that included the Location: header. --- lib/http_chunks.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index b0309fec8..ca3599ad0 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -102,8 +102,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, size_t length, size_t *wrote) { - CURLcode result; + CURLcode result=CURLE_OK; struct Curl_chunker *ch = &conn->proto.http->chunk; + struct Curl_transfer_keeper *k = &conn->keep; int piece; *wrote = 0; /* nothing yet */ @@ -180,8 +181,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, switch (conn->keep.content_encoding) { case IDENTITY: #endif - result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, - piece); + if(!k->ignorebody) + result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, + piece); #ifdef HAVE_LIBZ break; -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index ca3599ad0..38f2fd06f 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/http_chunks.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 38f2fd06f..70a48950a 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -34,6 +34,7 @@ #include "sendf.h" /* for the client write stuff */ #include "content_encoding.h" /* 08/29/02 jhrg */ +#include "http.h" #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -99,8 +100,8 @@ void Curl_httpchunk_init(struct connectdata *conn) */ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, - size_t length, - size_t *wrote) + ssize_t length, + ssize_t *wrote) { CURLcode result=CURLE_OK; struct Curl_chunker *ch = &conn->proto.http->chunk; -- cgit v1.2.1 From 1eb9fd6c4d93f7adbca00556575751537b4be47a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 4 Mar 2004 15:25:06 +0000 Subject: use size_t for the data, but keep the protos use ssize_t to better fit with the existing transfer.c code --- lib/http_chunks.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 70a48950a..673e8a0fe 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -100,14 +100,17 @@ void Curl_httpchunk_init(struct connectdata *conn) */ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, - ssize_t length, - ssize_t *wrote) + ssize_t datalen, + ssize_t *wrotep) { CURLcode result=CURLE_OK; struct Curl_chunker *ch = &conn->proto.http->chunk; struct Curl_transfer_keeper *k = &conn->keep; - int piece; - *wrote = 0; /* nothing yet */ + size_t piece; + size_t length = (size_t)datalen; + size_t *wrote = (size_t *)wrotep; + + *wrote = 0; /* nothing's written yet */ while(length) { switch(ch->state) { @@ -212,6 +215,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(result) return CHUNKE_WRITE_ERROR; + *wrote += piece; ch->datasize -= piece; /* decrease amount left to expect */ -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/http_chunks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 673e8a0fe..f939d2d06 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -35,14 +35,13 @@ #include "content_encoding.h" /* 08/29/02 jhrg */ #include "http.h" +#include "memory.h" #define _MPRINTF_REPLACE /* use our functions only */ #include /* The last #include file should be: */ -#ifdef CURLDEBUG #include "memdebug.h" -#endif /* * Chunk format (simplified): -- cgit v1.2.1 From aeb27ccfdb5cb87b14e6fbfeb2ef4afc06701412 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 12 May 2004 07:54:44 +0000 Subject: The Curl_unencode_XXX_write() function take a ssize_t as third argument, so we typecast on invoke. --- lib/http_chunks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index f939d2d06..baf2d66c0 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -33,7 +33,7 @@ #include "urldata.h" /* it includes http_chunks.h */ #include "sendf.h" /* for the client write stuff */ -#include "content_encoding.h" /* 08/29/02 jhrg */ +#include "content_encoding.h" #include "http.h" #include "memory.h" @@ -178,8 +178,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, piece = (ch->datasize >= length)?length:ch->datasize; /* Write the data portion available */ - /* Added content-encoding here; untested but almost identical to the - tested code in transfer.c. 08/29/02 jhrg */ #ifdef HAVE_LIBZ switch (conn->keep.content_encoding) { case IDENTITY: @@ -193,13 +191,15 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case DEFLATE: /* update conn->keep.str to point to the chunk data. */ conn->keep.str = datap; - result = Curl_unencode_deflate_write(conn->data, &conn->keep, piece); + result = Curl_unencode_deflate_write(conn->data, &conn->keep, + (ssize_t)piece); break; case GZIP: /* update conn->keep.str to point to the chunk data. */ conn->keep.str = datap; - result = Curl_unencode_gzip_write(conn->data, &conn->keep, piece); + result = Curl_unencode_gzip_write(conn->data, &conn->keep, + (ssize_t)piece); break; case COMPRESS: -- cgit v1.2.1 From 750e77137629caf03e025821cff79496bb8c14ca Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 4 Mar 2005 00:14:45 +0000 Subject: killed trailing whitespace --- lib/http_chunks.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index baf2d66c0..7ea9dcc6e 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -43,7 +43,7 @@ /* The last #include file should be: */ #include "memdebug.h" -/* +/* * Chunk format (simplified): * * [ chunk extension ] CRLF @@ -188,7 +188,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, #ifdef HAVE_LIBZ break; - case DEFLATE: + case DEFLATE: /* update conn->keep.str to point to the chunk data. */ conn->keep.str = datap; result = Curl_unencode_deflate_write(conn->data, &conn->keep, -- cgit v1.2.1 From ab4086bc244bf3267976e9f0193e5ed4430190d8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 Mar 2005 07:02:02 +0000 Subject: Updated the copyright year since changes have been this year. --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 7ea9dcc6e..f333f9559 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 465e19dbe9603bacba53bd73a607d5fbb37c08a4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 12 Jul 2005 18:15:34 +0000 Subject: Adrian Schuur added trailer support in the chunked encoding stream. The trailer is then sent to the normal header callback/stream. --- lib/http_chunks.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index f333f9559..63e136cb7 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -153,10 +153,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(*datap == '\n') { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { - ch->state = CHUNK_STOP; /* stop reading! */ - if(1 == length) { - /* This was the final byte, return right now */ - return CHUNKE_STOP; + if (conn->bits.trailerHdrPresent!=TRUE) { + /* No Trailer: header found - revert to original Curl processing */ + ch->state = CHUNK_STOP; + if (1 == length) { + /* This is the final byte, return right now */ + return CHUNKE_STOP; + } + } + else { + ch->state = CHUNK_TRAILER; /* attempt to read trailers */ + conn->trlPos=0; } } else @@ -250,6 +257,64 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_BAD_CHUNK; break; + case CHUNK_TRAILER: + /* conn->trailer is assumed to be freed in url.c on a + connection basis */ + if (conn->trlPos >= conn->trlMax) { + char *ptr; + if(conn->trlMax) { + conn->trlMax *= 2; + ptr = (char*)realloc(conn->trailer,conn->trlMax); + } + else { + conn->trlMax=128; + ptr = (char*)malloc(conn->trlMax); + } + if(!ptr) + return CHUNKE_OUT_OF_MEMORY; + conn->trailer = ptr; + } + conn->trailer[conn->trlPos++]=*datap; + + if(*datap == '\r') + ch->state = CHUNK_TRAILER_CR; + else { + datap++; + length--; + } + break; + + case CHUNK_TRAILER_CR: + if(*datap == '\r') { + ch->state = CHUNK_TRAILER_POSTCR; + datap++; + length--; + } + else + return CHUNKE_BAD_CHUNK; + break; + + case CHUNK_TRAILER_POSTCR: + if (*datap == '\n') { + conn->trailer[conn->trlPos++]='\n'; + conn->trailer[conn->trlPos]=0; + if (conn->trlPos==2) { + ch->state = CHUNK_STOP; + return CHUNKE_STOP; + } + else { + Curl_client_write(conn->data, CLIENTWRITE_HEADER, + conn->trailer, conn->trlPos); + } + ch->state = CHUNK_TRAILER; + conn->trlPos=0; + datap++; + length--; + } + else + return CHUNKE_BAD_CHUNK; + break; + case CHUNK_STOP: /* If we arrive here, there is data left in the end of the buffer even if there's no more chunks to read */ -- cgit v1.2.1 From cfdcae4bc75fba04b9864cae18e0bbe66b8655b9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 19 Aug 2006 21:18:36 +0000 Subject: Based on a patch by Armel Asselin, the FTP code no longer re-issues the TYPE command on subsequent requests on a re-used connection unless it has to. --- lib/http_chunks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 63e136cb7..30112f2b8 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -190,7 +190,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case IDENTITY: #endif if(!k->ignorebody) - result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, + result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, piece); #ifdef HAVE_LIBZ break; @@ -198,14 +198,14 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case DEFLATE: /* update conn->keep.str to point to the chunk data. */ conn->keep.str = datap; - result = Curl_unencode_deflate_write(conn->data, &conn->keep, + result = Curl_unencode_deflate_write(conn, &conn->keep, (ssize_t)piece); break; case GZIP: /* update conn->keep.str to point to the chunk data. */ conn->keep.str = datap; - result = Curl_unencode_gzip_write(conn->data, &conn->keep, + result = Curl_unencode_gzip_write(conn, &conn->keep, (ssize_t)piece); break; @@ -303,7 +303,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_STOP; } else { - Curl_client_write(conn->data, CLIENTWRITE_HEADER, + Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); } ch->state = CHUNK_TRAILER; -- cgit v1.2.1 From b7eeb6e67fca686f840eacd6b8394edb58b07482 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 7 Sep 2006 21:49:20 +0000 Subject: Major overhaul introducing http pipelining support and shared connection cache within the multi handle. --- lib/http_chunks.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 30112f2b8..8e9947f5d 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -83,7 +83,7 @@ void Curl_httpchunk_init(struct connectdata *conn) { - struct Curl_chunker *chunk = &conn->proto.http->chunk; + struct Curl_chunker *chunk = &conn->data->reqdata.proto.http->chunk; chunk->hexindex=0; /* start at 0 */ chunk->dataleft=0; /* no data left yet! */ chunk->state = CHUNK_HEX; /* we get hex first! */ @@ -103,8 +103,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, ssize_t *wrotep) { CURLcode result=CURLE_OK; - struct Curl_chunker *ch = &conn->proto.http->chunk; - struct Curl_transfer_keeper *k = &conn->keep; + struct SessionHandle *data = conn->data; + struct Curl_chunker *ch = &data->reqdata.proto.http->chunk; + struct Curl_transfer_keeper *k = &data->reqdata.keep; size_t piece; size_t length = (size_t)datalen; size_t *wrote = (size_t *)wrotep; @@ -186,7 +187,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* Write the data portion available */ #ifdef HAVE_LIBZ - switch (conn->keep.content_encoding) { + switch (data->reqdata.keep.content_encoding) { case IDENTITY: #endif if(!k->ignorebody) @@ -196,16 +197,16 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case DEFLATE: - /* update conn->keep.str to point to the chunk data. */ - conn->keep.str = datap; - result = Curl_unencode_deflate_write(conn, &conn->keep, + /* update data->reqdata.keep.str to point to the chunk data. */ + data->reqdata.keep.str = datap; + result = Curl_unencode_deflate_write(conn, &data->reqdata.keep, (ssize_t)piece); break; case GZIP: - /* update conn->keep.str to point to the chunk data. */ - conn->keep.str = datap; - result = Curl_unencode_gzip_write(conn, &conn->keep, + /* update data->reqdata.keep.str to point to the chunk data. */ + data->reqdata.keep.str = datap; + result = Curl_unencode_gzip_write(conn, &data->reqdata.keep, (ssize_t)piece); break; -- cgit v1.2.1 From 44d84ac1646cf04ccc2c1a736f3c9d1644ccacec Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 17 Oct 2006 21:32:56 +0000 Subject: Avoid typecasting a signed char to an int when using is*() functions, as that could very well cause a negate number get passed in and thus cause reading outside of the array usually used for this purpose. We avoid this by using the uppercase macro versions introduced just now that does some extra crazy typecasts to avoid byte codes > 127 to cause negative int values. --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 8e9947f5d..f398b100c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -115,7 +115,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, while(length) { switch(ch->state) { case CHUNK_HEX: - if(isxdigit((int)*datap)) { + if(ISXDIGIT(*datap)) { if(ch->hexindex < MAXNUM_SIZE) { ch->hexbuffer[ch->hexindex] = *datap; datap++; -- cgit v1.2.1 From 0fb5a65a58130da7882f0a8d396e24b95c25064f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 14 Jan 2007 14:57:51 +0000 Subject: - David McCreedy provided libcurl changes for doing HTTP communication on non-ASCII platforms. It does add some complexity, most notably with more #ifdefs, but I want to see this supported added and I can't see how we can add it without the extra stuff added. --- lib/http_chunks.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index f398b100c..d9774a2c3 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -36,6 +36,7 @@ #include "content_encoding.h" #include "http.h" #include "memory.h" +#include "easyif.h" /* for Curl_convert_to_network prototype */ #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -96,6 +97,9 @@ void Curl_httpchunk_init(struct connectdata *conn) * client (for byte-counting and whatever). * * The states and the state-machine is further explained in the header file. + * + * This function always uses ASCII hex values to accommodate non-ASCII hosts. + * For example, 0x0d and 0x0a are used instead of '\r' and '\n'. */ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, @@ -115,7 +119,11 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, while(length) { switch(ch->state) { case CHUNK_HEX: - if(ISXDIGIT(*datap)) { + /* Check for an ASCII hex digit. + We avoid the use of isxdigit to accommodate non-ASCII hosts. */ + if((*datap >= 0x30 && *datap <= 0x39) /* 0-9 */ + || (*datap >= 0x41 && *datap <= 0x46) /* A-F */ + || (*datap >= 0x61 && *datap <= 0x66)) { /* a-f */ if(ch->hexindex < MAXNUM_SIZE) { ch->hexbuffer[ch->hexindex] = *datap; datap++; @@ -134,6 +142,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } /* length and datap are unmodified */ ch->hexbuffer[ch->hexindex]=0; +#ifdef CURL_DOES_CONVERSIONS + /* convert to host encoding before calling strtoul */ + result = Curl_convert_from_network(conn->data, + ch->hexbuffer, + ch->hexindex); + if(result != CURLE_OK) { + /* Curl_convert_from_network calls failf if unsuccessful */ + /* Treat it as a bad hex character */ + return(CHUNKE_ILLEGAL_HEX); + } +#endif /* CURL_DOES_CONVERSIONS */ ch->datasize=strtoul(ch->hexbuffer, NULL, 16); ch->state = CHUNK_POSTHEX; } @@ -143,7 +162,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* In this state, we're waiting for CRLF to arrive. We support this to allow so called chunk-extensions to show up here before the CRLF comes. */ - if(*datap == '\r') + if(*datap == 0x0d) ch->state = CHUNK_CR; length--; datap++; @@ -151,7 +170,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case CHUNK_CR: /* waiting for the LF */ - if(*datap == '\n') { + if(*datap == 0x0a) { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { if (conn->bits.trailerHdrPresent!=TRUE) { @@ -235,7 +254,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_POSTCR: - if(*datap == '\r') { + if(*datap == 0x0d) { ch->state = CHUNK_POSTLF; datap++; length--; @@ -245,7 +264,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_POSTLF: - if(*datap == '\n') { + if(*datap == 0x0a) { /* * The last one before we go back to hex state and start all * over. @@ -277,7 +296,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } conn->trailer[conn->trlPos++]=*datap; - if(*datap == '\r') + if(*datap == 0x0d) ch->state = CHUNK_TRAILER_CR; else { datap++; @@ -286,7 +305,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_TRAILER_CR: - if(*datap == '\r') { + if(*datap == 0x0d) { ch->state = CHUNK_TRAILER_POSTCR; datap++; length--; @@ -296,14 +315,25 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_TRAILER_POSTCR: - if (*datap == '\n') { - conn->trailer[conn->trlPos++]='\n'; + if (*datap == 0x0a) { + conn->trailer[conn->trlPos++]=0x0a; conn->trailer[conn->trlPos]=0; if (conn->trlPos==2) { ch->state = CHUNK_STOP; return CHUNKE_STOP; } else { +#ifdef CURL_DOES_CONVERSIONS + /* Convert to host encoding before calling Curl_client_write */ + result = Curl_convert_from_network(conn->data, + ch->hexbuffer, + ch->hexindex); + if(result != CURLE_OK) { + /* Curl_convert_from_network calls failf if unsuccessful */ + /* Treat it as a bad chunk */ + return(CHUNKE_BAD_CHUNK); + } +#endif /* CURL_DOES_CONVERSIONS */ Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); } -- cgit v1.2.1 From 8cade952bf053cbcd8993c2df13d8b952d9c2f45 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 16 Jan 2007 22:26:50 +0000 Subject: David McCreedy fixed a flaw from his previous non-ascii HTTP patch --- lib/http_chunks.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index d9774a2c3..1b03a5569 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -324,15 +324,15 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } else { #ifdef CURL_DOES_CONVERSIONS - /* Convert to host encoding before calling Curl_client_write */ - result = Curl_convert_from_network(conn->data, - ch->hexbuffer, - ch->hexindex); - if(result != CURLE_OK) { - /* Curl_convert_from_network calls failf if unsuccessful */ - /* Treat it as a bad chunk */ - return(CHUNKE_BAD_CHUNK); - } + /* Convert to host encoding before calling Curl_client_write */ + result = Curl_convert_from_network(conn->data, + conn->trailer, + conn->trlPos); + if(result != CURLE_OK) { + /* Curl_convert_from_network calls failf if unsuccessful */ + /* Treat it as a bad chunk */ + return(CHUNKE_BAD_CHUNK); + } #endif /* CURL_DOES_CONVERSIONS */ Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); -- cgit v1.2.1 From 28b932fb4ef14b8b9ebda6823c98fbedad6be4b2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Feb 2007 21:13:47 +0000 Subject: - Shmulik Regev fixed so that the final CRLF of HTTP response headers are sent to the debug callback. - Shmulik Regev added CURLOPT_HTTP_CONTENT_DECODING and CURLOPT_HTTP_TRANSFER_DECODING that if set to zero will disable libcurl's internal decoding of content or transfer encoded content. This may be preferable in cases where you use libcurl for proxy purposes or similar. The command line tool got a --raw option to disable both at once. --- lib/http_chunks.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 1b03a5569..36bee789c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -116,6 +116,12 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, *wrote = 0; /* nothing's written yet */ + /* the original data is written to the client, but we go on with the + chunk read process, to properly calculate the content length*/ + if ( data->set.http_te_skip ) + Curl_client_write(conn, CLIENTWRITE_BODY, datap,datalen); + + while(length) { switch(ch->state) { case CHUNK_HEX: @@ -206,12 +212,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* Write the data portion available */ #ifdef HAVE_LIBZ - switch (data->reqdata.keep.content_encoding) { + switch (conn->data->set.http_ce_skip? + IDENTITY : data->reqdata.keep.content_encoding) { case IDENTITY: #endif - if(!k->ignorebody) - result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, - piece); + if(!k->ignorebody) { + if ( !data->set.http_te_skip ) + result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, + piece); + else + result = CURLE_OK; + } #ifdef HAVE_LIBZ break; @@ -334,6 +345,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return(CHUNKE_BAD_CHUNK); } #endif /* CURL_DOES_CONVERSIONS */ + if ( !data->set.http_te_skip ) Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); } -- cgit v1.2.1 From f19d333ef6b067809cb2b0c153fbd3f5db4321a1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 21 Feb 2007 21:59:40 +0000 Subject: - Ravi Pratap provided work on libcurl making pipelining more robust and fixing some bugs: o Don't mix GET and POST requests in a pipeline o Fix the order in which requests are dispatched from the pipeline o Fixed several curl bugs with pipelining when the server is returning chunked encoding: * Added states to chunked parsing for final CRLF * Rewind buffer after parsing chunk with data remaining * Moved chunked header initializing to a spot just before receiving headers --- lib/http_chunks.c | 72 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 15 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 36bee789c..4b416c136 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -181,19 +181,24 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(0 == ch->datasize) { if (conn->bits.trailerHdrPresent!=TRUE) { /* No Trailer: header found - revert to original Curl processing */ - ch->state = CHUNK_STOP; - if (1 == length) { - /* This is the final byte, return right now */ - return CHUNKE_STOP; - } + ch->state = CHUNK_STOPCR; + + /* We need to increment the datap here since we bypass the + increment below with the immediate break */ + length--; + datap++; + + /* This is the final byte, continue to read the final CRLF */ + break; } else { ch->state = CHUNK_TRAILER; /* attempt to read trailers */ conn->trlPos=0; } } - else + else { ch->state = CHUNK_DATA; + } } else /* previously we got a fake CR, go back to CR waiting! */ @@ -270,8 +275,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, datap++; length--; } - else + else { return CHUNKE_BAD_CHUNK; + } break; case CHUNK_POSTLF: @@ -284,8 +290,10 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, datap++; length--; } - else + else { return CHUNKE_BAD_CHUNK; + } + break; case CHUNK_TRAILER: @@ -331,7 +339,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, conn->trailer[conn->trlPos]=0; if (conn->trlPos==2) { ch->state = CHUNK_STOP; - return CHUNKE_STOP; + datap++; + length--; + + /* + * Note that this case skips over the final STOP states since we've + * already read the final CRLF and need to return + */ + + ch->dataleft = length; + + return CHUNKE_STOP; /* return stop */ } else { #ifdef CURL_DOES_CONVERSIONS @@ -346,8 +364,8 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } #endif /* CURL_DOES_CONVERSIONS */ if ( !data->set.http_te_skip ) - Curl_client_write(conn, CLIENTWRITE_HEADER, - conn->trailer, conn->trlPos); + Curl_client_write(conn, CLIENTWRITE_HEADER, + conn->trailer, conn->trlPos); } ch->state = CHUNK_TRAILER; conn->trlPos=0; @@ -358,11 +376,35 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_BAD_CHUNK; break; + case CHUNK_STOPCR: + /* Read the final CRLF that ends all chunk bodies */ + + if(*datap == 0x0d) { + ch->state = CHUNK_STOP; + datap++; + length--; + } + else { + return CHUNKE_BAD_CHUNK; + } + break; + case CHUNK_STOP: - /* If we arrive here, there is data left in the end of the buffer - even if there's no more chunks to read */ - ch->dataleft = length; - return CHUNKE_STOP; /* return stop */ + if (*datap == 0x0a) { + datap++; + length--; + + /* Record the length of any data left in the end of the buffer + even if there's no more chunks to read */ + + ch->dataleft = length; + return CHUNKE_STOP; /* return stop */ + } + else { + return CHUNKE_BAD_CHUNK; + } + break; + default: return CHUNKE_STATE_ERROR; } -- cgit v1.2.1 From 8e27ed2fdd63cba4c4be1d831675d0664ab0deaa Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 22 Feb 2007 06:22:19 +0000 Subject: Fix compiler warning "statement is unreachable" --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 4b416c136..cc89068f3 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -403,7 +403,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, else { return CHUNKE_BAD_CHUNK; } - break; + default: return CHUNKE_STATE_ERROR; -- cgit v1.2.1 From 5119fb16d63e91972924e54d455c825f62b1440d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 10 Jul 2007 22:45:01 +0000 Subject: Shmulik Regev: The tiny patch below fixes a bug (that I introduced :) which happens when negotiating authentication with a proxy (probably with web servers as well) that uses chunked transfer encoding for the 407 error pages. In this case the ''ignorebody'' flag was ignored (no pun intended). --- lib/http_chunks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index cc89068f3..8e44b6d05 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -118,10 +118,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* the original data is written to the client, but we go on with the chunk read process, to properly calculate the content length*/ - if ( data->set.http_te_skip ) + if (data->set.http_te_skip && !k->ignorebody) Curl_client_write(conn, CLIENTWRITE_BODY, datap,datalen); - while(length) { switch(ch->state) { case CHUNK_HEX: -- cgit v1.2.1 From 119364741ef2ca0931c0ceaa6f92cb476457863c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Oct 2007 10:21:36 +0000 Subject: known bug #46: chunked-encoded CONNECT responses from a http proxy now works. Added test case 1008 to verify. Note that #47 is still there. --- lib/http_chunks.c | 79 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 40 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 8e44b6d05..3ec89b9c2 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -84,7 +84,7 @@ void Curl_httpchunk_init(struct connectdata *conn) { - struct Curl_chunker *chunk = &conn->data->reqdata.proto.http->chunk; + struct Curl_chunker *chunk = &conn->chunk; chunk->hexindex=0; /* start at 0 */ chunk->dataleft=0; /* no data left yet! */ chunk->state = CHUNK_HEX; /* we get hex first! */ @@ -108,7 +108,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, { CURLcode result=CURLE_OK; struct SessionHandle *data = conn->data; - struct Curl_chunker *ch = &data->reqdata.proto.http->chunk; + struct Curl_chunker *ch = &conn->chunk; struct Curl_transfer_keeper *k = &data->reqdata.keep; size_t piece; size_t length = (size_t)datalen; @@ -124,11 +124,11 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, while(length) { switch(ch->state) { case CHUNK_HEX: - /* Check for an ASCII hex digit. - We avoid the use of isxdigit to accommodate non-ASCII hosts. */ - if((*datap >= 0x30 && *datap <= 0x39) /* 0-9 */ - || (*datap >= 0x41 && *datap <= 0x46) /* A-F */ - || (*datap >= 0x61 && *datap <= 0x66)) { /* a-f */ + /* Check for an ASCII hex digit. + We avoid the use of isxdigit to accommodate non-ASCII hosts. */ + if((*datap >= 0x30 && *datap <= 0x39) /* 0-9 */ + || (*datap >= 0x41 && *datap <= 0x46) /* A-F */ + || (*datap >= 0x61 && *datap <= 0x66)) { /* a-f */ if(ch->hexindex < MAXNUM_SIZE) { ch->hexbuffer[ch->hexindex] = *datap; datap++; @@ -218,39 +218,39 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, #ifdef HAVE_LIBZ switch (conn->data->set.http_ce_skip? IDENTITY : data->reqdata.keep.content_encoding) { - case IDENTITY: + case IDENTITY: #endif - if(!k->ignorebody) { - if ( !data->set.http_te_skip ) - result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, - piece); - else - result = CURLE_OK; - } + if(!k->ignorebody) { + if ( !data->set.http_te_skip ) + result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, + piece); + else + result = CURLE_OK; + } #ifdef HAVE_LIBZ - break; - - case DEFLATE: - /* update data->reqdata.keep.str to point to the chunk data. */ - data->reqdata.keep.str = datap; - result = Curl_unencode_deflate_write(conn, &data->reqdata.keep, - (ssize_t)piece); - break; - - case GZIP: - /* update data->reqdata.keep.str to point to the chunk data. */ - data->reqdata.keep.str = datap; - result = Curl_unencode_gzip_write(conn, &data->reqdata.keep, - (ssize_t)piece); - break; - - case COMPRESS: - default: - failf (conn->data, - "Unrecognized content encoding type. " - "libcurl understands `identity', `deflate' and `gzip' " - "content encodings."); - return CHUNKE_BAD_ENCODING; + break; + + case DEFLATE: + /* update data->reqdata.keep.str to point to the chunk data. */ + data->reqdata.keep.str = datap; + result = Curl_unencode_deflate_write(conn, &data->reqdata.keep, + (ssize_t)piece); + break; + + case GZIP: + /* update data->reqdata.keep.str to point to the chunk data. */ + data->reqdata.keep.str = datap; + result = Curl_unencode_gzip_write(conn, &data->reqdata.keep, + (ssize_t)piece); + break; + + case COMPRESS: + default: + failf (conn->data, + "Unrecognized content encoding type. " + "libcurl understands `identity', `deflate' and `gzip' " + "content encodings."); + return CHUNKE_BAD_ENCODING; } #endif @@ -319,7 +319,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, else { datap++; length--; - } + } break; case CHUNK_TRAILER_CR: @@ -403,7 +403,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_BAD_CHUNK; } - default: return CHUNKE_STATE_ERROR; } -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/http_chunks.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 3ec89b9c2..71b9b9791 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -118,7 +118,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* the original data is written to the client, but we go on with the chunk read process, to properly calculate the content length*/ - if (data->set.http_te_skip && !k->ignorebody) + if(data->set.http_te_skip && !k->ignorebody) Curl_client_write(conn, CLIENTWRITE_BODY, datap,datalen); while(length) { @@ -178,7 +178,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(*datap == 0x0a) { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { - if (conn->bits.trailerHdrPresent!=TRUE) { + if(conn->bits.trailerHdrPresent!=TRUE) { /* No Trailer: header found - revert to original Curl processing */ ch->state = CHUNK_STOPCR; @@ -221,7 +221,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case IDENTITY: #endif if(!k->ignorebody) { - if ( !data->set.http_te_skip ) + if( !data->set.http_te_skip ) result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, piece); else @@ -298,7 +298,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case CHUNK_TRAILER: /* conn->trailer is assumed to be freed in url.c on a connection basis */ - if (conn->trlPos >= conn->trlMax) { + if(conn->trlPos >= conn->trlMax) { char *ptr; if(conn->trlMax) { conn->trlMax *= 2; @@ -333,10 +333,10 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_TRAILER_POSTCR: - if (*datap == 0x0a) { + if(*datap == 0x0a) { conn->trailer[conn->trlPos++]=0x0a; conn->trailer[conn->trlPos]=0; - if (conn->trlPos==2) { + if(conn->trlPos==2) { ch->state = CHUNK_STOP; datap++; length--; @@ -362,7 +362,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return(CHUNKE_BAD_CHUNK); } #endif /* CURL_DOES_CONVERSIONS */ - if ( !data->set.http_te_skip ) + if( !data->set.http_te_skip ) Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); } @@ -389,7 +389,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case CHUNK_STOP: - if (*datap == 0x0a) { + if(*datap == 0x0a) { datap++; length--; -- cgit v1.2.1 From 50feea3eef87f1c07b954ad3020fdb836c7f279f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 15 Nov 2007 21:45:45 +0000 Subject: Rearranged code and changed Curl_readwrite_init() and Curl_pre_readwrite() into do_init() and do_complete() which now are called first and last in the DO function. It simplified the flow in multi.c and the functions got more sensible names! --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 71b9b9791..305a8a97a 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -178,7 +178,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(*datap == 0x0a) { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { - if(conn->bits.trailerHdrPresent!=TRUE) { + if(conn->bits.trailerhdrpresent!=TRUE) { /* No Trailer: header found - revert to original Curl processing */ ch->state = CHUNK_STOPCR; -- cgit v1.2.1 From 13648f8ccda6f99674ac407640474634e856804c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 24 Nov 2007 23:16:55 +0000 Subject: struct HandleData is now called struct SingleRequest, and is only for data that is inited at the start of the DO action. I removed the Curl_transfer_keeper struct completely, and I had to move out a few struct members (that had to be set before DO or used after DONE) to the UrlState struct. The SingleRequest struct is accessed with SessionHandle->req. One of the biggest reasons for doing this was the bunch of duplicate struct members in HandleData and Curl_transfer_keeper since it was really messy to keep track of two variables with the same name and basically the same purpose! --- lib/http_chunks.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 305a8a97a..2bf161560 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -109,7 +109,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, CURLcode result=CURLE_OK; struct SessionHandle *data = conn->data; struct Curl_chunker *ch = &conn->chunk; - struct Curl_transfer_keeper *k = &data->reqdata.keep; + struct SingleRequest *k = &data->req; size_t piece; size_t length = (size_t)datalen; size_t *wrote = (size_t *)wrotep; @@ -217,7 +217,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* Write the data portion available */ #ifdef HAVE_LIBZ switch (conn->data->set.http_ce_skip? - IDENTITY : data->reqdata.keep.content_encoding) { + IDENTITY : data->req.content_encoding) { case IDENTITY: #endif if(!k->ignorebody) { @@ -231,16 +231,16 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, break; case DEFLATE: - /* update data->reqdata.keep.str to point to the chunk data. */ - data->reqdata.keep.str = datap; - result = Curl_unencode_deflate_write(conn, &data->reqdata.keep, + /* update data->req.keep.str to point to the chunk data. */ + data->req.str = datap; + result = Curl_unencode_deflate_write(conn, &data->req, (ssize_t)piece); break; case GZIP: - /* update data->reqdata.keep.str to point to the chunk data. */ - data->reqdata.keep.str = datap; - result = Curl_unencode_gzip_write(conn, &data->reqdata.keep, + /* update data->req.keep.str to point to the chunk data. */ + data->req.str = datap; + result = Curl_unencode_gzip_write(conn, &data->req, (ssize_t)piece); break; -- cgit v1.2.1 From d9023c16abd0f6b89eb94bbad44d9723947f3c34 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 2 Jan 2008 22:30:34 +0000 Subject: - I fixed two cases of missing return code checks when handling chunked decoding where a write error (or abort return from a callback) didn't stop libcurl's processing. --- lib/http_chunks.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 2bf161560..d76586cb2 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -118,8 +118,11 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* the original data is written to the client, but we go on with the chunk read process, to properly calculate the content length*/ - if(data->set.http_te_skip && !k->ignorebody) - Curl_client_write(conn, CLIENTWRITE_BODY, datap,datalen); + if(data->set.http_te_skip && !k->ignorebody) { + result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, datalen); + if(result) + return CHUNKE_WRITE_ERROR; + } while(length) { switch(ch->state) { @@ -362,9 +365,12 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return(CHUNKE_BAD_CHUNK); } #endif /* CURL_DOES_CONVERSIONS */ - if( !data->set.http_te_skip ) - Curl_client_write(conn, CLIENTWRITE_HEADER, - conn->trailer, conn->trlPos); + if(!data->set.http_te_skip) { + result = Curl_client_write(conn, CLIENTWRITE_HEADER, + conn->trailer, conn->trlPos); + if(result) + return CHUNKE_WRITE_ERROR; + } } ch->state = CHUNK_TRAILER; conn->trlPos=0; -- cgit v1.2.1 From b620e62f0f4e90f4d1338117c67580a6f5f37377 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 Jan 2008 12:04:33 +0000 Subject: - Dmitry Kurochkin moved several struct fields from the connectdata struct to the SingleRequest one to make pipelining better. It is a bit tricky to keep them in the right place, to keep things related to the actual request or to the actual connection in the right place. --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index d76586cb2..ad9783404 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -181,7 +181,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(*datap == 0x0a) { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { - if(conn->bits.trailerhdrpresent!=TRUE) { + if(k->trailerhdrpresent!=TRUE) { /* No Trailer: header found - revert to original Curl processing */ ch->state = CHUNK_STOPCR; -- cgit v1.2.1 From 861b647e7b1da564b831a5b07312a30feb7b6c58 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 04:28:43 +0000 Subject: remove unnecessary typecasting of realloc() --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index ad9783404..45199866f 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -305,7 +305,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *ptr; if(conn->trlMax) { conn->trlMax *= 2; - ptr = (char*)realloc(conn->trailer,conn->trlMax); + ptr = realloc(conn->trailer,conn->trlMax); } else { conn->trlMax=128; -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 45199866f..0d72793ce 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -309,7 +309,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } else { conn->trlMax=128; - ptr = (char*)malloc(conn->trlMax); + ptr = malloc(conn->trlMax); } if(!ptr) return CHUNKE_OUT_OF_MEMORY; -- cgit v1.2.1 From 79fc481a2b2151421752ffd6dba01c30a0dc5302 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 7 Oct 2008 23:20:06 +0000 Subject: Split off Curl_isxdigit function --- lib/http_chunks.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 0d72793ce..e0887483a 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -81,6 +81,14 @@ */ +/* Check for an ASCII hex digit. + We avoid the use of isxdigit to accommodate non-ASCII hosts. */ +static bool Curl_isxdigit(char digit) +{ + return (digit >= 0x30 && digit <= 0x39) /* 0-9 */ + || (digit >= 0x41 && digit <= 0x46) /* A-F */ + || (digit >= 0x61 && digit <= 0x66); /* a-f */ +} void Curl_httpchunk_init(struct connectdata *conn) { @@ -127,11 +135,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, while(length) { switch(ch->state) { case CHUNK_HEX: - /* Check for an ASCII hex digit. - We avoid the use of isxdigit to accommodate non-ASCII hosts. */ - if((*datap >= 0x30 && *datap <= 0x39) /* 0-9 */ - || (*datap >= 0x41 && *datap <= 0x46) /* A-F */ - || (*datap >= 0x61 && *datap <= 0x66)) { /* a-f */ + if(Curl_isxdigit(*datap)) { if(ch->hexindex < MAXNUM_SIZE) { ch->hexbuffer[ch->hexindex] = *datap; datap++; -- cgit v1.2.1 From 6ea91af2f8f787f16b1bde88ae2293adcc961986 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 24 Oct 2008 01:27:00 +0000 Subject: fix compiler warning --- lib/http_chunks.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index e0887483a..630a5a265 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -85,9 +85,9 @@ We avoid the use of isxdigit to accommodate non-ASCII hosts. */ static bool Curl_isxdigit(char digit) { - return (digit >= 0x30 && digit <= 0x39) /* 0-9 */ - || (digit >= 0x41 && digit <= 0x46) /* A-F */ - || (digit >= 0x61 && digit <= 0x66); /* a-f */ + return (bool)( (digit >= 0x30 && digit <= 0x39) /* 0-9 */ + || (digit >= 0x41 && digit <= 0x46) /* A-F */ + || (digit >= 0x61 && digit <= 0x66) ); /* a-f */ } void Curl_httpchunk_init(struct connectdata *conn) -- cgit v1.2.1 From 33a3753c3f41d546ebf3350685eb7201d25783f4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/http_chunks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 630a5a265..13ef3cff6 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,7 +35,7 @@ #include "content_encoding.h" #include "http.h" -#include "memory.h" +#include "curl_memory.h" #include "easyif.h" /* for Curl_convert_to_network prototype */ #define _MPRINTF_REPLACE /* use our functions only */ -- cgit v1.2.1 From 352177090f710fd155d22a79d11f621482c09640 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 10 Jun 2009 21:26:11 +0000 Subject: - Fabian Keil ran clang on the (lib)curl code, found a bunch of warnings and contributed a range of patches to fix them. --- lib/http_chunks.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 13ef3cff6..ee35d6603 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -345,7 +345,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, conn->trailer[conn->trlPos]=0; if(conn->trlPos==2) { ch->state = CHUNK_STOP; - datap++; length--; /* @@ -400,7 +399,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case CHUNK_STOP: if(*datap == 0x0a) { - datap++; length--; /* Record the length of any data left in the end of the buffer -- cgit v1.2.1 From 03a57308b91911cdd91060b237715f0c5fe716da Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 26 Feb 2010 22:55:30 +0000 Subject: - Pat Ray in bug #2958474 pointed out an off-by-one case when receiving a chunked-encoding trailer. http://curl.haxx.se/bug/view.cgi?id=2958474 --- lib/http_chunks.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index ee35d6603..3649f9ee0 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -306,14 +306,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* conn->trailer is assumed to be freed in url.c on a connection basis */ if(conn->trlPos >= conn->trlMax) { + /* in this logic we always allocate one byte more than trlMax + contains, just because CHUNK_TRAILER_POSTCR will append two bytes + so we need to make sure we have room for an extra byte */ char *ptr; if(conn->trlMax) { conn->trlMax *= 2; - ptr = realloc(conn->trailer,conn->trlMax); + ptr = realloc(conn->trailer, conn->trlMax + 1); } else { conn->trlMax=128; - ptr = malloc(conn->trlMax); + ptr = malloc(conn->trlMax + 1); } if(!ptr) return CHUNKE_OUT_OF_MEMORY; -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/http_chunks.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 3649f9ee0..a66f87210 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 6b6a3bcb61f2d8f4e80a1e2a5bc62e78904256ed Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 25 Aug 2010 13:42:14 +0200 Subject: http: handle trailer headers in all chunked responses HTTP allows that a server sends trailing headers after all the chunks have been sent WITHOUT signalling their presence in the first response headers. The "Trailer:" header is only a SHOULD there and as we need to handle the situation even without that header I made libcurl ignore Trailer: completely. Test case 1116 was added to verify this and to make sure we handle more than one trailer header properly. Reported by: Patrick McManus Bug: http://curl.haxx.se/bug/view.cgi?id=3052450 --- lib/http_chunks.c | 151 ++++++++++++++++++++++++------------------------------ 1 file changed, 68 insertions(+), 83 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index a66f87210..0d41979af 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -184,22 +184,8 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(*datap == 0x0a) { /* we're now expecting data to come, unless size was zero! */ if(0 == ch->datasize) { - if(k->trailerhdrpresent!=TRUE) { - /* No Trailer: header found - revert to original Curl processing */ - ch->state = CHUNK_STOPCR; - - /* We need to increment the datap here since we bypass the - increment below with the immediate break */ - length--; - datap++; - - /* This is the final byte, continue to read the final CRLF */ - break; - } - else { - ch->state = CHUNK_TRAILER; /* attempt to read trailers */ - conn->trlPos=0; - } + ch->state = CHUNK_TRAILER; /* now check for trailers */ + conn->trlPos=0; } else { ch->state = CHUNK_DATA; @@ -280,9 +266,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, datap++; length--; } - else { + else return CHUNKE_BAD_CHUNK; - } + break; case CHUNK_POSTLF: @@ -295,80 +281,32 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, datap++; length--; } - else { + else return CHUNKE_BAD_CHUNK; - } break; case CHUNK_TRAILER: - /* conn->trailer is assumed to be freed in url.c on a - connection basis */ - if(conn->trlPos >= conn->trlMax) { - /* in this logic we always allocate one byte more than trlMax - contains, just because CHUNK_TRAILER_POSTCR will append two bytes - so we need to make sure we have room for an extra byte */ - char *ptr; - if(conn->trlMax) { - conn->trlMax *= 2; - ptr = realloc(conn->trailer, conn->trlMax + 1); - } - else { - conn->trlMax=128; - ptr = malloc(conn->trlMax + 1); - } - if(!ptr) - return CHUNKE_OUT_OF_MEMORY; - conn->trailer = ptr; - } - conn->trailer[conn->trlPos++]=*datap; - - if(*datap == 0x0d) - ch->state = CHUNK_TRAILER_CR; - else { - datap++; - length--; - } - break; - - case CHUNK_TRAILER_CR: if(*datap == 0x0d) { - ch->state = CHUNK_TRAILER_POSTCR; - datap++; - length--; - } - else - return CHUNKE_BAD_CHUNK; - break; - - case CHUNK_TRAILER_POSTCR: - if(*datap == 0x0a) { - conn->trailer[conn->trlPos++]=0x0a; - conn->trailer[conn->trlPos]=0; - if(conn->trlPos==2) { - ch->state = CHUNK_STOP; - length--; + /* this is the end of a trailer, but if the trailer was zero bytes + there was no trailer and we move on */ - /* - * Note that this case skips over the final STOP states since we've - * already read the final CRLF and need to return - */ + if(conn->trlPos) { + /* we allocate trailer with 3 bytes extra room to fit this */ + conn->trailer[conn->trlPos++]=0x0d; + conn->trailer[conn->trlPos++]=0x0a; + conn->trailer[conn->trlPos]=0; - ch->dataleft = length; - - return CHUNKE_STOP; /* return stop */ - } - else { #ifdef CURL_DOES_CONVERSIONS /* Convert to host encoding before calling Curl_client_write */ result = Curl_convert_from_network(conn->data, conn->trailer, conn->trlPos); - if(result != CURLE_OK) { + if(result != CURLE_OK) /* Curl_convert_from_network calls failf if unsuccessful */ /* Treat it as a bad chunk */ - return(CHUNKE_BAD_CHUNK); - } + return CHUNKE_BAD_CHUNK; + #endif /* CURL_DOES_CONVERSIONS */ if(!data->set.http_te_skip) { result = Curl_client_write(conn, CLIENTWRITE_HEADER, @@ -376,9 +314,44 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, if(result) return CHUNKE_WRITE_ERROR; } + conn->trlPos=0; + ch->state = CHUNK_TRAILER_CR; } - ch->state = CHUNK_TRAILER; - conn->trlPos=0; + else { + /* no trailer, we're on the final CRLF pair */ + ch->state = CHUNK_TRAILER_POSTCR; + break; /* don't advance the pointer */ + } + } + else { + /* conn->trailer is assumed to be freed in url.c on a + connection basis */ + if(conn->trlPos >= conn->trlMax) { + /* we always allocate three extra bytes, just because when the full + header has been received we append CRLF\0 */ + char *ptr; + if(conn->trlMax) { + conn->trlMax *= 2; + ptr = realloc(conn->trailer, conn->trlMax + 3); + } + else { + conn->trlMax=128; + ptr = malloc(conn->trlMax + 3); + } + if(!ptr) + return CHUNKE_OUT_OF_MEMORY; + conn->trailer = ptr; + } + fprintf(stderr, "MOO: %c\n", *datap); + conn->trailer[conn->trlPos++]=*datap; + } + datap++; + length--; + break; + + case CHUNK_TRAILER_CR: + if(*datap == 0x0a) { + ch->state = CHUNK_TRAILER_POSTCR; datap++; length--; } @@ -386,6 +359,20 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_BAD_CHUNK; break; + case CHUNK_TRAILER_POSTCR: + /* We enter this state when a CR should arrive so we expect to + have to first pass a CR before we wait for LF */ + if(*datap != 0x0d) { + /* not a CR then it must be another header in the trailer */ + ch->state = CHUNK_TRAILER; + break; + } + datap++; + length--; + /* now wait for the final LF */ + ch->state = CHUNK_STOP; + break; + case CHUNK_STOPCR: /* Read the final CRLF that ends all chunk bodies */ @@ -394,9 +381,8 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, datap++; length--; } - else { + else return CHUNKE_BAD_CHUNK; - } break; case CHUNK_STOP: @@ -409,9 +395,8 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, ch->dataleft = length; return CHUNKE_STOP; /* return stop */ } - else { + else return CHUNKE_BAD_CHUNK; - } default: return CHUNKE_STATE_ERROR; -- cgit v1.2.1 From 09a2d93a0f17ca9c068110a378496e3f4212abfd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 17 Oct 2010 18:50:38 +0200 Subject: http_chunks: remove debug output Accidentally left in there during my previous debugging of this --- lib/http_chunks.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 0d41979af..56d8248ff 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -342,7 +342,6 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, return CHUNKE_OUT_OF_MEMORY; conn->trailer = ptr; } - fprintf(stderr, "MOO: %c\n", *datap); conn->trailer[conn->trlPos++]=*datap; } datap++; -- cgit v1.2.1 From 2db6f7e703bda76872a0e05f2d5fe6c5a7ddaf74 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 8 Apr 2011 22:50:40 +0200 Subject: TE: rename struct field content_encoding Since this struct member is used in the code to determine what and how to decode automatically and since it is now also used for compressed Transfer-Encodings, I renamed it to the more suitable 'auto_decoding' --- lib/http_chunks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 56d8248ff..e955b945e 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -209,7 +209,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, /* Write the data portion available */ #ifdef HAVE_LIBZ switch (conn->data->set.http_ce_skip? - IDENTITY : data->req.content_encoding) { + IDENTITY : data->req.auto_decoding) { case IDENTITY: #endif if(!k->ignorebody) { -- cgit v1.2.1 From c828646f60b5bffb2bfcf924eba36da767bf08bf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Apr 2011 00:48:20 +0200 Subject: CURL_DOES_CONVERSIONS: cleanup Massively reduce #ifdefs all over (23 #ifdef lines less so far) Moved conversion-specific code to non-ascii.c --- lib/http_chunks.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index e955b945e..821a861f4 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -35,7 +35,7 @@ #include "content_encoding.h" #include "http.h" #include "curl_memory.h" -#include "easyif.h" /* for Curl_convert_to_network prototype */ +#include "non-ascii.h" /* for Curl_convert_to_network prototype */ #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -153,17 +153,16 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, } /* length and datap are unmodified */ ch->hexbuffer[ch->hexindex]=0; -#ifdef CURL_DOES_CONVERSIONS + /* convert to host encoding before calling strtoul */ - result = Curl_convert_from_network(conn->data, - ch->hexbuffer, + result = Curl_convert_from_network(conn->data, ch->hexbuffer, ch->hexindex); - if(result != CURLE_OK) { + if(result) { /* Curl_convert_from_network calls failf if unsuccessful */ /* Treat it as a bad hex character */ return(CHUNKE_ILLEGAL_HEX); } -#endif /* CURL_DOES_CONVERSIONS */ + ch->datasize=strtoul(ch->hexbuffer, NULL, 16); ch->state = CHUNK_POSTHEX; } @@ -297,17 +296,14 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, conn->trailer[conn->trlPos++]=0x0a; conn->trailer[conn->trlPos]=0; -#ifdef CURL_DOES_CONVERSIONS /* Convert to host encoding before calling Curl_client_write */ - result = Curl_convert_from_network(conn->data, - conn->trailer, + result = Curl_convert_from_network(conn->data, conn->trailer, conn->trlPos); - if(result != CURLE_OK) + if(result) /* Curl_convert_from_network calls failf if unsuccessful */ /* Treat it as a bad chunk */ return CHUNKE_BAD_CHUNK; -#endif /* CURL_DOES_CONVERSIONS */ if(!data->set.http_te_skip) { result = Curl_client_write(conn, CLIENTWRITE_HEADER, conn->trailer, conn->trlPos); -- cgit v1.2.1 From 889d1e973fb718a77c5000141d724ce03863af23 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 22 Apr 2011 23:01:30 +0200 Subject: whitespace cleanup: no space first in conditionals "if(a)" is our style, not "if( a )" --- lib/http_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 821a861f4..93de1d968 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -212,7 +212,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn, case IDENTITY: #endif if(!k->ignorebody) { - if( !data->set.http_te_skip ) + if(!data->set.http_te_skip) result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, piece); else -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/http_chunks.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 93de1d968..d7a5cb48c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -19,15 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ + #include "setup.h" #ifndef CURL_DISABLE_HTTP -/* -- WIN32 approved -- */ -#include -#include -#include -#include -#include #include "urldata.h" /* it includes http_chunks.h */ #include "sendf.h" /* for the client write stuff */ -- cgit v1.2.1 From a50210710ab6fd772e2762ed36602c15adfb49e1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 5 Sep 2011 20:46:09 +0200 Subject: fix bool variables checking and assignment --- lib/http_chunks.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/http_chunks.c') diff --git a/lib/http_chunks.c b/lib/http_chunks.c index d7a5cb48c..d6a0bec13 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -79,9 +79,9 @@ We avoid the use of isxdigit to accommodate non-ASCII hosts. */ static bool Curl_isxdigit(char digit) { - return (bool)( (digit >= 0x30 && digit <= 0x39) /* 0-9 */ - || (digit >= 0x41 && digit <= 0x46) /* A-F */ - || (digit >= 0x61 && digit <= 0x66) ); /* a-f */ + return ( (digit >= 0x30 && digit <= 0x39) /* 0-9 */ + || (digit >= 0x41 && digit <= 0x46) /* A-F */ + || (digit >= 0x61 && digit <= 0x66) /* a-f */ ) ? TRUE : FALSE; } void Curl_httpchunk_init(struct connectdata *conn) -- cgit v1.2.1