conftypes.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /** Enumeration of types which option values can take */
  33. typedef enum config_type_t {
  34. CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
  35. CONFIG_TYPE_FILENAME, /**< A filename: some prefixes get expanded. */
  36. CONFIG_TYPE_POSINT, /**< A non-negative integer less than MAX_INT */
  37. CONFIG_TYPE_INT, /**< Any integer. */
  38. CONFIG_TYPE_UINT64, /**< A value in range 0..UINT64_MAX */
  39. CONFIG_TYPE_INTERVAL, /**< A number of seconds, with optional units*/
  40. CONFIG_TYPE_MSEC_INTERVAL,/**< A number of milliseconds, with optional
  41. * units */
  42. CONFIG_TYPE_MEMUNIT, /**< A number of bytes, with optional units*/
  43. CONFIG_TYPE_DOUBLE, /**< A floating-point value */
  44. CONFIG_TYPE_BOOL, /**< A boolean value, expressed as 0 or 1. */
  45. CONFIG_TYPE_AUTOBOOL, /**< A boolean+auto value, expressed 0 for false,
  46. * 1 for true, and -1 for auto */
  47. CONFIG_TYPE_ISOTIME, /**< An ISO-formatted time relative to UTC. */
  48. CONFIG_TYPE_CSV, /**< A list of strings, separated by commas and
  49. * optional whitespace. */
  50. CONFIG_TYPE_CSV_INTERVAL, /**< A list of strings, separated by commas and
  51. * optional whitespace, representing intervals in
  52. * seconds, with optional units. We allow
  53. * multiple values here for legacy reasons, but
  54. * ignore every value after the first. */
  55. CONFIG_TYPE_LINELIST, /**< Uninterpreted config lines */
  56. CONFIG_TYPE_LINELIST_S, /**< Uninterpreted, context-sensitive config lines,
  57. * mixed with other keywords. */
  58. CONFIG_TYPE_LINELIST_V, /**< Catch-all "virtual" option to summarize
  59. * context-sensitive config lines when fetching.
  60. */
  61. CONFIG_TYPE_OBSOLETE, /**< Obsolete (ignored) option. */
  62. CONFIG_TYPE_EXTENDED, /**< Extended type; definition will appear in
  63. * pointer. */
  64. } config_type_t;
  65. /* Forward delcaration for var_type_def_t, for extended types. */
  66. struct var_type_def_t;
  67. /** Structure to specify a named, typed member within a structure. */
  68. typedef struct struct_member_t {
  69. /** Name of the field. */
  70. const char *name;
  71. /** Type of the field, according to the config_type_t enumeration.
  72. *
  73. * This value is CONFIG_TYPE_EXTENDED for any type not listed in
  74. * config_type_t.
  75. **/
  76. config_type_t type;
  77. /**
  78. * Pointer to a type definition for the type of this field. Overrides
  79. * <b>type</b> if not NULL.
  80. **/
  81. const struct var_type_def_t *type_def;
  82. /**
  83. * Offset of this field within the structure. Compute this with
  84. * offsetof(structure, fieldname).
  85. **/
  86. int offset;
  87. } struct_member_t;
  88. /**
  89. * Structure to describe the location and preferred value of a "magic number"
  90. * field within a structure.
  91. *
  92. * These 'magic numbers' are 32-bit values used to tag objects to make sure
  93. * that they have the correct type.
  94. */
  95. typedef struct struct_magic_decl_t {
  96. const char *typename;
  97. uint32_t magic_val;
  98. int magic_offset;
  99. } struct_magic_decl_t;
  100. /** A variable allowed in the configuration file or on the command line. */
  101. typedef struct config_var_t {
  102. struct_member_t member; /** A struct member corresponding to this
  103. * variable. */
  104. const char *initvalue; /**< String (or null) describing initial value. */
  105. #ifdef TOR_UNIT_TESTS
  106. /** Used for compiler-magic to typecheck the corresponding field in the
  107. * corresponding struct. Only used in unit test mode, at compile-time. */
  108. confparse_dummy_values_t var_ptr_dummy;
  109. #endif
  110. } config_var_t;
  111. #endif /* !defined(TOR_SRC_LIB_CONF_CONFTYPES_H) */