picohttpparser_sys/lib.rs
1extern crate libc;
2
3use libc::{c_char, c_int, size_t, ssize_t};
4use std::ptr;
5
6// /* contains name and value of a header (name == NULL if is a continuing line
7// * of a multiline header */
8// struct phr_header {
9// const char *name;
10// size_t name_len;
11// const char *value;
12// size_t value_len;
13// };
14#[repr(C)]
15#[derive(Clone, Copy, Debug)]
16pub struct phr_header {
17 pub name: *const c_char,
18 pub name_len: size_t,
19 pub value: *const c_char,
20 pub value_len: size_t,
21}
22
23impl Default for phr_header {
24 fn default() -> phr_header {
25 phr_header {
26 name: ptr::null(),
27 name_len: 0,
28 value: ptr::null(),
29 value_len: 0,
30 }
31 }
32}
33
34// /* should be zero-filled before start */
35// struct phr_chunked_decoder {
36// size_t bytes_left_in_chunk; /* number of bytes left in current chunk */
37// char consume_trailer; /* if trailing headers should be consumed */
38// char _hex_count;
39// char _state;
40// };
41#[repr(C)]
42#[derive(Clone, Copy, Debug)]
43pub struct phr_chunked_decoder {
44 pub bytes_left_in_chunk: size_t, // number of bytes left in current chunk
45 pub consume_trailer: c_char, // if trailing headers should be consumed
46 _hex_count: c_char,
47 _state: c_char,
48}
49
50#[link(name = "picohttpparser", kind = "static")]
51extern "C" {
52 // returns number of bytes consumed if successful, -2 if request is partial,-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 pub fn phr_parse_request(buf: *const c_char,
56 len: size_t,
57 method: *mut *const c_char,
58 method_len: *mut size_t,
59 path: *mut *const c_char,
60 path_len: *mut size_t,
61 minor_version: *mut c_int,
62 headers: *mut phr_header,
63 num_headers: *mut size_t,
64 last_len: size_t)
65 -> c_int;
66
67 // returns number of bytes consumed if successful, -2 if request is partial,-1 if failed
68 // int phr_parse_response(const char *_buf, size_t len, int *minor_version, int *status, const char **msg, size_t *msg_len,
69 // struct phr_header *headers, size_t *num_headers, size_t last_len);
70 pub fn phr_parse_response(buf: *const c_char,
71 len: size_t,
72 minor_version: *mut c_int,
73 status: *mut c_int,
74 msg: *mut *const c_char,
75 msg_len: *mut size_t,
76 headers: *mut phr_header,
77 num_headers: *mut size_t,
78 last_len: size_t)
79 -> c_int;
80
81 // returns number of bytes consumed if successful, -2 if request is partial,-1 if failed
82 // int phr_parse_headers(const char *buf, size_t len, struct phr_header *headers, size_t
83 // *num_headers, size_t last_len);
84 pub fn phr_parse_headers(buf: *const c_char,
85 len: size_t,
86 headers: *mut phr_header,
87 num_headers: *mut size_t,
88 last_len: size_t)
89 -> c_int;
90
91 // /* the function rewrites the buffer given as (buf, bufsz) removing the chunked-
92 // * encoding headers. When the function returns without an error, bufsz is
93 // * updated to the length of the decoded data available. Applications should
94 // * repeatedly call the function while it returns -2 (incomplete) every time
95 // * supplying newly arrived data. If the end of the chunked-encoded data is
96 // * found, the function returns a non-negative number indicating the number of
97 // * octets left undecoded at the tail of the supplied buffer. Returns -1 on
98 // * error.
99 // */
100 // ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_t *bufsz);
101 pub fn phr_decode_chunked(decoder: *mut phr_chunked_decoder,
102 buf: *mut c_char,
103 bufsz: *mut size_t)
104 -> ssize_t;
105
106 // /* returns if the chunked decoder is in middle of chunked data */
107 // int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder);
108 pub fn phr_decode_chunked_is_in_data(decoder: *mut phr_chunked_decoder) -> c_int;
109}