00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00039 #include "blocxx/BLOCXX_config.h"
00040 #include "blocxx/Socket.hpp"
00041 #include "blocxx/SocketImpl.hpp"
00042 #include "blocxx/SSLException.hpp"
00043 #include "blocxx/SSLSocketImpl.hpp"
00044
00045
00046
00047
00048 namespace BLOCXX_NAMESPACE
00049 {
00050
00052 Socket::Socket(const SSLClientCtxRef& sslCtx)
00053 {
00054 if (sslCtx)
00055 {
00056 #ifndef BLOCXX_NO_SSL
00057 m_impl = SocketBaseImplRef(new SSLSocketImpl(sslCtx));
00058 #else
00059 BLOCXX_THROW(SSLException, "Not built with SSL");
00060 #endif // #ifndef BLOCXX_NO_SSL
00061 }
00062 else
00063 {
00064 m_impl = SocketBaseImplRef(new SocketImpl);
00065 }
00066 }
00067
00069 Socket::Socket(SocketFlags::ESSLFlag isSSL)
00070 {
00071 if (isSSL == SocketFlags::E_SSL)
00072 {
00073 #ifndef BLOCXX_NO_SSL
00074 m_impl = SocketBaseImplRef(new SSLSocketImpl);
00075 #else
00076 BLOCXX_THROW(SSLException, "Not built with SSL");
00077 #endif // #ifndef BLOCXX_NO_SSL
00078 }
00079 else
00080 {
00081 m_impl = SocketBaseImplRef(new SocketImpl);
00082 }
00083 }
00085 Socket::Socket(SocketHandle_t fd,
00086 SocketAddress::AddressType addrType, SocketFlags::ESSLFlag isSSL)
00087 {
00088 if (isSSL == SocketFlags::E_SSL)
00089 {
00090 #ifndef BLOCXX_NO_SSL
00091 m_impl = SocketBaseImplRef(new SSLSocketImpl(fd, addrType));
00092 #else
00093 BLOCXX_THROW(SSLException, "Not built with SSL");
00094 #endif // #ifndef BLOCXX_NO_SSL
00095 }
00096 else
00097 {
00098 m_impl = SocketBaseImplRef(new SocketImpl(fd, addrType));
00099 }
00100 }
00102
00103 Socket::Socket(SocketHandle_t fd,
00104 SocketAddress::AddressType addrType, const SSLServerCtxRef& sslCtx)
00105 {
00106 if (sslCtx)
00107 {
00108 #ifndef BLOCXX_NO_SSL
00109 m_impl = SocketBaseImplRef(new SSLSocketImpl(fd, addrType, sslCtx));
00110 #else
00111 BLOCXX_THROW(SSLException, "Not built with SSL");
00112 #endif // #ifndef BLOCXX_NO_SSL
00113 }
00114 else
00115 {
00116 m_impl = SocketBaseImplRef(new SocketImpl(fd, addrType));
00117 }
00118 }
00120 Socket::Socket(const SocketAddress& addr, SocketFlags::ESSLFlag isSSL)
00121 {
00122 if (isSSL == SocketFlags::E_SSL)
00123 {
00124 #ifndef BLOCXX_NO_SSL
00125 m_impl = SocketBaseImplRef(new SSLSocketImpl(addr));
00126 #else
00127 BLOCXX_THROW(SSLException, "Not built with SSL");
00128 #endif // #ifndef BLOCXX_NO_SSL
00129 }
00130 else
00131 {
00132 m_impl = SocketBaseImplRef(new SocketImpl(addr));
00133 }
00134 }
00135
00136 #ifndef BLOCXX_NO_SSL
00137 SSL*
00138 Socket::getSSL() const
00139 {
00140 IntrusiveReference<SSLSocketImpl> sslsock = m_impl.cast_to<SSLSocketImpl>();
00141 if (!sslsock)
00142 {
00143 return 0;
00144 }
00145 return sslsock->getSSL();
00146 }
00147
00149 bool
00150 Socket::peerCertVerified() const
00151 {
00152 IntrusiveReference<SSLSocketImpl> sslsock = m_impl.cast_to<SSLSocketImpl>();
00153 if (!sslsock)
00154 {
00155 return false;
00156 }
00157 return sslsock->peerCertVerified();
00158 }
00159 #endif
00160
00161 }