XrdCksData.hh

Go to the documentation of this file.
00001 #ifndef __XRDCKSDATA_HH__
00002 #define __XRDCKSDATA_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                         X r d C k s D a t a . 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 
00035 class XrdCksData
00036 {
00037 public:
00038 
00039 static const int NameSize = 16; // Max name  length is NameSize - 1
00040 static const int ValuSize = 64; // Max value length is 512 bits
00041 
00042 char      Name[NameSize];       // Checksum algorithm name
00043 long long fmTime;               // File's mtime when checksum was computed.
00044 int       csTime;               // Delta from fmTime when checksum was computed.
00045 short     Rsvd1;                // Reserved field
00046 char      Rsvd2;                // Reserved field
00047 char      Length;               // Length, in bytes, of the checksum value
00048 char      Value[ValuSize];      // The binary checksum value
00049 
00050 inline
00051 int       operator==(const XrdCksData &oth)
00052                     {return (!strncmp(Name, oth.Name, NameSize)
00053                          &&  Length == oth.Length
00054                          &&  !memcmp(Value, oth.Value, Length));
00055                     }
00056 
00057 inline
00058 int       operator!=(const XrdCksData &oth)
00059                     {return (strncmp(Name, oth.Name, NameSize)
00060                          ||  Length != oth.Length
00061                          ||  memcmp(Value, oth.Value, Length));
00062                     }
00063 
00064 int       Get(char *Buff, int Blen)
00065              {const char *hv = "0123456789abcdef";
00066               int i, j = 0;
00067               if (Blen < Length*2+1) return 0;
00068               for (i = 0; i < Length; i++)
00069                   {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
00070                    Buff[j++] = hv[ Value[i]       & 0x0f];
00071                   }
00072               Buff[j] = '\0';
00073               return Length*2;
00074              }
00075 
00076 int       Set(const char *csName)
00077              {if (strlen(csName) >= sizeof(Name)) return 0;
00078               strncpy(Name, csName, sizeof(Name));
00079               return 1;
00080              }
00081 
00082 int       Set(const void *csVal, int csLen)
00083              {if (csLen > ValuSize || csLen < 1) return 0;
00084               memcpy(Value, csVal, csLen);
00085               Length = csLen;
00086               return 1;
00087              }
00088 
00089 int       Set(const char *csVal, int csLen)
00090              {int n, i = 0, Odd = 0;
00091               if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
00092               Length = csLen/2;
00093               while(csLen--)
00094                    {     if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
00095                     else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
00096                     else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
00097                     else return 0;
00098                     if (Odd) Value[i++] |= n;
00099                        else  Value[i  ]  = n << 4;
00100                     csVal++; Odd = ~Odd;
00101                    }
00102               return 1;
00103              }
00104 
00105           XrdCksData() : Rsvd1(0), Rsvd2(0), Length(0)
00106                        {memset(Name, 0, sizeof(Name));
00107                         memset(Value,0, sizeof(Value));
00108                        }
00109 };
00110 #endif

Generated on 27 Jul 2013 for xrootd by  doxygen 1.4.7