ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/match.C
Revision: 1.5
Committed: Sun Sep 16 18:54:45 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +7 -2 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * match.C: Casemapping and matching functions.
3 pippijn 1.5 *
4     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5     * Rights to this code are as documented in COPYING.
6     *
7     *
8     * Portions of this file were derived from sources bearing the following license:
9 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
10 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 pippijn 1.1 */
12    
13 pippijn 1.5 static char const rcsid[] = "$Id: match.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
14 pippijn 1.1
15     #include "atheme.h"
16    
17     #define BadPtr(x) (!(x) || (*(x) == '\0'))
18    
19     int match_mapping = MATCH_RFC1459;
20    
21     const unsigned char ToLowerTab[] = {
22     0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
23     0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
24     0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
25     0x1e, 0x1f,
26     ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')',
27     '*', '+', ',', '-', '.', '/',
28     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
29     ':', ';', '<', '=', '>', '?',
30     '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
31     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
32     't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
33     '_',
34     '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
35     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
36     't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
37     0x7f,
38     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
39     0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
40     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
41     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
42     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
43     0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
44     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
45     0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
46     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
47     0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
48     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
49     0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
50     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
51     0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
52     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
53     0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
54     };
55    
56     const unsigned char ToUpperTab[] = {
57     0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
58     0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
59     0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
60     0x1e, 0x1f,
61     ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')',
62     '*', '+', ',', '-', '.', '/',
63     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
64     ':', ';', '<', '=', '>', '?',
65     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
66     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
67     'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^',
68     0x5f,
69     '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
70     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
71     'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^',
72     0x7f,
73     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
74     0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
75     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
76     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
77     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
78     0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
79     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
80     0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
81     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
82     0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
83     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
84     0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
85     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
86     0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
87     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
88     0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
89     };
90    
91     int
92     ToLower (int c)
93     {
94     if (match_mapping == MATCH_ASCII)
95     return tolower (c);
96     /* else */
97     return (ToLowerTab[(unsigned char) (c)]);
98     }
99    
100     int
101     ToUpper (int c)
102     {
103     if (match_mapping == MATCH_ASCII)
104     return toupper (c);
105     /* else */
106     return (ToUpperTab[(unsigned char) (c)]);
107     }
108    
109     void
110     set_match_mapping (int type)
111     {
112     match_mapping = type;
113     }
114    
115     #define MAX_ITERATIONS 512
116     /*
117     ** Compare if a given string (name) matches the given
118     ** mask (which can contain wild cards: '*' - match any
119     ** number of chars, '?' - match any single character.
120     **
121     ** return 0, if match
122     ** 1, if no match
123     */
124    
125     /*
126     ** match()
127     ** Iterative matching function, rather than recursive.
128     ** Written by Douglas A Lewis (dalewis@acsu.buffalo.edu)
129     */
130    
131     int
132 pippijn 1.4 match (char const * const mask, char const * const name)
133 pippijn 1.1 {
134     const u_char *m = (const u_char *) mask, *n = (const u_char *) name;
135 pippijn 1.4 char const *ma = mask, *na = name;
136 pippijn 1.1 int wild = 0, q = 0, calls = 0;
137    
138     if (!mask || !name)
139     return 1;
140    
141     /* if the mask is "*", it matches everything */
142     if ((*m == '*') && (*(m + 1) == '\0'))
143     return 0;
144    
145     while (1)
146     {
147     #ifdef MAX_ITERATIONS
148     if (calls++ > MAX_ITERATIONS)
149     break;
150     #endif
151    
152     if (*m == '*')
153     {
154     while (*m == '*')
155     m++;
156     wild = 1;
157 pippijn 1.4 ma = reinterpret_cast<char const *> (m);
158     na = reinterpret_cast<char const *> (n);
159 pippijn 1.1 }
160    
161     if (!*m)
162     {
163     if (!*n)
164     return 0;
165     for (m--; (m > (const u_char *) mask) && (*m == '?' || *m == '&' || *m == '#'); m--)
166     ;
167     if ((m > (const u_char *) mask) && (*m == '*') && (m[-1] != '\\'))
168     return 0;
169     if (!wild)
170     return 1;
171     m = (const u_char *) ma;
172     n = (const u_char *) ++na;
173     }
174     else if (!*n)
175     return 1;
176     if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?') || (m[1] == '&') || (m[1] == '#') || (m[1] == '%')))
177     {
178     m++;
179     q = 1;
180     }
181     else
182     q = 0;
183    
184     if ((ToLower (*m) != ToLower (*n)) && (((*m != '?') && !(*m == '&' && IsAlpha (*n)) && !(*m == '#' && IsDigit (*n)) && !(*m == '%' && IsNon (*n))) || q))
185     {
186     if (!wild)
187     return 1;
188     m = (const u_char *) ma;
189     n = (const u_char *) ++na;
190     }
191     else
192     {
193     if (*m)
194     m++;
195     if (*n)
196     n++;
197     }
198     }
199    
200     return 1;
201     }
202    
203    
204     /*
205     ** collapse a pattern string into minimal components.
206     ** This particular version is "in place", so that it changes the pattern
207     ** which is to be reduced to a "minimal" size.
208     */
209     char *
210     collapse (char *pattern)
211     {
212     char *s = pattern, *s1, *t;
213    
214     if (BadPtr (pattern))
215     return pattern;
216     /*
217     * Collapse all \** into \*, \*[?]+\** into \*[?]+
218     */
219     for (; *s; s++)
220     if (*s == '\\')
221     if (!*(s + 1))
222     break;
223     else
224     s++;
225     else if (*s == '*')
226     {
227     if (*(t = s1 = s + 1) == '*')
228     while (*t == '*')
229     t++;
230     else if (*t == '?')
231     for (t++, s1++; *t == '*' || *t == '?'; t++)
232     if (*t == '?')
233     *s1++ = *t;
234     while ((*s1++ = *t++))
235     ;
236     }
237     return pattern;
238     }
239    
240     /*
241     ** Case insensitive comparison of two null terminated strings.
242     **
243     ** returns 0, if s1 equal to s2
244     ** <0, if s1 lexicographically less than s2
245     ** >0, if s1 lexicographically greater than s2
246     */
247     int
248 pippijn 1.4 irccasecmp (char const * const s1, char const * const s2)
249 pippijn 1.1 {
250     const unsigned char *str1 = (const unsigned char *) s1;
251     const unsigned char *str2 = (const unsigned char *) s2;
252     int res;
253    
254     if (!s1 || !s2)
255     return -1;
256    
257     if (match_mapping == MATCH_ASCII)
258     return strcasecmp (s1, s2);
259    
260     while ((res = ToUpper (*str1) - ToUpper (*str2)) == 0)
261     {
262     if (*str1 == '\0')
263     return 0;
264     str1++;
265     str2++;
266     }
267     return (res);
268     }
269    
270     int
271 pippijn 1.4 ircncasecmp (char const * const str1, char const * const str2, int n)
272 pippijn 1.1 {
273     const unsigned char *s1 = (const unsigned char *) str1;
274     const unsigned char *s2 = (const unsigned char *) str2;
275     int res;
276    
277     if (match_mapping == MATCH_ASCII)
278     return strncasecmp (str1, str2, n);
279    
280     while ((res = ToUpper (*s1) - ToUpper (*s2)) == 0)
281     {
282     s1++;
283     s2++;
284     n--;
285     if (n == 0 || (*s1 == '\0' && *s2 == '\0'))
286     return 0;
287     }
288     return (res);
289     }
290    
291     const unsigned int charattrs[] = {
292     /* 0 */ 0,
293     /* 1 */ 0,
294     /* 2 */ 0,
295     /* 3 */ 0,
296     /* 4 */ 0,
297     /* 5 */ 0,
298     /* 6 */ 0,
299     /* 7 BEL */ 0,
300     /* 8 \b */ 0,
301     /* 9 \t */ 0,
302     /* 10 \n */ 0,
303     /* 11 \v */ 0,
304     /* 12 \f */ 0,
305     /* 13 \r */ 0,
306     /* 14 */ 0,
307     /* 15 */ 0,
308     /* 16 */ 0,
309     /* 17 */ 0,
310     /* 18 */ 0,
311     /* 19 */ 0,
312     /* 20 */ 0,
313     /* 21 */ 0,
314     /* 22 */ 0,
315     /* 23 */ 0,
316     /* 24 */ 0,
317     /* 25 */ 0,
318     /* 26 */ 0,
319     /* 27 */ 0,
320     /* 28 */ 0,
321     /* 29 */ 0,
322     /* 30 */ 0,
323     /* 31 */ 0,
324     /* SP */ 0,
325     /* ! */ 0,
326     /* " */ 0,
327     /* # */ 0,
328     /* $ */ 0,
329     /* % */ 0,
330     /* & */ 0,
331     /* ' */ 0,
332     /* ( */ 0,
333     /* ) */ 0,
334     /* * */ 0,
335     /* + */ 0,
336     /* , */ 0,
337     /* - */ 0,
338     /* . */ 0,
339     /* / */ 0,
340     /* 0 */ C_DIGIT,
341     /* 1 */ C_DIGIT,
342     /* 2 */ C_DIGIT,
343     /* 3 */ C_DIGIT,
344     /* 4 */ C_DIGIT,
345     /* 5 */ C_DIGIT,
346     /* 6 */ C_DIGIT,
347     /* 7 */ C_DIGIT,
348     /* 8 */ C_DIGIT,
349     /* 9 */ C_DIGIT,
350     /* : */ 0,
351     /* ; */ 0,
352     /* < */ 0,
353     /* = */ 0,
354     /* > */ 0,
355     /* ? */ 0,
356     /* @ */ 0,
357     /* A */ C_ALPHA,
358     /* B */ C_ALPHA,
359     /* C */ C_ALPHA,
360     /* D */ C_ALPHA,
361     /* E */ C_ALPHA,
362     /* F */ C_ALPHA,
363     /* G */ C_ALPHA,
364     /* H */ C_ALPHA,
365     /* I */ C_ALPHA,
366     /* J */ C_ALPHA,
367     /* K */ C_ALPHA,
368     /* L */ C_ALPHA,
369     /* M */ C_ALPHA,
370     /* N */ C_ALPHA,
371     /* O */ C_ALPHA,
372     /* P */ C_ALPHA,
373     /* Q */ C_ALPHA,
374     /* R */ C_ALPHA,
375     /* S */ C_ALPHA,
376     /* T */ C_ALPHA,
377     /* U */ C_ALPHA,
378     /* V */ C_ALPHA,
379     /* W */ C_ALPHA,
380     /* X */ C_ALPHA,
381     /* Y */ C_ALPHA,
382     /* Z */ C_ALPHA,
383     /* [ */ 0,
384     /* \ */ 0,
385     /* ] */ 0,
386     /* ^ */ 0,
387     /* _ */ 0,
388     /* ` */ 0,
389     /* a */ C_ALPHA,
390     /* b */ C_ALPHA,
391     /* c */ C_ALPHA,
392     /* d */ C_ALPHA,
393     /* e */ C_ALPHA,
394     /* f */ C_ALPHA,
395     /* g */ C_ALPHA,
396     /* h */ C_ALPHA,
397     /* i */ C_ALPHA,
398     /* j */ C_ALPHA,
399     /* k */ C_ALPHA,
400     /* l */ C_ALPHA,
401     /* m */ C_ALPHA,
402     /* n */ C_ALPHA,
403     /* o */ C_ALPHA,
404     /* p */ C_ALPHA,
405     /* q */ C_ALPHA,
406     /* r */ C_ALPHA,
407     /* s */ C_ALPHA,
408     /* t */ C_ALPHA,
409     /* u */ C_ALPHA,
410     /* v */ C_ALPHA,
411     /* w */ C_ALPHA,
412     /* x */ C_ALPHA,
413     /* y */ C_ALPHA,
414     /* z */ C_ALPHA,
415     /* { */ 0,
416     /* | */ 0,
417     /* } */ 0,
418     /* ~ */ 0,
419     /* del */ 0,
420     /* 0x80 */ 0,
421     /* 0x81 */ 0,
422     /* 0x82 */ 0,
423     /* 0x83 */ 0,
424     /* 0x84 */ 0,
425     /* 0x85 */ 0,
426     /* 0x86 */ 0,
427     /* 0x87 */ 0,
428     /* 0x88 */ 0,
429     /* 0x89 */ 0,
430     /* 0x8A */ 0,
431     /* 0x8B */ 0,
432     /* 0x8C */ 0,
433     /* 0x8D */ 0,
434     /* 0x8E */ 0,
435     /* 0x8F */ 0,
436     /* 0x90 */ 0,
437     /* 0x91 */ 0,
438     /* 0x92 */ 0,
439     /* 0x93 */ 0,
440     /* 0x94 */ 0,
441     /* 0x95 */ 0,
442     /* 0x96 */ 0,
443     /* 0x97 */ 0,
444     /* 0x98 */ 0,
445     /* 0x99 */ 0,
446     /* 0x9A */ 0,
447     /* 0x9B */ 0,
448     /* 0x9C */ 0,
449     /* 0x9D */ 0,
450     /* 0x9E */ 0,
451     /* 0x9F */ 0,
452     /* 0xA0 */ 0,
453     /* 0xA1 */ 0,
454     /* 0xA2 */ 0,
455     /* 0xA3 */ 0,
456     /* 0xA4 */ 0,
457     /* 0xA5 */ 0,
458     /* 0xA6 */ 0,
459     /* 0xA7 */ 0,
460     /* 0xA8 */ 0,
461     /* 0xA9 */ 0,
462     /* 0xAA */ 0,
463     /* 0xAB */ 0,
464     /* 0xAC */ 0,
465     /* 0xAD */ 0,
466     /* 0xAE */ 0,
467     /* 0xAF */ 0,
468     /* 0xB0 */ 0,
469     /* 0xB1 */ 0,
470     /* 0xB2 */ 0,
471     /* 0xB3 */ 0,
472     /* 0xB4 */ 0,
473     /* 0xB5 */ 0,
474     /* 0xB6 */ 0,
475     /* 0xB7 */ 0,
476     /* 0xB8 */ 0,
477     /* 0xB9 */ 0,
478     /* 0xBA */ 0,
479     /* 0xBB */ 0,
480     /* 0xBC */ 0,
481     /* 0xBD */ 0,
482     /* 0xBE */ 0,
483     /* 0xBF */ 0,
484     /* 0xC0 */ 0,
485     /* 0xC1 */ 0,
486     /* 0xC2 */ 0,
487     /* 0xC3 */ 0,
488     /* 0xC4 */ 0,
489     /* 0xC5 */ 0,
490     /* 0xC6 */ 0,
491     /* 0xC7 */ 0,
492     /* 0xC8 */ 0,
493     /* 0xC9 */ 0,
494     /* 0xCA */ 0,
495     /* 0xCB */ 0,
496     /* 0xCC */ 0,
497     /* 0xCD */ 0,
498     /* 0xCE */ 0,
499     /* 0xCF */ 0,
500     /* 0xD0 */ 0,
501     /* 0xD1 */ 0,
502     /* 0xD2 */ 0,
503     /* 0xD3 */ 0,
504     /* 0xD4 */ 0,
505     /* 0xD5 */ 0,
506     /* 0xD6 */ 0,
507     /* 0xD7 */ 0,
508     /* 0xD8 */ 0,
509     /* 0xD9 */ 0,
510     /* 0xDA */ 0,
511     /* 0xDB */ 0,
512     /* 0xDC */ 0,
513     /* 0xDD */ 0,
514     /* 0xDE */ 0,
515     /* 0xDF */ 0,
516     /* 0xE0 */ 0,
517     /* 0xE1 */ 0,
518     /* 0xE2 */ 0,
519     /* 0xE3 */ 0,
520     /* 0xE4 */ 0,
521     /* 0xE5 */ 0,
522     /* 0xE6 */ 0,
523     /* 0xE7 */ 0,
524     /* 0xE8 */ 0,
525     /* 0xE9 */ 0,
526     /* 0xEA */ 0,
527     /* 0xEB */ 0,
528     /* 0xEC */ 0,
529     /* 0xED */ 0,
530     /* 0xEE */ 0,
531     /* 0xEF */ 0,
532     /* 0xF0 */ 0,
533     /* 0xF1 */ 0,
534     /* 0xF2 */ 0,
535     /* 0xF3 */ 0,
536     /* 0xF4 */ 0,
537     /* 0xF5 */ 0,
538     /* 0xF6 */ 0,
539     /* 0xF7 */ 0,
540     /* 0xF8 */ 0,
541     /* 0xF9 */ 0,
542     /* 0xFA */ 0,
543     /* 0xFB */ 0,
544     /* 0xFC */ 0,
545     /* 0xFD */ 0,
546     /* 0xFE */ 0,
547     /* 0xFF */ 0,
548     };
549    
550     /*
551     * regex_compile()
552     * Compile a regex of `pattern' and return it.
553     */
554     regex_t *
555     regex_create (char *pattern, int flags)
556     {
557     static char errmsg[BUFSIZE];
558     int errnum;
559     regex_t *preg;
560    
561     if (pattern == NULL)
562     {
563     return NULL;
564     }
565    
566 pippijn 1.4 preg = new regex_t;
567 pippijn 1.1 errnum = regcomp (preg, pattern, (flags & AREGEX_ICASE ? REG_ICASE : 0) | REG_EXTENDED);
568    
569     if (errnum != 0)
570     {
571     regerror (errnum, preg, errmsg, BUFSIZE);
572     slog (LG_ERROR, "regex_match(): %s\n", errmsg);
573     regfree (preg);
574 pippijn 1.4 delete preg;
575 pippijn 1.1 return NULL;
576     }
577    
578     return preg;
579     }
580    
581     char *
582     regex_extract (char *pattern, char **pend, int *pflags)
583     {
584     char c, *p, *p2;
585     bool backslash = false;
586    
587     c = *pattern;
588     if (isalnum (c) || isspace (c) || c == '\\')
589     return NULL;
590     p = pattern + 1;
591     while (*p != c || backslash)
592     {
593     if (*p == '\0')
594     return NULL;
595     if (backslash || *p == '\\')
596     backslash = !backslash;
597     p++;
598     }
599     p2 = p;
600     p++;
601     *pflags = 0;
602     while (*p != '\0' && *p != ' ')
603     {
604     if (*p == 'i')
605     *pflags |= AREGEX_ICASE;
606     else if (!isalnum (*p))
607     return NULL;
608     p++;
609     }
610     *pend = p;
611     *p2 = '\0';
612     return pattern + 1;
613     }
614    
615     /*
616     * regex_match()
617     * Internal wrapper API for POSIX-based regex matching.
618     * `preg' is the regex to check with, `string' needs to be checked against.
619     * Returns `true' on match, `false' else.
620     */
621     bool
622     regex_match (regex_t * preg, char *string)
623     {
624     bool retval;
625    
626     if (preg == NULL || string == NULL)
627     {
628     slog (LG_ERROR, "regex_match(): we were given NULL string or pattern, bad!");
629     return false;
630     }
631    
632     /* match it */
633     if (regexec (preg, string, 0, NULL, 0) == 0)
634     retval = true;
635     else
636     retval = false;
637    
638     return retval;
639     }
640    
641     /*
642     * regex_destroy()
643     * Perform cleanup with regex `preg', free associated memory.
644     */
645     bool
646     regex_destroy (regex_t * preg)
647     {
648     regfree (preg);
649 pippijn 1.4 delete preg;
650 pippijn 1.1 return true;
651     }