Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / lib / http_chunks.h
blob809f8f2c6b6170e4bd98a1b7c5025edf9aded1ac
1 #ifndef __HTTP_CHUNKS_H
2 #define __HTTP_CHUNKS_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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
18 * furnished to do so, under the terms of the COPYING file.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 * $Id: http_chunks.h,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
24 ***************************************************************************/
26 * The longest possible hexadecimal number we support in a chunked transfer.
27 * Weird enough, RFC2616 doesn't set a maximum size! Since we use strtoul()
28 * to convert it, we "only" support 2^32 bytes chunk data.
30 #define MAXNUM_SIZE 16
32 typedef enum {
33 CHUNK_FIRST, /* never use */
35 /* In this we await and buffer all hexadecimal digits until we get one
36 that isn't a hexadecimal digit. When done, we go POSTHEX */
37 CHUNK_HEX,
39 /* We have received the hexadecimal digit and we eat all characters until
40 we get a CRLF pair. When we see a CR we go to the CR state. */
41 CHUNK_POSTHEX,
43 /* A single CR has been found and we should get a LF right away in this
44 state or we go back to POSTHEX. When LF is received, we go to DATA.
45 If the size given was zero, we set state to STOP and return. */
46 CHUNK_CR,
48 /* We eat the amount of data specified. When done, we move on to the
49 POST_CR state. */
50 CHUNK_DATA,
52 /* POSTCR should get a CR and nothing else, then move to POSTLF */
53 CHUNK_POSTCR,
55 /* POSTLF should get a LF and nothing else, then move back to HEX as the
56 CRLF combination marks the end of a chunk */
57 CHUNK_POSTLF,
59 /* Each Chunk body should end with a CRLF. Read a CR and nothing else,
60 then move to CHUNK_STOP */
61 CHUNK_STOPCR,
63 /* This is mainly used to really mark that we're out of the game.
64 NOTE: that there's a 'dataleft' field in the struct that will tell how
65 many bytes that were not passed to the client in the end of the last
66 buffer! */
67 CHUNK_STOP,
69 /* At this point optional trailer headers can be found, unless the next line
70 is CRLF */
71 CHUNK_TRAILER,
73 /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR.
74 Next char must be a LF */
75 CHUNK_TRAILER_CR,
77 /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be
78 signalled If this is an empty trailer CHUNKE_STOP will be signalled.
79 Otherwise the trailer will be broadcasted via Curl_client_write() and the
80 next state will be CHUNK_TRAILER */
81 CHUNK_TRAILER_POSTCR,
83 CHUNK_LAST /* never use */
85 } ChunkyState;
87 typedef enum {
88 CHUNKE_STOP = -1,
89 CHUNKE_OK = 0,
90 CHUNKE_TOO_LONG_HEX = 1,
91 CHUNKE_ILLEGAL_HEX,
92 CHUNKE_BAD_CHUNK,
93 CHUNKE_WRITE_ERROR,
94 CHUNKE_STATE_ERROR,
95 CHUNKE_BAD_ENCODING,
96 CHUNKE_OUT_OF_MEMORY,
97 CHUNKE_LAST
98 } CHUNKcode;
100 struct Curl_chunker {
101 char hexbuffer[ MAXNUM_SIZE + 1];
102 int hexindex;
103 ChunkyState state;
104 size_t datasize;
105 size_t dataleft; /* untouched data amount at the end of the last buffer */
108 #endif