3 #include "telnetpp/session.hpp"
5 #include <boost/signals2.hpp>
41 telnetpp::command_type LocalPositive,
42 telnetpp::command_type LocalNegative,
43 telnetpp::command_type RemotePositive,
44 telnetpp::command_type RemoteNegative>
48 static constexpr
auto local_positive = LocalPositive;
49 static constexpr
auto local_negative = LocalNegative;
50 static constexpr
auto remote_positive = RemotePositive;
51 static constexpr
auto remote_negative = RemoteNegative;
61 [[nodiscard]] constexpr telnetpp::option_type
option_code() const noexcept
69 [[nodiscard]] constexpr
bool active() const noexcept
71 return state_ == internal_state::active;
81 case internal_state::inactive:
82 state_ = internal_state::activating;
83 write_negotiation(local_positive);
86 case internal_state::activating:
89 case internal_state::active:
93 case internal_state::deactivating:
97 assert(!
"Unimplemented");
109 case internal_state::active:
110 state_ = internal_state::deactivating;
111 write_negotiation(local_negative);
114 case internal_state::activating:
117 case internal_state::inactive:
121 case internal_state::deactivating:
125 assert(!
"Unimplemented");
135 constexpr
void negotiate(telnetpp::negotiation_type neg)
139 case internal_state::inactive:
140 if (neg == remote_positive)
142 state_ = internal_state::active;
143 write_negotiation(local_positive);
148 write_negotiation(local_negative);
152 case internal_state::activating:
153 if (neg == remote_positive)
155 state_ = internal_state::active;
160 state_ = internal_state::inactive;
165 case internal_state::active:
166 if (neg == remote_positive)
168 write_negotiation(local_positive);
172 state_ = internal_state::inactive;
174 write_negotiation(local_negative);
178 case internal_state::deactivating:
179 if (neg == remote_positive)
181 state_ = internal_state::active;
186 state_ = internal_state::inactive;
192 assert(!
"Unimplemented");
204 if (state_ == internal_state::active)
206 handle_subnegotiation(content);
222 boost::signals2::signal<void()> on_state_changed;
230 : session_{sess}, code_{code}
239 session_.
write(content);
254 void write_negotiation(telnetpp::negotiation_type neg)
263 virtual void handle_subnegotiation(telnetpp::bytes data) = 0;
265 enum class internal_state
274 telnetpp::option_type code_;
275 internal_state state_ = internal_state::inactive;
A class that encapsulates a Telnet negotiation.
Definition: negotiation.hpp:15
An class that encapsulates one side of a Telnet option.
Definition: option.hpp:46
constexpr void subnegotiate(telnetpp::bytes content)
Subnegotiate with the option. This should be called when a subnegotiation sequence has been received ...
Definition: option.hpp:202
constexpr void negotiate(telnetpp::negotiation_type neg)
Negotiate with the option. This should be called when the remote side either initiates a negotiation ...
Definition: option.hpp:135
virtual ~option()=default
Destructor.
constexpr option(telnetpp::session &sess, telnetpp::option_type code) noexcept
Constructor.
Definition: option.hpp:228
constexpr void deactivate()
Begins the deactivation process for the option.
Definition: option.hpp:105
void write_text(telnetpp::bytes content)
Write plain text to the session.
Definition: option.hpp:237
constexpr void activate()
Begins the activation process for the option.
Definition: option.hpp:77
constexpr bool active() const noexcept
Returns whether the option is active.
Definition: option.hpp:69
void write_subnegotiation(telnetpp::bytes content)
Write a subnegotiation to the session.
Definition: option.hpp:245
constexpr telnetpp::option_type option_code() const noexcept
Returns the code for the option.
Definition: option.hpp:61
An abstraction for a Telnet session.
Definition: session.hpp:141
void write(telnetpp::element const &elem)
Sends a Telnet data element. Translates the element into a sequence of bytes, that is then sent to th...
Definition: session.cpp:96
A class that encapsulates a Telnet subnegotiation.
Definition: subnegotiation.hpp:14