2019-02-18 19:40:21 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 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_RESOURCE_METHOD_H
|
|
|
|
|
|
|
|
struct ircd::resource::method
|
|
|
|
{
|
|
|
|
enum flag :uint;
|
|
|
|
struct opts;
|
|
|
|
struct stats;
|
|
|
|
using handler = std::function<response (client &, request &)>;
|
|
|
|
|
2020-06-08 23:19:55 +02:00
|
|
|
static conf::item<seconds> default_timeout;
|
|
|
|
static conf::item<size_t> default_payload_max;
|
2019-02-28 02:43:39 +01:00
|
|
|
static ctx::dock idle_dock;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
struct resource *resource;
|
|
|
|
string_view name;
|
|
|
|
handler function;
|
|
|
|
std::unique_ptr<const struct opts> opts;
|
|
|
|
std::unique_ptr<struct stats> stats;
|
|
|
|
unique_const_iterator<decltype(resource::methods)> methods_it;
|
|
|
|
|
2020-06-08 23:59:12 +02:00
|
|
|
bool content_length_acceptable(const http::request::head &) const;
|
|
|
|
bool mime_type_acceptable(const http::request::head &) const;
|
|
|
|
|
2019-02-18 19:40:21 +01:00
|
|
|
void handle_timeout(client &) const;
|
2019-09-28 23:17:54 +02:00
|
|
|
response call_handler(client &, request &);
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
public:
|
2019-09-28 23:17:54 +02:00
|
|
|
response operator()(client &, const http::request::head &, const string_view &content_partial);
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
method(struct resource &, const string_view &name, handler, struct opts);
|
|
|
|
method(struct resource &, const string_view &name, handler);
|
|
|
|
~method() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ircd::resource::method::flag
|
|
|
|
:uint
|
|
|
|
{
|
2019-12-03 02:50:11 +01:00
|
|
|
REQUIRES_AUTH = 0x01, //TODO: matrix abstraction bleed.
|
2019-02-18 19:40:21 +01:00
|
|
|
RATE_LIMITED = 0x02,
|
2019-12-03 02:50:11 +01:00
|
|
|
VERIFY_ORIGIN = 0x04, //TODO: matrix abstraction bleed.
|
2019-02-18 19:40:21 +01:00
|
|
|
CONTENT_DISCRETION = 0x08,
|
2020-12-25 03:05:40 +01:00
|
|
|
DELAYED_ACK = 0x10,
|
2020-12-25 09:10:14 +01:00
|
|
|
DELAYED_RESPONSE = 0x20,
|
2019-02-18 19:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::resource::method::opts
|
|
|
|
{
|
|
|
|
flag flags {(flag)0};
|
|
|
|
|
2020-06-08 23:19:55 +02:00
|
|
|
/// Timeout specific to this resource; 0 is automatic
|
|
|
|
seconds timeout {0};
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
/// The maximum size of the Content-Length for this method. Anything
|
2020-06-08 23:19:55 +02:00
|
|
|
/// larger will be summarily rejected with a 413. -1 is automatic.
|
|
|
|
size_t payload_max {-1UL};
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
/// MIME type; first part is the Registry (i.e application) and second
|
|
|
|
/// part is the format (i.e json). Empty value means nothing rejected.
|
|
|
|
std::pair<string_view, string_view> mime;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::resource::method::stats
|
|
|
|
{
|
2020-12-18 06:22:43 +01:00
|
|
|
using item = ircd::stats::item<uint64_t>;
|
|
|
|
|
|
|
|
item pending; ///< Clients currently inside the method
|
|
|
|
item requests; ///< The method was found and called.
|
|
|
|
item timeouts; ///< The method's timeout was exceeded.
|
|
|
|
item completions; ///< The handler returned without throwing.
|
|
|
|
item internal_errors; ///< The handler threw a very bad exception.
|
|
|
|
|
|
|
|
stats(method &);
|
2019-02-18 19:40:21 +01:00
|
|
|
};
|