diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2001-12-06 18:06:05 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2001-12-06 18:06:05 +0000 |
commit | 9eab262f1ce2e54f7e5d2b75477a606c33e8bc0a (patch) | |
tree | f60cdd6fb8816d62cc91209f16094bcb159f4fe6 /match.c | |
parent | ff4a14f809fc581bed0cd0ff7dd1dc5d5508944c (diff) |
- markus@cvs.openbsd.org 2001/12/05 16:54:51
[compat.c match.c match.h]
make theo and djm happy: bye bye regexp
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -35,7 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | RCSID("$OpenBSD: match.c,v 1.14 2001/06/27 04:48:53 markus Exp $"); | 38 | RCSID("$OpenBSD: match.c,v 1.15 2001/12/05 16:54:51 markus Exp $"); |
39 | 39 | ||
40 | #include "match.h" | 40 | #include "match.h" |
41 | #include "xmalloc.h" | 41 | #include "xmalloc.h" |
@@ -104,14 +104,15 @@ match_pattern(const char *s, const char *pattern) | |||
104 | } | 104 | } |
105 | 105 | ||
106 | /* | 106 | /* |
107 | * Tries to match the host name (which must be in all lowercase) against the | 107 | * Tries to match the string against the |
108 | * comma-separated sequence of subpatterns (each possibly preceded by ! to | 108 | * comma-separated sequence of subpatterns (each possibly preceded by ! to |
109 | * indicate negation). Returns -1 if negation matches, 1 if there is | 109 | * indicate negation). Returns -1 if negation matches, 1 if there is |
110 | * a positive match, 0 if there is no match at all. | 110 | * a positive match, 0 if there is no match at all. |
111 | */ | 111 | */ |
112 | 112 | ||
113 | int | 113 | int |
114 | match_hostname(const char *host, const char *pattern, u_int len) | 114 | match_pattern_list(const char *string, const char *pattern, u_int len, |
115 | int dolower) | ||
115 | { | 116 | { |
116 | char sub[1024]; | 117 | char sub[1024]; |
117 | int negated; | 118 | int negated; |
@@ -134,7 +135,8 @@ match_hostname(const char *host, const char *pattern, u_int len) | |||
134 | for (subi = 0; | 135 | for (subi = 0; |
135 | i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; | 136 | i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; |
136 | subi++, i++) | 137 | subi++, i++) |
137 | sub[subi] = isupper(pattern[i]) ? tolower(pattern[i]) : pattern[i]; | 138 | sub[subi] = dolower && isupper(pattern[i]) ? |
139 | tolower(pattern[i]) : pattern[i]; | ||
138 | /* If subpattern too long, return failure (no match). */ | 140 | /* If subpattern too long, return failure (no match). */ |
139 | if (subi >= sizeof(sub) - 1) | 141 | if (subi >= sizeof(sub) - 1) |
140 | return 0; | 142 | return 0; |
@@ -146,8 +148,8 @@ match_hostname(const char *host, const char *pattern, u_int len) | |||
146 | /* Null-terminate the subpattern. */ | 148 | /* Null-terminate the subpattern. */ |
147 | sub[subi] = '\0'; | 149 | sub[subi] = '\0'; |
148 | 150 | ||
149 | /* Try to match the subpattern against the host name. */ | 151 | /* Try to match the subpattern against the string. */ |
150 | if (match_pattern(host, sub)) { | 152 | if (match_pattern(string, sub)) { |
151 | if (negated) | 153 | if (negated) |
152 | return -1; /* Negative */ | 154 | return -1; /* Negative */ |
153 | else | 155 | else |
@@ -163,6 +165,18 @@ match_hostname(const char *host, const char *pattern, u_int len) | |||
163 | } | 165 | } |
164 | 166 | ||
165 | /* | 167 | /* |
168 | * Tries to match the host name (which must be in all lowercase) against the | ||
169 | * comma-separated sequence of subpatterns (each possibly preceded by ! to | ||
170 | * indicate negation). Returns -1 if negation matches, 1 if there is | ||
171 | * a positive match, 0 if there is no match at all. | ||
172 | */ | ||
173 | int | ||
174 | match_hostname(const char *host, const char *pattern, u_int len) | ||
175 | { | ||
176 | return match_pattern_list(host, pattern, len, 1); | ||
177 | } | ||
178 | |||
179 | /* | ||
166 | * returns 0 if we get a negative match for the hostname or the ip | 180 | * returns 0 if we get a negative match for the hostname or the ip |
167 | * or if we get no match at all. returns 1 otherwise. | 181 | * or if we get no match at all. returns 1 otherwise. |
168 | */ | 182 | */ |