/usr/include/barry18/barry/configfile.h is in libbarry-dev 0.18.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | ///
/// \file configfile.h
/// Barry configuraion class, for one device PIN
///
/*
Copyright (C) 2007-2013, Net Direct Inc. (http://www.netdirect.ca/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License in the COPYING file at the
root directory of this project for more details.
*/
#ifndef __BARRY_CONFIGFILE_H__
#define __BARRY_CONFIGFILE_H__
#include "dll.h"
#include "record.h"
#include "pin.h"
#include <string>
#include <iosfwd>
namespace Barry {
/// Creates a tar.gz filename using PIN + date + time + label.
/// Does not include any path, just returns a new filename.
BXEXPORT std::string MakeBackupFilename(const Barry::Pin &pin,
const std::string &label);
class BXEXPORT ConfigFile
{
public:
class BXEXPORT DBListType : public std::vector<std::string>
{
public:
bool IsSelected(const std::string &dbname) const;
DBListType& operator=(const DatabaseDatabase &dbdb);
DBListType() {}
DBListType(const DatabaseDatabase &dbdb)
{
operator=(dbdb);
}
};
private:
// meta data
Barry::Pin m_pin;
std::string m_path; // /path/to/config/dir without trailing slash
std::string m_filename; // /path/to/config/dir/filename
bool m_loaded;
std::string m_last_error;
// configuration data
DBListType m_backupList;
DBListType m_restoreList;
std::string m_deviceName;
bool m_promptBackupLabel; // if true, prompt the user on every
// backup for a string to label the
// backup file with
bool m_autoSelectAll; // if true, automatically select all
// databases on every backup
protected:
void BuildFilename();
void BuildDefaultPath();
void Clear();
void Load();
public:
/// Loads config file for the given pin, and ends up in an
/// unenlightened state. Throws ConfigFileError on error,
/// but it is not an error if the config does not exist.
/// Never use this if you have a DatabaseDatabase object!
/// This ctor is only for temporary loading of config data.
explicit ConfigFile(Barry::Pin pin);
/// Opens and loads config file for given pin, and calls Enlighten
/// Throws ConfigFileError on error. Should never fail unless
/// passed a bad pin, or if unable to get current user info.
ConfigFile(Barry::Pin pin, const Barry::DatabaseDatabase &db);
~ConfigFile();
//
// data access
//
const std::string& get_last_error() const { return m_last_error; }
bool IsConfigLoaded() const { return m_loaded; }
const std::string& GetPath() const { return m_path; }
// const std::string& GetDeviceConfigFilename() const { return m_device_filename; }
//
// per-Device Configuration
//
const DBListType& GetBackupList() const { return m_backupList; }
const DBListType& GetRestoreList() const { return m_restoreList; }
const std::string& GetDeviceName() const { return m_deviceName; }
bool HasDeviceName() const { return m_deviceName.size() != 0; }
bool PromptBackupLabel() const { return m_promptBackupLabel; }
bool AutoSelectAll() const { return m_autoSelectAll; }
//
// operations
//
/// Saves current device's config, overwriting or creating a
/// config file
bool Save();
/// Compares a given databasedatabase from a real device with the
/// current config. If not yet configured, initialize with valid
/// defaults.
void Enlighten(const Barry::DatabaseDatabase &db);
//
// per-Device Configuration setting
//
/// Sets list with new config
void SetBackupList(const DBListType &list);
void SetRestoreList(const DBListType &list);
void SetDeviceName(const std::string &name);
void SetBackupPath(const std::string &path);
void SetPromptBackupLabel(bool prompt = true);
void SetAutoSelectAll(bool asa = true);
//
// Utility functions
//
/// Checks that the path in path exists, and if not, creates it.
/// Returns false if unable to create path, true if ok.
static bool CheckPath(const std::string &path, std::string *perr = 0);
};
class BXEXPORT GlobalConfigFile
{
private:
typedef std::map<std::string, std::string> keymap_type;
// meta data
std::string m_path; // /path/to/.barry without trailing slash
std::string m_filename; // /path/to/.barry/config
bool m_loaded;
std::string m_last_error;
std::string m_appname;
// global configuration data
Barry::Pin m_lastDevice; // the last selected device in a GUI
bool m_verboseLogging;
// set/get key data
keymap_type m_keymap;
protected:
void BuildFilename();
void Clear();
void Load();
public:
/// Loads the global config file.
/// Throws ConfigFileError on error, but it is not an error
/// if the config does not exist.
GlobalConfigFile();
/// Loads the global config file, as well as any application-specific
/// keywords and variables. Use this if you wish to make use of
/// SetKey() and GetKey(), otherwise these functions will throw
/// and exception since they don't have an application name.
GlobalConfigFile(const std::string &appname);
~GlobalConfigFile();
//
// data access
//
const std::string& get_last_error() const { return m_last_error; }
bool IsConfigLoaded() const { return m_loaded; }
const std::string& GetPath() const { return m_path; }
//
// Global Configuration data access
//
Barry::Pin GetLastDevice() const { return m_lastDevice; }
bool VerboseLogging() const { return m_verboseLogging; }
//
// operations
//
/// Save the current global config, overwriting or creating as needed
bool Save();
/// Throws std::logic_error if not constructed with an appname
void SetKey(const std::string &key, const std::string &value);
/// Returns value for key, and returns default_value if key does not
/// exist in the config file.
/// Throws std::logic_error if not constructed with an appname
std::string GetKey(const std::string &key,
const std::string &default_value = "") const;
//
// Global Configuration setting
//
void SetLastDevice(const Barry::Pin &pin);
void SetVerboseLogging(bool verbose = true);
};
BXEXPORT std::ostream& operator<< (std::ostream &os, const ConfigFile::DBListType &list);
} // namespace Barry
#endif
|