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 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <string.h> 00034 #include <sys/types.h> 00035 #include <netinet/in.h> 00036 #include <inttypes.h> 00037 00038 #include "XrdCks/XrdCksCalc.hh" 00039 #include "XrdSys/XrdSysPlatform.hh" 00040 00041 class XrdCksCalccrc32 : public XrdCksCalc 00042 { 00043 public: 00044 00045 char *Final() {char buff[sizeof(long long)]; 00046 long long tLcs = TotLen; 00047 int i = 0; 00048 if (tLcs) 00049 {while(tLcs) {buff[i++] = tLcs & 0xff ; tLcs >>= 8;} 00050 Update(buff, i); 00051 } 00052 TheResult = C32Result ^ CRC32_XOROT; 00053 #ifndef Xrd_Big_Endian 00054 TheResult = htonl(TheResult); 00055 #endif 00056 return (char *)&TheResult; 00057 } 00058 00059 void Init() {C32Result = CRC32_XINIT; TotLen = 0;} 00060 00061 XrdCksCalc *New() {return (XrdCksCalc *)new XrdCksCalccrc32;} 00062 00063 void Update(const char *Buff, int BLen); 00064 00065 const char *Type(int &csSz) {csSz = sizeof(TheResult); return "crc32";} 00066 00067 XrdCksCalccrc32() {Init();} 00068 virtual ~XrdCksCalccrc32() {} 00069 00070 private: 00071 static const unsigned int CRC32_XINIT = 0; 00072 static const unsigned int CRC32_XOROT = 0xffffffff; 00073 static unsigned int crctable[256]; 00074 unsigned int C32Result; 00075 unsigned int TheResult; 00076 long long TotLen; 00077 }; 00078 #endif