• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

yapet/cfgfile.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: cfgfile.h 3356 2010-09-18 21:06:17Z rafi $
00004 //
00005 // Copyright (C) 2008-2010  Rafael Ostertag
00006 //
00007 // This file is part of YAPET.
00008 //
00009 // YAPET is free software: you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the Free Software
00011 // Foundation, either version 3 of the License, or (at your option) any later
00012 // version.
00013 //
00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00017 // details.
00018 //
00019 // You should have received a copy of the GNU General Public License along with
00020 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 
00023 #ifndef _CFGFILE_H
00024 #define _CFGFILE_H
00025 
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029 
00030 #ifdef HAVE_SYS_TYPES_H
00031 # include <sys/types.h>
00032 #endif
00033 
00034 #ifdef HAVE_STRING
00035 # include <string>
00036 #endif
00037 
00038 // Used for the YAPET::PWGEN::RNGENGINE type
00039 #include "pwgen/rng.h"
00040 
00046 namespace YAPET {
00047     namespace CONFIG {
00048 
00054         class ConfigFile {
00055             private:
00059         enum ReadResult {
00060             OPTION_NOT_FOUND,
00061             OPTION_EMPTY,
00062             OPTION_FOUND
00063         };
00064 
00065                 std::string filetoload;
00066                 bool usefsecurity;
00067                 unsigned int locktimeout;
00068         unsigned int pwinputtimeout;
00069         bool allowlockquit;
00070                 // Yes, the file can say that it should be ignored!
00071                 bool ignorerc;
00072                 std::string cfgfilepath;
00073 
00075                 bool opensuccess;
00076 
00077         // PWGen settings
00078         bool pwgen_letters;
00079         bool pwgen_digits;
00080         bool pwgen_punct;
00081         bool pwgen_special;
00082         bool pwgen_other;
00083         YAPET::PWGEN::RNGENGINE pwgen_rng;
00084         size_t pwgen_pwlen;
00085 
00086                 std::string getHomeDir() const;
00087         
00100         template<class t> ReadResult readOption(std::string l, const std::string& needle, t& val)  {
00101             if (l.find (needle, 0) == 0) {
00102             l.erase (0, needle.length() );
00103             if (l.empty())
00104                 return OPTION_EMPTY;
00105             
00106             std::istringstream sstr(l);
00107             sstr >> val;
00108             return OPTION_FOUND;
00109             }
00110             return OPTION_NOT_FOUND;
00111         }
00112 
00113                 void parseFile();
00114 
00115             public:
00116                 ConfigFile (std::string cfgfile = "");
00117                 ConfigFile (const ConfigFile& cfgfile);
00118                 inline ~ConfigFile() {};
00119 
00120 
00121                 inline const std::string& getConfigFilePath() const {
00122                     return cfgfilepath;
00123                 }
00124                 inline const std::string& getFileToLoad() const {
00125                     return filetoload;
00126                 }
00127                 inline bool getUseFileSecurity() const {
00128                     return usefsecurity;
00129                 }
00130                 inline unsigned int getLockTimeout() const {
00131                     return locktimeout;
00132                 }
00133                 inline bool getIgnoreRC() const {
00134                     return ignorerc ;
00135                 }
00136         inline unsigned int getPwInputTimeout() const {
00137             return pwinputtimeout;
00138         }
00139         inline bool getAllowLockQuit() const {
00140             return allowlockquit;
00141         }
00142         inline YAPET::PWGEN::RNGENGINE getPWGenRNG() const {
00143             return pwgen_rng;
00144         }
00145         inline size_t getPWGenPWLen() const {
00146             return pwgen_pwlen;
00147         }
00148         inline bool getPWGenLetters() const {
00149             return pwgen_letters;
00150         }
00151         inline bool getPWGenDigits() const {
00152             return pwgen_digits;
00153         }
00154         inline bool getPWGenPunct() const {
00155             return pwgen_punct;
00156         }
00157         inline bool getPWGenSpecial() const {
00158             return pwgen_special;
00159         }
00160         inline bool getPWGenOther() const {
00161             return pwgen_other;
00162         }
00163                 inline bool isOpenSuccess() const {
00164                     return opensuccess;
00165                 }
00166 
00167                 const ConfigFile& operator= (const ConfigFile& cfgfile);
00168         };
00169 
00170     }
00171 }
00172 
00173 #endif // _CFGFILE_H

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1