Skip to content

Commit

Permalink
Fix ".. has no member named ... compile error" (#1938)
Browse files Browse the repository at this point in the history
* Fix ".. has no member named ... compile error" by renaming apache conn_rec
attributes

 - conn_rec attributes remote_ip and remote_addr were replaced by client_ip
 and client_addr once they have been renamed in Apache 2.4
 - a server_rec pointer must be passed to ap_log_error() since apache 2.4,
 therefore, a change was necessary at the ap_log_error log function.
 A null pointer has been passed for avoiding deeper changes at the function.
 - the smart pointer auto_ptr was replaced by unique_ptr once it was made
 deprecated in C++11 standard, it has been replaced by unique_ptr.

* Add the properly #ifdef directives for backward compatibility purposes

 - Adding proper #ifdef preprocessor directives to keeping backward
 compatibility with older apache versions.

* Update ApacheConnector.cpp
  • Loading branch information
edson-a-soares authored and aleks-f committed Oct 17, 2017
1 parent 4a8d522 commit 7121b92
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions ApacheConnector/src/ApacheConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ void ApacheRequestRec::copyHeaders(ApacheServerRequest& request)

void ApacheConnector::log(const char* file, int line, int level, int status, const char *text)
{
ap_log_error(file, line, level, 0, NULL, "%s", text);
// ap_log_error() has undergone significant changes in Apache 2.4.
// Validate Apache version for using a proper ap_log_error() version.
#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER < 4
ap_log_error(file, line, level, 0, NULL, "%s", text);
#else
ap_log_error(file, line, level, 0, NULL, 0, text);
#endif
}


Expand All @@ -170,23 +176,34 @@ extern "C" int ApacheConnector_handler(request_rec *r)

apr_status_t rv;
if ((rv = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)))
return rv;

std::auto_ptr<ApacheServerRequest> pRequest(new ApacheServerRequest(
&rec,
r->connection->local_ip,
r->connection->local_addr->port,
r->connection->remote_ip,
r->connection->remote_addr->port));

std::auto_ptr<ApacheServerResponse> pResponse(new ApacheServerResponse(pRequest.get()));
return rv;

// The properties conn_rec->remote_ip and conn_rec->remote_addr have undergone significant changes in Apache 2.4.
// Validate Apache version for using conn_rec->remote_ip and conn_rec->remote_addr proper versions.
#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER < 4
std::unique_ptr<ApacheServerRequest> pRequest(new ApacheServerRequest(
&rec,
r->connection->local_ip,
r->connection->local_addr->port,
r->connection->remote_ip,
r->connection->remote_addr->port));
#else
std::unique_ptr<ApacheServerRequest> pRequest(new ApacheServerRequest(
&rec,
r->connection->local_ip,
r->connection->local_addr->port,
r->connection->client_ip,
r->connection->client_addr->port));
#endif

std::unique_ptr<ApacheServerResponse> pResponse(new ApacheServerResponse(pRequest.get()));

// add header information to request
rec.copyHeaders(*pRequest);

try
{
std::auto_ptr<HTTPRequestHandler> pHandler(app.factory().createRequestHandler(*pRequest));
std::unique_ptr<HTTPRequestHandler> pHandler(app.factory().createRequestHandler(*pRequest));

if (pHandler.get())
{
Expand Down

0 comments on commit 7121b92

Please sign in to comment.