mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd::parse: Capstan.
This commit is contained in:
parent
472ee2c648
commit
e849897cc0
7 changed files with 31 additions and 31 deletions
|
@ -74,7 +74,7 @@ struct line
|
|||
struct header;
|
||||
|
||||
using string_view::string_view;
|
||||
line(parse::context &);
|
||||
line(parse::capstan &);
|
||||
};
|
||||
|
||||
struct line::request
|
||||
|
@ -112,7 +112,7 @@ struct headers
|
|||
{
|
||||
using closure = std::function<void (const line::header &)>;
|
||||
|
||||
headers(parse::context &, const closure & = {});
|
||||
headers(parse::capstan &, const closure & = {});
|
||||
};
|
||||
|
||||
struct content
|
||||
|
@ -120,8 +120,8 @@ struct content
|
|||
{
|
||||
IRCD_OVERLOAD(discard)
|
||||
|
||||
content(parse::context &, const size_t &length, discard_t);
|
||||
content(parse::context &, const size_t &length);
|
||||
content(parse::capstan &, const size_t &length, discard_t);
|
||||
content(parse::capstan &, const size_t &length);
|
||||
content() = default;
|
||||
};
|
||||
|
||||
|
@ -138,7 +138,7 @@ struct response
|
|||
const write_closure &,
|
||||
const std::initializer_list<line::header> & = {});
|
||||
|
||||
response(parse::context &,
|
||||
response(parse::capstan &,
|
||||
content *const & = nullptr,
|
||||
const proffer & = nullptr,
|
||||
const headers::closure & = {});
|
||||
|
@ -149,17 +149,17 @@ struct response::head
|
|||
{
|
||||
size_t content_length {0};
|
||||
|
||||
head(parse::context &pc, const headers::closure &c = {});
|
||||
head(parse::capstan &pc, const headers::closure &c = {});
|
||||
};
|
||||
|
||||
struct response::content
|
||||
:http::content
|
||||
{
|
||||
content(parse::context &pc, const head &h, discard_t)
|
||||
content(parse::capstan &pc, const head &h, discard_t)
|
||||
:http::content{pc, h.content_length, discard}
|
||||
{}
|
||||
|
||||
content(parse::context &pc, const head &h)
|
||||
content(parse::capstan &pc, const head &h)
|
||||
:http::content{pc, h.content_length}
|
||||
{}
|
||||
|
||||
|
@ -181,7 +181,7 @@ struct request
|
|||
const write_closure & = nullptr,
|
||||
const std::initializer_list<line::header> & = {});
|
||||
|
||||
request(parse::context &,
|
||||
request(parse::capstan &,
|
||||
content *const & = nullptr,
|
||||
const write_closure & = nullptr,
|
||||
const proffer & = nullptr,
|
||||
|
@ -196,17 +196,17 @@ struct request::head
|
|||
string_view te;
|
||||
size_t content_length {0};
|
||||
|
||||
head(parse::context &pc, const headers::closure &c = {});
|
||||
head(parse::capstan &pc, const headers::closure &c = {});
|
||||
};
|
||||
|
||||
struct request::content
|
||||
:http::content
|
||||
{
|
||||
content(parse::context &pc, const head &h, discard_t)
|
||||
content(parse::capstan &pc, const head &h, discard_t)
|
||||
:http::content{pc, h.content_length, discard}
|
||||
{}
|
||||
|
||||
content(parse::context &pc, const head &h)
|
||||
content(parse::capstan &pc, const head &h)
|
||||
:http::content{pc, h.content_length}
|
||||
{}
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ struct parse
|
|||
using parse_closure = std::function<bool (const char *&, const char *)>;
|
||||
|
||||
struct grammar;
|
||||
struct context;
|
||||
struct capstan;
|
||||
struct buffer;
|
||||
};
|
||||
|
||||
|
@ -95,7 +95,7 @@ struct parse::buffer
|
|||
{}
|
||||
};
|
||||
|
||||
struct parse::context
|
||||
struct parse::capstan
|
||||
{
|
||||
const char *&parsed;
|
||||
char *&read;
|
||||
|
@ -107,14 +107,14 @@ struct parse::context
|
|||
read_closure reader;
|
||||
void operator()(const parse_closure &);
|
||||
|
||||
context(const char *&parsed, char *&read, char *const &max, const decltype(reader) &reader = nullptr);
|
||||
context(buffer &, const decltype(reader) &reader = nullptr);
|
||||
capstan(const char *&parsed, char *&read, char *const &max, const decltype(reader) &reader = nullptr);
|
||||
capstan(buffer &, const decltype(reader) &reader = nullptr);
|
||||
};
|
||||
|
||||
} // namespace ircd
|
||||
|
||||
inline
|
||||
ircd::parse::context::context(buffer &buffer,
|
||||
ircd::parse::capstan::capstan(buffer &buffer,
|
||||
const decltype(reader) &reader)
|
||||
:parsed{buffer.parsed}
|
||||
,read{buffer.read}
|
||||
|
@ -124,7 +124,7 @@ ircd::parse::context::context(buffer &buffer,
|
|||
}
|
||||
|
||||
inline
|
||||
ircd::parse::context::context(const char *&parsed,
|
||||
ircd::parse::capstan::capstan(const char *&parsed,
|
||||
char *&read,
|
||||
char *const &max,
|
||||
const decltype(reader) &reader)
|
||||
|
@ -136,7 +136,7 @@ ircd::parse::context::context(const char *&parsed,
|
|||
}
|
||||
|
||||
inline void
|
||||
ircd::parse::context::operator()(const parse_closure &pc)
|
||||
ircd::parse::capstan::operator()(const parse_closure &pc)
|
||||
{
|
||||
while(!pc(parsed, const_cast<const char *>(read)))
|
||||
reader(read, stop);
|
||||
|
|
|
@ -45,7 +45,7 @@ struct resource
|
|||
decltype(resources)::const_iterator resources_it;
|
||||
|
||||
public:
|
||||
void operator()(client &, parse::context &, const http::request::head &) const;
|
||||
void operator()(client &, parse::capstan &, const http::request::head &) const;
|
||||
|
||||
resource(const char *const &name,
|
||||
const char *const &description = "");
|
||||
|
|
|
@ -213,7 +213,7 @@ try
|
|||
char buffer[4096];
|
||||
|
||||
parse::buffer pb{buffer, buffer + sizeof(buffer)};
|
||||
parse::context pc{pb, read_closure(*this)};
|
||||
parse::capstan pc{pb, read_closure(*this)};
|
||||
http::request
|
||||
{
|
||||
pc, nullptr, write_closure(*this), [&]
|
||||
|
|
16
ircd/http.cc
16
ircd/http.cc
|
@ -311,7 +311,7 @@ ircd::http::printed_size(const std::initializer_list<line::header> &headers)
|
|||
});
|
||||
}
|
||||
|
||||
ircd::http::request::request(parse::context &pc,
|
||||
ircd::http::request::request(parse::capstan &pc,
|
||||
content *const &c,
|
||||
const write_closure &write_closure,
|
||||
const proffer &proffer,
|
||||
|
@ -396,7 +396,7 @@ ircd::http::request::request(const string_view &host,
|
|||
closure(vector);
|
||||
}
|
||||
|
||||
ircd::http::request::head::head(parse::context &pc,
|
||||
ircd::http::request::head::head(parse::capstan &pc,
|
||||
const headers::closure &c)
|
||||
:line::request{pc}
|
||||
{
|
||||
|
@ -416,7 +416,7 @@ ircd::http::request::head::head(parse::context &pc,
|
|||
}};
|
||||
}
|
||||
|
||||
ircd::http::response::response(parse::context &pc,
|
||||
ircd::http::response::response(parse::capstan &pc,
|
||||
content *const &c,
|
||||
const proffer &proffer,
|
||||
const headers::closure &headers_closure)
|
||||
|
@ -501,7 +501,7 @@ ircd::http::response::response(const code &code,
|
|||
closure(iov);
|
||||
}
|
||||
|
||||
ircd::http::response::head::head(parse::context &pc,
|
||||
ircd::http::response::head::head(parse::capstan &pc,
|
||||
const headers::closure &c)
|
||||
:line::response{pc}
|
||||
{
|
||||
|
@ -515,7 +515,7 @@ ircd::http::response::head::head(parse::context &pc,
|
|||
}};
|
||||
}
|
||||
|
||||
ircd::http::content::content(parse::context &pc,
|
||||
ircd::http::content::content(parse::capstan &pc,
|
||||
const size_t &length)
|
||||
:string_view{[&pc, &length]
|
||||
{
|
||||
|
@ -543,7 +543,7 @@ ircd::http::content::content(parse::context &pc,
|
|||
{
|
||||
}
|
||||
|
||||
ircd::http::content::content(parse::context &pc,
|
||||
ircd::http::content::content(parse::capstan &pc,
|
||||
const size_t &length,
|
||||
discard_t)
|
||||
:string_view{}
|
||||
|
@ -563,7 +563,7 @@ ircd::http::content::content(parse::context &pc,
|
|||
}
|
||||
}
|
||||
|
||||
ircd::http::headers::headers(parse::context &pc,
|
||||
ircd::http::headers::headers(parse::capstan &pc,
|
||||
const closure &c)
|
||||
{
|
||||
for(line::header h{pc}; !h.first.empty(); h = line::header{pc})
|
||||
|
@ -630,7 +630,7 @@ catch(const qi::expectation_failure<const char *> &e)
|
|||
throw error(code::BAD_REQUEST, buf);
|
||||
}
|
||||
|
||||
ircd::http::line::line(parse::context &pc)
|
||||
ircd::http::line::line(parse::capstan &pc)
|
||||
:string_view{[&pc]
|
||||
{
|
||||
static const auto grammar
|
||||
|
|
|
@ -55,7 +55,7 @@ try
|
|||
|
||||
char buf[4096];
|
||||
parse::buffer pb{buf};
|
||||
parse::context pc{pb, read_closure(client)};
|
||||
parse::capstan pc{pb, read_closure(client)};
|
||||
http::response
|
||||
{
|
||||
pc, nullptr, [&pc](const auto &head)
|
||||
|
|
|
@ -54,7 +54,7 @@ noexcept
|
|||
|
||||
void
|
||||
ircd::resource::operator()(client &client,
|
||||
parse::context &pc,
|
||||
parse::capstan &pc,
|
||||
const http::request::head &head)
|
||||
const try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue