xrootd
XrdCks.hh
Go to the documentation of this file.
1 #ifndef __XRDCKS_HH__
2 #define __XRDCKS_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C k s . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include "XrdCks/XrdCksData.hh"
14 
15 class XrdCks;
16 class XrdOucStream;
17 class XrdSysError;
18 class XrdSysPlugin;
19 
20 /* This class defines the checksum management interface. It should be used as
21  the base class for a plugin. When used that way, the shared library holding
22  the plugin must define a "C" entry point named XrdCksInit() as described at
23  the end of this include file. Note that you can also base you plugin on the
24  native implementation, XrdCks, and replace only selected methods.
25 */
26 
27 class XrdCks
28 {
29 public:
30 
31 /* Calc() Calculates a new checksum for the Pfn using the checksum name in
32  Cks parameter. The calculated value is returned in Cks as well. If
33  doSet is true, the new value replaces any existing value in the
34  Pfn's extended attributes.
35  Success: zero is returned.
36  Failure: -errno (see significant error numbers below).
37 */
38 virtual
39 int Calc( const char *Pfn, XrdCksData &Cks, int doSet=1) = 0;
40 
41 /* Del() deletes the checksum from the Pfn's xattrs.
42  Success: 0
43  Failure: -errno (see significant error numbers below).
44 */
45 virtual
46 int Del( const char *Pfn, XrdCksData &Cks) = 0;
47 
48 /* Get() retreives the checksum from the Pfn's xattrs and returns it and
49  indicates whether or not it is stale (i.e. the file modification has
50  changed or the name and length are not the expected values).
51  Success: The length of the binary checksum is returned.
52  Failure: -errno (see significant error numbers below).
53 */
54 virtual
55 int Get( const char *Pfn, XrdCksData &Cks) = 0;
56 
57 /* Config Is used to parse configuration directives specific to the manager.
58  Token points to the directive that triggered the call. Line are all
59  the characters after the directive.
60  Success: 1
61  Failure: 0
62 */
63 virtual
64 int Config(const char *Token, char *Line) = 0;
65 
66 /* Init() Init is used to fully initialize the manager which includes loading
67  any plugins. You can also specify the default checksum. If not given
68  it becomes adler32. A default is only needed if you will not be
69  specifying the checksum name in the XrdCksData object.
70  Success: 1
71  Failure: 0
72 */
73 virtual
74 int Init(const char *ConfigFN, const char *DfltCalc=0) = 0;
75 
76 /* List() returns the names of the checksums associated with Pfn. If Pfn is
77  not given, it returns a list of supported checksums. The buffer
78  should be at least 64 bytes in length; otherwise truncation occurs.
79  Success: Buff is returned with at least one checksum name.
80  Failure: A nil pointer is returned.
81 */
82 virtual
83 char *List(const char *Pfn, char *Buff, int Blen, char Sep=' ') = 0;
84 
85 /* Name() returns the name of the checksums associated with a sequence number.
86  Zero is the default name. Higher numbers are alternates. When no
87  more alternates exist, a null pointer is returned. Note that Name()
88  may be called prior to final config to see if there are any chksums
89  to configure and avoid unintended errors.
90  Success: Pointer to the name.
91  Failure: A nil pointer is returned.
92 */
93 virtual const
94 char *Name(int seqNum=0) = 0;
95 
96 /* Size() returns the binary length of the checksum with the corresponding
97  name. If no name is given, the default name is used.
98  Success: checksum length.
99  Failure: Zero if the checksum name does not exist.
100 */
101 virtual
102 int Size( const char *Name=0) = 0;
103 
104 /* Set() sets the Pfn's checksum in the extended attributes. The file's mtime
105  and the time of setting is automatically added to the information.
106  If myTime is true then CksData values for fmTime and gmTime are used.
107  Success: zero is returned.
108  Failure: -errno (see significant error numbers below).
109 */
110 virtual
111 int Set( const char *Pfn, XrdCksData &Cks, int myTime=0) = 0;
112 
113 /* Ver() retreives the checksum from the Pfn's xattrs and compares it to the
114  supplied checksum. If the checksum is not available or is stale,
115  a new checksum is calculated and written to the extended attributes.
116  Success: True
117  Failure: False (the checksums do not match).
118  -errno Otherwise (see significant error numbers below).
119 */
120 virtual
121 int Ver( const char *Pfn, XrdCksData &Cks) = 0;
122 
123  XrdCks(XrdSysError *erP) : eDest(erP) {}
124 virtual ~XrdCks() {}
125 
126 /* Significant errno values:
127 
128  -EDOM The supplied checksum length is invalid for the checksum name.
129  -ENOTSUP The supplied or default checksum name is not supported.
130  -ESRCH Checksum does not exist for file.
131  -ESTALE The file's checksum is no longer valid.
132 */
133 
134 protected:
135 
137 };
138 
139 /******************************************************************************/
140 /* X r d C k s I n i t */
141 /******************************************************************************/
142 
143 #define XRDCKSINITPARMS XrdSysError *, const char *, const char *
144 
145 /* When building a shared library plugin, the following "C" entry point must
146  exist in the library:
147 
148  extern "C"
149  {XrdCks *XrdCksInit(XrdSysError *eDest, // The error msg object
150  const char *cFN, // Config file name
151  const char *Parms // Parms via lib directive
152  );
153  }
154 
155  This entry is called to get an instance of the checksum manager.
156  If the object cannot be created; return 0.
157 */
158 #endif