Skip to content

uefi-raw: Add common impls for http types #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added `FirmwareVolumeBlock2Protocol`.
- Added `HiiDatabaseProtocol`.
- Added `ScsiIoProtocol`.
- Added `Default` and other common impls for HTTP types.


# uefi-raw - 0.9.0 (2024-10-23)
Expand Down
68 changes: 64 additions & 4 deletions uefi-raw/src/protocol/network/http.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{guid, Char16, Char8, Event, Guid, Ipv4Address, Ipv6Address, Status};
use core::ffi::c_void;
use core::fmt::{self, Debug, Formatter};
use core::ptr;

#[derive(Debug)]
#[derive(Debug, Default)]
#[repr(C)]
pub struct HttpConfigData {
pub http_version: HttpVersion,
Expand All @@ -12,14 +13,15 @@ pub struct HttpConfigData {
}

newtype_enum! {
#[derive(Default)]
pub enum HttpVersion: i32 => {
HTTP_VERSION_10 = 0,
HTTP_VERSION_11 = 1,
HTTP_VERSION_UNSUPPORTED = 2,
}
}

#[derive(Debug)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct HttpV4AccessPoint {
pub use_default_addr: bool,
Expand All @@ -28,7 +30,7 @@ pub struct HttpV4AccessPoint {
pub local_port: u16,
}

#[derive(Debug)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct HttpV6AccessPoint {
pub local_address: Ipv6Address,
Expand All @@ -48,6 +50,14 @@ impl Debug for HttpAccessPoint {
}
}

impl Default for HttpAccessPoint {
fn default() -> Self {
Self {
ipv4_node: ptr::null(),
}
}
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpToken {
Expand All @@ -56,6 +66,16 @@ pub struct HttpToken {
pub message: *mut HttpMessage,
}

impl Default for HttpToken {
fn default() -> Self {
Self {
event: ptr::null_mut(),
status: Status::SUCCESS,
message: ptr::null_mut(),
}
}
}

#[derive(Debug)]
#[repr(C)]
pub struct HttpMessage {
Expand All @@ -66,14 +86,36 @@ pub struct HttpMessage {
pub body: *mut c_void,
}

impl Default for HttpMessage {
fn default() -> Self {
Self {
data: HttpRequestOrResponse::default(),
header_count: 0,
header: ptr::null_mut(),
body_length: 0,
body: ptr::null_mut(),
}
}
}

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

impl Default for HttpRequestData {
fn default() -> Self {
Self {
method: HttpMethod::default(),
url: ptr::null(),
}
}
}

newtype_enum! {
#[derive(Default)]
pub enum HttpMethod: i32 => {
GET = 0,
POST = 1,
Expand All @@ -88,7 +130,7 @@ newtype_enum! {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
#[repr(C)]
pub struct HttpResponseData {
pub status_code: HttpStatusCode,
Expand All @@ -107,14 +149,32 @@ impl Debug for HttpRequestOrResponse {
}
}

impl Default for HttpRequestOrResponse {
fn default() -> Self {
Self {
request: ptr::null(),
}
}
}

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

impl Default for HttpHeader {
fn default() -> Self {
Self {
field_name: ptr::null(),
field_value: ptr::null(),
}
}
}

newtype_enum! {
#[derive(Default)]
pub enum HttpStatusCode: i32 => {
STATUS_UNSUPPORTED = 0,
STATUS_100_CONTINUE = 1,
Expand Down
Loading