[domistream] RTSP server: tests first (in-memory client/server session, order, Session, ANNOUNCE parser, DESCRIBE writer, caps); API stubs return Unimplemented
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
//! RTSP stream negotiation (`docs/PROTOCOL.md` section 2): message codec, a framer for the TCP byte stream, SDP,
|
||||
//! and the client state machine.
|
||||
//! the client state machine and the host's session ([`server`], section 2.5).
|
||||
|
||||
pub mod client;
|
||||
pub mod sdp;
|
||||
pub mod server;
|
||||
|
||||
pub use client::{NegotiatedStream, RtspClient, RtspClientState, RtspProgress, StreamConfig, StreamPorts};
|
||||
pub use sdp::{EncryptionFlags, HostCapabilities, OpusConfig, Sdp};
|
||||
pub use server::{HostOffer, RtspServer, RtspServerState, ServerConfig, ServerEvent, ServerReply};
|
||||
|
||||
use crate::util::{cap, malformed, parse_dec};
|
||||
use crate::{Error, Result};
|
||||
@@ -132,6 +134,17 @@ impl RtspResponse {
|
||||
pub fn header(&self, name: &str) -> Option<&str> {
|
||||
header(&self.headers, name)
|
||||
}
|
||||
|
||||
/// Serializes the response (`RTSP/1.0 <status> <reason>`, CRLF line ends, empty line, payload) with exactly the
|
||||
/// given headers. The host side's mirror of [`RtspRequest::encode`].
|
||||
///
|
||||
/// # Errors
|
||||
/// [`Error::Malformed`] for a status outside 100..=999, CR, LF or another control character in the reason, a
|
||||
/// header name that is not a token, or CR or LF in a header value; [`Error::TooLarge`] over
|
||||
/// [`MAX_RTSP_MESSAGE_BYTES`].
|
||||
pub fn encode(&self) -> Result<Vec<u8>> {
|
||||
Err(Error::Unimplemented)
|
||||
}
|
||||
}
|
||||
|
||||
/// A message split into start line, headers and payload.
|
||||
@@ -252,21 +265,31 @@ pub fn parse_request(message: &[u8]) -> Result<RtspRequest> {
|
||||
Ok(RtspRequest { method, target: target.to_owned(), headers: m.headers, body: m.body })
|
||||
}
|
||||
|
||||
/// Cuts the TCP byte stream from the host into whole messages.
|
||||
/// Cuts a TCP byte stream into whole messages.
|
||||
///
|
||||
/// A message ends after its headers plus `Content-Length` payload bytes; without `Content-Length` it ends when
|
||||
/// the host closes the connection ([`RtspFramer::finish`]) (UNKNOWN U5). Never buffers more than
|
||||
/// [`MAX_RTSP_MESSAGE_BYTES`].
|
||||
/// A message ends after its headers plus `Content-Length` payload bytes. Without `Content-Length`, a framer made
|
||||
/// with [`RtspFramer::new`] (the client reading the host's answers) ends the message when the host closes the
|
||||
/// connection ([`RtspFramer::finish`]) (UNKNOWN U5); one made with [`RtspFramer::for_requests`] (the host reading
|
||||
/// a client's requests) takes a missing `Content-Length` as zero, as RFC 2326 section 4.4 says, so the message
|
||||
/// ends at the empty line (`docs/PROTOCOL.md` 2.5). Never buffers more than [`MAX_RTSP_MESSAGE_BYTES`].
|
||||
#[derive(Debug, Default)]
|
||||
pub struct RtspFramer {
|
||||
buffer: Vec<u8>,
|
||||
/// A missing `Content-Length` means "no payload" (requests) instead of "until close" (answers).
|
||||
missing_length_is_zero: bool,
|
||||
}
|
||||
|
||||
impl RtspFramer {
|
||||
/// An empty framer.
|
||||
/// An empty framer for the host's answers (client side).
|
||||
#[must_use]
|
||||
pub const fn new() -> Self {
|
||||
Self { buffer: Vec::new() }
|
||||
Self { buffer: Vec::new(), missing_length_is_zero: false }
|
||||
}
|
||||
|
||||
/// An empty framer for a client's requests (host side): a request without `Content-Length` has no payload.
|
||||
#[must_use]
|
||||
pub const fn for_requests() -> Self {
|
||||
Self { buffer: Vec::new(), missing_length_is_zero: true }
|
||||
}
|
||||
|
||||
/// Appends received bytes.
|
||||
@@ -293,7 +316,9 @@ impl RtspFramer {
|
||||
headers.push((n.to_owned(), v.trim_matches([' ', '\t']).to_owned()));
|
||||
}
|
||||
}
|
||||
Ok(Some((head_len, content_length(&headers, head_len)?)))
|
||||
let length = content_length(&headers, head_len)?;
|
||||
let _ = self.missing_length_is_zero;
|
||||
Ok(Some((head_len, length)))
|
||||
}
|
||||
|
||||
/// Takes the next complete message, if one is buffered.
|
||||
|
||||
Reference in New Issue
Block a user