00001 #ifndef __XRDCKSXATTR_HH__ 00002 #define __XRDCKSXATTR_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C k s X A t t r . 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 <inttypes.h> 00034 #include <netinet/in.h> 00035 #include <sys/types.h> 00036 00037 #include "XrdCks/XrdCksData.hh" 00038 #include "XrdSys/XrdSysPlatform.hh" 00039 00040 /* XrdCksXAttr encapsulates the extended attributes needed to save a checksum. 00041 */ 00042 00043 class XrdCksXAttr 00044 { 00045 public: 00046 00047 XrdCksData Cks; // Check sum information 00048 00049 /* postGet() will put fmTime and csTime in host byte order (see preSet()). 00050 */ 00051 int postGet(int Result) 00052 {if (Result > 0) 00053 {Cks.fmTime = ntohll(Cks.fmTime); 00054 Cks.csTime = ntohl (Cks.csTime); 00055 } 00056 return Result; 00057 } 00058 00059 /* preSet() will put fmTime and csTime in network byte order to allow the 00060 attribute to be copied to different architectures and still work. 00061 */ 00062 XrdCksXAttr *preSet(XrdCksXAttr &tmp) 00063 {memcpy(&tmp.Cks, &Cks, sizeof(Cks)); 00064 tmp.Cks.fmTime = htonll(Cks.fmTime); 00065 tmp.Cks.csTime = htonl (Cks.csTime); 00066 return &tmp; 00067 } 00068 00069 /* Name() returns the extended attribute name for this object. 00070 */ 00071 const char *Name() {if (!(*VarName)) //01234567 00072 {strcpy(VarName, "XrdCks."); 00073 strcpy(VarName+7, Cks.Name); 00074 } 00075 return VarName; 00076 } 00077 00078 /* sizeGet() and sizeSet() return the actual size of the object is used. 00079 */ 00080 int sizeGet() {return sizeof(Cks);} 00081 int sizeSet() {return sizeof(Cks);} 00082 00083 XrdCksXAttr() {*VarName = 0;} 00084 ~XrdCksXAttr() {} 00085 00086 private: 00087 00088 char VarName[XrdCksData::NameSize+8]; 00089 }; 00090 #endif