File indexing completed on 2026-01-08 10:33:35
0001 #ifndef __XRDCKSDATA_HH__
0002 #define __XRDCKSDATA_HH__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <cstring>
0034
0035 class XrdOucEnv;
0036
0037 class XrdCksData
0038 {
0039 public:
0040
0041 static const int NameSize = 16;
0042 static const int ValuSize = 64;
0043
0044 char Name[NameSize];
0045 union {
0046 long long fmTime;
0047 XrdOucEnv*envP;
0048 };
0049 int csTime;
0050 short Rsvd1;
0051 char Rsvd2;
0052 char Length;
0053 char Value[ValuSize];
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