tor  0.4.2.1-alpha-dev
confparse.h
Go to the documentation of this file.
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 
13 #ifndef TOR_CONFPARSE_H
14 #define TOR_CONFPARSE_H
15 
16 #include "lib/conf/conftypes.h"
17 #include "lib/conf/confmacros.h"
19 
23 typedef struct config_abbrev_t {
25  const char *abbreviated;
27  const char *full;
31  int warn;
33 
37 typedef struct config_deprecation_t {
39  const char *name;
41  const char *why_deprecated;
43 
52 #define PLURAL(tok) { #tok, #tok "s", 0, 0 }
53 
71 typedef int (*validate_fn_t)(void *oldval,
72  void *newval,
73  void *default_val,
74  int from_setconf,
75  char **msg_out);
76 
77 struct config_mgr_t;
78 
89 typedef void (*clear_cfg_fn_t)(const struct config_mgr_t *mgr, void *obj);
90 
94 typedef struct config_format_t {
95  size_t size;
99  const config_deprecation_t *deprecations;
112 
119 typedef struct config_mgr_t config_mgr_t;
120 
121 config_mgr_t *config_mgr_new(const config_format_t *toplevel_fmt);
122 void config_mgr_free_(config_mgr_t *mgr);
124  const config_format_t *fmt);
126 #define config_mgr_free(mgr) \
127  FREE_AND_NULL(config_mgr_t, config_mgr_free_, (mgr))
128 struct smartlist_t *config_mgr_list_vars(const config_mgr_t *mgr);
130 
133 
143 #define CAL_USE_DEFAULTS (1u<<0)
144 
152 #define CAL_CLEAR_FIRST (1u<<1)
153 
156 #define CAL_WARN_DEPRECATIONS (1u<<2)
157 
158 void *config_new(const config_mgr_t *fmt);
159 void config_free_(const config_mgr_t *fmt, void *options);
160 #define config_free(mgr, options) do { \
161  config_free_((mgr), (options)); \
162  (options) = NULL; \
163  } while (0)
164 
166  const void *options, const char *key,
167  int escape_val);
168 int config_is_same(const config_mgr_t *fmt,
169  const void *o1, const void *o2,
170  const char *name);
172  const void *options1, const void *options2);
173 void config_init(const config_mgr_t *mgr, void *options);
174 void *config_dup(const config_mgr_t *mgr, const void *old);
175 char *config_dump(const config_mgr_t *mgr, const void *default_options,
176  const void *options, int minimal,
177  int comment_defaults);
178 bool config_check_ok(const config_mgr_t *mgr, const void *options,
179  int severity);
180 int config_assign(const config_mgr_t *mgr, void *options,
181  struct config_line_t *list,
182  unsigned flags, char **msg);
183 const char *config_find_deprecation(const config_mgr_t *mgr,
184  const char *key);
185 const char *config_find_option_name(const config_mgr_t *mgr,
186  const char *key);
187 const char *config_expand_abbrev(const config_mgr_t *mgr,
188  const char *option,
189  int command_line, int warn_obsolete);
190 void warn_deprecated_option(const char *what, const char *why);
191 
192 bool config_var_is_settable(const config_var_t *var);
193 bool config_var_is_listable(const config_var_t *var);
194 
195 /* Helper macros to compare an option across two configuration objects */
196 #define CFG_EQ_BOOL(a,b,opt) ((a)->opt == (b)->opt)
197 #define CFG_EQ_INT(a,b,opt) ((a)->opt == (b)->opt)
198 #define CFG_EQ_STRING(a,b,opt) (!strcmp_opt((a)->opt, (b)->opt))
199 #define CFG_EQ_SMARTLIST(a,b,opt) smartlist_strings_eq((a)->opt, (b)->opt)
200 #define CFG_EQ_LINELIST(a,b,opt) config_lines_eq((a)->opt, (b)->opt)
201 #define CFG_EQ_ROUTERSET(a,b,opt) routerset_equal((a)->opt, (b)->opt)
202 
203 #ifdef CONFPARSE_PRIVATE
204 STATIC void config_reset_line(const config_mgr_t *mgr, void *options,
205  const char *key, int use_defaults);
206 STATIC void *config_mgr_get_obj_mutable(const config_mgr_t *mgr,
207  void *toplevel, int idx);
208 STATIC const void *config_mgr_get_obj(const config_mgr_t *mgr,
209  const void *toplevel, int idx);
210 #endif /* defined(CONFPARSE_PRIVATE) */
211 
212 #endif /* !defined(TOR_CONFPARSE_H) */
config_mgr_t * config_mgr_new(const config_format_t *toplevel_fmt)
Definition: confparse.c:145
const char * name
Definition: confparse.h:39
ptrdiff_t config_suite_offset
Definition: confparse.h:110
struct config_line_t * config_get_changes(const config_mgr_t *mgr, const void *options1, const void *options2)
Definition: confparse.c:1072
void(* clear_cfg_fn_t)(const struct config_mgr_t *mgr, void *obj)
Definition: confparse.h:89
const char * config_expand_abbrev(const config_mgr_t *mgr, const char *option, int command_line, int warn_obsolete)
Definition: confparse.c:399
char * config_dump(const config_mgr_t *mgr, const void *default_options, const void *options, int minimal, int comment_defaults)
Definition: confparse.c:1150
void config_free_(const config_mgr_t *fmt, void *options)
Definition: confparse.c:1001
struct config_format_t config_format_t
struct smartlist_t * config_mgr_list_vars(const config_mgr_t *mgr)
Definition: confparse.c:314
const config_abbrev_t * abbrevs
Definition: confparse.h:97
int config_mgr_add_format(config_mgr_t *mgr, const config_format_t *fmt)
Definition: confparse.c:211
void config_init(const config_mgr_t *mgr, void *options)
Definition: confparse.c:1134
Macro definitions for declaring configuration variables.
STATIC void * config_mgr_get_obj_mutable(const config_mgr_t *mgr, void *toplevel, int idx)
Definition: confparse.c:241
const config_var_t * vars
Definition: confparse.h:100
void warn_deprecated_option(const char *what, const char *why)
Definition: confparse.c:668
int config_assign(const config_mgr_t *mgr, void *options, struct config_line_t *list, unsigned flags, char **msg)
Definition: confparse.c:913
const char * abbreviated
Definition: confparse.h:25
void config_mgr_free_(config_mgr_t *mgr)
Definition: confparse.c:297
bool config_check_ok(const config_mgr_t *mgr, const void *options, int severity)
Definition: confparse.c:1226
STATIC const void * config_mgr_get_obj(const config_mgr_t *mgr, const void *toplevel, int idx)
Definition: confparse.c:260
const char * why_deprecated
Definition: confparse.h:41
const char * config_find_deprecation(const config_mgr_t *mgr, const char *key)
Definition: confparse.c:426
const struct_member_t * extra
Definition: confparse.h:107
int(* validate_fn_t)(void *oldval, void *newval, void *default_val, int from_setconf, char **msg_out)
Definition: confparse.h:71
struct_magic_decl_t magic
Definition: confparse.h:96
bool config_var_is_settable(const config_var_t *var)
Definition: confparse.c:542
void * config_new(const config_mgr_t *fmt)
Definition: confparse.c:371
void config_mgr_freeze(config_mgr_t *mgr)
Definition: confparse.c:280
struct config_abbrev_t config_abbrev_t
struct config_line_t * config_get_assigned_option(const config_mgr_t *mgr, const void *options, const char *key, int escape_val)
Definition: confparse.c:819
Types used to specify configurable options.
bool config_var_is_listable(const config_var_t *var)
Definition: confparse.c:603
validate_fn_t validate_fn
Definition: confparse.h:103
Macros to implement mocking and selective exposure for the test code.
struct smartlist_t * config_mgr_list_deprecated_vars(const config_mgr_t *mgr)
Definition: confparse.c:328
const char * config_find_option_name(const config_mgr_t *mgr, const char *key)
Definition: confparse.c:497
const char * full
Definition: confparse.h:27
struct config_deprecation_t config_deprecation_t
STATIC void config_reset_line(const config_mgr_t *mgr, void *options, const char *key, int use_defaults)
Definition: confparse.c:774
int config_is_same(const config_mgr_t *fmt, const void *o1, const void *o2, const char *name)
Definition: confparse.c:1046
void * config_dup(const config_mgr_t *mgr, const void *old)
Definition: confparse.c:1108
int commandline_only
Definition: confparse.h:29
clear_cfg_fn_t clear_fn
Definition: confparse.h:104