0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

modules/ircd:Ⓜ️ Upgrade various json tuple templates with string literals.

This commit is contained in:
Jason Volk 2017-10-04 16:40:02 -07:00
parent 2d90965816
commit edcd95cd8f
7 changed files with 43 additions and 42 deletions

View file

@ -393,7 +393,7 @@ ircd::m::bootstrap_keys()
};
static char tls_fingerprints_buf[256];
json::val<name::tls_fingerprints>(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<name::signatures>(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<name::server_name>(key)
at<"server_name"_>(key)
};
const m::user::id::buf sender
{
"ircd", at<name::server_name>(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<name::content>(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<name::content>(event).size();
ret = json::get<"content"_>(event).size();
return true;
});
@ -693,7 +693,7 @@ const
{
const json::object &content
{
json::at<m::name::content>(event)
json::at<"content"_>(event)
};
const auto &existing_membership
@ -719,7 +719,7 @@ const
events::test(query, [&buf]
(const auto &event)
{
buf = json::val<name::event_id>(event);
buf = json::get<"event_id"_>(event);
return true;
});
@ -870,7 +870,7 @@ const
{
const json::object &content
{
json::at<m::name::content>(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<name::room_id>(value)};
const auto &type{json::val<name::type>(value)};
const auto &state_key{json::val<name::state_key>(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<name::type>(event))
if(!json::at<"type"_>(event))
throw BAD_JSON("Required event field: '%s'", name::type);
if(!json::at<name::sender>(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<name::event_id>(event), iov
txn, json::at<"event_id"_>(event), iov
};
append_indexes(event, txn);
txn(*event::events);
event::head = json::at<name::event_id>(event);
event::head = json::at<"event_id"_>(event);
event::inserted.notify(event);
}

View file

@ -137,14 +137,14 @@ try
// key which must be part of the redaction process.
const json::object &unsigned_
{
json::val<m::name::unsigned_>(event)
json::get<"unsigned"_>(event)
};
if(unsigned_.has("redacted_because"))
return false;
assert(at<m::name::state_key>(event) == access_token);
request.user_id = at<m::name::sender>(event);
assert(at<"state_key"_>(event) == access_token);
request.user_id = at<"sender"_>(event);
return true;
})
};

View file

@ -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<name::user>(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<name::password>(request))
unquote(at<"password"_>(request))
};
m::user user
@ -131,7 +131,7 @@ post_login(client &client, const resource::request::object<body> &request)
// Currently only "m.login.password" is supported.
const auto type
{
unquote(at<name::type>(request))
unquote(at<"type"_>(request))
};
if(type == "m.login.password")

View file

@ -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<name::auth>(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<name::username>(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<name::password>(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<name::bind_email>(request, false)
get<"bind_email"_>(request, false)
};
// Check if the password is acceptable for this server or throws

View file

@ -60,7 +60,7 @@ get_messages(client &client,
{
[](const auto &event)
{
return !defined(json::val<m::name::state_key>(event));
return !defined(json::get<"state_key"_>(event));
}
};

View file

@ -138,7 +138,7 @@ sync(client &client, const resource::request &request)
{
const json::object &content
{
at<m::name::content>(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<m::name::room_id>(event)
json::get<"room_id"_>(event)
};
if(room_id)
@ -378,7 +378,7 @@ update_sync_room(client &client,
const m::event &event)
{
std::vector<std::string> state;
if(defined(json::val<m::name::state_key>(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<std::string> timeline;
if(!defined(json::val<m::name::state_key>(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<m::name::event_id>(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<m::name::state_key>(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<std::vector<json::member>, 3> m;
m::events::for_each(query, [&r, &m, &client, &request, &full_state](const auto &event)
{
const auto &content{json::val<m::name::content>(event)};
const auto &content{json::get<"content"_>(event)};
const auto &membership{unquote(content["membership"])};
const m::room::id &room_id{json::val<m::name::room_id>(event)};
const m::room::id &room_id{json::get<"room_id"_>(event)};
const auto i
{
membership == "join"? 0:

View file

@ -56,7 +56,7 @@ get_filter(client &client, const resource::request &request)
{
const json::object &filter
{
json::at<m::name::content>(event)
json::at<"content"_>(event)
};
resource::response
@ -93,6 +93,7 @@ post_filter(client &client, const resource::request::object<const m::filter> &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<const m::filter> &re
// fields than were requested.
const auto &event_fields
{
json::get<m::name::event_fields>(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<const m::filter> &re
// The default is 'client'. One of: ["client", "federation"]
const auto &event_format
{
json::get<m::name::event_format>(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<m::name::account_data>(request)
json::get<"account_data"_>(request)
};
// (5.2) Filters to be applied to room data.
const auto &room
{
json::val<m::name::room>(request)
json::get<"room"_>(request)
};
const auto &state
{
json::val<m::name::state>(room)
json::get<"state"_>(room)
};
const auto &presence
{
// (5.2) The presence updates to include.
json::val<m::name::presence>(request)
json::get<"presence"_>(request)
};
const auto filter_id