00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __WVCONF_H
00013 #define __WVCONF_H
00014
00015 #include "strutils.h"
00016 #include "wvlinklist.h"
00017 #include "wvlog.h"
00018 #include "wvstringlist.h"
00019 #include "wvtr1.h"
00020
00021
00022 #ifdef __WVCONFEMU_H
00023 #warning "disabling wvconfemu transparent emulation"
00024 #undef WvConf
00025 #undef WvConfigSection
00026 #undef WvConfigSectionList
00027 #undef WvConfigEntry
00028 #undef WvConfigEntryList
00029 #endif
00030
00031
00032 class WvConf;
00033
00034
00035 class WvConfigEntry
00036 {
00037 public:
00038 WvConfigEntry();
00039 WvConfigEntry(WvStringParm _name, WvStringParm _value);
00040 ~WvConfigEntry();
00041
00042 void set(WvStringParm _value)
00043 { value = _value; }
00044
00045 WvString name;
00046 WvString value;
00047 };
00048
00049
00050 DeclareWvList(WvConfigEntry);
00051
00052
00053 class WvConfigSection : public WvConfigEntryList
00054 {
00055 public:
00056 WvConfigSection(WvStringParm name);
00057 ~WvConfigSection();
00058
00059 WvConfigEntry *operator[] (WvStringParm s);
00060
00061 const char *get(WvStringParm entry, const char *def_val = NULL);
00062 void set(WvStringParm entry, WvStringParm value);
00063 void set(WvConfigEntry *e, WvStringParm value);
00064
00065
00066 void quick_set(WvStringParm entry, WvStringParm value);
00067
00068 void dump(WvStream &fp);
00069
00070 WvString name;
00071 };
00072
00073
00074
00075 typedef wv::function<void(void*, WvStringParm, WvStringParm, WvStringParm, WvStringParm)> WvConfCallback;
00076
00077
00078 class WvConfCallbackInfo
00079 {
00080 public:
00081 WvConfCallback callback;
00082 void *userdata, *cookie;
00083 const WvString section, entry;
00084
00085 WvConfCallbackInfo(WvConfCallback _callback, void *_userdata,
00086 WvStringParm _section, WvStringParm _entry,
00087 void *_cookie)
00088 : callback(_callback), section(_section), entry(_entry)
00089 { userdata = _userdata; cookie = _cookie; }
00090 };
00091
00092
00093 DeclareWvList(WvConfCallbackInfo);
00094 DeclareWvList(WvConfigSection);
00095
00096
00097 class WvAuthDaemon;
00098 class WvAuthDaemonSvc;
00099
00104 class WvConf : public WvConfigSectionList
00105 {
00106 public:
00107 WvConf(WvStringParm _filename, int _create_mode = 0666);
00108 ~WvConf();
00109
00110 bool isok() const
00111 { return !error; }
00112 bool isclean() const
00113 { return isok() && !dirty; }
00114 void save(WvStringParm filename);
00115 void save();
00116 void flush();
00117
00118 WvConfigSection *operator[] (WvStringParm s);
00119
00120 static int check_for_bool_string(const char *s);
00121 int parse_wvconf_request(char *request, char *§ion, char *&entry,
00122 char *&value);
00123
00124 int getint(WvStringParm section, WvStringParm entry, int def_val);
00125
00126 const char *get(WvStringParm section, WvStringParm entry,
00127 const char *def_val = NULL);
00128 WvString getraw(WvString wvconfstr, int &parse_error);
00129
00130 int fuzzy_getint(WvStringList §, WvStringParm entry,
00131 int def_val);
00132 const char *fuzzy_get(WvStringList §, WvStringParm entry,
00133 const char *def_val = NULL);
00134
00135 int fuzzy_getint(WvStringList §, WvStringList &entry,
00136 int def_val);
00137 const char *fuzzy_get(WvStringList & sect, WvStringList & ent,
00138 const char *def_val = NULL);
00139
00140 void setint(WvStringParm section, WvStringParm entry, int value);
00141 void set(WvStringParm section, WvStringParm entry,
00142 const char *value);
00143 void setraw(WvString wvconfstr, const char *&value, int &parse_error);
00144
00145 void maybesetint(WvStringParm section, WvStringParm entry,
00146 int value);
00147 void maybeset(WvStringParm section, WvStringParm entry,
00148 const char *value);
00149
00150 void delete_section(WvStringParm section);
00151
00152
00153
00154
00155
00156 void add_callback(WvConfCallback callback, void *userdata,
00157 WvStringParm section, WvStringParm entry, void *cookie);
00158 void del_callback(WvStringParm section, WvStringParm entry, void *cookie);
00159 void run_callbacks(WvStringParm section, WvStringParm entry,
00160 WvStringParm oldvalue, WvStringParm newvalue);
00161 void run_all_callbacks();
00162
00163
00164 void setbool(void *userdata,
00165 WvStringParm section, WvStringParm entry,
00166 WvStringParm oldval, WvStringParm newval);
00167
00168
00169 void addname(void *userdata,
00170 WvStringParm section, WvStringParm entry,
00171 WvStringParm oldval, WvStringParm newval);
00172
00173
00174 void addfile(void *userdata,
00175 WvStringParm section, WvStringParm entry,
00176 WvStringParm oldval, WvStringParm newval);
00177
00178 void add_addfile(WvString *filename, WvStringParm sect, WvStringParm ent)
00179 { add_callback(wv::bind(&WvConf::addfile, this, _1, _2, _3, _4, _5),
00180 filename, sect, ent, new int); }
00181
00182 void add_addname(WvStringList *list, WvStringParm sect, WvStringParm ent)
00183 { add_callback(wv::bind(&WvConf::addname, this, _1, _2, _3, _4, _5),
00184 list, sect, ent, list); }
00185 void del_addname(WvStringList *list, WvStringParm sect, WvStringParm ent)
00186 { del_callback(sect, ent, list); }
00187
00188 void add_setbool(bool *b, WvStringParm section, WvStringParm entry)
00189 { add_callback(wv::bind(&WvConf::setbool, this, _1, _2, _3, _4, _5),
00190 b, section, entry, b); }
00191 void del_setbool(bool *b, WvStringParm section, WvStringParm entry)
00192 { del_callback(section, entry, b); }
00193
00194 void load_file()
00195 { load_file(filename); }
00196 void load_file(WvStringParm filename);
00197
00198
00199 WvString get_passwd(WvStringParm sect, WvStringParm user);
00200 WvString get_passwd(WvStringParm user)
00201 { return get_passwd("Users", user); }
00202 WvString get_passwd2(WvString pwenc);
00203
00204
00205
00206
00207 bool check_passwd(WvStringParm sect, WvStringParm user,
00208 WvStringParm passwd);
00209 bool check_passwd(WvStringParm user, WvStringParm passwd)
00210 {
00211 return check_passwd("Users", user, passwd);
00212 }
00213
00214
00215 bool user_exists(WvStringParm sect, WvStringParm user);
00216 bool user_exists(WvStringParm user)
00217 {
00218 return user_exists("Users", user);
00219 }
00220
00221
00222 void set_passwd(WvStringParm sect, WvStringParm user, WvStringParm passwd);
00223 void set_passwd(WvStringParm user, WvStringParm passwd)
00224 { set_passwd("Users", user, passwd); }
00225 WvString set_passwd2(WvStringParm passwd);
00226
00227
00228 void convert_to_old_pw();
00229
00230
00231 void setdirty()
00232 { dirty = true; }
00233
00234 private:
00235 bool dirty;
00236 bool error;
00237 bool loaded_once;
00238 int create_mode;
00239
00240 WvString filename;
00241 WvLog log;
00242
00243 WvConfigSection globalsection;
00244 WvConfCallbackInfoList callbacks;
00245
00246 char *parse_section(char *s);
00247 char *parse_value(char *s);
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 private:
00258 WvAuthDaemon *wvauthd;
00259 public:
00260 friend class WvAuthDaemonSvc;
00261 };
00262
00263
00264 #endif // __WVCONF_H