From 8e783de6f7e9e6f6e8fa1138cc3477ff6405ab58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 1 Jun 2014 19:56:22 -0300 Subject: [PATCH] Added cSSLSocket::IsSupported. The http_request example now use SSL only when is supported. --- include/eepp/network/ssl/csslsocket.hpp | 3 +++ src/eepp/network/ssl/csslsocket.cpp | 8 ++++++++ src/examples/http_request/http_request.cpp | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/eepp/network/ssl/csslsocket.hpp b/include/eepp/network/ssl/csslsocket.hpp index ad2272772..ec0f23d65 100644 --- a/include/eepp/network/ssl/csslsocket.hpp +++ b/include/eepp/network/ssl/csslsocket.hpp @@ -15,6 +15,9 @@ class EE_API cSSLSocket : public cTcpSocket { static bool End(); + /** @return True when the library was compiled with SSL support. */ + static bool IsSupported(); + cSSLSocket( std::string hostname, bool validateCertificate, bool validateHostname ); virtual ~cSSLSocket(); diff --git a/src/eepp/network/ssl/csslsocket.cpp b/src/eepp/network/ssl/csslsocket.cpp index 75ec2ebff..b972c52f9 100644 --- a/src/eepp/network/ssl/csslsocket.cpp +++ b/src/eepp/network/ssl/csslsocket.cpp @@ -70,6 +70,14 @@ bool cSSLSocket::End() { return ret; } +bool cSSLSocket::IsSupported() { +#ifdef EE_SSL_SUPPORT + return true; +#else + return false; +#endif +} + cSSLSocket::cSSLSocket( std::string hostname , bool validateCertificate, bool validateHostname ) : #ifdef EE_OPENSSL mImpl( eeNew( cOpenSSLSocket, ( this ) ) ), diff --git a/src/examples/http_request/http_request.cpp b/src/examples/http_request/http_request.cpp index 9b8bad807..b48688843 100644 --- a/src/examples/http_request/http_request.cpp +++ b/src/examples/http_request/http_request.cpp @@ -16,7 +16,11 @@ EE_MAIN_FUNC int main (int argc, char * argv []) { cHttp http; // We'll work on http://en.wikipedia.org - http.SetHost("https://en.wikipedia.org"); + if ( cSSLSocket::IsSupported() ) { + http.SetHost("https://en.wikipedia.org"); + } else { + http.SetHost("http://en.wikipedia.org"); + } // Prepare a request to get the wikipedia main page cHttp::Request request("/wiki/Main_Page");