Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvconfemu.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2004 Net Integration Technologies, Inc. 00004 * 00005 * Basic WvConf emulation layer for UniConf. 00006 */ 00007 #ifndef __WVCONFEMU_H 00008 #define __WVCONFEMU_H 00009 00010 00011 #include "uniconfroot.h" 00012 #include "wvsorter.h" 00013 00014 #define WvConf WvConfEmu 00015 #define WvConfigSection WvConfigSectionEmu 00016 #define WvConfigSectionList WvConfigSectionListEmu 00017 #define WvConfigEntry WvConfigEntryEmu 00018 #define WvConfigEntryList WvConfigEntryListEmu 00019 00020 00021 class WvConfEmu; 00022 class WvConfigEntryEmu; 00023 class WvConfigSectionEmu; 00024 class WvAuthDaemon; 00025 class WvAuthDaemonSvc; 00026 00027 typedef WvConfEmu WvConfigSectionListEmu; 00028 typedef WvConfigSectionEmu WvConfigEntryListEmu; 00029 00030 00031 class WvConfigEntryEmu 00032 { 00033 public: 00034 const WvString name; 00035 WvString value; 00036 WvConfigEntryEmu(WvStringParm _name, WvStringParm _value): 00037 name(_name), value(_value) 00038 {} 00039 }; 00040 00041 00042 DeclareWvDict(WvConfigEntryEmu, WvString, name); 00043 00044 00045 class WvConfigSectionEmu 00046 { 00047 private: 00048 const UniConf uniconf; 00049 WvConfigEntryEmuDict entries; 00050 WvStringList values; 00051 public: 00052 const WvString name; 00053 WvConfigSectionEmu(const UniConf& _uniconf, WvStringParm _name): 00054 uniconf(_uniconf), entries(42), name(_name) 00055 {} 00056 WvConfigEntryEmu *operator[] (WvStringParm s); 00057 const char *get(WvStringParm entry, const char *def_val = NULL); 00058 void set(WvStringParm entry, WvStringParm value); 00059 void quick_set(WvStringParm entry, WvStringParm value); 00060 00061 bool isempty() const; 00062 00063 class Iter; 00064 friend class Iter; 00065 00066 typedef WvSorter<WvConfigEntryEmu, WvConfigSectionEmu, Iter> Sorter; 00067 }; 00068 00069 00070 DeclareWvDict(WvConfigSectionEmu, WvString, name); 00071 00072 00073 class WvConfigSectionEmu::Iter 00074 { 00075 private: 00076 WvConfigSectionEmu& sect; 00077 UniConf::Iter iter; 00078 WvLink link; 00079 WvConfigEntryEmu* entry; 00080 public: 00081 Iter(WvConfigSectionEmu& _sect): 00082 sect(_sect), iter(_sect.uniconf), link(NULL, false), entry(NULL) 00083 {} 00084 ~Iter(); 00085 void rewind(); 00086 WvLink *next(); 00087 WvLink *cur(); 00088 WvConfigEntryEmu* ptr() const; 00089 void* vptr() const; 00090 WvIterStuff(WvConfigEntryEmu); 00091 }; 00092 00093 00094 // parameters are: userdata, section, entry, oldval, newval 00095 typedef WvCallback<void, void*, WvStringParm, WvStringParm, WvStringParm, WvStringParm> WvConfCallback; 00096 00097 00098 class WvConfEmu 00099 { 00100 private: 00101 struct CallbackInfo 00102 { 00103 WvConfCallback callback; 00104 void* userdata; 00105 WvString section; 00106 WvString key; 00107 void* cookie; 00108 WvString last; 00109 CallbackInfo(WvConfCallback _callback, void* _userdata, 00110 WvStringParm _section, WvStringParm _key, 00111 void* _cookie, WvStringParm _last): 00112 callback(_callback), userdata(_userdata), section(_section), 00113 key(_key), cookie(_cookie), last(_last) 00114 {} 00115 }; 00116 00117 const UniConf uniconf; 00118 WvConfigSectionEmuDict sections; 00119 bool hold; 00120 WvList<CallbackInfo> callbacks; 00121 WvStringList values; 00122 00123 void notify(const UniConf &_uni, const UniConfKey &_key); 00124 public: 00125 WvConfEmu(const UniConf& _uniconf); 00126 void zap(); 00127 bool isok() const; 00128 void load_file(WvStringParm filename); 00129 void save(WvStringParm filename); 00130 void save(); 00131 void flush(); 00132 00133 WvConfigSectionEmu *operator[] (WvStringParm sect); 00134 00135 void add_callback(WvConfCallback callback, void *userdata, 00136 WvStringParm section, WvStringParm key, void *cookie); 00137 void del_callback(WvStringParm section, WvStringParm key, void *cookie); 00138 00139 void add_setbool(bool *b, WvStringParm _section, WvStringParm _key); 00140 00141 void add_addname(WvStringList *list, WvStringParm sect, WvStringParm ent); 00142 void del_addname(WvStringList *list, WvStringParm sect, WvStringParm ent); 00143 00144 void add_addfile(WvString *filename, WvStringParm sect, WvStringParm ent); 00145 00146 WvString getraw(WvString wvconfstr, int &parse_error); 00147 int getint(WvStringParm section, WvStringParm entry, int def_val); 00148 const char *get(WvStringParm section, WvStringParm entry, 00149 const char *def_val = NULL); 00150 int fuzzy_getint(WvStringList &sect, WvStringParm entry, 00151 int def_val); 00152 const char *fuzzy_get(WvStringList &sect, WvStringParm entry, 00153 const char *def_val = NULL); 00154 00155 void setraw(WvString wvconfstr, const char *&value, int &parse_error); 00156 void setint(WvStringParm section, WvStringParm entry, int value); 00157 void set(WvStringParm section, WvStringParm entry, 00158 const char *value); 00159 00160 void maybesetint(WvStringParm section, WvStringParm entry, 00161 int value); 00162 void maybeset(WvStringParm section, WvStringParm entry, 00163 const char *value); 00164 00165 void delete_section(WvStringParm section); 00166 00167 // Gets a user's password and decrypts it. This isn't defined in wvconf.cc. 00168 WvString get_passwd(WvStringParm sect, WvStringParm user); 00169 WvString get_passwd(WvStringParm user) 00170 { return get_passwd("Users", user); } 00171 WvString get_passwd2(WvString pwenc); 00172 00173 // Check the password passed in. This isn't defined in wvconf.cc 00174 // We use this function to check passwords since we may not know what 00175 // the password actually is! 00176 bool check_passwd(WvStringParm sect, WvStringParm user, 00177 WvStringParm passwd); 00178 bool check_passwd(WvStringParm user, WvStringParm passwd) 00179 { 00180 return check_passwd("Users", user, passwd); 00181 } 00182 00183 // Check if the user exists. This isn't defined in wvconf.cc 00184 bool user_exists(WvStringParm sect, WvStringParm user); 00185 bool user_exists(WvStringParm user) 00186 { 00187 return user_exists("Users", user); 00188 } 00189 00190 // Encrypts and sets a user's password. This isn't defined in wvconf.cc. 00191 void set_passwd(WvStringParm sect, WvStringParm user, WvStringParm passwd); 00192 void set_passwd(WvStringParm user, WvStringParm passwd) 00193 { set_passwd("Users", user, passwd); } 00194 WvString set_passwd2(WvStringParm passwd); 00195 00196 // Converts all passwords to unencrypted format. Not defined in wvconf.cc. 00197 void convert_to_old_pw(); 00198 00199 static int check_for_bool_string(const char *s); 00200 00201 class Iter; 00202 friend class Iter; 00203 00204 private: 00205 /* The following is an ugly hack, but since WvConf is being 00206 * deprecated, we don't care. 00207 * 00208 * It seems that check_passwd() and user_exists() need to talk to a 00209 * WvAuthDaemon. However, making them virtual functions would break since 00210 * everyone else has to implement them. So we'll its pointer and accessors 00211 * here. 00212 */ 00213 private: 00214 WvAuthDaemon *wvauthd; // Authentication Daemon 00215 public: 00216 friend class WvAuthDaemonSvc; 00217 }; 00218 00219 00220 class WvConfEmu::Iter 00221 { 00222 WvConfEmu& conf; 00223 UniConf::Iter iter; 00224 WvLink link; 00225 public: 00226 Iter(WvConfEmu& _conf): 00227 conf(_conf), iter(conf.uniconf), link(NULL, false) 00228 {} 00229 void rewind(); 00230 WvLink *next(); 00231 WvConfigSectionEmu* ptr() const; 00232 WvIterStuff(WvConfigSectionEmu); 00233 }; 00234 00235 00236 #endif // __WVCONFEMU_H

Generated on Tue Oct 5 01:09:20 2004 for WvStreams by doxygen 1.3.7