From 0644db459cedac40758aff9e0d0726c07092d566 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 18 Feb 2019 12:25:00 -0800 Subject: [PATCH] ircd::m::event: Add various size constants replacing magic numbers. --- include/ircd/m/dbs.h | 4 ++-- include/ircd/m/event/event.h | 5 ++++- ircd/m_room.cc | 2 +- modules/client/rooms/state.cc | 10 +++++----- modules/client/user/account_data.cc | 4 ++-- modules/client/user/rooms.cc | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/ircd/m/dbs.h b/include/ircd/m/dbs.h index 55baf6cbb..082dddf87 100644 --- a/include/ircd/m/dbs.h +++ b/include/ircd/m/dbs.h @@ -54,12 +54,12 @@ namespace ircd::m::dbs string_view room_head_key(const mutable_buffer &out, const id::room &, const id::event &); string_view room_head_key(const string_view &amalgam); - constexpr size_t ROOM_STATE_KEY_MAX_SIZE {id::MAX_SIZE + 256 + 256}; + constexpr size_t ROOM_STATE_KEY_MAX_SIZE {id::MAX_SIZE + event::TYPE_MAX_SIZE + event::STATE_KEY_MAX_SIZE}; string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key); string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type); std::pair room_state_key(const string_view &amalgam); - constexpr size_t ROOM_JOINED_KEY_MAX_SIZE {id::MAX_SIZE + 256 + id::MAX_SIZE}; + constexpr size_t ROOM_JOINED_KEY_MAX_SIZE {id::MAX_SIZE + event::ORIGIN_MAX_SIZE + id::MAX_SIZE}; string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin, const id::user &member); string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin); std::pair room_joined_key(const string_view &amalgam); diff --git a/include/ircd/m/event/event.h b/include/ircd/m/event/event.h index bb591a061..35ea2ab0a 100644 --- a/include/ircd/m/event/event.h +++ b/include/ircd/m/event/event.h @@ -92,7 +92,10 @@ struct ircd::m::event using closure_idx_bool = std::function; using closure_iov_mutable = std::function; - static constexpr size_t MAX_SIZE = 64_KiB; + static constexpr const size_t MAX_SIZE = 64_KiB; + static constexpr const size_t TYPE_MAX_SIZE = 256; + static constexpr const size_t STATE_KEY_MAX_SIZE = 256; + static constexpr const size_t ORIGIN_MAX_SIZE = 256; static conf::item max_size; static void essential(json::iov &event, const json::iov &content, const closure_iov_mutable &); diff --git a/ircd/m_room.cc b/ircd/m_room.cc index e1fb22b46..31b6ff7f9 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -1485,7 +1485,7 @@ ircd::m::room::state::for_each(const types_bool &closure) const { string_view last; - char lastbuf[256]; //TODO: type maxlen + char lastbuf[m::event::TYPE_MAX_SIZE]; if(!present()) { m::state::for_each(root_id, m::state::iter_bool_closure{[&closure, &last, &lastbuf] diff --git a/modules/client/rooms/state.cc b/modules/client/rooms/state.cc index 8ef94de12..87dc56a07 100644 --- a/modules/client/rooms/state.cc +++ b/modules/client/rooms/state.cc @@ -39,13 +39,13 @@ get__state(client &client, const resource::request &request, const room::id &room_id) { - char type_buf[uint(256 * 1.34 + 1)]; + char type_buf[m::event::TYPE_MAX_SIZE]; const string_view &type { url::decode(type_buf, request.parv[2]) }; - char skey_buf[uint(256 * 1.34 + 1)]; + char skey_buf[m::event::STATE_KEY_MAX_SIZE]; const string_view &state_key { url::decode(skey_buf, request.parv[3]) @@ -53,7 +53,7 @@ get__state(client &client, // (non-standard) Allow an event_id to be passed in the query string // for reference framing. - char evid_buf[uint(256 * 1.34 + 1)]; + char evid_buf[m::id::MAX_SIZE]; const string_view &event_id { url::decode(evid_buf, request.query["event_id"]) @@ -73,13 +73,13 @@ put__state(client &client, const resource::request &request, const room::id &room_id) { - char type_buf[uint(256 * 1.34 + 1)]; + char type_buf[m::event::TYPE_MAX_SIZE]; const string_view &type { url::decode(type_buf, request.parv[2]) }; - char skey_buf[uint(256 * 1.34 + 1)]; + char skey_buf[m::event::STATE_KEY_MAX_SIZE]; const string_view &state_key { url::decode(skey_buf, request.parv[3]) diff --git a/modules/client/user/account_data.cc b/modules/client/user/account_data.cc index 97a992d76..389144538 100644 --- a/modules/client/user/account_data.cc +++ b/modules/client/user/account_data.cc @@ -34,7 +34,7 @@ put__account_data(client &client, "type path parameter required" }; - char typebuf[256]; + char typebuf[m::event::TYPE_MAX_SIZE]; const string_view type { url::decode(typebuf, request.parv[2]) @@ -67,7 +67,7 @@ get__account_data(client &client, "type path parameter required" }; - char typebuf[256]; + char typebuf[m::event::TYPE_MAX_SIZE]; const string_view type { url::decode(typebuf, request.parv[2]) diff --git a/modules/client/user/rooms.cc b/modules/client/user/rooms.cc index 57f49f502..1307a1b95 100644 --- a/modules/client/user/rooms.cc +++ b/modules/client/user/rooms.cc @@ -121,7 +121,7 @@ put__account_data(client &client, "type path parameter required" }; - char typebuf[256]; + char typebuf[m::event::TYPE_MAX_SIZE]; const auto &type { url::decode(typebuf, request.parv[4]) @@ -156,7 +156,7 @@ get__account_data(client &client, "type path parameter required" }; - char typebuf[256]; + char typebuf[m::event::TYPE_MAX_SIZE]; const auto &type { url::decode(typebuf, request.parv[4])