confline.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_append_line(config_line_t **lst, config_line_t *newline);
  37. void config_line_prepend(config_line_t **lst,
  38. const char *key, const char *val);
  39. config_line_t *config_lines_dup(const config_line_t *inp);
  40. config_line_t *config_lines_dup_and_filter(const config_line_t *inp,
  41. const char *key);
  42. const config_line_t *config_line_find(const config_line_t *lines,
  43. const char *key);
  44. const config_line_t *config_line_find_case(const config_line_t *lines,
  45. const char *key);
  46. int config_lines_eq(const config_line_t *a, const config_line_t *b);
  47. int config_count_key(const config_line_t *a, const char *key);
  48. void config_free_lines_(config_line_t *front);
  49. #define config_free_lines(front) \
  50. do { \
  51. config_free_lines_(front); \
  52. (front) = NULL; \
  53. } while (0)
  54. const char *parse_config_line_from_str_verbose(const char *line,
  55. char **key_out, char **value_out,
  56. const char **err_out);
  57. int config_get_lines(const char *string, struct config_line_t **result,
  58. int extended);
  59. typedef int (*include_handler_fn)(const char *, int, int,
  60. struct config_line_t **,
  61. struct config_line_t **,
  62. struct smartlist_t *);
  63. int config_get_lines_aux(const char *string, struct config_line_t **result,
  64. int extended,
  65. int allow_include, int *has_include,
  66. struct smartlist_t *opened_lst, int recursion_level,
  67. config_line_t **last,
  68. include_handler_fn handle_include);
  69. #endif /* !defined(TOR_CONFLINE_H) */