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 {if (strlen(csName) >= sizeof(Name)) return 0;
00078 strncpy(Name, csName, sizeof(Name));
00079 return 1;
00080 }
00081
00082 int Set(const void *csVal, int csLen)
00083 {if (csLen > ValuSize || csLen < 1) return 0;
00084 memcpy(Value, csVal, csLen);
00085 Length = csLen;
00086 return 1;
00087 }
00088
00089 int Set(const char *csVal, int csLen)
00090 {int n, i = 0, Odd = 0;
00091 if (csLen > (int)sizeof(Value)*2 || (csLen & 1)) return 0;
00092 Length = csLen/2;
00093 while(csLen--)
00094 { if (*csVal >= '0' && *csVal <= '9') n = *csVal-48;
00095 else if (*csVal >= 'a' && *csVal <= 'f') n = *csVal-87;
00096 else if (*csVal >= 'A' && *csVal <= 'F') n = *csVal-55;
00097 else return 0;
00098 if (Odd) Value[i++] |= n;
00099 else Value[i ] = n << 4;
00100 csVal++; Odd = ~Odd;
00101 }
00102 return 1;
00103 }
00104
00105 XrdCksData() : Rsvd1(0), Rsvd2(0), Length(0)
00106 {memset(Name, 0, sizeof(Name));
00107 memset(Value,0, sizeof(Value));
00108 }
00109 };
00110 #endif