XRootD
XrdCmsPList.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d C m s P L i s t . c c */
4 /* */
5 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include "XrdCms/XrdCmsPList.hh"
32 
33 /******************************************************************************/
34 /* A d d */
35 /******************************************************************************/
36 
37 /******************************************************************************/
38 /* I n s e r t */
39 /******************************************************************************/
40 
41 int XrdCmsPList_Anchor::Add(const char *pname, XrdCmsPInfo *pinfo)
42 {
43  int plen = strlen(pname);
44  XrdCmsPList *p, *pp;
45 
46 // Set up the search
47 //
48  Lock();
49  p = next;
50  pp = 0;
51 
52 // Find the proper insertion point. Paths are sorted in decreasin length order.
53 //
54  while(p && p->pathlen >= plen)
55  {if (p->pathlen == plen && !strcmp(p->pathname,pname))
56  {UnLock(); return 0;}
57  pp = p;
58  p = p->next;
59  }
60 
61 // Insert a new element
62 //
63  p = new XrdCmsPList(pname, pinfo);
64  if (pp) { p->next = pp->next; pp->next = p;}
65  else { p->next = next; next = p;}
66 
67 // All done
68 //
69  UnLock();
70  return 1;
71 }
72 
73 /******************************************************************************/
74 /* F i n d */
75 /******************************************************************************/
76 
77 int XrdCmsPList_Anchor::Find(const char *pname, XrdCmsPInfo &pinfo)
78 {
79  int plen = strlen(pname);
80 
81 // Lock the anchor and setup for search
82 //
83  Lock();
84  XrdCmsPList *p = next;
85 
86 // Find matching entry
87 //
88  while(p) if (p->pathlen <= plen && !strncmp(p->pathname, pname, p->pathlen))
89  {pinfo = p->pathmask; break;}
90  else p = p->next;
91 
92 // All done
93 //
94  UnLock();
95  return p != 0;
96 }
97 
98 /******************************************************************************/
99 /* I n s e r t */
100 /******************************************************************************/
101 
103 {
104  int rc, plen = strlen(pname);
105  XrdCmsPList *p, *pp;
106  SMask_t newmask;
107 
108 // Set up the search
109 //
110  Lock();
111  p = next;
112  pp = 0;
113 
114 // Find the proper insertion point. Paths are sorted in decreasin length
115 // order. We must merge in the incoming mask with all subset paths.
116 //
117  rc = 1;
118  while(p && p->pathlen >= plen)
119  {if (p->pathlen == plen && !(rc = strcmp(p->pathname,pname))) break;
120  else if (!strncmp(p->pathname,pname,plen)
121  && !(p->pathmask.rovec & pinfo->rovec))
122  {p->pathmask.And(~(pinfo->rovec)); p->pathmask.Or(pinfo);}
123  pp = p;
124  p = p->next;
125  }
126 
127 // Either merge the path masks or insert a new path. For a new path, add to
128 // it masks of all superset paths that may follow it in the chain of paths.
129 //
130  if (!rc) {p->pathmask.And(~(pinfo->rovec)); p->pathmask.Or(pinfo);}
131  else { p = new XrdCmsPList(pname, pinfo);
132  if (pp)
133  { p->next = pp->next;
134  pp->next = p;
135  } else {
136  p->next = next;
137  next = p;
138  }
139  pp = p->next;
140  while(pp) {if (pp->pathlen < plen
141  && !strncmp(pp->pathname,pname,pp->pathlen))
142  p->pathmask.Or(&(pp->pathmask));
143  pp = pp->next;
144  }
145  }
146 
147 // All done
148 //
149  newmask = p->pathmask.rovec | p->pathmask.rwvec;
150  UnLock();
151  return newmask;
152 }
153 
154 /******************************************************************************/
155 /* R e m o v e */
156 /******************************************************************************/
157 
159 {
160  SMask_t zmask(~mask);
161  XrdCmsPList *pp = next, *prevp = 0;
162 
163 // Lock the list
164 //
165  Lock();
166 
167 // Remove bit from mask. If mask is zero, remove the entry
168 //
169  while(pp)
170  {if (!pp->pathmask.And(zmask))
171  {if (prevp) {prevp->next = pp->next; delete pp; pp = prevp->next;}
172  else { next = pp->next; delete pp; pp = next;}
173  }
174  else {prevp = pp; pp = pp->next;}
175  }
176 
177 // All done
178 //
179  UnLock();
180 }
181 
182 /******************************************************************************/
183 /* F i n d */
184 /******************************************************************************/
185 
186 const char *XrdCmsPList_Anchor::Type(const char *pname)
187 {
188  int isrw = 0, plen = strlen(pname);
189 
190 // Lock the anchor and setup for search
191 //
192  Lock();
193  XrdCmsPList *p = next;
194 
195 // Find matching entry
196 //
197  while(p) if (p->pathlen <= plen && !strncmp(p->pathname, pname, p->pathlen))
198  {isrw = (p->pathmask.rwvec != 0); break;}
199  else p = p->next;
200 
201 // All done
202 //
203  UnLock();
204  if (p) return (isrw ? "w" : "r");
205  return "?";
206 }
207 
208 /******************************************************************************/
209 /* P T y p e */
210 /******************************************************************************/
211 
212 const char *XrdCmsPList::PType()
213 {
214  if (pathmask.ssvec) return (pathmask.rwvec ? "ws" : "rs");
215  return (pathmask.rwvec ? "w" : "r");
216 }
unsigned long long SMask_t
Definition: XrdCmsTypes.hh:33
SMask_t ssvec
Definition: XrdCmsPList.hh:49
int And(const SMask_t mask)
Definition: XrdCmsPList.hh:51
SMask_t rovec
Definition: XrdCmsPList.hh:47
SMask_t rwvec
Definition: XrdCmsPList.hh:48
void Or(const XrdCmsPInfo *pi)
Definition: XrdCmsPList.hh:54
void Remove(SMask_t mask)
Definition: XrdCmsPList.cc:158
int Find(const char *pname, XrdCmsPInfo &masks)
Definition: XrdCmsPList.cc:77
const char * Type(const char *pname)
Definition: XrdCmsPList.cc:186
int Add(const char *pname, XrdCmsPInfo *pinfo)
Definition: XrdCmsPList.cc:41
SMask_t Insert(const char *pname, XrdCmsPInfo *pinfo)
Definition: XrdCmsPList.cc:102
const char * PType()
Definition: XrdCmsPList.cc:212