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.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/http_chunks.h (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h new file mode 100644 index 000000000..5869b9173 --- /dev/null +++ b/lib/http_chunks.h @@ -0,0 +1,73 @@ +#ifndef __HTTP_CHUNKS_H +#define __HTTP_CHUNKS_H +/***************************************************************************** + * _ _ ____ _ + * 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$ + *****************************************************************************/ +/* + * The longest possible hexadecimal number we support in a chunked transfer. + * Weird enoug, RFC2616 doesn't set a maximum size! Since we use strtoul() + * to convert it, we "only" support 2^32 bytes chunk data. + */ +#define MAXNUM_SIZE 16 + +typedef enum { + CHUNK_LOST, /* never use */ + + /* In this we await and buffer all hexadecimal digits until we get one + that isn't a hexadecimal digit. When done, we go POSTHEX */ + CHUNK_HEX, + + /* We have received the hexadecimal digit and we eat all characters until + we get a CRLF pair. When we see a CR we go to the CR state. */ + CHUNK_POSTHEX, + + /* A single CR has been found and we should get a LF right away in this + state or we go back to POSTHEX. When LF is received, we go to DATA. + If the size given was zero, we set state to STOP and return. */ + CHUNK_CR, + + /* We eat the amount of data specified. When done, we move back to the + HEX state. */ + CHUNK_DATA, + + /* This is only used to really mark that we're out of the game */ + CHUNK_STOP, + + CHUNK_LAST /* never use */ +} ChunkyState; + +typedef enum { + CHUNKE_OK, + CHUNKE_TOO_LONG_HEX, + CHUNKE_WRITE_ERROR, + CHUNKE_STATE_ERROR, + CHUNKE_LAST +} CHUNKcode; + +struct Curl_chunker { + char hexbuffer[ MAXNUM_SIZE + 1]; + int hexindex; + ChunkyState state; + unsigned long datasize; +}; + +#endif -- 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.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 5869b9173..6f7716e43 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -49,15 +49,19 @@ typedef enum { HEX state. */ CHUNK_DATA, - /* This is only used to really mark that we're out of the game */ + /* This is mainly used to really mark that we're out of the game. + NOTE: that there's a 'dataleft' field in the struct that will tell how + many bytes that were not passed to the client in the end of the last + buffer! */ CHUNK_STOP, CHUNK_LAST /* never use */ } ChunkyState; typedef enum { - CHUNKE_OK, - CHUNKE_TOO_LONG_HEX, + CHUNKE_STOP = -1, + CHUNKE_OK = 0, + CHUNKE_TOO_LONG_HEX = 1, CHUNKE_WRITE_ERROR, CHUNKE_STATE_ERROR, CHUNKE_LAST @@ -67,7 +71,8 @@ struct Curl_chunker { char hexbuffer[ MAXNUM_SIZE + 1]; int hexindex; ChunkyState state; - unsigned long datasize; + size_t datasize; + size_t dataleft; /* untouched data amount at the end of the last buffer */ }; #endif -- cgit v1.2.1 From 563ad213dc6854eb5a57f390a8e1bbbecc4088e3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Mar 2001 15:20:02 +0000 Subject: added an error code for illegal hex values in the chunked stream --- lib/http_chunks.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 6f7716e43..2b7c61692 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -24,7 +24,7 @@ *****************************************************************************/ /* * The longest possible hexadecimal number we support in a chunked transfer. - * Weird enoug, RFC2616 doesn't set a maximum size! Since we use strtoul() + * Weird enough, RFC2616 doesn't set a maximum size! Since we use strtoul() * to convert it, we "only" support 2^32 bytes chunk data. */ #define MAXNUM_SIZE 16 @@ -62,6 +62,7 @@ typedef enum { CHUNKE_STOP = -1, CHUNKE_OK = 0, CHUNKE_TOO_LONG_HEX = 1, + CHUNKE_ILLEGAL_HEX, CHUNKE_WRITE_ERROR, CHUNKE_STATE_ERROR, CHUNKE_LAST -- 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.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 2b7c61692..c3e54a30b 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -30,7 +30,7 @@ #define MAXNUM_SIZE 16 typedef enum { - CHUNK_LOST, /* never use */ + CHUNK_FIRST, /* never use */ /* In this we await and buffer all hexadecimal digits until we get one that isn't a hexadecimal digit. When done, we go POSTHEX */ @@ -45,10 +45,17 @@ typedef enum { If the size given was zero, we set state to STOP and return. */ CHUNK_CR, - /* We eat the amount of data specified. When done, we move back to the - HEX state. */ + /* We eat the amount of data specified. When done, we move on to the + POST_CR state. */ CHUNK_DATA, + /* POSTCR should get a CR and nothing else, then move to POSTLF */ + CHUNK_POSTCR, + + /* POSTLF should get a LF and nothing else, then move back to HEX as + the CRLF combination marks the end of a chunk */ + CHUNK_POSTLF, + /* This is mainly used to really mark that we're out of the game. NOTE: that there's a 'dataleft' field in the struct that will tell how many bytes that were not passed to the client in the end of the last @@ -63,6 +70,7 @@ typedef enum { CHUNKE_OK = 0, CHUNKE_TOO_LONG_HEX = 1, CHUNKE_ILLEGAL_HEX, + CHUNKE_BAD_CHUNK, CHUNKE_WRITE_ERROR, CHUNKE_STATE_ERROR, CHUNKE_LAST -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index c3e54a30b..48bdbd37b 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -7,7 +7,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 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.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 48bdbd37b..482612d25 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -73,6 +73,7 @@ typedef enum { CHUNKE_BAD_CHUNK, CHUNKE_WRITE_ERROR, CHUNKE_STATE_ERROR, + CHUNKE_BAD_ENCODING, CHUNKE_LAST } CHUNKcode; -- 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.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 482612d25..1b15d6c45 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -1,6 +1,6 @@ #ifndef __HTTP_CHUNKS_H #define __HTTP_CHUNKS_H -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -9,19 +9,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$ - *****************************************************************************/ + ***************************************************************************/ /* * The longest possible hexadecimal number we support in a chunked transfer. * Weird enough, RFC2616 doesn't set a maximum size! Since we use strtoul() -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 1b15d6c45..00a348328 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -7,7 +7,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 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 00a348328..26b79de4e 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -7,7 +7,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.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 26b79de4e..58a3f12a8 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -81,8 +81,8 @@ struct Curl_chunker { char hexbuffer[ MAXNUM_SIZE + 1]; int hexindex; ChunkyState state; - size_t datasize; - size_t dataleft; /* untouched data amount at the end of the last buffer */ + ssize_t datasize; + ssize_t dataleft; /* untouched data amount at the end of the last buffer */ }; #endif -- 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.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 58a3f12a8..26b79de4e 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -81,8 +81,8 @@ struct Curl_chunker { char hexbuffer[ MAXNUM_SIZE + 1]; int hexindex; ChunkyState state; - ssize_t datasize; - ssize_t dataleft; /* untouched data amount at the end of the last buffer */ + size_t datasize; + size_t dataleft; /* untouched data amount at the end of the last buffer */ }; #endif -- cgit v1.2.1 From ccb7950c4ccb9641200994689661a75b4e11a457 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 4 Mar 2005 00:24:52 +0000 Subject: killed trailing whitespace --- lib/http_chunks.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 26b79de4e..a2564078b 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -1,10 +1,10 @@ #ifndef __HTTP_CHUNKS_H #define __HTTP_CHUNKS_H /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -12,7 +12,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. -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index a2564078b..c5b7fdf43 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -7,7 +7,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.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index c5b7fdf43..211818ab7 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -52,8 +52,8 @@ typedef enum { /* POSTCR should get a CR and nothing else, then move to POSTLF */ CHUNK_POSTCR, - /* POSTLF should get a LF and nothing else, then move back to HEX as - the CRLF combination marks the end of a chunk */ + /* POSTLF should get a LF and nothing else, then move back to HEX as the + CRLF combination marks the end of a chunk */ CHUNK_POSTLF, /* This is mainly used to really mark that we're out of the game. @@ -62,7 +62,22 @@ typedef enum { buffer! */ CHUNK_STOP, + /* At this point optional trailer headers can be found, unless the next line + is CRLF */ + CHUNK_TRAILER, + + /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR. + Next char must be a LF */ + CHUNK_TRAILER_CR, + + /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be + signalled If this is an empty trailer CHUNKE_STOP will be signalled. + Otherwise the trailer will be broadcasted via Curl_client_write() and the + next state will be CHUNK_TRAILER */ + CHUNK_TRAILER_POSTCR, + CHUNK_LAST /* never use */ + } ChunkyState; typedef enum { @@ -74,6 +89,7 @@ typedef enum { CHUNKE_WRITE_ERROR, CHUNKE_STATE_ERROR, CHUNKE_BAD_ENCODING, + CHUNKE_OUT_OF_MEMORY, CHUNKE_LAST } CHUNKcode; -- 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.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index 211818ab7..c478799c1 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, 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 @@ -56,6 +56,10 @@ typedef enum { CRLF combination marks the end of a chunk */ CHUNK_POSTLF, + /* Each Chunk body should end with a CRLF. Read a CR and nothing else, + then move to CHUNK_STOP */ + CHUNK_STOPCR, + /* This is mainly used to really mark that we're out of the game. NOTE: that there's a 'dataleft' field in the struct that will tell how many bytes that were not passed to the client in the end of the last -- 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.h | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/http_chunks.h') diff --git a/lib/http_chunks.h b/lib/http_chunks.h index c478799c1..6056e188c 100644 --- a/lib/http_chunks.h +++ b/lib/http_chunks.h @@ -20,7 +20,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ /* * The longest possible hexadecimal number we support in a chunked transfer. -- cgit v1.2.1