xrootd
Loading...
Searching...
No Matches
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 <cstdio>
34#include <cstring>
35#include <cstdlib>
36
38{
39public:
40
41inline int Attr() {return attrs;}
42inline unsigned long long Flag() {return flags;}
43inline const char *Name() {return name;}
44inline XrdOucPList *Next() {return next;}
45inline char *Path() {return path;}
46inline int Plen() {return pathlen;}
47
48inline int PathOK(const char *pd, const int pl)
49 {return pl >= pathlen && !strncmp(pd, path, pathlen);}
50
51inline void Set(int aval) {attrs = aval;}
52inline void Set(unsigned long long fval) {flags = fval;}
53inline 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
74friend class XrdOucPListAnchor;
75
76private:
77
78union{
79unsigned long long flags;
80char *name;
81 };
83char *path;
86};
87
89{
90public:
91
92inline 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
101inline void Default(unsigned long long x) {dflts = x;}
102inline
103unsigned long long Default() {return dflts;}
104inline void Defstar(unsigned long long x) {dstrs = x;}
105
106inline void Empty(XrdOucPList *newlist=0)
107 {XrdOucPList *p = next;
108 while(p) {next = p->next; delete p; p = next;}
109 next = newlist;
110 }
111
112inline 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
122inline 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
132inline XrdOucPList *First() {return next;}
133
134inline 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
141inline int NotEmpty() {return next != 0;}
142
143 XrdOucPListAnchor(unsigned long long dfx=0)
144 : dflts(dfx), dstrs(dfx) {}
146
147private:
148
149unsigned long long dflts;
150unsigned long long dstrs;
151};
152#endif
Definition XrdOucPList.hh:89
XrdOucPListAnchor(unsigned long long dfx=0)
Definition XrdOucPList.hh:143
unsigned long long dstrs
Definition XrdOucPList.hh:150
XrdOucPList * Match(const char *pathname)
Definition XrdOucPList.hh:122
void Default(unsigned long long x)
Definition XrdOucPList.hh:101
XrdOucPList * First()
Definition XrdOucPList.hh:132
void Insert(XrdOucPList *newitem)
Definition XrdOucPList.hh:134
int NotEmpty()
Definition XrdOucPList.hh:141
unsigned long long Default()
Definition XrdOucPList.hh:103
unsigned long long Find(const char *pathname)
Definition XrdOucPList.hh:112
void Defstar(unsigned long long x)
Definition XrdOucPList.hh:104
~XrdOucPListAnchor()
Definition XrdOucPList.hh:145
unsigned long long dflts
Definition XrdOucPList.hh:149
void Empty(XrdOucPList *newlist=0)
Definition XrdOucPList.hh:106
XrdOucPList * About(const char *pathname)
Definition XrdOucPList.hh:92
Definition XrdOucPList.hh:38
char * Path()
Definition XrdOucPList.hh:45
int Plen()
Definition XrdOucPList.hh:46
void Set(unsigned long long fval)
Definition XrdOucPList.hh:52
int Attr()
Definition XrdOucPList.hh:41
void Set(int aval)
Definition XrdOucPList.hh:51
unsigned long long flags
Definition XrdOucPList.hh:79
int attrs
Definition XrdOucPList.hh:85
int PathOK(const char *pd, const int pl)
Definition XrdOucPList.hh:48
int pathlen
Definition XrdOucPList.hh:84
XrdOucPList(const char *pd="", unsigned long long fv=0)
Definition XrdOucPList.hh:63
XrdOucPList(const char *pd, const char *pn)
Definition XrdOucPList.hh:67
~XrdOucPList()
Definition XrdOucPList.hh:71
void Set(const char *pd, const char *pn)
Definition XrdOucPList.hh:53
XrdOucPList * Next()
Definition XrdOucPList.hh:44
const char * Name()
Definition XrdOucPList.hh:43
XrdOucPList * next
Definition XrdOucPList.hh:82
unsigned long long Flag()
Definition XrdOucPList.hh:42
char * path
Definition XrdOucPList.hh:83
char * name
Definition XrdOucPList.hh:80