| 1 | #ifndef authconfigfile_h |
| 2 | #define authconfigfile_h |
| 3 | |
| 4 | #if HAVE_CONFIG_H |
| 5 | #include "courier_auth_config.h" |
| 6 | #endif |
| 7 | |
| 8 | #include <time.h> |
| 9 | #if HAVE_SYS_TIME_H |
| 10 | #include <sys/time.h> |
| 11 | #endif |
| 12 | |
| 13 | #include <string> |
| 14 | #include <sstream> |
| 15 | #include <map> |
| 16 | |
| 17 | namespace courier { |
| 18 | namespace auth { |
| 19 | #if 0 |
| 20 | } |
| 21 | } |
| 22 | #endif |
| 23 | |
| 24 | class config_file { |
| 25 | |
| 26 | protected: |
| 27 | const char *filename; |
| 28 | |
| 29 | std::map<std::string, std::string> parsed_config; |
| 30 | private: |
| 31 | bool loaded; |
| 32 | time_t config_timestamp; |
| 33 | |
| 34 | public: |
| 35 | config_file(const char *filenameArg); |
| 36 | bool load(bool reload=false); |
| 37 | |
| 38 | private: |
| 39 | virtual bool do_load()=0; |
| 40 | virtual void do_reload()=0; |
| 41 | |
| 42 | class isspace; |
| 43 | class not_isspace; |
| 44 | |
| 45 | bool open_and_load_file(bool reload); |
| 46 | |
| 47 | public: |
| 48 | |
| 49 | |
| 50 | template<typename value_type> |
| 51 | bool config(const char *name, |
| 52 | value_type &value, |
| 53 | bool required, |
| 54 | const char *default_value=0) |
| 55 | const |
| 56 | { |
| 57 | std::string string_value; |
| 58 | |
| 59 | if (!getconfig(name, string_value, required, default_value)) |
| 60 | return false; |
| 61 | |
| 62 | std::istringstream i(string_value); |
| 63 | |
| 64 | i >> value; |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | std::string config(const char *name) const; |
| 69 | std::string config(const char *name, const char *default_value) const; |
| 70 | |
| 71 | bool getconfig(const char *name, |
| 72 | std::string &value, |
| 73 | bool required, |
| 74 | const char *default_value=0) const; |
| 75 | |
| 76 | static std::string expand_string(const std::string &s, |
| 77 | const std::map<std::string, |
| 78 | std::string> ¶meters); |
| 79 | |
| 80 | static std::string |
| 81 | parse_custom_query(const std::string &s, |
| 82 | const std::string &login, |
| 83 | const std::string &defdomain, |
| 84 | std::map<std::string, |
| 85 | std::string> ¶meters); |
| 86 | }; |
| 87 | |
| 88 | template<> |
| 89 | bool config_file::config(const char *name, |
| 90 | std::string &value, |
| 91 | bool required, |
| 92 | const char *default_value) const; |
| 93 | |
| 94 | #if 0 |
| 95 | { |
| 96 | { |
| 97 | #endif |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | #endif |