Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:35

0001 #ifndef __XRDCKSDATA_HH__
0002 #define __XRDCKSDATA_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                         X r d C k s D a t a . h h                          */
0006 /*                                                                            */
0007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <cstring>
0034 
0035 class XrdOucEnv;
0036 
0037 class XrdCksData
0038 {
0039 public:
0040 
0041 static const int NameSize = 16; // Max name  length is NameSize - 1
0042 static const int ValuSize = 64; // Max value length is 512 bits
0043 
0044 char      Name[NameSize];       // Checksum algorithm name
0045 union    {
0046 long long fmTime;               // Out: File's mtime when checksum was computed.
0047 XrdOucEnv*envP;                 // In:  Set for get & calc, only!
0048          };
0049 int       csTime;               // Delta from fmTime when checksum was computed.
0050 short     Rsvd1;                // Reserved field
0051 char      Rsvd2;                // Reserved field
0052 char      Length;               // Length, in bytes, of the checksum value
0053 char      Value[ValuSize];      // The binary checksum value
0054 
0055 inline
0056 int       operator==(const XrdCksData &oth)
0057                     {return (!strncmp(Name, oth.Name, NameSize)
0058                          &&  Length == oth.Length
0059                          &&  !memcmp(Value, oth.Value, Length));
0060                     }
0061 
0062 inline
0063 int       operator!=(const XrdCksData &oth)
0064                     {return (strncmp(Name, oth.Name, NameSize)
0065                          ||  Length != oth.Length
0066                          ||  memcmp(Value, oth.Value, Length));
0067                     }
0068 
0069 int       Get(char *Buff, int Blen)
0070              {const char *hv = "0123456789abcdef";
0071               int i, j = 0;
0072               if (Blen < Length*2+1) return 0;
0073               for (i = 0; i < Length; i++)
0074                   {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
0075                    Buff[j++] = hv[ Value[i]       & 0x0f];
0076                   }
0077               Buff[j] = '\0';
0078               return Length*2;
0079              }
0080 
0081 int       Set(const char *csName)
0082              {size_t len = strlen(csName);
0083               if (len >= sizeof(Name)) return 0;
0084               memcpy(Name, csName, len);
0085           Name[len]=0;
0086               return 1;
0087              }
0088 
0089 int       Set(const void *csVal, int csLen)
0090              {if (csLen > ValuSize || csLen < 1) return 0;
0091               memcpy(Value, csVal, csLen);
0092               Length = csLen;
0093               return 1;
0094              }
0095 
0096 int       Set(const char *csVal, int csLen)
0097              {int n, i = 0, Odd = 0;
0098               if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
0099               Length = csLen/2;
0100               while(csLen--)
0101                    {     if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
0102                     else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
0103                     else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
0104                     else return 0;
0105                     if (Odd) Value[i++] |= n;
0106                        else  Value[i  ]  = n << 4;
0107                     csVal++; Odd = ~Odd;
0108                    }
0109               return 1;
0110              }
0111 
0112           void Reset()
0113                     {memset(Name, 0, sizeof(Name));
0114                      memset(Value,0, sizeof(Value));
0115                      fmTime = 0;
0116                      csTime = 0;
0117                      Rsvd1  = 0;
0118                      Rsvd2  = 0;
0119                      Length = 0;
0120                     }
0121 
0122           XrdCksData()
0123                        {Reset();}
0124 
0125 bool      HasValue()
0126                   {
0127                    return *Value;
0128                   }
0129 };
0130 #endif