1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![cfg_attr(test, deny(warnings))]
#![deny(missing_docs)]

//! # pico-sys
//!
//! Bindings to the PicoHTTPParser.
//!

extern crate libc;

/// Contains the ffi bindings to pico http parser.
pub mod ffi {
    use libc::{c_char, c_int, size_t, ssize_t};

    /// A header, pointing into an existing buffer.
    #[repr(C)]
    pub struct phr_header {
        name: *const c_char,
        name_len: size_t,
        value: *const c_char,
        value_len: size_t
    }

    /// A decoder for decoding chunked encoded data.
    #[repr(C)]
    pub struct phr_chunked_decoder {
        bytes_left_in_chunk: size_t,
        consume_trailer: c_char,
        hex_count: c_char,
        state: c_char,
    }

    extern {
        /// Parse a request, bit by bit.
        pub fn phr_parse_request(
            buf_start: *const c_char,
            buf_len: size_t,
            method: *mut *const c_char,
            method_len: *mut size_t,
            path: *mut *const c_char,
            path_len: *mut size_t,
            minor_version: *mut c_int,
            headers: *mut phr_header,
            num_headers: *mut size_t,
            prev_buf_len: size_t
        ) -> c_int;

        /// Parse a response, bit by bit.
        pub fn phr_parse_response(
            buf_start: *const c_char,
            buf_len: size_t,
            minor_version: *mut c_int,
            status: *mut c_int,
            message: *mut *const c_char,
            message_len: *mut size_t,
            headers: *mut phr_header,
            num_headers: *mut size_t,
            prev_buf_len: size_t
        ) -> c_int;

        /// Parse the headers, bit by bit.
        pub fn phr_parse_headers(
            buf_start: *const c_char,
            buf_len: size_t,
            headers: *mut phr_header,
            num_headers: *mut size_t,
            prev_buf_len: size_t
        ) -> c_int;

        /// Decode a chunked reqest body, bit by bit.
        pub fn phr_decode_chunked(
            decoder: *mut phr_chunked_decoder,
            buf: *mut c_char,
            buf_len: *mut size_t
        ) -> ssize_t;
    }
}