2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
5 * Basic WvConf emulation layer for UniConf.
10 #include "uniconfroot.h"
11 #include "wvstringtable.h"
14 #define WvConf WvConfEmu
15 #define WvConfigSection WvConfigSectionEmu
16 #define WvConfigSectionList WvConfigSectionListEmu
17 #define WvConfigEntry WvConfigEntryEmu
18 #define WvConfigEntryList WvConfigEntryListEmu
22 class WvConfigEntryEmu
;
23 class WvConfigSectionEmu
;
25 class WvAuthDaemonSvc
;
27 typedef WvConfEmu WvConfigSectionListEmu
;
28 typedef WvConfigSectionEmu WvConfigEntryListEmu
;
31 class WvConfigEntryEmu
36 WvConfigEntryEmu(WvStringParm _name
, WvStringParm _value
):
37 name(_name
), value(_value
)
42 DeclareWvDict(WvConfigEntryEmu
, WvString
, name
);
45 class WvConfigSectionEmu
48 const UniConf uniconf
;
49 WvConfigEntryEmuDict entries
;
50 WvStringTable
&values
;
53 WvConfigSectionEmu(const UniConf
& _uniconf
, WvStringParm _name
,
54 WvStringTable
*_values
):
55 uniconf(_uniconf
), entries(42), values(*_values
), name(_name
)
57 WvConfigEntryEmu
*operator[] (WvStringParm s
);
58 const char *get(WvStringParm entry
, const char *def_val
= NULL
);
59 void set(WvStringParm entry
, WvStringParm value
);
60 void quick_set(WvStringParm entry
, WvStringParm value
);
67 typedef WvSorter
<WvConfigEntryEmu
, WvConfigSectionEmu
, Iter
> Sorter
;
71 DeclareWvDict(WvConfigSectionEmu
, WvString
, name
);
74 class WvConfigSectionEmu::Iter
77 WvConfigSectionEmu
& sect
;
78 UniConf::RecursiveIter iter
;
80 WvConfigEntryEmu
* entry
;
82 Iter(WvConfigSectionEmu
& _sect
):
83 sect(_sect
), iter(_sect
.uniconf
), link(NULL
, false), entry(NULL
)
91 WvConfigEntryEmu
* ptr() const;
93 WvIterStuff(WvConfigEntryEmu
);
97 // parameters are: userdata, section, entry, oldval, newval
98 typedef wv::function
<void(void*, WvStringParm
, WvStringParm
, WvStringParm
, WvStringParm
)> WvConfCallback
;
106 WvConfCallback callback
;
111 CallbackInfo(WvConfCallback _callback
, void* _userdata
,
112 WvStringParm _section
, WvStringParm _key
,
114 callback(_callback
), userdata(_userdata
), section(_section
),
115 key(_key
), cookie(_cookie
)
119 WvConfigSectionEmuDict sections
;
122 WvList
<CallbackInfo
> callbacks
;
123 WvStringTable values
;
125 void notify(const UniConf
&_uni
, const UniConfKey
&_key
);
127 const UniConf uniconf
;
129 WvConfEmu(const UniConf
&_uniconf
);
132 bool isclean() const;
134 void load_file(WvStringParm filename
);
135 void save(WvStringParm filename
, int _create_mode
= 0666);
139 WvConfigSectionEmu
*operator[] (WvStringParm sect
);
141 void add_callback(WvConfCallback callback
, void *userdata
,
142 WvStringParm section
, WvStringParm key
, void *cookie
);
143 void del_callback(WvStringParm section
, WvStringParm key
, void *cookie
);
145 void add_setbool(bool *b
, WvStringParm _section
, WvStringParm _key
);
146 void del_setbool(bool *b
, WvStringParm _section
, WvStringParm _key
);
148 // The addname callback will add the key "ent" in "sect" to the "list"
149 // whenever "ent" changes. If ent is empty, add any key in the sect to
150 // the list when one is added/deleted/changed
151 void add_addname(WvStringList
*list
, WvStringParm sect
, WvStringParm ent
);
152 void del_addname(WvStringList
*list
, WvStringParm sect
, WvStringParm ent
);
154 WvString
getraw(WvString wvconfstr
, int &parse_error
);
155 int getint(WvStringParm section
, WvStringParm entry
, int def_val
);
156 const char *get(WvStringParm section
, WvStringParm entry
,
157 const char *def_val
= NULL
);
158 int fuzzy_getint(WvStringList
§
, WvStringParm entry
,
160 const char *fuzzy_get(WvStringList
§
, WvStringParm entry
,
161 const char *def_val
= NULL
);
163 void setraw(WvString wvconfstr
, const char *&value
, int &parse_error
);
164 void setint(WvStringParm section
, WvStringParm entry
, int value
);
165 void set(WvStringParm section
, WvStringParm entry
,
168 void maybesetint(WvStringParm section
, WvStringParm entry
,
170 void maybeset(WvStringParm section
, WvStringParm entry
,
173 void delete_section(WvStringParm section
);
175 // Gets a user's password and decrypts it. This isn't defined in wvconf.cc.
176 WvString
get_passwd(WvStringParm sect
, WvStringParm user
);
177 WvString
get_passwd(WvStringParm user
)
178 { return get_passwd("Users", user
); }
179 WvString
get_passwd2(WvString pwenc
);
181 // Check the password passed in. This isn't defined in wvconf.cc
182 // We use this function to check passwords since we may not know what
183 // the password actually is!
184 // If s is not null and has continue_select enabled, check_passwd will
185 // pause if the password is incorrect (the pause length depends on how
186 // many password failures have occurred recently).
187 bool check_passwd(WvStringParm sect
, WvStringParm user
,
188 WvStringParm passwd
, WvStream
*s
);
189 bool check_passwd(WvStringParm user
, WvStringParm passwd
, WvStream
*s
)
191 return check_passwd("Users", user
, passwd
, s
);
194 // Check if the user exists. This isn't defined in wvconf.cc
195 bool user_exists(WvStringParm sect
, WvStringParm user
);
196 bool user_exists(WvStringParm user
)
198 return user_exists("Users", user
);
201 // Encrypts and sets a user's password. This isn't defined in wvconf.cc.
202 void set_passwd(WvStringParm sect
, WvStringParm user
, WvStringParm passwd
);
203 void set_passwd(WvStringParm user
, WvStringParm passwd
)
204 { set_passwd("Users", user
, passwd
); }
205 WvString
set_passwd2(WvStringParm passwd
);
207 // Converts all passwords to unencrypted format. Not defined in wvconf.cc.
208 void convert_to_old_pw();
210 static int check_for_bool_string(const char *s
);
216 /* The following is an ugly hack, but since WvConf is being
217 * deprecated, we don't care.
219 * It seems that check_passwd() and user_exists() need to talk to a
220 * WvAuthDaemon. However, making them virtual functions would break since
221 * everyone else has to implement them. So we'll its pointer and accessors
225 WvAuthDaemon
*wvauthd
; // Authentication Daemon
227 friend class WvAuthDaemonSvc
;
231 class WvConfEmu::Iter
237 Iter(WvConfEmu
& _conf
):
238 conf(_conf
), iter(conf
.uniconf
), link(NULL
, false)
242 WvConfigSectionEmu
* ptr() const;
243 WvIterStuff(WvConfigSectionEmu
);
246 #endif // __WVCONFEMU_H