7 /* string-valued global configuration parameter support
9 /* #include <mail_conf.h>
11 /* char *get_mail_conf_str(name, defval, min, max)
13 /* const char *defval;
17 /* char *get_mail_conf_str_fn(name, defval, min, max)
19 /* const char *(*defval)(void);
23 /* void set_mail_conf_str(name, value)
27 /* void get_mail_conf_str_table(table)
28 /* const CONFIG_STR_TABLE *table;
30 /* void get_mail_conf_str_fn_table(table)
31 /* const CONFIG_STR_TABLE *table;
32 /* AUXILIARY FUNCTIONS
33 /* char *get_mail_conf_str2(name, suffix, defval, min, max)
35 /* const char *suffix;
36 /* const char *defval;
40 /* This module implements support for string-valued global
41 /* configuration parameters.
43 /* get_mail_conf_str() looks up the named entry in the global
44 /* configuration dictionary. The default value is returned when
45 /* no value was found. String results should be passed to myfree()
46 /* when no longer needed. \fImin\fR is zero or specifies a lower
47 /* bound on the string length; \fImax\fR is zero or specifies an
48 /* upper limit on the string length.
50 /* get_mail_conf_str_fn() is similar but specifies a function that
51 /* provides the default value. The function is called only when
52 /* the default value is used.
54 /* set_mail_conf_str() 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_str_table() and get_mail_conf_str_fn_table() read
59 /* lists of variables, as directed by their table arguments. A table
60 /* must be terminated by a null entry.
62 /* get_mail_conf_str2() concatenates the two names and is otherwise
63 /* identical to get_mail_conf_str().
65 /* Fatal errors: bad string length.
67 /* config(3) generic config parameter support
71 /* The Secure Mailer license must be distributed with this software.
74 /* IBM T.J. Watson Research
76 /* Yorktown Heights, NY 10598, USA
85 /* Utility library. */
89 #include <stringops.h>
93 #include "mail_conf.h"
95 /* check_mail_conf_str - validate string length */
97 static void check_mail_conf_str(const char *name
, const char *strval
,
100 ssize_t len
= strlen(strval
);
102 if (min
&& len
< min
)
103 msg_fatal("bad string length %ld < %d: %s = %s",
104 (long) len
, min
, name
, strval
);
105 if (max
&& len
> max
)
106 msg_fatal("bad string length %ld > %d: %s = %s",
107 (long) len
, max
, name
, strval
);
110 /* get_mail_conf_str - evaluate string-valued configuration variable */
112 char *get_mail_conf_str(const char *name
, const char *defval
,
117 if ((strval
= mail_conf_lookup_eval(name
)) == 0) {
118 strval
= mail_conf_eval(defval
);
119 mail_conf_update(name
, strval
);
121 check_mail_conf_str(name
, strval
, min
, max
);
122 return (mystrdup(strval
));
125 /* get_mail_conf_str2 - evaluate string-valued configuration variable */
127 char *get_mail_conf_str2(const char *name1
, const char *name2
,
134 name
= concatenate(name1
, name2
, (char *) 0);
135 if ((strval
= mail_conf_lookup_eval(name
)) == 0) {
136 strval
= mail_conf_eval(defval
);
137 mail_conf_update(name
, strval
);
139 check_mail_conf_str(name
, strval
, min
, max
);
141 return (mystrdup(strval
));
144 /* get_mail_conf_str_fn - evaluate string-valued configuration variable */
146 typedef const char *(*stupid_indent_str
) (void);
148 char *get_mail_conf_str_fn(const char *name
, stupid_indent_str defval
,
153 if ((strval
= mail_conf_lookup_eval(name
)) == 0) {
154 strval
= mail_conf_eval(defval());
155 mail_conf_update(name
, strval
);
157 check_mail_conf_str(name
, strval
, min
, max
);
158 return (mystrdup(strval
));
161 /* set_mail_conf_str - update string-valued configuration dictionary entry */
163 void set_mail_conf_str(const char *name
, const char *value
)
165 mail_conf_update(name
, value
);
168 /* get_mail_conf_str_table - look up table of strings */
170 void get_mail_conf_str_table(const CONFIG_STR_TABLE
*table
)
172 while (table
->name
) {
173 if (table
->target
[0])
174 myfree(table
->target
[0]);
175 table
->target
[0] = get_mail_conf_str(table
->name
, table
->defval
,
176 table
->min
, table
->max
);
181 /* get_mail_conf_str_fn_table - look up strings, defaults are functions */
183 void get_mail_conf_str_fn_table(const CONFIG_STR_FN_TABLE
*table
)
185 while (table
->name
) {
186 if (table
->target
[0])
187 myfree(table
->target
[0]);
188 table
->target
[0] = get_mail_conf_str_fn(table
->name
, table
->defval
,
189 table
->min
, table
->max
);