Changeset 84

Show
Ignore:
Timestamp:
01/13/06 23:32:35 (3 years ago)
Author:
edmanm
Message:

Use QAbstractSocket's isValid() method to determine if the control socket is
connected;
Check if the socket is ready for reading and writing before sending or
receiving;
Update the control test code for the method names I changed back in revision
75;
The authenticate() method in TorControl? will handle loading controller
authentication tokens itself, once it's implemented. (maybe)

Location:
trunk/src/control
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/control/controlconnection.cpp

    r61 r84  
    5757{ 
    5858  disconnectFromHost(); 
    59   if (!waitForDisconnected(-1)) { 
    60     if (errmsg) { 
    61       *errmsg = 
    62         QString("Error disconnecting socket. [%1]").arg(errorString()); 
     59  if (state() != QAbstractSocket::UnconnectedState) { 
     60    if (!waitForDisconnected(-1)) { 
     61      if (errmsg) { 
     62        *errmsg = 
     63          QString("Error disconnecting socket. [%1]").arg(errorString()); 
     64      } 
     65      return false; 
    6366    } 
    64     return false; 
    6567  } 
    6668  return true; 
     
    7779ControlConnection::sendCommand(ControlCommand cmd, QString *errmsg) 
    7880{ 
     81  if (!isValid()) { 
     82    return false; 
     83  } 
     84   
    7985  /* Format the control command */ 
    8086  QString strCmd = cmd.toString(); 
     
    109115  QChar c; 
    110116  QString line; 
     117 
     118  if (!isValid()) { 
     119    return false; 
     120  } 
    111121 
    112122  /* The implementation below is based on the Java control library from Tor */ 
  • trunk/src/control/test/control_test.cpp

    r72 r84  
    3838   
    3939  /* Start Tor */ 
    40   if (!control.startTor(&errmsg)) { 
     40  if (!control.start(&errmsg)) { 
    4141    qDebug() << "Could not start Tor:" << errmsg; 
    4242    return -1; 
     
    4848  if (!control.connect(&errmsg)) { 
    4949    qDebug() << "Could not connect to Tor:" << errmsg; 
    50     control.stopTor(); 
     50    control.stop(); 
    5151    return -1; 
    5252  } else { 
     
    5555 
    5656  /* Authenticate */ 
    57   if (control.authenticate(QByteArray(), &errmsg)) { 
     57  if (control.authenticate(&errmsg)) { 
    5858    qDebug() << "Authentication Successful..."; 
    5959     
     
    7171  /* Disconnect the control socket and stop Tor */ 
    7272  control.disconnect(); 
    73   control.stopTor(); 
     73  control.stop(); 
    7474   
    7575  return 0; 
  • trunk/src/control/torcontrol.cpp

    r83 r84  
    122122TorControl::isConnected() 
    123123{ 
    124   return (_controlConn.state() == QAbstractSocket::ConnectedState); 
     124  return _controlConn.isValid(); 
    125125} 
    126126 
     
    131131 */ 
    132132bool 
    133 TorControl::authenticate(QByteArray token, QString *errmsg) 
    134 { 
    135   ControlCommand cmd("AUTHENTICATE", QString(token)); 
     133TorControl::authenticate(QString *errmsg) 
     134{ 
     135  VidaliaSettings settings; 
     136  ControlCommand cmd("AUTHENTICATE", QString(settings.getAuthToken())); 
    136137  ControlReply reply; 
    137138 
     
    182183      } 
    183184    } 
     185  } else { 
     186    /* Sending the control command failed */ 
     187    return false; 
    184188  } 
    185189  return true; 
     
    195199  if (getInfo(map, errmsg)) { 
    196200    val = map.value(key); 
     201    return true; 
    197202  } 
    198203  return false; 
  • trunk/src/control/torcontrol.h

    r83 r84  
    7070 
    7171  /** Sends an authentication token to Tor */ 
    72   bool authenticate(QByteArray token, QString *errmsg = 0); 
     72  bool authenticate(QString *errmsg = 0); 
    7373 
    7474  /** Sends a GETINFO message to Tor based on the given keys */