XrdLinkMatch.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d L i n k M a t c h . c c                        */
00004 /*                                                                            */
00005 /* (c) 2005 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: XrdLinkMatch.cc 30949 2009-11-02 16:37:58Z ganis $
00012 
00013 const char *XrdLinkMatchCVSID = "$Id: XrdLinkMatch.cc 30949 2009-11-02 16:37:58Z ganis $";
00014 
00015 #include <string.h>
00016 
00017 #include "Xrd/XrdLinkMatch.hh"
00018 #include "XrdSys/XrdSysPlatform.hh"
00019  
00020 /******************************************************************************/
00021 /*                                 M a t c h                                  */
00022 /******************************************************************************/
00023   
00024 int XrdLinkMatch::Match(const char *uname, int unlen, 
00025                         const char *hname, int hnlen)
00026 {
00027 
00028 // Check if we should try to match the username
00029 //
00030    if (Unamelen && (Unamelen > unlen+1 || strncmp(uname,Uname,Unamelen))) return 0;
00031 
00032 // Check if we should match the full host name
00033 //
00034    if (HnameL && !HnamelenL) return !strcmp(HnameL, hname);
00035 
00036 // Check if prefix suffix matching might succeed
00037 //
00038    if (HnamelenL > hnlen) return 0;
00039 
00040 // Check if we should match the host name prefix
00041 //
00042    if (HnameL && strncmp(HnameL, hname, HnamelenL)) return 0;
00043 
00044 // Check if we should match the host name suffix
00045 //
00046    if (!HnameR) return 1;
00047    return !strcmp(hname+hnlen-HnamelenR, hname);
00048 }
00049 
00050 /******************************************************************************/
00051 /*                                   S e t                                    */
00052 /******************************************************************************/
00053   
00054 void XrdLinkMatch::Set(const char *target)
00055 {
00056    char *theast;
00057 
00058 // Free any existing target
00059 //
00060    if (!target || !strcmp(target, "*")) 
00061       {Uname = HnameL = HnameR = 0; 
00062        Unamelen = HnamelenL = HnamelenR = 0;
00063        return;
00064       }
00065    strlcpy(Buff, target, sizeof(Buff)-1);
00066    Uname = Buff;
00067 
00068 // Find the '@' as the pivot in this name
00069 //
00070    if (!(HnameL = index(Uname, '@')))
00071       {if ((Unamelen = strlen(Uname)))
00072           {if (Uname[Unamelen-1] == '*') Unamelen--;
00073               else if (index(Uname, ':')) Uname[Unamelen++] = '@';
00074                       else if (index(Uname, '.')) Uname[Unamelen++] = ':';
00075                            else Uname[Unamelen++] = '.';
00076           }
00077        HnameR = 0;
00078        return;
00079       }
00080 
00081 // We have a form of <string>@<string>
00082 //
00083    *HnameL++ = '\0';
00084    if ((Unamelen = strlen(Uname)))
00085       {if (Uname[Unamelen-1] == '*') Unamelen--;
00086           else if (index(Uname, ':')) Uname[Unamelen++] = '@';
00087                   else if (index(Uname, '.')) Uname[Unamelen++] = ':';
00088                        else Uname[Unamelen++] = '.';
00089       }
00090 
00091 // The post string may have an asterisk.
00092 //
00093    if (!(theast = index(HnameL, '*')))
00094       {HnamelenL = 0;
00095        HnameR    = 0;
00096        return;
00097       }
00098 
00099 // Indicate how much of the prefix should match
00100 //
00101    *theast = '\0';
00102    if (!(HnamelenL = strlen(HnameL))) HnameL = 0;
00103 
00104 // Indicate how much of the suffix should match
00105 //
00106    if ((HnamelenR = strlen(theast))) HnameR = theast+1;
00107       else HnameR = 0;
00108    Hnamelen = HnamelenL+HnamelenR;
00109 }

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