xrootd
XrdCksData.hh
Go to the documentation of this file.
1 #ifndef __XRDCKSDATA_HH__
2 #define __XRDCKSDATA_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C k s D a t a . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <string.h>
14 
16 {
17 public:
18 
19 static const int NameSize = 16; // Max name length is NameSize - 1
20 static const int ValuSize = 64; // Max value length is 512 bits
21 
22 char Name[NameSize]; // Checksum algorithm name
23 long long fmTime; // File's mtime when checksum was computed.
24 int csTime; // Delta from fmTime when checksum was computed.
25 short Rsvd1; // Reserved field
26 char Rsvd2; // Reserved field
27 char Length; // Length, in bytes, of the checksum value
28 char Value[ValuSize]; // The binary checksum value
29 
30 int Get(char *Buff, int Blen)
31  {const char *hv = "0123456789abcdef";
32  int i, j = 0;
33  if (Blen < Length*2+1) return 0;
34  for (i = 0; i < Length; i++)
35  {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
36  Buff[j++] = hv[ Value[i] & 0x0f];
37  }
38  Buff[j] = '\0';
39  return Length*2;
40  }
41 
42 int Set(const char *csName)
43  {if (strlen(csName) >= sizeof(Name)) return 0;
44  strncpy(Name, csName, sizeof(Name));
45  return 1;
46  }
47 
48 int Set(const char *csVal, int csLen)
49  {int n, i = 0, Odd = 0;
50  if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
51  Length = csLen/2;
52  while(csLen--)
53  { if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
54  else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
55  else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
56  else return 0;
57  if (Odd) Value[i++] |= n;
58  else Value[i ] = n << 4;
59  csVal++; Odd = ~Odd;
60  }
61  return 1;
62  }
63 
64  XrdCksData() : Rsvd1(0), Rsvd2(0), Length(0)
65  {memset(Name, 0, sizeof(Name));
66  memset(Value,0, sizeof(Value));
67  }
68 };
69 #endif