xrootd
XrdXrootdXPath.hh
Go to the documentation of this file.
1 #ifndef __XROOTD_XPATH__
2 #define __XROOTD_XPATH__
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d X P a t h . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #include <strings.h>
16 #include <stdlib.h>
17 
18 #define XROOTDXP_OK 1
19 #define XROOTDXP_NOLK 2
20 
22 {
23 public:
24 
25 inline XrdXrootdXPath *Next() {return next;}
26 inline int Opts() {return pathopt;}
27 inline char *Path() {return path;}
28 inline char *Path(int &PLen)
29  {PLen = pathlen; return path;}
30 
31  void Insert(const char *pd, int popt=0, int flags=XROOTDXP_OK)
32  {XrdXrootdXPath *pp = 0, *p = next;
33  XrdXrootdXPath *newp = new XrdXrootdXPath(pd,popt,flags);
34  while(p && newp->pathlen >= p->pathlen)
35  {pp = p; p = p->next;}
36  newp->next = p;
37  if (pp) pp->next = newp;
38  else next = newp;
39  }
40 
41 inline int Validate(const char *pd, const int pl=0)
42  {int plen = (pl ? pl : strlen(pd));
43  XrdXrootdXPath *p = next;
44  while(p && plen >= p->pathlen)
45  {if (!strncmp(pd, p->path, p->pathlen))
46  return p->pathopt;
47  p=p->next;
48  }
49  return 0;
50  }
51 
52  XrdXrootdXPath(const char *pathdata="",int popt=0,int flags=XROOTDXP_OK)
53  {next = 0;
54  pathopt = popt | flags;
55  pathlen = strlen(pathdata);
56  path = strdup(pathdata);
57  }
58 
59  ~XrdXrootdXPath() {if (path) free(path);}
60 
61 private:
62 
64  int pathlen;
65  int pathopt;
66  char *path;
67 };
68 #endif