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