ksslsession.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025 #include <kopenssl.h>
00026 #include <kmdcodec.h>
00027
00028 #include "ksslsession.h"
00029
00030
00031 KSSLSession::KSSLSession() : _session(0L) {
00032 }
00033
00034
00035 KSSLSession::~KSSLSession() {
00036 #ifdef KSSL_HAVE_SSL
00037 if (_session) {
00038 KOpenSSLProxy::self()->SSL_SESSION_free(static_cast<SSL_SESSION*>(_session));
00039 _session = 0L;
00040 }
00041 #endif
00042 }
00043
00044
00045 QString KSSLSession::toString() const {
00046 QString rc;
00047 #ifdef KSSL_HAVE_SSL
00048 QByteArray qba;
00049 SSL_SESSION *session = static_cast<SSL_SESSION*>(_session);
00050 unsigned int slen = KOpenSSLProxy::self()->i2d_SSL_SESSION(session, 0L);
00051
00052
00053 char *csess = new char[slen];
00054 char *p = csess;
00055
00056 if (!KOpenSSLProxy::self()->i2d_SSL_SESSION(session, (unsigned char **)&p)) {
00057 delete[] csess;
00058 return QString::null;
00059 }
00060
00061
00062 qba.duplicate(csess, slen);
00063 delete[] csess;
00064 rc = KCodecs::base64Encode(qba);
00065 #endif
00066 return rc;
00067 }
00068
00069
00070 KSSLSession *KSSLSession::fromString(const QString& s) {
00071 KSSLSession *session = 0L;
00072 #ifdef KSSL_HAVE_SSL
00073 QByteArray qba, qbb = s.local8Bit().copy();
00074 KCodecs::base64Decode(qbb, qba);
00075 unsigned char *qbap = reinterpret_cast<unsigned char *>(qba.data());
00076 SSL_SESSION *ss = KOSSL::self()->d2i_SSL_SESSION(0L, &qbap, qba.size());
00077 if (ss) {
00078 session = new KSSLSession;
00079 session->_session = ss;
00080 }
00081 #endif
00082 return session;
00083 }
00084
00085
This file is part of the documentation for kio Library Version 3.2.2.