0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:resource: Abstract request::version to ircd::request::agent.

This commit is contained in:
Jason Volk 2022-07-14 14:24:53 -07:00
parent 24cf3569a9
commit 93a7575352
4 changed files with 37 additions and 30 deletions

View file

@ -49,7 +49,6 @@ struct ircd::m::resource::request
pair<string_view> authorization; // proffering any
string_view access_token; // proffering user
m::request::x_matrix x_matrix; // proferring server
pair<string_view> version; // enumeration
string_view node_id; // authenticated server
m::user::id user_id; // authenticated user or bridge pup

View file

@ -19,10 +19,15 @@ struct ircd::resource::request
http::request::head head;
string_view content;
http::query::string query;
pair<string_view> agent;
string_view params;
vector_view<string_view> parv;
string_view param[8];
private:
static pair<string_view> parse_agent(const http::request::head &) noexcept;
public:
request(const http::request::head &, const string_view &content) noexcept;
request() = default;
};
@ -35,6 +40,7 @@ struct ircd::resource::request::object
const http::request::head &head;
const string_view &content;
const http::query::string &query;
const pair<string_view> &agent;
const string_view &params;
const vector_view<string_view> &parv;
const json::object &body;
@ -51,6 +57,7 @@ noexcept
,head{r.head}
,content{r.content}
,query{r.query}
,agent{r.agent}
,params{r.params}
,parv{r.parv}
,body{r}

View file

@ -762,7 +762,37 @@ noexcept
{
this->head.query
}
,agent
{
parse_agent(this->head)
}
{
}
[[gnu::visibility("internal")]]
ircd::pair<ircd::string_view>
ircd::resource::request::parse_agent(const http::request::head &head)
noexcept
{
const auto &user_agent
{
head.user_agent
};
const auto &[primary, info]
{
split(user_agent, ' ')
};
const auto &[name, agent]
{
split(primary, '/')
};
return
{
name, agent
};
}
///////////////////////////////////////////////////////////////////////////////

View file

@ -13,7 +13,6 @@ namespace ircd::m
extern conf::item<bool> x_matrix_verify_origin;
extern conf::item<bool> x_matrix_verify_destination;
static pair<string_view> parse_version(const resource::request &);
static string_view authenticate_bridge(const resource::method &, const client &, resource::request &);
static user::id authenticate_user(const resource::method &, const client &, resource::request &);
static string_view authenticate_node(const resource::method &, const client &, resource::request &);
@ -177,10 +176,6 @@ ircd::m::resource::request::request(const method &method,
m::request::x_matrix{authorization.first, authorization.second}:
m::request::x_matrix{}
}
,version
{
parse_version(*this)
}
,node_id
{
// Server X-Matrix header verified here. Similar to client auth, origin
@ -435,27 +430,3 @@ catch(const std::exception &e)
e.what()
};
}
ircd::pair<ircd::string_view>
ircd::m::parse_version(const m::resource::request &request)
{
const auto &user_agent
{
request.head.user_agent
};
const auto &[primary, info]
{
split(user_agent, ' ')
};
const auto &[name, version]
{
split(primary, '/')
};
return
{
name, version
};
}