Vidalia 0.2.15
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes
ControlSocket Class Reference

#include <ControlSocket.h>

List of all members.

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

Detailed Description

Definition at line 27 of file ControlSocket.h.


Constructor & Destructor Documentation

ControlSocket::ControlSocket ( ControlMethod::Method  method = ControlMethod::Port)

Member Function Documentation

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().

void ControlSocket::connected ( ) [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().

void ControlSocket::customEvent ( QEvent *  event) [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(), and SendCommandEvent::waiter().

void ControlSocket::disconnected ( ) [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().

void ControlSocket::error ( QAbstractSocket::SocketError  ) [signal]

Referenced by ControlSocket().

ControlMethod::Method ControlSocket::getMethod ( ) [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().

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 274 of file ControlSocket.cpp.

References _socket, err(), isConnected(), READ_TIMEOUT, and readLineData().

Referenced by readReply().

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 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().

void ControlSocket::readyRead ( ) [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::debug(), err(), isConnected(), ControlMethod::Port, ControlMethod::Socket, and ControlCommand::toString().

Referenced by customEvent().

QString ControlSocket::toString ( const QAbstractSocket::SocketError  error) [static]

Returns the string description of error.

Definition at line 104 of file ControlSocket.cpp.

Referenced by ControlConnection::onError().


Member Data Documentation

QLocalSocket* ControlSocket::_localSocket [private]

Socket used in the connection

Definition at line 77 of file ControlSocket.h.

Referenced by connectToServer(), ControlSocket(), disconnectFromServer(), isConnected(), and sendCommand().

Definition at line 79 of file ControlSocket.h.

Referenced by ControlSocket(), getMethod(), isConnected(), and sendCommand().

QIODevice* ControlSocket::_socket [private]

Abstract pointer to transparently use both sockets

Definition at line 78 of file ControlSocket.h.

Referenced by canReadLine(), ControlSocket(), readLine(), readLineData(), and sendCommand().

QTcpSocket* ControlSocket::_tcpSocket [private]

Socket used in the connection

Definition at line 76 of file ControlSocket.h.

Referenced by connectToHost(), ControlSocket(), disconnectFromHost(), isConnected(), and sendCommand().


The documentation for this class was generated from the following files: