torservice.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file torservice.h
00024  * \version $Id: torservice.h 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Starts, stops, installs, and uninstalls a Tor service (Win32).
00026  */
00027 
00028 #ifndef _TORSERVICE_H
00029 #define _TORSERVICE_H
00030 
00031 #include <QObject>
00032 
00033 #if defined(Q_OS_WIN32)
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 #else
00042   typedef void* SC_HANDLE; /** Make SC_HANDLE a void* on non-Windows. */
00043   typedef quint64 DWORD; /** DWORD only exists on Windows, so redefine it. */
00044 #endif
00045 
00046 
00047 class TorService : public QObject
00048 {
00049   Q_OBJECT
00050 
00051 public:
00052   /* Returns if services are supported. */
00053   static bool isSupported();
00054 
00055   /** Default ctor. */
00056   TorService(const QString &torPath,  const QString &torrc, QObject* parent = 0);
00057   /** Default dtor. */
00058   ~TorService();
00059 
00060   /** Returns true if the Tor service is installed. */
00061   bool isInstalled();
00062   /** Returns true if the Tor service is running. */
00063   bool isRunning();
00064   /** Starts the Tor service. Emits started on success. */
00065   void start();
00066   /** Stops the Tor service. Emits finished on success. */
00067   void stop();
00068   /** Installs the Tor service. */
00069   bool install();
00070   /** Removes the Tor service. */
00071   bool remove();
00072 
00073 signals:
00074   /** Called when the service gets started. */
00075   void started();
00076   /** Called when the service gets stopped. */
00077   void finished();
00078   /** Called when there is an error in starting the service. */
00079   void startFailed(QString error);
00080 
00081 private:
00082   /** Closes the service and the service manager. */
00083   void close();
00084   /** Initializes the service and the service manager. */
00085   void initialize();
00086   
00087   /** Path to the tor executable. */
00088   QString _torPath;
00089   /** Path to the torrc. */
00090   QString _torrc;
00091 
00092   DWORD status(); /** Gets the status of the Tor service. */
00093   SC_HANDLE _manager; /** Handle to a service manager object. */
00094   SC_HANDLE _service; /** Handle to the Tor service object. */
00095 };
00096 
00097 #endif
00098 

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0