XrdOucNList.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                        X r d O u c N L i s t . c c                         */
00004 /*                                                                            */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //        $Id: XrdOucNList.cc 22437 2008-03-04 14:35:16Z rdm $
00012 
00013 const char *XrdOucNListCVSID = "$Id: XrdOucNList.cc 22437 2008-03-04 14:35:16Z rdm $";
00014 
00015 #include <string.h>
00016 #include "XrdOuc/XrdOucNList.hh"
00017   
00018 /******************************************************************************/
00019 /*                           C o n s t r u c t o r                            */
00020 /******************************************************************************/
00021   
00022 XrdOucNList::XrdOucNList(const char *name, int nval)
00023 {
00024    char *ast;
00025 
00026 // Do the default assignments
00027 //
00028    nameL = strdup(name);
00029    next  = 0;
00030    flags = nval;
00031 
00032 // First find the asterisk, if any in the name
00033 //
00034    if ((ast = index(nameL, '*')))
00035       {namelenL = ast - nameL;
00036        *ast  = 0;
00037        nameR = ast+1;
00038        namelenR = strlen(nameR);
00039       } else {
00040        namelenL = strlen(nameL);
00041        namelenR = -1;
00042       }
00043 }
00044  
00045 /******************************************************************************/
00046 /*                                N a m e O K                                 */
00047 /******************************************************************************/
00048   
00049 int XrdOucNList::NameOK(const char *pd, const int pl)
00050 {
00051 
00052 // Check if exact match wanted
00053 //
00054    if (namelenR < 0) return !strcmp(pd, nameL);
00055 
00056 // Make sure the prefix matches
00057 //
00058    if (namelenL && namelenL <= pl && strncmp(pd,nameL,namelenL))
00059       return 0;
00060 
00061 // Make sure suffix matches
00062 //
00063    if (!namelenR)     return 1;
00064    if (namelenR > pl) return 0;
00065    return !strcmp((pd + pl - namelenR), nameR);
00066 }
00067 
00068 /******************************************************************************/
00069 /*                               R e p l a c e                                */
00070 /******************************************************************************/
00071   
00072 void XrdOucNList_Anchor::Replace(const char *name, int nval)
00073 {
00074    XrdOucNList *xp = new XrdOucNList(name, nval);
00075 
00076    Replace(xp);
00077 }
00078 
00079 
00080 void XrdOucNList_Anchor::Replace(XrdOucNList *xp)
00081 {
00082    XrdOucNList *np, *pp = 0;
00083 
00084 // Lock ourselves
00085 //
00086    Lock();
00087    np = next;
00088 
00089 // Find the matching item or the place to insert the item
00090 //
00091    while(np && np->namelenL >= xp->namelenL)
00092         {if (np->namelenL == xp->namelenL
00093          &&  np->namelenR == xp->namelenR
00094          && (np->nameL && xp->nameL && !strcmp(np->nameL, xp->nameL))
00095          && (np->nameR && xp->nameR && !strcmp(np->nameR, xp->nameR)))
00096             {np->Set(xp->flags);
00097              UnLock();
00098              delete xp;
00099              return;
00100             }
00101           pp = np; np = np->next;
00102          }
00103 
00104 // Must insert a new item
00105 //
00106    if (pp) {xp->next = np; pp->next = xp;}
00107       else {xp->next = next;   next = xp;}
00108 
00109 // All done
00110 //
00111    UnLock();
00112 }

Generated on Tue Jul 5 14:46:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1