/src/curl_fuzzer/proto_fuzzer/pop3_mock_server.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | /// @file |
8 | | /// @brief Implementation of the command-aware in-process POP3 peer. |
9 | | |
10 | | #include "proto_fuzzer/pop3_mock_server.h" |
11 | | |
12 | | #include <string> |
13 | | #include <string_view> |
14 | | |
15 | | namespace proto_fuzzer { |
16 | | |
17 | | /// Begin without a borrowed protobuf or open socketpair. RunLoop borrows a |
18 | | /// Scenario only for the synchronous DriveScenario call in which socket |
19 | | /// callbacks can run. |
20 | 3.82k | Pop3MockServer::Pop3MockServer() = default; |
21 | | |
22 | | /// Release the server-owned socketpair half after curl has returned its client |
23 | | /// descriptor. The out-of-line destructor keeps MockConnection's complete type |
24 | | /// local to this translation unit. |
25 | 3.82k | Pop3MockServer::~Pop3MockServer() = default; |
26 | | |
27 | | /// Advance one reply for every complete command. POP3's status lines are |
28 | | /// self-describing, so the scripted bytes are written unchanged; curl chooses |
29 | | /// multi-line handling from the command it sent, not from the reply. |
30 | | /// @param line One newline-terminated command from curl. |
31 | 4.14k | void Pop3MockServer::HandleLine(std::string_view /*line*/) { |
32 | 4.14k | if (scenario() == nullptr) { |
33 | 112 | return; |
34 | 112 | } |
35 | 4.03k | const std::string* response = NextControlReply(); |
36 | 4.03k | if (response != nullptr) { |
37 | 2.62k | (void)WriteControlBytes(*response); |
38 | 2.62k | } |
39 | 4.03k | } |
40 | | |
41 | | /// Queue a +OK for the blocking QUIT that follows easy cleanup, then let the |
42 | | /// shared transport half-close so an unfinished transfer cannot wait on a |
43 | | /// reply that will never arrive. |
44 | 3.24k | void Pop3MockServer::QueueShutdownReply() { (void)WriteControlBytes(kShutdownReply); } |
45 | | |
46 | | } // namespace proto_fuzzer |