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