Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 108 lines (90 sloc) 3.63 kb
55b8cea @bagder chunked transfer encoding support
authored
1 #ifndef __HTTP_CHUNKS_H
2 #define __HTTP_CHUNKS_H
ba4e69b @bagder updated source code boilerplate/header
authored
3 /***************************************************************************
ccb7950 @bagder killed trailing whitespace
authored
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
55b8cea @bagder chunked transfer encoding support
authored
8 * \___|\___/|_| \_\_____|
9 *
f19d333 @bagder - Ravi Pratap provided work on libcurl making pipelining more robust and
authored
10 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
55b8cea @bagder chunked transfer encoding support
authored
11 *
ba4e69b @bagder updated source code boilerplate/header
authored
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at http://curl.haxx.se/docs/copyright.html.
ccb7950 @bagder killed trailing whitespace
authored
15 *
55b8cea @bagder chunked transfer encoding support
authored
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
ba4e69b @bagder updated source code boilerplate/header
authored
18 * furnished to do so, under the terms of the COPYING file.
55b8cea @bagder chunked transfer encoding support
authored
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
ba4e69b @bagder updated source code boilerplate/header
authored
23 ***************************************************************************/
55b8cea @bagder chunked transfer encoding support
authored
24 /*
25 * The longest possible hexadecimal number we support in a chunked transfer.
563ad21 @bagder added an error code for illegal hex values in the chunked stream
authored
26 * Weird enough, RFC2616 doesn't set a maximum size! Since we use strtoul()
55b8cea @bagder chunked transfer encoding support
authored
27 * to convert it, we "only" support 2^32 bytes chunk data.
28 */
29 #define MAXNUM_SIZE 16
30
31 typedef enum {
195233e @bagder updated the chunked state-machine to deal with the trailing CRLF that…
authored
32 CHUNK_FIRST, /* never use */
55b8cea @bagder chunked transfer encoding support
authored
33
34 /* In this we await and buffer all hexadecimal digits until we get one
35 that isn't a hexadecimal digit. When done, we go POSTHEX */
36 CHUNK_HEX,
37
38 /* We have received the hexadecimal digit and we eat all characters until
39 we get a CRLF pair. When we see a CR we go to the CR state. */
40 CHUNK_POSTHEX,
41
42 /* A single CR has been found and we should get a LF right away in this
43 state or we go back to POSTHEX. When LF is received, we go to DATA.
44 If the size given was zero, we set state to STOP and return. */
45 CHUNK_CR,
46
195233e @bagder updated the chunked state-machine to deal with the trailing CRLF that…
authored
47 /* We eat the amount of data specified. When done, we move on to the
48 POST_CR state. */
55b8cea @bagder chunked transfer encoding support
authored
49 CHUNK_DATA,
50
195233e @bagder updated the chunked state-machine to deal with the trailing CRLF that…
authored
51 /* POSTCR should get a CR and nothing else, then move to POSTLF */
52 CHUNK_POSTCR,
53
465e19d @bagder Adrian Schuur added trailer support in the chunked encoding stream. The
authored
54 /* POSTLF should get a LF and nothing else, then move back to HEX as the
55 CRLF combination marks the end of a chunk */
195233e @bagder updated the chunked state-machine to deal with the trailing CRLF that…
authored
56 CHUNK_POSTLF,
57
f19d333 @bagder - Ravi Pratap provided work on libcurl making pipelining more robust and
authored
58 /* Each Chunk body should end with a CRLF. Read a CR and nothing else,
59 then move to CHUNK_STOP */
60 CHUNK_STOPCR,
61
a23db7b @bagder "Transfer-Encoding: chunked" support added
authored
62 /* This is mainly used to really mark that we're out of the game.
63 NOTE: that there's a 'dataleft' field in the struct that will tell how
64 many bytes that were not passed to the client in the end of the last
65 buffer! */
55b8cea @bagder chunked transfer encoding support
authored
66 CHUNK_STOP,
67
465e19d @bagder Adrian Schuur added trailer support in the chunked encoding stream. The
authored
68 /* At this point optional trailer headers can be found, unless the next line
69 is CRLF */
70 CHUNK_TRAILER,
71
72 /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR.
73 Next char must be a LF */
74 CHUNK_TRAILER_CR,
75
76 /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be
77 signalled If this is an empty trailer CHUNKE_STOP will be signalled.
78 Otherwise the trailer will be broadcasted via Curl_client_write() and the
79 next state will be CHUNK_TRAILER */
80 CHUNK_TRAILER_POSTCR,
81
55b8cea @bagder chunked transfer encoding support
authored
82 CHUNK_LAST /* never use */
465e19d @bagder Adrian Schuur added trailer support in the chunked encoding stream. The
authored
83
55b8cea @bagder chunked transfer encoding support
authored
84 } ChunkyState;
85
86 typedef enum {
a23db7b @bagder "Transfer-Encoding: chunked" support added
authored
87 CHUNKE_STOP = -1,
88 CHUNKE_OK = 0,
89 CHUNKE_TOO_LONG_HEX = 1,
563ad21 @bagder added an error code for illegal hex values in the chunked stream
authored
90 CHUNKE_ILLEGAL_HEX,
195233e @bagder updated the chunked state-machine to deal with the trailing CRLF that…
authored
91 CHUNKE_BAD_CHUNK,
55b8cea @bagder chunked transfer encoding support
authored
92 CHUNKE_WRITE_ERROR,
93 CHUNKE_STATE_ERROR,
64bbe9d @bagder James Gallagher's Content-Encoding work
authored
94 CHUNKE_BAD_ENCODING,
465e19d @bagder Adrian Schuur added trailer support in the chunked encoding stream. The
authored
95 CHUNKE_OUT_OF_MEMORY,
55b8cea @bagder chunked transfer encoding support
authored
96 CHUNKE_LAST
97 } CHUNKcode;
98
99 struct Curl_chunker {
100 char hexbuffer[ MAXNUM_SIZE + 1];
101 int hexindex;
102 ChunkyState state;
1eb9fd6 @bagder use size_t for the data, but keep the protos use ssize_t to better fit
authored
103 size_t datasize;
104 size_t dataleft; /* untouched data amount at the end of the last buffer */
55b8cea @bagder chunked transfer encoding support
authored
105 };
106
107 #endif
Something went wrong with that request. Please try again.