Vidalia  0.2.21
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 */
36 void
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*/
83 QString
85 {
86  QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString();
87  return port;
88 }
89 
90 /** Set the virtual port for a specific service*/
91 void
92 ServiceSettings::setVirtualPort(QString servicePort)
93 {
95 }
96 
97 /** Returns the .onion - service address for a specific service */
98 QString
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 */
106 void
108 {
110 }
111 
112 /** Returns the physical address for a specific service */
113 QString
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 */
121 void
123 {
125 }
126 
127 /** Returns if the Service is enabled */
128 bool
130 {
131  return value(SETTING_SERVICE_ENABLED).toBool();
132 }
133 
134 /** Set the service enabled */
135 void
137 {
139 }
140 
141 /** Get all service directories from Tor */
142 QString
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*/
153 void
154 ServiceSettings::applyServices(QString value, QString *errmsg)
155 {
156  _torControl->setConf(value, errmsg);
157  _torControl->saveConf(errmsg);
158 }
159 
160 /** Unpublish all HiddenServices */
161 void
163 {
164  _torControl->resetConf("HiddenServiceDir", errmsg);
165  _torControl->saveConf(errmsg);
166 }
167