TorService Class Reference

#include <torservice.h>

List of all members.

Signals

void started ()
void finished (int exitCode, QProcess::ExitStatus)
void startFailed (QString error)

Public Member Functions

 TorService (QObject *parent=0)
 ~TorService ()
bool isInstalled ()
bool isRunning ()
void start ()
bool stop ()
int exitCode ()
QProcess::ExitStatus exitStatus ()
bool install (const QString &torPath, const QString &torrc, quint16 controlPort)
bool remove ()

Static Public Member Functions

static bool isSupported ()
static bool loadServiceFunctions ()

Private Member Functions

SC_HANDLE openService ()
DWORD status ()

Static Private Member Functions

static SC_HANDLE openSCM ()
static void closeHandle (SC_HANDLE handle)

Private Attributes

SC_HANDLE _scm

Static Private Attributes

static ServiceFunctions _service_fns


Detailed Description

Definition at line 105 of file torservice.h.


Constructor & Destructor Documentation

TorService::TorService ( QObject *  parent = 0  ) 

Default ctor.

Definition at line 45 of file torservice.cpp.

References _scm, and openSCM().

TorService::~TorService (  ) 

Default dtor.

Definition at line 52 of file torservice.cpp.

References _scm, and closeHandle().


Member Function Documentation

bool TorService::isSupported (  )  [static]

Returns if services are supported.

Returns true if services are supported.

Definition at line 59 of file torservice.cpp.

Referenced by AdvancedPage::AdvancedPage(), loadServiceFunctions(), and TorControl::start().

bool TorService::loadServiceFunctions (  )  [static]

Dynamically loads NT service related functions from advapi32.dll.

Dyanmically loads NT service related functions from advapi32.dll. This function is adapted from Tor's nt_service_load_library() function. See LICENSE for details on Tor's license.

Definition at line 68 of file torservice.cpp.

References _service_fns, isSupported(), LOAD_SERVICE_FN, and ServiceFunctions::loaded.

Referenced by closeHandle(), openSCM(), and openService().

bool TorService::isInstalled (  ) 

Returns true if the Tor service is installed.

Definition at line 131 of file torservice.cpp.

References closeHandle(), and openService().

Referenced by AdvancedPage::load().

bool TorService::isRunning (  ) 

Returns true if the Tor service is running.

Definition at line 142 of file torservice.cpp.

References status().

void TorService::start (  ) 

Starts the Tor service. Emits started on success.

Starts Tor service.

Definition at line 149 of file torservice.cpp.

References _service_fns, closeHandle(), openService(), started(), startFailed(), ServiceFunctions::StartServiceA, status(), vNotice, and vWarn.

bool TorService::stop (  ) 

Stops the Tor service. Emits finished on success.

Stops Tor service.

Definition at line 180 of file torservice.cpp.

References _service_fns, closeHandle(), ServiceFunctions::ControlService, exitCode(), exitStatus(), finished(), openService(), status(), vNotice, and vWarn.

Referenced by remove().

int TorService::exitCode (  ) 

Returns the exit code of the last Tor service that finished.

Definition at line 215 of file torservice.cpp.

References _service_fns, closeHandle(), openService(), ServiceFunctions::QueryServiceStatus, and UNKNOWN_EXIT_CODE.

Referenced by stop().

QProcess::ExitStatus TorService::exitStatus (  ) 

Returns the exit status of the last Tor service that finished.

Definition at line 237 of file torservice.cpp.

Referenced by stop().

bool TorService::install ( const QString &  torPath,
const QString &  torrc,
quint16  controlPort 
)

Installs the Tor service.

Installs the Tor service. Returns true if the service was successfully installed or already exists.

Definition at line 251 of file torservice.cpp.

References _scm, _service_fns, ServiceFunctions::ChangeServiceConfig2A, closeHandle(), ServiceFunctions::CreateServiceA, openService(), TOR_SERVICE_ACCESS, TOR_SERVICE_DESC, TOR_SERVICE_DISP, TOR_SERVICE_NAME, vNotice, and vWarn.

bool TorService::remove (  ) 

Removes the Tor service.

Removes the Tor service. Returns true if the service was removed successfully or does not exist.

Definition at line 292 of file torservice.cpp.

References _service_fns, closeHandle(), ServiceFunctions::DeleteService, openService(), stop(), vNotice, and vWarn.

void TorService::started (  )  [signal]

Called when the service gets started.

Referenced by start().

void TorService::finished ( int  exitCode,
QProcess::ExitStatus   
) [signal]

Called when the service gets stopped.

Referenced by stop().

void TorService::startFailed ( QString  error  )  [signal]

Called when there is an error in starting the service.

Referenced by start().

SC_HANDLE TorService::openService (  )  [private]

Opens a handle to the Tor service. Returns NULL on error.

Definition at line 100 of file torservice.cpp.

References _scm, _service_fns, loadServiceFunctions(), ServiceFunctions::OpenServiceA, TOR_SERVICE_ACCESS, and TOR_SERVICE_NAME.

Referenced by exitCode(), install(), isInstalled(), remove(), start(), status(), and stop().

SC_HANDLE TorService::openSCM (  )  [static, private]

Opens a handle to the service control manager. Returns NULL on error.

Definition at line 113 of file torservice.cpp.

References _service_fns, loadServiceFunctions(), and ServiceFunctions::OpenSCManagerA.

Referenced by TorService().

void TorService::closeHandle ( SC_HANDLE  handle  )  [static, private]

Closes the service handle.

Definition at line 122 of file torservice.cpp.

References _service_fns, ServiceFunctions::CloseServiceHandle, and loadServiceFunctions().

Referenced by exitCode(), install(), isInstalled(), remove(), start(), status(), stop(), and ~TorService().

DWORD TorService::status (  )  [private]

Gets the status of the Tor service.

Definition at line 312 of file torservice.cpp.

References _service_fns, closeHandle(), openService(), ServiceFunctions::QueryServiceStatus, and SERVICE_ERROR.

Referenced by isRunning(), start(), and stop().


Member Data Documentation

SC_HANDLE TorService::_scm [private]

Handle to the service control manager.

Definition at line 157 of file torservice.h.

Referenced by install(), openService(), TorService(), and ~TorService().

ServiceFunctions TorService::_service_fns [static, private]

Initial value:

 
  { false,
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL }
List of dynamically loaded NT service functions.

Definition at line 159 of file torservice.h.

Referenced by closeHandle(), exitCode(), install(), loadServiceFunctions(), openSCM(), openService(), remove(), start(), status(), and stop().


The documentation for this class was generated from the following files:
Generated on Wed Sep 5 15:49:29 2007 for Vidalia by  doxygen 1.5.3