mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
Adds support to regexp::searchAll
This commit is contained in:
parent
d3a4ec760c
commit
9c7988d88f
@ -21,6 +21,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -48,6 +49,7 @@ Regex::Regex(const std::string& pattern_)
|
|||||||
|
|
||||||
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
|
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
|
||||||
&errptr, &erroffset, NULL);
|
&errptr, &erroffset, NULL);
|
||||||
|
|
||||||
m_pce = pcre_study(m_pc, pcre_study_opt, &errptr);
|
m_pce = pcre_study(m_pc, pcre_study_opt, &errptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +70,30 @@ Regex::~Regex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::list<SMatch> Regex::searchAll(const std::string& s) {
|
||||||
|
int ovector[OVECCOUNT];
|
||||||
|
std::list<SMatch> retList;
|
||||||
|
int i;
|
||||||
|
const char *subject = s.c_str();
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = pcre_exec(m_pc, m_pce, subject,
|
||||||
|
s.size(), 0, 0, ovector, OVECCOUNT);
|
||||||
|
|
||||||
|
for (i = 0; i < rc; i++) {
|
||||||
|
SMatch match;
|
||||||
|
const char *substring_start = subject + ovector[2*i];
|
||||||
|
int substring_length = ovector[2*i+1] - ovector[2*i];
|
||||||
|
|
||||||
|
match.match = std::string(subject, ovector[2*i],
|
||||||
|
ovector[2*i+1] - ovector[2*i]);
|
||||||
|
|
||||||
|
retList.push_front(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retList;
|
||||||
|
}
|
||||||
|
|
||||||
int regex_search(const std::string& s, SMatch *match,
|
int regex_search(const std::string& s, SMatch *match,
|
||||||
const Regex& regex) {
|
const Regex& regex) {
|
||||||
int ovector[OVECCOUNT];
|
int ovector[OVECCOUNT];
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#ifndef SRC_UTILS_REGEX_H_
|
#ifndef SRC_UTILS_REGEX_H_
|
||||||
#define SRC_UTILS_REGEX_H_
|
#define SRC_UTILS_REGEX_H_
|
||||||
@ -28,6 +29,16 @@ namespace Utils {
|
|||||||
|
|
||||||
#define OVECCOUNT 30
|
#define OVECCOUNT 30
|
||||||
|
|
||||||
|
class SMatch {
|
||||||
|
public:
|
||||||
|
SMatch() : size_(0) { }
|
||||||
|
size_t size() const { return size_; }
|
||||||
|
std::string str() const { return match; }
|
||||||
|
int size_;
|
||||||
|
std::string match;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Regex {
|
class Regex {
|
||||||
public:
|
public:
|
||||||
explicit Regex(const std::string& pattern_);
|
explicit Regex(const std::string& pattern_);
|
||||||
@ -36,16 +47,8 @@ class Regex {
|
|||||||
pcre *m_pc = NULL;
|
pcre *m_pc = NULL;
|
||||||
pcre_extra *m_pce = NULL;
|
pcre_extra *m_pce = NULL;
|
||||||
int m_ovector[OVECCOUNT];
|
int m_ovector[OVECCOUNT];
|
||||||
};
|
|
||||||
|
|
||||||
|
std::list<SMatch> searchAll(const std::string& s);
|
||||||
class SMatch {
|
|
||||||
public:
|
|
||||||
SMatch() : size_(0) { }
|
|
||||||
size_t size() const { return size_; }
|
|
||||||
std::string str() const { return match; }
|
|
||||||
int size_;
|
|
||||||
std::string match;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user