Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvconfemu.h

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

Generated on Sun Jul 10 15:30:56 2005 for WvStreams by  doxygen 1.4.0