From 43d66420cd0f581d72301002bd8951913dbf4cb8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 10 Jul 2019 00:26:25 -0700 Subject: [PATCH] Update incompatible uses of event_id. --- include/ircd/m/event/event.h | 4 +--- ircd/m.cc | 4 ++-- ircd/m_event.cc | 30 +++++++++++++++--------------- ircd/m_room.cc | 8 ++++---- modules/client/rooms/context.cc | 4 ++-- modules/client/rooms/invite.cc | 2 +- modules/client/rooms/join.cc | 4 ++-- modules/client/rooms/messages.cc | 2 +- modules/client/rooms/send.cc | 2 +- modules/console.cc | 8 ++++---- modules/federation/invite2.cc | 2 +- modules/m_receipt.cc | 2 +- modules/m_room_create.cc | 8 ++++---- modules/m_vm.cc | 7 ------- 14 files changed, 39 insertions(+), 48 deletions(-) diff --git a/include/ircd/m/event/event.h b/include/ircd/m/event/event.h index 891b3792c..0c94aef29 100644 --- a/include/ircd/m/event/event.h +++ b/include/ircd/m/event/event.h @@ -163,7 +163,5 @@ inline ircd::m::event::operator id() const { - return json::get<"event_id"_>(*this)? - id{json::get<"event_id"_>(*this)}: - id{}; + return event_id; } diff --git a/ircd/m.cc b/ircd/m.cc index dea829b8c..9d1ae80b6 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -1467,7 +1467,7 @@ ircd::m::vm::eval::find(const event::id &event_id) { if(e.event_) { - if(json::get<"event_id"_>(*e.event_) == event_id) + if(e.event_->event_id == event_id) ret = &e; } else if(e.issue) @@ -1568,7 +1568,7 @@ ircd::m::vm::eval::eval(const json::array &pdus, // any way we can elide a lot of grief by checking this here first and // skipping the event. The query path will be adequately cached anyway. if(~(opts.warnlog | opts.errorlog) & fault::EXISTS) - if(m::exists(m::event::id(at<"event_id"_>(event)))) + if(m::exists(event.event_id)) continue; operator()(event); diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 31294be33..efbae0c54 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -148,8 +148,8 @@ ircd::m::pretty_oneline(std::ostream &s, else s << "* "; - if(defined(json::get<"event_id"_>(event))) - s << json::get<"event_id"_>(event) << " "; + if(event.event_id) + s << event.event_id << " "; else s << "* "; @@ -243,7 +243,7 @@ ircd::m::pretty_msgline(std::ostream &s, s << json::get<"depth"_>(event) << " :"; s << json::get<"type"_>(event) << " "; s << json::get<"sender"_>(event) << " "; - s << json::get<"event_id"_>(event) << " "; + s << event.event_id << " "; const auto &state_key { @@ -394,7 +394,7 @@ ircd::m::append(json::stack::object &object, const auto txnid_idx { !has_client_txnid && sender_is_user && opts.query_txnid? - opts.user_room->get(std::nothrow, "ircd.client.txnid", at<"event_id"_>(event)): + opts.user_room->get(std::nothrow, "ircd.client.txnid", event.event_id): 0UL }; @@ -403,7 +403,7 @@ ircd::m::append(json::stack::object &object, log::dwarning { log, "Could not find transaction_id for %s from %s in %s", - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"sender"_>(event), json::get<"room_id"_>(event) }; @@ -417,7 +417,7 @@ ircd::m::append(json::stack::object &object, log::debug { log, "Not sending event '%s' because '%s' is ignored by '%s'", - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"sender"_>(event), string_view{*opts.user_id} }; @@ -717,7 +717,7 @@ ircd::m::event::conforms::conforms(const event &e) set(INVALID_OR_MISSING_REDACTS_ID); if(json::get<"redacts"_>(e)) - if(json::get<"redacts"_>(e) == json::get<"event_id"_>(e)) + if(json::get<"redacts"_>(e) == e.event_id) set(SELF_REDACTS); if(json::get<"type"_>(e) == "m.room.member") @@ -1663,7 +1663,7 @@ ircd::m::event::idx ircd::m::index(const event &event) try { - return index(at<"event_id"_>(event)); + return index(event.event_id); } catch(const json::not_found &) { @@ -1678,7 +1678,7 @@ ircd::m::index(const event &event, std::nothrow_t) try { - return index(at<"event_id"_>(event), std::nothrow); + return index(event.event_id, std::nothrow); } catch(const json::not_found &) { @@ -1764,7 +1764,7 @@ ircd::m::event::auth::check(const event &event) throw m::ACCESS_DENIED { "Authorization of %s failed against its auth_events :%s", - json::get<"event_id"_>(event), + string_view{event.event_id}, reason }; } @@ -2321,7 +2321,7 @@ ircd::m::event::auth::failed(const m::event &event, // b. If the domain of the event_id of the event being redacted is the // same as the domain of the event_id of the m.room.redaction, allow. - if(event::id(json::get<"redacts"_>(event)).host() == event::id(at<"event_id"_>(event)).host()) + if(event::id(json::get<"redacts"_>(event)).host() == user::id(at<"sender"_>(event)).host()) return {}; // c. Otherwise, reject. @@ -3414,7 +3414,7 @@ catch(const m::NOT_FOUND &e) log::derror { "Failed to verify %s because key %s for %s :%s", - string_view{json::get<"event_id"_>(event)}, + string_view{event.event_id}, keyid, origin, e.what() @@ -3768,7 +3768,7 @@ ircd::m::before(const event &a, const event &b) { const event::prev prev{b}; - return prev.prev_events_has(at<"event_id"_>(a)); + return prev.prev_events_has(a.event_id); } bool @@ -3803,7 +3803,7 @@ bool ircd::m::operator==(const event &a, const event &b) { //assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b)); - return json::get<"event_id"_>(a) == json::get<"event_id"_>(b); + return a.event_id == b.event_id; } bool @@ -3896,7 +3896,7 @@ bool ircd::m::my(const event &event) { const auto &origin(json::get<"origin"_>(event)); - const auto &eid(json::get<"event_id"_>(event)); + const auto &eid(event.event_id); return origin? my_host(origin): diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 6c19e1e4c..b752e1cdc 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -107,14 +107,14 @@ ircd::m::room::state::force_present(const m::event &event) throw error { "event %s is not a room event (no room_id)", - json::get<"event_id"_>(event) + string_view{event.event_id} }; if(!defined(json::get<"state_key"_>(event))) throw error { "event %s is not a state event (no state_key)", - json::get<"event_id"_>(event) + string_view{event.event_id} }; dbs::write_opts opts; @@ -3746,7 +3746,7 @@ ircd::m::room::head::make_refs(const head &head, return true; if(need_tophead) - if(json::get<"event_id"_>(event) == std::get<0>(top_head)) + if(event.event_id == std::get<0>(top_head)) need_tophead = false; depth = std::max(json::get<"depth"_>(event), depth); @@ -4854,7 +4854,7 @@ ircd::m::dagree_histogram(const m::room &room, log::warning { m::log, "Event '%s' had %zu prev events (ignored)", - string_view(at<"event_id"_>(event)) + string_view{event.event_id}, }; continue; diff --git a/modules/client/rooms/context.cc b/modules/client/rooms/context.cc index 1489f4419..26f55863b 100644 --- a/modules/client/rooms/context.cc +++ b/modules/client/rooms/context.cc @@ -189,7 +189,7 @@ get__context(client &client, for(size_t i(0); i < limit && before; --before, ++i) { const m::event &event{*before}; - start = at<"event_id"_>(event); + start = event.event_id; if(!visible(event, request.user_id)) continue; @@ -230,7 +230,7 @@ get__context(client &client, for(size_t i(0); i < limit && after; ++after, ++i) { const m::event &event{*after}; - end = at<"event_id"_>(event); + end = event.event_id; if(!visible(event, request.user_id)) continue; diff --git a/modules/client/rooms/invite.cc b/modules/client/rooms/invite.cc index 12b677075..29fa89ec1 100644 --- a/modules/client/rooms/invite.cc +++ b/modules/client/rooms/invite.cc @@ -124,7 +124,7 @@ ircd::m::invite_foreign(const event &event) { const auto &event_id { - at<"event_id"_>(event) + event.event_id }; const auto &room_id diff --git a/modules/client/rooms/join.cc b/modules/client/rooms/join.cc index 18a2adec7..987405020 100644 --- a/modules/client/rooms/join.cc +++ b/modules/client/rooms/join.cc @@ -293,7 +293,7 @@ try { const m::event::id &event_id { - at<"event_id"_>(event) + event.event_id }; const m::room::id &room_id @@ -387,7 +387,7 @@ catch(const std::exception &e) log::error { join_log, "join bootstrap for %s to %s :%s", - string_view{at<"event_id"_>(event)}, + string_view{event.event_id}, string(host), e.what() }; diff --git a/modules/client/rooms/messages.cc b/modules/client/rooms/messages.cc index c3ac1c3e4..7155ac491 100644 --- a/modules/client/rooms/messages.cc +++ b/modules/client/rooms/messages.cc @@ -152,7 +152,7 @@ get__messages(client &client, for(; it; page.dir == 'b'? --it : ++it) { const m::event &event{*it}; - end = at<"event_id"_>(event); + end = event.event_id; if(hit > page.limit || miss >= size_t(max_filter_miss)) break; diff --git a/modules/client/rooms/send.cc b/modules/client/rooms/send.cc index 88df7e1da..c67986a49 100644 --- a/modules/client/rooms/send.cc +++ b/modules/client/rooms/send.cc @@ -170,7 +170,7 @@ save_transaction_id(const m::event &event, const auto &state_key { - at<"event_id"_>(event) + event.event_id }; send(user_room, at<"sender"_>(event), type, state_key, diff --git a/modules/console.cc b/modules/console.cc index 43ecfa028..526ef261d 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -8377,7 +8377,7 @@ console_cmd__room__members__read(opt &out, const string_view &line) out << timestr(at<"origin_server_ts"_>(event) / 1000) << " " << at<"sender"_>(event) << " " << at<"content"_>(event) - << " " << at<"event_id"_>(event) + << " " << event.event_id << std::endl; }}; @@ -10046,7 +10046,7 @@ console_cmd__user__presence(opt &out, const string_view &line) { out << timestr(at<"origin_server_ts"_>(event) / 1000) << " " << at<"content"_>(event) - << " " << at<"event_id"_>(event) + << " " << event.event_id << std::endl; return --limit > 0; @@ -10142,7 +10142,7 @@ console_cmd__user__read(opt &out, const string_view &line) out << timestr(at<"origin_server_ts"_>(event) / 1000) << " " << at<"state_key"_>(event) << " " << at<"content"_>(event) - << " " << at<"event_id"_>(event) + << " " << event.event_id << std::endl; }}); @@ -10456,7 +10456,7 @@ console_cmd__user__tokens(opt &out, const string_view &line) { const auto eid { - m::redact(m::user::tokens, user.user_id, at<"event_id"_>(event), "cleared") + m::redact(m::user::tokens, user.user_id, event.event_id, "cleared") }; out << " - cleared by " << eid; diff --git a/modules/federation/invite2.cc b/modules/federation/invite2.cc index 1c7e9b25b..d3e109de8 100644 --- a/modules/federation/invite2.cc +++ b/modules/federation/invite2.cc @@ -237,7 +237,7 @@ try vmopts.fetch_prev_check = false; vmopts.fetch_prev = false; - vmopts.non_conform |= m::event::conforms::INVALID_OR_MISSING_EVENT_ID; + // Don't throw an exception for a re-evaluation; this will just be a no-op vmopts.nothrows |= m::vm::fault::EXISTS; m::vm::eval diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc index 5a95a39cf..e0273439a 100644 --- a/modules/m_receipt.cc +++ b/modules/m_receipt.cc @@ -437,7 +437,7 @@ try const m::event::id &event_id { - at<"event_id"_>(event) + event.event_id }; const time_t &ms diff --git a/modules/m_room_create.cc b/modules/m_room_create.cc index 98728b1b6..11b8073e5 100644 --- a/modules/m_room_create.cc +++ b/modules/m_room_create.cc @@ -22,7 +22,7 @@ _can_create_room(const m::event &event, { const m::event::id &event_id { - at<"event_id"_>(event) + event.event_id }; const m::room::id &room_id @@ -43,12 +43,12 @@ _can_create_room(const m::event &event, sender.host() }; - if(room_id.host() != event_id.host()) + if(room_id.host() != sender.host()) throw m::ACCESS_DENIED { "Room on '%s' cannot be created by event from '%s'", room_id.host(), - event_id.host() + sender.host() }; if(room_id.host() != at<"origin"_>(event)) @@ -111,7 +111,7 @@ _created_room(const m::event &event, m::log, "Creation of room %s by %s (%s)", string_view{room_id}, at<"sender"_>(event), - at<"event_id"_>(event) + string_view{event.event_id}, }; } diff --git a/modules/m_vm.cc b/modules/m_vm.cc index 17219c5b3..c1cda1f88 100644 --- a/modules/m_vm.cc +++ b/modules/m_vm.cc @@ -503,13 +503,6 @@ try if(opts.conform) call_hook(conform_hook, eval, event, eval); - if(json::get<"event_id"_>(event)) - if(event.event_id != json::get<"event_id"_>(event)) - throw error - { - fault::INVALID, "event.event_id not set." - }; - const fault ret { event.event_id?