XRootD
XrdPssCks Class Reference

#include <XrdPssCks.hh>

+ Inheritance diagram for XrdPssCks:
+ Collaboration diagram for XrdPssCks:

Public Member Functions

 XrdPssCks (XrdSysError *erP)
 
virtual ~XrdPssCks ()
 
virtual int Calc (const char *Pfn, XrdCksData &Cks, int doSet=1)
 
virtual int Config (const char *Token, char *Line)
 
virtual int Del (const char *Pfn, XrdCksData &Cks)
 
virtual int Get (const char *Pfn, XrdCksData &Cks)
 
virtual int Init (const char *ConfigFN, const char *DfltCalc=0)
 
virtual char * List (const char *Pfn, char *Buff, int Blen, char Sep=' ')
 
virtual const char * Name (int seqNum=0)
 
virtual int Set (const char *Pfn, XrdCksData &Cks, int myTime=0)
 
virtual int Size (const char *Name=0)
 
virtual int Ver (const char *Pfn, XrdCksData &Cks)
 
- Public Member Functions inherited from XrdCks
 XrdCks (XrdSysError *erP)
 Constructor. More...
 
virtual ~XrdCks ()
 Destructor. More...
 
virtual int Calc (const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP, int doSet=1)
 
virtual XrdCksCalcObject (const char *name)
 
virtual int Ver (const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP)
 

Additional Inherited Members

- Protected Attributes inherited from XrdCks
XrdSysErroreDest
 

Detailed Description

Definition at line 40 of file XrdPssCks.hh.

Constructor & Destructor Documentation

◆ XrdPssCks()

XrdPssCks::XrdPssCks ( XrdSysError erP)

Definition at line 80 of file XrdPssCks.cc.

80  : XrdCks(erP)
81 {
82 
83 // Prefill the native digests we support
84 //
85  csTab[0].Len = 4; strcpy(csTab[0].Name, "adler32");
86  csTab[1].Len = 4; strcpy(csTab[1].Name, "crc32");
87  csTab[2].Len = 16; strcpy(csTab[2].Name, "md5");
88  csTab[3].Len = 4; strcpy(csTab[3].Name, "crc32c");
89  csLast = 3;
90 }
XrdCks(XrdSysError *erP)
Constructor.
Definition: XrdCks.hh:272
virtual const char * Name(int seqNum=0)
Definition: XrdPssCks.cc:191

References Name().

+ Here is the call graph for this function:

◆ ~XrdPssCks()

virtual XrdPssCks::~XrdPssCks ( )
inlinevirtual

Definition at line 69 of file XrdPssCks.hh.

69 {}

Member Function Documentation

◆ Calc()

virtual int XrdPssCks::Calc ( const char *  Xfn,
XrdCksData Cks,
int  doSet = 1 
)
inlinevirtual

Calculate a new checksum for a physical file using the checksum algorithm named in the Cks parameter.

Parameters
XfnThe logical or physical name of the file to be checksumed.
CksFor input, it specifies the checksum algorithm to be used. For output, the checksum value is returned upon success.
doSetWhen true, the new value must replace any existing value in the Xfn's extended file attributes.
pcbPIn the second form, the pointer to the callback object. A nil pointer does not invoke any callback.
Returns
Success: zero with Cks structure holding the checksum value. Failure: -errno (see significant error numbers below).

Implements XrdCks.

Definition at line 44 of file XrdPssCks.hh.

45  {return Get(Pfn, Cks);}
virtual int Get(const char *Pfn, XrdCksData &Cks)
Definition: XrdPssCks.cc:108

References Get().

+ Here is the call graph for this function:

◆ Config()

virtual int XrdPssCks::Config ( const char *  Token,
char *  Line 
)
inlinevirtual

Parse a configuration directives specific to the checksum manager.

Parameters
TokenPoints to the directive that triggered the call.
LineAll the characters after the directive.
Returns
Success: 1 Failure: 0

Implements XrdCks.

Definition at line 52 of file XrdPssCks.hh.

52 {return 1;}

◆ Del()

virtual int XrdPssCks::Del ( const char *  Xfn,
XrdCksData Cks 
)
inlinevirtual

Delete the checksum from the Xfn's xattrs.

Parameters
XfnThe logical or physical name of the file to be checksumed.
CksSpecifies the checksum type to delete.
Returns
Success: 0 Failure: -errno (see significant error numbers below).

Implements XrdCks.

Definition at line 47 of file XrdPssCks.hh.

48  {return -ENOTSUP;}

◆ Get()

