uefi_raw/protocol/network/
http.rs

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use crate::{guid, Char16, Char8, Event, Guid, Ipv4Address, Ipv6Address, Status};
use core::ffi::c_void;
use core::fmt::{self, Debug, Formatter};

#[derive(Debug)]
#[repr(C)]
pub struct HttpConfigData {
    pub http_version: HttpVersion,
    pub time_out_millisec: u32,
    pub local_addr_is_ipv6: bool,
    pub access_point: HttpAccessPoint,
}

newtype_enum! {
    pub enum HttpVersion: i32 => {
        HTTP_VERSION_10 = 0,
        HTTP_VERSION_11 = 1,
        HTTP_VERSION_UNSUPPORTED = 2,
    }
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpV4AccessPoint {
    pub use_default_addr: bool,
    pub local_address: Ipv4Address,
    pub local_subnet: Ipv4Address,
    pub local_port: u16,
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpV6AccessPoint {
    pub local_address: Ipv6Address,
    pub local_port: u16,
}

#[repr(C)]
pub union HttpAccessPoint {
    pub ipv4_node: *const HttpV4AccessPoint,
    pub ipv6_node: *const HttpV6AccessPoint,
}

impl Debug for HttpAccessPoint {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        // This is a union type, so we can't access the internal data.
        f.debug_struct("HttpAccessPoint").finish()
    }
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpToken {
    pub event: Event,
    pub status: Status,
    pub message: *mut HttpMessage,
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpMessage {
    pub data: HttpRequestOrResponse,
    pub header_count: usize,
    pub header: *mut HttpHeader,
    pub body_length: usize,
    pub body: *mut c_void,
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpRequestData {
    pub method: HttpMethod,
    pub url: *const Char16,
}

newtype_enum! {
    pub enum HttpMethod: i32 => {
        GET     = 0,
        POST    = 1,
        PATCH   = 2,
        OPTIONS = 3,
        CONNECT = 4,
        HEAD    = 5,
        PUT     = 6,
        DELETE  = 7,
        TRACE   = 8,
        MAX     = 9,
    }
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpResponseData {
    pub status_code: HttpStatusCode,
}

#[repr(C)]
pub union HttpRequestOrResponse {
    pub request: *const HttpRequestData,
    pub response: *const HttpResponseData,
}

impl Debug for HttpRequestOrResponse {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        // This is a union type, so we can't access the internal data.
        f.debug_struct("RequestOrResponse").finish()
    }
}

#[derive(Clone, Debug)]
#[repr(C)]
pub struct HttpHeader {
    pub field_name: *const Char8,
    pub field_value: *const Char8,
}

newtype_enum! {
    pub enum HttpStatusCode: i32 => {
        STATUS_UNSUPPORTED = 0,
        STATUS_100_CONTINUE = 1,
        STATUS_101_SWITCHING_PROTOCOLS = 2,
        STATUS_200_OK = 3,
        STATUS_201_CREATED = 4,
        STATUS_202_ACCEPTED = 5,
        STATUS_203_NON_AUTHORITATIVE_INFORMATION = 6,
        STATUS_204_NO_CONTENT = 7,
        STATUS_205_RESET_CONTENT = 8,
        STATUS_206_PARTIAL_CONTENT = 9,
        STATUS_300_MULTIPLE_CHOICES = 10,
        STATUS_301_MOVED_PERMANENTLY = 11,
        STATUS_302_FOUND = 12,
        STATUS_303_SEE_OTHER = 13,
        STATUS_304_NOT_MODIFIED = 14,
        STATUS_305_USE_PROXY = 15,
        STATUS_307_TEMPORARY_REDIRECT = 16,
        STATUS_400_BAD_REQUEST = 17,
        STATUS_401_UNAUTHORIZED = 18,
        STATUS_402_PAYMENT_REQUIRED = 19,
        STATUS_403_FORBIDDEN = 20,
        STATUS_404_NOT_FOUND = 21,
        STATUS_405_METHOD_NOT_ALLOWED = 22,
        STATUS_406_NOT_ACCEPTABLE = 23,
        STATUS_407_PROXY_AUTHENTICATION_REQUIRED = 24,
        STATUS_408_REQUEST_TIME_OUT = 25,
        STATUS_409_CONFLICT = 26,
        STATUS_410_GONE = 27,
        STATUS_411_LENGTH_REQUIRED = 28,
        STATUS_412_PRECONDITION_FAILED = 29,
        STATUS_413_REQUEST_ENTITY_TOO_LARGE = 30,
        STATUS_414_REQUEST_URI_TOO_LARGE = 31,
        STATUS_415_UNSUPPORTED_MEDIA_TYPE = 32,
        STATUS_416_REQUESTED_RANGE_NOT_SATISFIED = 33,
        STATUS_417_EXPECTATION_FAILED = 34,
        STATUS_500_INTERNAL_SERVER_ERROR = 35,
        STATUS_501_NOT_IMPLEMENTED = 36,
        STATUS_502_BAD_GATEWAY = 37,
        STATUS_503_SERVICE_UNAVAILABLE = 38,
        STATUS_504_GATEWAY_TIME_OUT = 39,
        STATUS_505_VERSION_NOT_SUPPORTED = 40,
        STATUS_308_PERMANENT_REDIRECT = 41,
    }
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpProtocol {
    pub get_mode_data:
        unsafe extern "efiapi" fn(this: *const Self, config_data: *mut HttpConfigData) -> Status,
    pub configure:
        unsafe extern "efiapi" fn(this: *mut Self, config_data: *const HttpConfigData) -> Status,
    pub request: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
    pub cancel: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
    pub response: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
    pub poll: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
}

impl HttpProtocol {
    pub const GUID: Guid = guid!("7a59b29b-910b-4171-8242-a85a0df25b5b");
    pub const SERVICE_BINDING_GUID: Guid = guid!("bdc8e6af-d9bc-4379-a72a-e0c4e75dae1c");
}