xrootd
XrdOucPList.hh
Go to the documentation of this file.
1 #ifndef __OUC_PLIST__
2 #define __OUC_PLIST__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c P L i s t . h h */
6 /* */
7 /* (c) 2003 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-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <stdio.h>
34 #include <strings.h>
35 #include <stdlib.h>
36 
38 {
39 public:
40 
41 inline int Attr() {return attrs;}
42 inline unsigned long long Flag() {return flags;}
43 inline const char *Name() {return name;}
44 inline XrdOucPList *Next() {return next;}
45 inline char *Path() {return path;}
46 inline int Plen() {return pathlen;}
47 
48 inline int PathOK(const char *pd, const int pl)
49  {return pl >= pathlen && !strncmp(pd, path, pathlen);}
50 
51 inline void Set(int aval) {attrs = aval;}
52 inline void Set(unsigned long long fval) {flags = fval;}
53 inline void Set(const char *pd, const char *pn)
54  {if (path) free(path);
55  pathlen = strlen(pd);
56  int n = strlen(pn) + 1 + pathlen + 1;
57  path = (char *)malloc(n);
58  n = snprintf(path, n, "%s", pd);
59  name = path+pathlen+1;
60  strcpy(name, pn); // This is safe
61  }
62 
63  XrdOucPList(const char *pd="", unsigned long long fv=0)
64  : flags(fv), next(0), path(strdup(pd)),
65  pathlen(strlen(pd)), attrs(0) {}
66 
67  XrdOucPList(const char *pd, const char *pn)
68  : next(0), path(0), attrs(0)
69  {Set(pd, pn);}
70 
72  {if (path) free(path);}
73 
74 friend class XrdOucPListAnchor;
75 
76 private:
77 
78 union{
79 unsigned long long flags;
80 char *name;
81  };
83 char *path;
84 int pathlen;
85 int attrs;
86 };
87 
89 {
90 public:
91 
92 inline XrdOucPList *About(const char *pathname)
93  {int plen = strlen(pathname);
94  XrdOucPList *p = next;
95  while(p) {if (p->PathOK(pathname, plen)) break;
96  p=p->next;
97  }
98  return p;
99  }
100 
101 inline void Default(unsigned long long x) {dflts = x;}
102 inline
103 unsigned long long Default() {return dflts;}
104 inline void Defstar(unsigned long long x) {dstrs = x;}
105 
106 inline void Empty(XrdOucPList *newlist=0)
107  {XrdOucPList *p = next;
108  while(p) {next = p->next; delete p; p = next;}
109  next = newlist;
110  }
111 
112 inline unsigned long long Find(const char *pathname)
113  {int plen = strlen(pathname);
114  XrdOucPList *p = next;
115  while(p) {if (p->PathOK(pathname, plen)) break;
116  p=p->next;
117  }
118  if (p) return p->flags;
119  return (*pathname == '/' ? dflts : dstrs);
120  }
121 
122 inline XrdOucPList *Match(const char *pathname)
123  {int plen = strlen(pathname);
124  XrdOucPList *p = next;
125  while(p) {if (p->pathlen == plen
126  && !strcmp(p->path, pathname)) break;
127  p=p->next;
128  }
129  return p;
130  }
131 
132 inline XrdOucPList *First() {return next;}
133 
134 inline void Insert(XrdOucPList *newitem)
135  {XrdOucPList *pp = 0, *cp = next;
136  while(cp && newitem->pathlen < cp->pathlen) {pp=cp;cp=cp->next;}
137  if (pp) {newitem->next = pp->next; pp->next = newitem;}
138  else {newitem->next = next; next = newitem;}
139  }
140 
141 inline int NotEmpty() {return next != 0;}
142 
143  XrdOucPListAnchor(unsigned long long dfx=0)
144  : dflts(dfx), dstrs(dfx) {}
146 
147 private:
148 
149 unsigned long long dflts;
150 unsigned long long dstrs;
151 };
152 #endif
XrdOucPList(const char *pd, const char *pn)
Definition: XrdOucPList.hh:67
unsigned long long Default()
Definition: XrdOucPList.hh:103
void Insert(XrdOucPList *newitem)
Definition: XrdOucPList.hh:134
int Plen()
Definition: XrdOucPList.hh:46
Definition: XrdOucPList.hh:88
void Set(const char *pd, const char *pn)
Definition: XrdOucPList.hh:53
XrdOucPListAnchor(unsigned long long dfx=0)
Definition: XrdOucPList.hh:143
XrdOucPList(const char *pd="", unsigned long long fv=0)
Definition: XrdOucPList.hh:63
void Empty(XrdOucPList *newlist=0)
Definition: XrdOucPList.hh:106
int Attr()
Definition: XrdOucPList.hh:41
int pathlen
Definition: XrdOucPList.hh:84
XrdOucPList * next
Definition: XrdOucPList.hh:82
void Set(int aval)
Definition: XrdOucPList.hh:51
~XrdOucPList()
Definition: XrdOucPList.hh:71
XrdOucPList * Next()
Definition: XrdOucPList.hh:44
const char * Name()
Definition: XrdOucPList.hh:43
char * name
Definition: XrdOucPList.hh:80
void Default(unsigned long long x)
Definition: XrdOucPList.hh:101
void Defstar(unsigned long long x)
Definition: XrdOucPList.hh:104
~XrdOucPListAnchor()
Definition: XrdOucPList.hh:145
unsigned long long dstrs
Definition: XrdOucPList.hh:150
unsigned long long Find(const char *pathname)
Definition: XrdOucPList.hh:112
unsigned long long dflts
Definition: XrdOucPList.hh:149
int NotEmpty()
Definition: XrdOucPList.hh:141
XrdOucPList * First()
Definition: XrdOucPList.hh:132
unsigned long long flags
Definition: XrdOucPList.hh:79
XrdOucPList * About(const char *pathname)
Definition: XrdOucPList.hh:92
int attrs
Definition: XrdOucPList.hh:85
Definition: XrdOucPList.hh:37
void Set(unsigned long long fval)
Definition: XrdOucPList.hh:52
XrdOucPList * Match(const char *pathname)
Definition: XrdOucPList.hh:122
char * Path()
Definition: XrdOucPList.hh:45
int PathOK(const char *pd, const int pl)
Definition: XrdOucPList.hh:48
unsigned long long Flag()
Definition: XrdOucPList.hh:42
char * path
Definition: XrdOucPList.hh:83