00001
00002
00003
00004
00005
00006
00007 #ifndef __WVCONFEMU_H
00008 #define __WVCONFEMU_H
00009
00010
00011 #include "uniconfroot.h"
00012 #include "wvstringtable.h"
00013 #include "wvsorter.h"
00014
00015 #define WvConf WvConfEmu
00016 #define WvConfigSection WvConfigSectionEmu
00017 #define WvConfigSectionList WvConfigSectionListEmu
00018 #define WvConfigEntry WvConfigEntryEmu
00019 #define WvConfigEntryList WvConfigEntryListEmu
00020
00021
00022 class WvConfEmu;
00023 class WvConfigEntryEmu;
00024 class WvConfigSectionEmu;
00025 class WvAuthDaemon;
00026 class WvAuthDaemonSvc;
00027
00028 typedef WvConfEmu WvConfigSectionListEmu;
00029 typedef WvConfigSectionEmu WvConfigEntryListEmu;
00030
00031
00032 class WvConfigEntryEmu
00033 {
00034 public:
00035 const WvString name;
00036 WvString value;
00037 WvConfigEntryEmu(WvStringParm _name, WvStringParm _value):
00038 name(_name), value(_value)
00039 {}
00040 };
00041
00042
00043 DeclareWvDict(WvConfigEntryEmu, WvString, name);
00044
00045
00046 class WvConfigSectionEmu
00047 {
00048 private:
00049 const UniConf uniconf;
00050 WvConfigEntryEmuDict entries;
00051 WvStringTable &values;
00052 public:
00053 const WvString name;
00054 WvConfigSectionEmu(const UniConf& _uniconf, WvStringParm _name,
00055 WvStringTable *_values):
00056 uniconf(_uniconf), entries(42), values(*_values), name(_name)
00057 {}
00058 WvConfigEntryEmu *operator[] (WvStringParm s);
00059 const char *get(WvStringParm entry, const char *def_val = NULL);
00060 void set(WvStringParm entry, WvStringParm value);
00061 void quick_set(WvStringParm entry, WvStringParm value);
00062
00063 bool isempty() const;
00064
00065 class Iter;
00066 friend class Iter;
00067
00068 typedef WvSorter<WvConfigEntryEmu, WvConfigSectionEmu, Iter> Sorter;
00069 };
00070
00071
00072 DeclareWvDict(WvConfigSectionEmu, WvString, name);
00073
00074
00075 class WvConfigSectionEmu::Iter
00076 {
00077 private:
00078 WvConfigSectionEmu& sect;
00079 UniConf::RecursiveIter iter;
00080 WvLink link;
00081 WvConfigEntryEmu* entry;
00082 public:
00083 Iter(WvConfigSectionEmu& _sect):
00084 sect(_sect), iter(_sect.uniconf), link(NULL, false), entry(NULL)
00085 {
00086 assert(&_sect);
00087 }
00088 ~Iter();
00089 void rewind();
00090 WvLink *next();
00091 WvLink *cur();
00092 WvConfigEntryEmu* ptr() const;
00093 void* vptr() const;
00094 WvIterStuff(WvConfigEntryEmu);
00095 };
00096
00097
00098
00099 typedef WvCallback<void, void*, WvStringParm, WvStringParm, WvStringParm, WvStringParm> WvConfCallback;
00100
00101
00102 class WvConfEmu
00103 {
00104 private:
00105 struct CallbackInfo
00106 {
00107 WvConfCallback callback;
00108 void* userdata;
00109 WvString section;
00110 WvString key;
00111 void* cookie;
00112 CallbackInfo(WvConfCallback _callback, void* _userdata,
00113 WvStringParm _section, WvStringParm _key,
00114 void* _cookie):
00115 callback(_callback), userdata(_userdata), section(_section),
00116 key(_key), cookie(_cookie)
00117 {}
00118 };
00119
00120 WvConfigSectionEmuDict sections;
00121 bool hold;
00122 bool dirty;
00123 WvList<CallbackInfo> callbacks;
00124 WvStringTable values;
00125
00126 void notify(const UniConf &_uni, const UniConfKey &_key);
00127 public:
00128 const UniConf uniconf;
00129
00130 WvConfEmu(const UniConf &_uniconf);
00131 ~WvConfEmu();
00132 void zap();
00133 bool isclean() const;
00134 bool isok() const;
00135 void load_file(WvStringParm filename);
00136 void save(WvStringParm filename, int _create_mode = 0666);
00137 void save();
00138 void flush();
00139
00140 WvConfigSectionEmu *operator[] (WvStringParm sect);
00141
00142 void add_callback(WvConfCallback callback, void *userdata,
00143 WvStringParm section, WvStringParm key, void *cookie);
00144 void del_callback(WvStringParm section, WvStringParm key, void *cookie);
00145
00146 void add_setbool(bool *b, WvStringParm _section, WvStringParm _key);
00147 void del_setbool(bool *b, WvStringParm _section, WvStringParm _key);
00148
00149
00150
00151
00152 void add_addname(WvStringList *list, WvStringParm sect, WvStringParm ent);
00153 void del_addname(WvStringList *list, WvStringParm sect, WvStringParm ent);
00154
00155 WvString getraw(WvString wvconfstr, int &parse_error);
00156 int getint(WvStringParm section, WvStringParm entry, int def_val);
00157 const char *get(WvStringParm section, WvStringParm entry,
00158 const char *def_val = NULL);
00159 int fuzzy_getint(WvStringList §, WvStringParm entry,
00160 int def_val);
00161 const char *fuzzy_get(WvStringList §, WvStringParm entry,
00162 const char *def_val = NULL);
00163
00164 void setraw(WvString wvconfstr, const char *&value, int &parse_error);
00165 void setint(WvStringParm section, WvStringParm entry, int value);
00166 void set(WvStringParm section, WvStringParm entry,
00167 const char *value);
00168
00169 void maybesetint(WvStringParm section, WvStringParm entry,
00170 int value);
00171 void maybeset(WvStringParm section, WvStringParm entry,
00172 const char *value);
00173
00174 void delete_section(WvStringParm section);
00175
00176
00177 WvString get_passwd(WvStringParm sect, WvStringParm user);
00178 WvString get_passwd(WvStringParm user)
00179 { return get_passwd("Users", user); }
00180 WvString get_passwd2(WvString pwenc);
00181
00182
00183
00184
00185
00186
00187
00188 bool check_passwd(WvStringParm sect, WvStringParm user,
00189 WvStringParm passwd, WvStream *s);
00190 bool check_passwd(WvStringParm user, WvStringParm passwd, WvStream *s)
00191 {
00192 return check_passwd("Users", user, passwd, s);
00193 }
00194
00195
00196 bool user_exists(WvStringParm sect, WvStringParm user);
00197 bool user_exists(WvStringParm user)
00198 {
00199 return user_exists("Users", user);
00200 }
00201
00202
00203 void set_passwd(WvStringParm sect, WvStringParm user, WvStringParm passwd);
00204 void set_passwd(WvStringParm user, WvStringParm passwd)
00205 { set_passwd("Users", user, passwd); }
00206 WvString set_passwd2(WvStringParm passwd);
00207
00208
00209 void convert_to_old_pw();
00210
00211 static int check_for_bool_string(const char *s);
00212
00213 class Iter;
00214 friend class Iter;
00215
00216 private:
00217
00218
00219
00220
00221
00222
00223
00224
00225 private:
00226 WvAuthDaemon *wvauthd;
00227 public:
00228 friend class WvAuthDaemonSvc;
00229 };
00230
00231
00232 class WvConfEmu::Iter
00233 {
00234 WvConfEmu& conf;
00235 UniConf::Iter iter;
00236 WvLink link;
00237 public:
00238 Iter(WvConfEmu& _conf):
00239 conf(_conf), iter(conf.uniconf), link(NULL, false)
00240 {}
00241 void rewind();
00242 WvLink *next();
00243 WvConfigSectionEmu* ptr() const;
00244 WvIterStuff(WvConfigSectionEmu);
00245 };
00246
00247
00248 #endif // __WVCONFEMU_H