コード例 #1
0
 /// <summary>
 /// Checks whether 'host' matches pattern 'tok'
 /// </summary>
 /// <param name="host">hostname</param>
 /// <param name="tok">pattern</param>
 /// <returns>True if matched</returns>
 protected bool MatchHostname(string host, string tok)
 {
     if (host == null)
     {
         return(false);
     }
     return(WildMatch.CheckWildMatch(tok, host));
 }
コード例 #2
0
        static bool CheckOneExclude(string name, ExcludeStruct ex, int nameIsDir)
        {
            int    match_start = 0;
            string pattern     = ex.pattern;

            if (name.CompareTo(String.Empty) == 0)
            {
                return(false);
            }
            if (pattern.CompareTo(String.Empty) == 0)
            {
                return(false);
            }

            if (0 != (ex.matchFlags & Options.MATCHFLG_DIRECTORY) && nameIsDir == 0)
            {
                return(false);
            }

            if (pattern[0] == '/')
            {
                match_start = 1;
                pattern     = pattern.TrimStart('/');
                if (name[0] == '/')
                {
                    name = name.TrimStart('/');
                }
            }

            if ((ex.matchFlags & Options.MATCHFLG_WILD) != 0)
            {
                /* A non-anchored match with an infix slash and no "**"
                * needs to match the last slash_cnt+1 name elements. */
                if (match_start != 0 && ex.slashCnt != 0 && 0 == (ex.matchFlags & Options.MATCHFLG_WILD2))
                {
                    name = name.Substring(name.IndexOf('/') + 1);
                }
                if (WildMatch.CheckWildMatch(pattern, name))
                {
                    return(true);
                }
                if ((ex.matchFlags & Options.MATCHFLG_WILD2_PREFIX) != 0)
                {
                    /* If the **-prefixed pattern has a '/' as the next
                     * character, then try to match the rest of the
                     * pattern at the root. */
                    if (pattern[2] == '/' && WildMatch.CheckWildMatch(pattern.Substring(3), name))
                    {
                        return(true);
                    }
                }
                else if (0 == match_start && (ex.matchFlags & Options.MATCHFLG_WILD2) != 0)
                {
                    /* A non-anchored match with an infix or trailing "**"
                     * (but not a prefixed "**") needs to try matching
                     * after every slash. */
                    int posSlash;
                    while ((posSlash = name.IndexOf('/')) != -1)
                    {
                        name = name.Substring(posSlash + 1);
                        if (WildMatch.CheckWildMatch(pattern, name))
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (match_start != 0)
            {
                if (name.CompareTo(pattern) == 0)
                {
                    return(true);
                }
            }
            else
            {
                int l1 = name.Length;
                int l2 = pattern.Length;
                if (l2 <= l1 &&
                    name.Substring(l1 - l2).CompareTo(pattern) == 0 &&
                    (l1 == l2 || name[l1 - (l2 + 1)] == '/'))
                {
                    return(true);
                }
            }

            return(false);
        }