1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*++
/* NAME
/* mail_conf_bool 3
/* SUMMARY
/* boolean-valued configuration parameter support
/* SYNOPSIS
/* #include <mail_conf.h>
/*
/* int get_mail_conf_bool(name, defval)
/* const char *name;
/* int defval;
/*
/* int get_mail_conf_bool_fn(name, defval)
/* const char *name;
/* int (*defval)();
/*
/* void set_mail_conf_bool(name, value)
/* const char *name;
/* int value;
/*
/* void get_mail_conf_bool_table(table)
/* const CONFIG_BOOL_TABLE *table;
/*
/* void get_mail_conf_bool_fn_table(table)
/* const CONFIG_BOOL_TABLE *table;
/* DESCRIPTION
/* This module implements configuration parameter support for
/* boolean values. The internal representation is zero (false)
/* and non-zero (true). The external representation is "no"
/* (false) and "yes" (true). The conversion from external
/* representation is case insensitive.
/*
/* get_mail_conf_bool() looks up the named entry in the global
/* configuration dictionary. The specified default value is
/* returned when no value was found.
/*
/* get_mail_conf_bool_fn() is similar but specifies a function that
/* provides the default value. The function is called only
/* when the default value is needed.
/*
/* set_mail_conf_bool() updates the named entry in the global
/* configuration dictionary. This has no effect on values that
/* have been looked up earlier via the get_mail_conf_XXX() routines.
/*
/* get_mail_conf_bool_table() and get_mail_conf_int_fn_table() initialize
/* lists of variables, as directed by their table arguments. A table
/* must be terminated by a null entry.
/* DIAGNOSTICS
/* Fatal errors: malformed boolean value.
/* SEE ALSO
/* config(3) general configuration
/* mail_conf_str(3) string-valued configuration parameters
/* mail_conf_int(3) integer-valued configuration parameters
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System library. */
#include <sys_defs.h>
#include <stdlib.h>
#include <string.h>
#ifdef STRCASECMP_IN_STRINGS_H
#include <strings.h>
#endif
/* Utility library. */
#include <msg.h>
#include <dict.h>
/* Global library. */
#include "mail_conf.h"
/* convert_mail_conf_bool - look up and convert boolean parameter value */
static int convert_mail_conf_bool(const char *name, int *intval)
{
const char *strval;
if ((strval = mail_conf_lookup_eval(name)) == 0) {
return (0);
} else {
if (strcasecmp(strval, CONFIG_BOOL_YES) == 0) {
*intval = 1;
} else if (strcasecmp(strval, CONFIG_BOOL_NO) == 0) {
*intval = 0;
} else {
msg_fatal("bad boolean configuration: %s = %s", name, strval);
}
return (1);
}
}
/* get_mail_conf_bool - evaluate boolean-valued configuration variable */
int get_mail_conf_bool(const char *name, int defval)
{
int intval;
if (convert_mail_conf_bool(name, &intval) == 0)
set_mail_conf_bool(name, intval = defval);
return (intval);
}
/* get_mail_conf_bool_fn - evaluate boolean-valued configuration variable */
typedef int (*stupid_indent_int) (void);
int get_mail_conf_bool_fn(const char *name, stupid_indent_int defval)
{
int intval;
if (convert_mail_conf_bool(name, &intval) == 0)
set_mail_conf_bool(name, intval = defval());
return (intval);
}
/* set_mail_conf_bool - update boolean-valued configuration dictionary entry */
void set_mail_conf_bool(const char *name, int value)
{
mail_conf_update(name, value ? CONFIG_BOOL_YES : CONFIG_BOOL_NO);
}
/* get_mail_conf_bool_table - look up table of booleans */
void get_mail_conf_bool_table(const CONFIG_BOOL_TABLE *table)
{
while (table->name) {
table->target[0] = get_mail_conf_bool(table->name, table->defval);
table++;
}
}
/* get_mail_conf_bool_fn_table - look up booleans, defaults are functions */
void get_mail_conf_bool_fn_table(const CONFIG_BOOL_FN_TABLE *table)
{
while (table->name) {
table->target[0] = get_mail_conf_bool_fn(table->name, table->defval);
table++;
}
}
|