servicesettings.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 #include <stringutil.h>
00012 #include "servicesettings.h"
00013 #include "torsettings.h"
00014 
00015 /* Service Settings */
00016 #define SETTING_SERVICE_VIRTUAL_PORT "Service/VirtualPort"
00017 #define SETTING_SERVICE_ADDRESS "Service/ServiceAddress"
00018 #define SETTING_SERVICE_PHYSICAL_ADDRESS "Service/ServicePhysicalAddress"
00019 #define SETTING_SERVICE_ENABLED "Service/Enabled"
00020 #define SETTING_TOR_SERVICES "Service/Services"
00021 
00022 /** Constructor.
00023  * \param torControl a TorControl object used to read and apply the Service
00024  * configuration settings.
00025  */
00026 ServiceSettings::ServiceSettings(TorControl *torControl)
00027 {
00028   _torControl = torControl;
00029   setDefault(SETTING_SERVICE_VIRTUAL_PORT , 0);
00030   setDefault(SETTING_SERVICE_PHYSICAL_ADDRESS, "127.0.0.1:0");
00031   setDefault(SETTING_SERVICE_ENABLED, "true");
00032 }
00033 
00034 /** Set ServiceList to serialise it */
00035 void
00036 ServiceSettings::setServices(ServiceList service)
00037 {
00038   QStringList serviceList;
00039   if(service.services().size() > 0) {
00040     QList<Service> services = service.services();
00041     foreach (Service tempService, services) {
00042       serviceList << tempService.toString();
00043     }
00044   }
00045   setValue(SETTING_TOR_SERVICES, serviceList);
00046 }
00047 
00048 /** Get  serialised ServiceList */
00049 ServiceList
00050 ServiceSettings::getServices()
00051 {
00052   QString address,virtualPort,physAddrPort,serviceDir,enabledS,additionalData;
00053   bool enabled = false;
00054   QStringList stringList;
00055   ServiceList services;
00056 
00057   stringList = value(SETTING_TOR_SERVICES).toStringList();
00058   foreach (QString s, stringList) {
00059     QStringList skippedList = s.split("#");
00060     address = skippedList.first();
00061     skippedList.removeFirst();
00062     virtualPort = skippedList.first();
00063     skippedList.removeFirst();
00064     physAddrPort = skippedList.first();
00065     skippedList.removeFirst();
00066     serviceDir = skippedList.first();
00067     skippedList.removeFirst();
00068     enabledS = skippedList.first();
00069     skippedList.removeFirst();
00070     additionalData = skippedList.first();
00071     if(enabledS.compare("x1") == 0) {
00072       enabled = true;
00073     }
00074     Service service(address, virtualPort, physAddrPort, serviceDir, enabled);
00075     service.setAdditionalServiceOptions(additionalData);
00076     services.addService(service);
00077   }
00078   return services;
00079 }
00080 
00081 /** Returns the virtual port for a specific service*/
00082 QString
00083 ServiceSettings::getVirtualPort()
00084 {
00085   QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString();
00086   return port;
00087 }
00088 
00089 /** Set the virtual port for a specific service*/
00090 void
00091 ServiceSettings::setVirtualPort(QString servicePort)
00092 {
00093   setValue(SETTING_SERVICE_VIRTUAL_PORT, servicePort);
00094 }
00095 
00096 /** Returns the .onion - service address for a specific service */
00097 QString
00098 ServiceSettings::getServiceAddress()
00099 {
00100   QString addr = value(SETTING_SERVICE_ADDRESS).toString();
00101   return addr;
00102 }
00103 
00104 /** Set the .onion - service address or hostname for a specific service */
00105 void
00106 ServiceSettings::setServiceAddress(QString addr)
00107 {
00108   setValue(SETTING_SERVICE_ADDRESS, addr);
00109 }
00110 
00111 /** Returns the physical address for a specific service */
00112 QString
00113 ServiceSettings::getPhysicalAddressPort()
00114 {
00115   QString addr = value(SETTING_SERVICE_PHYSICAL_ADDRESS).toString();
00116   return addr;
00117 }
00118 
00119 /** Set the physical address or hostname for a specific service */
00120 void
00121 ServiceSettings::setPhysicalAddressPort(QString addr)
00122 {
00123   setValue(SETTING_SERVICE_PHYSICAL_ADDRESS, addr);
00124 }
00125 
00126 /** Returns if the Service is enabled */
00127 bool
00128 ServiceSettings::isEnabled()
00129 {
00130   return value(SETTING_SERVICE_ENABLED).toBool();
00131 }
00132 
00133 /** Set the service enabled */
00134 void
00135 ServiceSettings::setEnabled(bool boolean)
00136 {
00137   setValue(SETTING_SERVICE_ENABLED, boolean);
00138 }
00139 
00140 /** Get all service directories from Tor */
00141 QString
00142 ServiceSettings::getHiddenServiceDirectories()
00143 {
00144   /*XXX: Domenik: Why does this always try to getconf hiddenserviceoptions
00145    * even if the socket is not connected? */
00146   QString value =  _torControl->getHiddenServiceConf("hiddenserviceoptions");
00147   return value;
00148 }
00149 
00150 /** Set all services the user wants to start and send it to the
00151  * Tor Controller*/
00152 void
00153 ServiceSettings::applyServices(QString value, QString *errmsg)
00154 {
00155   _torControl->setConf(value, errmsg);
00156   _torControl->saveConf(errmsg);
00157 }
00158 
00159 /** Unpublish all HiddenServices */
00160 void
00161 ServiceSettings::unpublishAllServices(QString *errmsg)
00162 {
00163   _torControl->resetConf("HiddenServiceDir", errmsg);
00164   _torControl->saveConf(errmsg);
00165 }
00166 

Generated on 2 Sep 2009 for Vidalia by  doxygen 1.6.1