Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / wvconfemu.h
blob6c6a63a7778fc3b5a0b52c77e9068aa5dbadfa85
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
5 * Basic WvConf emulation layer for UniConf.
6 */
7 #ifndef __WVCONFEMU_H
8 #define __WVCONFEMU_H
10 #include "uniconfroot.h"
11 #include "wvstringtable.h"
12 #include "wvsorter.h"
14 #define WvConf WvConfEmu
15 #define WvConfigSection WvConfigSectionEmu
16 #define WvConfigSectionList WvConfigSectionListEmu
17 #define WvConfigEntry WvConfigEntryEmu
18 #define WvConfigEntryList WvConfigEntryListEmu
21 class WvConfEmu;
22 class WvConfigEntryEmu;
23 class WvConfigSectionEmu;
24 class WvAuthDaemon;
25 class WvAuthDaemonSvc;
27 typedef WvConfEmu WvConfigSectionListEmu;
28 typedef WvConfigSectionEmu WvConfigEntryListEmu;
31 class WvConfigEntryEmu
33 public:
34 const WvString name;
35 WvString value;
36 WvConfigEntryEmu(WvStringParm _name, WvStringParm _value):
37 name(_name), value(_value)
42 DeclareWvDict(WvConfigEntryEmu, WvString, name);
45 class WvConfigSectionEmu
47 private:
48 const UniConf uniconf;
49 WvConfigEntryEmuDict entries;
50 WvStringTable &values;
51 public:
52 const WvString name;
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);
62 bool isempty() const;
64 class Iter;
65 friend class Iter;
67 typedef WvSorter<WvConfigEntryEmu, WvConfigSectionEmu, Iter> Sorter;
71 DeclareWvDict(WvConfigSectionEmu, WvString, name);
74 class WvConfigSectionEmu::Iter
76 private:
77 WvConfigSectionEmu& sect;
78 UniConf::RecursiveIter iter;
79 WvLink link;
80 WvConfigEntryEmu* entry;
81 public:
82 Iter(WvConfigSectionEmu& _sect):
83 sect(_sect), iter(_sect.uniconf), link(NULL, false), entry(NULL)
85 assert(&_sect);
87 ~Iter();
88 void rewind();
89 WvLink *next();
90 WvLink *cur();
91 WvConfigEntryEmu* ptr() const;
92 void* vptr() const;
93 WvIterStuff(WvConfigEntryEmu);
97 // parameters are: userdata, section, entry, oldval, newval
98 typedef wv::function<void(void*, WvStringParm, WvStringParm, WvStringParm, WvStringParm)> WvConfCallback;
101 class WvConfEmu
103 private:
104 struct CallbackInfo
106 WvConfCallback callback;
107 void* userdata;
108 WvString section;
109 WvString key;
110 void* cookie;
111 CallbackInfo(WvConfCallback _callback, void* _userdata,
112 WvStringParm _section, WvStringParm _key,
113 void* _cookie):
114 callback(_callback), userdata(_userdata), section(_section),
115 key(_key), cookie(_cookie)
119 WvConfigSectionEmuDict sections;
120 bool hold;
121 bool dirty;
122 WvList<CallbackInfo> callbacks;
123 WvStringTable values;
125 void notify(const UniConf &_uni, const UniConfKey &_key);
126 public:
127 const UniConf uniconf;
129 WvConfEmu(const UniConf &_uniconf);
130 ~WvConfEmu();
131 void zap();
132 bool isclean() const;
133 bool isok() const;
134 void load_file(WvStringParm filename);
135 void save(WvStringParm filename, int _create_mode = 0666);
136 void save();
137 void flush();
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 &sect, WvStringParm entry,
159 int def_val);
160 const char *fuzzy_get(WvStringList &sect, 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,
166 const char *value);
168 void maybesetint(WvStringParm section, WvStringParm entry,
169 int value);
170 void maybeset(WvStringParm section, WvStringParm entry,
171 const char *value);
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);
212 class Iter;
213 friend class Iter;
215 private:
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
222 * here.
224 private:
225 WvAuthDaemon *wvauthd; // Authentication Daemon
226 public:
227 friend class WvAuthDaemonSvc;
231 class WvConfEmu::Iter
233 WvConfEmu& conf;
234 UniConf::Iter iter;
235 WvLink link;
236 public:
237 Iter(WvConfEmu& _conf):
238 conf(_conf), iter(conf.uniconf), link(NULL, false)
240 void rewind();
241 WvLink *next();
242 WvConfigSectionEmu* ptr() const;
243 WvIterStuff(WvConfigSectionEmu);
246 #endif // __WVCONFEMU_H