|
xrootd
|
00001 #ifndef __XRDCKSCALCCRC32_HH__ 00002 #define __XRDCKSCALCCRC32_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C k s C a l c c r c 3 2 . 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 <string.h> 00014 #include <sys/types.h> 00015 #include <netinet/in.h> 00016 #include <inttypes.h> 00017 00018 #include "XrdCks/XrdCksCalc.hh" 00019 #include "XrdSys/XrdSysPlatform.hh" 00020 00021 class XrdCksCalccrc32 : public XrdCksCalc 00022 { 00023 public: 00024 00025 char *Final() {char buff[sizeof(long long)]; 00026 long long tLcs = TotLen; 00027 int i = 0; 00028 if (tLcs) 00029 {while(tLcs) {buff[i++] = tLcs & 0xff ; tLcs >>= 8;} 00030 Update(buff, i); 00031 } 00032 TheResult = C32Result ^ CRC32_XOROT; 00033 #ifndef Xrd_Big_Endian 00034 TheResult = htonl(TheResult); 00035 #endif 00036 return (char *)&TheResult; 00037 } 00038 00039 void Init() {C32Result = CRC32_XINIT; TotLen = 0;} 00040 00041 XrdCksCalc *New() {return (XrdCksCalc *)new XrdCksCalccrc32;} 00042 00043 void Update(const char *Buff, int BLen); 00044 00045 const char *Type(int &csSz) {csSz = sizeof(TheResult); return "crc32";} 00046 00047 XrdCksCalccrc32() {Init();} 00048 virtual ~XrdCksCalccrc32() {} 00049 00050 private: 00051 static const unsigned int CRC32_XINIT = 0; 00052 static const unsigned int CRC32_XOROT = 0xffffffff; 00053 static unsigned int crctable[256]; 00054 unsigned int C32Result; 00055 unsigned int TheResult; 00056 long long TotLen; 00057 }; 00058 #endif
1.7.5