mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ESP8266WebServer - UriRegex runtime logic within assert() (#9185)
This commit is contained in:
parent
bb3360d0ec
commit
ccea72823a
@ -2,8 +2,9 @@
|
||||
#define URI_REGEX_H
|
||||
|
||||
#include "Uri.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <regex.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef REGEX_MAX_GROUPS
|
||||
#define REGEX_MAX_GROUPS 10
|
||||
@ -12,13 +13,20 @@
|
||||
class UriRegex : public Uri {
|
||||
|
||||
private:
|
||||
regex_t _regexCompiled;
|
||||
regex_t _regexCompiled{};
|
||||
int _regexErr{REG_EMPTY};
|
||||
|
||||
public:
|
||||
explicit UriRegex(const char *uri) : Uri(uri) {
|
||||
assert(regcomp(&_regexCompiled, uri, REG_EXTENDED) == 0);
|
||||
};
|
||||
explicit UriRegex(const String &uri) : UriRegex(uri.c_str()) {};
|
||||
UriRegex() = delete;
|
||||
|
||||
explicit UriRegex(const char *uri) :
|
||||
Uri(uri),
|
||||
_regexErr(regcomp(&_regexCompiled, uri, REG_EXTENDED))
|
||||
{
|
||||
assert(_regexErr == 0);
|
||||
}
|
||||
|
||||
explicit UriRegex(const String &uri) : UriRegex(uri.c_str()) {}
|
||||
|
||||
~UriRegex() {
|
||||
regfree(&_regexCompiled);
|
||||
@ -26,15 +34,17 @@ class UriRegex : public Uri {
|
||||
|
||||
Uri* clone() const override final {
|
||||
return new UriRegex(_uri);
|
||||
};
|
||||
}
|
||||
|
||||
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {
|
||||
if (Uri::canHandle(requestUri, pathArgs))
|
||||
return true;
|
||||
|
||||
if (_regexErr != 0)
|
||||
return false;
|
||||
|
||||
regmatch_t groupArray[REGEX_MAX_GROUPS];
|
||||
if (regexec(&_regexCompiled, requestUri.c_str(), REGEX_MAX_GROUPS, groupArray, 0) == 0) {
|
||||
// matches
|
||||
pathArgs.clear();
|
||||
|
||||
unsigned int g = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user