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