123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #ifndef ECCONFIGIMPL_H
- #define ECCONFIGIMPL_H
- #include <kopano/zcdefs.h>
- using namespace std;
- #include <kopano/ECConfig.h>
- #include <map>
- #include <set>
- #include <list>
- #include <string>
- #include <cstring>
- #include <pthread.h>
- #include <iostream>
- #include <fstream>
- #include <kopano/lockhelper.hpp>
- namespace KC {
- struct settingkey_t {
- char s[256];
- unsigned short ulFlags;
- unsigned short ulGroup;
- };
- struct settingcompare {
- bool operator()(const settingkey_t &a, const settingkey_t &b) const
- {
- return strcmp(a.s, b.s) < 0;
- }
- };
- #define MAXLINELEN 4096
- class ECConfigImpl;
- typedef std::map<settingkey_t, char*, settingcompare> settingmap_t;
- typedef bool (ECConfigImpl::*directive_func_t)(const char *, unsigned int);
- struct directive_t {
- const char *lpszDirective;
- directive_func_t fExecute;
- };
- #define LOADSETTING_INITIALIZING 0x0001
- #define LOADSETTING_UNKNOWN 0x0002
- #define LOADSETTING_OVERWRITE 0x0004
- #define LOADSETTING_OVERWRITE_GROUP 0x0008
- #define LOADSETTING_OVERWRITE_RELOAD 0x0010
- #define LOADSETTING_CMDLINE_PARAM 0x0020
- class ECConfigImpl _kc_final : public ECConfig {
- public:
- ECConfigImpl(const configsetting_t *lpDefaults, const char *const *lpszDirectives);
- ~ECConfigImpl();
- bool LoadSettings(const char *file) _kc_override;
- virtual int ParseParams(int argc, char **argv) _kc_override;
- const char *GetSettingsPath(void) _kc_override { return m_szConfigFile; }
- bool ReloadSettings(void) _kc_override;
- bool AddSetting(const char *name, const char *value, const unsigned int group = 0) _kc_override;
- const char *GetSetting(const char *name) _kc_override;
- const char *GetSetting(const char *name, const char *equal, const char *other) _kc_override;
- const wchar_t *GetSettingW(const char *name) _kc_override;
- const wchar_t *GetSettingW(const char *name, const wchar_t *equal, const wchar_t *other) _kc_override;
- std::list<configsetting_t> GetSettingGroup(unsigned int group) _kc_override;
- std::list<configsetting_t> GetAllSettings(void) _kc_override;
- bool HasWarnings(void) _kc_override;
- const std::list<std::string> *GetWarnings(void) _kc_override { return &warnings; }
- bool HasErrors(void) _kc_override;
- const std::list<std::string> *GetErrors(void) _kc_override { return &errors; }
- private:
- bool InitDefaults(unsigned int ulFlags);
- bool InitConfigFile(unsigned int ulFlags);
- bool ReadConfigFile(const std::string &file, unsigned int ulFlags, unsigned int ulGroup = 0);
- bool HandleDirective(const std::string &strLine, unsigned int ulFlags);
- bool HandleInclude(const char *lpszArgs, unsigned int ulFlags);
- bool HandlePropMap(const char *lpszArgs, unsigned int ulFlags);
- size_t GetSize(const char *szValue);
- void InsertOrReplace(settingmap_t *lpMap, const settingkey_t &s, const char* szValue, bool bIsSize);
- const char *GetMapEntry(const settingmap_t *lpMap, const char *szName);
- const char *GetAlias(const char *szAlias);
- bool AddSetting(const configsetting_t *lpsConfig, unsigned int ulFlags);
- void AddAlias(const configsetting_t *lpsAlias);
- void CleanupMap(settingmap_t *lpMap);
- bool CopyConfigSetting(const configsetting_t *lpsSetting, settingkey_t *lpsKey);
- bool CopyConfigSetting(const settingkey_t *lpsKey, const char *szValue, configsetting_t *lpsSetting);
- const configsetting_t *m_lpDefaults;
- const char *m_szConfigFile = nullptr;
- std::list<std::string> m_lDirectives;
-
- KC::shared_mutex m_settingsRWLock;
- settingmap_t m_mapSettings;
- settingmap_t m_mapAliases;
- std::list<std::string> warnings;
- std::list<std::string> errors;
- std::string m_currentFile;
- std::set<std::string> m_readFiles;
- typedef std::map<const char*, std::wstring> ConvertCache;
- ConvertCache m_convertCache;
- static const directive_t s_sDirectives[];
- };
- }
- #endif
|