54 string_parse(
void *target,
const char *value,
char **errmsg,
59 char **p = (
char**)target;
60 *p = tor_strdup(value);
65 string_encode(
const void *value,
const void *params)
68 const char **p = (
const char**)value;
69 return *p ? tor_strdup(*p) : NULL;
73 string_clear(
void *value,
const void *params)
76 char **p = (
char**)value;
81 .
parse = string_parse,
82 .encode = string_encode,
83 .clear = string_clear,
96 typedef struct int_type_params_t {
112 int_parse(
void *target,
const char *value,
char **errmsg,
const void *params)
118 pp = &INT_PARSE_UNRESTRICTED;
124 tor_asprintf(errmsg,
"Integer %s is malformed or out of bounds. "
125 "Allowed values are between %d and %d.",
133 int_encode(
const void *value,
const void *params)
136 int v = *(
int*)value;
143 int_clear(
void *value,
const void *params)
150 int_ok(
const void *value,
const void *params)
154 int v = *(
int*)value;
163 .encode = int_encode,
175 uint64_parse(
void *target,
const char *value,
char **errmsg,
180 uint64_t *p = target;
184 tor_asprintf(errmsg,
"Integer %s is malformed or out of bounds.",
192 uint64_encode(
const void *value,
const void *params)
195 uint64_t v = *(uint64_t*)value;
202 uint64_clear(
void *value,
const void *params)
205 *(uint64_t*)value = 0;
209 .
parse = uint64_parse,
210 .encode = uint64_encode,
211 .clear = uint64_clear,
225 units_parse_u64(
void *target,
const char *value,
char **errmsg,
230 uint64_t *v = (uint64_t*)target;
235 tor_asprintf(errmsg,
"Provided value is malformed or out of bounds: %s",
247 units_parse_int(
void *target,
const char *value,
char **errmsg,
252 int *v = (
int*)target;
257 tor_asprintf(errmsg,
"Provided value is malformed or out of bounds: %s",
266 tor_asprintf(errmsg,
"Provided value %s is too large", value);
274 units_ok_int(
const void *value,
const void *params)
277 int v = *(
int*)value;
282 .
parse = units_parse_u64,
283 .encode = uint64_encode,
284 .clear = uint64_clear,
288 .
parse = units_parse_int,
289 .encode = int_encode,
301 double_parse(
void *target,
const char *value,
char **errmsg,
306 double *v = (
double*)target;
309 *v = strtod(value, &endptr);
310 if (endptr == value || *endptr !=
'\0') {
316 if (errno == ERANGE) {
318 bool underflow = -.00001 < *v && *v < .00001;
320 "%s is too %s to express as a floating-point number.",
321 escaped(value), underflow ?
"small" :
"large");
328 double_encode(
const void *value,
const void *params)
331 double v = *(
double*)value;
338 double_clear(
void *value,
const void *params)
341 double *v = (
double *)value;
346 .
parse = double_parse,
347 .encode = double_encode,
348 .clear = double_clear,
365 const char *allowed_val_string;
370 enum_parse(
void *target,
const char *value,
char **errmsg,
375 int *p = (
int *)target;
376 for (; table->name; ++table) {
377 if (!strcasecmp(value, table->name)) {
383 value, params->allowed_val_string);
388 enum_encode(
const void *value,
const void *params_)
390 int v = *(
const int*)value;
393 for (; table->name; ++table) {
394 if (v == table->value)
395 return tor_strdup(table->name);
401 enum_clear(
void *value,
const void *params_)
403 int *p = (
int*)value;
411 enum_ok(
const void *value,
const void *params_)
413 int v = *(
const int*)value;
416 for (; table->name; ++table) {
417 if (v == table->value)
430 "Allowed values are 0 and 1.",
442 "Allowed values are 0, 1, and auto.",
448 .encode = enum_encode,
460 time_parse(
void *target,
const char *value,
char **errmsg,
473 time_encode(
const void *value,
const void *params)
476 time_t v = *(
const time_t *)value;
477 char *result = tor_malloc(ISO_TIME_LEN+1);
483 time_clear(
void *value,
const void *params)
492 .encode = time_encode,
504 csv_parse(
void *target,
const char *value,
char **errmsg,
512 SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
517 csv_encode(
const void *value,
const void *params)
522 return tor_strdup(
"");
528 csv_clear(
void *value,
const void *params)
540 .encode = csv_encode,
553 legacy_csv_interval_parse(
void *target,
const char *value,
char **errmsg,
560 const char *comma = strchr(value,
',');
561 const char *val = value;
564 tmp = tor_strndup(val, comma - val);
568 int rv = units_parse_int(target, val, errmsg, &
time_units);
574 .
parse = legacy_csv_interval_parse,
575 .encode = int_encode,
602 linelist_kv_parse(
void *target,
const struct config_line_t *line,
603 char **errmsg,
const void *params)
609 if (*lines && (*lines)->fragile) {
613 config_free_lines(*lines);
622 linelist_kv_virt_noparse(
void *target,
const struct config_line_t *line,
623 char **errmsg,
const void *params)
628 *errmsg = tor_strdup(
"Cannot assign directly to virtual option.");
633 linelist_kv_encode(
const char *key,
const void *value,
643 linelist_s_kv_encode(
const char *key,
const void *value,
652 linelist_clear(
void *target,
const void *params)
656 config_free_lines(*lines);
660 linelist_eq(
const void *a,
const void *b,
const void *params)
669 linelist_copy(
void *target,
const void *value,
const void *params)
674 config_free_lines(*ptr);
680 linelist_mark_fragile(
void *target,
const void *params)
690 .kv_encode = linelist_kv_encode,
691 .clear = linelist_clear,
693 .copy = linelist_copy,
694 .mark_fragile = linelist_mark_fragile,
698 .
kv_parse = linelist_kv_virt_noparse,
699 .kv_encode = linelist_kv_encode,
700 .clear = linelist_clear,
702 .copy = linelist_copy,
703 .mark_fragile = linelist_mark_fragile,
708 .kv_encode = linelist_s_kv_encode,
709 .clear = linelist_clear,
711 .copy = linelist_copy,
727 ignore_parse(
void *target,
const char *value,
char **errmsg,
738 ignore_encode(
const void *value,
const void *params)
746 .
parse = ignore_parse,
747 .encode = ignore_encode,
751 .
name=
"String", .fns=&string_fns };
753 .
name=
"Filename", .fns=&string_fns };
755 .
name=
"SignedInteger", .fns=&int_fns,
756 .params=&INT_PARSE_UNRESTRICTED };
758 .
name=
"Integer", .fns=&int_fns,
759 .params=&INT_PARSE_POSINT };
761 .
name=
"Integer", .fns=&uint64_fns, };
763 .
name=
"DataSize", .fns=&memunit_fns,
766 .
name=
"TimeInterval", .fns=&interval_fns,
769 .
name=
"TimeMsecInterval",
773 .
name=
"Float", .fns=&double_fns, };
775 .
name=
"Boolean", .fns=&enum_fns,
776 .params=&enum_params_bool };
778 .
name=
"Boolean+Auto", .fns=&enum_fns,
779 .params=&enum_params_autobool };
781 .
name=
"Time", .fns=&time_fns, };
783 .
name=
"CommaList", .fns=&csv_fns, };
785 .
name=
"TimeInterval",
786 .fns=&legacy_csv_interval_fns, };
788 .
name=
"LineList", .fns=&linelist_fns,
795 .
name=
"Dependent", .fns=&linelist_s_fns,
801 .
name=
"Virtual", .fns=&linelist_v_fns,
804 .
name=
"Ignored", .fns=&ignore_fns,
808 .
name=
"Obsolete", .fns=&ignore_fns,
Utility macros to handle different features and behavior in different compilers.
Macros for generating a configuration struct from a list of its individual fields.
config_line_t * config_lines_dup_and_filter(const config_line_t *inp, const char *key)
config_line_t * config_lines_dup(const config_line_t *inp)
void config_line_append(config_line_t **lst, const char *key, const char *val)
int config_lines_eq(const config_line_t *a, const config_line_t *b)
#define CONFIG_LINE_APPEND
Types used to specify configurable options.
@ CONFIG_TYPE_CSV_INTERVAL
@ CONFIG_TYPE_MSEC_INTERVAL
#define CFLG_GROUP_OBSOLETE
const char * escaped(const char *s)
Headers for util_malloc.c.
uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next)
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
int tor_asprintf(char **strp, const char *fmt,...)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
smartlist_t * smartlist_new(void)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
int(* parse)(void *target, const char *value, char **errmsg, const void *params)
int(* kv_parse)(void *target, const struct config_line_t *line, char **errmsg, const void *params)
int parse_iso_time(const char *cp, time_t *t)
void format_iso_time(char *buf, time_t t)
static const var_type_def_t * type_definitions_table[]
const var_type_def_t * lookup_type_def(config_type_t type)
Header for lib/confmgt/type_defs.c.
Header for lib/confmgt/typedvar.c.
const struct unit_table_t time_units[]
const struct unit_table_t time_msec_units[]
const struct unit_table_t memory_units[]
uint64_t config_parse_units(const char *val, const unit_table_t *u, int *ok, char **errmsg_out)
Header for lib/confmgt/unitparse.c.
Macros to manage assertions, fatal and non-fatal.
Structure declarations for typedvar type definitions.