XRootD
Loading...
Searching...
No Matches
XrdCl::CheckSumManager Class Reference

Manage the checksum calc objects. More...

#include <XrdClCheckSumManager.hh>

Collaboration diagram for XrdCl::CheckSumManager:

Public Member Functions

 CheckSumManager ()
 Constructor.
virtual ~CheckSumManager ()
bool Calculate (XrdCksData &result, const std::string &algName, const std::string &filePath)
 Calculate a checksum of for a given file.
XrdCksCalcGetCalculator (const std::string &algName)

Detailed Description

Manage the checksum calc objects.

Definition at line 41 of file XrdClCheckSumManager.hh.

Constructor & Destructor Documentation

◆ CheckSumManager()

XrdCl::CheckSumManager::CheckSumManager ( )

Constructor.

Definition at line 47 of file XrdClCheckSumManager.cc.

48 {
49 pLoader = new XrdCksLoader( XrdVERSIONINFOVAR( XrdCl ) );
50 pCalculators["md5"] = new XrdCksCalcmd5();
51 pCalculators["crc32"] = new XrdCksCalccrc32;
52 pCalculators["crc32c"] = new XrdCksCalccrc32C;
53 pCalculators["adler32"] = new XrdCksCalcadler32;
54 }

◆ ~CheckSumManager()

XrdCl::CheckSumManager::~CheckSumManager ( )
virtual

Definition at line 59 of file XrdClCheckSumManager.cc.

60 {
61 CalcMap::iterator it;
62 for( it = pCalculators.begin(); it != pCalculators.end(); ++it )
63 delete it->second;
64 delete pLoader;
65 }

Member Function Documentation

◆ Calculate()

bool XrdCl::CheckSumManager::Calculate ( XrdCksData & result,
const std::string & algName,
const std::string & filePath )

Calculate a checksum of for a given file.

Definition at line 100 of file XrdClCheckSumManager.cc.

103 {
104 //--------------------------------------------------------------------------
105 // Get a calculator
106 //--------------------------------------------------------------------------
107 Log *log = DefaultEnv::GetLog();
108 XrdCksCalc *calc = GetCalculator( algName );
109
110 if( !calc )
111 {
112 log->Error( UtilityMsg, "Unable to get a calculator for %s",
113 algName.c_str() );
114 return false;
115 }
116 std::unique_ptr<XrdCksCalc> calcPtr( calc );
117
118 //--------------------------------------------------------------------------
119 // Open the file
120 //--------------------------------------------------------------------------
121 log->Debug( UtilityMsg, "Opening %s for reading (checksum calc)",
122 filePath.c_str() );
123
124 int fd = open( filePath.c_str(), O_RDONLY );
125 if( fd == -1 )
126 {
127 log->Error( UtilityMsg, "Unable to open %s: %s", filePath.c_str(),
128 XrdSysE2T( errno ) );
129 return false;
130 }
131
132 //--------------------------------------------------------------------------
133 // Calculate the checksum
134 //--------------------------------------------------------------------------
135 const uint32_t buffSize = 2*1024*1024;
136 char *buffer = new char[buffSize];
137 int64_t bytesRead = 0;
138
139 while( (bytesRead = read( fd, buffer, buffSize )) )
140 {
141 if( bytesRead == -1 )
142 {
143 log->Error( UtilityMsg, "Unable read from %s: %s", filePath.c_str(),
144 XrdSysE2T( errno ) );
145 close( fd );
146 delete [] buffer;
147 return false;
148 }
149 calc->Update( buffer, bytesRead );
150 }
151
152 int size;
153 calc->Type( size );
154 result.Set( (void*)calc->Final(), size );
155
156 //--------------------------------------------------------------------------
157 // Clean up
158 //--------------------------------------------------------------------------
159 delete [] buffer;
160 close( fd );
161 return true;
162 }
#define close(a)
Definition XrdPosix.hh:43
#define open
Definition XrdPosix.hh:71
#define read(a, b, c)
Definition XrdPosix.hh:77
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
virtual void Update(const char *Buff, int BLen)=0
virtual const char * Type(int &csSize)=0
virtual char * Final()=0
int Set(const char *csName)
Definition XrdCksData.hh:81
XrdCksCalc * GetCalculator(const std::string &algName)
static Log * GetLog()
Get default log.
const uint64_t UtilityMsg
XrdSysError Log
Definition XrdConfig.cc:112

References close, XrdCl::Log::Debug(), XrdCl::Log::Error(), XrdCksCalc::Final(), GetCalculator(), XrdCl::DefaultEnv::GetLog(), open, read, XrdCksData::Set(), XrdCksCalc::Type(), XrdCksCalc::Update(), XrdCl::UtilityMsg, and XrdSysE2T().

Referenced by XrdCl::Utils::GetLocalCheckSum().

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

◆ GetCalculator()

XrdCksCalc * XrdCl::CheckSumManager::GetCalculator ( const std::string & algName)

Get the check sum calc object for a given checksum type

Parameters
algNamename of the checksumming algorithm
Returns
the appropriate calc object (must be deleted by the user) or 0 if a calculator cannot be obtained

Definition at line 70 of file XrdClCheckSumManager.cc.

71 {
72 Log *log = DefaultEnv::GetLog();
73 XrdSysMutexHelper scopedLock( pMutex );
74 CalcMap::iterator it = pCalculators.find( algName );
75 if( it == pCalculators.end() )
76 {
77 char *errBuff = new char[1024];
78 log->Dump( UtilityMsg, "Attempting to load a calculator for: %s",
79 algName.c_str() );
80 XrdCksCalc *c = pLoader->Load( algName.c_str(), "", errBuff, 1024 );
81 if( !c )
82 {
83 log->Error( UtilityMsg, "Unable to load %s calculator: %s",
84 algName.c_str(), errBuff );
85 delete [] errBuff;
86 return 0;
87
88 }
89 delete [] errBuff;
90
91 pCalculators[algName] = c;
92 return c->New();
93 }
94 return it->second->New();;
95 }
virtual XrdCksCalc * New()=0

References XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCksCalc::New(), and XrdCl::UtilityMsg.

Referenced by Calculate(), and XrdCl::CheckSumHelper::Initialize().

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: