[domistream] Host HTTP: tests first (request head and query parsing, caps, XML answers read back by the client parsers); API stubs return Unimplemented

This commit is contained in:
2026-12-04 12:24:42 +01:00
parent 7b9b1f4e9c
commit 3aa3775de8
7 changed files with 1545 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
//! The host's XML answers (`docs/PROTOCOL.md` 1.1-1.5): every body is `<root status_code="…">` with elements
//! inside. Text and attribute values are escaped; a value the client's parser would refuse (too long, empty where
//! required, control characters) is refused here first, so the host never sends what its clients cannot read.
use crate::host::pairing::PairAnswer;
use crate::http::{App, Scheme};
use crate::{Error, Result};
/// What the host says about itself in `serverinfo` (`docs/PROTOCOL.md` 1.2).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HostInfo {
/// `hostname`: the name the client shows. Non-empty.
pub hostname: String,
/// `appversion`, the protocol version string, e.g. `7.1.431.-1`.
pub app_version: String,
/// `GfeVersion`, the compatibility version string.
pub gfe_version: String,
/// `uniqueid`: the host's stable id. Non-empty.
pub unique_id: String,
/// `HttpsPort`.
pub https_port: u16,
/// `ExternalPort`: the HTTP port.
pub http_port: u16,
/// `mac` for Wake-on-LAN, written `aa:bb:cc:dd:ee:ff`; `None` writes an empty element.
pub mac: Option<[u8; 6]>,
/// `LocalIP`: the host's address as this client reached it; empty is allowed.
pub local_ip: String,
/// `MaxLumaPixelsHEVC`; 0 = no HEVC.
pub max_luma_pixels_hevc: u64,
/// `ServerCodecModeSupport` bitmask (bit meanings UNKNOWN U25).
pub codec_mode_support: u32,
/// `currentgame`: id of the running app, 0 = none.
pub current_game: u32,
/// Prefix of `state`: written `<prefix>_SERVER_BUSY` when `current_game != 0`, else `<prefix>_SERVER_FREE`.
/// Letters, digits and `_` only.
pub state_prefix: String,
}
/// `serverinfo`. `PairStatus` is 1 only when the request came over HTTPS (`scheme`) with a paired client certificate
/// (`client_paired`); over plain HTTP it is always 0 (`docs/PROTOCOL.md` 1.2).
///
/// # Errors
/// [`Error::Malformed`] for an empty `hostname` or `unique_id`, a bad `state_prefix`, or control characters;
/// [`Error::TooLarge`] for a field over [`crate::http::serverinfo::MAX_SERVERINFO_FIELD_BYTES`].
pub fn server_info_xml(info: &HostInfo, scheme: Scheme, client_paired: bool) -> Result<Vec<u8>> {
let _ = (info, scheme, client_paired);
Err(Error::Unimplemented)
}
/// `applist`: one `<App>` per app with `AppTitle`, `ID` and `IsHdrSupported`, in the given order.
///
/// # Errors
/// [`Error::TooLarge`] over [`crate::http::applist::MAX_APPS`] apps or a title over
/// [`crate::http::applist::MAX_APP_TITLE_BYTES`]; [`Error::Malformed`] for a duplicate id or control characters.
pub fn app_list_xml(apps: &[App]) -> Result<Vec<u8>> {
let _ = apps;
Err(Error::Unimplemented)
}
/// `launch`: `gamesession=1` and `sessionUrl0=rtsp://<rtsp_host>:<rtsp_port>` (`docs/PROTOCOL.md` 1.4).
///
/// # Errors
/// [`Error::Malformed`] unless `rtsp_host` is a host name, an IPv4 address or a bracketed IPv6 literal and the
/// port is not 0; [`Error::TooLarge`] for a URL over [`crate::http::launch::MAX_SESSION_URL_BYTES`].
pub fn launch_xml(rtsp_host: &str, rtsp_port: u16) -> Result<Vec<u8>> {
let _ = (rtsp_host, rtsp_port);
Err(Error::Unimplemented)
}
/// `resume`: the same body as [`launch_xml`] (the client reads both with one parser).
///
/// # Errors
/// As [`launch_xml`].
pub fn resume_xml(rtsp_host: &str, rtsp_port: u16) -> Result<Vec<u8>> {
let _ = (rtsp_host, rtsp_port);
Err(Error::Unimplemented)
}
/// A bare `<root status_code="200"/>`: the answer to `cancel` and `unpair`.
#[must_use]
pub fn ok_xml() -> Vec<u8> {
Vec::new()
}
/// One pairing answer: `paired` and the phase's element, hex-encoded (`docs/PROTOCOL.md` 1.5).
///
/// # Errors
/// [`Error::TooLarge`] for a value over the client's caps (a certificate over
/// [`crate::pairing::identity::MAX_CERT_PEM_BYTES`], a body over [`crate::pairing::MAX_PAIR_RESPONSE_BYTES`]).
pub fn pair_answer_xml(answer: &PairAnswer) -> Result<Vec<u8>> {
let _ = answer;
Err(Error::Unimplemented)
}
/// The error root: `<root status_code="<code>" status_message="<message>"/>` (`docs/PROTOCOL.md` 1.1).
///
/// # Errors
/// [`Error::Malformed`] for code 200 or a code outside 100..=999, or control characters in `message`;
/// [`Error::TooLarge`] for a message over [`MAX_STATUS_MESSAGE_BYTES`].
pub fn error_xml(status_code: u32, message: &str) -> Result<Vec<u8>> {
let _ = (status_code, message);
Err(Error::Unimplemented)
}
/// Maximum length of an error's `status_message`, in bytes.
pub const MAX_STATUS_MESSAGE_BYTES: usize = 256;
/// Most apps one `applist` answer carries: the client's [`crate::http::applist::MAX_APPS`], lowered so the
/// document stays within the client's [`crate::http::xml::MAX_XML_ELEMENTS`] (the root plus four elements per app).
pub const MAX_WRITTEN_APPS: usize = {
let by_elements = (crate::http::xml::MAX_XML_ELEMENTS - 1) / 4;
if crate::http::applist::MAX_APPS < by_elements { crate::http::applist::MAX_APPS } else { by_elements }
};