5 #ifndef CVMFS_UID_MAP_H_
6 #define CVMFS_UID_MAP_H_
50 typedef typename std::map<key_type, value_type> map_type;
55 , has_default_value_(false)
56 , default_value_(T(0)) {}
63 void Set(
const T k,
const T v) { map_[k] = v; }
70 void SetDefault(
const T v) {
71 has_default_value_ =
true;
84 bool Read(
const std::string &path) {
85 valid_ = ReadFromFile(path);
94 bool Contains(
const T k)
const {
96 return map_.find(k) != map_.end();
104 T Map(
const T k)
const {
106 typename map_type::const_iterator i = map_.find(k);
107 if (i != map_.end()) {
111 return (HasDefault())
116 bool HasEffect()
const {
117 return (map_.size() != 0) || has_default_value_;
120 bool IsEmpty()
const {
return map_.size() == 0; }
121 bool IsValid()
const {
return valid_; }
122 bool HasDefault()
const {
return has_default_value_; }
123 size_t RuleCount()
const {
return map_.size(); }
125 T GetDefault()
const {
assert(has_default_value_);
return default_value_; }
126 const map_type& GetRuleMap()
const {
return map_; }
129 bool ReadFromFile(
const std::string &path) {
130 FILE *fmap = fopen(path.c_str(),
"r");
133 path.c_str(), errno);
140 unsigned int line_number = 0;
144 if (line.empty() || line[0] ==
'#') {
148 std::vector<std::string> components =
SplitString(line,
' ');
149 FilterEmptyStrings(&components);
150 if (components.size() != 2 ||
151 !int_sanitizer.
IsValid(components[1]) ||
152 (components[0] !=
"*" && !int_sanitizer.
IsValid(components[0]))) {
155 line_number, path.c_str());
160 if (components[0] ==
"*") {
173 void FilterEmptyStrings(std::vector<std::string> *vec)
const {
174 std::vector<std::string>::iterator i = vec->begin();
175 for (; i != vec->end(); ) {
176 i = (i->empty()) ? vec->erase(i) : i + 1;
184 bool has_default_value_;
188 typedef IntegerMap<uid_t> UidMap;
189 typedef IntegerMap<gid_t> GidMap;
191 #endif // CVMFS_UID_MAP_H_
string Trim(const string &raw, bool trim_newline)
static void Read(void *buf, size_t nbyte)
assert((mem||(size==0))&&"Out Of Memory")
bool GetLineFile(FILE *f, std::string *line)
vector< string > SplitString(const string &str, char delim)
uint64_t String2Uint64(const string &value)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)