XRootD
XrdOucNList.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d O u c N L i s t . c c */
4 /* */
5 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* Produced by Andrew Hanushevsky for Stanford University under contract */
7 /* DE-AC02-76-SFO0515 with the Department of Energy */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
30 #include <cstring>
31 #include "XrdOuc/XrdOucNList.hh"
32 
33 /******************************************************************************/
34 /* C o n s t r u c t o r */
35 /******************************************************************************/
36 
37 XrdOucNList::XrdOucNList(const char *name, int nval)
38 {
39  char *ast;
40 
41 // Do the default assignments
42 //
43  nameL = strdup(name);
44  next = 0;
45  flags = nval;
46 
47 // First find the asterisk, if any in the name
48 //
49  if ((ast = index(nameL, '*')))
50  {namelenL = ast - nameL;
51  *ast = 0;
52  nameR = ast+1;
53  namelenR = strlen(nameR);
54  } else {
55  namelenL = strlen(nameL);
56  namelenR = -1;
57  }
58 }
59 
60 /******************************************************************************/
61 /* N a m e K O */
62 /******************************************************************************/
63 
64 int XrdOucNList::NameKO(const char *pd, const int pl)
65 {
66 
67 // Check if exact match wanted
68 //
69  if (namelenR < 0) return !strcasecmp(pd, nameL);
70 
71 // Make sure the prefix matches
72 //
73  if (namelenL && namelenL <= pl && strncasecmp(pd,nameL,namelenL))
74  return 0;
75 
76 // Make sure suffix matches
77 //
78  if (!namelenR) return 1;
79  if (namelenR > pl) return 0;
80  return !strcasecmp((pd + pl - namelenR), nameR);
81 }
82 
83 /******************************************************************************/
84 /* N a m e O K */
85 /******************************************************************************/
86 
87 int XrdOucNList::NameOK(const char *pd, const int pl)
88 {
89 
90 // Check if exact match wanted
91 //
92  if (namelenR < 0) return !strcmp(pd, nameL);
93 
94 // Make sure the prefix matches
95 //
96  if (namelenL && namelenL <= pl && strncmp(pd,nameL,namelenL))
97  return 0;
98 
99 // Make sure suffix matches
100 //
101  if (!namelenR) return 1;
102  if (namelenR > pl) return 0;
103  return !strcmp((pd + pl - namelenR), nameR);
104 }
105 
106 /******************************************************************************/
107 /* R e p l a c e */
108 /******************************************************************************/
109 
110 void XrdOucNList_Anchor::Replace(const char *name, int nval)
111 {
112  XrdOucNList *xp = new XrdOucNList(name, nval);
113 
114  Replace(xp);
115 }
116 
117 
119 {
120  XrdOucNList *np, *pp = 0;
121 
122 // Lock ourselves
123 //
124  Lock();
125  np = next;
126 
127 // Find the matching item or the place to insert the item
128 //
129  while(np && np->namelenL >= xp->namelenL)
130  {if (np->namelenL == xp->namelenL
131  && np->namelenR == xp->namelenR
132  && (np->nameL && xp->nameL && !strcmp(np->nameL, xp->nameL))
133  && (np->nameR && xp->nameR && !strcmp(np->nameR, xp->nameR)))
134  {np->Set(xp->flags);
135  UnLock();
136  delete xp;
137  return;
138  }
139  pp = np; np = np->next;
140  }
141 
142 // Must insert a new item
143 //
144  if (pp) {xp->next = np; pp->next = xp;}
145  else {xp->next = next; next = xp;}
146 
147 // All done
148 //
149  UnLock();
150 }
void Replace(const char *name, int nval)
Definition: XrdOucNList.cc:110
int NameKO(const char *pd, const int pl)
Definition: XrdOucNList.cc:64
int NameOK(const char *pd, const int pl)
Definition: XrdOucNList.cc:87
XrdOucNList(const char *name="", int nvals=0)
Definition: XrdOucNList.cc:37
void Set(int fval)
Definition: XrdOucNList.hh:55