curl-fuzzer C++ reference
Loading...
Searching...
No Matches
proto_fuzzer::RtspMockServer Class Reference

Services curl's single-socket RTSP exchange. More...

#include <rtsp_mock_server.h>

Inheritance diagram for proto_fuzzer::RtspMockServer:
proto_fuzzer::PingpongMockServer proto_fuzzer::MockServerBase proto_fuzzer::IncomingDataObserver

Public Member Functions

 RtspMockServer ()
 Begin without a borrowed protobuf or open socketpair.
 ~RtspMockServer () override
 Release the server-owned socketpair half after curl has returned its client descriptor.
void ObserveState () override
 Retain protocol outcomes in coverage and introspector builds.
void ConfigureClient (CURL *easy, curl::fuzzer::proto::RtspProbeMode mode)
 Install only the callback and receive-buffer boundary required by the split-RTP probe.
CURLcode DriveCrossOriginReuseScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Run three ordinary OPTIONS-style exchanges through one multi connection cache.
std::size_t request_count () const
 Expose how far the bounded request stream progressed.
std::size_t response_count () const
 Expose how many scripted replies could be released before the bounded script ran out.
std::uint32_t last_client_cseq () const
 Expose the last parsed client sequence number so tests can verify that one request advanced the exchange exactly once.
const std::string & last_request_line () const
const std::string & last_method () const
const std::string & last_stream_uri () const
std::size_t client_write_failure_count () const
std::size_t opened_transport_count () const
Public Member Functions inherited from proto_fuzzer::PingpongMockServer
 ~PingpongMockServer () override
 Release the server-owned socketpair half after curl has returned its client descriptor.
const std::string & control_transcript () const
 Expose the bounded command capture from the most recent drive so tests can verify protocol states without coupling assertions to curl debug output.
const std::string & uploaded_data () const
 Expose a bounded prefix of bytes drained during the most recent body phase while continuing to drain every client byte, so test observability cannot create backpressure.
std::size_t active_pollset_probe_count () const
 Report how many requested zero-timeout multi-poll probes ran during the most recent drive.
std::size_t writable_pollset_probe_count () const
 Report how often curl retained writable interest while the peer held an incomplete control command.
Public Member Functions inherited from proto_fuzzer::MockServerBase
virtual ~MockServerBase ()
 Out-of-line destructor so MockConnection can stay forward-declared in the base header (its complete type is only needed where unique_ptr is instantiated for destruction).
virtual void Install (CURL *easy)
 Install the common OPENSOCKETFUNCTION / OPENSOCKETDATA / SOCKOPTFUNCTION callbacks on 'easy'.
virtual void ConfigureRequestData (ScenarioRequestData *request_data)
 Bind protocol-specific work to the request-data callbacks after their per-scenario state has been constructed.
CURLcode DriveScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Run 'scenario' to completion on 'easy': allocate a multi, attach 'easy', delegate protocol-specific work to RunLoop, consume its completion message, and clean up.
virtual CURLcode DriveEasyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario, bool use_events=false)
 Run through the public easy entrypoint when a protocol mock can preload all peer work before curl takes control.
virtual ConnectOnlyRunStats DriveConnectOnlyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Establish a CONNECT_ONLY transport, then perform bounded direct I/O.
void SetMultiObserver (MultiObserver observer)
 Register an observer invoked with the live multi handle after 'easy' is attached and before the drive loop starts.
MockConnection * connection ()

Protected Member Functions

curl_socket_t HandleOpenSocket (curlsocktype purpose=CURLSOCKTYPE_IPCXN, struct curl_sockaddr *address=nullptr) override
 Count successfully handed-off transports without changing the shared request-aligned socket construction.
void HandleLine (std::string_view line) override
 Consume one complete request line or header line.
void HandleBodyComplete () override
 Release the reply after an announced request body was drained exactly.
void ResetProtocolState () override
 Clear RTSP's per-request parse state before the next drive.
