36static size_t re_atom_len(
const char *p)
42 const char *q = p + 1;
47 while (*q && *q !=
']')
49 if (*q ==
'\\' && q[1])
54 return (
size_t)((*q ==
']' ? q + 1 : q) - p);
59static bool re_class_member(
char lo,
char hi,
char ch)
61 return ch >= lo && ch <= hi;
65static char re_read_atom(
const char *&q,
const char *end)
67 if (*q ==
'\\' && (q + 1) < end)
79static bool re_match_escape(
char e,
char ch)
84 return ch >=
'0' && ch <=
'9';
86 return !(ch >=
'0' && ch <=
'9');
88 return (ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9') || ch ==
'_';
90 return !((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9') || ch ==
'_');
92 return ch ==
' ' || ch ==
'\t';
94 return !(ch ==
' ' || ch ==
'\t');
101static bool re_match_class(
const char *p,
size_t len,
char ch)
103 const char *q = p + 1;
104 const char *end = p + len - 1;
106 if (q < end && *q ==
'^')
114 char lo = re_read_atom(q, end);
115 if (q < end && *q ==
'-' && (q + 1) < end && q[1] !=
']')
118 char hi = re_read_atom(q, end);
119 m = re_class_member(lo, hi, ch) || m;
130static bool re_atom_matches(
const char *p,
size_t len,
char ch)
135 return re_match_escape(p[1], ch);
139 return re_match_class(p, len, ch);
143static bool re_match(
ReCtx *c,
const char *pat,
const char *text);
146static bool re_star(
ReCtx *c,
const char *atom,
size_t al,
const char *rest,
const char *text)
150 if (re_atom_matches(atom, al, *text) && re_star(c, atom, al, rest, text + 1))
152 return re_match(c, rest, text);
155static bool re_match(
ReCtx *c,
const char *pat,
const char *text)
160 return *text ==
'\0';
162 size_t al = re_atom_len(pat);
163 char quant = pat[al];
164 const char *rest = (quant ==
'*' || quant ==
'+' || quant ==
'?') ? pat + al + 1 : pat + al;
167 return re_star(c, pat, al, rest, text);
170 if (!re_atom_matches(pat, al, *text))
172 return re_star(c, pat, al, rest, text + 1);
176 if (re_atom_matches(pat, al, *text) && re_match(c, rest, text + 1))
178 return re_match(c, rest, text);
181 if (re_atom_matches(pat, al, *text))
182 return re_match(c, rest, text + 1);
193 return re_match(&c, pattern, path);
#define RE_MAX_STEPS
Step budget for the regex route matcher (see on_regex()).
Layer 7 (Application) - public HTTP routing API.
Library-private declarations shared between dwserver.cpp and the src/server/*.cpp request-handler tra...
bool regex_match(const char *pattern, const char *path)
Whole-path regex match (anchored both ends; bounded by RE_MAX_STEPS, fails closed)....