confline.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 confline.h
  8. *
  9. * \brief Header for confline.c
  10. **/
  11. #ifndef TOR_CONFLINE_H
  12. #define TOR_CONFLINE_H
  13. struct smartlist_t;
  14. /** Ordinary configuration line. */
  15. #define CONFIG_LINE_NORMAL 0
  16. /** Appends to previous configuration for the same option, even if we
  17. * would ordinary replace it. */
  18. #define CONFIG_LINE_APPEND 1
  19. /* Removes all previous configuration for an option. */
  20. #define CONFIG_LINE_CLEAR 2
  21. #define MAX_INCLUDE_RECURSION_LEVEL 31
  22. /** A linked list of lines in a config file, or elsewhere */
  23. typedef struct config_line_t {
  24. char *key;
  25. char *value;
  26. struct config_line_t *next;
  27. /** What special treatment (if any) does this line require? */
  28. unsigned int command:2;
  29. /** If true, subsequent assignments to this linelist should replace
  30. * it, not extend it. Set only on the first item in a linelist in an
  31. * or_options_t. */
  32. unsigned int fragile:1;
  33. } config_line_t;
  34. void config_line_append(config_line_t **lst,
  35. const char *key, const char *val);
  36. void config_line_prepend(config_line_t **lst,
  37. const char *key, const char *val);
  38. config_line_t *config_lines_dup(const config_line_t *inp);
  39. config_line_t *config_lines_dup_and_filter(const config_line_t *inp,
  40. const char *key);
  41. const config_line_t *config_line_find(const config_line_t *lines,
  42. const char *key);
  43. const config_line_t *config_line_find_case(const config_line_t *lines,
  44. const char *key);
  45. int config_lines_eq(const config_line_t *a, const config_line_t *b);
  46. int config_count_key(const config_line_t *a, const char *key);
  47. void config_free_lines_(config_line_t *front);
  48. #define config_free_lines(front) \
  49. do { \
  50. config_free_lines_(front); \
  51. (front) = NULL; \
  52. } while (0)
  53. const char *parse_config_line_from_str_verbose(const char *line,
  54. char **key_out, char **value_out,
  55. const char **err_out);
  56. int config_get_lines(const char *string, struct config_line_t **result,
  57. int extended);
  58. typedef int (*include_handler_fn)(const char *, int, int,
  59. struct config_line_t **,
  60. struct config_line_t **,
  61. struct smartlist_t *);
  62. int config_get_lines_aux(const char *string, struct config_line_t **result,
  63. int extended,
  64. int allow_include, int *has_include,
  65. struct smartlist_t *opened_lst, int recursion_level,
  66. config_line_t **last,
  67. include_handler_fn handle_include);
  68. #endif /* !defined(TOR_CONFLINE_H) */