23 #define UNKNOWN_EXIT_CODE -999999 28 NULL, NULL, NULL, NULL, NULL,
29 NULL, NULL, NULL, NULL, NULL
50 return (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based);
59 #define LOAD_SERVICE_FN(f) do { \ 61 if (!((fn = QLibrary::resolve("advapi32", #f)))) { \ 64 _service_fns.f = (f ## _fn) fn; \ 123 installed = (service != NULL);
132 return (
status() == SERVICE_RUNNING);
142 tc::error(
"Bug: We tried to start the Tor service, but it is not installed.");
143 emit
startFailed(tr(
"The Tor service is not installed."));
148 if (
status() != SERVICE_RUNNING) {
153 while ((
status() != SERVICE_RUNNING) && ++tries <= 5)
157 if (
status() == SERVICE_RUNNING) {
160 tc::error(
"Unable to start the Tor service.");
161 emit
startFailed(tr(
"Unable to start the Tor service."));
175 if (
status() != SERVICE_STOPPED) {
177 stat.dwCurrentState = SERVICE_RUNNING;
185 while ((
status() != SERVICE_STOPPED) && (++tries <= 5))
192 if (
status() == SERVICE_STOPPED) {
197 tc::error(
"Unable to stop the Tor service.");
214 exitCode = (int)(s.dwWin32ExitCode == ERROR_SERVICE_SPECIFIC_ERROR
215 ? s.dwServiceSpecificExitCode
216 : s.dwWin32ExitCode);
233 return QProcess::NormalExit;
249 QString command = QString(
"\"%1\" --nt-service -f \"%2\" ControlPort %3")
254 tc::debug(
"Installing the Tor service using the command line '%1'")
259 SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
260 (LPCTSTR)command.toAscii().data(), NULL, NULL, NULL,
264 tc::error(
"Failed to install the Tor service.");
268 SERVICE_DESCRIPTION desc;
271 SERVICE_CONFIG_DESCRIPTION, &desc);
293 tc::error(
"Failed to remove the Tor service.");
308 stat = s.dwCurrentState;
DebugMessage error(const QString &fmt)
DeleteService_fn DeleteService
bool install(const QString &torPath, const QString &torrc, quint16 controlPort)
static void closeHandle(SC_HANDLE handle)
static ServiceFunctions _service_fns
#define UNKNOWN_EXIT_CODE
DebugMessage arg(const QString &a)
ChangeServiceConfig2A_fn ChangeServiceConfig2A
QProcess::ExitStatus exitStatus()
#define TOR_SERVICE_ACCESS
void startFailed(QString error)
static bool isSupported()
QueryServiceStatus_fn QueryServiceStatus
static bool loadServiceFunctions()
void finished(int exitCode, QProcess::ExitStatus)
#define LOAD_SERVICE_FN(f)
OpenSCManagerA_fn OpenSCManagerA
TorService(QObject *parent=0)
static SC_HANDLE openSCM()
ControlService_fn ControlService
DebugMessage debug(const QString &fmt)
CreateServiceA_fn CreateServiceA
OpenServiceA_fn OpenServiceA
StartServiceA_fn StartServiceA
CloseServiceHandle_fn CloseServiceHandle