![]() |
TSDuck v3.43-4441
MPEG Transport Stream Toolkit
|
Implementation of a half-duplex line oriented telnet connection. More...
#include <tsTelnetConnection.h>
Public Member Functions | |
TelnetConnection (TCPConnection &connection, const std::string &prompt=std::string()) | |
Constructor. | |
virtual | ~TelnetConnection () override |
Virtual destructor. | |
TCPConnection & | connection () |
Get a reference to the associated TCPConnection. | |
bool | debug () const |
Check if debugging is active. | |
template<class... Args> | |
void | debug (const UChar *fmt, Args &&... args) |
Report a debug message with a printf-like interface. | |
void | debug (const UChar *msg) |
Report a debug message. | |
template<class... Args> | |
void | debug (const UString &fmt, Args &&... args) |
Report a debug message with a printf-like interface. | |
void | debug (const UString &msg) |
Report a debug message. | |
Report * | delegateReport (Report *report) |
Delegate message logging to another report object. | |
template<class... Args> | |
void | error (const UChar *fmt, Args &&... args) |
Report an error message with a printf-like interface. | |
void | error (const UChar *msg) |
Report an error message. | |
template<class... Args> | |
void | error (const UString &fmt, Args &&... args) |
Report an error message with a printf-like interface. | |
void | error (const UString &msg) |
Report an error message. | |
template<class... Args> | |
void | fatal (const UChar *fmt, Args &&... args) |
Report a fatal error message with a printf-like interface. | |
void | fatal (const UChar *msg) |
Report a fatal error message. | |
template<class... Args> | |
void | fatal (const UString &fmt, Args &&... args) |
Report a fatal error message with a printf-like interface. | |
void | fatal (const UString &msg) |
Report a fatal error message. | |
void | getAndFlush (ByteBlock &data) |
Get currently buffered input data and flush that buffer. | |
bool | gotErrors () const |
Check if errors (or worse) were reported through this object. | |
template<class... Args> | |
void | info (const UChar *fmt, Args &&... args) |
Report an informational message with a printf-like interface. | |
void | info (const UChar *msg) |
Report an informational message. | |
template<class... Args> | |
void | info (const UString &fmt, Args &&... args) |
Report an informational message with a printf-like interface. | |
void | info (const UString &msg) |
Report an informational message. | |
template<class... Args> | |
void | log (int severity, const UChar *fmt, Args &&... args) |
Report a message with an explicit severity and a printf-like interface. | |
template<class... Args> | |
void | log (int severity, const UString &fmt, Args &&... args) |
Report a message with an explicit severity and a printf-like interface. | |
void | log (int severity, const UString &msg) |
Report a message with an explicit severity. | |
int | maxSeverity () const |
Get maximum severity level. | |
void | raiseMaxSeverity (int level) |
Raise maximum severity level. | |
bool | receiveLine (std::string &line, const AbortInterface *abort, Report &report) |
Receive a line. | |
bool | receiveLine (UString &line, const AbortInterface *abort, Report &report) |
Receive a line. | |
bool | receiveText (std::string &data, const AbortInterface *abort, Report &report) |
Receive character data. | |
bool | receiveText (UString &data, const AbortInterface *abort, Report &report) |
Receive character data. | |
UString | reportPrefix () const |
Get the current prefix to display. | |
bool | reset () |
Reset the internal buffer. | |
void | resetErrors () |
Reset the error indicator. | |
bool | sendLine (const std::string &str, Report &report) |
Send a text line to the server. | |
bool | sendLine (const UString &str, Report &report) |
Send a text line to the server. | |
bool | sendText (const std::string &str, Report &report) |
Send a string to the server. | |
bool | sendText (const UString &str, Report &report) |
Send a string to the server. | |
void | setMaxSeverity (int level) |
Set maximum severity level. | |
void | setReportPrefix (const UString &prefix) |
Set the prefix to display before each message. | |
template<class... Args> | |
void | severe (const UChar *fmt, Args &&... args) |
Report a severe error message with a printf-like interface. | |
void | severe (const UChar *msg) |
Report a severe error message. | |
template<class... Args> | |
void | severe (const UString &fmt, Args &&... args) |
Report a severe error message with a printf-like interface. | |
void | severe (const UString &msg) |
Report a severe error message. | |
bool | verbose () const |
Check if verbose reporting is active. | |
template<class... Args> | |
void | verbose (const UChar *fmt, Args &&... args) |
Report a verbose message with a printf-like interface. | |
void | verbose (const UChar *msg) |
Report a verbose message. | |
template<class... Args> | |
void | verbose (const UString &fmt, Args &&... args) |
Report a verbose message with a printf-like interface. | |
void | verbose (const UString &msg) |
Report a verbose message. | |
bool | waitForPrompt (const AbortInterface *abort, Report &report) |
Receive a prompt. | |
template<class... Args> | |
void | warning (const UChar *fmt, Args &&... args) |
Report a warning message with a printf-like interface. | |
void | warning (const UChar *msg) |
Report a warning error message. | |
template<class... Args> | |
void | warning (const UString &fmt, Args &&... args) |
Report a warning message with a printf-like interface. | |
void | warning (const UString &msg) |
Report a warning error message. | |
Static Public Attributes | |
static const std::string | EOL |
A telnet end-of-line sequence. | |
Protected Member Functions | |
virtual void | writeLog (int severity, const UString &msg) override |
Actual message reporting method. | |
Implementation of a half-duplex line oriented telnet connection.
This class supports the communication with a half-duplex line oriented telnet server:
From the client point of view the interface must allow:
This class is also a subclass of Report, allowing it to be used to end log messages.
ts::TelnetConnection::TelnetConnection | ( | TCPConnection & | connection, |
const std::string & | prompt = std::string() |
||
) |
Constructor.
[in,out] | connection | The underlying connection. A reference is kept in this instance. |
[in] | prompt | Prompt string to send to the client. |
|
inline |
Get a reference to the associated TCPConnection.
bool ts::TelnetConnection::reset | ( | ) |
Reset the internal buffer.
If the underlying TCPConnection is reused for several connections, reset() should be called each time a new connection is established. Otherwise, the new connection would reuse unread bytes from the previous connection.
bool ts::TelnetConnection::sendText | ( | const std::string & | str, |
Report & | report | ||
) |
Send a string to the server.
[in] | str | The string to sendText to the server. |
[in,out] | report | Where to report errors. |
Send a string to the server.
[in] | str | The string to sendText to the server. |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::sendLine | ( | const std::string & | str, |
Report & | report | ||
) |
Send a text line to the server.
[in] | str | The line to send to the server. |
[in,out] | report | Where to report errors. |
Send a text line to the server.
[in] | str | The line to send to the server. |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveText | ( | std::string & | data, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive character data.
[out] | data | The received data. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveText | ( | UString & | data, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive character data.
[out] | data | The received data. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveLine | ( | std::string & | line, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive a line.
[out] | line | The received line. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveLine | ( | UString & | line, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive a line.
[out] | line | The received line. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::waitForPrompt | ( | const AbortInterface * | abort, |
Report & | report | ||
) |
Receive a prompt.
Do not wait if the prompt is empty.
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
void ts::TelnetConnection::getAndFlush | ( | ByteBlock & | data | ) |
Get currently buffered input data and flush that buffer.
This method is useful when TCP connection switches from text mode (telnet protocol) to binary mode. The returned data are the start of the input binary data. The remaining data can be received using methods from the parent class TCPConnection.
[out] | data | Currently buffered data. |
|
overrideprotectedvirtual |
Actual message reporting method.
The method is called only when a message passed the severity filter. It is not necessary to recheck the maximum severity inside the method. By default, does nothing.
[in] | severity | Message severity. |
[in] | msg | Message text. |
Reimplemented from ts::Report.
|
inherited |
Set maximum severity level.
Messages with higher severities are not reported.
[in] | level | Set report to that level. |
|
inherited |
Raise maximum severity level.
The severity can only be increased (more verbose, more debug), never decreased.
[in] | level | Set report at least to that level. |
|
inlineinherited |
Get maximum severity level.
|
inlineinherited |
Check if errors (or worse) were reported through this object.
Errors which were reported through delegated reports are ignored.
|
inlineinherited |
Reset the error indicator.
|
inlineinherited |
Set the prefix to display before each message.
[in] | prefix | The prefix to prepend to all messages. |
|
inlineinherited |
Get the current prefix to display.
Delegate message logging to another report object.
[in] | report | New report object to which messages are delegated. Use nullptr to remove the delegation and return to normal logging. |
|
inlineinherited |
Check if debugging is active.
|
inlineinherited |
Report a debug message.
[in] | msg | Message line. |
|
inlineinherited |
Report a debug message.
[in] | msg | Message line. |
|
inlineinherited |
Report a debug message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a debug message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Check if verbose reporting is active.
|
inlineinherited |
Report a verbose message.
[in] | msg | Message line. |
|
inlineinherited |
Report a verbose message.
[in] | msg | Message line. |
|
inlineinherited |
Report a verbose message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a verbose message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inherited |
Report a message with an explicit severity.
[in] | severity | Message severity. |
[in] | msg | Message line. |
|
inlineinherited |
Report a message with an explicit severity and a printf-like interface.
[in] | severity | Message severity. |
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a message with an explicit severity and a printf-like interface.
[in] | severity | Message severity. |
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a fatal error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a fatal error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a fatal error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a fatal error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a severe error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a severe error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a severe error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a severe error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an error message.
[in] | msg | Message line. |
|
inlineinherited |
Report an error message.
[in] | msg | Message line. |
|
inlineinherited |
Report an error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a warning error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a warning error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a warning message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a warning message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an informational message.
[in] | msg | Message line. |
|
inlineinherited |
Report an informational message.
[in] | msg | Message line. |
|
inlineinherited |
Report an informational message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an informational message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |