conftypes.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * @file conftypes.h
  8. * @brief Types used to specify configurable options.
  9. *
  10. * This header defines the types that different modules will use in order to
  11. * declare their configuration and state variables, and tell the configuration
  12. * management code about those variables. From the individual module's point
  13. * of view, its configuration and state are simply data structures.
  14. *
  15. * For defining new variable types, see var_type_def_st.h.
  16. *
  17. * For the code that manipulates variables defined via this module, see
  18. * lib/confmgt/, especially typedvar.h and (later) structvar.h. The
  19. * configuration manager is responsible for encoding, decoding, and
  20. * maintaining the configuration structures used by the various modules.
  21. *
  22. * STATUS NOTE: This is a work in process refactoring. It is not yet possible
  23. * for modules to define their own variables, and much of the configuration
  24. * management code is still in src/app/config/.
  25. **/
  26. #ifndef TOR_SRC_LIB_CONF_CONFTYPES_H
  27. #define TOR_SRC_LIB_CONF_CONFTYPES_H
  28. #include "lib/cc/torint.h"
  29. #ifdef TOR_UNIT_TESTS
  30. #include "lib/conf/conftesting.h"
  31. #endif
  32. #include <stddef.h>
  33. /** Enumeration of types which option values can take */
  34. typedef enum config_type_t {
  35. CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
  36. CONFIG_TYPE_FILENAME, /**< A filename: some prefixes get expanded. */
  37. CONFIG_TYPE_POSINT, /**< A non-negative integer less than MAX_INT */
  38. CONFIG_TYPE_INT, /**< Any integer. */
  39. CONFIG_TYPE_UINT64, /**< A value in range 0..UINT64_MAX */
  40. CONFIG_TYPE_INTERVAL, /**< A number of seconds, with optional units*/
  41. CONFIG_TYPE_MSEC_INTERVAL,/**< A number of milliseconds, with optional
  42. * units */
  43. CONFIG_TYPE_MEMUNIT, /**< A number of bytes, with optional units*/
  44. CONFIG_TYPE_DOUBLE, /**< A floating-point value */
  45. CONFIG_TYPE_BOOL, /**< A boolean value, expressed as 0 or 1. */
  46. CONFIG_TYPE_AUTOBOOL, /**< A boolean+auto value, expressed 0 for false,
  47. * 1 for true, and -1 for auto */
  48. CONFIG_TYPE_ISOTIME, /**< An ISO-formatted time relative to UTC. */
  49. CONFIG_TYPE_CSV, /**< A list of strings, separated by commas and
  50. * optional whitespace. */
  51. CONFIG_TYPE_CSV_INTERVAL, /**< A list of strings, separated by commas and
  52. * optional whitespace, representing intervals in
  53. * seconds, with optional units. We allow
  54. * multiple values here for legacy reasons, but
  55. * ignore every value after the first. */
  56. CONFIG_TYPE_LINELIST, /**< Uninterpreted config lines */
  57. CONFIG_TYPE_LINELIST_S, /**< Uninterpreted, context-sensitive config lines,
  58. * mixed with other keywords. */
  59. CONFIG_TYPE_LINELIST_V, /**< Catch-all "virtual" option to summarize
  60. * context-sensitive config lines when fetching.
  61. */
  62. CONFIG_TYPE_OBSOLETE, /**< Obsolete (ignored) option. */
  63. CONFIG_TYPE_EXTENDED, /**< Extended type; definition will appear in
  64. * pointer. */
  65. } config_type_t;
  66. /* Forward delcaration for var_type_def_t, for extended types. */
  67. struct var_type_def_t;
  68. /** Structure to specify a named, typed member within a structure. */
  69. typedef struct struct_member_t {
  70. /** Name of the field. */
  71. const char *name;
  72. /** Type of the field, according to the config_type_t enumeration.
  73. *
  74. * This value is CONFIG_TYPE_EXTENDED for any type not listed in
  75. * config_type_t.
  76. **/
  77. config_type_t type;
  78. /**
  79. * Pointer to a type definition for the type of this field. Overrides
  80. * <b>type</b> if not NULL.
  81. **/
  82. const struct var_type_def_t *type_def;
  83. /**
  84. * Offset of this field within the structure. Compute this with
  85. * offsetof(structure, fieldname).
  86. **/
  87. ptrdiff_t offset;
  88. } struct_member_t;
  89. /**
  90. * Structure to describe the location and preferred value of a "magic number"
  91. * field within a structure.
  92. *
  93. * These 'magic numbers' are 32-bit values used to tag objects to make sure
  94. * that they have the correct type.
  95. */
  96. typedef struct struct_magic_decl_t {
  97. const char *typename;
  98. uint32_t magic_val;
  99. ptrdiff_t magic_offset;
  100. } struct_magic_decl_t;
  101. /**
  102. * Flag to indicate that an option is obsolete. Any attempt to set or
  103. * fetch this option should produce a warning.
  104. **/
  105. #define CVFLAG_OBSOLETE (1u<<0)
  106. /**
  107. * Flag to indicate that an option is undumpable. An undumpable option is
  108. * never saved to disk. For historical reasons it is prefixed with __ but
  109. * not with ___.
  110. **/
  111. #define CVFLAG_NODUMP (1u<<1)
  112. /**
  113. * Flag to indicate that an option is "invisible". An invisible option
  114. * is always undumpable, and we don't tell the controller about it.
  115. * For historical reasons it is prefixed with ___.
  116. **/
  117. #define CVFLAG_INVISIBLE (1u<<2)
  118. /** A variable allowed in the configuration file or on the command line. */
  119. typedef struct config_var_t {
  120. struct_member_t member; /** A struct member corresponding to this
  121. * variable. */
  122. const char *initvalue; /**< String (or null) describing initial value. */
  123. uint32_t flags; /**< One or more flags describing special handling for this
  124. * variable */
  125. #ifdef TOR_UNIT_TESTS
  126. /** Used for compiler-magic to typecheck the corresponding field in the
  127. * corresponding struct. Only used in unit test mode, at compile-time. */
  128. confparse_dummy_values_t var_ptr_dummy;
  129. #endif
  130. } config_var_t;
  131. #endif /* !defined(TOR_SRC_LIB_CONF_CONFTYPES_H) */