Browse code

dconf: added pcre options and pcre global dconf: fixed issue in module support report

Kevin Lin authored on 2014/09/17 00:20:39
Showing 3 changed files
... ...
@@ -137,6 +137,8 @@ static struct dconf_module modules[] = {
137 137
     { "STATS",      "PESECTION DISABLED", DCONF_STATS_PE_SECTION_DISABLED, 0 },
138 138
 
139 139
     { "PCRE",       "SUPPORT",      PCRE_CONF_SUPPORT,   1 },
140
+    { "PCRE",       "OPTIONS",      PCRE_CONF_OPTIONS,   1 },
141
+    { "PCRE",       "GLOBAL",       PCRE_CONF_GLOBAL,    1 },
140 142
 
141 143
     { NULL,     NULL,       0,              0 }
142 144
 };
... ...
@@ -303,7 +305,7 @@ void cli_dconf_print(struct cli_dconf *dconf)
303 303
         } else if (!strcmp(modules[i].mname, "PCRE")) {
304 304
             if (!pcre) {
305 305
                 cli_dbgmsg("Module PCRE %s\n", dconf->pcre ? "On" : "Off");
306
-                stats = 1;
306
+                pcre = 1;
307 307
             }
308 308
 
309 309
             if (dconf->pcre)
... ...
@@ -132,6 +132,8 @@ struct cli_dconf {
132 132
 
133 133
 /* PCRE flags */
134 134
 #define PCRE_CONF_SUPPORT 0x1
135
+#define PCRE_CONF_OPTIONS 0x2
136
+#define PCRE_CONF_GLOBAL  0x4
135 137
 
136 138
 #define BYTECODE_ENGINE_MASK (BYTECODE_INTERPRETER | BYTECODE_JIT_X86 | BYTECODE_JIT_PPC | BYTECODE_JIT_ARM)
137 139
 
... ...
@@ -210,15 +210,28 @@ int cli_pcre_addpatt(struct cli_matcher *root, const char *trigger, const char *
210 210
             return CL_ENULLARG;
211 211
         }
212 212
 
213
-        cli_dbgmsg("cli_pcre_build: Compiling regex: %s\n", pm->pdata.expression);
213
+        /* disable global */
214
+        if ((pm->flags & CLI_PCRE_GLOBAL) & !(dconf->pcre & PCRE_CONF_GLOBAL)) {
215
+            cli_dbgmsg("cli_pcre_build: disabling global option for regex /%s/\n", pm->pdata.expression);
216
+            pm->flags &= ~(CLI_PCRE_GLOBAL);
217
+        }
214 218
 
215 219
         /* options override through metadata manipulation */
216 220
         //pm->pdata.options |= PCRE_NEVER_UTF; /* implemented in 8.33, disables (?UTF*) */
217 221
         //pm->pdata.options |= PCRE_UCP;/* implemented in 8.20 */
218 222
         //pm->pdata.options |= PCRE_AUTO_CALLOUT; /* used with CALLOUT(-BACK) function */
219 223
 
220
-        /* parse the regex, no options override *wink* */
221
-        if ((ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 0)) != CL_SUCCESS) {
224
+        if (dconf->pcre & PCRE_CONF_OPTIONS) {
225
+            /* compile the regex, no options override *wink* */
226
+            cli_dbgmsg("cli_pcre_build: Compiling regex: /%s/\n", pm->pdata.expression);
227
+            ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 0);
228
+        }
229
+        else {
230
+            /* compile the regex, options overrided and disabled */
231
+            cli_dbgmsg("cli_pcre_build: Compiling regex: /%s/ (without options)\n", pm->pdata.expression);
232
+            ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 1);
233
+        }
234
+        if (ret != CL_SUCCESS) {
222 235
             cli_errmsg("cli_pcre_build: failed to build pcre regex\n");
223 236
             pm->flags |= CLI_PCRE_DISABLED; /* disable the pcre */
224 237
             return ret;