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

tdeio/tdeio

  • tdeio
  • tdeio
sessiondata.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License (LGPL) as published by the Free Software Foundation;
7  either version 2 of the License, or (at your option) any
8  later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; see the file COPYING.LIB. If not,
17  write to the Free Software Foundation, Inc., 51 Franklin Street,
18  Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqptrlist.h>
22 #include <tqtextcodec.h>
23 
24 #include <kdebug.h>
25 #include <tdeconfig.h>
26 #include <tdeglobal.h>
27 #include <tdelocale.h>
28 #include <kcharsets.h>
29 #include <dcopclient.h>
30 #include <tdeprotocolmanager.h>
31 #include <kstandarddirs.h>
32 
33 #include <tdesu/client.h>
34 #include <tdeio/slaveconfig.h>
35 #include <tdeio/http_slave_defaults.h>
36 
37 #include "sessiondata.h"
38 #include "sessiondata.moc"
39 
40 namespace TDEIO {
41 
42 /***************************** SessionData::AuthData ************************/
43 struct SessionData::AuthData
44 {
45 
46 public:
47  AuthData() {}
48 
49  AuthData(const TQCString& k, const TQCString& g, bool p) {
50  key = k;
51  group = g;
52  persist = p;
53  }
54 
55  bool isKeyMatch( const TQCString& val ) const {
56  return (val==key);
57  }
58 
59  bool isGroupMatch( const TQCString& val ) const {
60  return (val==group);
61  }
62 
63  TQCString key;
64  TQCString group;
65  bool persist;
66 };
67 
68 /************************* SessionData::AuthDataList ****************************/
69 class SessionData::AuthDataList : public TQPtrList<SessionData::AuthData>
70 {
71 public:
72  AuthDataList();
73  ~AuthDataList();
74 
75  void addData( SessionData::AuthData* );
76  void removeData( const TQCString& );
77 
78  bool pingCacheDaemon();
79  void registerAuthData( SessionData::AuthData* );
80  void unregisterAuthData( SessionData::AuthData* );
81  void purgeCachedData();
82 
83 private:
84 #ifdef Q_OS_UNIX
85  TDEsuClient * m_tdesuClient;
86 #endif
87 };
88 
89 SessionData::AuthDataList::AuthDataList()
90 {
91 #ifdef Q_OS_UNIX
92  m_tdesuClient = new TDEsuClient;
93 #endif
94  setAutoDelete(true);
95 }
96 
97 SessionData::AuthDataList::~AuthDataList()
98 {
99  purgeCachedData();
100 #ifdef Q_OS_UNIX
101  delete m_tdesuClient;
102  m_tdesuClient = 0;
103 #endif
104 }
105 
106 void SessionData::AuthDataList::addData( SessionData::AuthData* d )
107 {
108  TQPtrListIterator<SessionData::AuthData> it ( *this );
109  for ( ; it.current(); ++it )
110  {
111  if ( it.current()->isKeyMatch( d->key ) )
112  return;
113  }
114  registerAuthData( d );
115  append( d );
116 }
117 
118 void SessionData::AuthDataList::removeData( const TQCString& gkey )
119 {
120  TQPtrListIterator<SessionData::AuthData> it( *this );
121  for( ; it.current(); ++it )
122  {
123  if ( it.current()->isGroupMatch(gkey) && pingCacheDaemon() )
124  {
125  unregisterAuthData( it.current() );
126  remove( it.current() );
127  }
128  }
129 }
130 
131 bool SessionData::AuthDataList::pingCacheDaemon()
132 {
133 #ifdef Q_OS_UNIX
134  Q_ASSERT(m_tdesuClient);
135 
136  int success = m_tdesuClient->ping();
137  if( success == -1 )
138  {
139  success = m_tdesuClient->startServer();
140  if( success == -1 )
141  return false;
142  }
143  return true;
144 #else
145  return false;
146 #endif
147 }
148 
149 void SessionData::AuthDataList::registerAuthData( SessionData::AuthData* d )
150 {
151  if( !pingCacheDaemon() )
152  return;
153 
154 #ifdef Q_OS_UNIX
155  bool ok;
156  TQCString ref_key = d->key + "-refcount";
157  int count = m_tdesuClient->getVar(ref_key).toInt( &ok );
158  if( ok )
159  {
160  TQCString val;
161  val.setNum( count+1 );
162  m_tdesuClient->setVar( ref_key, val, 0, d->group );
163  }
164  else
165  m_tdesuClient->setVar( ref_key, "1", 0, d->group );
166 #endif
167 }
168 
169 void SessionData::AuthDataList::unregisterAuthData( SessionData::AuthData* d )
170 {
171  if ( !d || d->persist )
172  return;
173 
174  bool ok;
175  int count;
176  TQCString ref_key = d->key + "-refcount";
177 
178 #ifdef Q_OS_UNIX
179  count = m_tdesuClient->getVar( ref_key ).toInt( &ok );
180  if ( ok )
181  {
182  if ( count > 1 )
183  {
184  TQCString val;
185  val.setNum(count-1);
186  m_tdesuClient->setVar( ref_key, val, 0, d->group );
187  }
188  else
189  {
190  m_tdesuClient->delVars(d->key);
191  }
192  }
193 #endif
194 }
195 
196 void SessionData::AuthDataList::purgeCachedData()
197 {
198  if ( !isEmpty() && pingCacheDaemon() )
199  {
200  TQPtrListIterator<SessionData::AuthData> it( *this );
201  for ( ; it.current(); ++it )
202  unregisterAuthData( it.current() );
203  }
204 }
205 
206 /********************************* SessionData ****************************/
207 
208 class SessionData::SessionDataPrivate
209 {
210 public:
211  SessionDataPrivate() {
212  useCookie = true;
213  initDone = false;
214  }
215 
216  bool initDone;
217  bool useCookie;
218  TQString charsets;
219  TQString language;
220 };
221 
222 SessionData::SessionData()
223 {
224  authData = 0;
225  d = new SessionDataPrivate;
226 }
227 
228 SessionData::~SessionData()
229 {
230  delete d;
231  delete authData;
232  d = 0L;
233  authData = 0L;
234 }
235 
236 void SessionData::configDataFor( MetaData &configData, const TQString &proto,
237  const TQString & )
238 {
239  if ( (proto.find("http", 0, false) == 0 ) ||
240  (proto.find("webdav", 0, false) == 0) )
241  {
242  if (!d->initDone)
243  reset();
244 
245  // These might have already been set so check first
246  // to make sure that we do not trumpt settings sent
247  // by apps or end-user.
248  if ( configData["Cookies"].isEmpty() )
249  configData["Cookies"] = d->useCookie ? "true" : "false";
250  if ( configData["Languages"].isEmpty() )
251  configData["Languages"] = d->language;
252  if ( configData["Charsets"].isEmpty() )
253  configData["Charsets"] = d->charsets;
254  if ( configData["CacheDir"].isEmpty() )
255  configData["CacheDir"] = TDEGlobal::dirs()->saveLocation("cache", "http");
256  if ( configData["UserAgent"].isEmpty() )
257  {
258  configData["UserAgent"] = KProtocolManager::defaultUserAgent();
259  }
260  }
261 }
262 
263 void SessionData::reset()
264 {
265  d->initDone = true;
266  // Get Cookie settings...
267  TDEConfig* cfg = new TDEConfig("kcookiejarrc", true, false);
268  cfg->setGroup( "Cookie Policy" );
269  d->useCookie = cfg->readBoolEntry( "Cookies", true );
270  delete cfg;
271 
272  static const TQString & english = TDEGlobal::staticQString( "en" );
273 
274  // Get language settings...
275  TQStringList languageList = TDEGlobal::locale()->languagesTwoAlpha();
276  TQStringList::Iterator it = languageList.find( TQString::fromLatin1("C") );
277  if ( it != languageList.end() )
278  {
279  if ( languageList.contains( english ) > 0 )
280  languageList.remove( it );
281  else
282  (*it) = english;
283  }
284  if ( !languageList.contains( english ) )
285  languageList.append( english );
286 
287  d->language = languageList.join( ", " );
288 
289  d->charsets = TQString::fromLatin1(TQTextCodec::codecForLocale()->mimeName()).lower();
290  KProtocolManager::reparseConfiguration();
291 }
292 
293 void SessionData::slotAuthData( const TQCString& key, const TQCString& gkey,
294  bool keep )
295 {
296  if (!authData)
297  authData = new AuthDataList;
298  authData->addData( new SessionData::AuthData(key, gkey, keep) );
299 }
300 
301 void SessionData::slotDelAuthData( const TQCString& gkey )
302 {
303  if (!authData)
304  return;
305  authData->removeData( gkey );
306 }
307 
308 void SessionData::virtual_hook( int, void* )
309 { /*BASE::virtual_hook( id, data );*/ }
310 
311 }
KProtocolManager::reparseConfiguration
static void reparseConfiguration()
Force a reload of the general config file of io-slaves ( tdeioslaverc).
Definition: tdeprotocolmanager.cpp:78
KProtocolManager::defaultUserAgent
static TQString defaultUserAgent()
Returns the default user-agent string.
Definition: tdeprotocolmanager.cpp:434
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29

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.