Vidalia 0.3.1
Signals | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TorService Class Reference

#include <TorService.h>

Inheritance diagram for TorService:

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 93 of file TorService.h.

Constructor & Destructor Documentation

◆ TorService()

TorService::TorService ( QObject *  parent = 0)

Default ctor.

Definition at line 34 of file TorService.cpp.

References _scm, and openSCM().

◆ ~TorService()

TorService::~TorService ( )

Default dtor.

Definition at line 41 of file TorService.cpp.

References _scm, and closeHandle().

Member Function Documentation

◆ closeHandle()

void TorService::closeHandle ( SC_HANDLE  handle)
staticprivate

Closes the service handle.

Definition at line 110 of file TorService.cpp.

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

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

◆ exitCode()

int TorService::exitCode ( )

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

Definition at line 203 of file TorService.cpp.

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

Referenced by exitCode(), and stop().

◆ exitStatus()

QProcess::ExitStatus TorService::exitStatus ( )

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

Definition at line 225 of file TorService.cpp.

Referenced by stop().

◆ finished

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

Called when the service gets stopped.

Referenced by stop().

◆ install()

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 239 of file TorService.cpp.

References _scm, _service_fns, tc::DebugMessage::arg(), ServiceFunctions::ChangeServiceConfig2A, closeHandle(), ServiceFunctions::CreateServiceA, tc::debug(), tc::error(), openService(), TOR_SERVICE_ACCESS, TOR_SERVICE_DESC, TOR_SERVICE_DISP, and TOR_SERVICE_NAME.

◆ isInstalled()

bool TorService::isInstalled ( )

Returns true if the Tor service is installed.

Definition at line 119 of file TorService.cpp.

References closeHandle(), and openService().

Referenced by AdvancedPage::load().

◆ isRunning()

bool TorService::isRunning ( )

Returns true if the Tor service is running.

Definition at line 130 of file TorService.cpp.

References status().

◆ isSupported()

bool TorService::isSupported ( )
static

Returns if services are supported.

Returns true if services are supported.

Definition at line 48 of file TorService.cpp.

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

◆ loadServiceFunctions()

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 57 of file TorService.cpp.

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

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

◆ openSCM()

SC_HANDLE TorService::openSCM ( )
staticprivate

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

Definition at line 101 of file TorService.cpp.

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

Referenced by TorService().

◆ openService()

SC_HANDLE TorService::openService ( )
private

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

Definition at line 88 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().

◆ remove()

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 280 of file TorService.cpp.

References _service_fns, closeHandle(), tc::debug(), ServiceFunctions::DeleteService, tc::error(), openService(), and stop().

◆ start()

void TorService::start ( )

Starts the Tor service. Emits started on success.

Starts Tor service.

Definition at line 137 of file TorService.cpp.

References _service_fns, closeHandle(), tc::debug(), tc::error(), openService(), started(), startFailed(), ServiceFunctions::StartServiceA, and status().

◆ started

void TorService::started ( )
signal

Called when the service gets started.

Referenced by start().

◆ startFailed

void TorService::startFailed ( QString  error)
signal

Called when there is an error in starting the service.

Referenced by start().

◆ status()

DWORD TorService::status ( )
private

Gets the status of the Tor service.

Definition at line 300 of file TorService.cpp.

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

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

◆ stop()

bool TorService::stop ( )

Stops the Tor service. Emits finished on success.

Stops Tor service.

Definition at line 168 of file TorService.cpp.

References _service_fns, closeHandle(), ServiceFunctions::ControlService, tc::debug(), tc::error(), exitCode(), exitStatus(), finished(), openService(), and status().

Referenced by remove().

Member Data Documentation

◆ _scm

SC_HANDLE TorService::_scm
private

Handle to the service control manager.

Definition at line 145 of file TorService.h.

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

◆ _service_fns

ServiceFunctions TorService::_service_fns
staticprivate
Initial value:
=
{ false,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
}

List of dynamically loaded NT service functions.

Definition at line 147 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: