Changeset 78

Show
Ignore:
Timestamp:
01/12/06 20:02:07 (3 years ago)
Author:
edmanm
Message:

Add support for the SIGNAL keyword;
Fix two potential segfaults.

Location:
trunk/src/control
Files:
2 modified

Legend:

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

    r77 r78  
    138138  if (_controlConn.send(cmd, reply, errmsg)) { 
    139139    ReplyLine line = reply.getLine(); 
    140     if (line.getStatus() == "250") { 
    141       return true; 
     140    if (line.getStatus() != "250") { 
     141      if (errmsg) { 
     142        *errmsg = line.getMessage(); 
     143      } 
     144      return false; 
    142145    } 
    143146  } 
    144   return false; 
     147  return true; 
    145148} 
    146149 
     
    167170    foreach (ReplyLine line, reply.getLines()) { 
    168171      if (line.getStatus() != "250") { 
    169         *errmsg = line.getMessage(); 
     172        if (errmsg) { 
     173          *errmsg = line.getMessage(); 
     174        } 
    170175        return false; 
    171176      } 
     
    194199} 
    195200 
     201/** Sends a signal to Tor */ 
     202bool 
     203TorControl::signal(Signal sig, QString *errmsg) 
     204{ 
     205  ControlCommand cmd("SIGNAL"); 
     206  ControlReply reply; 
     207  QString sigtype; 
     208   
     209  /* Convert the signal to the correct string */ 
     210  switch (sig) { 
     211    case Reload:   sigtype = "RELOAD"; break; 
     212    case Shutdown: sigtype = "SHUTDOWN"; break; 
     213    case Dump:     sigtype = "DUMP"; break; 
     214    case Debug:    sigtype = "DEBUG"; break; 
     215    case Halt:     sigtype = "HALT"; break; 
     216    default: return false; break; 
     217  } 
     218   
     219  /* Send and check the response */ 
     220  if (_controlConn.send(cmd, reply, errmsg)) { 
     221    ReplyLine line = reply.getLine(); 
     222    if (line.getStatus() != "250") { 
     223      if (errmsg) { 
     224        *errmsg = line.getMessage(); 
     225      } 
     226      return false; 
     227    } 
     228  } 
     229  return true; 
     230} 
     231 
    196232/** Ask Tor for its version */ 
    197233QString 
  • trunk/src/control/torcontrol.h

    r77 r78  
    3636   
    3737public: 
     38  /** Signals that can be sent by the controller */ 
     39  enum Signal { 
     40    Reload, 
     41    Shutdown, 
     42    Dump, 
     43    Debug, 
     44    Halt 
     45  }; 
     46   
    3847  /** Default constructor */ 
    3948  TorControl(); 
     
    6978  bool getInfo(QString key, QString &val, QString *errmsg = 0); 
    7079 
     80  /** Sends a signal to Tor */ 
     81  bool signal(Signal sig, QString *errmsg = 0); 
     82   
    7183  /** Ask Tor for its version */ 
    7284  QString getTorVersion(QString *errmsg = 0);