Skip to content

Commit 6e69584

Browse files
uefi-raw: Add common impls for http types
Of note, all types now implement `Default`, with all fields set to zero/null. This can be useful when constructing the types, even if the default is not itself particularly semantically meaningful.
1 parent a2b78a7 commit 6e69584

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

uefi-raw/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Added `FirmwareVolumeBlock2Protocol`.
1010
- Added `HiiDatabaseProtocol`.
1111
- Added `ScsiIoProtocol`.
12+
- Added `Default` and other common impls for HTTP types.
1213

1314

1415
# uefi-raw - 0.9.0 (2024-10-23)

uefi-raw/src/protocol/network/http.rs

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::{guid, Char16, Char8, Event, Guid, Ipv4Address, Ipv6Address, Status};
22
use core::ffi::c_void;
33
use core::fmt::{self, Debug, Formatter};
4+
use core::ptr;
45

5-
#[derive(Debug)]
6+
#[derive(Debug, Default)]
67
#[repr(C)]
78
pub struct HttpConfigData {
89
pub http_version: HttpVersion,
@@ -12,14 +13,15 @@ pub struct HttpConfigData {
1213
}
1314

1415
newtype_enum! {
16+
#[derive(Default)]
1517
pub enum HttpVersion: i32 => {
1618
HTTP_VERSION_10 = 0,
1719
HTTP_VERSION_11 = 1,
1820
HTTP_VERSION_UNSUPPORTED = 2,
1921
}
2022
}
2123

22-
#[derive(Debug)]
24+
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
2325
#[repr(C)]
2426
pub struct HttpV4AccessPoint {
2527
pub use_default_addr: bool,
@@ -28,7 +30,7 @@ pub struct HttpV4AccessPoint {
2830
pub local_port: u16,
2931
}
3032

31-
#[derive(Debug)]
33+
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
3234
#[repr(C)]
3335
pub struct HttpV6AccessPoint {
3436
pub local_address: Ipv6Address,
@@ -48,6 +50,14 @@ impl Debug for HttpAccessPoint {
4850
}
4951
}
5052

53+
impl Default for HttpAccessPoint {
54+
fn default() -> Self {
55+
Self {
56+
ipv4_node: ptr::null(),
57+
}
58+
}
59+
}
60+
5161
#[derive(Debug)]
5262
#[repr(C)]
5363
pub struct HttpToken {
@@ -56,6 +66,16 @@ pub struct HttpToken {
5666
pub message: *mut HttpMessage,
5767
}
5868

69+
impl Default for HttpToken {
70+
fn default() -> Self {
71+
Self {
72+
event: ptr::null_mut(),
73+
status: Status::SUCCESS,
74+
message: ptr::null_mut(),
75+
}
76+
}
77+
}
78+
5979
#[derive(Debug)]
6080
#[repr(C)]
6181
pub struct HttpMessage {
@@ -66,14 +86,36 @@ pub struct HttpMessage {
6686
pub body: *mut c_void,
6787
}
6888

89+
impl Default for HttpMessage {
90+
fn default() -> Self {
91+
Self {
92+
data: HttpRequestOrResponse::default(),
93+
header_count: 0,
94+
header: ptr::null_mut(),
95+
body_length: 0,
96+
body: ptr::null_mut(),
97+
}
98+
}
99+
}
100+
69101
#[derive(Debug)]
70102
#[repr(C)]
71103
pub struct HttpRequestData {
72104
pub method: HttpMethod,
73105
pub url: *const Char16,
74106
}
75107

108+
impl Default for HttpRequestData {
109+
fn default() -> Self {
110+
Self {
111+
method: HttpMethod::default(),
112+
url: ptr::null(),
113+
}
114+
}
115+
}
116+
76117
newtype_enum! {
118+
#[derive(Default)]
77119
pub enum HttpMethod: i32 => {
78120
GET = 0,
79121
POST = 1,
@@ -88,7 +130,7 @@ newtype_enum! {
88130
}
89131
}
90132

91-
#[derive(Debug)]
133+
#[derive(Debug, Default)]
92134
#[repr(C)]
93135
pub struct HttpResponseData {
94136
pub status_code: HttpStatusCode,
@@ -107,14 +149,32 @@ impl Debug for HttpRequestOrResponse {
107149
}
108150
}
109151

152+
impl Default for HttpRequestOrResponse {
153+
fn default() -> Self {
154+
Self {
155+
request: ptr::null(),
156+
}
157+
}
158+
}
159+
110160
#[derive(Clone, Debug)]
111161
#[repr(C)]
112162
pub struct HttpHeader {
113163
pub field_name: *const Char8,
114164
pub field_value: *const Char8,
115165
}
116166

167+
impl Default for HttpHeader {
168+
fn default() -> Self {
169+
Self {
170+
field_name: ptr::null(),
171+
field_value: ptr::null(),
172+
}
173+
}
174+
}
175+
117176
newtype_enum! {
177+
#[derive(Default)]
118178
pub enum HttpStatusCode: i32 => {
119179
STATUS_UNSUPPORTED = 0,
120180
STATUS_100_CONTINUE = 1,

0 commit comments

Comments
 (0)