|
|
|||
File indexing completed on 2026-01-08 10:33:35
0001 #ifndef __XRDCKS_HH__ 0002 #define __XRDCKS_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d C k s . h h */ 0006 /* */ 0007 /* (c) 2011 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/XrdCksData.hh" 0034 0035 class XrdCks; 0036 class XrdCksCalc; 0037 class XrdOucStream; 0038 class XrdSysError; 0039 class XrdSysPlugin; 0040 0041 /*! This class defines the checksum management interface. It should be used as 0042 the base class for a plugin. When used that way, the shared library holding 0043 the plugin must define a "C" entry point named XrdCksInit() as described at 0044 the end of this include file. Note that you can also base you plugin on the 0045 native implementation, XrdCks, and replace only selected methods. 0046 */ 0047 0048 /******************************************************************************/ 0049 /* X r d C k s P C B */ 0050 /******************************************************************************/ 0051 /*! The XrdCksPCB object defines a callback hat allows he caller to monitor the 0052 progress of a checksum calculation (calc or verify). 0053 */ 0054 0055 class XrdCksPCB 0056 { 0057 public: 0058 0059 //------------------------------------------------------------------------------ 0060 //! Report checksum progress. 0061 //! @param fsize The file size in bytes. 0062 //! @param csbytes Bytes checksummed so far. 0063 //------------------------------------------------------------------------------ 0064 0065 virtual void Info(long long fsize, long long csbytes); 0066 0067 long long rsvd; 0068 0069 XrdCksPCB() : rsvd(0) {} 0070 virtual ~XrdCksPCB() {} 0071 }; 0072 0073 /******************************************************************************/ 0074 /* X r d C k s */ 0075 /******************************************************************************/ 0076 //------------------------------------------------------------------------------ 0077 //! @note Filenames passed to any of the manager's methods may be either logical 0078 //! (lfn) or physical (pfn). By default, these are always physical file names. 0079 //! However, it is possible to configure the default manager to use the Oss 0080 //! plugin for all I/O related functions. In this case, a logical filename may 0081 //! be passed if this is required by the Oss plugin as it will translate the 0082 //! logical name to the physical one. See the "ofs.osslib" directive for 0083 //! details. Additionally, when using the default Oss or Pss plugins as the I/O 0084 //! provider, logical file names are always provided to the manager. Note that 0085 //! default manager is automatically configured to accept the correct type of 0086 //! file name. There is no mechanism to do this for a specialized manager. So, 0087 //! it's possible to create a configuration file that requires logical name to 0088 //! be supplied when the manager override only accepts physical ones. 0089 //------------------------------------------------------------------------------ 0090 0091 class XrdCks 0092 { 0093 public: 0094 0095 //------------------------------------------------------------------------------ 0096 //! Calculate a new checksum for a physical file using the checksum algorithm 0097 //! named in the Cks parameter. 0098 //! 0099 //! @param Xfn The logical or physical name of the file to be checksumed. 0100 //! @param Cks For input, it specifies the checksum algorithm to be used. 0101 //! For output, the checksum value is returned upon success. 0102 //! @param doSet When true, the new value must replace any existing value 0103 //! in the Xfn's extended file attributes. 0104 //! @param pcbP In the second form, the pointer to the callback object. 0105 //! A nil pointer does not invoke any callback. 0106 //! 0107 //! @return Success: zero with Cks structure holding the checksum value. 0108 //! Failure: -errno (see significant error numbers below). 0109 //------------------------------------------------------------------------------ 0110 virtual 0111 int Calc( const char *Xfn, XrdCksData &Cks, int doSet=1) = 0; 0112 0113 virtual 0114 int Calc( const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP, int doSet=1) 0115 {(void)pcbP; return Calc(Xfn, Cks, doSet);} 0116 0117 //------------------------------------------------------------------------------ 0118 //! Delete the checksum from the Xfn's xattrs. 0119 //! 0120 //! @param Xfn The logical or physical name of the file to be checksumed. 0121 //! @param Cks Specifies the checksum type to delete. 0122 //! 0123 //! @return Success: 0 0124 //! Failure: -errno (see significant error numbers below). 0125 //------------------------------------------------------------------------------ 0126 virtual 0127 int Del( const char *Xfn, XrdCksData &Cks) = 0; 0128 0129 //------------------------------------------------------------------------------ 0130 //! Retreive the checksum from the Xfn's xattrs and return it and indicate 0131 //! whether or not it is stale (i.e. the file modification has changed or the 0132 //! name and length are not the expected values). 0133 //! 0134 //! @param Xfn The logical or physical name of the file to be checksumed. 0135 //! @param Cks For input, it specifies the checksum type to return. 0136 //! For output, the checksum value is returned upon success. 0137 //! 0138 //! @return Success: The length of the binary checksum in the Cks structure. 0139 //! Failure: -errno (see significant error numbers below). 0140 //------------------------------------------------------------------------------ 0141 virtual 0142 int Get( const char *Xfn, XrdCksData &Cks) = 0; 0143 0144 //------------------------------------------------------------------------------ 0145 //! Parse a configuration directives specific to the checksum manager. 0146 //! 0147 //! @param Token Points to the directive that triggered the call. 0148 //! @param Line All the characters after the directive. 0149 //! 0150 //! @return Success: 1 0151 //! Failure: 0 0152 //------------------------------------------------------------------------------ 0153 virtual 0154 int Config(const char *Token, char *Line) = 0; 0155 0156 //------------------------------------------------------------------------------ 0157 //! Fully initialize the manager which includes loading any plugins. 0158 //! 0159 //! @param ConfigFN Points to the configuration file path. 0160 //! @param DfltCalc Is the default checksum and should be defaulted if NULL. 0161 //! The default implementation defaults this to adler32. A 0162 //! default is only needed should the checksum name in the 0163 //! XrdCksData object be omitted. 0164 //! 0165 //!@return Success: 1 0166 //! Failure: 0 0167 //------------------------------------------------------------------------------ 0168 virtual 0169 int Init(const char *ConfigFN, const char *DfltCalc=0) = 0; 0170 0171 //------------------------------------------------------------------------------ 0172 //! List names of the checksums associated with a Xfn or all supported ones. 0173 //! 0174 //! @param Xfn The logical or physical file name whose checksum names are 0175 //! to be returned. When Xfn is null, return all supported 0176 //! checksum algorithm names. 0177 //! @param Buff Points to a buffer, at least 64 bytes in length, to hold 0178 //! a "Sep" separated list of checksum names. 0179 //! @param Blen The length of the buffer. 0180 //! @param Sep The separation character to be used between adjacent names. 0181 //! 0182 //! @return Success: Pointer to Buff holding at least one checksum name. 0183 //! Failure: A nil pointer is returned. 0184 //------------------------------------------------------------------------------ 0185 virtual 0186 char *List(const char *Xfn, char *Buff, int Blen, char Sep=' ') = 0; 0187 0188 //------------------------------------------------------------------------------ 0189 //! Get the name of the checksums associated with a sequence number. Note that 0190 //! Name() may be called prior to final config to see if there are any chksums 0191 //! to configure and avoid unintended errors. 0192 //! 0193 //! @param seqNum The sequence number. Zero signifies the default name. 0194 //! Higher numbers are alternates. 0195 //! @return Success: Pointer to the name. 0196 //! Failure: A nil pointer is returned (no more alternates exist). 0197 //------------------------------------------------------------------------------ 0198 virtual const 0199 char *Name(int seqNum=0) = 0; 0200 0201 //------------------------------------------------------------------------------ 0202 //! Get a new XrdCksCalc object that can calculate the checksum corresponding to 0203 //! the specified name or the default object if name is a null pointer. The 0204 //! object can be used to compute checksums on the fly. The object's Recycle() 0205 //! method must be used to delete it. 0206 //! 0207 //! @param name The name of the checksum algorithm. If null, use the 0208 //! default one. 0209 //! 0210 //! @return Success: A pointer to the object is returned. 0211 //! Failure: Zero if no corresponding object exists. 0212 //------------------------------------------------------------------------------ 0213 virtual 0214 XrdCksCalc *Object(const char *name) 0215 { 0216 (void)name; 0217 return 0; 0218 } 0219 0220 //------------------------------------------------------------------------------ 0221 //! Get the binary length of the checksum with the corresponding name. 0222 //! 0223 //! @param Name The checksum algorithm name. If null, use the default name. 0224 //! 0225 //! @return Success: checksum length. 0226 //! Failure: Zero if the checksum name does not exist. 0227 //------------------------------------------------------------------------------ 0228 virtual 0229 int Size( const char *Name=0) = 0; 0230 0231 //------------------------------------------------------------------------------ 0232 //! Set a file's checksum in the extended attributes along with the file's mtime 0233 //! and the time of setting. 0234 //! 0235 //! @param Xfn The logical or physical name of the file to be set. 0236 //! @param Cks Specifies the checksum name and value. 0237 //! @param myTime When true then the fmTime and gmTime in the Cks structure 0238 //! are to be used; as opposed to the current time. 0239 //! 0240 //! @return Success: zero is returned. 0241 //! Failure: -errno (see significant error numbers below). 0242 //------------------------------------------------------------------------------ 0243 virtual 0244 int Set( const char *Xfn, XrdCksData &Cks, int myTime=0) = 0; 0245 0246 //------------------------------------------------------------------------------ 0247 //! Retreive the checksum from the Xfn's xattrs and compare it to the supplied 0248 //! checksum. If the checksum is not available or is stale, a new checksum is 0249 //! calculated and written to the extended attributes. 0250 //! 0251 //! @param Xfn The logical or physical name of the file to be verified. 0252 //! @param Cks Specifies the checksum name and value. 0253 //! @param pcbP In the second form, the pointer to the callback object. 0254 //! A nil pointer does not invoke any callback. 0255 //! 0256 //! @return Success: True 0257 //! Failure: False (the checksums do not match) or -errno indicating 0258 //! that verification could not be performed (see significant 0259 //! error numbers below). 0260 //------------------------------------------------------------------------------ 0261 virtual 0262 int Ver( const char *Xfn, XrdCksData &Cks) = 0; 0263 0264 virtual 0265 int Ver( const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP) 0266 {(void)pcbP; return Ver(Xfn, Cks);} 0267 0268 //------------------------------------------------------------------------------ 0269 //! Constructor 0270 //------------------------------------------------------------------------------ 0271 0272 XrdCks(XrdSysError *erP) : eDest(erP) {} 0273 0274 //------------------------------------------------------------------------------ 0275 //! Destructor 0276 //------------------------------------------------------------------------------ 0277 virtual ~XrdCks() {} 0278 0279 /*! Significant errno values: 0280 0281 -EDOM The supplied checksum length is invalid for the checksum name. 0282 -ENOTSUP The supplied or default checksum name is not supported. 0283 -ESRCH Checksum does not exist for file. 0284 -ESTALE The file's checksum is no longer valid. 0285 */ 0286 0287 protected: 0288 0289 XrdSysError *eDest; 0290 }; 0291 0292 /******************************************************************************/ 0293 /* X r d C k s I n i t */ 0294 /******************************************************************************/ 0295 0296 #define XRDCKSINITPARMS XrdSysError *, const char *, const char * 0297 0298 //------------------------------------------------------------------------------ 0299 //! Obtain an instance of the checksum manager. 0300 //! 0301 //! XrdCksInit() is an extern "C" function that is called to obtain an instance 0302 //! of a checksum manager object that will be used for all subsequent checksums. 0303 //! This is useful when checksums come from an alternate source (e.g. database). 0304 //! The proxy server uses this mechanism to obtain checksums from the underlying 0305 //! data server. You can also defined plugins for specific checksum calculations 0306 //! (see XrdCksCalc.hh). The function must be defined in the plug-in shared 0307 //! library. All the following extern symbols must be defined at file level! 0308 //! 0309 //! @param eDest-> The XrdSysError object for messages. 0310 //! @param cfn -> The name of the configuration file 0311 //! @param parm -> Parameters specified on the ckslib directive. If none it is 0312 //! zero. 0313 //! 0314 //! @return Success: A pointer to the checksum manager object. 0315 //! Failure: Null pointer which causes initialization to fail. 0316 //------------------------------------------------------------------------------ 0317 0318 /*! extern "C" XrdCks *XrdCksInit(XrdSysError *eDest, 0319 const char *cFN, 0320 const char *Parms 0321 ); 0322 */ 0323 //------------------------------------------------------------------------------ 0324 //! Declare the compilation version number. 0325 //! 0326 //! Additionally, you *should* declare the xrootd version you used to compile 0327 //! your plug-in. While not currently required, it is highly recommended to 0328 //! avoid execution issues should the class definition change. Declare it as: 0329 //------------------------------------------------------------------------------ 0330 0331 /*! #include "XrdVersion.hh" 0332 XrdVERSIONINFO(XrdCksInit,<name>); 0333 0334 where <name> is a 1- to 15-character unquoted name identifying your plugin. 0335 */ 0336 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|