xrootd
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 
00013 #include <string.h>
00014   
00015 class XrdCksData
00016 {
00017 public:
00018 
00019 static const int NameSize = 16; // Max name  length is NameSize - 1
00020 static const int ValuSize = 64; // Max value length is 512 bits
00021 
00022 char      Name[NameSize];       // Checksum algorithm name
00023 long long fmTime;               // File's mtime when checksum was computed.
00024 int       csTime;               // Delta from fmTime when checksum was computed.
00025 short     Rsvd1;                // Reserved field
00026 char      Rsvd2;                // Reserved field
00027 char      Length;               // Length, in bytes, of the checksum value
00028 char      Value[ValuSize];      // The binary checksum value
00029 
00030 int       Get(char *Buff, int Blen)
00031              {const char *hv = "0123456789abcdef";
00032               int i, j = 0;
00033               if (Blen < Length*2+1) return 0;
00034               for (i = 0; i < Length; i++)
00035                   {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
00036                    Buff[j++] = hv[ Value[i]       & 0x0f];
00037                   }
00038               Buff[j] = '\0';
00039               return Length*2;
00040              }
00041 
00042 int       Set(const char *csName)
00043              {if (strlen(csName) >= sizeof(Name)) return 0;
00044               strncpy(Name, csName, sizeof(Name));
00045               return 1;
00046              }
00047 
00048 int       Set(const char *csVal, int csLen)
00049              {int n, i = 0, Odd = 0;
00050               if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
00051               Length = csLen/2;
00052               while(csLen--)
00053                    {     if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
00054                     else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
00055                     else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
00056                     else return 0;
00057                     if (Odd) Value[i++] |= n;
00058                        else  Value[i  ]  = n << 4;
00059                     csVal++; Odd = ~Odd;
00060                    }
00061               return 1;
00062              }
00063 
00064           XrdCksData() : Rsvd1(0), Rsvd2(0), Length(0)
00065                        {memset(Name, 0, sizeof(Name));
00066                         memset(Value,0, sizeof(Value));
00067                        }
00068 };
00069 #endif