XRootD
Loading...
Searching...
No Matches
XrdCksLoader Class Reference

#include <XrdCksLoader.hh>

+ Collaboration diagram for XrdCksLoader:

Public Member Functions

 XrdCksLoader (XrdVersionInfo &vInfo, const char *libPath=0)
 
 ~XrdCksLoader ()
 Destructor.
 
XrdCksCalcLoad (const char *csName, const char *csParms=0, char *eBuff=0, int eBlen=0, bool orig=false)
 

Detailed Description

This class defines the checksum loader interface. It is intended to be used by xrootd clients to obtain an instance of a checksum calculation object. This object may be builtin or may come from a shared library.

Definition at line 42 of file XrdCksLoader.hh.

Constructor & Destructor Documentation

◆ XrdCksLoader()

XrdCksLoader::XrdCksLoader ( XrdVersionInfo & vInfo,
const char * libPath = 0 )

Constructor

Parameters
vInfoIs the reference to the version information corresponding to the xrootd version you compiled with. You define this information using the XrdVERSIONINFODEF macro defined in XrdVersion.hh. You must supply your version information and it must be compatible with the loader and any shared libraries that it might load on your behalf.
libPathThe path where dynamic checksum calculators are to be found and dynamically loaded, if need be. If libPath is nil then the default loader search order is used. The name of the shared library must follow the naming convention "libXrdCksCalc<csName>.so" where <csName> is the checksum name. So, an sha256 checksum would try to load libXrdCksCalcsha256.so shared library.

Definition at line 55 of file XrdCksLoader.cc.

56{
57 static XrdVERSIONINFODEF(myVersion, XrdCks, XrdVNUMBER, XrdVERSION);
58 static const char libSfx[] = "/libXrdCksCalc%s.so";
59 int k, n;
60
61// Verify that versions are compatible.
62//
63 if (vInfo.vNum != myVersion.vNum
64 && !XrdSysPlugin::VerCmp(vInfo, myVersion, true))
65 {char buff[1024];
66 snprintf(buff, sizeof(buff), "Version %s is incompatible with %s.",
67 vInfo.vStr, myVersion.vStr);
68 verMsg = strdup(buff); urVersion = 0;
69 return;
70 }
71 urVersion = &vInfo;
72 verMsg = 0;
73
74// Prefill the native digests we support
75//
76 csTab[0].Name = strdup("adler32");
77 csTab[1].Name = strdup("crc32");
78 csTab[2].Name = strdup("md5");
79 csLast = 2;
80
81// Record the over-ride loader path
82//
83 if (libPath)
84 {n = strlen(libPath);
85 ldPath = (char *)malloc(n+sizeof(libSfx)+1);
86 k = (libPath[n-1] == '/');
87 strcpy(ldPath, libPath);
88 strcpy(ldPath+n, libSfx+k);
89 } else ldPath = strdup(libSfx+1);
90}
static XrdVERSIONINFODEF(compiledVer, XrdHttpProtocolTest, XrdVNUMBER, XrdVERSION)
static bool VerCmp(XrdVersionInfo &vInf1, XrdVersionInfo &vInf2, bool noMsg=false)
XrdVersionInfo myVersion

References XrdSysPlugin::VerCmp(), and XrdVERSIONINFODEF().

+ Here is the call graph for this function:

◆ ~XrdCksLoader()

XrdCksLoader::~XrdCksLoader ( )

Destructor.

Definition at line 96 of file XrdCksLoader.cc.

97{
98 int i;
99 for (i = 0; i <= csLast; i++)
100 {if (csTab[i].Name) free( csTab[i].Name);
101 if (csTab[i].Obj) csTab[i].Obj->Recycle();
102 if (csTab[i].Plugin) delete csTab[i].Plugin;
103 }
104 if (ldPath) free(ldPath);
105 if (verMsg) free(verMsg);
106}
virtual void Recycle()
Recycle the checksum object as it is no longer needed. A default is given.
Definition XrdCksCalc.hh:95

References XrdCksCalc::Recycle().

+ Here is the call graph for this function:

Member Function Documentation

◆ Load()

XrdCksCalc * XrdCksLoader::Load ( const char * csName,
const char * csParms = 0,
char * eBuff = 0,
int eBlen = 0,
bool orig = false )

