|
|
|||
File indexing completed on 2026-01-08 10:33:35
0001 #ifndef __XRDCKSWRAPPER_HH__ 0002 #define __XRDCKSWRAPPER_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d C k s W r a p p e r . h h */ 0006 /* */ 0007 /* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* All Rights Reserved */ 0009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0011 /* */ 0012 /* This file is part of the XRootD software suite. */ 0013 /* */ 0014 /* XRootD is free software: you can redistribute it and/or modify it under */ 0015 /* the terms of the GNU Lesser General Public License as published by the */ 0016 /* Free Software Foundation, either version 3 of the License, or (at your */ 0017 /* option) any later version. */ 0018 /* */ 0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0022 /* License for more details. */ 0023 /* */ 0024 /* You should have received a copy of the GNU Lesser General Public License */ 0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0027 /* */ 0028 /* The copyright holder's institutional names and contributor's names may not */ 0029 /* be used to endorse or promote products derived from this software without */ 0030 /* specific prior written permission of the institution or contributor. */ 0031 /******************************************************************************/ 0032 0033 #include "XrdCks/XrdCks.hh" 0034 0035 class XrdCksCalc; 0036 class XrdCksData; 0037 class XrdOucEnv; 0038 class XrdOucStream; 0039 class XrdSysError; 0040 0041 /*! This class defines the wrapper for the checksum management interface. 0042 It should be used as the base class for a stacked plugin. When used that 0043 way, the shared library holding the plugin must define a "C" entry point 0044 named XrdCksAdd2() as described at the end of this include file. Note 0045 you pass a reference to the previous plugin-in in the plug-in chain as a 0046 constructor argument as supplied to the XrdCksAdd2() function. 0047 Override the methods you wish to wrap. Methods that are not overridden 0048 are forwarded to the previous plug-in. 0049 */ 0050 0051 class XrdCksWrapper : public XrdCks 0052 { 0053 public: 0054 0055 //------------------------------------------------------------------------------ 0056 //! Calculate a new checksum for a physical file using the checksum algorithm 0057 //! named in the Cks parameter. 0058 //! 0059 //! @param Xfn The logical or physical name of the file to be checksumed. 0060 //! @param Cks For input, it specifies the checksum algorithm to be used. 0061 //! For output, the checksum value is returned upon success. 0062 //! @param doSet When true, the new value must replace any existing value 0063 //! in the Xfn's extended file attributes. 0064 //! @param pcbP In the second form, the pointer to the callback object. 0065 //! A nil pointer does not invoke any callback. 0066 //! 0067 //! @return Success: zero with Cks structure holding the checksum value. 0068 //! Failure: -errno (see significant error numbers below). 0069 //------------------------------------------------------------------------------ 0070 virtual 0071 int Calc( const char *Xfn, XrdCksData &Cks, int doSet=1) 0072 {return cksPI.Calc(Xfn, Cks, doSet);} 0073 0074 virtual 0075 int Calc( const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP, int doSet=1) 0076 {(void)pcbP; return Calc(Xfn, Cks, doSet);} 0077 0078 //------------------------------------------------------------------------------ 0079 //! Delete the checksum from the Xfn's xattrs. 0080 //! 0081 //! @param Xfn The logical or physical name of the file to be checksumed. 0082 //! @param Cks Specifies the checksum type to delete. 0083 //! 0084 //! @return Success: 0 0085 //! Failure: -errno (see significant error numbers below). 0086 //------------------------------------------------------------------------------ 0087 virtual 0088 int Del( const char *Xfn, XrdCksData &Cks) 0089 {return cksPI.Del(Xfn, Cks);} 0090 0091 //------------------------------------------------------------------------------ 0092 //! Retreive the checksum from the Xfn's xattrs and return it and indicate 0093 //! whether or not it is stale (i.e. the file modification has changed or the 0094 //! name and length are not the expected values). 0095 //! 0096 //! @param Xfn The logical or physical name of the file to be checksumed. 0097 //! @param Cks For input, it specifies the checksum type to return. 0098 //! For output, the checksum value is returned upon success. 0099 //! 0100 //! @return Success: The length of the binary checksum in the Cks structure. 0101 //! Failure: -errno (see significant error numbers below). 0102 //------------------------------------------------------------------------------ 0103 virtual 0104 int Get( const char *Xfn, XrdCksData &Cks) 0105 {return cksPI.Get(Xfn, Cks);} 0106 0107 //------------------------------------------------------------------------------ 0108 //! Parse a configuration directives specific to the checksum manager. 0109 //! 0110 //! @param Token Points to the directive that triggered the call. 0111 //! @param Line All the characters after the directive. 0112 //! 0113 //! @return Success: 1 0114 //! Failure: 0 0115 //------------------------------------------------------------------------------ 0116 virtual 0117 int Config(const char *Token, char *Line) 0118 {return cksPI.Config(Token, Line);} 0119 0120 //------------------------------------------------------------------------------ 0121 //! Fully initialize the manager which includes loading any plugins. 0122 //! 0123 //! @param ConfigFN Points to the configuration file path. 0124 //! @param DfltCalc Is the default checksum and should be defaulted if NULL. 0125 //! The default implementation defaults this to adler32. A 0126 //! default is only needed should the checksum name in the 0127 //! XrdCksData object be omitted. 0128 //! 0129 //!@return Success: 1 0130 //! Failure: 0 0131 //------------------------------------------------------------------------------ 0132 virtual 0133 int Init(const char *ConfigFN, const char *DfltCalc=0) 0134 {return cksPI.Init(ConfigFN, DfltCalc);} 0135 0136 //------------------------------------------------------------------------------ 0137 //! List names of the checksums associated with a Xfn or all supported ones. 0138 //! 0139 //! @param Xfn The logical or physical file name whose checksum names are 0140 //! to be returned. When Xfn is null, return all supported 0141 //! checksum algorithm names. 0142 //! @param Buff Points to a buffer, at least 64 bytes in length, to hold 0143 //! a "Sep" separated list of checksum names. 0144 //! @param Blen The length of the buffer. 0145 //! @param Sep The separation character to be used between adjacent names. 0146 //! 0147 //! @return Success: Pointer to Buff holding at least one checksum name. 0148 //! Failure: A nil pointer is returned. 0149 //------------------------------------------------------------------------------ 0150 virtual 0151 char *List(const char *Xfn, char *Buff, int Blen, char Sep=' ') 0152 {return cksPI.List(Xfn, Buff, Blen, Sep);} 0153 0154 //------------------------------------------------------------------------------ 0155 //! Get the name of the checksums associated with a sequence number. Note that 0156 //! Name() may be called prior to final config to see if there are any chksums 0157 //! to configure and avoid unintended errors. 0158 //! 0159 //! @param seqNum The sequence number. Zero signifies the default name. 0160 //! Higher numbers are alternates. 0161 //! @return Success: Pointer to the name. 0162 //! Failure: A nil pointer is returned (no more alternates exist). 0163 //------------------------------------------------------------------------------ 0164 virtual const 0165 char *Name(int seqNum=0) {return cksPI.Name(seqNum);} 0166 0167 //------------------------------------------------------------------------------ 0168 //! Get a new XrdCksCalc object that can calculate the checksum corresponding to 0169 //! the specified name or the default object if name is a null pointer. The 0170 //! object can be used to compute checksums on the fly. The object's Recycle() 0171 //! method must be used to delete it. 0172 //! 0173 //! @param name The name of the checksum algorithm. If null, use the 0174 //! default one. 0175 //! 0176 //! @return Success: A pointer to the object is returned. 0177 //! Failure: Zero if no corresponding object exists. 0178 //------------------------------------------------------------------------------ 0179 virtual 0180 XrdCksCalc *Object(const char *name) {return cksPI.Object(name);} 0181 0182 //------------------------------------------------------------------------------ 0183 //! Get the binary length of the checksum with the corresponding name. 0184 //! 0185 //! @param Name The checksum algorithm name. If null, use the default name. 0186 //! 0187 //! @return Success: checksum length. 0188 //! Failure: Zero if the checksum name does not exist. 0189 //------------------------------------------------------------------------------ 0190 virtual 0191 int Size( const char *Name=0) {return cksPI.Size(Name);} 0192 0193 //------------------------------------------------------------------------------ 0194 //! Set a file's checksum in the extended attributes along with the file's mtime 0195 //! and the time of setting. 0196 //! 0197 //! @param Xfn The logical or physical name of the file to be set. 0198 //! @param Cks Specifies the checksum name and value. 0199 //! @param myTime When true then the fmTime and gmTime in the Cks structure 0200 //! are to be used; as opposed to the current time. 0201 //! 0202 //! @return Success: zero is returned. 0203 //! Failure: -errno (see significant error numbers below). 0204 //------------------------------------------------------------------------------ 0205 virtual 0206 int Set( const char *Xfn, XrdCksData &Cks, int myTime=0) 0207 {return cksPI.Set(Xfn, Cks, myTime);} 0208 0209 //------------------------------------------------------------------------------ 0210 //! Retreive the checksum from the Xfn's xattrs and compare it to the supplied 0211 //! checksum. If the checksum is not available or is stale, a new checksum is 0212 //! calculated and written to the extended attributes. 0213 //! 0214 //! @param Xfn The logical or physical name of the file to be verified. 0215 //! @param Cks Specifies the checksum name and value. 0216 //! @param pcbP In the second form, the pointer to the callback object. 0217 //! A nil pointer does not invoke any callback. 0218 //! 0219 //! @return Success: True 0220 //! Failure: False (the checksums do not match) or -errno indicating 0221 //! that verification could not be performed (see significant 0222 //! error numbers below). 0223 //------------------------------------------------------------------------------ 0224 virtual 0225 int Ver( const char *Xfn, XrdCksData &Cks) 0226 {return cksPI.Ver(Xfn, Cks);} 0227 0228 virtual 0229 int Ver( const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP) 0230 {(void)pcbP; return Ver(Xfn, Cks);} 0231 0232 //------------------------------------------------------------------------------ 0233 //! Constructor 0234 //! 0235 //! @param prevPI Reference to the antecedent plugin. 0236 //! @param errP Pointer to error message object 0237 //------------------------------------------------------------------------------ 0238 0239 XrdCksWrapper(XrdCks &prevPI, XrdSysError *errP) 0240 : XrdCks(errP), cksPI(prevPI) {} 0241 0242 //------------------------------------------------------------------------------ 0243 //! Destructor 0244 //------------------------------------------------------------------------------ 0245 0246 virtual ~XrdCksWrapper() {} 0247 0248 protected: 0249 0250 XrdCks &cksPI; 0251 }; 0252 0253 /******************************************************************************/ 0254 /* X r d C k s A d d 2 */ 0255 /******************************************************************************/ 0256 0257 #define XRDCKSADD2PARMS XrdCks &, XrdSysError *, const char *, \ 0258 const char *, XrdOucEnv * 0259 0260 //------------------------------------------------------------------------------ 0261 //! Obtain an instance of a stacked checksum manager. 0262 //! 0263 //! XrdCksAdd2() is an extern "C" function that is called to obtain an 0264 //! instance of a stacked checksum manager object that will be used for all 0265 //! subsequent checksums. This function is passed a refernce to the previous 0266 //! checksum manager. Overridden methods should, if appropriate, invoke the 0267 //! previous plug-ins corresponding method to complete the required task. 0268 //! All the following extern symbols must be defined at file level! 0269 //! 0270 //! @param pPI -> Reference to the previous checksum manager plug-in. 0271 //! @param eDest-> The XrdSysError object for messages. 0272 //! @param cFN -> The name of the configuration file 0273 //! @param Parm -> Parameters specified on the ckslib directive. If none it is 0274 //! zero. 0275 //! @param pEnv -> Pointer to environmental information or nil. 0276 //! 0277 //! @return Success: A pointer to the checksum manager object. 0278 //! Failure: Null pointer which causes initialization to fail. 0279 //------------------------------------------------------------------------------ 0280 0281 /*! extern "C" XrdCks *XrdCksAdd2(XrdCks &pPI, 0282 XrdSysError *eDest, 0283 const char *cFN, 0284 const char *Parm, 0285 XrdOucEnv *envP 0286 ); 0287 */ 0288 //------------------------------------------------------------------------------ 0289 //! Declare the compilation version number. 0290 //! 0291 //! Additionally, you *should* declare the xrootd version you used to compile 0292 //! your plug-in. While not currently required, it is highly recommended to 0293 //! avoid execution issues should the class definition change. Declare it as: 0294 //------------------------------------------------------------------------------ 0295 0296 /*! #include "XrdVersion.hh" 0297 XrdVERSIONINFO(XrdCksAdd2,<name>); 0298 0299 where <name> is a 1- to 15-character unquoted name identifying your plugin. 0300 */ 0301 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|