00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 00003 // Author: Michal Simon <simonm@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // XRootD is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // XRootD is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00017 //------------------------------------------------------------------------------ 00018 00019 #ifndef __XRD_CL_TLS_HH__ 00020 #define __XRD_CL_TLS_HH__ 00021 00022 #include <memory> 00023 00024 #include "XrdTls/XrdTlsSocket.hh" 00025 00026 #include "XrdCl/XrdClXRootDResponses.hh" 00027 #include "XrdCl/XrdClAsyncSocketHandler.hh" 00028 00029 namespace XrdCl 00030 { 00031 class Socket; 00032 00033 //---------------------------------------------------------------------------- 00035 //---------------------------------------------------------------------------- 00036 class Tls 00037 { 00038 public: 00039 00040 //------------------------------------------------------------------------ 00042 //------------------------------------------------------------------------ 00043 Tls( Socket *socket, AsyncSocketHandler *socketHandler ); 00044 00045 //------------------------------------------------------------------------ 00047 //------------------------------------------------------------------------ 00048 ~Tls() 00049 { 00050 } 00051 00052 //------------------------------------------------------------------------ 00054 //------------------------------------------------------------------------ 00055 XRootDStatus Connect( const std::string &thehost, XrdNetAddrInfo *netInfo ); 00056 00057 //------------------------------------------------------------------------ 00060 //------------------------------------------------------------------------ 00061 XRootDStatus Read( char *buffer, size_t size, int &bytesRead ); 00062 00063 //------------------------------------------------------------------------ 00066 //------------------------------------------------------------------------ 00067 XRootDStatus Send( const char *buffer, size_t size, int &bytesWritten ); 00068 00069 //------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------ 00076 uint8_t MapEvent( uint8_t event ); 00077 00078 //------------------------------------------------------------------------ 00080 //------------------------------------------------------------------------ 00081 static void ClearErrorQueue(); 00082 00083 private: 00084 00085 //------------------------------------------------------------------------ 00093 //------------------------------------------------------------------------ 00094 enum TlsHSRevert{ None, ReadOnWrite, WriteOnRead }; 00095 00096 //------------------------------------------------------------------------ 00098 //------------------------------------------------------------------------ 00099 XRootDStatus ToStatus( XrdTls::RC rc ); 00100 00101 //------------------------------------------------------------------------ 00103 //------------------------------------------------------------------------ 00104 Socket *pSocket; 00105 00106 //------------------------------------------------------------------------ 00108 //------------------------------------------------------------------------ 00109 std::unique_ptr<XrdTlsSocket> pTls; 00110 00111 //------------------------------------------------------------------------ 00112 // In case during TLS hand-shake WantRead has been returned on write or 00113 // WantWrite has been returned on read we need to flip the following events. 00114 // 00115 // None : all events should be processed normally 00116 // ReadOnWrite : on write event the OnRead routines should be called 00117 // WriteOnRead : on read event the OnWrite routines should be called 00118 //------------------------------------------------------------------------ 00119 TlsHSRevert pTlsHSRevert; 00120 00121 //------------------------------------------------------------------------ 00123 //------------------------------------------------------------------------ 00124 AsyncSocketHandler *pSocketHandler; 00125 }; 00126 } 00127 00128 #endif // __XRD_CL_TLS_HH__ 00129