int XrdPssCks::Get ( const char *  Xfn,
XrdCksData Cks 
)
virtual

Retreive the checksum from the Xfn's xattrs and return it and indicate whether or not it is stale (i.e. the file modification has changed or the name and length are not the expected values).

Parameters
XfnThe logical or physical name of the file to be checksumed.
CksFor input, it specifies the checksum type to return. For output, the checksum value is returned upon success.
Returns
Success: The length of the binary checksum in the Cks structure. Failure: -errno (see significant error numbers below).

Implements XrdCks.

Definition at line 108 of file XrdPssCks.cc.

109 {
110  EPNAME("GetCks");
111  static const int cksBLen = 256;
112  static const int urlBLen = 2048;
113  char cksBuff[cksBLen], pBuff[urlBLen], cgiBuff[32], *tP;
114  XrdOucTokenizer Resp(cksBuff);
115  time_t Mtime;
116  int rc, n;
117 
118 // Construct the cgi for digest type
119 //
120  n = snprintf(cgiBuff, sizeof(cgiBuff), "cks.type=%s", Cks.Name);
121  if (n >= (int)sizeof(cgiBuff)) return -ENAMETOOLONG;
122 
123 // Construct the correct url info
124 //
125  XrdPssUrlInfo uInfo(Cks.envP, Pfn, cgiBuff, true);
126  uInfo.setID();
127 
128 // Direct the path to the origin
129 //
130  if ((rc = XrdPssSys::P2URL(pBuff, sizeof(pBuff), uInfo))) return rc;
131 
132 // Do some debugging
133 //
134 
135  if(DEBUGON) {
136  auto urlObf = obfuscateAuth(pBuff);
137  DEBUG(uInfo.Tident(),"url="<<urlObf);
138  }
139 
140 // First step is to getthe checksum value
141 //
142  if ((rc = XrdPosixXrootd::QueryChksum(pBuff, Mtime, cksBuff, cksBLen)) <= 0)
143  return (rc ? -errno : -ENOTSUP);
144 
145 // Get the checksum name
146 //
147  if (!Resp.GetLine() || !(tP = Resp.GetToken()) || !(*tP)) return -ENOMSG;
148  if (!Cks.Set(tP)) return -ENOTSUP;
149 
150 // Now get the checksum value
151 //
152  if (!(tP = Resp.GetToken()) || !(*tP)) return -ENODATA;
153  if (!Cks.Set(tP, strlen(tP))) return -ENOTSUP;
154 
155 // Set remaining fields and return success
156 //
157  Cks.fmTime = static_cast<long long>(Mtime);
158  Cks.csTime = 0;
159  return Cks.Length;
160 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
std::string obfuscateAuth(const std::string &input)
#define DEBUGON
#define ENODATA
Definition: XrdPssCks.cc:45
int Set(const char *csName)
Definition: XrdCksData.hh:81
char Length
Definition: XrdCksData.hh:52
char Name[NameSize]
Definition: XrdCksData.hh:44
static int QueryChksum(const char *path, time_t &mtime, char *buff, int blen)
static int P2URL(char *pbuff, int pblen, XrdPssUrlInfo &uInfo, bool doN2N=true)
Definition: XrdPss.cc:1414

References XrdCksData::csTime, DEBUG, DEBUGON, ENODATA, EPNAME, XrdOucTokenizer::GetLine(), XrdOucTokenizer::GetToken(), XrdCksData::Length, XrdCksData::Name, obfuscateAuth(), XrdPssSys::P2URL(), XrdPosixXrootd::QueryChksum(), XrdCksData::Set(), XrdPssUrlInfo::setID(), and XrdPssUrlInfo::Tident().

Referenced by Calc(), and Ver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Init()

int XrdPssCks::Init ( const char *  ConfigFN,
const char *  DfltCalc = 0 
)
virtual

Fully initialize the manager which includes loading any plugins.

Parameters
ConfigFNPoints to the configuration file path.
DfltCalcIs the default checksum and should be defaulted if NULL. The default implementation defaults this to adler32. A default is only needed should the checksum name in the XrdCksData object be omitted.
Returns
Success: 1 Failure: 0

Implements XrdCks.

Definition at line 166 of file XrdPssCks.cc.

167 {
168  int i;
169 
170 // See if we need to set the default calculation
171 //
172  if (DfltCalc)
173  {for (i = 0; i <= csLast; i++) if (!strcmp(csTab[i].Name, DfltCalc)) break;
174  if (i >= csMax)
175  {eDest->Emsg("Config", DfltCalc, "cannot be made the default; "
176  "not supported.");
177  return 0;
178  }
179  if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;}
180  }
181 
182 // All done
183 //
184  return 1;
185 }
XrdSysError * eDest
Definition: XrdCks.hh:289
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdCks::eDest, XrdSysError::Emsg(), and Name().

