00001 #ifndef __XRDCKSDATA_HH__
00002 #define __XRDCKSDATA_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string.h>
00034
00035 class XrdOucEnv;
00036
00037 class XrdCksData
00038 {
00039 public:
00040
00041 static const int NameSize = 16;
00042 static const int ValuSize = 64;
00043
00044 char Name[NameSize];
00045 union {
00046 long long fmTime;
00047 XrdOucEnv*envP;
00048 };
00049 int csTime;
00050 short Rsvd1;
00051 char Rsvd2;
00052 char Length;
00053 char Value[ValuSize];
00054
00055 inline
00056 int operator==(const XrdCksData &oth)
00057 {return (!strncmp(Name, oth.Name, NameSize)
00058 && Length == oth.Length
00059 && !memcmp(Value, oth.Value, Length));
00060 }
00061
00062 inline
00063 int operator!=(const XrdCksData &oth)
00064 {return (strncmp(Name, oth.Name, NameSize)
00065 || Length != oth.Length
00066 || memcmp(Value, oth.Value, Length));
00067 }
00068
00069 int Get(char *Buff, int Blen)
00070 {const char *hv = "0123456789abcdef";
00071 int i, j = 0;
00072 if (Blen < Length*2+1) return 0;
00073 for (i = 0; i < Length; i++)
00074 {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
00075 Buff[j++] = hv[ Value[i] & 0x0f];
00076 }
00077 Buff[j] = '\0';
00078 return Length*2;
00079 }
00080
00081 int Set(const char *csName)
00082 {size_t len = strlen(csName);
00083 if (len >= sizeof(Name)) return 0;
00084 memcpy(Name, csName, len);
00085 Name[len]=0;
00086 return 1;
00087 }
00088
00089 int Set(const void *csVal, int csLen)
00090 {if (csLen > ValuSize || csLen < 1) return 0;
00091 memcpy(Value, csVal, csLen);
00092 Length = csLen;
00093 return 1;
00094 }
00095
00096 int Set(const char *csVal, int csLen)
00097 {int n, i = 0, Odd = 0;
00098 if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
00099 Length = csLen/2;
00100 while(csLen--)
00101 { if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
00102 else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
00103 else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
00104 else return 0;
00105 if (Odd) Value[i++] |= n;
00106 else Value[i ] = n << 4;
00107 csVal++; Odd = ~Odd;
00108 }
00109 return 1;
00110 }
00111
00112 void Reset()
00113 {memset(Name, 0, sizeof(Name));
00114 memset(Value,0, sizeof(Value));
00115 fmTime = 0;
00116 csTime = 0;
00117 Rsvd1 = 0;
00118 Rsvd2 = 0;
00119 Length = 0;
00120 }
00121
00122 XrdCksData()
00123 {Reset();}
00124
00125 bool HasValue()
00126 {
00127 return *Value;
00128 }
00129 };
00130 #endif