Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:38

0001 #ifndef __OUC_PLIST__
0002 #define __OUC_PLIST__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d O u c P L i s t . h h                         */
0006 /*                                                                            */
0007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <cstdio>
0034 #include <cstring>
0035 #include <cstdlib>
0036   
0037 class XrdOucPList
0038 {
0039 public:
0040 
0041 inline int                 Attr() {return attrs;}
0042 inline unsigned long long  Flag() {return flags;}
0043 inline const char         *Name() {return name;}
0044 inline XrdOucPList        *Next() {return next;}
0045 inline char               *Path() {return path;}
0046 inline int                 Plen() {return pathlen;}
0047 
0048 inline int          PathOK(const char *pd, const int pl)
0049                           {return pl >= pathlen && !strncmp(pd, path, pathlen);}
0050 
0051 inline void         Set(int                aval) {attrs = aval;}
0052 inline void         Set(unsigned long long fval) {flags = fval;}
0053 inline void         Set(const char *pd, const char *pn)
0054                        {if (path) free(path);
0055                         pathlen = strlen(pd);
0056                         int n = strlen(pn) + 1 + pathlen + 1;
0057                         path = (char *)malloc(n);
0058                         n = snprintf(path, n, "%s", pd);
0059                         name = path+pathlen+1;
0060                         strcpy(name, pn); // This is safe
0061                        }
0062 
0063              XrdOucPList(const char *pd="", unsigned long long fv=0)
0064                         : flags(fv), next(0),  path(strdup(pd)),
0065                           pathlen(strlen(pd)), attrs(0) {}
0066 
0067              XrdOucPList(const char *pd, const char *pn) 
0068                         : next(0), path(0), attrs(0)
0069                         {Set(pd, pn);}
0070 
0071             ~XrdOucPList()
0072                   {if (path) free(path);}
0073 
0074 friend class XrdOucPListAnchor;
0075 
0076 private:
0077 
0078 union{
0079 unsigned long long flags;
0080 char              *name;
0081      };
0082 XrdOucPList       *next;
0083 char              *path;
0084 int                pathlen;
0085 int                attrs;
0086 };
0087 
0088 class XrdOucPListAnchor : public XrdOucPList
0089 {
0090 public:
0091 
0092 inline XrdOucPList *About(const char *pathname)
0093                    {int plen = strlen(pathname); 
0094                     XrdOucPList *p = next;
0095                     while(p) {if (p->PathOK(pathname, plen)) break;
0096                               p=p->next;
0097                              }
0098                     return p;
0099                    }
0100 
0101 inline void        Default(unsigned long long x) {dflts = x;}
0102 inline
0103 unsigned long long Default() {return dflts;}
0104 inline void        Defstar(unsigned long long x) {dstrs = x;}
0105 
0106 inline void        Empty(XrdOucPList *newlist=0)
0107                    {XrdOucPList *p = next;
0108                     while(p) {next = p->next; delete p; p = next;}
0109                     next = newlist;
0110                    }
0111 
0112 inline unsigned long long  Find(const char *pathname)
0113                    {int plen = strlen(pathname); 
0114                     XrdOucPList *p = next;
0115                     while(p) {if (p->PathOK(pathname, plen)) break;
0116                               p=p->next;
0117                              }
0118                     if (p) return p->flags;
0119                     return (*pathname == '/' ? dflts : dstrs);
0120                    }
0121 
0122 inline XrdOucPList *Match(const char *pathname)
0123                    {int plen = strlen(pathname); 
0124                     XrdOucPList *p = next;
0125                     while(p) {if (p->pathlen == plen 
0126                               &&  !strcmp(p->path, pathname)) break;
0127                               p=p->next;
0128                              }
0129                     return p;
0130                    }
0131 
0132 inline XrdOucPList *First() {return next;}
0133 
0134 inline void        Insert(XrdOucPList *newitem)
0135                    {XrdOucPList *pp = 0, *cp = next;
0136                     while(cp && newitem->pathlen < cp->pathlen) {pp=cp;cp=cp->next;}
0137                     if (pp) {newitem->next = pp->next; pp->next = newitem;}
0138                        else {newitem->next = next;         next = newitem;}
0139                    }
0140 
0141 inline int         NotEmpty() {return next != 0;}
0142 
0143                    XrdOucPListAnchor(unsigned long long dfx=0)
0144                                     : dflts(dfx), dstrs(dfx) {}
0145                   ~XrdOucPListAnchor() {}
0146 
0147 private:
0148 
0149 unsigned long long dflts;
0150 unsigned long long dstrs;
0151 };
0152 #endif