Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / mail_conf_raw.c
blobc808e17e4343994cacf89bf85fc39faeddff2320
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* mail_conf_raw 3
6 /* SUMMARY
7 /* raw string-valued global configuration parameter support
8 /* SYNOPSIS
9 /* #include <mail_conf.h>
11 /* char *get_mail_conf_raw(name, defval, min, max)
12 /* const char *name;
13 /* const char *defval;
14 /* int min;
15 /* int max;
17 /* char *get_mail_conf_raw_fn(name, defval, min, max)
18 /* const char *name;
19 /* const char *(*defval)(void);
20 /* int min;
21 /* int max;
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;
28 /* DESCRIPTION
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.
46 /* DIAGNOSTICS
47 /* Fatal errors: bad string length.
48 /* SEE ALSO
49 /* config(3) generic config parameter support
50 /* LICENSE
51 /* .ad
52 /* .fi
53 /* The Secure Mailer license must be distributed with this software.
54 /* AUTHOR(S)
55 /* Wietse Venema
56 /* IBM T.J. Watson Research
57 /* P.O. Box 704
58 /* Yorktown Heights, NY 10598, USA
59 /*--*/
61 /* System library. */
63 #include <sys_defs.h>
64 #include <stdlib.h>
65 #include <string.h>
67 /* Utility library. */
69 #include <msg.h>
70 #include <mymalloc.h>
72 /* Global 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,
79 int min, int max)
81 ssize_t len = strlen(strval);
83 if (min && len < min)
84 msg_fatal("bad string length (%ld < %d): %s = %s",
85 (long) len, min, name, strval);
86 if (max && len > max)
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,
94 int min, int max)
96 const char *strval;
98 if ((strval = mail_conf_lookup(name)) == 0) {
99 strval = defval;
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,
111 int min, int max)
113 const char *strval;
115 if ((strval = mail_conf_lookup(name)) == 0) {
116 strval = defval();
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);
132 table++;
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);
145 table++;