mirror of
https://github.com/Icinga/icinga2.git
synced 2026-03-21 18:11:32 -04:00
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' {} +
```
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#ifndef MACROPROCESSOR_H
|
|
#define MACROPROCESSOR_H
|
|
|
|
#include "icinga/i2-icinga.hpp"
|
|
#include "icinga/checkable.hpp"
|
|
#include "base/value.hpp"
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
namespace icinga
|
|
{
|
|
|
|
/**
|
|
* Resolves macros.
|
|
*
|
|
* @ingroup icinga
|
|
*/
|
|
class MacroProcessor
|
|
{
|
|
public:
|
|
struct ResolverSpec
|
|
{
|
|
String Name;
|
|
Object::Ptr Obj;
|
|
|
|
// Whether to resolve not only e.g. $host.address$, but also just $address$
|
|
bool ResolveShortMacros;
|
|
|
|
inline ResolverSpec(String name, Object::Ptr obj, bool resolveShortMacros = true)
|
|
: Name(std::move(name)), Obj(std::move(obj)), ResolveShortMacros(resolveShortMacros)
|
|
{
|
|
}
|
|
};
|
|
|
|
typedef std::function<Value (const Value&)> EscapeCallback;
|
|
typedef std::vector<ResolverSpec> ResolverList;
|
|
|
|
static Value ResolveMacros(const Value& str, const ResolverList& resolvers,
|
|
const CheckResult::Ptr& cr = nullptr, String *missingMacro = nullptr,
|
|
const EscapeCallback& escapeFn = EscapeCallback(),
|
|
const Dictionary::Ptr& resolvedMacros = nullptr,
|
|
bool useResolvedMacros = false, int recursionLevel = 0);
|
|
|
|
static Value ResolveArguments(const Value& command, const Dictionary::Ptr& arguments,
|
|
const MacroProcessor::ResolverList& resolvers, const CheckResult::Ptr& cr,
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel = 0);
|
|
|
|
static bool ValidateMacroString(const String& macro);
|
|
static void ValidateCustomVars(const ConfigObject::Ptr& object, const Dictionary::Ptr& value);
|
|
|
|
private:
|
|
MacroProcessor();
|
|
|
|
static bool ResolveMacro(const String& macro, const ResolverList& resolvers,
|
|
const CheckResult::Ptr& cr, Value *result, bool *recursive_macro);
|
|
static Value InternalResolveMacros(const String& str,
|
|
const ResolverList& resolvers, const CheckResult::Ptr& cr,
|
|
String *missingMacro, const EscapeCallback& escapeFn,
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros,
|
|
int recursionLevel = 0);
|
|
static Value EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
|
|
const CheckResult::Ptr& cr,
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel);
|
|
|
|
static void AddArgumentHelper(const Array::Ptr& args, const String& key, const String& value,
|
|
bool add_key, bool add_value, const Value& separator);
|
|
static Value EscapeMacroShellArg(const Value& value);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* MACROPROCESSOR_H */
|