File indexing completed on 2025-01-18 10:15:38
0001 #ifndef __OUC_PLIST__
0002 #define __OUC_PLIST__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
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);
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