1 | /* |
1 | /* |
2 | * match.C: Casemapping and matching functions. |
2 | * match.C: Casemapping and matching functions. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 | */ |
6 | */ |
7 | |
7 | |
8 | static char const rcsid[] = "$Id: match.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: match.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
11 | |
11 | |
12 | #define BadPtr(x) (!(x) || (*(x) == '\0')) |
12 | #define BadPtr(x) (!(x) || (*(x) == '\0')) |
13 | |
13 | |
… | |
… | |
122 | ** Iterative matching function, rather than recursive. |
122 | ** Iterative matching function, rather than recursive. |
123 | ** Written by Douglas A Lewis (dalewis@acsu.buffalo.edu) |
123 | ** Written by Douglas A Lewis (dalewis@acsu.buffalo.edu) |
124 | */ |
124 | */ |
125 | |
125 | |
126 | int |
126 | int |
127 | match (const char *mask, const char *name) |
127 | match (char const * const mask, char const * const name) |
128 | { |
128 | { |
129 | const u_char *m = (const u_char *) mask, *n = (const u_char *) name; |
129 | const u_char *m = (const u_char *) mask, *n = (const u_char *) name; |
130 | const char *ma = mask, *na = name; |
130 | char const *ma = mask, *na = name; |
131 | int wild = 0, q = 0, calls = 0; |
131 | int wild = 0, q = 0, calls = 0; |
132 | |
132 | |
133 | if (!mask || !name) |
133 | if (!mask || !name) |
134 | return 1; |
134 | return 1; |
135 | |
135 | |
… | |
… | |
147 | if (*m == '*') |
147 | if (*m == '*') |
148 | { |
148 | { |
149 | while (*m == '*') |
149 | while (*m == '*') |
150 | m++; |
150 | m++; |
151 | wild = 1; |
151 | wild = 1; |
152 | ma = (const char *) m; |
152 | ma = reinterpret_cast<char const *> (m); |
153 | na = (const char *) n; |
153 | na = reinterpret_cast<char const *> (n); |
154 | } |
154 | } |
155 | |
155 | |
156 | if (!*m) |
156 | if (!*m) |
157 | { |
157 | { |
158 | if (!*n) |
158 | if (!*n) |
… | |
… | |
238 | ** returns 0, if s1 equal to s2 |
238 | ** returns 0, if s1 equal to s2 |
239 | ** <0, if s1 lexicographically less than s2 |
239 | ** <0, if s1 lexicographically less than s2 |
240 | ** >0, if s1 lexicographically greater than s2 |
240 | ** >0, if s1 lexicographically greater than s2 |
241 | */ |
241 | */ |
242 | int |
242 | int |
243 | irccasecmp (const char *s1, const char *s2) |
243 | irccasecmp (char const * const s1, char const * const s2) |
244 | { |
244 | { |
245 | const unsigned char *str1 = (const unsigned char *) s1; |
245 | const unsigned char *str1 = (const unsigned char *) s1; |
246 | const unsigned char *str2 = (const unsigned char *) s2; |
246 | const unsigned char *str2 = (const unsigned char *) s2; |
247 | int res; |
247 | int res; |
248 | |
248 | |
… | |
… | |
261 | } |
261 | } |
262 | return (res); |
262 | return (res); |
263 | } |
263 | } |
264 | |
264 | |
265 | int |
265 | int |
266 | ircncasecmp (const char *str1, const char *str2, int n) |
266 | ircncasecmp (char const * const str1, char const * const str2, int n) |
267 | { |
267 | { |
268 | const unsigned char *s1 = (const unsigned char *) str1; |
268 | const unsigned char *s1 = (const unsigned char *) str1; |
269 | const unsigned char *s2 = (const unsigned char *) str2; |
269 | const unsigned char *s2 = (const unsigned char *) str2; |
270 | int res; |
270 | int res; |
271 | |
271 | |
… | |
… | |
556 | if (pattern == NULL) |
556 | if (pattern == NULL) |
557 | { |
557 | { |
558 | return NULL; |
558 | return NULL; |
559 | } |
559 | } |
560 | |
560 | |
561 | preg = (regex_t *) malloc (sizeof (regex_t)); |
561 | preg = new regex_t; |
562 | errnum = regcomp (preg, pattern, (flags & AREGEX_ICASE ? REG_ICASE : 0) | REG_EXTENDED); |
562 | errnum = regcomp (preg, pattern, (flags & AREGEX_ICASE ? REG_ICASE : 0) | REG_EXTENDED); |
563 | |
563 | |
564 | if (errnum != 0) |
564 | if (errnum != 0) |
565 | { |
565 | { |
566 | regerror (errnum, preg, errmsg, BUFSIZE); |
566 | regerror (errnum, preg, errmsg, BUFSIZE); |
567 | slog (LG_ERROR, "regex_match(): %s\n", errmsg); |
567 | slog (LG_ERROR, "regex_match(): %s\n", errmsg); |
568 | regfree (preg); |
568 | regfree (preg); |
569 | free (preg); |
569 | delete preg; |
570 | return NULL; |
570 | return NULL; |
571 | } |
571 | } |
572 | |
572 | |
573 | return preg; |
573 | return preg; |
574 | } |
574 | } |
… | |
… | |
639 | */ |
639 | */ |
640 | bool |
640 | bool |
641 | regex_destroy (regex_t * preg) |
641 | regex_destroy (regex_t * preg) |
642 | { |
642 | { |
643 | regfree (preg); |
643 | regfree (preg); |
644 | free (preg); |
644 | delete preg; |
645 | return true; |
645 | return true; |
646 | } |
646 | } |
647 | |
|
|
648 | /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
|
|
649 | * vim:ts=8 |
|
|
650 | * vim:sw=8 |
|
|
651 | * vim:noexpandtab |
|
|
652 | */ |
|
|