1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <regex.h>
20 #include "common.h"
21 #include <stdbool.h>
22 #include <string.h>
23 
24 bool
match_hash(const char * needle,const char * haystack)25 match_hash(const char *needle, const char *haystack)
26 {
27   return false;
28 }
29 
30 bool
match_regex(const char * pattern,const char * uri)31 match_regex(const char *pattern, const char *uri)
32 {
33   struct re_pattern_buffer pat_buff;
34 
35   pat_buff.translate = 0;
36   pat_buff.fastmap   = 0;
37   pat_buff.buffer    = 0;
38   pat_buff.allocated = 0;
39 
40   re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED;
41 
42   PluginDebug("Testing regex pattern /%s/ against \"%s\"", pattern, uri);
43 
44   const char *comp_err = re_compile_pattern(pattern, strlen(pattern), &pat_buff);
45 
46   if (comp_err) {
47     PluginDebug("Regex Compilation ERROR: %s", comp_err);
48     return false;
49   }
50 
51   int match_ret;
52   match_ret = re_match(&pat_buff, uri, strlen(uri), 0, 0);
53   regfree(&pat_buff);
54 
55   return match_ret >= 0;
56 }
57