#include <cctype>
#include <cerrno>
#include <string>
#include <cstring>
#include <strings.h>
#include <ctime>
#include <vector>
#include <sys/types.h>
#include "XrdCks/XrdCksData.hh"
Go to the source code of this file.
|
std::vector< char > | XrdCksAttrData (const char *cstype, const char *csval, time_t mtime) |
|
std::string | XrdCksAttrName (const char *cstype, const char *nspfx) |
|
std::string | XrdCksAttrValue (const char *cstype, const char *csbuff, int csblen) |
|
◆ XrdCksAttrData()
std::vector<char> XrdCksAttrData |
( |
const char * |
cstype, |
|
|
const char * |
csval, |
|
|
time_t |
mtime |
|
) |
| |
This header file defines linkages to various XRootD checksum assistants. The functions described here are located in libXrdUtils.so. Generate the extended attribute data for a particular checksum that can be used to set the corresponding checksum attribute variable.
- Parameters
-
cstype | A null terminated string holding the checksum type (e.g. "adler32", "md5", "sha2", etc). |
csval | A null terminated string holding the corresonding checksum value. This must be an ASCII hex representation of the value and must be of appropriate length. |
mtime | The subject file's modification time. |
- Returns
- A vector of bytes that should be usedto set the attribute variable. If the size of the vector is zero, then the supplied parameters were incorrect and valid data cannot be generated; errno is: EINVAL - csval length is incorrect for checksum type or contains a non-hex digit. ENAMETOOLONG - checksum type is too long. EOVERFLOW - csval could not be represented in the data.
Definition at line 84 of file XrdCksAssist.cc.
87 std::vector<char> cksError;
90 int n = strlen(cstype);
94 if (!LowerCase(cstype, csName,
sizeof(csName)))
95 {errno = ENAMETOOLONG;
return cksError;}
101 for (
int i = 0; i < csNum; i++)
102 {
if (!strcmp(csTab[i].csName, csName) && csTab[i].csLenC != n)
103 {errno = EINVAL;
return cksError;}
108 if (!cksData.
Set(csName)) {errno = ENAMETOOLONG;
return cksError;}
109 if (!cksData.
Set(csval, n)) {errno = EOVERFLOW;
return cksError;}
110 cksData.fmTime = mtime;
111 cksData.
csTime = time(0) - mtime;
115 return std::vector<char>( (
char *)&cksData,
116 ((
char *)&cksData) +
sizeof(cksData));
int Set(const char *csName)
static const int NameSize
References XrdCksData::csTime, XrdCksData::NameSize, and XrdCksData::Set().
◆ XrdCksAttrName()
std::string XrdCksAttrName |
( |
const char * |
cstype, |
|
|
const char * |
nspfx = "" |
|
) |
| |
Generate the extended attribute variable name for a particular checksum.
- Parameters
-
cstype | A null terminated string holding the checksum type (e.g. "adler32", "md5", "sha2", etc). |
nspfx | Is the namespace prefix to add to the variable name. By default no prefix os used. Certain platforms and/or filesystems require that user attributes start with a particular prefix (e.g. Linux requires 'user.') others do not. If your are going to use the variable name to get or set an attribute you should specify any required prefix. If specified and it does not end with a dot, a dot is automatically added to the nspfx. |
- Returns
- A string holding the variable name that should be used to get or set the extended attribute holding the correspnding checksum. If a null string is returned, the variable could not be generated; errno is set to: ENAMETOOLONG - checksum type is too long.
Definition at line 125 of file XrdCksAssist.cc.
129 int pfxlen = strlen(nspfx);
134 {
if (!strcmp(cstype,
"adler32"))
return std::string(
"XrdCks.adler32");
135 if (!strcmp(cstype,
"md5" ))
return std::string(
"XrdCks.md5");
136 if (!strcmp(cstype,
"crc32" ))
return std::string(
"XrdCks.crc32");
141 if (!LowerCase(cstype, csName,
sizeof(csName)))
142 {errno = ENAMETOOLONG;
return xaName;}
146 xaName.reserve(strlen(nspfx) + strlen(cstype) + 8);
149 if (nspfx[pfxlen-1] !=
'.') xaName +=
'.';
References XrdCksData::NameSize.
◆ XrdCksAttrValue()
std::string XrdCksAttrValue |
( |
const char * |
cstype, |
|
|
const char * |
csbuff, |
|
|
int |
csblen |
|
) |
| |
Extract th checksum value from checksum extended attribute data.
- Parameters
-
cstype | A null terminated string holding the checksum type (e.g. "adler32", "md5", "sha2", etc). |
csbuff | A pointer to a buffer hlding the checksum data. |
csblen | The length of the checksum data (i.e. the length of the retrieved extended attribute). |
- Returns
- A string holding the ASCII hexstring correspoding to the checksum value. If a null string is returned then the checksum data was invalid or did not correspond to the specified checksum type, the errno is set to: EINVAL - the checksum length in csbuff is incorrect. EMSGSIZE - csblen was not the expected value. ENOENT - the specified cstype did not match the one in csbuff. EOVERFLOW - checksum value could not be generated from csbuff.
Definition at line 163 of file XrdCksAssist.cc.
172 if (csblen != (
int)
sizeof(cksData)) {errno = EMSGSIZE;
return csError;}
176 memcpy(&cksData, csbuff,
sizeof(cksData));
181 {errno = ENOENT;
return csError;}
183 {errno = EINVAL;
return csError;}
187 for (
int i = 0; i < csNum; i++)
188 {
if (!strcmp(csTab[i].csName, cstype)
189 && csTab[i].csLenB !=
int(cksData.
Length))
190 {errno = EINVAL;
return csError;}
195 if (!cksData.
Get(csBuff,
sizeof(csBuff)))
196 {errno = EOVERFLOW;
return csError;}
200 return std::string(csBuff);
static const int ValuSize
int Get(char *Buff, int Blen)
References XrdCksData::Get(), XrdCksData::Length, XrdCksData::Name, XrdCksData::NameSize, and XrdCksData::ValuSize.