text:
#include <nano/boost/asio/bind_executor.hpp>
#include <nano/rpc/rpc_connection_secure.hpp>
#include <nano/rpc/rpc_secure.hpp>

#include <boost/format.hpp>
#include <boost/polymorphic_pointer_cast.hpp>

#include <iostream>

bool nano::rpc_secure::on_verify_certificate (bool preverified, boost::asio::ssl::verify_context & ctx)
{
	X509_STORE_CTX * cts = ctx.native_handle ();
	auto error (X509_STORE_CTX_get_error (cts));
	switch (error)
	{
		case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
			logger.always_log ("TLS: Unable to get issuer");
			break;
		case X509_V_ERR_CERT_NOT_YET_VALID:
		case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
			logger.always_log ("TLS: Certificate not yet valid");
			break;
		case X509_V_ERR_CERT_HAS_EXPIRED:
		case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
			logger.always_log ("TLS: Certificate expired");
			break;
		case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
			if (config.secure.verbose_logging)
			{
				logger.always_log ("TLS: self signed certificate in chain");
			}

			// Allow self-signed certificates
			preverified = true;
			break;
		case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
			logger.always_log ("TLS: Self signed certificate not in the list of trusted certs (forgot to subject-hash certificate filename?)");
			break;
		default:
			break;
	}

	if (config.secure.verbose_logging)
	{
		if (error != 0)
		{
			logger.always_log ("TLS: Error: ", X509_verify_cert_error_string (error));
			logger.always_log ("TLS: Error chain depth : ", X509_STORE_CTX_get_error_depth (cts));
		}

		X509 * cert = X509_STORE_CTX_get_current_cert (cts);
		char subject_name[512];
		X509_NAME_oneline (X509_get_subject_name (cert), subject_name, sizeof (subject_name) - 1);
		logger.always_log ("TLS: Verifying: ", subject_name);
		logger.always_log ("TLS: Verification: ", preverified);
	}
	else if (!preverified)
	{
		logger.always_log ("TLS: Pre-verification failed. Turn on verbose logging for more information.");
	}

	return preverified;
}

void nano::rpc_secure::load_certs (boost::asio::ssl::context & context_a)
{
	try
	{
		// This is called if the key is password protected
		context_a.set_password_callback (
		[this] (std::size_t,
		boost::asio::ssl::context_base::password_purpose) {
			return config.secure.server_key_passphrase;
		});

		// The following two options disables the session cache and enables stateless session resumption.
		// This is necessary because of the way the RPC server abruptly terminate connections.
		SSL_CTX_set_session_cache_mode (context_a.native_handle (), SSL_SESS_CACHE_OFF);
		SSL_CTX_set_options (context_a.native_handle (), SSL_OP_NO_TICKET);

		context_a.set_options (
		boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::no_sslv3 | boost::asio::ssl::context::single_dh_use);

		context_a.use_certificate_chain_file (config.secure.server_cert_path);
		context_a.use_private_key_file (config.secure.server_key_path, boost::asio::ssl::context::pem);
		context_a.use_tmp_dh_file (config.secure.server_dh_path);

		// Verify client certificates?
		if (!config.secure.client_certs_path.empty ())
		{
			context_a.set_verify_mode (boost::asio::ssl::verify_fail_if_no_peer_cert | boost::asio::ssl::verify_peer);
			context_a.add_verify_path (config.secure.client_certs_path);
			context_a.set_verify_callback ([this] (auto preverified, auto & ctx) {
				return this->on_verify_certificate (preverified, ctx);
			});
		}
	}
	catch (boost::system::system_error const & err)
	{
		auto error (boost::str (boost::format ("Could not load certificate information: %1%. Make sure the paths in the secure rpc configuration are correct.") % err.what ()));
		std::cerr << error << std::endl;
		logger.always_log (error);
	}
}

nano::rpc_secure::rpc_secure (boost::asio::io_context & context_a, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a) :
	rpc (context_a, config_a, rpc_handler_interface_a),
	ssl_context (boost::asio::ssl::context::tlsv12_server)
{
	load_certs (ssl_context);
}

void nano::rpc_secure::accept ()
{
	auto connection (std::make_shared<nano::rpc_connection_secure> (config, io_ctx, logger, rpc_handler_interface, this->ssl_context));
	acceptor.async_accept (connection->socket, boost::asio::bind_executor (connection->strand, [this, connection] (boost::system::error_code const & ec) {
		if (ec != boost::asio::error::operation_aborted && acceptor.is_open ())
		{
			accept ();
		}
		if (!ec)
		{
			connection->parse_connection ();
		}
		else
		{
			logger.always_log (boost::str (boost::format ("Error accepting RPC connections: %1%") % ec));
		}
	}));
}


text:
#include <boost/bimap.hpp>
#include <string>
#include <unordered_map>

#include "sql/Expr.h"
#include "sql/SelectStatement.h"

#include "all_type_variant.hpp"
#include "expression/function_expression.hpp"
#include "types.hpp"

namespace opossum {

enum class EncodingType : uint8_t;
enum class VectorCompressionType : uint8_t;
enum class AggregateFunction;
enum class ExpressionType;
enum class TableType;

extern const boost::bimap<PredicateCondition, std::string> predicate_condition_to_string;
extern const std::unordered_map<OrderByMode, std::string> order_by_mode_to_string;
extern const std::unordered_map<hsql::OrderType, OrderByMode> order_type_to_order_by_mode;
extern const std::unordered_map<ExpressionType, std::string> expression_type_to_operator_string;
extern const std::unordered_map<JoinMode, std::string> join_mode_to_string;
extern const std::unordered_map<UnionMode, std::string> union_mode_to_string;
extern const boost::bimap<AggregateFunction, std::string> aggregate_function_to_string;
extern const boost::bimap<FunctionType, std::string> function_type_to_string;
extern const boost::bimap<DataType, std::string> data_type_to_string;
extern const boost::bimap<EncodingType, std::string> encoding_type_to_string;
extern const boost::bimap<VectorCompressionType, std::string> vector_compression_type_to_string;
extern const boost::bimap<TableType, std::string> table_type_to_string;

}  // namespace opossum

ext: hpp

max_stars_repo_name: nilsthamm/hyrise

max_issues_repo_name: nilsthamm/hyrise

max_forks_repo_name: nilsthamm/hyrise


text:
#include <iostream>
#include <iterator>
#include <map>
#include <boost/foreach.hpp>
#include <algorithm>

template <typename Iterator, typename Tag> struct iterator_adapter;

// Modern C++, no way to hide...
// Just like calling a function dont_call_me_XXXX()
namespace detail {
struct value_iterator_tag {};
}

template <typename AdapterIterator, typename BaseIterator>
class iterator_adapter_base {
public:
	bool operator==(iterator_adapter_base const& o) const
	{
		return base_iter_ == o.base_iter_;
	}

	bool operator!=(iterator_adapter_base const& o) const
	{
		return base_iter_ != o.base_iter_;
	}

	bool operator<(iterator_adapter_base const& o) const
	{
		return base_iter_ < o.base_iter_;
	}

	bool operator<=(iterator_adapter_base const& o) const
	{
		return base_iter_ <= o.base_iter_;
	}

	bool operator>=(iterator_adapter_base const& o) const
	{
		return base_iter_ >= o.base_iter_;
	}

	AdapterIterator & operator++()
	{
		++base_iter_;
		// oh my...
		return *static_cast<AdapterIterator*>(this);
	}

	// overload crap...
	AdapterIterator operator++(int)
	{
		AdapterIterator res(base_iter_);
		++base_iter_;
		return res;
	}

	AdapterIterator & operator--()
	{
		--base_iter_;
		return *this;
	}

	AdapterIterator operator--(int)
	{
		AdapterIterator res(base_iter_);
		--base_iter_;
		return res;
	}

protected:
	iterator_adapter_base()
	:
		base_iter_()
	{ }

	iterator_adapter_base(BaseIterator const& base_iter)
	:
		base_iter_(base_iter)
	{ }

	BaseIterator base_iter_;
};

