diff options
Diffstat (limited to 'plugins/picohttpparser/picohttpparser.h')
-rw-r--r-- | plugins/picohttpparser/picohttpparser.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/plugins/picohttpparser/picohttpparser.h b/plugins/picohttpparser/picohttpparser.h new file mode 100644 index 0000000..a8fad71 --- /dev/null +++ b/plugins/picohttpparser/picohttpparser.h | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, | ||
3 | * Shigeo Mitsunari | ||
4 | * | ||
5 | * The software is licensed under either the MIT License (below) or the Perl | ||
6 | * license. | ||
7 | * | ||
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
9 | * of this software and associated documentation files (the "Software"), to | ||
10 | * deal in the Software without restriction, including without limitation the | ||
11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
12 | * sell copies of the Software, and to permit persons to whom the Software is | ||
13 | * furnished to do so, subject to the following conditions: | ||
14 | * | ||
15 | * The above copyright notice and this permission notice shall be included in | ||
16 | * all copies or substantial portions of the Software. | ||
17 | * | ||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
24 | * IN THE SOFTWARE. | ||
25 | */ | ||
26 | |||
27 | #ifndef picohttpparser_h | ||
28 | #define picohttpparser_h | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | |||
32 | #ifdef _MSC_VER | ||
33 | #define ssize_t intptr_t | ||
34 | #endif | ||
35 | |||
36 | /* $Id: 67fd3ee74103ada60258d8a16e868f483abcca87 $ */ | ||
37 | |||
38 | #ifdef __cplusplus | ||
39 | extern "C" { | ||
40 | #endif | ||
41 | |||
42 | /* contains name and value of a header (name == NULL if is a continuing line | ||
43 | * of a multiline header */ | ||
44 | struct phr_header { | ||
45 | const char *name; | ||
46 | size_t name_len; | ||
47 | const char *value; | ||
48 | size_t value_len; | ||
49 | }; | ||
50 | |||
51 | /* returns number of bytes consumed if successful, -2 if request is partial, | ||
52 | * -1 if failed */ | ||
53 | int phr_parse_request(const char *buf, size_t len, const char **method, size_t *method_len, const char **path, size_t *path_len, | ||
54 | int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
55 | |||
56 | /* ditto */ | ||
57 | int phr_parse_response(const char *_buf, size_t len, int *minor_version, int *status, const char **msg, size_t *msg_len, | ||
58 | struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
59 | |||
60 | /* ditto */ | ||
61 | int phr_parse_headers(const char *buf, size_t len, struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
62 | |||
63 | /* should be zero-filled before start */ | ||
64 | struct phr_chunked_decoder { | ||
65 | size_t bytes_left_in_chunk; /* number of bytes left in current chunk */ | ||
66 | char consume_trailer; /* if trailing headers should be consumed */ | ||
67 | char _hex_count; | ||
68 | char _state; | ||
69 | }; | ||
70 | |||
71 | /* the function rewrites the buffer given as (buf, bufsz) removing the chunked- | ||
72 | * encoding headers. When the function returns without an error, bufsz is | ||
73 | * updated to the length of the decoded data available. Applications should | ||
74 | * repeatedly call the function while it returns -2 (incomplete) every time | ||
75 | * supplying newly arrived data. If the end of the chunked-encoded data is | ||
76 | * found, the function returns a non-negative number indicating the number of | ||
77 | * octets left undecoded at the tail of the supplied buffer. Returns -1 on | ||
78 | * error. | ||
79 | */ | ||
80 | ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_t *bufsz); | ||
81 | |||
82 | /* returns if the chunked decoder is in middle of chunked data */ | ||
83 | int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder); | ||
84 | |||
85 | #ifdef __cplusplus | ||
86 | } | ||
87 | #endif | ||
88 | |||
89 | #endif | ||