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
#ifdef Q_WS_WIN
00030
#include "ksslconfig_win.h"
00031
#else
00032
#include "ksslconfig.h"
00033
#endif
00034
00035
#include "ksslcsessioncache.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
#define MAX_ENTRIES 32
00054
00055
#ifdef KSSL_HAVE_SSL
00056
00057
typedef QPair<QString,QString> KSSLCSession;
00058
typedef QPtrList<KSSLCSession> KSSLCSessions;
00059
00060
static KSSLCSessions *sessions = 0L;
00061
static KStaticDeleter<KSSLCSessions> med;
00062
00063
00064
static QString URLtoKey(
const KURL &kurl) {
00065
return kurl.
host() +
":" + kurl.
protocol() +
":" + QString::number(kurl.
port());
00066 }
00067
00068
00069
static void setup() {
00070 KSSLCSessions *ses =
new KSSLCSessions;
00071 ses->setAutoDelete(
true);
00072 med.setObject(sessions, ses);
00073 }
00074
00075
#endif
00076
00077
QString KSSLCSessionCache::getSessionForURL(
const KURL &kurl) {
00078
#ifdef KSSL_HAVE_SSL
00079
if (!sessions)
return QString::null;
00080
QString key = URLtoKey(kurl);
00081
00082
for(KSSLCSession *it = sessions->first(); it; it=sessions->next()) {
00083
if (it->first ==
key) {
00084 sessions->take();
00085 sessions->prepend(it);
00086
return it->second;
00087 }
00088 }
00089
00090
00091
#if 0
00092
kdDebug(7029) <<
"Negative caching " <<
key <<
endl;
00093
if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
00094 sessions->prepend(
new KSSLCSession(key, QString::null));
00095
#endif
00096
00097
#endif
00098
return QString::null;
00099 }
00100
00101
00102
void KSSLCSessionCache::putSessionForURL(
const KURL &kurl,
const QString &session) {
00103
#ifdef KSSL_HAVE_SSL
00104
if (!sessions) setup();
00105
QString key = URLtoKey(kurl);
00106 KSSLCSession *it;
00107
00108
for(it = sessions->first(); it && it->first !=
key; it=sessions->next());
00109
00110
if (it) {
00111 sessions->take();
00112 it->second = session;
00113 }
else {
00114 it =
new KSSLCSession(key, session);
00115
if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
00116 }
00117
00118 sessions->prepend(it);
00119
#endif
00120
}