Fixed compile error without SSL/TLS lib

pull/36/head release-1.16.0
Tatsuhiro Tsujikawa 2012-12-01 23:37:57 +09:00
parent 2cbdd8b845
commit 8ac433a8e9
4 changed files with 14 additions and 3 deletions

View File

@ -128,6 +128,7 @@ bool HttpRequestCommand::executeInternal() {
getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) { getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) {
return true; return true;
} }
#ifdef ENABLE_SSL
if(getRequest()->getProtocol() == "https") { if(getRequest()->getProtocol() == "https") {
if(!getSocket()->tlsConnect(getRequest()->getHost())) { if(!getSocket()->tlsConnect(getRequest()->getHost())) {
setReadCheckSocketIf(getSocket(), getSocket()->wantRead()); setReadCheckSocketIf(getSocket(), getSocket()->wantRead());
@ -136,6 +137,7 @@ bool HttpRequestCommand::executeInternal() {
return false; return false;
} }
} }
#endif // ENABLE_SSL
if(getSegments().empty()) { if(getSegments().empty()) {
SharedHandle<HttpRequest> httpRequest SharedHandle<HttpRequest> httpRequest
(createHttpRequest(getRequest(), (createHttpRequest(getRequest(),

View File

@ -178,6 +178,7 @@ bool HttpServerCommand::execute()
!httpServer_->getSocketRecvBuffer()->bufferEmpty()) { !httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
timeoutTimer_ = global::wallclock(); timeoutTimer_ = global::wallclock();
#ifdef ENABLE_SSL
if(httpServer_->getSecure()) { if(httpServer_->getSecure()) {
// tlsAccept() just returns true if handshake has already // tlsAccept() just returns true if handshake has already
// finished. // finished.
@ -187,6 +188,7 @@ bool HttpServerCommand::execute()
return false; return false;
} }
} }
#endif // ENABLE_SSL
SharedHandle<HttpHeader> header; SharedHandle<HttpHeader> header;
header = httpServer_->receiveRequest(); header = httpServer_->receiveRequest();

View File

@ -829,6 +829,8 @@ void SocketCore::readData(char* data, size_t& len)
len = ret; len = ret;
} }
#ifdef ENABLE_SSL
bool SocketCore::tlsAccept() bool SocketCore::tlsAccept()
{ {
return tlsHandshake(svTlsContext_.get(), A2STR::NIL); return tlsHandshake(svTlsContext_.get(), A2STR::NIL);
@ -1162,6 +1164,8 @@ bool SocketCore::tlsHandshake(TLSContext* tlsctx, const std::string& hostname)
return true; return true;
} }
#endif // ENABLE_SSL
ssize_t SocketCore::writeData(const char* data, size_t len, ssize_t SocketCore::writeData(const char* data, size_t len,
const std::string& host, uint16_t port) const std::string& host, uint16_t port)
{ {

View File

@ -109,14 +109,15 @@ private:
void setSockOpt(int level, int optname, void* optval, socklen_t optlen); void setSockOpt(int level, int optname, void* optval, socklen_t optlen);
#ifdef ENABLE_SSL
/** /**
* Makes this socket secure. * Makes this socket secure. The connection must be established
* If the system has not OpenSSL, then this method do nothing. * before calling this method.
* connection must be established before calling this method.
* *
* If you are going to verify peer's certificate, hostname must be supplied. * If you are going to verify peer's certificate, hostname must be supplied.
*/ */
bool tlsHandshake(TLSContext* tlsctx, const std::string& hostname); bool tlsHandshake(TLSContext* tlsctx, const std::string& hostname);
#endif // ENABLE_SSL
SocketCore(sock_t sockfd, int sockType); SocketCore(sock_t sockfd, int sockType);
public: public:
@ -305,6 +306,7 @@ public:
return readDataFrom(reinterpret_cast<char*>(data), len, sender); return readDataFrom(reinterpret_cast<char*>(data), len, sender);
} }
#ifdef ENABLE_SSL
// Performs TLS server side handshake. If handshake is completed, // Performs TLS server side handshake. If handshake is completed,
// returns true. If handshake has not been done yet, returns false. // returns true. If handshake has not been done yet, returns false.
bool tlsAccept(); bool tlsAccept();
@ -315,6 +317,7 @@ public:
// If you are going to verify peer's certificate, hostname must be // If you are going to verify peer's certificate, hostname must be
// supplied. // supplied.
bool tlsConnect(const std::string& hostname); bool tlsConnect(const std::string& hostname);
#endif // ENABLE_SSL
bool operator==(const SocketCore& s) { bool operator==(const SocketCore& s) {
return sockfd_ == s.sockfd_; return sockfd_ == s.sockfd_;