7 /* boolean-valued configuration parameter support
9 /* #include <mail_conf.h>
11 /* int get_mail_conf_bool(name, defval)
15 /* int get_mail_conf_bool_fn(name, defval)
19 /* void set_mail_conf_bool(name, value)
23 /* void get_mail_conf_bool_table(table)
24 /* const CONFIG_BOOL_TABLE *table;
26 /* void get_mail_conf_bool_fn_table(table)
27 /* const CONFIG_BOOL_TABLE *table;
29 /* This module implements configuration parameter support for
30 /* boolean values. The internal representation is zero (false)
31 /* and non-zero (true). The external representation is "no"
32 /* (false) and "yes" (true). The conversion from external
33 /* representation is case insensitive.
35 /* get_mail_conf_bool() looks up the named entry in the global
36 /* configuration dictionary. The specified default value is
37 /* returned when no value was found.
39 /* get_mail_conf_bool_fn() is similar but specifies a function that
40 /* provides the default value. The function is called only
41 /* when the default value is needed.
43 /* set_mail_conf_bool() updates the named entry in the global
44 /* configuration dictionary. This has no effect on values that
45 /* have been looked up earlier via the get_mail_conf_XXX() routines.
47 /* get_mail_conf_bool_table() and get_mail_conf_int_fn_table() initialize
48 /* lists of variables, as directed by their table arguments. A table
49 /* must be terminated by a null entry.
51 /* Fatal errors: malformed boolean value.
53 /* config(3) general configuration
54 /* mail_conf_str(3) string-valued configuration parameters
55 /* mail_conf_int(3) integer-valued configuration parameters
59 /* The Secure Mailer license must be distributed with this software.
62 /* IBM T.J. Watson Research
64 /* Yorktown Heights, NY 10598, USA
73 #ifdef STRCASECMP_IN_STRINGS_H
77 /* Utility library. */
84 #include "mail_conf.h"
86 /* convert_mail_conf_bool - look up and convert boolean parameter value */
88 static int convert_mail_conf_bool(const char *name
, int *intval
)
92 if ((strval
= mail_conf_lookup_eval(name
)) == 0) {
95 if (strcasecmp(strval
, CONFIG_BOOL_YES
) == 0) {
97 } else if (strcasecmp(strval
, CONFIG_BOOL_NO
) == 0) {
100 msg_fatal("bad boolean configuration: %s = %s", name
, strval
);
106 /* get_mail_conf_bool - evaluate boolean-valued configuration variable */
108 int get_mail_conf_bool(const char *name
, int defval
)
112 if (convert_mail_conf_bool(name
, &intval
) == 0)
113 set_mail_conf_bool(name
, intval
= defval
);
117 /* get_mail_conf_bool_fn - evaluate boolean-valued configuration variable */
119 typedef int (*stupid_indent_int
) (void);
121 int get_mail_conf_bool_fn(const char *name
, stupid_indent_int defval
)
125 if (convert_mail_conf_bool(name
, &intval
) == 0)
126 set_mail_conf_bool(name
, intval
= defval());
130 /* set_mail_conf_bool - update boolean-valued configuration dictionary entry */
132 void set_mail_conf_bool(const char *name
, int value
)
134 mail_conf_update(name
, value
? CONFIG_BOOL_YES
: CONFIG_BOOL_NO
);
137 /* get_mail_conf_bool_table - look up table of booleans */
139 void get_mail_conf_bool_table(const CONFIG_BOOL_TABLE
*table
)
141 while (table
->name
) {
142 table
->target
[0] = get_mail_conf_bool(table
->name
, table
->defval
);
147 /* get_mail_conf_bool_fn_table - look up booleans, defaults are functions */
149 void get_mail_conf_bool_fn_table(const CONFIG_BOOL_FN_TABLE
*table
)
151 while (table
->name
) {
152 table
->target
[0] = get_mail_conf_bool_fn(table
->name
, table
->defval
);