#include <controlsocket.h>
Public Member Functions | |
ControlSocket () | |
bool | sendCommand (ControlCommand cmd, QString *errmsg=0) |
bool | readReply (ControlReply &reply, QString *errmsg=0) |
bool | isConnected () |
Static Public Member Functions | |
static QString | toString (const QAbstractSocket::SocketError error) |
Protected Member Functions | |
void | customEvent (QEvent *event) |
bool | readLineData (QString &line, QString *errmsg=0) |
bool | readLine (QString &line, QString *errmsg=0) |
Definition at line 26 of file controlsocket.h.
ControlSocket::ControlSocket | ( | ) |
Default constructor.
Definition at line 29 of file controlsocket.cpp.
bool ControlSocket::sendCommand | ( | ControlCommand | cmd, | |
QString * | errmsg = 0 | |||
) |
Send a command to Tor
Send a control command to Tor on the control socket, conforming to Tor's Control Protocol V1:
Command = Keyword Arguments CRLF / "+" Keyword Arguments CRLF Data Keyword = 1*ALPHA Arguments = *(SP / VCHAR)
Definition at line 67 of file controlsocket.cpp.
References tc::debug(), err(), isConnected(), and ControlCommand::toString().
Referenced by customEvent().
bool ControlSocket::readReply | ( | ControlReply & | reply, | |
QString * | errmsg = 0 | |||
) |
Read a response from Tor
Read a complete reply from the control socket. Replies take the following form, based on Tor's Control Protocol v1:
Reply = *(MidReplyLine / DataReplyLine) EndReplyLine
MidReplyLine = "-" ReplyLine DataReplyLine = "+" ReplyLine Data EndReplyLine = SP ReplyLine ReplyLine = StatusCode [ SP ReplyText ] CRLF ReplyText = XXXX StatusCode = XXiX
Definition at line 138 of file controlsocket.cpp.
References ControlReply::appendLine(), err(), isConnected(), and readLine().
Referenced by ControlConnection::onReadyRead().
bool ControlSocket::isConnected | ( | ) |
Returns true if the control socket is connected and ready to send or receive.
Definition at line 36 of file controlsocket.cpp.
Referenced by readLine(), readReply(), ControlConnection::send(), and sendCommand().
QString ControlSocket::toString | ( | const QAbstractSocket::SocketError | error | ) | [static] |
Returns the string description of error.
Definition at line 187 of file controlsocket.cpp.
Referenced by ControlConnection::onError().
void ControlSocket::customEvent | ( | QEvent * | event | ) | [protected] |
Processes custom events sent to this object (e.g. SendCommandEvents) from other threads.
Processes custom events sent to this object (e.g. SendCommandEvents) from other threads.
Definition at line 44 of file controlsocket.cpp.
References SendCommandEvent::command(), sendCommand(), CustomEventType::SendCommandEvent, and SendCommandEvent::waiter().
bool ControlSocket::readLineData | ( | QString & | line, | |
QString * | errmsg = 0 | |||
) | [protected] |
Reads line data off the socket in chunks.
Reads line data, one chunk at a time, until a newline character is encountered.
Definition at line 89 of file controlsocket.cpp.
References err().
Referenced by readLine().
bool ControlSocket::readLine | ( | QString & | line, | |
QString * | errmsg = 0 | |||
) | [protected] |
Reads a line of data from the socket (blocking)
Reads a line of data from the socket and returns true if successful or false if an error occurred while waiting for a line of data to become available.
Definition at line 110 of file controlsocket.cpp.
References err(), isConnected(), READ_TIMEOUT, and readLineData().
Referenced by readReply().