7 /* raw string-valued global configuration parameter support
9 /* #include <mail_conf.h>
11 /* char *get_mail_conf_raw(name, defval, min, max)
13 /* const char *defval;
17 /* char *get_mail_conf_raw_fn(name, defval, min, max)
19 /* const char *(*defval)(void);
23 /* void get_mail_conf_raw_table(table)
24 /* const CONFIG_RAW_TABLE *table;
26 /* void get_mail_conf_raw_fn_table(table)
27 /* const CONFIG_RAW_TABLE *table;
29 /* This module implements support for string-valued global
30 /* configuration parameters that are loaded without $name expansion.
32 /* get_mail_conf_raw() looks up the named entry in the global
33 /* configuration dictionary. The default value is returned when
34 /* no value was found. String results should be passed to myfree()
35 /* when no longer needed. \fImin\fR is zero or specifies a lower
36 /* bound on the string length; \fImax\fR is zero or specifies an
37 /* upper limit on the string length.
39 /* get_mail_conf_raw_fn() is similar but specifies a function that
40 /* provides the default value. The function is called only when
41 /* the default value is used.
43 /* get_mail_conf_raw_table() and get_mail_conf_raw_fn_table() read
44 /* lists of variables, as directed by their table arguments. A table
45 /* must be terminated by a null entry.
47 /* Fatal errors: bad string length.
49 /* config(3) generic config parameter support
53 /* The Secure Mailer license must be distributed with this software.
56 /* IBM T.J. Watson Research
58 /* Yorktown Heights, NY 10598, USA
67 /* Utility library. */
74 #include "mail_conf.h"
76 /* check_mail_conf_raw - validate string length */
78 static void check_mail_conf_raw(const char *name
, const char *strval
,
81 ssize_t len
= strlen(strval
);
84 msg_fatal("bad string length (%ld < %d): %s = %s",
85 (long) len
, min
, name
, strval
);
87 msg_fatal("bad string length (%ld > %d): %s = %s",
88 (long) len
, max
, name
, strval
);
91 /* get_mail_conf_raw - evaluate string-valued configuration variable */
93 char *get_mail_conf_raw(const char *name
, const char *defval
,
98 if ((strval
= mail_conf_lookup(name
)) == 0) {
100 mail_conf_update(name
, strval
);
102 check_mail_conf_raw(name
, strval
, min
, max
);
103 return (mystrdup(strval
));
106 /* get_mail_conf_raw_fn - evaluate string-valued configuration variable */
108 typedef const char *(*stupid_indent_str
) (void);
110 char *get_mail_conf_raw_fn(const char *name
, stupid_indent_str defval
,
115 if ((strval
= mail_conf_lookup(name
)) == 0) {
117 mail_conf_update(name
, strval
);
119 check_mail_conf_raw(name
, strval
, min
, max
);
120 return (mystrdup(strval
));
123 /* get_mail_conf_raw_table - look up table of strings */
125 void get_mail_conf_raw_table(const CONFIG_RAW_TABLE
*table
)
127 while (table
->name
) {
128 if (table
->target
[0])
129 myfree(table
->target
[0]);
130 table
->target
[0] = get_mail_conf_raw(table
->name
, table
->defval
,
131 table
->min
, table
->max
);
136 /* get_mail_conf_raw_fn_table - look up strings, defaults are functions */
138 void get_mail_conf_raw_fn_table(const CONFIG_RAW_FN_TABLE
*table
)
140 while (table
->name
) {
141 if (table
->target
[0])
142 myfree(table
->target
[0]);
143 table
->target
[0] = get_mail_conf_raw_fn(table
->name
, table
->defval
,
144 table
->min
, table
->max
);