curl-fuzzer C++ reference
Loading...
Searching...
No Matches
imap_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_IMAP_MOCK_SERVER_H_
11#define PROTO_FUZZER_IMAP_MOCK_SERVER_H_
12
13#include <cstddef>
14#include <string>
15#include <string_view>
16
18
19namespace proto_fuzzer {
20
50class ImapMockServer : public PingpongMockServer {
51 public:
53
54 ~ImapMockServer() override;
55
56 void ObserveState() override;
57
58 ImapMockServer(const ImapMockServer&) = delete;
59 ImapMockServer& operator=(const ImapMockServer&) = delete;
60
61 protected:
62 void HandleLine(std::string_view line) override;
63
64 void ResetProtocolState() override;
65
66 void QueueShutdownReply() override;
67
68 private:
72 static constexpr std::string_view kShutdownTail = " OK LOGOUT completed\r\n";
73
74 // Resolve a scripted reply into wire bytes.
75 std::string RewriteReply(std::string_view response) const;
76
77 // Whether a complete line needs the current command tag prepended.
78 static bool StatusLineNeedsTag(std::string_view line);
79
80 // Whether a scripted reply contains a terminal tag-relative status line.
81 bool ResponseHasTaggedCompletion(std::string_view response) const;
82
83 // Whether a scripted reply contains an IMAP continuation line.
84 static bool ResponseHasContinuation(std::string_view response);
85
86 // Literal byte count for a trailing `{N}` marker, or 0 when absent.
87 static std::size_t LiteralSize(std::string_view line);
88
89 // Literal size announced by an APPEND command, or max size_t when absent.
90 static std::size_t AppendLiteralSize(std::string_view command);
91
92 // Tag curl will use for the next command, derived from the current tag.
93 std::string NextCommandTag() const;
94
96 std::string current_tag_;
97
100 bool authentication_continuation_active_ = false;
101};
102
103} // namespace proto_fuzzer
104
105#endif // PROTO_FUZZER_IMAP_MOCK_SERVER_H_
void ObserveState() override
Retain protocol outcomes in coverage and introspector builds.
void HandleLine(std::string_view line) override
Advance one reply for every complete command or AUTHENTICATE continuation.
void QueueShutdownReply() override
Queue a tagged completion for curl's blocking LOGOUT during teardown.
~ImapMockServer() override
Release the server-owned socketpair half after curl has returned its client descriptor.
void ResetProtocolState() override
Clear the tag remembered from the previous drive.
ImapMockServer()
Begin without a borrowed protobuf or open socketpair.
PingpongMockServer — shared line-oriented command/response transport for the mail-style protocol peer...