TorService.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _TORSERVICE_H
00018 #define _TORSERVICE_H
00019
00020 #include <QObject>
00021 #include <QProcess>
00022
00023 #include <windows.h>
00024 #define TOR_SERVICE_NAME "tor"
00025 #define TOR_SERVICE_DISP "Tor Win32 Service"
00026 #define TOR_SERVICE_DESC \
00027 TEXT("Provides an anonymous Internet communication system.")
00028 #define TOR_SERVICE_ACCESS SERVICE_ALL_ACCESS
00029 #define SERVICE_ERROR 8
00030
00031
00032
00033
00034 typedef BOOL (WINAPI *ChangeServiceConfig2A_fn)(
00035 SC_HANDLE hService,
00036 DWORD dwInfoLevel,
00037 LPVOID lpInfo);
00038 typedef BOOL (WINAPI *CloseServiceHandle_fn)(
00039 SC_HANDLE hSCObject);
00040 typedef BOOL (WINAPI *ControlService_fn)(
00041 SC_HANDLE hService,
00042 DWORD dwControl,
00043 LPSERVICE_STATUS lpServiceStatus);
00044 typedef SC_HANDLE (WINAPI *CreateServiceA_fn)(
00045 SC_HANDLE hSCManager,
00046 LPCTSTR lpServiceName,
00047 LPCTSTR lpDisplayName,
00048 DWORD dwDesiredAccess,
00049 DWORD dwServiceType,
00050 DWORD dwStartType,
00051 DWORD dwErrorControl,
00052 LPCTSTR lpBinaryPathName,
00053 LPCTSTR lpLoadOrderGroup,
00054 LPDWORD lpdwTagId,
00055 LPCTSTR lpDependencies,
00056 LPCTSTR lpServiceStartName,
00057 LPCTSTR lpPassword);
00058 typedef BOOL (WINAPI *DeleteService_fn)(
00059 SC_HANDLE hService);
00060 typedef SC_HANDLE (WINAPI *OpenSCManagerA_fn)(
00061 LPCTSTR lpMachineName,
00062 LPCTSTR lpDatabaseName,
00063 DWORD dwDesiredAccess);
00064 typedef SC_HANDLE (WINAPI *OpenServiceA_fn)(
00065 SC_HANDLE hSCManager,
00066 LPCTSTR lpServiceName,
00067 DWORD dwDesiredAccess);
00068 typedef BOOL (WINAPI *QueryServiceStatus_fn)(
00069 SC_HANDLE hService,
00070 LPSERVICE_STATUS lpServiceStatus);
00071 typedef BOOL (WINAPI *SetServiceStatus_fn)(SERVICE_STATUS_HANDLE,
00072 LPSERVICE_STATUS);
00073 typedef BOOL (WINAPI *StartServiceA_fn)(
00074 SC_HANDLE hService,
00075 DWORD dwNumServiceArgs,
00076 LPCTSTR* lpServiceArgVectors);
00077
00078
00079 struct ServiceFunctions {
00080 bool loaded;
00081 ChangeServiceConfig2A_fn ChangeServiceConfig2A;
00082 CloseServiceHandle_fn CloseServiceHandle;
00083 ControlService_fn ControlService;
00084 CreateServiceA_fn CreateServiceA;
00085 DeleteService_fn DeleteService;
00086 OpenSCManagerA_fn OpenSCManagerA;
00087 OpenServiceA_fn OpenServiceA;
00088 QueryServiceStatus_fn QueryServiceStatus;
00089 SetServiceStatus_fn SetServiceStatus;
00090 StartServiceA_fn StartServiceA;
00091 };
00092
00093
00094 class TorService : public QObject
00095 {
00096 Q_OBJECT
00097
00098 public:
00099
00100 static bool isSupported();
00101
00102 static bool loadServiceFunctions();
00103
00104
00105 TorService(QObject* parent = 0);
00106
00107 ~TorService();
00108
00109
00110 bool isInstalled();
00111
00112 bool isRunning();
00113
00114 void start();
00115
00116 bool stop();
00117
00118 int exitCode();
00119
00120 QProcess::ExitStatus exitStatus();
00121
00122 bool install(const QString &torPath, const QString &torrc,
00123 quint16 controlPort);
00124
00125 bool remove();
00126
00127 signals:
00128
00129 void started();
00130
00131 void finished(int exitCode, QProcess::ExitStatus);
00132
00133 void startFailed(QString error);
00134
00135 private:
00136
00137 SC_HANDLE openService();
00138
00139 static SC_HANDLE openSCM();
00140
00141 static void closeHandle(SC_HANDLE handle);
00142
00143 DWORD status();
00144
00145
00146 SC_HANDLE _scm;
00147
00148 static ServiceFunctions _service_fns;
00149 };
00150
00151 #endif
00152