2019-02-12 20:03:59 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_ROOM_AUTH_H
|
|
|
|
|
|
|
|
/// Interface to the auth_chain / auth_dag.
|
|
|
|
///
|
|
|
|
struct ircd::m::room::auth
|
|
|
|
{
|
2019-08-18 08:19:05 +02:00
|
|
|
struct refs;
|
|
|
|
struct chain;
|
|
|
|
struct hookdata;
|
2019-03-06 07:49:05 +01:00
|
|
|
using types = vector_view<const string_view>;
|
2019-08-18 08:19:05 +02:00
|
|
|
using events_view = vector_view<const event *>;
|
|
|
|
using passfail = std::tuple<bool, std::exception_ptr>;
|
2019-08-21 07:15:21 +02:00
|
|
|
IRCD_M_EXCEPTION(m::error, error, http::INTERNAL_SERVER_ERROR)
|
2019-08-18 08:19:05 +02:00
|
|
|
IRCD_M_EXCEPTION(error, FAIL, http::UNAUTHORIZED)
|
2019-03-06 07:49:05 +01:00
|
|
|
|
2019-08-18 08:19:05 +02:00
|
|
|
static bool is_power_event(const event &);
|
|
|
|
|
|
|
|
static passfail check(std::nothrow_t, const event &, hookdata &);
|
|
|
|
static passfail check(std::nothrow_t, const event &);
|
|
|
|
static void check(const event &);
|
|
|
|
|
|
|
|
static bool generate(json::stack::array &, const m::room &, const m::event &);
|
|
|
|
static json::array generate(const mutable_buffer &, const m::room &, const m::event &);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Interface to the references made by other power events to this power
|
|
|
|
/// event in the `auth_events`. This interface only deals with power events,
|
|
|
|
/// it doesn't care if a non-power event referenced a power event. This does
|
|
|
|
/// not contain the auth-chain or state resolution algorithm here, those are
|
|
|
|
/// later constructed out of this data.
|
|
|
|
struct ircd::m::room::auth::refs
|
|
|
|
{
|
|
|
|
event::idx idx;
|
2019-02-12 20:03:59 +01:00
|
|
|
|
2019-03-06 07:49:05 +01:00
|
|
|
public:
|
2019-08-18 08:19:05 +02:00
|
|
|
using closure_bool = event::closure_idx_bool;
|
|
|
|
|
|
|
|
bool for_each(const string_view &type, const closure_bool &) const;
|
|
|
|
bool for_each(const closure_bool &) const;
|
|
|
|
|
2019-08-21 07:19:24 +02:00
|
|
|
bool has(const string_view &type) const;
|
|
|
|
bool has(const event::idx &) const;
|
2019-03-06 07:49:05 +01:00
|
|
|
|
2019-08-21 07:19:24 +02:00
|
|
|
size_t count(const string_view &type) const;
|
|
|
|
size_t count() const;
|
2019-08-18 08:19:05 +02:00
|
|
|
|
|
|
|
refs(const event::idx &idx)
|
|
|
|
:idx{idx}
|
2019-02-12 20:03:59 +01:00
|
|
|
{}
|
|
|
|
};
|
2019-08-18 08:19:05 +02:00
|
|
|
|
|
|
|
struct ircd::m::room::auth::chain
|
|
|
|
{
|
2019-08-18 14:38:44 +02:00
|
|
|
using closure = event::closure_idx_bool;
|
2019-08-18 08:19:05 +02:00
|
|
|
|
|
|
|
event::idx idx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool for_each(const closure &) const;
|
2019-08-21 07:19:24 +02:00
|
|
|
bool has(const string_view &type) const;
|
|
|
|
size_t depth() const;
|
2019-08-18 08:19:05 +02:00
|
|
|
|
|
|
|
chain(const event::idx &idx)
|
|
|
|
:idx{idx}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ircd::m::room::auth::hookdata
|
|
|
|
{
|
|
|
|
const event *find(const event::closure_bool &) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
event::prev prev;
|
|
|
|
vector_view<const event *> auth_events;
|
|
|
|
const event *auth_create {nullptr};
|
|
|
|
const event *auth_power {nullptr};
|
|
|
|
const event *auth_join_rules {nullptr};
|
|
|
|
const event *auth_member_target {nullptr};
|
|
|
|
const event *auth_member_sender {nullptr};
|
|
|
|
|
|
|
|
bool allow {false};
|
|
|
|
std::exception_ptr fail;
|
|
|
|
|
|
|
|
hookdata(const event &, const events_view &auth_events);
|
|
|
|
hookdata() = default;
|
|
|
|
};
|