xrootd
XrdCks.hh
Go to the documentation of this file.
00001 #ifndef __XRDCKS_HH__
00002 #define __XRDCKS_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                             X r d C k s . h h                              */
00006 /*                                                                            */
00007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 #include "XrdCks/XrdCksData.hh"
00014 
00015 class XrdCks;
00016 class XrdOucStream;
00017 class XrdSysError;
00018 class XrdSysPlugin;
00019 
00020 /* This class defines the checksum management interface. It should be used as
00021    the base class for a plugin. When used that way, the shared library holding
00022    the plugin must define a "C" entry point named XrdCksInit() as described at
00023    the end of this include file. Note that you can also base you plugin on the
00024    native implementation, XrdCks, and replace only selected methods.
00025 */
00026   
00027 class XrdCks
00028 {
00029 public:
00030 
00031 /* Calc()  Calculates a new checksum for the Pfn using the checksum name in
00032            Cks parameter. The calculated value is returned in Cks as well. If
00033            doSet is true, the new value replaces any existing value in the
00034            Pfn's extended attributes.
00035            Success:  zero is returned.
00036            Failure: -errno (see significant error numbers below).
00037 */
00038 virtual
00039 int        Calc( const char *Pfn, XrdCksData &Cks, int doSet=1) = 0;
00040 
00041 /* Del()   deletes the checksum from the Pfn's xattrs.
00042            Success: 0
00043            Failure: -errno (see significant error numbers below).
00044 */
00045 virtual
00046 int        Del(  const char *Pfn, XrdCksData &Cks) = 0;
00047 
00048 /* Get()   retreives the checksum from the Pfn's xattrs and returns it and
00049            indicates whether or not it is stale (i.e. the file modification has
00050            changed or the name and length are not the expected values).
00051            Success: The length of the binary checksum is returned.
00052            Failure: -errno (see significant error numbers below).
00053 */
00054 virtual
00055 int        Get(  const char *Pfn, XrdCksData &Cks) = 0;
00056 
00057 /* Config  Is used to parse configuration directives specific to the manager.
00058            Token points to the directive that triggered the call. Line are all
00059            the characters after the directive.
00060            Success:  1
00061            Failure:  0
00062 */
00063 virtual
00064 int        Config(const char *Token, char *Line) = 0;
00065 
00066 /* Init()  Init is used to fully initialize the manager which includes loading
00067            any plugins. You can also specify the default checksum. If not given
00068            it becomes adler32. A default is only needed if you will not be
00069            specifying the checksum name in the XrdCksData object.
00070            Success:  1
00071            Failure:  0
00072 */
00073 virtual
00074 int        Init(const char *ConfigFN, const char *DfltCalc=0) = 0;
00075 
00076 /* List()  returns the names of the checksums associated with Pfn. If Pfn is
00077            not given, it returns a list of supported checksums. The buffer
00078            should be at least 64 bytes in length; otherwise truncation occurs.
00079            Success: Buff is returned with at least one checksum name.
00080            Failure: A nil pointer is returned.
00081 */
00082 virtual
00083 char      *List(const char *Pfn, char *Buff, int Blen, char Sep=' ') = 0;
00084 
00085 /* Name()  returns the name of the checksums associated with a sequence number.
00086            Zero is the default name. Higher numbers are alternates. When no
00087            more alternates exist, a null pointer is returned. Note that Name()
00088            may be called prior to final config to see if there are any chksums
00089            to configure and avoid unintended errors.
00090            Success: Pointer to the name.
00091            Failure: A nil pointer is returned.
00092 */
00093 virtual const
00094 char      *Name(int seqNum=0) = 0;
00095 
00096 /* Size()  returns the binary length of the checksum with the corresponding
00097            name. If no name is given, the default name is used.
00098            Success: checksum length.
00099            Failure: Zero  if the checksum name does not exist.
00100 */
00101 virtual
00102 int        Size( const char  *Name=0) = 0;
00103 
00104 /* Set()   sets the Pfn's checksum in the extended attributes. The file's mtime
00105            and the time of setting is automatically added to the information.
00106            If myTime is true then CksData values for fmTime and gmTime are used.
00107            Success:  zero is returned.
00108            Failure: -errno (see significant error numbers below).
00109 */
00110 virtual
00111 int        Set(  const char *Pfn, XrdCksData &Cks, int myTime=0) = 0;
00112 
00113 /* Ver()   retreives the checksum from the Pfn's xattrs and compares it to the
00114            supplied checksum. If the checksum is not available or is stale,
00115            a new checksum is calculated and written to the extended attributes.
00116            Success: True
00117            Failure: False (the checksums do not match).
00118                     -errno Otherwise (see significant error numbers below).
00119 */
00120 virtual
00121 int        Ver(  const char *Pfn, XrdCksData &Cks) = 0;
00122 
00123            XrdCks(XrdSysError *erP) : eDest(erP) {}
00124 virtual   ~XrdCks() {}
00125 
00126 /* Significant errno values:
00127 
00128    -EDOM       The supplied checksum length is invalid for the checksum name.
00129    -ENOTSUP    The supplied or default checksum name is not supported.
00130    -ESRCH      Checksum does not exist for file.
00131    -ESTALE     The file's checksum is no longer valid.
00132 */
00133 
00134 protected:
00135 
00136 XrdSysError   *eDest;
00137 };
00138 
00139 /******************************************************************************/
00140 /*                            X r d C k s I n i t                             */
00141 /******************************************************************************/
00142 
00143 #define XRDCKSINITPARMS XrdSysError *, const char *, const char *
00144   
00145 /* When building a shared library plugin, the following "C" entry point must
00146    exist in the library:
00147 
00148    extern "C"
00149           {XrdCks *XrdCksInit(XrdSysError *eDest,  // The error msg object
00150                               const char  *cFN,    // Config file name
00151                               const char  *Parms   // Parms via lib directive
00152                              );
00153           }
00154 
00155    This entry is called to get an instance of the checksum manager.
00156    If the object cannot be created; return 0.
00157 */
00158 #endif