2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Definition of the WvConfigFile, WvConfigSection, and WvConfigEntry classes,
6 * which are used to read and write entries from a Windows-INI-style file.
8 * Created: Sept 12 1997 D. Coombs
16 #include "wvlinklist.h"
18 #include "wvstringlist.h"
23 #warning "disabling wvconfemu transparent emulation"
25 #undef WvConfigSection
26 #undef WvConfigSectionList
28 #undef WvConfigEntryList
39 WvConfigEntry(WvStringParm _name
, WvStringParm _value
);
42 void set(WvStringParm _value
)
50 DeclareWvList(WvConfigEntry
);
53 class WvConfigSection
: public WvConfigEntryList
56 WvConfigSection(WvStringParm name
);
59 WvConfigEntry
*operator[] (WvStringParm s
);
61 const char *get(WvStringParm entry
, const char *def_val
= NULL
);
62 void set(WvStringParm entry
, WvStringParm value
);
63 void set(WvConfigEntry
*e
, WvStringParm value
);
65 // add an entry to the end of the section, _assuming_ no duplicates exist
66 void quick_set(WvStringParm entry
, WvStringParm value
);
68 void dump(WvStream
&fp
);
74 // parameters are: userdata, section, entry, oldval, newval
75 typedef wv::function
<void(void*, WvStringParm
, WvStringParm
, WvStringParm
, WvStringParm
)> WvConfCallback
;
78 class WvConfCallbackInfo
81 WvConfCallback callback
;
82 void *userdata
, *cookie
;
83 const WvString section
, entry
;
85 WvConfCallbackInfo(WvConfCallback _callback
, void *_userdata
,
86 WvStringParm _section
, WvStringParm _entry
,
88 : callback(_callback
), section(_section
), entry(_entry
)
89 { userdata
= _userdata
; cookie
= _cookie
; }
93 DeclareWvList(WvConfCallbackInfo
);
94 DeclareWvList(WvConfigSection
);
98 class WvAuthDaemonSvc
;
101 * WvConf configuration file management class: used to read/write config
102 * files that are formatted in the style of Windows .ini files.
104 class WvConf
: public WvConfigSectionList
107 WvConf(WvStringParm _filename
, int _create_mode
= 0666);
113 { return isok() && !dirty
; }
114 void save(WvStringParm filename
);
118 WvConfigSection
*operator[] (WvStringParm s
);
120 static int check_for_bool_string(const char *s
);
121 int parse_wvconf_request(char *request
, char *§ion
, char *&entry
,
124 int getint(WvStringParm section
, WvStringParm entry
, int def_val
);
126 const char *get(WvStringParm section
, WvStringParm entry
,
127 const char *def_val
= NULL
);
128 WvString
getraw(WvString wvconfstr
, int &parse_error
);
130 int fuzzy_getint(WvStringList
§
, WvStringParm entry
,
132 const char *fuzzy_get(WvStringList
§
, WvStringParm entry
,
133 const char *def_val
= NULL
);
135 int fuzzy_getint(WvStringList
§
, WvStringList
&entry
,
137 const char *fuzzy_get(WvStringList
& sect
, WvStringList
& ent
,
138 const char *def_val
= NULL
);
140 void setint(WvStringParm section
, WvStringParm entry
, int value
);
141 void set(WvStringParm section
, WvStringParm entry
,
143 void setraw(WvString wvconfstr
, const char *&value
, int &parse_error
);
145 void maybesetint(WvStringParm section
, WvStringParm entry
,
147 void maybeset(WvStringParm section
, WvStringParm entry
,
150 void delete_section(WvStringParm section
);
152 // section and entry may be blank -- that means _all_ sections/entries!
153 // the 'cookie' is a random value that must be unique between all
154 // registered callbacks on a particular key. (Hint: maybe you should
155 // use your 'this' pointer.)
156 void add_callback(WvConfCallback callback
, void *userdata
,
157 WvStringParm section
, WvStringParm entry
, void *cookie
);
158 void del_callback(WvStringParm section
, WvStringParm entry
, void *cookie
);
159 void run_callbacks(WvStringParm section
, WvStringParm entry
,
160 WvStringParm oldvalue
, WvStringParm newvalue
);
161 void run_all_callbacks();
163 // generic callback function for setting a bool to "true" when changed
164 void setbool(void *userdata
,
165 WvStringParm section
, WvStringParm entry
,
166 WvStringParm oldval
, WvStringParm newval
);
168 // generic callback for adding an entry name to name list when changed
169 void addname(void *userdata
,
170 WvStringParm section
, WvStringParm entry
,
171 WvStringParm oldval
, WvStringParm newval
);
173 // generic callback to create a file with a one-line backup string
174 void addfile(void *userdata
,
175 WvStringParm section
, WvStringParm entry
,
176 WvStringParm oldval
, WvStringParm newval
);
178 void add_addfile(WvString
*filename
, WvStringParm sect
, WvStringParm ent
)
179 { add_callback(wv::bind(&WvConf::addfile
, this, _1
, _2
, _3
, _4
, _5
),
180 filename
, sect
, ent
, new int); }
182 void add_addname(WvStringList
*list
, WvStringParm sect
, WvStringParm ent
)
183 { add_callback(wv::bind(&WvConf::addname
, this, _1
, _2
, _3
, _4
, _5
),
184 list
, sect
, ent
, list
); }
185 void del_addname(WvStringList
*list
, WvStringParm sect
, WvStringParm ent
)
186 { del_callback(sect
, ent
, list
); }
188 void add_setbool(bool *b
, WvStringParm section
, WvStringParm entry
)
189 { add_callback(wv::bind(&WvConf::setbool
, this, _1
, _2
, _3
, _4
, _5
),
190 b
, section
, entry
, b
); }
191 void del_setbool(bool *b
, WvStringParm section
, WvStringParm entry
)
192 { del_callback(section
, entry
, b
); }
194 void load_file() // append the contents of the real config file
195 { load_file(filename
); }
196 void load_file(WvStringParm filename
); // append any config file
198 // Gets a user's password and decrypts it. This isn't defined in wvconf.cc.
199 WvString
get_passwd(WvStringParm sect
, WvStringParm user
);
200 WvString
get_passwd(WvStringParm user
)
201 { return get_passwd("Users", user
); }
202 WvString
get_passwd2(WvString pwenc
);
204 // Check the password passed in. This isn't defined in wvconf.cc
205 // We use this function to check passwords since we may not know what
206 // the password actually is!
207 bool check_passwd(WvStringParm sect
, WvStringParm user
,
208 WvStringParm passwd
);
209 bool check_passwd(WvStringParm user
, WvStringParm passwd
)
211 return check_passwd("Users", user
, passwd
);
214 // Check if the user exists. This isn't defined in wvconf.cc
215 bool user_exists(WvStringParm sect
, WvStringParm user
);
216 bool user_exists(WvStringParm user
)
218 return user_exists("Users", user
);
221 // Encrypts and sets a user's password. This isn't defined in wvconf.cc.
222 void set_passwd(WvStringParm sect
, WvStringParm user
, WvStringParm passwd
);
223 void set_passwd(WvStringParm user
, WvStringParm passwd
)
224 { set_passwd("Users", user
, passwd
); }
225 WvString
set_passwd2(WvStringParm passwd
);
227 // Converts all passwords to unencrypted format. Not defined in wvconf.cc.
228 void convert_to_old_pw();
230 // needed by wvfast_user_import
235 bool dirty
; // true if changed since last flush()
236 bool error
; // true if something has gone wrong
237 bool loaded_once
; // true if load_file succeeded at least once
238 int create_mode
; // if we must create config file
243 WvConfigSection globalsection
;
244 WvConfCallbackInfoList callbacks
;
246 char *parse_section(char *s
);
247 char *parse_value(char *s
);
249 /* The following is an ugly hack, but since WvConf is being
250 * deprecated, we don't care.
252 * It seems that check_passwd() and user_exists() need to talk to a
253 * WvAuthDaemon. However, making them virtual functions would break since
254 * everyone else has to implement them. So we'll its pointer and accessors
258 WvAuthDaemon
*wvauthd
; // Authentication Daemon
260 friend class WvAuthDaemonSvc
;