Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / mail_conf_long.c
blob400ff86d467443ac047f51e62f538baec1d14bd8
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* mail_conf_long 3
6 /* SUMMARY
7 /* long integer-valued configuration parameter support
8 /* SYNOPSIS
9 /* #include <mail_conf.h>
11 /* int get_mail_conf_long(name, defval, min, max);
12 /* const char *name;
13 /* long defval;
14 /* long min;
15 /* long max;
17 /* int get_mail_conf_long_fn(name, defval, min, max);
18 /* const char *name;
19 /* long (*defval)(void);
20 /* long min;
21 /* long max;
23 /* void set_mail_conf_long(name, value)
24 /* const char *name;
25 /* long value;
27 /* void get_mail_conf_long_table(table)
28 /* const CONFIG_LONG_TABLE *table;
30 /* void get_mail_conf_long_fn_table(table)
31 /* const CONFIG_LONG_TABLE *table;
32 /* AUXILIARY FUNCTIONS
33 /* int get_mail_conf_long2(name1, name2, defval, min, max);
34 /* const char *name1;
35 /* const char *name2;
36 /* long defval;
37 /* long min;
38 /* long max;
39 /* DESCRIPTION
40 /* This module implements configuration parameter support
41 /* for long integer values.
43 /* get_mail_conf_long() 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 long
47 /* integer value; \fImax\fR is zero or specifies an upper limit
48 /* on the long integer value.
50 /* get_mail_conf_long_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_long() 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_long_table() and get_mail_conf_long_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_long2() concatenates the two names and is otherwise
63 /* identical to get_mail_conf_long().
64 /* DIAGNOSTICS
65 /* Fatal errors: malformed numerical value.
66 /* SEE ALSO
67 /* config(3) general configuration
68 /* mail_conf_str(3) string-valued configuration parameters
69 /* LICENSE
70 /* .ad
71 /* .fi
72 /* The Secure Mailer license must be distributed with this software.
73 /* AUTHOR(S)
74 /* Wietse Venema
75 /* IBM T.J. Watson Research
76 /* P.O. Box 704
77 /* Yorktown Heights, NY 10598, USA
78 /*--*/
80 /* System library. */
82 #include <sys_defs.h>
83 #include <stdlib.h>
84 #include <stdio.h> /* sscanf() */
86 /* Utility library. */
88 #include <msg.h>
89 #include <mymalloc.h>
90 #include <dict.h>
91 #include <stringops.h>
93 /* Global library. */
95 #include "mail_conf.h"
97 /* convert_mail_conf_long - look up and convert integer parameter value */
99 static int convert_mail_conf_long(const char *name, long *longval)
101 const char *strval;
102 char junk;
104 if ((strval = mail_conf_lookup_eval(name)) != 0) {
105 if (sscanf(strval, "%ld%c", longval, &junk) != 1)
106 msg_fatal("bad numerical configuration: %s = %s", name, strval);
107 return (1);
109 return (0);
112 /* check_mail_conf_long - validate integer value */
114 static void check_mail_conf_long(const char *name, long longval, long min, long max)
116 if (min && longval < min)
117 msg_fatal("invalid %s parameter value %ld < %ld", name, longval, min);
118 if (max && longval > max)
119 msg_fatal("invalid %s parameter value %ld > %ld", name, longval, max);
122 /* get_mail_conf_long - evaluate integer-valued configuration variable */
124 long get_mail_conf_long(const char *name, long defval, long min, long max)
126 long longval;
128 if (convert_mail_conf_long(name, &longval) == 0)
129 set_mail_conf_long(name, longval = defval);
130 check_mail_conf_long(name, longval, min, max);
131 return (longval);
134 /* get_mail_conf_long2 - evaluate integer-valued configuration variable */
136 long get_mail_conf_long2(const char *name1, const char *name2, long defval,
137 long min, long max)
139 long longval;
140 char *name;
142 name = concatenate(name1, name2, (char *) 0);
143 if (convert_mail_conf_long(name, &longval) == 0)
144 set_mail_conf_long(name, longval = defval);
145 check_mail_conf_long(name, longval, min, max);
146 myfree(name);
147 return (longval);
150 /* get_mail_conf_long_fn - evaluate integer-valued configuration variable */
152 typedef long (*stupid_indent_long) (void);
154 long get_mail_conf_long_fn(const char *name, stupid_indent_long defval,
155 long min, long max)
157 long longval;
159 if (convert_mail_conf_long(name, &longval) == 0)
160 set_mail_conf_long(name, longval = defval());
161 check_mail_conf_long(name, longval, min, max);
162 return (longval);
165 /* set_mail_conf_long - update integer-valued configuration dictionary entry */
167 void set_mail_conf_long(const char *name, long value)
169 char buf[BUFSIZ]; /* yeah! crappy code! */
171 sprintf(buf, "%ld", value); /* yeah! more crappy code! */
172 mail_conf_update(name, buf);
175 /* get_mail_conf_long_table - look up table of integers */
177 void get_mail_conf_long_table(const CONFIG_LONG_TABLE *table)
179 while (table->name) {
180 table->target[0] = get_mail_conf_long(table->name, table->defval,
181 table->min, table->max);
182 table++;
186 /* get_mail_conf_long_fn_table - look up integers, defaults are functions */
188 void get_mail_conf_long_fn_table(const CONFIG_LONG_FN_TABLE *table)
190 while (table->name) {
191 table->target[0] = get_mail_conf_long_fn(table->name, table->defval,
192 table->min, table->max);
193 table++;