Added authentication backends: internal, pam and http-headers. fixes #119
This commit is contained in:
@@ -18,9 +18,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
// Used to get config values from configuration files
|
||||
class IConfig
|
||||
@@ -30,11 +29,11 @@ class IConfig
|
||||
virtual ~IConfig() = default;
|
||||
|
||||
// Default values are returned in case of setting not found
|
||||
virtual std::string getString(const std::string& setting, const std::string& def = "", const std::unordered_set<std::string>& allowedValues = {}) = 0;
|
||||
virtual std::filesystem::path getPath(const std::string& setting, const std::filesystem::path& def = std::filesystem::path()) = 0;
|
||||
virtual unsigned long getULong(const std::string& setting, unsigned long def = 0) = 0;
|
||||
virtual long getLong(const std::string& setting, long def = 0) = 0;
|
||||
virtual bool getBool(const std::string& setting, bool def = false) = 0;
|
||||
virtual std::string_view getString(std::string_view setting, std::string_view def = "") = 0;
|
||||
virtual std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def = std::filesystem::path()) = 0;
|
||||
virtual unsigned long getULong(std::string_view setting, unsigned long def = 0) = 0;
|
||||
virtual long getLong(std::string_view setting, long def = 0) = 0;
|
||||
virtual bool getBool(std::string_view setting, bool def = false) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
// API compatible with shared_mutex
|
||||
class RecursiveSharedMutex
|
||||
{
|
||||
public:
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void lock_shared();
|
||||
void unlock_shared();
|
||||
|
||||
private:
|
||||
std::shared_mutex _mutex;
|
||||
std::thread::id _uniqueOwner;
|
||||
std::size_t _uniqueCount{};
|
||||
|
||||
std::mutex _sharedCountMutex;
|
||||
std::unordered_map<std::thread::id, std::size_t> _sharedCounts;
|
||||
};
|
||||
|
||||
@@ -26,6 +26,7 @@ template <typename Class>
|
||||
class Service
|
||||
{
|
||||
public:
|
||||
Service() = default;
|
||||
Service(std::unique_ptr<Class> service)
|
||||
{
|
||||
assign(std::move(service));
|
||||
@@ -52,14 +53,17 @@ class Service
|
||||
}
|
||||
|
||||
static Class* get() { return _service.get(); }
|
||||
static bool exists() { return _service.get(); }
|
||||
|
||||
private:
|
||||
static Class& assign(std::unique_ptr<Class> service)
|
||||
template <typename SubClass>
|
||||
static Class& assign(std::unique_ptr<SubClass> service)
|
||||
{
|
||||
assert(!_service);
|
||||
_service = std::move(service);
|
||||
return *get();
|
||||
}
|
||||
|
||||
private:
|
||||
static void clear() { _service.reset(); }
|
||||
|
||||
static inline std::unique_ptr<Class> _service;
|
||||
|
||||
Reference in New Issue
Block a user