Get a new XrdCksCalc object that can calculate the checksum corresponding to the specified name. The object can be used to compute checksums on the fly. The object's Recycle() method must be used to delete it. The adler32, crc32, and md5 checksums are natively supported. Up to five more checksum algorithms can be loaded from shared libraries.

Parameters
csNameThe name of the checksum algorithm (e.g. md5).
csParmsAny parameters that might be needed by the checksum algorithm should it be loaded from a shared library.
eBuffOptional pointer to a buffer to receive the reason for a load failure as a null terminated string.
eBlenThe length of the buffer.
origReturns the original object not a new instance of it. This is usually used by CksManager during an autoload.
Returns
Success: A pointer to a new checksum calculation object. Failure: Zero if the corresponding checksum object could not be loaded. If eBuff was supplied, it holds the reason.

Definition at line 114 of file XrdCksLoader.cc.

116{
117 static XrdSysMutex myMutex;
118 XrdSysMutexHelper ldMutex(myMutex);
120 XrdCksCalc *csObj;
121 XrdOucPinLoader *myPin;
122 csInfo *csIP;
123 char ldBuff[2048];
124 int n;
125
126// Verify that version checking succeeded
127//
128 if (verMsg) {if (eBuff) strncpy(eBuff, verMsg, eBlen); return 0;}
129
130// First check if we have loaded this before
131//
132 if ((csIP = Find(csName)))
133 {if (!(csIP->Obj))
134 { if (!strcmp("adler32", csIP->Name))
135 csIP->Obj = new XrdCksCalcadler32;
136 else if (!strcmp("crc32", csIP->Name))
137 csIP->Obj = new XrdCksCalccrc32;
138 else if (!strcmp("md5", csIP->Name))
139 csIP->Obj = new XrdCksCalcmd5;
140 else {if (eBuff) snprintf(eBuff, eBlen, "Logic error configuring %s "
141 "checksum.", csName);
142 return 0;
143 }
144 }
145 return (orig ? csIP->Obj : csIP->Obj->New());
146 }
147
148// Check if we can add a new entry
149//
150 if (csLast+1 >= csMax)
151 {if (eBuff) strncpy(eBuff, "Maximum number of checksums loaded.", eBlen);
152 return 0;
153 }
154
155// Get the path where this object lives
156//
157 snprintf(ldBuff, sizeof(ldBuff), ldPath, csName);
158
159// Get the plugin loader
160//
161 if (!(myPin = new XrdOucPinLoader(eBuff,eBlen,urVersion,"ckslib",ldBuff)))
162 return 0;
163
164// Find the entry point
165//
166 if (!(ep = (XrdCksCalc *(*)(XRDOSSCKSLIBARGS))
167 (myPin->Resolve("XrdCksCalcInit"))))
168 {myPin->Unload(true); return 0;}
169
170// Get the initial object
171//
172 if (!(csObj = ep(0, 0, csName, csParms)))
173 {if (eBuff)
174 snprintf(eBuff, eBlen, "%s checksum initialization failed.", csName);
175 myPin->Unload(true);
176 return 0;
177 }
178
179// Verify the object
180//
181 if (strcmp(csName, csObj->Type(n)))
182 {if (eBuff)
183 snprintf(eBuff, eBlen, "%s cksum plugin returned wrong name - %s",
184 csName, csObj->Type(n));
185 delete csObj;
186 myPin->Unload(true);
187 return 0;
188 }
189
190// Allocate a new entry in the table and initialize it
191//
192 csLast++;
193 csTab[csLast].Name = strdup(csName);
194 csTab[csLast].Obj = csObj;
195 csTab[csLast].Plugin = myPin->Export();
196
197// Return new instance of this object
198//
199 return (orig ? csObj : csObj->New());
200}
#define XRDOSSCKSLIBARGS
void * Resolve(const char *symbl, int mcnt=1)
void Unload(bool dodel=false)
XrdSysPlugin * Export()

References XrdOucPinLoader::Export(), XrdCksCalc::New(), XrdOucPinLoader::Resolve(), XrdOucPinLoader::Unload(), and XRDOSSCKSLIBARGS.

Referenced by XrdCl::CheckSumManager::GetCalculator().

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

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