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 const
00048 char *tident;
00049 };
00050 int csTime;
00051 short Rsvd1;
00052 char Rsvd2;
00053 char Length;
00054 char Value[ValuSize];
00055
00056 inline
00057 int operator==(const XrdCksData &oth)
00058 {return (!strncmp(Name, oth.Name, NameSize)
00059 && Length == oth.Length
00060 && !memcmp(Value, oth.Value, Length));
00061 }
00062
00063 inline
00064 int operator!=(const XrdCksData &oth)
00065 {return (strncmp(Name, oth.Name, NameSize)
00066 || Length != oth.Length
00067 || memcmp(Value, oth.Value, Length));
00068 }
00069
00070 int Get(char *Buff, int Blen)
00071 {const char *hv = "0123456789abcdef";
00072 int i, j = 0;
00073 if (Blen < Length*2+1) return 0;
00074 for (i = 0; i < Length; i++)
00075 {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
00076 Buff[j++] = hv[ Value[i] & 0x0f];
00077 }
00078 Buff[j] = '\0';
00079 return Length*2;
00080 }
00081
00082 int Set(const char *csName)
00083 {size_t len = strlen(csName);
00084 if (len >= sizeof(Name)) return 0;
00085 memcpy(Name, csName, len);
00086 Name[len]=0;
00087 return 1;
00088 }
00089
00090 int Set(const void *csVal, int csLen)
00091 {if (csLen > ValuSize || csLen < 1) return 0;
00092 memcpy(Value, csVal, csLen);
00093 Length = csLen;
00094 return 1;
00095 }
00096
00097 int Set(const char *csVal, int csLen)
00098 {int n, i = 0, Odd = 0;
00099 if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
00100 Length = csLen/2;
00101 while(csLen--)
00102 { if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
00103 else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
00104 else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
00105 else return 0;
00106 if (Odd) Value[i++] |= n;
00107 else Value[i ] = n << 4;
00108 csVal++; Odd = ~Odd;
00109 }
00110 return 1;
00111 }
00112
00113 void Reset()
00114 {memset(Name, 0, sizeof(Name));
00115 memset(Value,0, sizeof(Value));
00116 fmTime = 0;
00117 csTime = 0;
00118 Rsvd1 = 0;
00119 Rsvd2 = 0;
00120 Length = 0;
00121 }
00122
00123 XrdCksData()
00124 {Reset();}
00125
00126 bool HasValue()
00127 {
00128 return *Value;
00129 }
00130 };
00131 #endif