+/* Return 1 is STRING (case-insensitively) matches PATTERN, 0
+ otherwise. The recognized wildcard character is "*", which matches
+ any character in STRING except ".". Any number of the "*" wildcard
+ may be present in the pattern.
+
+ This is used to match of hosts as indicated in rfc2818: "Names may
+ contain the wildcard character * which is considered to match any
+ single domain name component or component fragment. E.g., *.a.com
+ matches foo.a.com but not bar.foo.a.com. f*.com matches foo.com but
+ not bar.com." */
+
+static int
+pattern_match (const char *pattern, const char *string)
+{
+ const char *p = pattern, *n = string;
+ char c;
+ for (; (c = TOLOWER (*p++)) != '\0'; n++)
+ if (c == '*')
+ {
+ for (c = TOLOWER (*p); c == '*'; c = TOLOWER (*++p))
+ ;
+ for (; *n != '\0'; n++)
+ if (TOLOWER (*n) == c && pattern_match (p, n))
+ return 1;
+ else if (*n == '.')
+ return 0;
+ return c == '\0';
+ }
+ else
+ {
+ if (c != TOLOWER (*n))
+ return 0;
+ }
+ return *n == '\0';
+}
+