xrootd
XrdXrootdXPath.hh
Go to the documentation of this file.
00001 #ifndef __XROOTD_XPATH__
00002 #define __XROOTD_XPATH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                     X r d X r o o t d X P a t h . h h                      */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include <strings.h>
00034 #include <stdlib.h>
00035 
00036 #define XROOTDXP_OK        1
00037 #define XROOTDXP_NOLK      2
00038   
00039 class XrdXrootdXPath
00040 {
00041 public:
00042 
00043 inline XrdXrootdXPath *Next()  {return next;}
00044 inline int             Opts()  {return pathopt;}
00045 inline char           *Path()  {return path;}
00046 inline char           *Path(int &PLen)
00047                                {PLen = pathlen; return path;}
00048 
00049        void            Insert(const char *pd, int popt=0, int flags=XROOTDXP_OK)
00050                              {XrdXrootdXPath *pp = 0, *p = next;
00051                               XrdXrootdXPath *newp = new XrdXrootdXPath(pd,popt,flags);
00052                               while(p && newp->pathlen >= p->pathlen)
00053                                    {pp = p; p = p->next;}
00054                               newp->next = p;
00055                               if (pp) pp->next = newp;
00056                                  else     next = newp;
00057                              }
00058 
00059 inline int             Validate(const char *pd, const int pl=0)
00060                                {int plen = (pl ? pl : strlen(pd));
00061                                 XrdXrootdXPath *p = next;
00062                                 while(p && plen >= p->pathlen)
00063                                      {if (!strncmp(pd, p->path, p->pathlen))
00064                                          return p->pathopt;
00065                                       p=p->next;
00066                                      }
00067                                 return 0;
00068                                }
00069 
00070        XrdXrootdXPath(const char *pathdata="",int popt=0,int flags=XROOTDXP_OK)
00071                      {next = 0;
00072                       pathopt = popt | flags;
00073                       pathlen = strlen(pathdata);
00074                       path    = strdup(pathdata);
00075                      }
00076 
00077       ~XrdXrootdXPath() {if (path) free(path);}
00078 
00079 private:
00080 
00081        XrdXrootdXPath *next;
00082        int             pathlen;
00083        int             pathopt;
00084        char           *path;
00085 };
00086 #endif