XRootD
Loading...
Searching...
No Matches
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
37XrdOucNList::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 nameR = nullptr;
58 }
59}
60
61/******************************************************************************/
62/* N a m e K O */
63/******************************************************************************/
64
65int XrdOucNList::NameKO(const char *pd, const int pl)
66{
67
68// Check if exact match wanted
69//
70 if (namelenR < 0) return !strcasecmp(pd, nameL);
71
72// Make sure the prefix matches
73//
74 if (namelenL && namelenL <= pl && strncasecmp(pd,nameL,namelenL))
75 return 0;
76
77// Make sure suffix matches
78//
79 if (!namelenR) return 1;
80 if (namelenR > pl) return 0;
81 return !strcasecmp((pd + pl - namelenR), nameR);
82}
83
84/******************************************************************************/
85/* N a m e O K */
86/******************************************************************************/
87
88int XrdOucNList::NameOK(const char *pd, const int pl)
89{
90
91// Check if exact match wanted
92//
93 if (namelenR < 0) return !strcmp(pd, nameL);
94
95// Make sure the prefix matches
96//
97 if (namelenL && namelenL <= pl && strncmp(pd,nameL,namelenL))
98 return 0;
99
100// Make sure suffix matches
101//
102 if (!namelenR) return 1;
103 if (namelenR > pl) return 0;
104 return !strcmp((pd + pl - namelenR), nameR);
105}
106
107/******************************************************************************/
108/* R e p l a c e */
109/******************************************************************************/
110
111void XrdOucNList_Anchor::Replace(const char *name, int nval)
112{
113 XrdOucNList *xp = new XrdOucNList(name, nval);
114
115 Replace(xp);
116}
117
118
120{
121 XrdOucNList *np, *pp = 0;
122
123// Lock ourselves
124//
125 Lock();
126 np = next;
127
128// Find the matching item or the place to insert the item
129//
130 while(np && np->namelenL >= xp->namelenL)
131 {if (np->namelenL == xp->namelenL
132 && np->namelenR == xp->namelenR
133 && (np->nameL && xp->nameL && !strcmp(np->nameL, xp->nameL))
134 && (np->namelenR < 0
135 || (np->nameR && xp->nameR && !strcmp(np->nameR, xp->nameR))))
136 {np->Set(xp->flags);
137 UnLock();
138 delete xp;
139 return;
140 }
141 pp = np; np = np->next;
142 }
143
144// Must insert a new item
145//
146 if (pp) {xp->next = np; pp->next = xp;}
147 else {xp->next = next; next = xp;}
148
149// All done
150//
151 UnLock();
152}
void Replace(const char *name, int nval)
int NameKO(const char *pd, const int pl)
int NameOK(const char *pd, const int pl)
XrdOucNList(const char *name="", int nvals=0)
void Set(int fval)