conftypes.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /** Enumeration of types which option values can take */
  30. typedef enum config_type_t {
  31. CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
  32. CONFIG_TYPE_FILENAME, /**< A filename: some prefixes get expanded. */
  33. CONFIG_TYPE_POSINT, /**< A non-negative integer less than MAX_INT */
  34. CONFIG_TYPE_INT, /**< Any integer. */
  35. CONFIG_TYPE_UINT64, /**< A value in range 0..UINT64_MAX */
  36. CONFIG_TYPE_INTERVAL, /**< A number of seconds, with optional units*/
  37. CONFIG_TYPE_MSEC_INTERVAL,/**< A number of milliseconds, with optional
  38. * units */
  39. CONFIG_TYPE_MEMUNIT, /**< A number of bytes, with optional units*/
  40. CONFIG_TYPE_DOUBLE, /**< A floating-point value */
  41. CONFIG_TYPE_BOOL, /**< A boolean value, expressed as 0 or 1. */
  42. CONFIG_TYPE_AUTOBOOL, /**< A boolean+auto value, expressed 0 for false,
  43. * 1 for true, and -1 for auto */
  44. CONFIG_TYPE_ISOTIME, /**< An ISO-formatted time relative to UTC. */
  45. CONFIG_TYPE_CSV, /**< A list of strings, separated by commas and
  46. * optional whitespace. */
  47. CONFIG_TYPE_CSV_INTERVAL, /**< A list of strings, separated by commas and
  48. * optional whitespace, representing intervals in
  49. * seconds, with optional units. We allow
  50. * multiple values here for legacy reasons, but
  51. * ignore every value after the first. */
  52. CONFIG_TYPE_LINELIST, /**< Uninterpreted config lines */
  53. CONFIG_TYPE_LINELIST_S, /**< Uninterpreted, context-sensitive config lines,
  54. * mixed with other keywords. */
  55. CONFIG_TYPE_LINELIST_V, /**< Catch-all "virtual" option to summarize
  56. * context-sensitive config lines when fetching.
  57. */
  58. // XXXX this doesn't belong at this level of abstraction.
  59. CONFIG_TYPE_ROUTERSET, /**< A list of router names, addrs, and fps,
  60. * parsed into a routerset_t. */
  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. #ifdef TOR_UNIT_TESTS
  101. /**
  102. * Union used when building in test mode typechecking the members of a type
  103. * used with confparse.c. See CONF_CHECK_VAR_TYPE for a description of how
  104. * it is used. */
  105. typedef union {
  106. char **STRING;
  107. char **FILENAME;
  108. int *POSINT; /* yes, this is really an int, and not an unsigned int. For
  109. * historical reasons, many configuration values are restricted
  110. * to the range [0,INT_MAX], and stored in signed ints.
  111. */
  112. uint64_t *UINT64;
  113. int *INT;
  114. int *INTERVAL;
  115. int *MSEC_INTERVAL;
  116. uint64_t *MEMUNIT;
  117. double *DOUBLE;
  118. int *BOOL;
  119. int *AUTOBOOL;
  120. time_t *ISOTIME;
  121. struct smartlist_t **CSV;
  122. int *CSV_INTERVAL;
  123. struct config_line_t **LINELIST;
  124. struct config_line_t **LINELIST_S;
  125. struct config_line_t **LINELIST_V;
  126. // XXXX this doesn't belong at this level of abstraction.
  127. struct routerset_t **ROUTERSET;
  128. } confparse_dummy_values_t;
  129. #endif /* defined(TOR_UNIT_TESTS) */
  130. #endif /* !defined(TOR_SRC_LIB_CONF_CONFTYPES_H) */