static int http_replace_header(struct my_regex *re, char *dst, uint dst_size, char *val, int len,
const char *rep_str)
{
- if (!regex_exec_match2(re, val, len, MAX_MATCH, pmatch))
+ if (!regex_exec_match2(re, val, len, MAX_MATCH, pmatch, 0))
return -2;
return exp_replace(dst, dst_size, val, rep_str, pmatch);
while (p_delim < p + len && *p_delim != delim)
p_delim++;
- if (regex_exec_match2(re, p, p_delim-p, MAX_MATCH, pmatch)) {
+ if (regex_exec_match2(re, p, p_delim-p, MAX_MATCH, pmatch, 0)) {
int replace_n = exp_replace(dst_p, dst_end - dst_p, p, rep_str, pmatch);
if (replace_n < 0)
* and the next header starts at cur_next.
*/
- if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) {
+ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_SETBE:
/* It is not possible to jump a second time.
/* Now we have the request line between cur_ptr and cur_end */
- if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) {
+ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_SETBE:
/* It is not possible to jump a second time.
* and the next header starts at cur_next.
*/
- if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) {
+ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_ALLOW:
txn->flags |= TX_SVALLOW;
/* Now we have the status line between cur_ptr and cur_end */
- if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch)) {
+ if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_ALLOW:
txn->flags |= TX_SVALLOW;
/* This function apply regex. It take const null terminated char as input.
* If the function doesn't match, it returns false, else it returns true.
* When it is compiled with JIT, this function execute strlen on the subject.
+ * Currently the only supported flag is REG_NOTBOL.
*/
int regex_exec_match(const struct my_regex *preg, const char *subject,
- size_t nmatch, regmatch_t pmatch[]) {
+ size_t nmatch, regmatch_t pmatch[], int flags) {
#if defined(USE_PCRE) || defined(USE_PCRE_JIT)
int ret;
int matches[MAX_MATCH * 3];
int enmatch;
int i;
+ int options;
/* Silently limit the number of allowed matches. max
* match i the maximum value for match, in fact this
if (enmatch > MAX_MATCH)
enmatch = MAX_MATCH;
+ options = 0;
+ if (flags & REG_NOTBOL)
+ options |= PCRE_NOTBOL;
+
/* The value returned by pcre_exec() is one more than the highest numbered
* pair that has been set. For example, if two substrings have been captured,
* the returned value is 3. If there are no capturing subpatterns, the return
* It seems that this function returns 0 if it detect more matches than avalaible
* space in the matches array.
*/
- ret = pcre_exec(preg->reg, preg->extra, subject, strlen(subject), 0, 0, matches, enmatch * 3);
+ ret = pcre_exec(preg->reg, preg->extra, subject, strlen(subject), 0, options, matches, enmatch * 3);
if (ret < 0)
return 0;
return 1;
#else
int match;
- match = regexec(&preg->regex, subject, nmatch, pmatch, 0);
+
+ flags &= REG_NOTBOL;
+ match = regexec(&preg->regex, subject, nmatch, pmatch, flags);
if (match == REG_NOMATCH)
return 0;
return 1;
* match, it returns false, else it returns true.
* When it is compiled with standard POSIX regex or PCRE, this function add
* a temporary null chracters at the end of the <subject>. The <subject> must
- * have a real length of <length> + 1.
+ * have a real length of <length> + 1. Currently the only supported flag is
+ * REG_NOTBOL.
*/
int regex_exec_match2(const struct my_regex *preg, char *subject, int length,
- size_t nmatch, regmatch_t pmatch[]) {
+ size_t nmatch, regmatch_t pmatch[], int flags) {
#if defined(USE_PCRE) || defined(USE_PCRE_JIT)
int ret;
int matches[MAX_MATCH * 3];
int enmatch;
int i;
+ int options;
/* Silently limit the number of allowed matches. max
* match i the maximum value for match, in fact this
if (enmatch > MAX_MATCH)
enmatch = MAX_MATCH;
+ options = 0;
+ if (flags & REG_NOTBOL)
+ options |= PCRE_NOTBOL;
+
/* The value returned by pcre_exec() is one more than the highest numbered
* pair that has been set. For example, if two substrings have been captured,
* the returned value is 3. If there are no capturing subpatterns, the return
* It seems that this function returns 0 if it detect more matches than avalaible
* space in the matches array.
*/
- ret = pcre_exec(preg->reg, preg->extra, subject, length, 0, 0, matches, enmatch * 3);
+ ret = pcre_exec(preg->reg, preg->extra, subject, length, 0, options, matches, enmatch * 3);
if (ret < 0)
return 0;
#else
char old_char = subject[length];
int match;
+
+ flags &= REG_NOTBOL;
subject[length] = 0;
- match = regexec(&preg->regex, subject, nmatch, pmatch, 0);
+ match = regexec(&preg->regex, subject, nmatch, pmatch, flags);
subject[length] = old_char;
if (match == REG_NOMATCH)
return 0;