From b7e0b79e7ce53bf467b1bcb8d60e86fac509f776 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 4 Nov 2011 03:02:16 +0200 Subject: config.cfg parser --- client/Config.h | 134 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 41 deletions(-) (limited to 'client/Config.h') diff --git a/client/Config.h b/client/Config.h index 3701cd7..c95d9c6 100644 --- a/client/Config.h +++ b/client/Config.h @@ -3,9 +3,12 @@ #ifndef CONFIG_H #define CONFIG_H -#include +#include #include "Proxy.h" +using std::vector; +using std::string; + class ProxyEntryGeneric; class ProxyEntryStatic; @@ -22,10 +25,10 @@ public: /** * @brief Class to represent 'firewall' record in the config file */ - class FirewallRecord + class FirewallEntry { public: - FirewallRecord(): block(false), host("127.0.0.1") + FirewallEntry(): block(false), host("127.0.0.1") { } /** @@ -36,33 +39,7 @@ public: /** * @brief Hostname or address to allow/block access to */ - std::string host; - }; - - /** - * @brief Class to represend 'server' record in the config file - */ - class ServerRecord - { - public: - ServerRecord(): host("127.0.0.1"), timeout(120), retry(60) - { - } - /** - * @brief Hostname or address of server
- * Note that default port is 13666 as specified in SslClient - */ - std::string host; - /** - * @brief Cumulative timeout value (in seconds)
- * When this time is expired then no further attempts is made - * to connect to this particular server - */ - unsigned timeout; - /** - * @brief Time (in seconds) between consecutive retries - */ - unsigned retry; + string host; }; /** @@ -71,6 +48,37 @@ public: */ static Config *CurrentConfig(); + /** + * @brief Time between consecutive program updates + */ + unsigned ClientUpdateInterval; + + /** + * @brief Welcome message that is displayed after program start + */ + string WelcomeMsg; + + /** + * @brief Message that is shown when the config.cfg downloaded/updated + * successfully + */ + string ConfigLoadedMsg; + + /** + * @brief Text that is displayed in as the top panel caption in the UI + */ + string TopPanelText; + + /** + * @brief Text that is displayed in as the bottom panel caption in the UI + */ + string BottomPanelText; + + /** + * @brief Determines whether proxy speed displayed in the UI or not + */ + bool IsSpeedVisible; + /** * @brief Update client configuration * @todo update config periodically on timer events @@ -90,7 +98,7 @@ public: * (generic proxy records only) * @return Alphabetically sorted vector with unique country names */ - std::vector GetCountries(); + vector GetCountries(); /** * @brief Get list of country states where at least one proxy available
@@ -99,7 +107,7 @@ public: * @return Alphabetically sorted vector with unique state names.
* Resultant vector may be empty in case if there are no states in specified country */ - std::vector GetStates(std::string &country); + vector GetStates(std::string &country); /** * @brief Get list of cities in particular country without states
@@ -107,7 +115,7 @@ public: * @param country name of country to get list of states for * @return Alphabetically sorted vector with unique city names */ - std::vector GetCities(std::string &country); + vector GetCities(string &country); /** * @brief Get list of cities in particular country and state
@@ -116,7 +124,7 @@ public: * @param state name of state to get list of cities for * @return Alphabetically sorted vector with unique city names */ - std::vector GetCities(std::string &country, std::string &state); + vector GetCities(string &country, string &state); /** * @brief Get list of proxy server addresses in particular country and city (without states)
@@ -125,7 +133,7 @@ public: * @param city name of city to get list of proxies for * @return Alphabetically sorted vector with unique proxy names */ - std::vector GetProxies(std::string &country, std::string &city); + vector GetProxies(string &country, string &city); /** * @brief Get list of proxy server addresses in particular country, state and city
@@ -135,14 +143,14 @@ public: * @param city name of city to get list of proxies for * @return Alphabetically sorted vector with unique proxy names */ - std::vector GetProxies(std::string &country, std::string &state, std::string &city); + vector GetProxies(string &country, string &state, string &city); /** * @brief Get list of static proxy entries * @param line number of GUI line proxy list associated with * @return List of static proxy entries sorted by speed in descending order */ - std::vector GetStaticProxyGuiLine(unsigned line); + vector GetStaticProxyGuiLine(unsigned line); /** * @brief Get number of static proxy GUI lines @@ -159,12 +167,56 @@ public: protected: Config(); private: + /** + * @brief Class to represend 'server' record in the config file + */ + class ServerEntry + { + public: + /** + * @brief Initialize ServerEntry instance to default values + */ + ServerEntry(); + + /** + * @brief initilize ServerEntry instance from config file entry
+ * @param entry config file entry value, e.g.: '8.8.8.8:8080 600 60' + */ + ServerEntry(string entry); + + /** + * @brief Hostname or address of server
+ * Note that default port is 13666 as specified in SslClient + */ + string host; + + /** + * @brief Cumulative timeout value (in seconds)
+ * When this time is expired then no further attempts is made + * to connect to this particular server + */ + unsigned timeout; + + /** + * @brief Time (in seconds) between consecutive retries + */ + unsigned retry; + }; + + /** + * @brief Pointer to the singleton Config instance + */ static Config *self; + + /** + * @brief time interval between consequtive config updates + */ + unsigned updateInterval; bool configValid; - std::vector genericProxy; - std::vector staticProxy; - std::vector firewallList; - + vector genericProxy; + vector staticProxy; + vector firewalls; + vector servers; int ReadGenericProxy(); int ReadStaticProxy(); }; -- cgit v1.2.3