KjSslObject.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00032  ***************************************************************************/
00033 
00034 #include "KjSslObject.h"
00035 
00036 KjSslObject::KjSslObject()
00037 {
00038         m_pCtx = NULL;
00039     SSL_load_error_strings();
00040     SSL_library_init();
00041     m_pCtx=SSL_CTX_new(SSLv3_method());
00042     SSL_CTX_set_options(m_pCtx, SSL_OP_ALL);
00043 }
00044 
00045 KjSslObject::~KjSslObject()
00046 {
00047 }
00048 
00051 void KjSslObject::CheckErrors(const string &_str)
00052 {
00053         int i;
00054         cerr << _str << ':' << endl;
00055         while((i=ERR_get_error()))
00056         {
00057                 char strErr[1024];
00058                 ERR_error_string_n(i,strErr,sizeof(strErr));
00059                 cerr<< "\tError " << i << ": " << strErr << endl;
00060     }
00061 }
00062 
00067 void KjSslObject::CheckSslErrors(const SSL *_pSsl, const int _iRet, const string &_str)
00068 {
00069         int iErr = SSL_get_error(_pSsl, _iRet);
00070         switch (iErr)
00071         {
00072         case SSL_ERROR_NONE:
00073                 cout << "No Error:: " << _str << " -- The TLS/SSL I/O operation completed." << endl;
00074                 break;
00075         case SSL_ERROR_ZERO_RETURN:
00076                 cerr << "Error:: " << _str << " -- The TLS/SSL connection has been closed." << endl;
00077                 break;
00078         case SSL_ERROR_WANT_READ:
00079                 cerr << "Error:: " << _str << " -- The operation READ did not complete" << endl;
00080                 break;
00081         case SSL_ERROR_WANT_WRITE:
00082                 cerr << "Error:: " << _str << " -- The operation WRITE did not complete" << endl;
00083                 break;
00084         case SSL_ERROR_WANT_CONNECT:
00085                 cerr << "Error:: " << _str << " -- The operation CONNECT did not complete" << endl;
00086                 break;
00087         case SSL_ERROR_WANT_X509_LOOKUP:
00088                 cerr << "Error:: " << _str << " -- The operation X509_LOOKUP did not complete" << endl;
00089                 break;
00090         case SSL_ERROR_SYSCALL:
00091                 cerr << "Error:: " << _str << " -- Some I/O error occurred." << endl;
00092                 break;
00093         case SSL_ERROR_SSL:
00094                 cerr << "Error:: " << _str << " -- A failure in the SSL library occurred, usually a protocol error." << endl;
00095                 break;
00096         default:
00097                 break;
00098         }
00099 }

Generated on Tue Jul 24 10:03:19 2007 for KjSslSocket by  doxygen 1.4.6