confmacros.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 confmacros.h
  8. * @brief Macro definitions for declaring configuration variables
  9. **/
  10. #ifndef TOR_LIB_CONF_CONFMACROS_H
  11. #define TOR_LIB_CONF_CONFMACROS_H
  12. #include "orconfig.h"
  13. #include "lib/conf/conftesting.h"
  14. /**
  15. * Used to indicate the end of an array of configuration variables.
  16. **/
  17. #define END_OF_CONFIG_VARS \
  18. { { .name = NULL }, NULL DUMMY_CONF_TEST_MEMBERS }
  19. /**
  20. * Declare a config_var_t as a member named <b>membername</b> of the structure
  21. * <b>structtype</b>, whose user-visible name is <b>varname</b>, whose
  22. * type corresponds to the config_type_t member CONFIG_TYPE_<b>vartype</b>,
  23. * and whose initial value is <b>intval</b>.
  24. *
  25. * Most modules that use this macro should wrap it in a local macro that
  26. * sets structtype to the local configuration type.
  27. **/
  28. #define CONFIG_VAR_ETYPE(structtype, varname, vartype, membername, initval) \
  29. { .member = \
  30. { .name = varname, \
  31. .type = CONFIG_TYPE_ ## vartype, \
  32. .offset = offsetof(structtype, membername), \
  33. }, \
  34. .initvalue = initval \
  35. CONF_TEST_MEMBERS(structtype, vartype, membername) \
  36. }
  37. /**
  38. * As CONFIG_VAR_XTYPE, but declares a value using an extension type whose
  39. * type definition is <b>vartype</b>_type_defn.
  40. **/
  41. #define CONFIG_VAR_DEFN(structtype, varname, vartype, membername, initval) \
  42. { .member = \
  43. { .name = varname, \
  44. .type = CONFIG_TYPE_EXTENDED, \
  45. .type_def = &vartype ## _type_defn, \
  46. .offset = offsetof(structtype, membername), \
  47. }, \
  48. .initvalue = initval \
  49. CONF_TEST_MEMBERS(structtype, vartype, membername) \
  50. }
  51. #define CONFIG_VAR_OBSOLETE(varname) \
  52. { .member = { .name = varname, .type = CONFIG_TYPE_OBSOLETE } }
  53. #endif /* !defined(TOR_LIB_CONF_CONFMACROS_H) */