5 #include "cvmfs_config.h"
34 if ((sz_list < 0) || (sz_list > 64*1024)) {
36 }
else if (sz_list == 0) {
40 list =
reinterpret_cast<char *
>(alloca(sz_list));
44 }
else if (sz_list == 0) {
49 vector<string> keys =
SplitString(
string(list, sz_list),
'\0');
54 for (
unsigned i = 0; i < keys.size(); ++i) {
61 result->
Set(keys[i],
string(value, sz_value));
68 const unsigned char *inbuf,
78 memcpy(&header, inbuf,
sizeof(header));
81 unsigned pos =
sizeof(header);
82 for (
unsigned i = 0; i < header.
num_xattrs; ++i) {
85 if (size - pos < size_preamble)
87 memcpy(&entry, inbuf + pos, size_preamble);
88 if (size - pos < entry.
GetSize())
90 if (entry.
GetSize() == size_preamble)
93 memcpy(entry.
data, inbuf + pos, entry.
GetSize() - size_preamble);
94 pos += entry.
GetSize() - size_preamble;
104 return xattrs_.find(key) != xattrs_.end();
110 map<string, string>::const_iterator iter = xattrs_.find(key);
111 if (iter != xattrs_.end()) {
112 *value = iter->second;
120 vector<string> result;
121 for (map<string, string>::const_iterator i = xattrs_.begin(),
122 iEnd = xattrs_.end(); i != iEnd; ++i)
124 result.push_back(i->first);
139 if (!merge_with.empty()) {
140 vector<string> merge_list =
SplitString(merge_with,
'\0');
141 for (
unsigned i = 0; i < merge_list.size(); ++i) {
142 if (merge_list[i].empty())
144 if (xattrs_.find(merge_list[i]) == xattrs_.end()) {
145 result += merge_list[i];
146 result.push_back(
'\0');
150 for (map<string, string>::const_iterator i = xattrs_.begin(),
151 iEnd = xattrs_.end(); i != iEnd; ++i)
154 result.push_back(
'\0');
163 if (key.length() > 256)
165 if (key.find(
'\0') != string::npos)
167 if (value.length() > 256)
170 map<string, string>::iterator iter = xattrs_.find(key);
171 if (iter != xattrs_.end()) {
172 iter->second = value;
174 if (xattrs_.size() >= 256)
176 xattrs_[key] = value;
183 map<string, string>::iterator iter = xattrs_.find(key);
184 if (iter != xattrs_.end()) {
197 unsigned char **outbuf,
199 const std::vector<std::string> *blacklist)
const
201 if (xattrs_.empty()) {
208 uint32_t packed_size =
sizeof(header);
212 smalloc(header.num_xattrs *
sizeof(
XattrEntry)));
213 unsigned ientries = 0;
214 for (map<string, string>::const_iterator it_att = xattrs_.begin(),
215 it_att_end = xattrs_.end(); it_att != it_att_end; ++it_att)
218 if (blacklist != NULL) {
220 for (
unsigned i_bl = 0; i_bl < blacklist->size(); ++i_bl) {
221 if (
HasPrefix(it_att->first, (*blacklist)[i_bl],
231 new (entries + ientries)
XattrEntry(it_att->first, it_att->second);
232 packed_size += entries[ientries].
GetSize();
245 header.num_xattrs = ientries;
247 *outbuf =
reinterpret_cast<unsigned char *
>(smalloc(packed_size));
248 memcpy(*outbuf, &header,
sizeof(header));
249 unsigned pos =
sizeof(header);
250 for (
unsigned i = 0; i < header.num_xattrs; ++i) {
251 memcpy(*outbuf + pos, &entries[i], entries[i].GetSize());
265 return string(data, len_key);
270 return sizeof(len_key) +
sizeof(len_value) +
271 uint16_t(len_key) + uint16_t(len_value);
278 return string(&data[len_key], len_value);
283 : len_key(key.
size())
284 , len_value(value.
size())
std::string ListKeysPosix(const std::string &merge_with) const
bool Set(const std::string &key, const std::string &value)
assert((mem||(size==0))&&"Out Of Memory")
bool Get(const std::string &key, std::string *value) const
vector< string > SplitString(const string &str, char delim)
std::string GetValue() const
void Serialize(unsigned char **outbuf, unsigned *size, const std::vector< std::string > *blacklist=NULL) const
bool Has(const std::string &key) const
std::string GetKey() const
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
static XattrList * Deserialize(const unsigned char *inbuf, const unsigned size)
static XattrList * CreateFromFile(const std::string &path)
static const uint8_t kVersion
std::vector< std::string > ListKeys() const
bool Remove(const std::string &key)