Skip to content

Commit 69f4c2b

Browse files
committed
ircd::m::resource: Obtain version information for request if possible.
1 parent 71b69d6 commit 69f4c2b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/ircd/m/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct ircd::m::resource::request
4747
pair<string_view> authorization; // proffering any
4848
string_view access_token; // proffering user
4949
m::request::x_matrix x_matrix; // proferring server
50+
pair<string_view> version; // enumeration
5051

5152
string_view node_id; // authenticated server
5253
m::user::id user_id; // authenticated user or bridge pup

matrix/resource.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ namespace ircd::m
1414
extern conf::item<bool> x_matrix_verify_origin;
1515
extern conf::item<bool> x_matrix_verify_destination;
1616

17+
static void cache_warm_origin(const resource::request &);
18+
static pair<string_view> parse_version(const resource::request &);
1719
static string_view authenticate_bridge(const resource::method &, const client &, resource::request &);
1820
static user::id authenticate_user(const resource::method &, const client &, resource::request &);
1921
static string_view authenticate_node(const resource::method &, const client &, resource::request &);
20-
static void cache_warm_origin(const resource::request &);
2122
}
2223

2324
decltype(ircd::m::cache_warmup_time)
@@ -154,6 +155,10 @@ ircd::m::resource::request::request(const method &method,
154155
m::request::x_matrix{authorization.first, authorization.second}:
155156
m::request::x_matrix{}
156157
}
158+
,version
159+
{
160+
parse_version(*this)
161+
}
157162
,node_id
158163
{
159164
// Server X-Matrix header verified here. Similar to client auth, origin
@@ -391,6 +396,30 @@ catch(const std::exception &e)
391396
};
392397
}
393398

399+
ircd::pair<ircd::string_view>
400+
ircd::m::parse_version(const m::resource::request &request)
401+
{
402+
const auto &user_agent
403+
{
404+
request.head.user_agent
405+
};
406+
407+
const auto &[primary, info]
408+
{
409+
split(user_agent, ' ')
410+
};
411+
412+
const auto &[name, version]
413+
{
414+
split(primary, '/')
415+
};
416+
417+
return
418+
{
419+
name, version
420+
};
421+
}
422+
394423
/// We can smoothly warmup some memory caches after daemon startup as the
395424
/// requests trickle in from remote servers. This function is invoked after
396425
/// a remote contacts and reveals its identity with the X-Matrix verification.

0 commit comments

Comments
 (0)