1 | // |
2 | // DialogServer.h |
3 | // |
4 | // Definition of the DialogServer class. |
5 | // |
6 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
7 | // and Contributors. |
8 | // |
9 | // SPDX-License-Identifier: BSL-1.0 |
10 | // |
11 | |
12 | |
13 | #ifndef DialogServer_INCLUDED |
14 | #define DialogServer_INCLUDED |
15 | |
16 | |
17 | #include "Poco/Net/Net.h" |
18 | #include "Poco/Net/ServerSocket.h" |
19 | #include "Poco/Net/StreamSocket.h" |
20 | #include "Poco/Thread.h" |
21 | #include "Poco/Event.h" |
22 | #include "Poco/Mutex.h" |
23 | #include <vector> |
24 | #include "Poco/Net/Session.h" |
25 | |
26 | |
27 | class DialogServer: public Poco::Runnable |
28 | /// A server for testing FTPClientSession and friends. |
29 | { |
30 | public: |
31 | DialogServer(bool acceptCommands = true, bool ssl = false); |
32 | /// Creates the DialogServer. |
33 | |
34 | ~DialogServer(); |
35 | /// Destroys the DialogServer. |
36 | |
37 | Poco::UInt16 port() const; |
38 | /// Returns the port the echo server is |
39 | /// listening on. |
40 | |
41 | void run(); |
42 | /// Does the work. |
43 | |
44 | const std::string& lastCommand() const; |
45 | /// Returns the last command received by the server. |
46 | |
47 | std::string popCommand(); |
48 | /// Pops the next command from the list of received commands. |
49 | |
50 | std::string popCommandWait(); |
51 | /// Pops the next command from the list of received commands. |
52 | /// Waits until a command is available. |
53 | |
54 | const std::vector<std::string>& lastCommands() const; |
55 | /// Returns the last command received by the server. |
56 | |
57 | void addResponse(const std::string& response); |
58 | /// Sets the next response returned by the server. |
59 | |
60 | void clearCommands(); |
61 | /// Clears all commands. |
62 | |
63 | void clearResponses(); |
64 | /// Clears all responses. |
65 | |
66 | void log(bool flag); |
67 | /// Enables or disables logging to stdout. |
68 | |
69 | Poco::Net::Session::Ptr getSslSession(); |
70 | void setSslSession(Poco::Net::Session::Ptr cSession); |
71 | |
72 | private: |
73 | Poco::Net::ServerSocket _socket; |
74 | Poco::Thread _thread; |
75 | Poco::Event _ready; |
76 | mutable Poco::FastMutex _mutex; |
77 | bool _stop; |
78 | std::vector<std::string> _nextResponses; |
79 | std::vector<std::string> _lastCommands; |
80 | bool _acceptCommands; |
81 | bool _log; |
82 | bool _ssl; |
83 | Poco::Net::Session::Ptr _SSLsession = nullptr; |
84 | }; |
85 | |
86 | |
87 | #endif // DialogServer_INCLUDED |
88 | |