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_RESOURCE_H
|
|
|
|
|
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
struct client;
|
|
|
|
struct resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The target of an HTTP request specified by clients with a path.
|
|
|
|
///
|
|
|
|
struct ircd::resource
|
2022-07-14 21:41:12 +02:00
|
|
|
:instance_map<string_view, resource, iless>
|
2019-02-18 19:40:21 +01:00
|
|
|
{
|
|
|
|
IRCD_EXCEPTION(ircd::error, error)
|
|
|
|
|
|
|
|
enum flag :uint;
|
|
|
|
struct opts;
|
|
|
|
struct method;
|
|
|
|
struct request;
|
|
|
|
struct response;
|
2019-02-19 20:36:31 +01:00
|
|
|
struct redirect;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
static log::log log;
|
|
|
|
|
|
|
|
string_view path;
|
|
|
|
std::unique_ptr<const struct opts> opts;
|
|
|
|
std::map<string_view, method *> methods;
|
2019-04-01 03:51:59 +02:00
|
|
|
std::unique_ptr<method> default_method_head;
|
|
|
|
std::unique_ptr<method> default_method_options;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
2022-07-18 06:39:10 +02:00
|
|
|
private:
|
2019-04-01 04:15:45 +02:00
|
|
|
using method_closure = std::function<bool (const method &)>;
|
|
|
|
string_view method_list(const mutable_buffer &buf, const method_closure &) const;
|
|
|
|
string_view method_list(const mutable_buffer &buf) const;
|
2019-04-01 03:51:59 +02:00
|
|
|
response handle_options(client &, const request &) const;
|
|
|
|
response handle_head(client &, const request &) const;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
method &operator[](const string_view &name) const;
|
2022-07-18 06:39:10 +02:00
|
|
|
virtual resource &route(const string_view &path) const;
|
|
|
|
virtual string_view params(const string_view &path) const;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
resource(const string_view &path, struct opts);
|
|
|
|
resource(const string_view &path);
|
2022-07-14 21:41:12 +02:00
|
|
|
resource(resource &&) = delete;
|
|
|
|
resource(const resource &) = delete;
|
2022-07-18 06:39:10 +02:00
|
|
|
virtual ~resource() noexcept;
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
static resource &find(const string_view &path);
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "method.h"
|
|
|
|
#include "request.h"
|
|
|
|
#include "response.h"
|
2019-02-19 20:36:31 +01:00
|
|
|
#include "redirect.h"
|
2019-02-18 19:40:21 +01:00
|
|
|
|
|
|
|
enum ircd::resource::flag
|
|
|
|
:uint
|
|
|
|
{
|
2019-04-01 03:51:59 +02:00
|
|
|
DIRECTORY = 0x01,
|
|
|
|
OVERRIDE_HEAD = 0x02,
|
|
|
|
OVERRIDE_OPTIONS = 0x04,
|
2019-02-18 19:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::resource::opts
|
|
|
|
{
|
|
|
|
/// developer's literal description of the resource
|
|
|
|
string_view description
|
|
|
|
{
|
|
|
|
"no description"
|
|
|
|
};
|
|
|
|
|
|
|
|
/// flags for the resource
|
|
|
|
flag flags
|
|
|
|
{
|
|
|
|
flag(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
/// parameter count limits (DIRECTORY only)
|
|
|
|
std::pair<short, short> parc
|
|
|
|
{
|
|
|
|
0, // minimum params
|
|
|
|
15 // maximum params
|
|
|
|
};
|
|
|
|
};
|