icinga2/lib/remote/apiaction.hpp

67 lines
1.7 KiB
C++
Raw Permalink Normal View History

Replace all existing copyright headers with `SPDX` headers I've used the following command to replace the original copyright header lines in a C-style comment block: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` For files that use shell-style comments (#) like CMakeLists.txt, I've used this command: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` And for SQL files: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ```
2026-01-27 09:06:40 -05:00
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef APIACTION_H
#define APIACTION_H
#include "remote/i2-remote.hpp"
#include "base/registry.hpp"
#include "base/value.hpp"
#include "base/dictionary.hpp"
#include "base/configobject.hpp"
#include "remote/apiuser.hpp"
#include <vector>
#include <boost/algorithm/string/replace.hpp>
namespace icinga
{
/**
* An action available over the external HTTP API.
*
* @ingroup remote
*/
2018-01-04 00:11:04 -05:00
class ApiAction final : public Object
{
public:
DECLARE_PTR_TYPEDEFS(ApiAction);
typedef std::function<Value(const ConfigObject::Ptr& target, const ApiUser::Ptr&, const Dictionary::Ptr& params)> Callback;
ApiAction(std::vector<String> registerTypes, Callback function);
Value Invoke(const ConfigObject::Ptr& target, const ApiUser::Ptr& user, const Dictionary::Ptr& params);
const std::vector<String>& GetTypes() const;
static ApiAction::Ptr GetByName(const String& name);
static void Register(const String& name, const ApiAction::Ptr& action);
private:
std::vector<String> m_Types;
Callback m_Callback;
};
/**
* A registry for API actions.
*
* @ingroup remote
*/
using ApiActionRegistry = Registry<ApiAction::Ptr>;
#define REGISTER_APIACTION(name, types, callback) \
INITIALIZE_ONCE([]() { \
String registerName = #name; \
boost::algorithm::replace_all(registerName, "_", "-"); \
std::vector<String> registerTypes; \
String typeNames = types; \
if (!typeNames.IsEmpty()) \
2018-01-04 12:24:45 -05:00
registerTypes = typeNames.Split(";"); \
ApiAction::Ptr action = new ApiAction(registerTypes, callback); \
ApiActionRegistry::GetInstance()->Register(registerName, action); \
})
}
#endif /* APIACTION_H */