Protected Member Functions inherited from proto_fuzzer::PingpongMockServer
 PingpongMockServer (MultiDrivePolicy drive_policy=MultiDrivePolicy::kPerform)
 Construct the shared transport state without a borrowed protobuf or open socketpair.
virtual std::unique_ptr< MockConnection > CreateConnection ()
 Create the default plaintext transport.
void BeginMarkerBody (std::string_view terminator)
 Enter marker-terminated body mode.
void BeginLiteralBody (std::size_t length)
 Enter length-announced literal body mode.
void BeginExactBody (std::size_t length)
 Enter exact-length body mode.
void BeginOpaqueDrain ()
 Enter an opaque drain after a transport upgrade.
virtual void QueueShutdownReply ()
 Queue protocol-specific teardown liveness bytes before the control socket is half-closed.
void RunLoop (CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
 Alternate curl transitions with immediate peer service until the transfer completes or deterministic idle/operation caps win.
void HandleDetachedMulti (CurlMultiPtr multi) override
 Give curl's graceful shutdown one last chance to emit its teardown command while the peer still owns its read half, then release the multi as the base class would.
void ObserveIncomingData (const unsigned char *data, std::size_t size) override
 Append decoded application bytes to the pending parser buffer.
const curl::fuzzer::proto::Scenario * scenario () const
 Borrowed scenario for the synchronous drive, or nullptr outside RunLoop().
const std::string * NextControlReply ()
 Return the next command-aligned response within the shared response-count budget.
bool WriteControlBytes (std::string_view bytes)
 Keep failed peer writes local to the mock.
bool WriteNextReply ()
 Consume the next scripted reply.
void ShutdownControlWrite ()
 Half-close the server-to-client direction while retaining the read half.
Protected Member Functions inherited from proto_fuzzer::MockServerBase
 MockServerBase (MultiDrivePolicy drive_policy=MultiDrivePolicy::kPerform)
 Construct an empty base instance with a fixed multi-drive policy.
virtual SocketSetupDisposition GetSocketSetupDisposition (curl_socket_t curlfd, curlsocktype purpose) const
 Describe the socket returned by HandleOpenSocket without issuing native descriptor queries.
MultiSocketDriver * multi_socket_driver ()
 Expose the callback state installed for the current socket-action drive.
std::size_t additional_handle_cleanup_count () const
void ResumeResponseIfRequested (CURL *easy)
 Resume receive-side callback output at one bounded drive boundary when the dedicated API plan requested it.
void ApplyPendingBackpressure ()
 Apply the BackpressureConfig cached by DriveScenario to the new connection_.

Additional Inherited Members

Public Types inherited from proto_fuzzer::MockServerBase
using MultiObserver = std::function<void(CURLM*)>
 Callback type used to publish the driving multi handle to observers.
Static Protected Member Functions inherited from proto_fuzzer::PingpongMockServer
static std::string_view FirstToken (std::string_view line)
 Remove optional leading horizontal whitespace and return the first token without allocating.
static std::string_view SecondToken (std::string_view line)
 Skip the first token and return the second whitespace-delimited token without allocating.
static bool TokenEquals (std::string_view token, std::string_view expected_uppercase)
 Fold only ASCII lowercase command letters.
Static Protected Member Functions inherited from proto_fuzzer::MockServerBase
static int WaitOnMultiFdset (CURLM *multi, CURLMcode *rc)
 Wait on curl's fdset with a short timeout.
static void ProbeMultiPollset (CURLM *multi)
 Ask curl to construct and inspect its connection-filter pollset without waiting.
static bool MultiPollsetWantsWrite (CURLM *multi, curl_socket_t socket)
 Inspect one socket's current writable interest through curl's public multi fdset API.
static bool UsesTimedDrive (const curl::fuzzer::proto::Scenario &scenario)
 Treat a non-default BackpressureConfig as an explicit request for the slower, timed drive policy.
Protected Attributes inherited from proto_fuzzer::MockServerBase
std::unique_ptr< MockConnection > connection_
 The per-scenario MockConnection, lazily created by HandleOpenSocket().
int pending_recv_buf_bytes_
 Cached SO_RCVBUF/SO_SNDBUF setting in bytes.
std::size_t pending_drain_limit_
 Cached per-call DrainIncoming byte budget.
MultiSocketDriver * multi_socket_driver_
 Non-owning pointer into DriveScenario's stack.
std::size_t additional_handle_cleanup_count_
 Number of application-created handles, excluding the caller's parent, successfully removed from the current multi and cleaned up.
bool resume_response_
 True only for an API-plan multi drive with its one-shot write callback.
MultiObserver multi_observer_
 Observer receiving the live multi handle at the start of a drive.
Static Protected Attributes inherited from proto_fuzzer::MockServerBase
static constexpr int kMaxDriveIterations = 512
 Hard operation budget for one scenario.
static constexpr int kMaxIdleIterations = 8
 Consecutive no-progress budget for ordinary scenarios.
static constexpr int kMaxTimedIdleIterations = 256
 Explicit backpressure scenarios get a larger idle budget and may use the short timed wait above.

Detailed Description

Services curl's single-socket RTSP exchange.

RTSP is HTTP-like but starts with a client request: there is no server greeting, and every response is tied to exactly one request line plus its header block. That request/response rhythm is line-aligned, so this peer reuses PingpongMockServer rather than duplicating its bounded transport loop. Scenario.connection.initial_response is normally empty; each on_readable entry is one complete response to the next request. A response may contain a status line, headers, an entity body, and RFC 2326 interleaved RTP packets in the same byte string.

The peer parses the request start line and CSeq to track the exchange, and drains an announced request body with BeginExactBody() because RTSP body bytes are followed immediately by the next request rather than by a line terminator. The response text remains entirely fuzz-controlled: it is not rewritten to match the observed CSeq, so a mismatch still reaches curl's CURLE_RTSP_CSEQ_ERROR path. An ordinary drive cannot open follow-on sockets or pipeline multiple outstanding requests. The closed lifecycle probe runs three sequential drives so curl can replace one half-closed cached transport before changing origins.

Definition at line 44 of file rtsp_mock_server.h.

Constructor & Destructor Documentation

◆ RtspMockServer()

proto_fuzzer::RtspMockServer::RtspMockServer ( )

Begin without a borrowed protobuf or open socketpair.

RunLoop borrows a Scenario only for the synchronous drive in which socket callbacks can run.

Definition at line 146 of file rtsp_mock_server.cc.

◆ ~RtspMockServer()

proto_fuzzer::RtspMockServer::~RtspMockServer ( )
overridedefault

Release the server-owned socketpair half after curl has returned its client descriptor.

The out-of-line destructor keeps inherited transport ownership local to this translation unit.

Member Function Documentation

◆ client_write_failure_count()

std::size_t proto_fuzzer::RtspMockServer::client_write_failure_count ( ) const
Returns
Number of semantic one-byte '$' writes rejected in the latest drive.

Definition at line 276 of file rtsp_mock_server.cc.

◆ ConfigureClient()

void proto_fuzzer::RtspMockServer::ConfigureClient ( CURL * easy,
curl::fuzzer::proto::RtspProbeMode mode )

Install only the callback and receive-buffer boundary required by the split-RTP probe.

The callback otherwise consumes bytes exactly like the baseline sink, so enabling the closed mode changes behavior only for the single buffered '$' byte selected below.

Parameters
easyBorrowed easy handle whose callback and receive buffer may be configured.
modeClosed RTSP probe selected by the normalized scenario.

Definition at line 172 of file rtsp_mock_server.cc.

◆ DriveCrossOriginReuseScenario()

CURLcode proto_fuzzer::RtspMockServer::DriveCrossOriginReuseScenario ( CURL * easy,
const curl::fuzzer::proto::Scenario & scenario )

Run three ordinary OPTIONS-style exchanges through one multi connection cache.

The first response can teach curl a Session ID. Closing the peer's write half leaves that completed connection cached; the same-origin second add makes curl run RTSP's liveness check before opening a replacement transport. The fixed URL for the third transfer then exercises suppression of the learned Session header across origins without accepting an input-controlled destination.

Parameters
easyBorrowed easy handle repeated across all three transfers.
scenarioNormalized RTSP script supplying one response per transfer.
Returns
First non-success result, otherwise the final cross-origin result.

Definition at line 209 of file rtsp_mock_server.cc.

◆ HandleLine()

void proto_fuzzer::RtspMockServer::HandleLine ( std::string_view line)
overrideprotectedvirtual

Consume one complete request line or header line.

The blank line that ends the header block is the reply trigger: an announced body first switches the shared parser into exact-length mode, whose completion calls HandleBodyComplete().

Parameters
lineComplete line sent by curl.

Implements proto_fuzzer::PingpongMockServer.

Definition at line 395 of file rtsp_mock_server.cc.

◆ HandleOpenSocket()

curl_socket_t proto_fuzzer::RtspMockServer::HandleOpenSocket ( curlsocktype purpose = CURLSOCKTYPE_IPCXN,
struct curl_sockaddr * address = nullptr )
overrideprotectedvirtual

Count successfully handed-off transports without changing the shared request-aligned socket construction.

The lifecycle test uses the same-origin retry opening to establish that curl discarded the cached half-closed connection before issuing its second request.

Parameters
purposeSocket role requested by curl.
addressDestination metadata passed through to the shared peer.
Returns
Client descriptor for a successful control transport, or CURL_SOCKET_BAD.

Reimplemented from proto_fuzzer::PingpongMockServer.

Definition at line 289 of file rtsp_mock_server.cc.

◆ last_client_cseq()

std::uint32_t proto_fuzzer::RtspMockServer::last_client_cseq ( ) const

Expose the last parsed client sequence number so tests can verify that one request advanced the exchange exactly once.

Returns
Last request CSeq, or zero when no parseable CSeq was present.

Definition at line 263 of file rtsp_mock_server.cc.

◆ last_method()

const std::string & proto_fuzzer::RtspMockServer::last_method ( ) const
Returns
Method token of the most recently completed request.

Definition at line 269 of file rtsp_mock_server.cc.

◆ last_request_line()

const std::string & proto_fuzzer::RtspMockServer::last_request_line ( ) const
Returns
Start line of the most recently completed request.

Definition at line 266 of file rtsp_mock_server.cc.

◆ last_stream_uri()

const std::string & proto_fuzzer::RtspMockServer::last_stream_uri ( ) const
Returns
Stream URI token of the most recently completed request.

Definition at line 272 of file rtsp_mock_server.cc.

◆ opened_transport_count()

std::size_t proto_fuzzer::RtspMockServer::opened_transport_count ( ) const
Returns
Number of control transports opened since ConfigureClient().

Definition at line 279 of file rtsp_mock_server.cc.

◆ request_count()

std::size_t proto_fuzzer::RtspMockServer::request_count ( ) const

Expose how far the bounded request stream progressed.

The parser counts a request only after its header block and any announced body were consumed.

Returns
Complete requests observed in the most recent drive.

Definition at line 253 of file rtsp_mock_server.cc.

◆ ResetProtocolState()

void proto_fuzzer::RtspMockServer::ResetProtocolState ( )
overrideprotectedvirtual

Clear RTSP's per-request parse state before the next drive.

The shared base has already reset the transport, reply cursor, transcript, upload capture, and body mode.

Reimplemented from proto_fuzzer::PingpongMockServer.

Definition at line 300 of file rtsp_mock_server.cc.

◆ response_count()

std::size_t proto_fuzzer::RtspMockServer::response_count ( ) const

Expose how many scripted replies could be released before the bounded script ran out.

Returns
Scripted replies written in the most recent drive.

Definition at line 258 of file rtsp_mock_server.cc.


The documentation for this class was generated from the following files: