/* This file is part of libhttpserver Copyright (C) 2011-2019 Sebastiano Merlino This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #if defined(_WIN32) && !defined(__CYGWIN__) #define _WINDOWS #undef _WIN32_WINNT #define _WIN32_WINNT 0x600 #include #include #else #include #include #include #endif #include #include #include #include #include "httpserver/create_webserver.hpp" namespace httpserver { // Defined here (not as a default member // initializer in the header) so the public header carries no // #ifdef HAVE_BAUTH. The library was compiled with the right // HAVE_BAUTH state; the consumer TU's HAVE_BAUTH is irrelevant. bool detail::default_basic_auth_enabled() noexcept { #ifdef HAVE_BAUTH return true; #else return false; #endif } // Same pattern as default_basic_auth_enabled(). Returns true // on HAVE_DAUTH-on builds (preserving historical behaviour) and false // on HAVE_DAUTH-off builds so an unmodified builder doesn't trip the // feature_unavailable guard in webserver::webserver(). bool detail::default_digest_auth_enabled() noexcept { #ifdef HAVE_DAUTH return true; #else return false; #endif } create_webserver& create_webserver::bind_address(const std::string& ip) { _config.bind_address_storage = std::make_shared(); std::memset(_config.bind_address_storage.get(), 0, sizeof(struct sockaddr_storage)); // Try IPv4 first auto* addr4 = reinterpret_cast(_config.bind_address_storage.get()); if (inet_pton(AF_INET, ip.c_str(), &(addr4->sin_addr)) == 1) { addr4->sin_family = AF_INET; addr4->sin_port = htons(_config.port); _config.bind_address = reinterpret_cast(_config.bind_address_storage.get()); return *this; } // Try IPv6 auto* addr6 = reinterpret_cast(_config.bind_address_storage.get()); if (inet_pton(AF_INET6, ip.c_str(), &(addr6->sin6_addr)) == 1) { addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(_config.port); _config.bind_address = reinterpret_cast(_config.bind_address_storage.get()); _config.use_ipv6 = true; return *this; } throw std::invalid_argument("bind_address: invalid IP address: " + ip); } } // namespace httpserver