Vidalia 0.3.1
ServiceSettings.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11#include "ServiceSettings.h"
12#include "TorSettings.h"
13
14#include "stringutil.h"
15
16/* Service Settings */
17#define SETTING_SERVICE_VIRTUAL_PORT "Service/VirtualPort"
18#define SETTING_SERVICE_ADDRESS "Service/ServiceAddress"
19#define SETTING_SERVICE_PHYSICAL_ADDRESS "Service/ServicePhysicalAddress"
20#define SETTING_SERVICE_ENABLED "Service/Enabled"
21#define SETTING_TOR_SERVICES "Service/Services"
22
23/** Constructor.
24 * \param torControl a TorControl object used to read and apply the Service
25 * configuration settings.
26 */
28{
29 _torControl = torControl;
33}
34
35/** Set ServiceList to serialise it */
36void
38{
39 QStringList serviceList;
40 if(service.services().size() > 0) {
41 QList<Service> services = service.services();
42 foreach (Service tempService, services) {
43 serviceList << tempService.toString();
44 }
45 }
46 setValue(SETTING_TOR_SERVICES, serviceList);
47}
48
49/** Get serialised ServiceList */
52{
53 QString address,virtualPort,physAddrPort,serviceDir,enabledS,additionalData;
54 bool enabled = false;
55 QStringList stringList;
56 ServiceList services;
57
58 stringList = value(SETTING_TOR_SERVICES).toStringList();
59 foreach (QString s, stringList) {
60 QStringList skippedList = s.split("#");
61 address = skippedList.first();
62 skippedList.removeFirst();
63 virtualPort = skippedList.first();
64 skippedList.removeFirst();
65 physAddrPort = skippedList.first();
66 skippedList.removeFirst();
67 serviceDir = skippedList.first();
68 skippedList.removeFirst();
69 enabledS = skippedList.first();
70 skippedList.removeFirst();
71 additionalData = skippedList.first();
72 if(enabledS.compare("x1") == 0) {
73 enabled = true;
74 }
75 Service service(address, virtualPort, physAddrPort, serviceDir, enabled);
76 service.setAdditionalServiceOptions(additionalData);
77 services.addService(service);
78 }
79 return services;
80}
81
82/** Returns the virtual port for a specific service*/
83QString
85{
86 QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString();
87 return port;
88}
89
90/** Set the virtual port for a specific service*/
91void
93{
95}
96
97/** Returns the .onion - service address for a specific service */
98QString
100{
101 QString addr = value(SETTING_SERVICE_ADDRESS).toString();
102 return addr;
103}
104
105/** Set the .onion - service address or hostname for a specific service */
106void
108{
110}
111
112/** Returns the physical address for a specific service */
113QString
115{
116 QString addr = value(SETTING_SERVICE_PHYSICAL_ADDRESS).toString();
117 return addr;
118}
119
120/** Set the physical address or hostname for a specific service */
121void
123{
125}
126
127/** Returns if the Service is enabled */
128bool
130{
131 return value(SETTING_SERVICE_ENABLED).toBool();
132}
133
134/** Set the service enabled */
135void
137{
139}
140
141/** Get all service directories from Tor */
142QString
144{
145 /*XXX: Domenik: Why does this always try to getconf hiddenserviceoptions
146 * even if the socket is not connected? */
147 QString value = _torControl->getHiddenServiceConf("hiddenserviceoptions");
148 return value;
149}
150
151/** Set all services the user wants to start and send it to the
152 * Tor Controller*/
153void
154ServiceSettings::applyServices(QString value, QString *errmsg)
155{
156 _torControl->setConf(value, errmsg);
157 _torControl->saveConf(errmsg);
158}
159
160/** Unpublish all HiddenServices */
161void
163{
164 _torControl->resetConf("HiddenServiceDir", errmsg);
165 _torControl->saveConf(errmsg);
166}
167
#define SETTING_SERVICE_PHYSICAL_ADDRESS
#define SETTING_TOR_SERVICES
#define SETTING_SERVICE_VIRTUAL_PORT
#define SETTING_SERVICE_ADDRESS
#define SETTING_SERVICE_ENABLED
void setAdditionalServiceOptions(QString options)
Definition: Service.cpp:66
QString toString()
Definition: Service.cpp:114
QList< Service > services() const
Definition: ServiceList.h:32
void addService(Service service)
Definition: ServiceList.cpp:20
QString getServiceAddress()
QString getVirtualPort()
void setServices(ServiceList services)
void setEnabled(bool enabled)
void applyServices(QString value, QString *errmsg)
TorControl * _torControl
ServiceSettings(TorControl *torControl)
void setPhysicalAddressPort(QString physicalAddress)
ServiceList getServices()
void setServiceAddress(QString serviceAddress)
void setVirtualPort(QString servicePort)
void unpublishAllServices(QString *errmsg)
QString getPhysicalAddressPort()
QString getHiddenServiceDirectories()
bool saveConf(QString *errmsg=0)
Definition: TorControl.cpp:914
QString getHiddenServiceConf(const QString &key, QString *errmsg=0)
Definition: TorControl.cpp:899
bool resetConf(QStringList keys, QString *errmsg=0)
Definition: TorControl.cpp:929
bool setConf(QHash< QString, QString > map, QString *errmsg=0)
Definition: TorControl.cpp:722
virtual void setValue(const QString &key, const QVariant &val)
Definition: VSettings.cpp:61
virtual QVariant value(const QString &key, const QVariant &defaultVal=QVariant()) const
Definition: VSettings.cpp:53
void setDefault(const QString &key, const QVariant &val)
Definition: VSettings.cpp:71