+ Here is the call graph for this function:

◆ List()

virtual char* XrdPssCks::List ( const char *  Xfn,
char *  Buff,
int  Blen,
char  Sep = ' ' 
)
inlinevirtual

List names of the checksums associated with a Xfn or all supported ones.

Parameters
XfnThe logical or physical file name whose checksum names are to be returned. When Xfn is null, return all supported checksum algorithm names.
BuffPoints to a buffer, at least 64 bytes in length, to hold a "Sep" separated list of checksum names.
BlenThe length of the buffer.
SepThe separation character to be used between adjacent names.
Returns
Success: Pointer to Buff holding at least one checksum name. Failure: A nil pointer is returned.

Implements XrdCks.

Definition at line 56 of file XrdPssCks.hh.

57  {return 0;}

◆ Name()

const char * XrdPssCks::Name ( int  seqNum = 0)
virtual

Get the name of the checksums associated with a sequence number. Note that Name() may be called prior to final config to see if there are any chksums to configure and avoid unintended errors.

Parameters
seqNumThe sequence number. Zero signifies the default name. Higher numbers are alternates.
Returns
Success: Pointer to the name. Failure: A nil pointer is returned (no more alternates exist).

Implements XrdCks.

Definition at line 191 of file XrdPssCks.cc.

192 {
193 
194  return (seqNum < 0 || seqNum > csLast ? 0 : csTab[seqNum].Name);
195 }

Referenced by XrdPssCks(), Init(), and Size().

+ Here is the caller graph for this function:

◆ Set()

virtual int XrdPssCks::Set ( const char *  Xfn,
XrdCksData Cks,
int  myTime = 0 
)
inlinevirtual

Set a file's checksum in the extended attributes along with the file's mtime and the time of setting.

Parameters
XfnThe logical or physical name of the file to be set.
CksSpecifies the checksum name and value.
myTimeWhen true then the fmTime and gmTime in the Cks structure are to be used; as opposed to the current time.
Returns
Success: zero is returned. Failure: -errno (see significant error numbers below).

Implements XrdCks.

Definition at line 63 of file XrdPssCks.hh.

64  {return -ENOTSUP;}

◆ Size()

int XrdPssCks::Size ( const char *  Name = 0)
virtual

Get the binary length of the checksum with the corresponding name.

Parameters
NameThe checksum algorithm name. If null, use the default name.
Returns
Success: checksum length. Failure: Zero if the checksum name does not exist.

Implements XrdCks.

Definition at line 201 of file XrdPssCks.cc.

202 {
203  csInfo *iP = (Name != 0 ? Find(Name) : &csTab[0]);
204  return (iP != 0 ? iP->Len : 0);
205 }

References Name().

+ Here is the call graph for this function:

◆ Ver()

int XrdPssCks::Ver ( const char *  Xfn,
XrdCksData Cks 
)
virtual

Retreive the checksum from the Xfn's xattrs and compare it to the supplied checksum. If the checksum is not available or is stale, a new checksum is calculated and written to the extended attributes.

Parameters
XfnThe logical or physical name of the file to be verified.
CksSpecifies the checksum name and value.
pcbPIn the second form, the pointer to the callback object. A nil pointer does not invoke any callback.
Returns
Success: True Failure: False (the checksums do not match) or -errno indicating that verification could not be performed (see significant error numbers below).

Implements XrdCks.

Definition at line 211 of file XrdPssCks.cc.

212 {
213  XrdCksData fCks;
214  csInfo *csIP = &csTab[0];
215  int rc;
216 
217 // Determine which checksum to get
218 //
219  if (!(*Cks.Name)) strcpy(Cks.Name, csTab[0].Name);
220  else if (!(csIP = Find(Cks.Name))) return -ENOTSUP;
221 
222 // Get the file checksum
223 //
224  if ((rc = Get(Pfn, fCks))) return rc;
225 
226 // Compare the checksums
227 //
228  return (!strcmp(fCks.Name, Cks.Name) && fCks.Length == Cks.Length
229  && !memcmp(fCks.Value, Cks.Value, csIP->Len));
230 }
char Value[ValuSize]
Definition: XrdCksData.hh:53

References Get(), XrdCksData::Length, XrdCksData::Name, and XrdCksData::Value.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: