From 69f4c2b224bd40468e7c6556da5afe24835673c6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 Apr 2020 20:02:43 -0700 Subject: [PATCH] ircd::m::resource: Obtain version information for request if possible. --- include/ircd/m/resource.h | 1 + matrix/resource.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/ircd/m/resource.h b/include/ircd/m/resource.h index bea814368..b5753ae01 100644 --- a/include/ircd/m/resource.h +++ b/include/ircd/m/resource.h @@ -47,6 +47,7 @@ struct ircd::m::resource::request pair authorization; // proffering any string_view access_token; // proffering user m::request::x_matrix x_matrix; // proferring server + pair version; // enumeration string_view node_id; // authenticated server m::user::id user_id; // authenticated user or bridge pup diff --git a/matrix/resource.cc b/matrix/resource.cc index 2b32adcec..49e3d43cf 100644 --- a/matrix/resource.cc +++ b/matrix/resource.cc @@ -14,10 +14,11 @@ namespace ircd::m extern conf::item x_matrix_verify_origin; extern conf::item x_matrix_verify_destination; + static void cache_warm_origin(const resource::request &); + static pair 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 &); - static void cache_warm_origin(const resource::request &); } decltype(ircd::m::cache_warmup_time) @@ -154,6 +155,10 @@ 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 @@ -391,6 +396,30 @@ catch(const std::exception &e) }; } +ircd::pair +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 + }; +} + /// We can smoothly warmup some memory caches after daemon startup as the /// requests trickle in from remote servers. This function is invoked after /// a remote contacts and reveals its identity with the X-Matrix verification.