Vidalia
0.2.21
|
#include <ControlSocket.h>
Signals | |
void | readyRead () |
void | disconnected () |
void | connected () |
void | error (QAbstractSocket::SocketError) |
Public Member Functions | |
ControlSocket (ControlMethod::Method method=ControlMethod::Port) | |
bool | sendCommand (ControlCommand cmd, QString *errmsg=0) |
bool | readReply (ControlReply &reply, QString *errmsg=0) |
bool | isConnected () |
bool | canReadLine () |
void | connectToHost (const QHostAddress &address, quint16 port) |
void | disconnectFromHost () |
void | connectToServer (const QString &name) |
void | disconnectFromServer () |
ControlMethod::Method | getMethod () |
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) |
Private Attributes | |
QTcpSocket * | _tcpSocket |
QLocalSocket * | _localSocket |
QIODevice * | _socket |
ControlMethod::Method | _method |
Definition at line 27 of file ControlSocket.h.
ControlSocket::ControlSocket | ( | ControlMethod::Method | method = ControlMethod::Port | ) |
Default constructor.
Definition at line 28 of file ControlSocket.cpp.
References _localSocket, _method, _socket, _tcpSocket, connected(), disconnected(), error(), ControlMethod::Port, readyRead(), and ControlMethod::Socket.
bool ControlSocket::canReadLine | ( | ) |
Interface to each socket's canReadLine implementation
Interface to QTcpSocket::canReadLine
Definition at line 97 of file ControlSocket.cpp.
References _socket.
Referenced by ControlConnection::onReadyRead().
|
signal |
Referenced by ControlSocket().
void ControlSocket::connectToHost | ( | const QHostAddress & | address, |
quint16 | port | ||
) |
Connects to address:port
Definition at line 69 of file ControlSocket.cpp.
References _tcpSocket.
Referenced by ControlConnection::connect().
void ControlSocket::connectToServer | ( | const QString & | name | ) |
Connects to a unix socket file
Definition at line 83 of file ControlSocket.cpp.
References _localSocket.
Referenced by ControlConnection::connect().
|
protected |
Processes custom events sent to this object (e.g. SendCommandEvents) from other threads.
Definition at line 139 of file ControlSocket.cpp.
References SendCommandEvent::command(), sendCommand(), SendCommandEvent::SendWaiter::setResult(), and SendCommandEvent::waiter().
|
signal |
Referenced by ControlSocket().
void ControlSocket::disconnectFromHost | ( | ) |
Disconnects from host
Definition at line 76 of file ControlSocket.cpp.
References _tcpSocket.
Referenced by ControlConnection::disconnect().
void ControlSocket::disconnectFromServer | ( | ) |
Disconnects from the socket
Definition at line 90 of file ControlSocket.cpp.
References _localSocket.
Referenced by ControlConnection::disconnect().
|
signal |
Referenced by ControlSocket().
|
inline |
Definition at line 54 of file ControlSocket.h.
References _method.
bool ControlSocket::isConnected | ( | ) |
Returns true if the control socket is connected and ready to send or receive.
Definition at line 53 of file ControlSocket.cpp.
References _localSocket, _method, _tcpSocket, ControlMethod::Port, and ControlMethod::Socket.
Referenced by readLine(), readReply(), ControlConnection::send(), and sendCommand().
|
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 274 of file ControlSocket.cpp.
References _socket, err(), isConnected(), READ_TIMEOUT, and readLineData().
Referenced by readReply().
|
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 253 of file ControlSocket.cpp.
References _socket, and err().
Referenced by readLine().
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 203 of file ControlSocket.cpp.
References ReplyLine::appendData(), ControlReply::appendLine(), err(), isConnected(), and readLine().
Referenced by ControlConnection::onReadyRead().
|
signal |
Interface to the signals from each socket used
Referenced by ControlSocket().
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 162 of file ControlSocket.cpp.
References _localSocket, _method, _socket, _tcpSocket, tc::DebugMessage::arg(), tc::debug(), err(), isConnected(), ControlMethod::Port, ControlMethod::Socket, and ControlCommand::toString().
Referenced by customEvent().
|
static |
Returns the string description of error.
Definition at line 104 of file ControlSocket.cpp.
Referenced by ControlConnection::onError().
|
private |
Socket used in the connection
Definition at line 77 of file ControlSocket.h.
Referenced by connectToServer(), ControlSocket(), disconnectFromServer(), isConnected(), and sendCommand().
|
private |
Definition at line 79 of file ControlSocket.h.
Referenced by ControlSocket(), getMethod(), isConnected(), and sendCommand().
|
private |
Abstract pointer to transparently use both sockets
Definition at line 78 of file ControlSocket.h.
Referenced by canReadLine(), ControlSocket(), readLine(), readLineData(), and sendCommand().
|
private |
Socket used in the connection
Definition at line 76 of file ControlSocket.h.
Referenced by connectToHost(), ControlSocket(), disconnectFromHost(), isConnected(), and sendCommand().