curl-fuzzer C++ reference
Loading...
Searching...
No Matches
rtsp_mock_server.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
9
10#ifndef PROTO_FUZZER_RTSP_MOCK_SERVER_H_
11#define PROTO_FUZZER_RTSP_MOCK_SERVER_H_
12
13#include <cstddef>
14#include <cstdint>
15#include <string>
16#include <string_view>
17
18#include "curl_fuzzer.pb.h"
20
21namespace proto_fuzzer {
22
44class RtspMockServer : public PingpongMockServer {
45 public:
47
48 ~RtspMockServer() override;
49
50 void ObserveState() override;
51
52 RtspMockServer(const RtspMockServer&) = delete;
53 RtspMockServer& operator=(const RtspMockServer&) = delete;
54
55 void ConfigureClient(CURL* easy, curl::fuzzer::proto::RtspProbeMode mode);
56
57 CURLcode DriveCrossOriginReuseScenario(CURL* easy, const curl::fuzzer::proto::Scenario& scenario);
58
59 std::size_t request_count() const;
60
61 std::size_t response_count() const;
62
63 std::uint32_t last_client_cseq() const;
64
65 const std::string& last_request_line() const;
66
67 const std::string& last_method() const;
68
69 const std::string& last_stream_uri() const;
70
71 std::size_t client_write_failure_count() const;
72
73 std::size_t opened_transport_count() const;
74
75 protected:
76 curl_socket_t HandleOpenSocket(curlsocktype purpose = CURLSOCKTYPE_IPCXN,
77 struct curl_sockaddr* address = nullptr) override;
78
79 void HandleLine(std::string_view line) override;
80
81 void HandleBodyComplete() override;
82
83 void ResetProtocolState() override;
84
85 private:
86 static std::size_t ProbeWriteCallback(char* contents, std::size_t size, std::size_t nmemb, void* userdata);
87
88 void BeginRequest(std::string_view line);
89
90 void FinishRequest();
91
92 void ParseHeader(std::string_view line);
93
94 bool in_request_;
95 bool in_headers_;
96 bool have_client_cseq_;
97 bool have_content_length_;
98 std::uint32_t client_cseq_;
99 std::uint32_t last_client_cseq_;
100 std::size_t content_length_;
101 std::size_t request_count_;
102 std::size_t response_count_;
103 std::string last_request_line_;
104 std::string last_method_;
105 std::string last_stream_uri_;
106 curl::fuzzer::proto::RtspProbeMode probe_mode_;
107 std::size_t client_write_failure_count_;
108 std::size_t opened_transport_count_;
109};
110
111} // namespace proto_fuzzer
112
113#endif // PROTO_FUZZER_RTSP_MOCK_SERVER_H_
const curl::fuzzer::proto::Scenario * scenario() const
Borrowed scenario for the synchronous drive, or nullptr outside RunLoop().
void HandleLine(std::string_view line) override
Consume one complete request line or header line.
std::size_t opened_transport_count() const
void HandleBodyComplete() override
Release the reply after an announced request body was drained exactly.
void ConfigureClient(CURL *easy, curl::fuzzer::proto::RtspProbeMode mode)
Install only the callback and receive-buffer boundary required by the split-RTP probe.
void ObserveState() override
Retain protocol outcomes in coverage and introspector builds.
std::size_t response_count() const
Expose how many scripted replies could be released before the bounded script ran out.
void ResetProtocolState() override
Clear RTSP's per-request parse state before the next drive.
RtspMockServer()
Begin without a borrowed protobuf or open socketpair.
std::size_t client_write_failure_count() const
~RtspMockServer() override
Release the server-owned socketpair half after curl has returned its client descriptor.
const std::string & last_method() const
std::size_t request_count() const
Expose how far the bounded request stream progressed.
CURLcode DriveCrossOriginReuseScenario(CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
Run three ordinary OPTIONS-style exchanges through one multi connection cache.
std::uint32_t last_client_cseq() const
Expose the last parsed client sequence number so tests can verify that one request advanced the excha...
const std::string & last_stream_uri() const
const std::string & last_request_line() const
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 construct...
PingpongMockServer — shared line-oriented command/response transport for the mail-style protocol peer...