2019-01-22 14:13:26 +00:00
|
|
|
#ifndef LOKINET_BOOTSERV_CONFIG_HPP
|
|
|
|
#define LOKINET_BOOTSERV_CONFIG_HPP
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
#include <util/string_view.hpp>
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <unordered_map>
|
2018-08-01 02:20:40 +00:00
|
|
|
#include <vector>
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
namespace llarp
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-01-22 14:13:26 +00:00
|
|
|
struct ConfigParser
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2019-02-24 02:45:40 +00:00
|
|
|
using String_t = llarp::string_view;
|
|
|
|
using Section_t =
|
|
|
|
std::unordered_multimap< String_t, String_t, string_view_hash >;
|
|
|
|
using Config_impl_t =
|
|
|
|
std::unordered_map< String_t, Section_t, string_view_hash >;
|
2019-01-22 14:13:26 +00:00
|
|
|
/// clear parser
|
|
|
|
void
|
|
|
|
Clear();
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
/// load config file for bootserv
|
|
|
|
/// return true on success
|
|
|
|
/// return false on error
|
|
|
|
bool
|
2019-07-02 21:28:28 +00:00
|
|
|
LoadFile(string_view fname);
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
/// load from string
|
|
|
|
/// return true on success
|
|
|
|
/// return false on error
|
|
|
|
bool
|
2019-07-02 21:28:28 +00:00
|
|
|
LoadString(string_view str);
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
/// iterate all sections and thier values
|
2018-08-01 02:20:40 +00:00
|
|
|
void
|
2019-01-22 14:13:26 +00:00
|
|
|
IterAll(std::function< void(const String_t&, const Section_t&) > visit);
|
2018-08-01 02:20:40 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
/// visit a section in config read only by name
|
|
|
|
/// return false if no section or value propagated from visitor
|
2018-08-01 02:20:40 +00:00
|
|
|
bool
|
2019-01-22 14:13:26 +00:00
|
|
|
VisitSection(const char* name,
|
|
|
|
std::function< bool(const Section_t&) > visit) const;
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
private:
|
2019-01-22 14:13:26 +00:00
|
|
|
bool
|
|
|
|
Parse();
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
std::vector< char > m_Data;
|
|
|
|
Config_impl_t m_Config;
|
2019-05-03 13:39:25 +00:00
|
|
|
std::string m_FileName;
|
2018-05-22 15:54:19 +00:00
|
|
|
};
|
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
} // namespace llarp
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2019-01-22 14:13:26 +00:00
|
|
|
#endif
|