template <typename Iterator>
// Yeah looks sophisticated, doesn't it? Sophisticate my arse!
class iterator_adapter<Iterator, detail::value_iterator_tag> : public iterator_adapter_base<iterator_adapter<Iterator, detail::value_iterator_tag>, Iterator > {
public:
	// STL is just broken...
	typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
	typedef typename std::iterator_traits<Iterator>::value_type::second_type value_type;
	typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
	// uhrg yes well you see it's a const iterator, but there is this std::pair...
	typedef typename std::iterator_traits<Iterator>::value_type::second_type const* pointer;
	typedef typename std::iterator_traits<Iterator>::value_type::second_type const& reference;

	iterator_adapter() { }

	iterator_adapter(Iterator const& base_iter)
	:
		// Well we don't know what this means, could be anything... so please be explicit.
		iterator_adapter_base<iterator_adapter<Iterator, detail::value_iterator_tag>, Iterator >(base_iter)
	{ }

	iterator_adapter(iterator_adapter const& o)
	:
		// Oh, and mark the space at the end. C++1X finally did away with this HOORAYY! (srysly?)
		iterator_adapter_base<iterator_adapter<Iterator, detail::value_iterator_tag>, Iterator >(o.base_iter_)
	{ }

	iterator_adapter & operator=(iterator_adapter const& o)
	{
		// Again... what is base_iter_? ahh *this* one.
		this->base_iter_ = o.base_iter_;
		return *this;
	}

	reference operator*() const
	{
		return this->base_iter_->second;
	}

	pointer operator->() const
	{
		// Looks beautiful doesn't it?
		return &(this->base_iter_->second);
	}
};

template <typename Iterator>
iterator_adapter<Iterator, detail::value_iterator_tag> make_value_iterator(Iterator const& it)
{
	return iterator_adapter<Iterator, detail::value_iterator_tag>(it);
}

detail::value_iterator_tag value_adapter;

template <typename ContainerT, typename Tag>
struct range_adaptor;

template <typename ContainerT, typename Tag>
struct range_adaptor {
	range_adaptor(ContainerT & container)
	:
		begin_(container.begin()),
		end_(container.end())
	{ }

	range_adaptor(ContainerT const& container)
	:
		cbegin_(container.begin()),
		cend_(container.end())
	{ }

	// needed
	range_adaptor(range_adaptor const& o)
	{ }

	// I just *love* the typename shit.
	typedef iterator_adapter<typename ContainerT::iterator, Tag> iterator;
	typedef iterator_adapter<typename ContainerT::const_iterator, Tag> const_iterator;

	iterator begin()
	{
		return begin_;
	}

	iterator end()
	{
		return end_;
	}

	const_iterator begin() const
	{
		return cbegin_;
	}

	const_iterator end() const
	{
		return cend_;
	}

private:
	range_adaptor() {}
	range_adaptor & operator=(range_adaptor const&) {}

	iterator begin_;
	iterator end_;
	// meh. giving up.
	const_iterator cbegin_;
	const_iterator cend_;
};

// Yay let's overload some operators. 'Cause you know: *frameworks*
template <typename ContainerT, typename Tag>
range_adaptor<ContainerT, Tag> operator|(ContainerT const& container, Tag)
{
	return range_adaptor<ContainerT, Tag>(container);
}

template <typename ContainerT, typename Tag>
range_adaptor<ContainerT, Tag> operator|(ContainerT & container, Tag)
{
	return range_adaptor<ContainerT, Tag>(container);
}

void foo(bool const&)
{
}

int main()
{
	typedef std::map<int, bool> map_type;
	map_type m;

	// Now any decent language has had this since 1995.
	BOOST_FOREACH(bool x, m | value_adapter) {
		(void) x;
	}

	BOOST_FOREACH(bool const& x, m | value_adapter) {
		(void) x;
	}

#if 0
	// ahhrgg... it's still essentially broken...
	BOOST_FOREACH(bool & x, m | value_adapter) {
		(void) x;
	}
#endif
	std::for_each(make_value_iterator(m.begin()), make_value_iterator(m.end()), foo);

	return 0;
}

ext: cc

max_stars_repo_name: afett/iterator-fun

max_issues_repo_name: afett/iterator-fun

max_forks_repo_name: afett/iterator-fun