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