diff --git a/ircd/matrix.cc b/ircd/matrix.cc index 816b9164c..a8c94a88b 100644 --- a/ircd/matrix.cc +++ b/ircd/matrix.cc @@ -393,7 +393,7 @@ ircd::m::bootstrap_keys() }; static char tls_fingerprints_buf[256]; - json::val(my_key) = json::stringify(tls_fingerprints_buf, json::value + json::get<"tls_fingerprints"_>(my_key) = json::stringify(tls_fingerprints_buf, json::value { tlsfp, 1 }); @@ -409,7 +409,7 @@ ircd::m::bootstrap_keys() }; static char signature[128], signatures[256]; - json::val(my_key) = json::stringify(signatures, json::members + json::get<"signatures"_>(my_key) = json::stringify(signatures, json::members { { my_host(), json::members { @@ -425,12 +425,12 @@ ircd::m::keys::set(const key &key) { const auto &state_key { - at(key) + at<"server_name"_>(key) }; const m::user::id::buf sender { - "ircd", at(key) + "ircd", at<"server_name"_>(key) }; const auto content @@ -555,7 +555,7 @@ ircd::m::filter::filter(const string_view &filter_id, m::events::test(query, [&buf, &len] (const auto &event) { - len = copy(buf, json::val(event)); + len = copy(buf, json::get<"content"_>(event)); return true; }); @@ -576,7 +576,7 @@ ircd::m::filter::size(const string_view &filter_id) m::events::test(query, [&ret] (const auto &event) { - ret = json::val(event).size(); + ret = json::get<"content"_>(event).size(); return true; }); @@ -693,7 +693,7 @@ const { const json::object &content { - json::at(event) + json::at<"content"_>(event) }; const auto &existing_membership @@ -719,7 +719,7 @@ const events::test(query, [&buf] (const auto &event) { - buf = json::val(event); + buf = json::get<"event_id"_>(event); return true; }); @@ -870,7 +870,7 @@ const { const json::object &content { - json::at(event) + json::at<"content"_>(event) }; const auto &correct_password @@ -1244,9 +1244,9 @@ ircd::m::events::query(const event::query<> &where, }; const auto &value{clause.value}; - const auto &room_id{json::val(value)}; - const auto &type{json::val(value)}; - const auto &state_key{json::val(value)}; + const auto &room_id{json::get<"room_id"_>(value)}; + const auto &type{json::get<"type"_>(value)}; + const auto &state_key{json::get<"state_key"_>(value)}; if(room_id && type && state_key.defined()) return _query_for_type_state_key_in_room_id(where, closure, room_id, type, state_key); @@ -1410,10 +1410,10 @@ ircd::m::event::insert(json::iov &iov) iov }; - if(!json::at(event)) + if(!json::at<"type"_>(event)) throw BAD_JSON("Required event field: '%s'", name::type); - if(!json::at(event)) + if(!json::at<"sender"_>(event)) throw BAD_JSON("Required event field: '%s'", name::sender); db::iov txn @@ -1423,12 +1423,12 @@ ircd::m::event::insert(json::iov &iov) db::iov::append { - txn, json::at(event), iov + txn, json::at<"event_id"_>(event), iov }; append_indexes(event, txn); txn(*event::events); - event::head = json::at(event); + event::head = json::at<"event_id"_>(event); event::inserted.notify(event); } diff --git a/ircd/resource.cc b/ircd/resource.cc index 9fe3afae7..1923083cc 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -137,14 +137,14 @@ try // key which must be part of the redaction process. const json::object &unsigned_ { - json::val(event) + json::get<"unsigned"_>(event) }; if(unsigned_.has("redacted_because")) return false; - assert(at(event) == access_token); - request.user_id = at(event); + assert(at<"state_key"_>(event) == access_token); + request.user_id = at<"sender"_>(event); return true; }) }; diff --git a/modules/client/login.cc b/modules/client/login.cc index 2787882e9..528e03b92 100644 --- a/modules/client/login.cc +++ b/modules/client/login.cc @@ -57,7 +57,7 @@ post_login_password(client &client, // Build a canonical MXID from a the user field const m::id::user::buf user_id { - unquote(at(request)), my_host() + unquote(at<"user"_>(request)), my_host() }; if(!user_id.valid() || user_id.host() != my_host()) @@ -68,7 +68,7 @@ post_login_password(client &client, const auto &supplied_password { - unquote(at(request)) + unquote(at<"password"_>(request)) }; m::user user @@ -131,7 +131,7 @@ post_login(client &client, const resource::request::object &request) // Currently only "m.login.password" is supported. const auto type { - unquote(at(request)) + unquote(at<"type"_>(request)) }; if(type == "m.login.password") diff --git a/modules/client/register.cc b/modules/client/register.cc index f678159d7..53bcbb4b7 100644 --- a/modules/client/register.cc +++ b/modules/client/register.cc @@ -51,7 +51,7 @@ handle_post_kind_user(client &client, // 3.3.1 Additional authentication information for the user-interactive authentication API. const auto &auth { - at(request) + at<"auth"_>(request) }; // 3.3.1 Required. The login type that the client is attempting to complete. @@ -71,7 +71,7 @@ handle_post_kind_user(client &client, // generate a Matrix ID local part. const auto &username { - unquote(get(request)) + unquote(json::get<"username"_>(request)) }; // Generate canonical mxid. The home_server is appended if one is not @@ -88,14 +88,14 @@ handle_post_kind_user(client &client, // 3.3.1 Required. The desired password for the account. const auto &password { - at(request) + at<"password"_>(request) }; // 3.3.1 If true, the server binds the email used for authentication to the // Matrix ID with the ID Server. Defaults to false. const auto &bind_email { - get(request, false) + get<"bind_email"_>(request, false) }; // Check if the password is acceptable for this server or throws diff --git a/modules/client/rooms.cc b/modules/client/rooms.cc index c2379f6ea..84e57e51e 100644 --- a/modules/client/rooms.cc +++ b/modules/client/rooms.cc @@ -60,7 +60,7 @@ get_messages(client &client, { [](const auto &event) { - return !defined(json::val(event)); + return !defined(json::get<"state_key"_>(event)); } }; diff --git a/modules/client/sync.cc b/modules/client/sync.cc index 1a99602e6..2b2c805e2 100644 --- a/modules/client/sync.cc +++ b/modules/client/sync.cc @@ -138,7 +138,7 @@ sync(client &client, const resource::request &request) { const json::object &content { - at(event) + at<"content"_>(event) }; head = unquote(content.at("event_id")); @@ -329,7 +329,7 @@ synchronize(const m::event &event) { const auto &room_id { - json::val(event) + json::get<"room_id"_>(event) }; if(room_id) @@ -378,7 +378,7 @@ update_sync_room(client &client, const m::event &event) { std::vector state; - if(defined(json::val(event))) + if(defined(json::get<"state_key"_>(event))) state.emplace_back(json::string(event)); const auto state_serial @@ -387,7 +387,7 @@ update_sync_room(client &client, }; std::vector timeline; - if(!defined(json::val(event))) + if(!defined(json::get<"state_key"_>(event))) timeline.emplace_back(json::string(event)); const auto timeline_serial @@ -451,7 +451,7 @@ try const string_view next_batch { - at(event) + at<"event_id"_>(event) }; resource::response @@ -508,7 +508,7 @@ initial_sync_room(client &client, if(timeline.size() > 10) return true; - if(!defined(json::val(event))) + if(!defined(json::get<"state_key"_>(event))) timeline.emplace_back(json::string(event)); return false; @@ -545,9 +545,9 @@ initial_sync_rooms(client &client, std::array, 3> m; m::events::for_each(query, [&r, &m, &client, &request, &full_state](const auto &event) { - const auto &content{json::val(event)}; + const auto &content{json::get<"content"_>(event)}; const auto &membership{unquote(content["membership"])}; - const m::room::id &room_id{json::val(event)}; + const m::room::id &room_id{json::get<"room_id"_>(event)}; const auto i { membership == "join"? 0: diff --git a/modules/client/user.cc b/modules/client/user.cc index d36a92d0a..010602345 100644 --- a/modules/client/user.cc +++ b/modules/client/user.cc @@ -56,7 +56,7 @@ get_filter(client &client, const resource::request &request) { const json::object &filter { - json::at(event) + json::at<"content"_>(event) }; resource::response @@ -93,6 +93,7 @@ post_filter(client &client, const resource::request::object &re { urldecode(token(request.head.path, '/', 4), user_id) }; + user_id.validate(); // (5.2) List of event fields to include. If this list is absent then all fields are @@ -102,7 +103,7 @@ post_filter(client &client, const resource::request::object &re // fields than were requested. const auto &event_fields { - json::get(request) + json::get<"event_fields"_>(request) }; // (5.2) The format to use for events. 'client' will return the events in a format suitable @@ -110,30 +111,30 @@ post_filter(client &client, const resource::request::object &re // The default is 'client'. One of: ["client", "federation"] const auto &event_format { - json::get(request) + json::get<"event_format"_>(request) }; // (5.2) The user account data that isn't associated with rooms to include. const auto &account_data { - json::val(request) + json::get<"account_data"_>(request) }; // (5.2) Filters to be applied to room data. const auto &room { - json::val(request) + json::get<"room"_>(request) }; const auto &state { - json::val(room) + json::get<"state"_>(room) }; const auto &presence { // (5.2) The presence updates to include. - json::val(request) + json::get<"presence"_>(request) }; const auto filter_id