Files
DomiStream/crates/domistream/src/http/applist.rs
T
mnovak 30a7b90034 [domistream] Implementation: HTTP, pairing, RTSP/SDP, ENet, control, input, RTP, FEC, video and audio receivers
Per PROTOCOL.md and the Wolf docs; interop with a real host is unverified. Strict, capped parsers throughout,
shared helpers in util.rs. Where PROTOCOL.md says UNKNOWN the Wolf-documented behaviour is used. The audio
receiver waits for the jitter budget before rebuilding a missing packet, so a late packet beats a rebuilt one.
2026-11-25 14:10:24 +01:00

49 lines
2.0 KiB
Rust

//! `GET /applist` (`docs/PROTOCOL.md` 1.3).
use crate::Result;
use crate::util::{cap, malformed, parse_u32};
/// Maximum size of an applist body, in bytes.
pub const MAX_APPLIST_BYTES: usize = 1024 * 1024;
/// Maximum number of apps accepted in one list.
pub const MAX_APPS: usize = 4096;
/// Maximum length of an app title, in bytes.
pub const MAX_APP_TITLE_BYTES: usize = 512;
/// One app the host can launch.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct App {
/// `ID`: the value for `appid` in launch.
pub id: u32,
/// `AppTitle`, unescaped.
pub title: String,
/// `IsHdrSupported == 1`.
pub hdr_supported: bool,
}
/// Parses an applist body. Apps keep the host's order; duplicate ids are refused; other elements are ignored.
///
/// # Errors
/// [`crate::Error::TooLarge`] over [`MAX_APPLIST_BYTES`], [`MAX_APPS`] or [`MAX_APP_TITLE_BYTES`],
/// [`crate::Error::HostStatus`] for a non-200 answer, [`crate::Error::Malformed`] for an `App` without `ID` or
/// `AppTitle`, a bad `ID`, or a duplicate `ID`.
pub fn parse_app_list(body: &[u8]) -> Result<Vec<App>> {
let doc = super::document(body, MAX_APPLIST_BYTES, "applist")?;
let count = doc.root.children.iter().filter(|c| c.name == "App").count();
cap("applist apps", MAX_APPS, count)?;
let mut apps: Vec<App> = Vec::with_capacity(count);
let mut ids = std::collections::BTreeSet::new();
for e in doc.root.children.iter().filter(|c| c.name == "App") {
let title = e.child("AppTitle").ok_or(malformed("applist: App without AppTitle"))?;
cap("applist AppTitle", MAX_APP_TITLE_BYTES, title.text.len())?;
let id = e.child("ID").ok_or(malformed("applist: App without ID"))?;
let id = parse_u32("applist ID", &id.text)?;
if !ids.insert(id) {
return Err(malformed("applist: duplicate ID"));
}
let hdr_supported = e.child("IsHdrSupported").is_some_and(|h| h.text == "1");
apps.push(App { id, title: title.text.clone(), hdr_supported });
}
Ok(apps)
}