~jackweirdy/vidalia/680192

« back to all changes in this revision

Viewing changes to src/torcontrol/ControlSocket.cpp

  • Committer: Package Import Robot
  • Author(s): Ulises Vitulli, intrigeri, Ulises Vitulli
  • Date: 2012-06-22 07:18:44 UTC
  • mfrom: (1.4.8) (8.2.13 sid)
  • Revision ID: package-import@ubuntu.com-20120622071844-s278v0p646pqt949
Tags: 0.2.19-1
[ intrigeri ]
* Imported Upstream version 0.2.19
* Install AppArmor profile.
* Enable hardening flags.

[ Ulises Vitulli ]
* Added runtime dependency on apparmor.
* Updated d/NEWS and d/README.Debian to reflect new features.
* Move dirs from d/rules to d/vidalia.dir.
* Updated Standard-version to 3.9.3 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
**  This file is part of Vidalia, and is subject to the license terms in the
3
 
**  LICENSE file, found in the top level directory of this distribution. If 
 
3
**  LICENSE file, found in the top level directory of this distribution. If
4
4
**  you did not receive the LICENSE file with this file, you may obtain it
5
5
**  from the Vidalia source package distributed by the Vidalia Project at
6
 
**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
7
 
**  including this file, may be copied, modified, propagated, or distributed 
 
6
**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
 
7
**  including this file, may be copied, modified, propagated, or distributed
8
8
**  except according to the terms described in the LICENSE file.
9
9
*/
10
10
 
34
34
    case ControlMethod::Port:
35
35
      _socket = _tcpSocket;
36
36
      break;
37
 
      
 
37
 
38
38
    case ControlMethod::Socket:
39
39
      _socket = _localSocket;
40
40
      break;
43
43
  QObject::connect(_socket, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
44
44
  QObject::connect(_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
45
45
  QObject::connect(_socket, SIGNAL(connected()), this, SIGNAL(connected()));
46
 
  QObject::connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), 
 
46
  QObject::connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)),
47
47
                   this, SIGNAL(error(QAbstractSocket::SocketError)));
48
48
}
49
49
 
56
56
    case ControlMethod::Port:
57
57
      return (_tcpSocket->isValid() && _tcpSocket->state() == QAbstractSocket::ConnectedState);
58
58
      break;
59
 
      
 
59
 
60
60
    default:
61
61
    case ControlMethod::Socket:
62
62
      return (_localSocket->isValid() && _localSocket->state() == QLocalSocket::ConnectedState);
65
65
}
66
66
 
67
67
/** Connects to address:port */
68
 
void 
 
68
void
69
69
ControlSocket::connectToHost(const QHostAddress &address, quint16 port)
70
70
{
71
71
  _tcpSocket->connectToHost(address, port);
72
72
}
73
73
 
74
74
/** Disconnects from host */
75
 
void 
 
75
void
76
76
ControlSocket::disconnectFromHost()
77
77
{
78
78
  _tcpSocket->disconnectFromHost();
79
79
}
80
80
 
81
81
/** Connects to a unix socket file */
82
 
void 
 
82
void
83
83
ControlSocket::connectToServer(const QString &name)
84
84
{
85
85
  _localSocket->connectToServer(name);
86
86
}
87
87
 
88
88
/** Disconnects from the socket */
89
 
void 
 
89
void
90
90
ControlSocket::disconnectFromServer()
91
91
{
92
92
  _localSocket->disconnectFromServer();
160
160
 */
161
161
bool
162
162
ControlSocket::sendCommand(ControlCommand cmd, QString *errmsg)
163
 
{  
 
163
{
164
164
  if (!isConnected()) {
165
165
    return err(errmsg, tr("Control socket is not connected."));
166
166
  }
167
 
  
 
167
 
168
168
  /* Format the control command */
169
169
  QString strCmd = cmd.toString();
170
170
  tc::debug("Control Command: %1").arg(strCmd.trimmed());
178
178
    case ControlMethod::Port:
179
179
      _tcpSocket->flush();
180
180
      break;
181
 
      
 
181
 
182
182
    case ControlMethod::Socket:
183
183
      _localSocket->flush();
184
184
      break;
216
216
    if (!readLine(line, errmsg)) {
217
217
      return false;
218
218
    }
219
 
    
 
219
 
220
220
    if (line.length() < 4) {
221
221
      return err(errmsg, tr("Invalid control reply. [%1]").arg(line));
222
222
    }