2018-11-03 17:12:20 +01:00
|
|
|
#ifndef CONFIG_H
|
|
|
|
#define CONFIG_H
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <map>
|
|
|
|
#include "permissions.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2019-09-29 20:27:53 +02:00
|
|
|
/* Stuff handlers/ (may) need to know */
|
|
|
|
struct HandlerConfig
|
2019-09-29 17:12:36 +02:00
|
|
|
{
|
2019-09-29 20:27:53 +02:00
|
|
|
Permissions anon_permissions;
|
2018-11-03 17:12:20 +01:00
|
|
|
std::string wikiname;
|
|
|
|
std::string anon_username;
|
2019-10-02 21:40:58 +02:00
|
|
|
std::string page_title_template;
|
2019-09-29 17:12:36 +02:00
|
|
|
int max_pagename_length;
|
|
|
|
int query_limit;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigUrls
|
|
|
|
{
|
2018-11-03 17:12:20 +01:00
|
|
|
std::string linkindex;
|
|
|
|
std::string linkrecent;
|
|
|
|
std::string linkallpages;
|
|
|
|
std::string linkallcats;
|
|
|
|
std::string linkshere;
|
|
|
|
std::string linkpage;
|
2022-03-29 22:37:20 +02:00
|
|
|
std::string linkpagebytitle;
|
2018-11-03 17:12:20 +01:00
|
|
|
std::string linkrevision;
|
|
|
|
std::string linkhistory;
|
|
|
|
std::string linkedit;
|
|
|
|
std::string linksettings;
|
|
|
|
std::string linkdelete;
|
|
|
|
std::string linklogout;
|
|
|
|
std::string linkcategory;
|
|
|
|
std::string loginurl;
|
|
|
|
std::string linkrecentsort;
|
|
|
|
std::string actionurl;
|
|
|
|
std::string settingsurl;
|
|
|
|
std::string deletionurl;
|
|
|
|
std::string linkhistorysort;
|
|
|
|
std::string adminregisterurl;
|
2021-03-26 22:45:09 +01:00
|
|
|
std::string usersettingsurl;
|
2022-03-27 19:50:51 +02:00
|
|
|
std::string rooturl;
|
|
|
|
std::string atomurl;
|
2019-09-29 17:12:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigVariableResolver
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const std::map<std::string, std::string> *configmap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigVariableResolver()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigVariableResolver(const std::map<std::string, std::string> &configmap)
|
|
|
|
{
|
|
|
|
this->configmap = &configmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getConfig(const std::string &key) const
|
|
|
|
{
|
|
|
|
return utils::getKeyOrEmpty(*configmap, key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Config
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::map<std::string, std::string> configmap;
|
|
|
|
std::string required(const std::string &key);
|
|
|
|
|
|
|
|
std::string optional(const std::string &key, std::string defaultvalue = "");
|
|
|
|
int optional(const std::string &key, int defaulvalue);
|
|
|
|
uint64_t optional(const std::string &key, uint64_t defaultvalue);
|
|
|
|
|
|
|
|
public:
|
2019-09-29 20:27:53 +02:00
|
|
|
Config(const std::map<std::string, std::string> &map);
|
|
|
|
|
2019-09-29 17:12:36 +02:00
|
|
|
ConfigUrls urls;
|
|
|
|
ConfigVariableResolver configVarResolver;
|
2019-09-29 20:27:53 +02:00
|
|
|
HandlerConfig handlersConfig;
|
2019-09-29 17:12:36 +02:00
|
|
|
|
|
|
|
std::string wikipath;
|
|
|
|
std::string templatepath;
|
|
|
|
std::string templateprefix;
|
|
|
|
std::string logfile;
|
2018-11-03 17:12:20 +01:00
|
|
|
std::string connectionstring;
|
|
|
|
int session_max_lifetime;
|
|
|
|
int threadscount;
|
2019-05-04 00:02:17 +02:00
|
|
|
|
|
|
|
uint64_t max_payload_length;
|
2018-11-03 17:12:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigReader(const std::string &file);
|
|
|
|
Config readConfig();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONFIG_H
|