Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / mail_conf_bool.c
blob9e58e4f0c62f9e1d5ec9c3dc7293b21006c5b6fa
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* mail_conf_bool 3
6 /* SUMMARY
7 /* boolean-valued configuration parameter support
8 /* SYNOPSIS
9 /* #include <mail_conf.h>
11 /* int get_mail_conf_bool(name, defval)
12 /* const char *name;
13 /* int defval;
15 /* int get_mail_conf_bool_fn(name, defval)
16 /* const char *name;
17 /* int (*defval)();
19 /* void set_mail_conf_bool(name, value)
20 /* const char *name;
21 /* int 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;
28 /* DESCRIPTION
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.
50 /* DIAGNOSTICS
51 /* Fatal errors: malformed boolean value.
52 /* SEE ALSO
53 /* config(3) general configuration
54 /* mail_conf_str(3) string-valued configuration parameters
55 /* mail_conf_int(3) integer-valued configuration parameters
56 /* LICENSE
57 /* .ad
58 /* .fi
59 /* The Secure Mailer license must be distributed with this software.
60 /* AUTHOR(S)
61 /* Wietse Venema
62 /* IBM T.J. Watson Research
63 /* P.O. Box 704
64 /* Yorktown Heights, NY 10598, USA
65 /*--*/
67 /* System library. */
69 #include <sys_defs.h>
70 #include <stdlib.h>
71 #include <string.h>
73 #ifdef STRCASECMP_IN_STRINGS_H
74 #include <strings.h>
75 #endif
77 /* Utility library. */
79 #include <msg.h>
80 #include <dict.h>
82 /* Global 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)
90 const char *strval;
92 if ((strval = mail_conf_lookup_eval(name)) == 0) {
93 return (0);
94 } else {
95 if (strcasecmp(strval, CONFIG_BOOL_YES) == 0) {
96 *intval = 1;
97 } else if (strcasecmp(strval, CONFIG_BOOL_NO) == 0) {
98 *intval = 0;
99 } else {
100 msg_fatal("bad boolean configuration: %s = %s", name, strval);
102 return (1);
106 /* get_mail_conf_bool - evaluate boolean-valued configuration variable */
108 int get_mail_conf_bool(const char *name, int defval)
110 int intval;
112 if (convert_mail_conf_bool(name, &intval) == 0)
113 set_mail_conf_bool(name, intval = defval);
114 return (intval);
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)
123 int intval;
125 if (convert_mail_conf_bool(name, &intval) == 0)
126 set_mail_conf_bool(name, intval = defval());
127 return (intval);
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);
143 table++;
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);
153 table++;