conftypes.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /**
  64. * Extended type: definition appears in the <b>type_def</b> pointer
  65. * of the corresponding struct_member_t.
  66. *
  67. * For some types, we cannot define them as particular values of this
  68. * enumeration, since those types are abstractions defined at a higher level
  69. * than this module. (For example, parsing a routerset_t is higher-level
  70. * than this module.) To handle this, we use CONFIG_TYPE_EXTENDED for those
  71. * types, and give a definition for them in the struct_member_t.type_def.
  72. **/
  73. CONFIG_TYPE_EXTENDED,
  74. } config_type_t;
  75. /* Forward delcaration for var_type_def_t, for extended types. */
  76. struct var_type_def_t;
  77. /** Structure to specify a named, typed member within a structure. */
  78. typedef struct struct_member_t {
  79. /** Name of the field. */
  80. const char *name;
  81. /**
  82. * Type of the field, according to the config_type_t enumeration.
  83. *
  84. * For any type not otherwise listed in config_type_t, this field's value
  85. * should be CONFIG_TYPE_EXTENDED. When it is, the <b>type_def</b> pointer
  86. * must be set.
  87. **/
  88. /*
  89. * NOTE: In future refactoring, we might remove this field entirely, along
  90. * with its corresponding enumeration. In that case, we will require that
  91. * type_def be set in all cases. If we do, we will also need a new mechanism
  92. * to enforce consistency between configuration variable types and their
  93. * corresponding structures, since our current design in
  94. * lib/conf/conftesting.h won't work any more.
  95. */
  96. config_type_t type;
  97. /**
  98. * Pointer to a type definition for the type of this field. Overrides
  99. * <b>type</b> if it is not NULL. Must be set when <b>type</b> is
  100. * CONFIG_TYPE_EXTENDED.
  101. **/
  102. const struct var_type_def_t *type_def;
  103. /**
  104. * Offset of this field within the structure. Compute this with
  105. * offsetof(structure, fieldname).
  106. **/
  107. ptrdiff_t offset;
  108. } struct_member_t;
  109. /**
  110. * Structure to describe the location and preferred value of a "magic number"
  111. * field within a structure.
  112. *
  113. * These 'magic numbers' are 32-bit values used to tag objects to make sure
  114. * that they have the correct type.
  115. */
  116. typedef struct struct_magic_decl_t {
  117. /** The name of the structure */
  118. const char *typename;
  119. /** A value used to recognize instances of this structure. */
  120. uint32_t magic_val;
  121. /** The location within the structure at which we expect to find
  122. * <b>magic_val</b>. */
  123. ptrdiff_t magic_offset;
  124. } struct_magic_decl_t;
  125. /**
  126. * Flag to indicate that an option or type is "undumpable". An
  127. * undumpable option is never saved to disk.
  128. *
  129. * For historical reasons its name is usually is prefixed with __.
  130. **/
  131. #define CFLG_NODUMP (1u<<0)
  132. /**
  133. * Flag to indicate that an option or type is "unlisted".
  134. *
  135. * We don't tell the controller about unlisted options when it asks for a
  136. * list of them.
  137. **/
  138. #define CFLG_NOLIST (1u<<1)
  139. /**
  140. * Flag to indicate that an option or type is "unsettable".
  141. *
  142. * An unsettable option can never be set directly by name.
  143. **/
  144. #define CFLG_NOSET (1u<<2)
  145. /**
  146. * Flag to indicate that an option or type does not need to be copied when
  147. * copying the structure that contains it.
  148. *
  149. * (Usually, if an option does not need to be copied, then either it contains
  150. * no data, or the data that it does contain is completely contained within
  151. * another option.)
  152. **/
  153. #define CFLG_NOCOPY (1u<<3)
  154. /**
  155. * Flag to indicate that an option or type does not need to be compared
  156. * when telling the controller about the differences between two
  157. * configurations.
  158. *
  159. * (Usually, if an option does not need to be compared, then either it
  160. * contains no data, or the data that it does contain is completely contained
  161. * within another option.)
  162. **/
  163. #define CFLG_NOCMP (1u<<4)
  164. /**
  165. * Flag to indicate that an option or type should not be replaced when setting
  166. * it.
  167. *
  168. * For most options, setting them replaces their old value. For some options,
  169. * however, setting them appends to their old value.
  170. */
  171. #define CFLG_NOREPLACE (1u<<5)
  172. /**
  173. * A group of flags that should be set on all obsolete options and types.
  174. **/
  175. #define CFLG_GROUP_OBSOLETE \
  176. (CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST)
  177. /** A variable allowed in the configuration file or on the command line. */
  178. typedef struct config_var_t {
  179. struct_member_t member; /** A struct member corresponding to this
  180. * variable. */
  181. const char *initvalue; /**< String (or null) describing initial value. */
  182. uint32_t flags; /**< One or more flags describing special handling for this
  183. * variable */
  184. #ifdef TOR_UNIT_TESTS
  185. /** Used for compiler-magic to typecheck the corresponding field in the
  186. * corresponding struct. Only used in unit test mode, at compile-time. */
  187. confparse_dummy_values_t var_ptr_dummy;
  188. #endif
  189. } config_var_t;
  190. #endif /* !defined(TOR_SRC_LIB_CONF_CONFTYPES_H) */