7 /* integer-valued configuration parameter support
9 /* #include <mail_conf.h>
11 /* int get_mail_conf_nint(name, defval, min, max);
13 /* const char *defval;
17 /* int get_mail_conf_nint_fn(name, defval, min, max);
23 /* void set_mail_conf_nint(name, value)
27 /* void set_mail_conf_nint_int(name, value)
31 /* void get_mail_conf_nint_table(table)
32 /* const CONFIG_NINT_TABLE *table;
34 /* void get_mail_conf_nint_fn_table(table)
35 /* const CONFIG_NINT_TABLE *table;
36 /* AUXILIARY FUNCTIONS
37 /* int get_mail_conf_nint2(name1, name2, defval, min, max);
44 /* This module implements configuration parameter support
45 /* for integer values. The default value can be a macro
46 /* expression ($name, ${name?value} and ${name:value}).
48 /* get_mail_conf_nint() looks up the named entry in the global
49 /* configuration dictionary. The default value is returned
50 /* when no value was found.
51 /* \fImin\fR is zero or specifies a lower limit on the integer
52 /* value or string length; \fImax\fR is zero or specifies an
53 /* upper limit on the integer value or string length.
55 /* get_mail_conf_nint_fn() is similar but specifies a function that
56 /* provides the default value. The function is called only
57 /* when the default value is needed.
59 /* set_mail_conf_nint() updates the named entry in the global
60 /* configuration dictionary. This has no effect on values that
61 /* have been looked up earlier via the get_mail_conf_XXX() routines.
63 /* get_mail_conf_nint_table() and get_mail_conf_nint_fn_table() initialize
64 /* lists of variables, as directed by their table arguments. A table
65 /* must be terminated by a null entry.
67 /* get_mail_conf_nint2() concatenates the two names and is otherwise
68 /* identical to get_mail_conf_nint().
70 /* Fatal errors: malformed numerical value.
72 /* config(3) general configuration
73 /* mail_conf_str(3) string-valued configuration parameters
77 /* The Secure Mailer license must be distributed with this software.
80 /* IBM T.J. Watson Research
82 /* Yorktown Heights, NY 10598, USA
89 #include <stdio.h> /* sscanf() */
91 /* Utility library. */
96 #include <stringops.h>
100 #include "mail_conf.h"
102 /* convert_mail_conf_nint - look up and convert integer parameter value */
104 static int convert_mail_conf_nint(const char *name
, int *intval
)
109 if ((strval
= mail_conf_lookup_eval(name
)) != 0) {
110 if (sscanf(strval
, "%d%c", intval
, &junk
) != 1)
111 msg_fatal("bad numerical configuration: %s = %s", name
, strval
);
117 /* check_mail_conf_nint - validate integer value */
119 static void check_mail_conf_nint(const char *name
, int intval
, int min
, int max
)
121 if (min
&& intval
< min
)
122 msg_fatal("invalid %s parameter value %d < %d", name
, intval
, min
);
123 if (max
&& intval
> max
)
124 msg_fatal("invalid %s parameter value %d > %d", name
, intval
, max
);
127 /* get_mail_conf_nint - evaluate integer-valued configuration variable */
129 int get_mail_conf_nint(const char *name
, const char *defval
, int min
, int max
)
133 if (convert_mail_conf_nint(name
, &intval
) == 0)
134 set_mail_conf_nint(name
, defval
);
135 if (convert_mail_conf_nint(name
, &intval
) == 0)
136 msg_panic("get_mail_conf_nint: parameter not found: %s", name
);
137 check_mail_conf_nint(name
, intval
, min
, max
);
141 /* get_mail_conf_nint2 - evaluate integer-valued configuration variable */
143 int get_mail_conf_nint2(const char *name1
, const char *name2
, int defval
,
149 name
= concatenate(name1
, name2
, (char *) 0);
150 if (convert_mail_conf_nint(name
, &intval
) == 0)
151 set_mail_conf_nint_int(name
, defval
);
152 if (convert_mail_conf_nint(name
, &intval
) == 0)
153 msg_panic("get_mail_conf_nint2: parameter not found: %s", name
);
154 check_mail_conf_nint(name
, intval
, min
, max
);
159 /* get_mail_conf_nint_fn - evaluate integer-valued configuration variable */
161 typedef const char *(*stupid_indent_int
) (void);
163 int get_mail_conf_nint_fn(const char *name
, stupid_indent_int defval
,
168 if (convert_mail_conf_nint(name
, &intval
) == 0)
169 set_mail_conf_nint(name
, defval());
170 if (convert_mail_conf_nint(name
, &intval
) == 0)
171 msg_panic("get_mail_conf_nint_fn: parameter not found: %s", name
);
172 check_mail_conf_nint(name
, intval
, min
, max
);
176 /* set_mail_conf_nint - update integer-valued configuration dictionary entry */
178 void set_mail_conf_nint(const char *name
, const char *value
)
180 mail_conf_update(name
, value
);
183 /* set_mail_conf_nint_int - update integer-valued configuration dictionary entry */
185 void set_mail_conf_nint_int(const char *name
, int value
)
187 char buf
[BUFSIZ
]; /* yeah! crappy code! */
189 sprintf(buf
, "%d", value
); /* yeah! more crappy code! */
190 mail_conf_update(name
, buf
);
193 /* get_mail_conf_nint_table - look up table of integers */
195 void get_mail_conf_nint_table(const CONFIG_NINT_TABLE
*table
)
197 while (table
->name
) {
198 table
->target
[0] = get_mail_conf_nint(table
->name
, table
->defval
,
199 table
->min
, table
->max
);
204 /* get_mail_conf_nint_fn_table - look up integers, defaults are functions */
206 void get_mail_conf_nint_fn_table(const CONFIG_NINT_FN_TABLE
*table
)
208 while (table
->name
) {
209 table
->target
[0] = get_mail_conf_nint_fn(table
->name
, table
->defval
,
210 table
->min
, table
->max
);