[domistream] HTTP API: serverinfo, applist, launch/resume/cancel requests and capped XML parsers

This commit is contained in:
2026-11-25 11:45:30 +01:00
parent cb8e7ed4c3
commit 0188ffba97
6 changed files with 310 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
//! The HTTP/HTTPS side of GameStream (`docs/PROTOCOL.md` section 1): request building and strict parsers of the
//! host's XML answers. Pairing has its own module, [`crate::pairing`].
//!
//! DomiStream builds the path and query of each `GET`; the caller sends it over plain HTTP or over TLS (with the
//! client certificate and the pinned host certificate, see [`crate::pairing::ServerCert`]) and hands the response
//! body back to the matching `parse_*` function.
use core::time::Duration;
pub mod applist;
pub mod launch;
pub mod serverinfo;
pub mod xml;
pub use applist::{App, parse_app_list};
pub use launch::{LaunchParams, LaunchResponse, parse_launch_response};
pub use serverinfo::{ServerInfo, parse_server_info};
/// Default HTTP port of a GameStream host.
pub const DEFAULT_HTTP_PORT: u16 = 47989;
/// Default HTTPS port of a GameStream host.
pub const DEFAULT_HTTPS_PORT: u16 = 47984;
/// Maximum length of the client's `uniqueid`, in bytes.
pub const MAX_UNIQUE_ID_BYTES: usize = 64;
/// Maximum length of the device name sent while pairing, in bytes.
pub const MAX_DEVICE_NAME_BYTES: usize = 64;
/// Plain HTTP or HTTPS.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Scheme {
/// Plain HTTP (port [`DEFAULT_HTTP_PORT`] unless the host says otherwise).
Http,
/// HTTPS with the client certificate (port from `serverinfo`'s `HttpsPort`).
Https,
}
/// One `GET` request for the caller to send. Always a `GET`; the body is always empty.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HttpRequest {
/// Which port and transport to use.
pub scheme: Scheme,
/// Path and percent-encoded query, e.g. `/serverinfo?uniqueid=0123456789ABCDEF`.
pub path_and_query: String,
/// How long the caller should wait for the answer. `None` = the caller's normal timeout. Pairing step 1 blocks
/// on the host until the PIN is entered, so it asks for a long one.
pub timeout: Option<Duration>,
}
/// Builds `GET /serverinfo` for this client.
///
/// # Errors
/// [`crate::Error::Malformed`] for an empty or oversized `unique_id`. Phase A: always
/// [`crate::Error::Unimplemented`].
pub fn server_info_request(scheme: Scheme, unique_id: &str) -> crate::Result<HttpRequest> {
let _ = (scheme, unique_id);
Err(crate::Error::Unimplemented)
}
/// Builds `GET /applist` (HTTPS).
///
/// # Errors
/// As [`server_info_request`].
pub fn app_list_request(unique_id: &str) -> crate::Result<HttpRequest> {
let _ = unique_id;
Err(crate::Error::Unimplemented)
}
/// Builds `GET /cancel` (HTTPS): quits the app running on the host.
///
/// # Errors
/// As [`server_info_request`].
pub fn cancel_request(unique_id: &str) -> crate::Result<HttpRequest> {
let _ = unique_id;
Err(crate::Error::Unimplemented)
}
/// Builds `GET /unpair` (HTTPS): the host forgets this client.
///
/// # Errors
/// As [`server_info_request`].
pub fn unpair_request(unique_id: &str) -> crate::Result<HttpRequest> {
let _ = unique_id;
Err(crate::Error::Unimplemented)
}
/// Checks a plain `<root status_code="200"/>` answer (cancel, unpair).
///
/// # Errors
/// [`crate::Error::HostStatus`] for a non-200 status, parser errors as [`xml::parse`]. Phase A: always
/// [`crate::Error::Unimplemented`].
pub fn parse_status_response(body: &[u8]) -> crate::Result<()> {
let _ = body;
Err(crate::Error::Unimplemented)
}