2 * Copyright (c) 2014-present, Facebook, Inc.
5 * This source code is licensed in accordance with the terms specified in
6 * the LICENSE file found in the root directory of this source tree.
11 #include <boost/lexical_cast.hpp>
13 #include <osquery/flags.h>
16 /// We define a lexical_cast template for boolean for Gflags boolean string
19 bool lexical_cast<bool, std::string>(const std::string& arg);
22 std::string lexical_cast<std::string, bool>(const bool& arg);
27 * @brief Helper accessor/assignment alias class to support deprecated flags.
29 * This templated class wraps Flag::updateValue and Flag::getValue to 'alias'
30 * a deprecated flag name as the updated name. The helper macro FLAG_ALIAS
31 * will create a global variable instances of this wrapper using the same
32 * Gflags naming scheme to prevent collisions and support existing callsites.
37 FlagAlias& operator=(T const& v) {
38 Flag::updateValue(name_, boost::lexical_cast<std::string>(v));
42 /*explicit*/ operator T() const {
43 return boost::lexical_cast<T>(Flag::getValue(name_));
46 FlagAlias(const std::string& /*alias*/,
47 const std::string& /*type*/,
50 : name_(std::move(name)) {}
53 /// Friendly flag name.
56 } // namespace osquery
59 * @brief Create an alias to a command line flag.
61 * Like OSQUERY_FLAG, do not use this in the osquery codebase. Use the derived
62 * macros that abstract the tail of boolean arguments.
64 #define OSQUERY_FLAG_ALIAS(t, a, n, s, e) \
65 FlagAlias<t> FLAGS_##a(#a, #t, #n, &FLAGS_##n); \
67 static GFLAGS_NAMESPACE::FlagRegisterer oflag_##a( \
68 #a, #a, #a, &FLAGS_##n, &FLAGS_##n); \
69 const int flag_alias_##a = Flag::createAlias(#a, {#n, s, e, 0, 1}); \
72 /// See FLAG, FLAG_ALIAS aliases a flag name to an existing FLAG.
73 #define FLAG_ALIAS(t, a, n) OSQUERY_FLAG_ALIAS(t, a, n, 0, 0)
75 /// See FLAG_ALIAS, SHELL_FLAG_ALIAS%es are only available in osqueryi.
76 #define SHELL_FLAG_ALIAS(t, a, n) _OSQUERY_FLAG_ALIAS(t, a, n, 1, 0)
78 /// See FLAG_ALIAS, EXTENSION_FLAG_ALIAS%es are only available to extensions.
79 #define EXTENSION_FLAG_ALIAS(a, n) OSQUERY_FLAG_ALIAS(std::string, a, n, 0, 1)