Add roadmap for tizen-6.0
[platform/core/security/vist.git] / src / osquery / include / osquery / flagalias.h
1 /**
2  *  Copyright (c) 2014-present, Facebook, Inc.
3  *  All rights reserved.
4  *
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.
7  */
8
9 #pragma once
10
11 #include <boost/lexical_cast.hpp>
12
13 #include <osquery/flags.h>
14
15 namespace boost {
16 /// We define a lexical_cast template for boolean for Gflags boolean string
17 /// values.
18 template <>
19 bool lexical_cast<bool, std::string>(const std::string& arg);
20
21 template <>
22 std::string lexical_cast<std::string, bool>(const bool& arg);
23 } // namespace boost
24
25 namespace osquery {
26 /**
27  * @brief Helper accessor/assignment alias class to support deprecated flags.
28  *
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.
33  */
34 template <typename T>
35 class FlagAlias {
36  public:
37   FlagAlias& operator=(T const& v) {
38     Flag::updateValue(name_, boost::lexical_cast<std::string>(v));
39     return *this;
40   }
41
42   /*explicit*/ operator T() const {
43     return boost::lexical_cast<T>(Flag::getValue(name_));
44   }
45
46   FlagAlias(const std::string& /*alias*/,
47             const std::string& /*type*/,
48             std::string name,
49             T* /*storage*/)
50       : name_(std::move(name)) {}
51
52  private:
53   /// Friendly flag name.
54   std::string name_;
55 };
56 } // namespace osquery
57
58 /**
59  * @brief Create an alias to a command line flag.
60  *
61  * Like OSQUERY_FLAG, do not use this in the osquery codebase. Use the derived
62  * macros that abstract the tail of boolean arguments.
63  */
64 #define OSQUERY_FLAG_ALIAS(t, a, n, s, e)                                      \
65   FlagAlias<t> FLAGS_##a(#a, #t, #n, &FLAGS_##n);                              \
66   namespace flags {                                                            \
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});          \
70   }
71
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)
74
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)
77
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)