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/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <string.h>
34
35class XrdOucEnv;
36
38{
39public:
40
41static const int NameSize = 16; // Max name length is NameSize - 1
42static const int ValuSize = 64; // Max value length is 512 bits
43
44char Name[NameSize]; // Checksum algorithm name
45union {
46long long fmTime; // File's mtime when checksum was computed.
47const
48char *tident; // Set for get & calc only if proxy server!
49 };
50int csTime; // Delta from fmTime when checksum was computed.
51short Rsvd1; // Reserved field
52char Rsvd2; // Reserved field
53char Length; // Length, in bytes, of the checksum value
54char Value[ValuSize]; // The binary checksum value
55
56inline
57int operator==(const XrdCksData &oth)
58 {return (!strncmp(Name, oth.Name, NameSize)
59 && Length == oth.Length
60 && !memcmp(Value, oth.Value, Length));
61 }
62
63inline
64int operator!=(const XrdCksData &oth)
65 {return (strncmp(Name, oth.Name, NameSize)
66 || Length != oth.Length
67 || memcmp(Value, oth.Value, Length));
68 }
69
70int Get(char *Buff, int Blen)
71 {const char *hv = "0123456789abcdef";
72 int i, j = 0;
73 if (Blen < Length*2+1) return 0;
74 for (i = 0; i < Length; i++)
75 {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
76 Buff[j++] = hv[ Value[i] & 0x0f];
77 }
78 Buff[j] = '\0';
79 return Length*2;
80 }
81
82int Set(const char *csName)
83 {size_t len = strlen(csName);
84 if (len >= sizeof(Name)) return 0;
85 memcpy(Name, csName, len);
86 Name[len]=0;
87 return 1;
88 }
89
90int Set(const void *csVal, int csLen)
91 {if (csLen > ValuSize || csLen < 1) return 0;
92 memcpy(Value, csVal, csLen);
93 Length = csLen;
94 return 1;
95 }
96
97int Set(const char *csVal, int csLen)
98 {int n, i = 0, Odd = 0;
99 if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
100 Length = csLen/2;
101 while(csLen--)
102 { if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
103 else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
104 else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
105 else return 0;
106 if (Odd) Value[i++] |= n;
107 else Value[i ] = n << 4;
108 csVal++; Odd = ~Odd;
109 }
110 return 1;
111 }
112
113 void Reset()
114 {memset(Name, 0, sizeof(Name));
115 memset(Value,0, sizeof(Value));
116 fmTime = 0;
117 csTime = 0;
118 Rsvd1 = 0;
119 Rsvd2 = 0;
120 Length = 0;
121 }
122
124 {Reset();}
125
127 {
128 return *Value;
129 }
130};
131#endif
Definition: XrdCksData.hh:38
int csTime
Definition: XrdCksData.hh:50
int operator==(const XrdCksData &oth)
Definition: XrdCksData.hh:57
char Value[ValuSize]
Definition: XrdCksData.hh:54
int Set(const char *csVal, int csLen)
Definition: XrdCksData.hh:97
static const int ValuSize
Definition: XrdCksData.hh:42
XrdCksData()
Definition: XrdCksData.hh:123
int Set(const char *csName)
Definition: XrdCksData.hh:82
void Reset()
Definition: XrdCksData.hh:113
int Get(char *Buff, int Blen)
Definition: XrdCksData.hh:70
char Length
Definition: XrdCksData.hh:53
int Set(const void *csVal, int csLen)
Definition: XrdCksData.hh:90
int operator!=(const XrdCksData &oth)
Definition: XrdCksData.hh:64
short Rsvd1
Definition: XrdCksData.hh:51
bool HasValue()
Definition: XrdCksData.hh:126
const char * tident
Definition: XrdCksData.hh:48
long long fmTime
Definition: XrdCksData.hh:46
char Rsvd2
Definition: XrdCksData.hh:52
static const int NameSize
Definition: XrdCksData.hh:41
char Name[NameSize]
Definition: XrdCksData.hh:44
Definition: XrdOucEnv.hh:42