Merge pull request #8793 from Icinga/bugfix/211boost174

Support Boost 1.74
This commit is contained in:
Alexander Aleksandrovič Klimov 2021-05-25 15:26:19 +02:00 committed by GitHub
commit 04d8eee3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 31 additions and 10 deletions

View File

@ -165,6 +165,9 @@ add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED)
# Required for Boost v1.74+
add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
link_directories(${Boost_LIBRARY_DIRS}) link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})

View File

@ -127,6 +127,18 @@ String::operator const std::string&() const
return m_Data; return m_Data;
} }
/**
* Conversion function to boost::string_view.
*
* This allows using String as the value for HTTP headers in boost::beast::http::basic_fields::set.
*
* @return A boost::string_view representing this string.
*/
String::operator boost::string_view() const
{
return boost::string_view(m_Data);
}
const char *String::CStr() const const char *String::CStr() const
{ {
return m_Data.c_str(); return m_Data.c_str();

View File

@ -6,6 +6,7 @@
#include "base/i2-base.hpp" #include "base/i2-base.hpp"
#include "base/object.hpp" #include "base/object.hpp"
#include <boost/range/iterator.hpp> #include <boost/range/iterator.hpp>
#include <boost/utility/string_view.hpp>
#include <string> #include <string>
#include <iosfwd> #include <iosfwd>
@ -71,6 +72,7 @@ public:
bool operator<(const String& rhs) const; bool operator<(const String& rhs) const;
operator const std::string&() const; operator const std::string&() const;
operator boost::string_view() const;
const char *CStr() const; const char *CStr() const;

View File

@ -725,7 +725,11 @@ void Utility::CopyFile(const String& source, const String& target)
{ {
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
#if BOOST_VERSION >= 107400
fs::copy_file(fs::path(source.Begin(), source.End()), fs::path(target.Begin(), target.End()), fs::copy_options::overwrite_existing);
#else /* BOOST_VERSION */
fs::copy_file(fs::path(source.Begin(), source.End()), fs::path(target.Begin(), target.End()), fs::copy_option::overwrite_if_exists); fs::copy_file(fs::path(source.Begin(), source.End()), fs::path(target.Begin(), target.End()), fs::copy_option::overwrite_if_exists);
#endif /* BOOST_VERSION */
} }
/* /*

View File

@ -494,7 +494,7 @@ void ElasticsearchWriter::SendRequest(const String& body)
request.set(http::field::authorization, "Basic " + Base64::Encode(username + ":" + password)); request.set(http::field::authorization, "Basic " + Base64::Encode(username + ":" + password));
request.body() = body; request.body() = body;
request.set(http::field::content_length, request.body().size()); request.content_length(request.body().size());
/* Don't log the request body to debug log, this is already done above. */ /* Don't log the request body to debug log, this is already done above. */
Log(LogDebug, "ElasticsearchWriter") Log(LogDebug, "ElasticsearchWriter")

View File

@ -504,7 +504,7 @@ void InfluxdbWriter::Flush()
request.set(http::field::host, url->GetHost() + ":" + url->GetPort()); request.set(http::field::host, url->GetHost() + ":" + url->GetPort());
request.body() = body; request.body() = body;
request.set(http::field::content_length, request.body().size()); request.content_length(request.body().size());
try { try {
if (stream.first) { if (stream.first) {

View File

@ -84,7 +84,7 @@ bool ConfigFilesHandler::HandleRequest(
response.result(http::status::ok); response.result(http::status::ok);
response.set(http::field::content_type, "application/octet-stream"); response.set(http::field::content_type, "application/octet-stream");
response.body() = content; response.body() = content;
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, params, 500, "Could not read file.", HttpUtility::SendJsonError(response, params, 500, "Could not read file.",
DiagnosticInformation(ex)); DiagnosticInformation(ex));

View File

@ -186,7 +186,7 @@ bool EnsureValidHeaders(
} else { } else {
response.set(http::field::content_type, "text/html"); response.set(http::field::content_type, "text/html");
response.body() = String("<h1>Bad Request</h1><p><pre>") + errorMsg + "</pre></p>"; response.body() = String("<h1>Bad Request</h1><p><pre>") + errorMsg + "</pre></p>";
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} }
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
@ -259,7 +259,7 @@ bool HandleAccessControl(
response.set(http::field::access_control_allow_methods, "GET, POST, PUT, DELETE"); response.set(http::field::access_control_allow_methods, "GET, POST, PUT, DELETE");
response.set(http::field::access_control_allow_headers, "Authorization, X-HTTP-Method-Override"); response.set(http::field::access_control_allow_headers, "Authorization, X-HTTP-Method-Override");
response.body() = "Preflight OK"; response.body() = "Preflight OK";
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
boost::system::error_code ec; boost::system::error_code ec;
@ -290,7 +290,7 @@ bool EnsureAcceptHeader(
response.result(http::status::bad_request); response.result(http::status::bad_request);
response.set(http::field::content_type, "text/html"); response.set(http::field::content_type, "text/html");
response.body() = "<h1>Accept header is missing or not set to 'application/json'.</h1>"; response.body() = "<h1>Accept header is missing or not set to 'application/json'.</h1>";
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
boost::system::error_code ec; boost::system::error_code ec;
@ -331,7 +331,7 @@ bool EnsureAuthenticatedUser(
} else { } else {
response.set(http::field::content_type, "text/html"); response.set(http::field::content_type, "text/html");
response.body() = "<h1>Unauthorized. Please check your user credentials.</h1>"; response.body() = "<h1>Unauthorized. Please check your user credentials.</h1>";
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} }
boost::system::error_code ec; boost::system::error_code ec;
@ -423,7 +423,7 @@ bool EnsureValidBody(
} else { } else {
response.set(http::field::content_type, "text/html"); response.set(http::field::content_type, "text/html");
response.body() = String("<h1>Bad Request</h1><p><pre>") + ec.message() + "</pre></p>"; response.body() = String("<h1>Bad Request</h1><p><pre>") + ec.message() + "</pre></p>";
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} }
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");

View File

@ -58,7 +58,7 @@ void HttpUtility::SendJsonBody(boost::beast::http::response<boost::beast::http::
response.set(http::field::content_type, "application/json"); response.set(http::field::content_type, "application/json");
response.body() = JsonEncode(val, params && GetLastParameter(params, "pretty")); response.body() = JsonEncode(val, params && GetLastParameter(params, "pretty"));
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} }
void HttpUtility::SendJsonError(boost::beast::http::response<boost::beast::http::string_body>& response, void HttpUtility::SendJsonError(boost::beast::http::response<boost::beast::http::string_body>& response,

View File

@ -92,7 +92,7 @@ bool InfoHandler::HandleRequest(
body += R"(<p>More information about API requests is available in the <a href="https://icinga.com/docs/icinga2/latest/" target="_blank">documentation</a>.</p></html>)"; body += R"(<p>More information about API requests is available in the <a href="https://icinga.com/docs/icinga2/latest/" target="_blank">documentation</a>.</p></html>)";
response.body() = body; response.body() = body;
response.set(http::field::content_length, response.body().size()); response.content_length(response.body().size());
} }
return true; return true;