aboutsummaryrefslogtreecommitdiffstats
path: root/main/coova-chilli/posix-regex.patch
blob: 73cb417e1838d2d575db56787566eaa820de27b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Index: src/garden.h
===================================================================
--- a/src/garden.h	(revision 492)
+++ b/src/garden.h	(working copy)
@@ -39,13 +39,18 @@
   (a)->port        == (b)->port)
 
 #ifdef ENABLE_CHILLIREDIR
+struct chilli_regex {
+  regex_t re;
+  char allocated:1;
+};
+
 typedef struct regex_pass_through_t {
   char regex_host[512];
   char regex_path[512];
   char regex_qs[512];
-  regex_t re_host;
-  regex_t re_path;
-  regex_t re_qs;
+  struct chilli_regex re_host;
+  struct chilli_regex re_path;
+  struct chilli_regex re_qs;
   char inuse:1;
   char neg_host:1;
   char neg_path:1;
Index: src/main-redir.c
===================================================================
--- a/src/main-redir.c	(revision 492)
+++ b/src/main-redir.c	(working copy)
@@ -503,7 +503,7 @@
 }
 
 static int
-check_regex(regex_t *re, char *regex, char *s) {
+check_regex(struct chilli_regex *re, char *regex, char *s) {
   int ret;
 
 #if(_debug_)
@@ -510,22 +510,19 @@
   log_dbg("Checking %s =~ %s", s, regex);
 #endif
 
-#if defined (__FreeBSD__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
-  if (!re->re_g)
-#else
-  if (!re->allocated) 
-#endif
+  if (!re->allocated)
   {
-    if ((ret = regcomp(re, regex, REG_EXTENDED | REG_NOSUB)) != 0) {
+    if ((ret = regcomp(&re->re, regex, REG_EXTENDED | REG_NOSUB)) != 0) {
       char error[512];
-      regerror(ret, re, error, sizeof(error));
+      regerror(ret, &re->re, error, sizeof(error));
       log_err(0, "regcomp(%s) failed (%s)", regex, error);
       regex[0] = 0;
       return -1;
     }
+    re->allocated = 1;
   }
   
-  if ((ret = regexec(re, s, 0, 0, 0)) == 0) {
+  if ((ret = regexec(&re->re, s, 0, 0, 0)) == 0) {
     
     log_dbg("Matched regex %s", regex);
     return 0;
Index: src/options.c
===================================================================
--- a/src/options.c	(revision 492)
+++ b/src/options.c	(working copy)
@@ -373,18 +373,12 @@
 
 #ifdef ENABLE_CHILLIREDIR
   for (i = 0; i < MAX_REGEX_PASS_THROUGHS; i++) {
-#if defined (__FreeBSD__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__)
-    regfree(&_options.regex_pass_throughs[i].re_host);
-    regfree(&_options.regex_pass_throughs[i].re_path);
-    regfree(&_options.regex_pass_throughs[i].re_qs);
-#else
     if (_options.regex_pass_throughs[i].re_host.allocated)
-      regfree(&_options.regex_pass_throughs[i].re_host);
+      regfree(&_options.regex_pass_throughs[i].re_host.re);
     if (_options.regex_pass_throughs[i].re_path.allocated)
-      regfree(&_options.regex_pass_throughs[i].re_path);
+      regfree(&_options.regex_pass_throughs[i].re_path.re);
     if (_options.regex_pass_throughs[i].re_qs.allocated)
-      regfree(&_options.regex_pass_throughs[i].re_qs);
-#endif
+      regfree(&_options.regex_pass_throughs[i].re_qs.re);
   }
 #endif