ksslcsessioncache.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qpair.h>
00022 #include <qstring.h>
00023 #include <qptrlist.h>
00024
00025 #include <kdebug.h>
00026 #include <kstaticdeleter.h>
00027 #include <kurl.h>
00028
00029 #include "ksslconfig.h"
00030
00031 #include "ksslcsessioncache.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define MAX_ENTRIES 32
00050
00051 #ifdef KSSL_HAVE_SSL
00052
00053 typedef QPair<QString,QString> KSSLCSession;
00054 typedef QPtrList<KSSLCSession> KSSLCSessions;
00055
00056 static KSSLCSessions *sessions = 0L;
00057 static KStaticDeleter<KSSLCSessions> med;
00058
00059
00060 static QString URLtoKey(const KURL &kurl) {
00061 return kurl.host() + ":" + kurl.protocol() + ":" + QString::number(kurl.port());
00062 }
00063
00064
00065 static void setup() {
00066 KSSLCSessions *ses = new KSSLCSessions;
00067 ses->setAutoDelete(true);
00068 med.setObject(sessions, ses);
00069 }
00070
00071 #endif
00072
00073 QString KSSLCSessionCache::getSessionForURL(const KURL &kurl) {
00074 #ifdef KSSL_HAVE_SSL
00075 if (!sessions) return QString::null;
00076 QString key = URLtoKey(kurl);
00077
00078 for(KSSLCSession *it = sessions->first(); it; it=sessions->next()) {
00079 if (it->first == key) {
00080 sessions->take();
00081 sessions->prepend(it);
00082 return it->second;
00083 }
00084 }
00085
00086
00087 #if 0
00088 kdDebug(7029) <<"Negative caching " <<key <<endl;
00089 if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
00090 sessions->prepend(new KSSLCSession(key, QString::null));
00091 #endif
00092
00093 #endif
00094 return QString::null;
00095 }
00096
00097
00098 void KSSLCSessionCache::putSessionForURL(const KURL &kurl, const QString &session) {
00099 #ifdef KSSL_HAVE_SSL
00100 if (!sessions) setup();
00101 QString key = URLtoKey(kurl);
00102 KSSLCSession *it;
00103
00104 for(it = sessions->first(); it && it->first != key; it=sessions->next());
00105
00106 if (it) {
00107 sessions->take();
00108 it->second = session;
00109 } else {
00110 it = new KSSLCSession(key, session);
00111 if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
00112 }
00113
00114 sessions->prepend(it);
00115 #endif
00116 }
This file is part of the documentation for kio Library Version 3.3.1.