servicesettings.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stringutil.h>
00012 #include "servicesettings.h"
00013 #include "torsettings.h"
00014
00015
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
00023
00024
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
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
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
00082 QString
00083 ServiceSettings::getVirtualPort()
00084 {
00085 QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString();
00086 return port;
00087 }
00088
00089
00090 void
00091 ServiceSettings::setVirtualPort(QString servicePort)
00092 {
00093 setValue(SETTING_SERVICE_VIRTUAL_PORT, servicePort);
00094 }
00095
00096
00097 QString
00098 ServiceSettings::getServiceAddress()
00099 {
00100 QString addr = value(SETTING_SERVICE_ADDRESS).toString();
00101 return addr;
00102 }
00103
00104
00105 void
00106 ServiceSettings::setServiceAddress(QString addr)
00107 {
00108 setValue(SETTING_SERVICE_ADDRESS, addr);
00109 }
00110
00111
00112 QString
00113 ServiceSettings::getPhysicalAddressPort()
00114 {
00115 QString addr = value(SETTING_SERVICE_PHYSICAL_ADDRESS).toString();
00116 return addr;
00117 }
00118
00119
00120 void
00121 ServiceSettings::setPhysicalAddressPort(QString addr)
00122 {
00123 setValue(SETTING_SERVICE_PHYSICAL_ADDRESS, addr);
00124 }
00125
00126
00127 bool
00128 ServiceSettings::isEnabled()
00129 {
00130 return value(SETTING_SERVICE_ENABLED).toBool();
00131 }
00132
00133
00134 void
00135 ServiceSettings::setEnabled(bool boolean)
00136 {
00137 setValue(SETTING_SERVICE_ENABLED, boolean);
00138 }
00139
00140
00141 QString
00142 ServiceSettings::getHiddenServiceDirectories()
00143 {
00144
00145
00146 QString value = _torControl->getHiddenServiceConf("hiddenserviceoptions");
00147 return value;
00148 }
00149
00150
00151
00152 void
00153 ServiceSettings::applyServices(QString value, QString *errmsg)
00154 {
00155 _torControl->setConf(value, errmsg);
00156 _torControl->saveConf(errmsg);
00157 }
00158
00159
00160 void
00161 ServiceSettings::unpublishAllServices(QString *errmsg)
00162 {
00163 _torControl->resetConf("HiddenServiceDir", errmsg);
00164 _torControl->saveConf(errmsg);
00165 }
00166