40 #include "XrdVersion.hh"
54 char h2c[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
55 '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
62 extern unsigned long XrdOucHashVal2(
const char *KeyVal,
int KeyLen);
72 virtual int lfn2pfn(
const char* lfn,
char* buff,
int blen);
74 virtual int lfn2rfn(
const char* lfn,
char* buff,
int blen) {
return -ENOTSUP;}
76 virtual int pfn2lfn(
const char* pfn,
char* buff,
int blen);
79 const char* pfx,
int fnmax,
char sc)
80 : eDest(erp), sChar(sc),
81 oidPfx(strdup(pfx)), oidPsz(strlen(pfx)), oidMax(fnmax)
82 {
if (!lroot) {lRoot = 0; lRLen = 0;}
83 else {lRoot = strdup(lroot);
84 lRLen = strlen(lroot);
85 if (lRoot[lRLen-1] ==
'/')
86 {lRoot[lRLen-1] = 0; lRLen--;}
91 if (lRoot) free(lRoot);
113 {
if (lRLen >= blen-1)
return ENAMETOOLONG;
115 buff += lRLen; blen -= lRLen;
120 return pfn2lfn(lfn, buff, blen);
132 int pfnLen = strlen(pfn);
137 {
if (pfnLen >= blen)
return ENAMETOOLONG;
144 if ((sP = index(pfn,
'/')))
146 std::replace(pstr.begin(), pstr.end(),
'/', sChar);
154 if (pfnLen <= oidMax)
156 unsigned long sVal = ((int)
sizeof(
unsigned long) > 4 ? 32 : 16);
158 if (pfnLen <= (
int)
sizeof(
unsigned long)) hVal = hVal ^ (hVal >> sVal);
159 subP[1] = h2c[(hVal & 0x0f)]; hVal >>= 4; subP[0] = h2c[(hVal & 0x0f)];
160 subP[2] =
'/'; hVal >>= 4;
161 subP[4] = h2c[(hVal & 0x0f)]; hVal >>= 4; subP[3] = h2c[(hVal & 0x0f)];
162 subP[5] =
'/'; subP[6] = 0;
163 int n = snprintf(buff, blen,
"%s%s%s", oidPfx, subP, pfn);
164 return (n < blen ? 0 : ENAMETOOLONG);
171 if ((oidPsz + pfnLen + (pfnLen/oidMax)) >= blen)
return ENAMETOOLONG;
175 strcpy(buff, oidPfx); bP = buff + oidPsz; blen -= oidPsz;
179 while(blen > oidMax && pfnLen > oidMax)
180 {strncpy(bP, pfn, oidMax);
181 bP += oidMax; blen -= oidMax;
182 pfn += oidMax; pfnLen -= oidMax;
183 if (blen > 0) {*bP++ =
'/'; blen--;}
188 if (blen <= pfnLen)
return ENAMETOOLONG;
199 struct bHelper {
char *p; bHelper(
const char *bP) : p(bP ? strdup(bP) : 0) {}
200 ~bHelper() {
if (p) free(p);}
213 while((val = toks.
GetToken()) && *val)
214 {
if (!strcmp(val,
"-slash"))
215 {
if (!(val = toks.
GetToken()) || !(*val))
216 {
eDest->
Emsg(
"N2No2p",
"-slash argument not specified.");
219 if (strlen(val) == 1) {sChar = *val;
continue;}
220 n = strtol(val, &eP, 16);
222 {
eDest->
Emsg(
"N2No2p",
"Invalid -slash argument -",val);
225 sChar =
static_cast<char>(n);
227 else if (!strcmp(val,
"-maxfnlen"))
228 {
if (!(val = toks.
GetToken()) || !(*val))
229 {
eDest->
Emsg(
"N2No2p",
"-maxfnlen argument not specified.");
232 fnMax = strtol(val, &eP, 16);
233 if (fnMax <= 0 || *eP)
234 {
eDest->
Emsg(
"N2No2p",
"Invalid -maxfnlen argument -",val);
243 if (!val || !(*val)) oPfx =
"/";
244 else {
if (*val !=
'/')
245 {
eDest->
Emsg(
"N2No2p",
"Invalid object ID path prefix -", val);
250 if (val[n-1] !=
'/') {ostr = val; ostr +=
'/'; oPfx = ostr.c_str();}
256 if ((fnMax =
pathconf(
"/", _PC_NAME_MAX)) < 0)
257 {
eDest->
Emsg(
"N2No2p", errno,
"determine -fnmaxlen for '/'; using 255.");
static XrdSysError eDest(0,"crypto_")
XrdOucName2Name * XrdOucgetName2Name(XrdOucgetName2NameArgs)
unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)
XrdVERSIONINFO(XrdOucgetName2Name, "XrdN2No2p")
#define XrdOucgetName2NameArgs
long pathconf(const char *path, int name)
XrdOucN2No2p(XrdSysError *erp, const char *lroot, const char *pfx, int fnmax, char sc)
virtual int pfn2lfn(const char *pfn, char *buff, int blen)
virtual int lfn2pfn(const char *lfn, char *buff, int blen)
virtual int lfn2rfn(const char *lfn, char *buff, int blen)
char * GetToken(char **rest=0, int lowcase=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)