7 /* integer-valued configuration parameter support
9 /* #include <mail_conf.h>
11 /* int get_mail_conf_int(name, defval, min, max);
17 /* int get_mail_conf_int_fn(name, defval, min, max);
23 /* void set_mail_conf_int(name, value)
27 /* void get_mail_conf_int_table(table)
28 /* const CONFIG_INT_TABLE *table;
30 /* void get_mail_conf_int_fn_table(table)
31 /* const CONFIG_INT_TABLE *table;
32 /* AUXILIARY FUNCTIONS
33 /* int get_mail_conf_int2(name1, name2, defval, min, max);
40 /* This module implements configuration parameter support
41 /* for integer values.
43 /* get_mail_conf_int() looks up the named entry in the global
44 /* configuration dictionary. The default value is returned
45 /* when no value was found.
46 /* \fImin\fR is zero or specifies a lower limit on the integer
47 /* value or string length; \fImax\fR is zero or specifies an
48 /* upper limit on the integer value or string length.
50 /* get_mail_conf_int_fn() is similar but specifies a function that
51 /* provides the default value. The function is called only
52 /* when the default value is needed.
54 /* set_mail_conf_int() updates the named entry in the global
55 /* configuration dictionary. This has no effect on values that
56 /* have been looked up earlier via the get_mail_conf_XXX() routines.
58 /* get_mail_conf_int_table() and get_mail_conf_int_fn_table() initialize
59 /* lists of variables, as directed by their table arguments. A table
60 /* must be terminated by a null entry.
62 /* get_mail_conf_int2() concatenates the two names and is otherwise
63 /* identical to get_mail_conf_int().
65 /* Fatal errors: malformed numerical value.
67 /* config(3) general configuration
68 /* mail_conf_str(3) string-valued configuration parameters
72 /* The Secure Mailer license must be distributed with this software.
75 /* IBM T.J. Watson Research
77 /* Yorktown Heights, NY 10598, USA
84 #include <stdio.h> /* sscanf() */
86 /* Utility library. */
91 #include <stringops.h>
95 #include "mail_conf.h"
97 /* convert_mail_conf_int - look up and convert integer parameter value */
99 static int convert_mail_conf_int(const char *name
, int *intval
)
104 if ((strval
= mail_conf_lookup_eval(name
)) != 0) {
105 if (sscanf(strval
, "%d%c", intval
, &junk
) != 1)
106 msg_fatal("bad numerical configuration: %s = %s", name
, strval
);
112 /* check_mail_conf_int - validate integer value */
114 static void check_mail_conf_int(const char *name
, int intval
, int min
, int max
)
116 if (min
&& intval
< min
)
117 msg_fatal("invalid %s parameter value %d < %d", name
, intval
, min
);
118 if (max
&& intval
> max
)
119 msg_fatal("invalid %s parameter value %d > %d", name
, intval
, max
);
122 /* get_mail_conf_int - evaluate integer-valued configuration variable */
124 int get_mail_conf_int(const char *name
, int defval
, int min
, int max
)
128 if (convert_mail_conf_int(name
, &intval
) == 0)
129 set_mail_conf_int(name
, intval
= defval
);
130 check_mail_conf_int(name
, intval
, min
, max
);
134 /* get_mail_conf_int2 - evaluate integer-valued configuration variable */
136 int get_mail_conf_int2(const char *name1
, const char *name2
, int defval
,
142 name
= concatenate(name1
, name2
, (char *) 0);
143 if (convert_mail_conf_int(name
, &intval
) == 0)
144 set_mail_conf_int(name
, intval
= defval
);
145 check_mail_conf_int(name
, intval
, min
, max
);
150 /* get_mail_conf_int_fn - evaluate integer-valued configuration variable */
152 typedef int (*stupid_indent_int
) (void);
154 int get_mail_conf_int_fn(const char *name
, stupid_indent_int defval
,
159 if (convert_mail_conf_int(name
, &intval
) == 0)
160 set_mail_conf_int(name
, intval
= defval());
161 check_mail_conf_int(name
, intval
, min
, max
);
165 /* set_mail_conf_int - update integer-valued configuration dictionary entry */
167 void set_mail_conf_int(const char *name
, int value
)
169 char buf
[BUFSIZ
]; /* yeah! crappy code! */
171 sprintf(buf
, "%d", value
); /* yeah! more crappy code! */
172 mail_conf_update(name
, buf
);
175 /* get_mail_conf_int_table - look up table of integers */
177 void get_mail_conf_int_table(const CONFIG_INT_TABLE
*table
)
179 while (table
->name
) {
180 table
->target
[0] = get_mail_conf_int(table
->name
, table
->defval
,
181 table
->min
, table
->max
);
186 /* get_mail_conf_int_fn_table - look up integers, defaults are functions */
188 void get_mail_conf_int_fn_table(const CONFIG_INT_FN_TABLE
*table
)
190 while (table
->name
) {
191 table
->target
[0] = get_mail_conf_int_fn(table
->name
, table
->defval
,
192 table
->min
, table
->max
);