XRootD
XrdOucN2No2p.cc File Reference
#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <string>
#include <cstring>
#include <unistd.h>
#include "XrdVersion.hh"
#include "XrdOuc/XrdOucName2Name.hh"
#include "XrdOuc/XrdOucTokenizer.hh"
#include "XrdSys/XrdSysError.hh"
+ Include dependency graph for XrdOucN2No2p.cc:

Go to the source code of this file.

Classes

class  XrdOucN2No2p
 

Functions

XrdOucName2NameXrdOucgetName2Name (XrdOucgetName2NameArgs)
 
unsigned long XrdOucHashVal2 (const char *KeyVal, int KeyLen)
 
 XrdVERSIONINFO (XrdOucgetName2Name, "XrdN2No2p")
 

Function Documentation

◆ XrdOucgetName2Name()

XrdOucName2Name* XrdOucgetName2Name ( XrdOucgetName2NameArgs  )

Definition at line 197 of file XrdOucN2No2p.cc.

198 {
199  struct bHelper {char *p; bHelper(const char *bP) : p(bP ? strdup(bP) : 0) {}
200  ~bHelper() {if (p) free(p);}
201  };
202  bHelper prms(parms);
203  const char *oPfx;
204  char *val, *eP;
205  std::string ostr;
206  int fnMax = 0, n;
207  char sChar = '\\';
208 
209 // Process options
210 //
211  XrdOucTokenizer toks(prms.p);
212  toks.GetLine();
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.");
217  return 0;
218  }
219  if (strlen(val) == 1) {sChar = *val; continue;}
220  n = strtol(val, &eP, 16);
221  if (n & 0xff || *eP)
222  {eDest->Emsg("N2No2p", "Invalid -slash argument -",val);
223  return 0;
224  }
225  sChar = static_cast<char>(n);
226  }
227  else if (!strcmp(val, "-maxfnlen"))
228  {if (!(val = toks.GetToken()) || !(*val))
229  {eDest->Emsg("N2No2p", "-maxfnlen argument not specified.");
230  return 0;
231  }
232  fnMax = strtol(val, &eP, 16);
233  if (fnMax <= 0 || *eP)
234  {eDest->Emsg("N2No2p", "Invalid -maxfnlen argument -",val);
235  return 0;
236  }
237  }
238  else break;
239  }
240 
241 // Obtain the objectid prefix we are to use (default is '/')
242 //
243  if (!val || !(*val)) oPfx = "/";
244  else {if (*val != '/')
245  {eDest->Emsg("N2No2p", "Invalid object ID path prefix -", val);
246  return 0;
247  }
248  oPfx = val;
249  n = strlen(val);
250  if (val[n-1] != '/') {ostr = val; ostr += '/'; oPfx = ostr.c_str();}
251  }
252 
253 // Now determine what the maximum filename length if not specified
254 //
255  if (!fnMax)
256  if ((fnMax = pathconf("/", _PC_NAME_MAX)) < 0)
257  {eDest->Emsg("N2No2p", errno, "determine -fnmaxlen for '/'; using 255.");
258  fnMax = 255;
259  }
260 
261 // Return a new n2n object
262 //
263  return new XrdOucN2No2p(eDest, lroot, oPfx, fnMax, sChar);
264 }
static XrdSysError eDest(0,"crypto_")
long pathconf(const char *path, int name)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References eDest, XrdSysError::Emsg(), XrdOucTokenizer::GetLine(), XrdOucTokenizer::GetToken(), and pathconf().

Referenced by XrdOucN2NLoader::Load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ XrdOucHashVal2()

unsigned long XrdOucHashVal2 ( const char *  KeyVal,
int  KeyLen 
)

Definition at line 40 of file XrdOucHashVal.cc.

41 { int j;
42  unsigned long *lp, lword, hval = 0;
43  int hl = sizeof(hval);
44 
45 // If name is shorter than the hash length, use the name.
46 //
47  if (KeyLen <= hl)
48  {memcpy(&hval, KeyVal, (size_t)KeyLen);
49  return hval;
50  }
51 
52 // Compute the length of the name and develop starting hash.
53 //
54  hval = KeyLen;
55  j = KeyLen % hl; KeyLen /= hl;
56  if (j)
57  {memcpy(&lword, KeyVal, (size_t)hl);
58  hval ^= lword;
59  }
60  lp = (unsigned long *)&KeyVal[j];
61 
62 // Compute and return the full hash.
63 //
64  while(KeyLen--)
65  {memcpy(&lword, lp++, (size_t)hl);
66  hval ^= lword;
67  }
68  return (hval ? hval : 1);
69 }

Referenced by XrdOucN2No2p::pfn2lfn(), and XrdOucHashVal().

+ Here is the caller graph for this function:

◆ XrdVERSIONINFO()

XrdVERSIONINFO ( XrdOucgetName2Name  ,
"XrdN2No2p"   
)