5
/* integer-valued configuration parameter support
7
/* #include <mail_conf.h>
9
/* int get_mail_conf_nint(name, defval, min, max);
11
/* const char *defval;
15
/* int get_mail_conf_nint_fn(name, defval, min, max);
21
/* void set_mail_conf_nint(name, value)
25
/* void set_mail_conf_nint_int(name, value)
29
/* void get_mail_conf_nint_table(table)
30
/* const CONFIG_NINT_TABLE *table;
32
/* void get_mail_conf_nint_fn_table(table)
33
/* const CONFIG_NINT_TABLE *table;
34
/* AUXILIARY FUNCTIONS
35
/* int get_mail_conf_nint2(name1, name2, defval, min, max);
42
/* This module implements configuration parameter support
43
/* for integer values. The default value can be a macro
44
/* expression ($name, ${name?value} and ${name:value}).
46
/* get_mail_conf_nint() looks up the named entry in the global
47
/* configuration dictionary. The default value is returned
48
/* when no value was found.
49
/* \fImin\fR is zero or specifies a lower limit on the integer
50
/* value or string length; \fImax\fR is zero or specifies an
51
/* upper limit on the integer value or string length.
53
/* get_mail_conf_nint_fn() is similar but specifies a function that
54
/* provides the default value. The function is called only
55
/* when the default value is needed.
57
/* set_mail_conf_nint() updates the named entry in the global
58
/* configuration dictionary. This has no effect on values that
59
/* have been looked up earlier via the get_mail_conf_XXX() routines.
61
/* get_mail_conf_nint_table() and get_mail_conf_nint_fn_table() initialize
62
/* lists of variables, as directed by their table arguments. A table
63
/* must be terminated by a null entry.
65
/* get_mail_conf_nint2() concatenates the two names and is otherwise
66
/* identical to get_mail_conf_nint().
68
/* Fatal errors: malformed numerical value.
70
/* config(3) general configuration
71
/* mail_conf_str(3) string-valued configuration parameters
75
/* The Secure Mailer license must be distributed with this software.
78
/* IBM T.J. Watson Research
80
/* Yorktown Heights, NY 10598, USA
87
#include <stdio.h> /* sscanf() */
89
/* Utility library. */
94
#include <stringops.h>
98
#include "mail_conf.h"
100
/* convert_mail_conf_nint - look up and convert integer parameter value */
102
static int convert_mail_conf_nint(const char *name, int *intval)
107
if ((strval = mail_conf_lookup_eval(name)) != 0) {
108
if (sscanf(strval, "%d%c", intval, &junk) != 1)
109
msg_fatal("bad numerical configuration: %s = %s", name, strval);
115
/* check_mail_conf_nint - validate integer value */
117
static void check_mail_conf_nint(const char *name, int intval, int min, int max)
119
if (min && intval < min)
120
msg_fatal("invalid %s parameter value %d < %d", name, intval, min);
121
if (max && intval > max)
122
msg_fatal("invalid %s parameter value %d > %d", name, intval, max);
125
/* get_mail_conf_nint - evaluate integer-valued configuration variable */
127
int get_mail_conf_nint(const char *name, const char *defval, int min, int max)
131
if (convert_mail_conf_nint(name, &intval) == 0)
132
set_mail_conf_nint(name, defval);
133
if (convert_mail_conf_nint(name, &intval) == 0)
134
msg_panic("get_mail_conf_nint: parameter not found: %s", name);
135
check_mail_conf_nint(name, intval, min, max);
139
/* get_mail_conf_nint2 - evaluate integer-valued configuration variable */
141
int get_mail_conf_nint2(const char *name1, const char *name2, int defval,
147
name = concatenate(name1, name2, (char *) 0);
148
if (convert_mail_conf_nint(name, &intval) == 0)
149
set_mail_conf_nint_int(name, defval);
150
if (convert_mail_conf_nint(name, &intval) == 0)
151
msg_panic("get_mail_conf_nint2: parameter not found: %s", name);
152
check_mail_conf_nint(name, intval, min, max);
157
/* get_mail_conf_nint_fn - evaluate integer-valued configuration variable */
159
typedef const char *(*stupid_indent_int) (void);
161
int get_mail_conf_nint_fn(const char *name, stupid_indent_int defval,
166
if (convert_mail_conf_nint(name, &intval) == 0)
167
set_mail_conf_nint(name, defval());
168
if (convert_mail_conf_nint(name, &intval) == 0)
169
msg_panic("get_mail_conf_nint_fn: parameter not found: %s", name);
170
check_mail_conf_nint(name, intval, min, max);
174
/* set_mail_conf_nint - update integer-valued configuration dictionary entry */
176
void set_mail_conf_nint(const char *name, const char *value)
178
mail_conf_update(name, value);
181
/* set_mail_conf_nint_int - update integer-valued configuration dictionary entry */
183
void set_mail_conf_nint_int(const char *name, int value)
185
char buf[BUFSIZ]; /* yeah! crappy code! */
187
sprintf(buf, "%d", value); /* yeah! more crappy code! */
188
mail_conf_update(name, buf);
191
/* get_mail_conf_nint_table - look up table of integers */
193
void get_mail_conf_nint_table(const CONFIG_NINT_TABLE *table)
195
while (table->name) {
196
table->target[0] = get_mail_conf_nint(table->name, table->defval,
197
table->min, table->max);
202
/* get_mail_conf_nint_fn_table - look up integers, defaults are functions */
204
void get_mail_conf_nint_fn_table(const CONFIG_NINT_FN_TABLE *table)
206
while (table->name) {
207
table->target[0] = get_mail_conf_nint_fn(table->name, table->defval,
208
table->min, table->max);