• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
slaveconfig.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
4  *
5  * $Id$
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License version 2 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  **/
21 
22 #include <assert.h>
23 
24 #include <tqdict.h>
25 
26 #include <tdeconfig.h>
27 #include <kstaticdeleter.h>
28 #include <kprotocolinfo.h>
29 #include <tdeprotocolmanager.h>
30 
31 #include "slaveconfig.h"
32 
33 using namespace TDEIO;
34 
35 namespace TDEIO {
36 
37 class SlaveConfigProtocol
38 {
39 public:
40  SlaveConfigProtocol() { host.setAutoDelete(true); }
41  ~SlaveConfigProtocol()
42  {
43  delete configFile;
44  }
45 
46 public:
47  MetaData global;
48  TQDict<MetaData> host;
49  TDEConfig *configFile;
50 };
51 
52 static void readConfig(TDEConfig *config, const TQString & group, MetaData *metaData)
53 {
54  *metaData += config->entryMap(group);
55 }
56 
57 class SlaveConfigPrivate
58 {
59  public:
60  void readGlobalConfig();
61  SlaveConfigProtocol *readProtocolConfig(const TQString &_protocol);
62  SlaveConfigProtocol *findProtocolConfig(const TQString &_protocol);
63  void readConfigProtocolHost(const TQString &_protocol, SlaveConfigProtocol *scp, const TQString &host);
64  public:
65  MetaData global;
66  TQDict<SlaveConfigProtocol> protocol;
67 };
68 
69 void SlaveConfigPrivate::readGlobalConfig()
70 {
71  global.clear();
72  // Read stuff...
73  TDEConfig *config = KProtocolManager::config();
74  readConfig(TDEGlobal::config(), "Socks", &global); // Socks settings.
75  if ( config )
76  readConfig(config, "<default>", &global);
77 }
78 
79 SlaveConfigProtocol* SlaveConfigPrivate::readProtocolConfig(const TQString &_protocol)
80 {
81  SlaveConfigProtocol *scp = protocol.find(_protocol);
82  if (!scp)
83  {
84  TQString filename = KProtocolInfo::config(_protocol);
85  scp = new SlaveConfigProtocol;
86  scp->configFile = new TDEConfig(filename, true, false);
87  protocol.insert(_protocol, scp);
88  }
89  // Read global stuff...
90  readConfig(scp->configFile, "<default>", &(scp->global));
91  return scp;
92 }
93 
94 SlaveConfigProtocol* SlaveConfigPrivate::findProtocolConfig(const TQString &_protocol)
95 {
96  SlaveConfigProtocol *scp = protocol.find(_protocol);
97  if (!scp)
98  scp = readProtocolConfig(_protocol);
99  return scp;
100 }
101 
102 void SlaveConfigPrivate::readConfigProtocolHost(const TQString &, SlaveConfigProtocol *scp, const TQString &host)
103 {
104  MetaData *metaData = new MetaData;
105  scp->host.replace(host, metaData);
106 
107  // Read stuff
108  // Break host into domains
109  TQString domain = host;
110 
111  if (!domain.contains('.'))
112  {
113  // Host without domain.
114  if (scp->configFile->hasGroup("<local>"))
115  readConfig(scp->configFile, "<local>", metaData);
116  }
117 
118  int pos = 0;
119  do
120  {
121  pos = host.findRev('.', pos-1);
122 
123  if (pos < 0)
124  domain = host;
125  else
126  domain = host.mid(pos+1);
127 
128  if (scp->configFile->hasGroup(domain))
129  readConfig(scp->configFile, domain.lower(), metaData);
130  }
131  while (pos > 0);
132 }
133 
134 
135 SlaveConfig *SlaveConfig::_self = 0;
136 static KStaticDeleter<SlaveConfig> slaveconfigsd;
137 
138 SlaveConfig *SlaveConfig::self()
139 {
140  if (!_self)
141  _self = slaveconfigsd.setObject(_self, new SlaveConfig);
142  return _self;
143 }
144 
145 SlaveConfig::SlaveConfig()
146 {
147  d = new SlaveConfigPrivate;
148  d->protocol.setAutoDelete(true);
149  d->readGlobalConfig();
150 }
151 
152 SlaveConfig::~SlaveConfig()
153 {
154  delete d; d = 0;
155  _self = 0;
156 }
157 
158 void SlaveConfig::setConfigData(const TQString &protocol,
159  const TQString &host,
160  const TQString &key,
161  const TQString &value )
162 {
163  MetaData config;
164  config.insert(key, value);
165  setConfigData(protocol, host, config);
166 }
167 
168 void SlaveConfig::setConfigData(const TQString &protocol, const TQString &host, const MetaData &config )
169 {
170  if (protocol.isEmpty())
171  d->global += config;
172  else {
173  SlaveConfigProtocol *scp = d->findProtocolConfig(protocol);
174  if (host.isEmpty())
175  {
176  scp->global += config;
177  }
178  else
179  {
180  MetaData *hostConfig = scp->host.find(host);
181  if (!hostConfig)
182  {
183  d->readConfigProtocolHost(protocol, scp, host);
184  hostConfig = scp->host.find(host);
185  assert(hostConfig);
186  }
187  *hostConfig += config;
188  }
189  }
190 }
191 
192 MetaData SlaveConfig::configData(const TQString &protocol, const TQString &host)
193 {
194  MetaData config = d->global;
195  SlaveConfigProtocol *scp = d->findProtocolConfig(protocol);
196  config += scp->global;
197  if (host.isEmpty())
198  return config;
199  MetaData *hostConfig = scp->host.find(host);
200  if (!hostConfig)
201  {
202  d->readConfigProtocolHost(protocol, scp, host);
203  emit configNeeded(protocol, host);
204  hostConfig = scp->host.find(host);
205  assert(hostConfig);
206  }
207  config += *hostConfig;
208  return config;
209 }
210 
211 TQString SlaveConfig::configData(const TQString &protocol, const TQString &host, const TQString &key)
212 {
213  return configData(protocol, host)[key];
214 }
215 
216 void SlaveConfig::reset()
217 {
218  d->protocol.clear();
219  d->readGlobalConfig();
220 }
221 
222 }
223 
224 #include "slaveconfig.moc"
TDEIO::SlaveConfig
SlaveConfig.
Definition: slaveconfig.h:46
TDEIO::SlaveConfig::configNeeded
void configNeeded(const TQString &protocol, const TQString &host)
This signal is raised when a slave of type protocol deals with host for the first time...
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
KProtocolInfo::config
static TQString config(const TQString &protocol)
Returns the name of the config file associated with the specified protocol.
TDEIO::SlaveConfig::reset
void reset()
Undo any changes made by calls to setConfigData.
Definition: slaveconfig.cpp:216
TDEIO::SlaveConfig::configData
MetaData configData(const TQString &protocol, const TQString &host)
Query slave configuration for slaves of type protocol when dealing with host.
Definition: slaveconfig.cpp:192
TDEIO::SlaveConfig::setConfigData
void setConfigData(const TQString &protocol, const TQString &host, const TQString &key, const TQString &value)
Configure slaves of type protocol by setting key to value.
Definition: slaveconfig.cpp:158
TDEIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:515

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.