Commit a3a31df1 a3a31df1d1c1606c5e20409289d1161bdcc5dfd9 by Sergey Poznyakoff

* include/mailutils/cfg.h, mailbox/cfg_lexer.c,

mailbox/cfg_parser.y (mu_cfg_tree_t):
New data type.
(mu_cfg_perror_t): Remove
(mu_cfg_parse): Change prototype.
(mu_cfg_perror): Change type.
(mu_cfg_format_error): New function.
(mu_cfg_destroy_tree): Change signature.
(mu_cfg_callback_t): Take mu_debug_t as its first argument,
instead of mu_cfg_locus_t. The mu_debug_t is to be used for error
reporting and debugging diagnostics. The cfg_lexer is responsible
for storing the necessary locus data into it before calling
callbacks.
(mu_cfg_section_fp): Take an additional argument.
(mu_cfg_scan_tree): Simplified prototype. The mu_cfg_tree_t passed
as its first argument already contains all necessary data that
were passed as arguments previously.
(mu_parse_config): First two args are consts.

* include/mailutils/libcfg.h, imap4d/imap4d.c, libcfg/auth.c,
libcfg/common.c, libcfg/ldap.c, libcfg/sieve.c, libcfg/sql.c,
maidag/maidag.c, mail.local/main.c, mimeview/mimeview.c,
pop3d/pop3d.c, sieve/sieve.c: Reflect changes to the cfg
framework.

* mailbox/debug.c (mu_debug_vprintf): Make sure the locus info is
formatted on the first call.
1 parent 0c81afb7
1 2007-11-28 Sergey Poznyakoff <gray@gnu.org.ua> 1 2007-11-28 Sergey Poznyakoff <gray@gnu.org.ua>
2 2
3 Further improvement of mu_debug_t. 3 III. Use mu_debug_t for diagnostics in cfg framework.
4
5 * include/mailutils/cfg.h, mailbox/cfg_lexer.c,
6 mailbox/cfg_parser.y (mu_cfg_tree_t):
7 New data type.
8 (mu_cfg_perror_t): Remove
9 (mu_cfg_parse): Change prototype.
10 (mu_cfg_perror): Change type.
11 (mu_cfg_format_error): New function.
12 (mu_cfg_destroy_tree): Change signature.
13 (mu_cfg_callback_t): Take mu_debug_t as its first argument,
14 instead of mu_cfg_locus_t. The mu_debug_t is to be used for error
15 reporting and debugging diagnostics. The cfg_lexer is responsible
16 for storing the necessary locus data into it before calling
17 callbacks.
18 (mu_cfg_section_fp): Take an additional argument.
19 (mu_cfg_scan_tree): Simplified prototype. The mu_cfg_tree_t passed
20 as its first argument already contains all necessary data that
21 were passed as arguments previously.
22 (mu_parse_config): First two args are consts.
23
24 * include/mailutils/libcfg.h, imap4d/imap4d.c, libcfg/auth.c,
25 libcfg/common.c, libcfg/ldap.c, libcfg/sieve.c, libcfg/sql.c,
26 maidag/maidag.c, mail.local/main.c, mimeview/mimeview.c,
27 pop3d/pop3d.c, sieve/sieve.c: Reflect changes to the cfg
28 framework.
29
30 * mailbox/debug.c (mu_debug_vprintf): Make sure the locus info is
31 formatted on the first call.
32
33 II. Further improvement of mu_debug_t.
4 34
5 * include/mailutils/debug.hm4 (struct mu_debug_locus): New data 35 * include/mailutils/debug.hm4 (struct mu_debug_locus): New data
6 type. 36 type.
...@@ -32,9 +62,7 @@ ...@@ -32,9 +62,7 @@
32 mu_debug_set_function to print source locations. This allows for 62 mu_debug_set_function to print source locations. This allows for
33 easy i18n of the MU_DEBUG[0-9]* format strings. 63 easy i18n of the MU_DEBUG[0-9]* format strings.
34 64
35 2007-11-28 Sergey Poznyakoff <gray@gnu.org.ua> 65 I. Introduce "global debug settings". Mailutils objects are supposed
36
37 Introduce "global debug settings". Mailutils objects are supposed
38 to set their default mu_debug_t objects basing on these settings. 66 to set their default mu_debug_t objects basing on these settings.
39 67
40 * include/mailutils/Makefile.am: Add debug.hm4. Build debug.h from 68 * include/mailutils/Makefile.am: Add debug.hm4. Build debug.h from
......
...@@ -146,27 +146,27 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -146,27 +146,27 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state)
146 } 146 }
147 147
148 static int 148 static int
149 cb_other (mu_cfg_locus_t *locus, void *data, char *arg) 149 cb_other (mu_debug_t debug, void *data, char *arg)
150 { 150 {
151 set_namespace (NS_OTHER, arg); 151 set_namespace (NS_OTHER, arg);
152 return 0; 152 return 0;
153 } 153 }
154 154
155 static int 155 static int
156 cb_shared (mu_cfg_locus_t *locus, void *data, char *arg) 156 cb_shared (mu_debug_t debug, void *data, char *arg)
157 { 157 {
158 set_namespace (NS_SHARED, arg); 158 set_namespace (NS_SHARED, arg);
159 return 0; 159 return 0;
160 } 160 }
161 161
162 static int 162 static int
163 cb_mode (mu_cfg_locus_t *locus, void *data, char *arg) 163 cb_mode (mu_debug_t debug, void *data, char *arg)
164 { 164 {
165 char *p; 165 char *p;
166 home_dir_mode = strtoul (arg, &p, 8); 166 home_dir_mode = strtoul (arg, &p, 8);
167 if (p || (home_dir_mode & 0777)) 167 if (p || (home_dir_mode & 0777))
168 mu_error (_("%s:%d: Invalid mode specification: %s"), 168 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
169 locus->file, locus->line, arg); 169 _("Invalid mode specification: %s"), arg);
170 return 0; 170 return 0;
171 } 171 }
172 172
......
...@@ -19,17 +19,21 @@ ...@@ -19,17 +19,21 @@
19 #define _MAILUTILS_CFG_H 19 #define _MAILUTILS_CFG_H
20 20
21 #include <mailutils/list.h> 21 #include <mailutils/list.h>
22 #include <mailutils/debug.h>
22 #include <sys/socket.h> 23 #include <sys/socket.h>
23 #include <netinet/in.h> 24 #include <netinet/in.h>
24 #include <arpa/inet.h> 25 #include <arpa/inet.h>
25 26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
26 typedef enum mu_cfg_node_type mu_cfg_node_type_t; 31 typedef enum mu_cfg_node_type mu_cfg_node_type_t;
27 typedef struct mu_cfg_node mu_cfg_node_t; 32 typedef struct mu_cfg_node mu_cfg_node_t;
28 typedef struct mu_cfg_locus mu_cfg_locus_t; 33 typedef struct mu_cfg_locus mu_cfg_locus_t;
34 typedef struct mu_cfg_tree mu_cfg_tree_t;
29 35
30 typedef int (*mu_cfg_lexer_t) (void *ptr); 36 typedef int (*mu_cfg_lexer_t) (void *ptr);
31 typedef void (*mu_cfg_perror_t) (void *ptr, const mu_cfg_locus_t *loc,
32 const char *fmt, ...);
33 typedef void *(*mu_cfg_alloc_t) (size_t size); 37 typedef void *(*mu_cfg_alloc_t) (size_t size);
34 typedef void (*mu_cfg_free_t) (void *ptr); 38 typedef void (*mu_cfg_free_t) (void *ptr);
35 39
...@@ -56,16 +60,26 @@ struct mu_cfg_node ...@@ -56,16 +60,26 @@ struct mu_cfg_node
56 mu_cfg_node_t *node; 60 mu_cfg_node_t *node;
57 }; 61 };
58 62
59 int mu_cfg_parse (mu_cfg_node_t **ptree, 63 struct mu_cfg_tree
64 {
65 mu_cfg_node_t *node;
66 mu_debug_t debug;
67 mu_cfg_alloc_t alloc;
68 mu_cfg_free_t free;
69 };
70
71 int mu_cfg_parse (mu_cfg_tree_t **ptree,
60 void *data, 72 void *data,
61 mu_cfg_lexer_t lexer, 73 mu_cfg_lexer_t lexer,
62 mu_cfg_perror_t perror, 74 mu_debug_t debug,
63 mu_cfg_alloc_t alloc, 75 mu_cfg_alloc_t alloc,
64 mu_cfg_free_t free); 76 mu_cfg_free_t free);
65 77
66 extern mu_cfg_locus_t mu_cfg_locus; 78 extern mu_cfg_locus_t mu_cfg_locus;
67 extern int mu_cfg_tie_in; 79 extern int mu_cfg_tie_in;
68 extern mu_cfg_perror_t mu_cfg_perror; 80
81 void mu_cfg_perror (const mu_cfg_locus_t *, const char *, ...);
82 void mu_cfg_format_error (mu_debug_t debug, size_t, const char *fmt, ...);
69 83
70 #define MU_CFG_ITER_OK 0 84 #define MU_CFG_ITER_OK 0
71 #define MU_CFG_ITER_SKIP 1 85 #define MU_CFG_ITER_SKIP 1
...@@ -73,7 +87,7 @@ extern mu_cfg_perror_t mu_cfg_perror; ...@@ -73,7 +87,7 @@ extern mu_cfg_perror_t mu_cfg_perror;
73 87
74 typedef int (*mu_cfg_iter_func_t) (const mu_cfg_node_t *node, void *data); 88 typedef int (*mu_cfg_iter_func_t) (const mu_cfg_node_t *node, void *data);
75 89
76 void mu_cfg_destroy_tree (mu_cfg_node_t **tree); 90 void mu_cfg_destroy_tree (mu_cfg_tree_t **tree);
77 91
78 int mu_cfg_preorder (mu_cfg_node_t *node, 92 int mu_cfg_preorder (mu_cfg_node_t *node,
79 mu_cfg_iter_func_t fun, mu_cfg_iter_func_t endfun, 93 mu_cfg_iter_func_t fun, mu_cfg_iter_func_t endfun,
...@@ -107,7 +121,7 @@ enum mu_cfg_param_data_type ...@@ -107,7 +121,7 @@ enum mu_cfg_param_data_type
107 mu_cfg_callback 121 mu_cfg_callback
108 }; 122 };
109 123
110 typedef int (*mu_cfg_callback_t) (mu_cfg_locus_t *, void *, char *); 124 typedef int (*mu_cfg_callback_t) (mu_debug_t, void *, char *);
111 125
112 struct mu_cfg_param 126 struct mu_cfg_param
113 { 127 {
...@@ -125,7 +139,9 @@ enum mu_cfg_section_stage ...@@ -125,7 +139,9 @@ enum mu_cfg_section_stage
125 139
126 typedef int (*mu_cfg_section_fp) (enum mu_cfg_section_stage stage, 140 typedef int (*mu_cfg_section_fp) (enum mu_cfg_section_stage stage,
127 const mu_cfg_node_t *node, 141 const mu_cfg_node_t *node,
128 void *section_data, void *call_data); 142 void *section_data,
143 void *call_data,
144 mu_cfg_tree_t *tree);
129 145
130 struct mu_cfg_section 146 struct mu_cfg_section
131 { 147 {
...@@ -167,10 +183,8 @@ int mu_config_create_container (struct mu_cfg_cont **pcont, ...@@ -167,10 +183,8 @@ int mu_config_create_container (struct mu_cfg_cont **pcont,
167 int mu_config_clone_container (struct mu_cfg_cont *cont); 183 int mu_config_clone_container (struct mu_cfg_cont *cont);
168 void mu_config_destroy_container (struct mu_cfg_cont **pcont); 184 void mu_config_destroy_container (struct mu_cfg_cont **pcont);
169 185
170 int mu_cfg_scan_tree (mu_cfg_node_t *node, 186 int mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
171 struct mu_cfg_section *sections, 187 void *call_data);
172 void *data, mu_cfg_perror_t perror,
173 mu_cfg_alloc_t palloc, mu_cfg_free_t pfree);
174 188
175 int mu_cfg_find_section (struct mu_cfg_section *root_sec, 189 int mu_cfg_find_section (struct mu_cfg_section *root_sec,
176 const char *path, struct mu_cfg_section **retval); 190 const char *path, struct mu_cfg_section **retval);
...@@ -184,10 +198,15 @@ int mu_config_register_plain_section (const char *parent_path, ...@@ -184,10 +198,15 @@ int mu_config_register_plain_section (const char *parent_path,
184 const char *ident, 198 const char *ident,
185 struct mu_cfg_param *params); 199 struct mu_cfg_param *params);
186 200
187 int mu_parse_config (char *file, char *progname, 201 int mu_parse_config (const char *file, const char *progname,
188 struct mu_cfg_param *progparam, int global); 202 struct mu_cfg_param *progparam, int global);
189 203
190 int mu_cfg_parse_boolean (const char *str, int *res); 204 int mu_cfg_parse_boolean (const char *str, int *res);
191 205
192 extern int mu_cfg_parser_verbose; 206 extern int mu_cfg_parser_verbose;
207
208 #ifdef __cplusplus
209 }
210 #endif
211
193 #endif 212 #endif
......
...@@ -57,7 +57,7 @@ extern int mu_parse_config_files (struct mu_cfg_param *param); ...@@ -57,7 +57,7 @@ extern int mu_parse_config_files (struct mu_cfg_param *param);
57 int \ 57 int \
58 __mu_common_cat3__(mu_,capa,_section_parser) \ 58 __mu_common_cat3__(mu_,capa,_section_parser) \
59 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, \ 59 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, \
60 void *section_data, void *call_data) \ 60 void *section_data, void *call_data, mu_cfg_tree_t *tree) \
61 { \ 61 { \
62 switch (stage) \ 62 switch (stage) \
63 { \ 63 { \
......
...@@ -29,22 +29,23 @@ ...@@ -29,22 +29,23 @@
29 /* Resource-style configuration */ 29 /* Resource-style configuration */
30 /* ************************************************************************* */ 30 /* ************************************************************************* */
31 static int 31 static int
32 cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg) 32 cb_authentication (mu_debug_t err, void *data, char *arg)
33 { 33 {
34 if (strcmp (arg, "clear") == 0) 34 if (strcmp (arg, "clear") == 0)
35 mu_authentication_clear_list (); 35 mu_authentication_clear_list ();
36 else 36 else
37 mu_authentication_add_module_list (arg);/*FIXME: error reporting*/ 37 mu_authentication_add_module_list (arg);/*FIXME: use err for error
38 reporting*/
38 return 0; 39 return 0;
39 } 40 }
40 41
41 static int 42 static int
42 cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg) 43 cb_authorization (mu_debug_t err, void *data, char *arg)
43 { 44 {
44 if (strcmp (arg, "clear") == 0) 45 if (strcmp (arg, "clear") == 0)
45 mu_authorization_clear_list (); 46 mu_authorization_clear_list ();
46 else 47 else
47 mu_authorization_add_module_list (arg); 48 mu_authorization_add_module_list (arg);/* FIXME: see above */
48 return 0; 49 return 0;
49 } 50 }
50 51
...@@ -57,7 +58,7 @@ static struct mu_cfg_param mu_auth_param[] = { ...@@ -57,7 +58,7 @@ static struct mu_cfg_param mu_auth_param[] = {
57 int 58 int
58 mu_auth_section_parser 59 mu_auth_section_parser
59 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, 60 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
60 void *section_data, void *call_data) 61 void *section_data, void *call_data, mu_cfg_tree_t *tree)
61 { 62 {
62 switch (stage) 63 switch (stage)
63 { 64 {
......
...@@ -94,12 +94,13 @@ DCL_CFG_CAPA (mailer); ...@@ -94,12 +94,13 @@ DCL_CFG_CAPA (mailer);
94 /* ************************************************************************* */ 94 /* ************************************************************************* */
95 95
96 int 96 int
97 cb_facility (mu_cfg_locus_t *locus, void *data, char *arg) 97 cb_facility (mu_debug_t debug, void *data, char *arg)
98 { 98 {
99 if (mu_string_to_syslog_facility (arg, &logging_settings.facility)) 99 if (mu_string_to_syslog_facility (arg, &logging_settings.facility))
100 { 100 {
101 mu_error (_("%s:%d: Unknown syslog facility `%s'"), 101 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
102 locus->file, locus->line, arg); 102 _("Unknown syslog facility `%s'"),
103 arg);
103 return 1; 104 return 1;
104 } 105 }
105 return 0; 106 return 0;
...@@ -118,7 +119,7 @@ DCL_CFG_CAPA (logging); ...@@ -118,7 +119,7 @@ DCL_CFG_CAPA (logging);
118 /* ************************************************************************* */ 119 /* ************************************************************************* */
119 120
120 static int 121 static int
121 _cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg) 122 _cb_daemon_mode (mu_debug_t debug, void *data, char *arg)
122 { 123 {
123 if (strcmp (arg, "inetd") == 0 124 if (strcmp (arg, "inetd") == 0
124 || strcmp (arg, "interactive") == 0) 125 || strcmp (arg, "interactive") == 0)
...@@ -127,7 +128,7 @@ _cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -127,7 +128,7 @@ _cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg)
127 daemon_settings.mode = MODE_DAEMON; 128 daemon_settings.mode = MODE_DAEMON;
128 else 129 else
129 { 130 {
130 mu_error ("%s:%d: unknown daemon mode", locus->file, locus->line); 131 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("unknown daemon mode"));
131 return 1; 132 return 1;
132 } 133 }
133 return 0; 134 return 0;
...@@ -146,7 +147,7 @@ static struct mu_cfg_param mu_daemon_param[] = { ...@@ -146,7 +147,7 @@ static struct mu_cfg_param mu_daemon_param[] = {
146 int 147 int
147 mu_daemon_section_parser 148 mu_daemon_section_parser
148 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, 149 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
149 void *section_data, void *call_data) 150 void *section_data, void *call_data, mu_cfg_tree_t *tree)
150 { 151 {
151 switch (stage) 152 switch (stage)
152 { 153 {
...@@ -170,23 +171,25 @@ struct mu_cfg_capa mu_daemon_cfg_capa = { ...@@ -170,23 +171,25 @@ struct mu_cfg_capa mu_daemon_cfg_capa = {
170 /* ************************************************************************* */ 171 /* ************************************************************************* */
171 172
172 static int 173 static int
173 cb_debug_level (mu_cfg_locus_t *locus, void *data, char *arg) 174 cb_debug_level (mu_debug_t debug, void *data, char *arg)
174 { 175 {
175 char buf[UINTMAX_STRSIZE_BOUND]; 176 char buf[UINTMAX_STRSIZE_BOUND];
176 char *p; 177 char *p;
177 size_t size; 178 size_t size;
178 char *pfx; 179 char *pfx;
180 struct mu_debug_locus locus;
179 181
180 debug_settings.string = arg; 182 debug_settings.string = arg;
181 p = umaxtostr (locus->line, buf); 183 mu_debug_get_locus (debug, &locus);
182 size = strlen (locus->file) + 1 + strlen (p) + 1; 184 p = umaxtostr (locus.line, buf);
185 size = strlen (locus.file) + 1 + strlen (p) + 1;
183 pfx = malloc (size); 186 pfx = malloc (size);
184 if (!pfx) 187 if (!pfx)
185 { 188 {
186 mu_error ("%s", mu_strerror (errno)); 189 mu_cfg_format_error (debug, MU_DEBUG_ERROR, "%s", mu_strerror (errno));
187 return 1; 190 return 1;
188 } 191 }
189 strcpy (pfx, locus->file); 192 strcpy (pfx, locus.file);
190 strcat (pfx, ":"); 193 strcat (pfx, ":");
191 strcat (pfx, p); 194 strcat (pfx, p);
192 debug_settings.errpfx = pfx; 195 debug_settings.errpfx = pfx;
......
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
26 static struct mu_ldap_module_config ldap_settings; 26 static struct mu_ldap_module_config ldap_settings;
27 27
28 static int 28 static int
29 cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg) 29 cb_field_map (mu_debug_t debug, void *data, char *arg)
30 { 30 {
31 int err; 31 int err;
32 int rc = mutil_parse_field_map (arg, &ldap_settings.field_map, &err); 32 int rc = mutil_parse_field_map (arg, &ldap_settings.field_map, &err);
33 if (rc) 33 if (rc)
34 mu_error (_("%s:%d: Error near element %d: %s"), 34 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("Error near element %d: %s"),
35 locus->file, locus->line, err, mu_strerror (rc)); 35 err, mu_strerror (rc));
36 return 0; 36 return 0;
37 } 37 }
38 38
...@@ -53,7 +53,7 @@ static struct mu_cfg_param mu_ldap_param[] = { ...@@ -53,7 +53,7 @@ static struct mu_cfg_param mu_ldap_param[] = {
53 int 53 int
54 mu_ldap_section_parser 54 mu_ldap_section_parser
55 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, 55 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
56 void *section_data, void *call_data) 56 void *section_data, void *call_data, mu_cfg_tree_t *tree)
57 { 57 {
58 switch (stage) 58 switch (stage)
59 { 59 {
......
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
25 static struct mu_gocs_sieve sieve_settings; 25 static struct mu_gocs_sieve sieve_settings;
26 26
27 static int 27 static int
28 cb_clear_library_path (mu_cfg_locus_t *locus, void *data, char *arg) 28 cb_clear_library_path (mu_debug_t debug, void *data, char *arg)
29 { 29 {
30 int flag; 30 int flag;
31 if (mu_cfg_parse_boolean (arg, &flag)) 31 if (mu_cfg_parse_boolean (arg, &flag))
32 { 32 {
33 mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean")); 33 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("not a boolean"));
34 return 1; 34 return 1;
35 } 35 }
36 if (flag) 36 if (flag)
...@@ -39,12 +39,12 @@ cb_clear_library_path (mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -39,12 +39,12 @@ cb_clear_library_path (mu_cfg_locus_t *locus, void *data, char *arg)
39 } 39 }
40 40
41 static int 41 static int
42 cb_clear_include_path (mu_cfg_locus_t *locus, void *data, char *arg) 42 cb_clear_include_path (mu_debug_t debug, void *data, char *arg)
43 { 43 {
44 int flag; 44 int flag;
45 if (mu_cfg_parse_boolean (arg, &flag)) 45 if (mu_cfg_parse_boolean (arg, &flag))
46 { 46 {
47 mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean")); 47 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("not a boolean"));
48 return 1; 48 return 1;
49 } 49 }
50 if (flag) 50 if (flag)
...@@ -59,7 +59,7 @@ destroy_string (void *str) ...@@ -59,7 +59,7 @@ destroy_string (void *str)
59 } 59 }
60 60
61 static int 61 static int
62 _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg) 62 _add_path (mu_list_t *plist, mu_debug_t debug, void *data, char *arg)
63 { 63 {
64 char *p; 64 char *p;
65 65
...@@ -68,7 +68,8 @@ _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -68,7 +68,8 @@ _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg)
68 int rc = mu_list_create (plist); 68 int rc = mu_list_create (plist);
69 if (rc) 69 if (rc)
70 { 70 {
71 mu_error (_("cannot create list: %s"), mu_strerror (rc)); 71 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
72 _("cannot create list: %s"), mu_strerror (rc));
72 exit (1); 73 exit (1);
73 } 74 }
74 mu_list_set_destroy_item (*plist, destroy_string); 75 mu_list_set_destroy_item (*plist, destroy_string);
...@@ -79,15 +80,15 @@ _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -79,15 +80,15 @@ _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg)
79 } 80 }
80 81
81 static int 82 static int
82 cb_include_path (mu_cfg_locus_t *locus, void *data, char *arg) 83 cb_include_path (mu_debug_t debug, void *data, char *arg)
83 { 84 {
84 return _add_path (&sieve_settings.include_path, locus, data, arg); 85 return _add_path (&sieve_settings.include_path, debug, data, arg);
85 } 86 }
86 87
87 static int 88 static int
88 cb_library_path (mu_cfg_locus_t *locus, void *data, char *arg) 89 cb_library_path (mu_debug_t debug, void *data, char *arg)
89 { 90 {
90 return _add_path (&sieve_settings.library_path, locus, data, arg); 91 return _add_path (&sieve_settings.library_path, debug, data, arg);
91 } 92 }
92 93
93 static struct mu_cfg_param mu_sieve_param[] = { 94 static struct mu_cfg_param mu_sieve_param[] = {
......
...@@ -29,22 +29,23 @@ static struct mu_sql_module_config sql_settings; ...@@ -29,22 +29,23 @@ static struct mu_sql_module_config sql_settings;
29 29
30 /* Resource file configuration */ 30 /* Resource file configuration */
31 static int 31 static int
32 cb_password_type (mu_cfg_locus_t *locus, void *data, char *arg) 32 cb_password_type (mu_debug_t debug, void *data, char *arg)
33 { 33 {
34 if (mu_sql_decode_password_type (arg, &sql_settings.password_type)) 34 if (mu_sql_decode_password_type (arg, &sql_settings.password_type))
35 mu_error (_("%s:%d: Unknown password type `%s'"), 35 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
36 locus->file, locus->line, arg); 36 _("Unknown password type `%s'"),
37 arg);
37 return 0; 38 return 0;
38 } 39 }
39 40
40 static int 41 static int
41 cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg) 42 cb_field_map (mu_debug_t debug, void *data, char *arg)
42 { 43 {
43 int err; 44 int err;
44 int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err); 45 int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err);
45 if (rc) 46 if (rc)
46 mu_error (_("%s:%d: Error near element %d: %s"), 47 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("Error near element %d: %s"),
47 locus->file, locus->line, err, mu_strerror (rc)); 48 err, mu_strerror (rc));
48 return 0; 49 return 0;
49 } 50 }
50 51
......
...@@ -123,7 +123,7 @@ static const char *maidag_argp_capa[] = { ...@@ -123,7 +123,7 @@ static const char *maidag_argp_capa[] = {
123 #define D_DEFAULT "9,s" 123 #define D_DEFAULT "9,s"
124 124
125 static void 125 static void
126 set_debug_flags (const mu_cfg_locus_t *locus, const char *arg) 126 set_debug_flags (mu_debug_t debug, const char *arg)
127 { 127 {
128 while (*arg) 128 while (*arg)
129 { 129 {
...@@ -153,21 +153,16 @@ set_debug_flags (const mu_cfg_locus_t *locus, const char *arg) ...@@ -153,21 +153,16 @@ set_debug_flags (const mu_cfg_locus_t *locus, const char *arg)
153 break; 153 break;
154 154
155 default: 155 default:
156 if (locus) 156 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
157 mu_error (_("%s:%d: %c is not a valid debug flag"), 157 _("%c is not a valid debug flag"), *arg);
158 locus->file, locus->line, *arg);
159 else
160 mu_error (_("%c is not a valid debug flag"), *arg);
161 break; 158 break;
162 } 159 }
163 } 160 }
164 if (*arg == ',') 161 if (*arg == ',')
165 arg++; 162 arg++;
166 else if (locus)
167 mu_error (_("%s:%d: expected comma, but found %c"),
168 locus->file, locus->line, *arg);
169 else 163 else
170 mu_error (_("expected comma, but found %c"), *arg); 164 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
165 _("expected comma, but found %c"), *arg);
171 } 166 }
172 } 167 }
173 168
...@@ -229,9 +224,9 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -229,9 +224,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
229 224
230 225
231 static int 226 static int
232 cb_debug (mu_cfg_locus_t *locus, void *data, char *arg) 227 cb_debug (mu_debug_t debug, void *data, char *arg)
233 { 228 {
234 set_debug_flags (locus, arg); 229 set_debug_flags (debug, arg);
235 return 0; 230 return 0;
236 } 231 }
237 232
......
...@@ -130,7 +130,7 @@ char *saved_envelope; /* A hack to spare mu_envelope_ calls */ ...@@ -130,7 +130,7 @@ char *saved_envelope; /* A hack to spare mu_envelope_ calls */
130 #define D_DEFAULT "9s" 130 #define D_DEFAULT "9s"
131 131
132 static void 132 static void
133 set_debug_flags (const mu_cfg_locus_t *locus, const char *arg) 133 set_debug_flags (mu_debug_t debug, const char *arg)
134 { 134 {
135 for (; *arg; arg++) 135 for (; *arg; arg++)
136 { 136 {
...@@ -165,9 +165,10 @@ set_debug_flags (const mu_cfg_locus_t *locus, const char *arg) ...@@ -165,9 +165,10 @@ set_debug_flags (const mu_cfg_locus_t *locus, const char *arg)
165 default: 165 default:
166 if (isdigit (*arg)) 166 if (isdigit (*arg))
167 debug_level = *arg - '0'; 167 debug_level = *arg - '0';
168 else if (locus) 168 else if (debug)
169 mu_error (_("%s:%d: %c is not a valid debug flag"), 169 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
170 locus->file, locus->line, *arg); 170 _("%c is not a valid debug flag"),
171 *arg);
171 else 172 else
172 mu_error (_("%c is not a valid debug flag"), *arg); 173 mu_error (_("%c is not a valid debug flag"), *arg);
173 break; 174 break;
...@@ -239,9 +240,9 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -239,9 +240,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
239 240
240 241
241 static int 242 static int
242 cb_debug (mu_cfg_locus_t *locus, void *data, char *arg) 243 cb_debug (mu_debug_t debug, void *data, char *arg)
243 { 244 {
244 set_debug_flags (locus, arg); 245 set_debug_flags (debug, arg);
245 return 0; 246 return 0;
246 } 247 }
247 248
......
...@@ -225,8 +225,7 @@ again: ...@@ -225,8 +225,7 @@ again:
225 { 225 {
226 if (*p->curp == 0) 226 if (*p->curp == 0)
227 { 227 {
228 mu_cfg_perror (p, 228 mu_cfg_perror (&mu_cfg_locus,
229 &mu_cfg_locus,
230 _("unexpected EOF in comment started at line %d"), 229 _("unexpected EOF in comment started at line %d"),
231 keep_line); 230 keep_line);
232 return 0; 231 return 0;
...@@ -605,7 +604,8 @@ mu_config_register_plain_section (const char *parent_path, const char *ident, ...@@ -605,7 +604,8 @@ mu_config_register_plain_section (const char *parent_path, const char *ident,
605 static int 604 static int
606 prog_parser (enum mu_cfg_section_stage stage, 605 prog_parser (enum mu_cfg_section_stage stage,
607 const mu_cfg_node_t *node, 606 const mu_cfg_node_t *node,
608 void *section_data, void *call_data) 607 void *section_data, void *call_data,
608 mu_cfg_tree_t *tree)
609 { 609 {
610 if (stage == mu_cfg_section_start) 610 if (stage == mu_cfg_section_start)
611 { 611 {
...@@ -638,11 +638,11 @@ struct include_data ...@@ -638,11 +638,11 @@ struct include_data
638 int global; 638 int global;
639 }; 639 };
640 640
641 static int _mu_parse_config (char *file, char *progname, 641 static int _mu_parse_config (const char *file, const char *progname,
642 struct mu_cfg_param *progparam, int global); 642 struct mu_cfg_param *progparam, int global);
643 643
644 static int 644 static int
645 _cb_include (mu_cfg_locus_t *locus, void *data, char *arg) 645 _cb_include (mu_debug_t debug, void *data, char *arg)
646 { 646 {
647 int ret = 0; 647 int ret = 0;
648 struct stat sb; 648 struct stat sb;
...@@ -666,14 +666,14 @@ _cb_include (mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -666,14 +666,14 @@ _cb_include (mu_cfg_locus_t *locus, void *data, char *arg)
666 } 666 }
667 else if (errno == ENOENT) 667 else if (errno == ENOENT)
668 { 668 {
669 mu_cfg_perror (NULL, locus, 669 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
670 _("include directory does not exist")); 670 _("include file or directory does not exist"));
671 ret = 1; 671 ret = 1;
672 } 672 }
673 else 673 else
674 { 674 {
675 mu_cfg_perror (NULL, locus, 675 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
676 _("cannot stat include directory: %s"), 676 _("cannot stat include file or directory: %s"),
677 mu_strerror (errno)); 677 mu_strerror (errno));
678 ret = 1; 678 ret = 1;
679 } 679 }
...@@ -682,7 +682,7 @@ _cb_include (mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -682,7 +682,7 @@ _cb_include (mu_cfg_locus_t *locus, void *data, char *arg)
682 } 682 }
683 683
684 static int 684 static int
685 _mu_parse_config (char *file, char *progname, 685 _mu_parse_config (const char *file, const char *progname,
686 struct mu_cfg_param *progparam, int global) 686 struct mu_cfg_param *progparam, int global)
687 { 687 {
688 struct lexer_data data; 688 struct lexer_data data;
...@@ -690,7 +690,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -690,7 +690,7 @@ _mu_parse_config (char *file, char *progname,
690 int fd; 690 int fd;
691 extern int mu_cfg_yydebug; 691 extern int mu_cfg_yydebug;
692 int rc; 692 int rc;
693 mu_cfg_node_t *parse_tree; 693 mu_cfg_tree_t *parse_tree;
694 694
695 if (stat (file, &st)) 695 if (stat (file, &st))
696 { 696 {
...@@ -723,7 +723,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -723,7 +723,7 @@ _mu_parse_config (char *file, char *progname,
723 mu_cfg_yydebug = 0; 723 mu_cfg_yydebug = 0;
724 724
725 /* Parse configuration */ 725 /* Parse configuration */
726 mu_cfg_locus.file = file; 726 mu_cfg_locus.file = (char*) file;
727 mu_cfg_locus.line = 1; 727 mu_cfg_locus.line = 1;
728 rc = mu_cfg_parse (&parse_tree, 728 rc = mu_cfg_parse (&parse_tree,
729 &data, 729 &data,
...@@ -746,7 +746,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -746,7 +746,7 @@ _mu_parse_config (char *file, char *progname,
746 idata.progparam = progparam; 746 idata.progparam = progparam;
747 idata.global = global; 747 idata.global = global;
748 _mu_config_register_section (&cont, NULL, NULL, NULL, 748 _mu_config_register_section (&cont, NULL, NULL, NULL,
749 progname, mu_include_param, NULL); 749 (void*) progname, mu_include_param, NULL);
750 if (global) 750 if (global)
751 { 751 {
752 mu_iterator_t iter; 752 mu_iterator_t iter;
...@@ -757,7 +757,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -757,7 +757,7 @@ _mu_parse_config (char *file, char *progname,
757 progparam = &empty_param; 757 progparam = &empty_param;
758 758
759 _mu_config_register_section (&cont, NULL, "program", prog_parser, 759 _mu_config_register_section (&cont, NULL, "program", prog_parser,
760 progname, 760 (void*) progname,
761 progparam, &prog_sect); 761 progparam, &prog_sect);
762 762
763 if (old_root->v.section.subsec) 763 if (old_root->v.section.subsec)
...@@ -794,8 +794,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -794,8 +794,7 @@ _mu_parse_config (char *file, char *progname,
794 _mu_config_register_section (&cont, NULL, NULL, NULL, NULL, 794 _mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
795 progparam, NULL); 795 progparam, NULL);
796 796
797 rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, 797 rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, (void*) progname);
798 progname, NULL, NULL, NULL);
799 mu_config_destroy_container (&cont); 798 mu_config_destroy_container (&cont);
800 } 799 }
801 800
...@@ -811,7 +810,7 @@ _mu_parse_config (char *file, char *progname, ...@@ -811,7 +810,7 @@ _mu_parse_config (char *file, char *progname,
811 } 810 }
812 811
813 int 812 int
814 mu_parse_config (char *file, char *progname, 813 mu_parse_config (const char *file, const char *progname,
815 struct mu_cfg_param *progparam, int global) 814 struct mu_cfg_param *progparam, int global)
816 { 815 {
817 int rc; 816 int rc;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
28 #include <mailutils/error.h> 28 #include <mailutils/error.h>
29 #include <mailutils/list.h> 29 #include <mailutils/list.h>
30 #include <mailutils/iterator.h> 30 #include <mailutils/iterator.h>
31 #include <mailutils/debug.h>
31 32
32 int mu_cfg_parser_verbose; 33 int mu_cfg_parser_verbose;
33 static mu_cfg_node_t *parse_tree; 34 static mu_cfg_node_t *parse_tree;
...@@ -36,15 +37,15 @@ int mu_cfg_tie_in; ...@@ -36,15 +37,15 @@ int mu_cfg_tie_in;
36 37
37 static int _mu_cfg_errcnt; 38 static int _mu_cfg_errcnt;
38 static mu_cfg_lexer_t _mu_cfg_lexer; 39 static mu_cfg_lexer_t _mu_cfg_lexer;
39 mu_cfg_perror_t mu_cfg_perror;
40 static void *_mu_cfg_lexer_data; 40 static void *_mu_cfg_lexer_data;
41 mu_cfg_alloc_t _mu_cfg_alloc; 41 mu_cfg_alloc_t _mu_cfg_alloc;
42 mu_cfg_free_t _mu_cfg_free; 42 mu_cfg_free_t _mu_cfg_free;
43 static mu_debug_t _mu_cfg_debug;
43 44
44 static int 45 static int
45 yyerror (char *s) 46 yyerror (char *s)
46 { 47 {
47 mu_cfg_perror (_mu_cfg_lexer_data, &mu_cfg_locus, "%s", s); 48 mu_cfg_perror (&mu_cfg_locus, "%s", s);
48 return 0; 49 return 0;
49 } 50 }
50 51
...@@ -65,8 +66,7 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc, ...@@ -65,8 +66,7 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc,
65 np = _mu_cfg_alloc (size); 66 np = _mu_cfg_alloc (size);
66 if (!np) 67 if (!np)
67 { 68 {
68 mu_cfg_perror (_mu_cfg_lexer_data, &mu_cfg_locus, 69 mu_cfg_perror (&mu_cfg_locus, _("Not enough memory"));
69 _("Not enough memory"));
70 abort(); 70 abort();
71 } 71 }
72 np->type = type; 72 np->type = type;
...@@ -87,22 +87,47 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc, ...@@ -87,22 +87,47 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc,
87 return np; 87 return np;
88 } 88 }
89 89
90 void
91 mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...)
92 {
93 va_list ap;
94
95 va_start (ap, fmt);
96 mu_debug_vprintf (debug, 0, fmt, ap);
97 mu_debug_printf (debug, 0, "\n");
98 va_end (ap);
99 }
100
101 static void
102 _mu_cfg_vperror (mu_debug_t debug, const mu_cfg_locus_t *loc,
103 const char *fmt, va_list ap)
104 {
105 mu_debug_set_locus (_mu_cfg_debug,
106 loc->file ? loc->file : _("unknown file"),
107 loc->line);
108 mu_debug_vprintf (_mu_cfg_debug, 0, fmt, ap);
109 mu_debug_printf (_mu_cfg_debug, 0, "\n");
110 }
111
90 static void 112 static void
91 _mu_cfg_default_perror (void *ptr, const mu_cfg_locus_t *loc, 113 _mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *loc,
92 const char *fmt, ...) 114 const char *fmt, ...)
93 { 115 {
94 va_list ap; 116 va_list ap;
95 117
96 fprintf (stderr, "%s:", loc->file ? loc->file : _("unknown file"));
97 if (loc->line > 0)
98 fprintf (stderr, "%lu", (unsigned long) loc->line);
99 else
100 fprintf (stderr, "%s", _("unknown line"));
101 fprintf (stderr, ": ");
102 va_start (ap, fmt); 118 va_start (ap, fmt);
103 vfprintf (stderr, fmt, ap); 119 _mu_cfg_vperror (debug, loc, fmt, ap);
120 va_end (ap);
121 }
122
123 void
124 mu_cfg_perror (const mu_cfg_locus_t *loc, const char *fmt, ...)
125 {
126 va_list ap;
127
128 va_start (ap, fmt);
129 _mu_cfg_vperror (_mu_cfg_debug, loc, fmt, ap);
104 va_end (ap); 130 va_end (ap);
105 fprintf (stderr, "\n");
106 } 131 }
107 132
108 %} 133 %}
...@@ -157,12 +182,10 @@ tag : MU_CFG_START_TOKEN opt_eol taglist MU_CFG_END_TOKEN MU_CFG_EOL_TOKEN ...@@ -157,12 +182,10 @@ tag : MU_CFG_START_TOKEN opt_eol taglist MU_CFG_END_TOKEN MU_CFG_EOL_TOKEN
157 { 182 {
158 if ($4.tag_name && strcmp ($4.tag_name, $1.tag_name)) 183 if ($4.tag_name && strcmp ($4.tag_name, $1.tag_name))
159 { 184 {
160 mu_cfg_perror (_mu_cfg_lexer_data, 185 mu_cfg_perror (&$1.locus,
161 &$1.locus,
162 _("Tag %s not closed"), 186 _("Tag %s not closed"),
163 $1.tag_name); 187 $1.tag_name);
164 mu_cfg_perror (_mu_cfg_lexer_data, 188 mu_cfg_perror (&$4.locus,
165 &$4.locus,
166 _("Found closing %s tag instead"), 189 _("Found closing %s tag instead"),
167 $4.tag_name); 190 $4.tag_name);
168 _mu_cfg_errcnt++; 191 _mu_cfg_errcnt++;
...@@ -180,17 +203,31 @@ tag : MU_CFG_START_TOKEN opt_eol taglist MU_CFG_END_TOKEN MU_CFG_EOL_TOKEN ...@@ -180,17 +203,31 @@ tag : MU_CFG_START_TOKEN opt_eol taglist MU_CFG_END_TOKEN MU_CFG_EOL_TOKEN
180 203
181 %% 204 %%
182 205
206 static int
207 _cfg_default_printer (void *unused, size_t level, const char *str)
208 {
209 fprintf (stderr, "%s", str);
210 return 0;
211 }
212
183 int 213 int
184 mu_cfg_parse (mu_cfg_node_t **ptree, 214 mu_cfg_parse (mu_cfg_tree_t **ptree,
185 void *data, mu_cfg_lexer_t lexer, 215 void *data, mu_cfg_lexer_t lexer,
186 mu_cfg_perror_t perror, 216 mu_debug_t debug,
187 mu_cfg_alloc_t palloc, mu_cfg_free_t pfree) 217 mu_cfg_alloc_t palloc, mu_cfg_free_t pfree)
188 { 218 {
189 int rc; 219 int rc;
220 mu_cfg_tree_t *tree;
190 221
191 _mu_cfg_lexer = lexer; 222 _mu_cfg_lexer = lexer;
192 _mu_cfg_lexer_data = data; 223 _mu_cfg_lexer_data = data;
193 mu_cfg_perror = perror ? perror : _mu_cfg_default_perror; 224 if (debug)
225 _mu_cfg_debug = debug;
226 else
227 {
228 mu_debug_create (&_mu_cfg_debug, NULL);
229 mu_debug_set_print (_mu_cfg_debug, _cfg_default_printer, NULL);
230 }
194 _mu_cfg_alloc = palloc ? palloc : malloc; 231 _mu_cfg_alloc = palloc ? palloc : malloc;
195 _mu_cfg_free = pfree ? pfree : free; 232 _mu_cfg_free = pfree ? pfree : free;
196 _mu_cfg_errcnt = 0; 233 _mu_cfg_errcnt = 0;
...@@ -199,8 +236,14 @@ mu_cfg_parse (mu_cfg_node_t **ptree, ...@@ -199,8 +236,14 @@ mu_cfg_parse (mu_cfg_node_t **ptree,
199 if (rc == 0 && _mu_cfg_errcnt) 236 if (rc == 0 && _mu_cfg_errcnt)
200 rc = 1; 237 rc = 1;
201 /* FIXME if (rc) free_memory; else */ 238 /* FIXME if (rc) free_memory; else */
202 *ptree = parse_tree; 239
240 tree = _mu_cfg_alloc (sizeof (*tree));
241 tree->debug = _mu_cfg_debug;
242 tree->alloc = _mu_cfg_alloc;
243 tree->free = _mu_cfg_free;
244 tree->node = parse_tree;
203 parse_tree = NULL; 245 parse_tree = NULL;
246 *ptree = tree;
204 return rc; 247 return rc;
205 } 248 }
206 249
...@@ -382,12 +425,14 @@ free_param (const mu_cfg_node_t *node, void *data) ...@@ -382,12 +425,14 @@ free_param (const mu_cfg_node_t *node, void *data)
382 } 425 }
383 426
384 void 427 void
385 mu_cfg_destroy_tree (mu_cfg_node_t **tree) 428 mu_cfg_destroy_tree (mu_cfg_tree_t **ptree)
386 { 429 {
387 if (tree && *tree) 430 if (ptree && *ptree)
388 { 431 {
389 mu_cfg_postorder (*tree, free_param, free_section, _mu_cfg_free); 432 mu_cfg_tree_t *tree = *ptree;
390 *tree = NULL; 433 mu_cfg_postorder (tree->node, free_param, free_section, tree->free);
434 mu_debug_destroy (&tree->debug, NULL);
435 *ptree = NULL;
391 } 436 }
392 } 437 }
393 438
...@@ -488,6 +533,7 @@ struct scan_tree_data ...@@ -488,6 +533,7 @@ struct scan_tree_data
488 { 533 {
489 struct mu_cfg_section_list *list; 534 struct mu_cfg_section_list *list;
490 void *call_data; 535 void *call_data;
536 mu_cfg_tree_t *tree;
491 int error; 537 int error;
492 }; 538 };
493 539
...@@ -551,10 +597,10 @@ find_param (struct mu_cfg_section *sec, const char *ident, size_t len) ...@@ -551,10 +597,10 @@ find_param (struct mu_cfg_section *sec, const char *ident, size_t len)
551 static int 597 static int
552 push_section (struct scan_tree_data *dat, struct mu_cfg_section *sec) 598 push_section (struct scan_tree_data *dat, struct mu_cfg_section *sec)
553 { 599 {
554 struct mu_cfg_section_list *p = _mu_cfg_alloc (sizeof *p); 600 struct mu_cfg_section_list *p = dat->tree->alloc (sizeof *p);
555 if (!p) 601 if (!p)
556 { 602 {
557 mu_cfg_perror (dat->call_data, NULL, _("not enough memory")); 603 _mu_cfg_perror (dat->tree->debug, NULL, _("not enough memory"));
558 return 1; 604 return 1;
559 } 605 }
560 p->sec = sec; 606 p->sec = sec;
...@@ -569,11 +615,11 @@ pop_section (struct scan_tree_data *dat) ...@@ -569,11 +615,11 @@ pop_section (struct scan_tree_data *dat)
569 struct mu_cfg_section_list *p = dat->list; 615 struct mu_cfg_section_list *p = dat->list;
570 struct mu_cfg_section *sec = p->sec; 616 struct mu_cfg_section *sec = p->sec;
571 dat->list = p->next; 617 dat->list = p->next;
572 _mu_cfg_free (p); 618 dat->tree->free (p);
573 return sec; 619 return sec;
574 } 620 }
575 621
576 #define STRTONUM(s, type, base, res, limit) \ 622 #define STRTONUM(s, type, base, res, limit, d) \
577 { \ 623 { \
578 type sum = 0; \ 624 type sum = 0; \
579 \ 625 \
...@@ -591,15 +637,13 @@ pop_section (struct scan_tree_data *dat) ...@@ -591,15 +637,13 @@ pop_section (struct scan_tree_data *dat)
591 break; \ 637 break; \
592 if (x <= sum) \ 638 if (x <= sum) \
593 { \ 639 { \
594 mu_cfg_perror (sdata->call_data, \ 640 _mu_cfg_perror (d, &node->locus, \
595 &node->locus, \
596 _("numeric overflow")); \ 641 _("numeric overflow")); \
597 return 1; \ 642 return 1; \
598 } \ 643 } \
599 else if (limit && x > limit) \ 644 else if (limit && x > limit) \
600 { \ 645 { \
601 mu_cfg_perror (sdata->call_data, \ 646 _mu_cfg_perror (d, &node->locus, \
602 &node->locus, \
603 _("value out of allowed range")); \ 647 _("value out of allowed range")); \
604 return 1; \ 648 return 1; \
605 } \ 649 } \
...@@ -609,7 +653,7 @@ pop_section (struct scan_tree_data *dat) ...@@ -609,7 +653,7 @@ pop_section (struct scan_tree_data *dat)
609 res = sum; \ 653 res = sum; \
610 } 654 }
611 655
612 #define STRxTONUM(s, type, res, limit) \ 656 #define STRxTONUM(s, type, res, limit, d) \
613 { \ 657 { \
614 int base; \ 658 int base; \
615 if (*s == '0') \ 659 if (*s == '0') \
...@@ -626,18 +670,17 @@ pop_section (struct scan_tree_data *dat) ...@@ -626,18 +670,17 @@ pop_section (struct scan_tree_data *dat)
626 base = 8; \ 670 base = 8; \
627 } else \ 671 } else \
628 base = 10; \ 672 base = 10; \
629 STRTONUM (s, type, base, res, limit); \ 673 STRTONUM (s, type, base, res, limit, d); \
630 } 674 }
631 675
632 #define GETUNUM(str, type, res) \ 676 #define GETUNUM(str, type, res, d) \
633 { \ 677 { \
634 type tmpres; \ 678 type tmpres; \
635 const char *s = str; \ 679 const char *s = str; \
636 STRxTONUM (s, type, tmpres, 0); \ 680 STRxTONUM (s, type, tmpres, 0, d); \
637 if (*s) \ 681 if (*s) \
638 { \ 682 { \
639 mu_cfg_perror (sdata->call_data, \ 683 _mu_cfg_perror (d, &node->locus, \
640 &node->locus, \
641 _("not a number (stopped near `%s')"), \ 684 _("not a number (stopped near `%s')"), \
642 s); \ 685 s); \
643 return 1; \ 686 return 1; \
...@@ -645,7 +688,7 @@ pop_section (struct scan_tree_data *dat) ...@@ -645,7 +688,7 @@ pop_section (struct scan_tree_data *dat)
645 res = tmpres; \ 688 res = tmpres; \
646 } 689 }
647 690
648 #define GETSNUM(str, type, res) \ 691 #define GETSNUM(str, type, res, d) \
649 { \ 692 { \
650 unsigned type tmpres; \ 693 unsigned type tmpres; \
651 const char *s = str; \ 694 const char *s = str; \
...@@ -665,11 +708,10 @@ pop_section (struct scan_tree_data *dat) ...@@ -665,11 +708,10 @@ pop_section (struct scan_tree_data *dat)
665 limit = TYPE_MAXIMUM (type); \ 708 limit = TYPE_MAXIMUM (type); \
666 } \ 709 } \
667 \ 710 \
668 STRxTONUM (s, unsigned type, tmpres, limit); \ 711 STRxTONUM (s, unsigned type, tmpres, limit, d); \
669 if (*s) \ 712 if (*s) \
670 { \ 713 { \
671 mu_cfg_perror (sdata->call_data, \ 714 _mu_cfg_perror (d, &node->locus, \
672 &node->locus, \
673 _("not a number (stopped near `%s')"), \ 715 _("not a number (stopped near `%s')"), \
674 s); \ 716 s); \
675 return 1; \ 717 return 1; \
...@@ -684,9 +726,7 @@ parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -684,9 +726,7 @@ parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
684 struct in_addr addr; 726 struct in_addr addr;
685 if (inet_aton (node->tag_label, &addr) == 0) 727 if (inet_aton (node->tag_label, &addr) == 0)
686 { 728 {
687 mu_cfg_perror (sdata->call_data, 729 _mu_cfg_perror (sdata->tree->debug, &node->locus, _("not an IPv4"));
688 &node->locus,
689 _("not an IPv4"));
690 return 1; 730 return 1;
691 } 731 }
692 addr.s_addr = ntohl (addr.s_addr); 732 addr.s_addr = ntohl (addr.s_addr);
...@@ -704,10 +744,9 @@ parse_host (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -704,10 +744,9 @@ parse_host (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
704 { 744 {
705 addr.s_addr = *(unsigned long *)hp->h_addr; 745 addr.s_addr = *(unsigned long *)hp->h_addr;
706 } 746 }
707 else if (inet_aton(node->tag_label, &addr) == 0) 747 else if (inet_aton (node->tag_label, &addr) == 0)
708 { 748 {
709 mu_cfg_perror (sdata->call_data, 749 _mu_cfg_perror (sdata->tree->debug, &node->locus,
710 &node->locus,
711 _("cannot resolve hostname `%s'"), 750 _("cannot resolve hostname `%s'"),
712 node->tag_label); 751 node->tag_label);
713 return 1; 752 return 1;
...@@ -730,8 +769,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -730,8 +769,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
730 { 769 {
731 int len = p - node->tag_label; 770 int len = p - node->tag_label;
732 if (len > sizeof astr - 1) { 771 if (len > sizeof astr - 1) {
733 mu_cfg_perror (sdata->call_data, 772 _mu_cfg_perror (sdata->tree->debug, &node->locus,
734 &node->locus,
735 _("not a valid IPv4 address in CIDR")); 773 _("not a valid IPv4 address in CIDR"));
736 return 1; 774 return 1;
737 } 775 }
...@@ -739,8 +777,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -739,8 +777,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
739 astr[len] = 0; 777 astr[len] = 0;
740 if (inet_aton (astr, &addr) == 0) 778 if (inet_aton (astr, &addr) == 0)
741 { 779 {
742 mu_cfg_perror (sdata->call_data, 780 _mu_cfg_perror (sdata->tree->debug, &node->locus,
743 &node->locus,
744 _("not a valid IPv4 address in CIDR")); 781 _("not a valid IPv4 address in CIDR"));
745 return 1; 782 return 1;
746 } 783 }
...@@ -748,14 +785,13 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -748,14 +785,13 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
748 785
749 p++; 786 p++;
750 s = p; 787 s = p;
751 STRxTONUM (s, unsigned long, mask, 0); 788 STRxTONUM (s, unsigned long, mask, 0, sdata->tree->debug);
752 if (*s == '.') 789 if (*s == '.')
753 { 790 {
754 struct in_addr a; 791 struct in_addr a;
755 if (inet_aton (p, &a) == 0) 792 if (inet_aton (p, &a) == 0)
756 { 793 {
757 mu_cfg_perror (sdata->call_data, 794 _mu_cfg_perror (sdata->tree->debug, &node->locus,
758 &node->locus,
759 _("not a valid network in CIDR")); 795 _("not a valid network in CIDR"));
760 return 1; 796 return 1;
761 } 797 }
...@@ -769,8 +805,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -769,8 +805,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
769 } 805 }
770 else if (mask > 32) 806 else if (mask > 32)
771 { 807 {
772 mu_cfg_perror (sdata->call_data, 808 _mu_cfg_perror (sdata->tree->debug, &node->locus,
773 &node->locus,
774 _("not a valid network mask in CIDR")); 809 _("not a valid network mask in CIDR"));
775 return 1; 810 return 1;
776 } 811 }
...@@ -783,7 +818,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -783,7 +818,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
783 818
784 for (i = 0; i < 3; i++) 819 for (i = 0; i < 3; i++)
785 { 820 {
786 STRxTONUM(p, unsigned short, x, 255); 821 STRxTONUM(p, unsigned short, x, 255, sdata->tree->debug);
787 if (*p != '.') 822 if (*p != '.')
788 break; 823 break;
789 addr.s_addr = (addr.s_addr << 8) + x; 824 addr.s_addr = (addr.s_addr << 8) + x;
...@@ -791,8 +826,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, ...@@ -791,8 +826,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
791 826
792 if (*p) 827 if (*p)
793 { 828 {
794 mu_cfg_perror (sdata->call_data, 829 _mu_cfg_perror (sdata->tree->debug, &node->locus,
795 &node->locus,
796 _("not a CIDR (stopped near `%s')"), 830 _("not a CIDR (stopped near `%s')"),
797 p); 831 p);
798 return 1; 832 return 1;
...@@ -833,7 +867,7 @@ parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res) ...@@ -833,7 +867,7 @@ parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res)
833 { 867 {
834 if (mu_cfg_parse_boolean (node->tag_label, res)) 868 if (mu_cfg_parse_boolean (node->tag_label, res))
835 { 869 {
836 mu_cfg_perror (sdata->call_data, &node->locus, _("not a boolean")); 870 _mu_cfg_perror (sdata->tree->debug, &node->locus, _("not a boolean"));
837 return 1; 871 return 1;
838 } 872 }
839 return 0; 873 return 0;
...@@ -846,8 +880,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -846,8 +880,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
846 0); 880 0);
847 if (!param) 881 if (!param)
848 { 882 {
849 mu_cfg_perror (sdata->call_data, 883 _mu_cfg_perror (sdata->tree->debug, &node->locus,
850 &node->locus,
851 _("unknown keyword `%s'"), 884 _("unknown keyword `%s'"),
852 node->tag_name); 885 node->tag_name);
853 return 1; 886 return 1;
...@@ -858,11 +891,10 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -858,11 +891,10 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
858 case mu_cfg_string: 891 case mu_cfg_string:
859 { 892 {
860 size_t len = strlen (node->tag_label); 893 size_t len = strlen (node->tag_label);
861 char *s = _mu_cfg_alloc (len + 1); 894 char *s = sdata->tree->alloc (len + 1);
862 if (!s) 895 if (!s)
863 { 896 {
864 mu_cfg_perror (sdata->call_data, 897 _mu_cfg_perror (sdata->tree->debug, &node->locus,
865 &node->locus,
866 _("not enough memory")); 898 _("not enough memory"));
867 return 1; 899 return 1;
868 } 900 }
...@@ -873,40 +905,48 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -873,40 +905,48 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
873 } 905 }
874 906
875 case mu_cfg_short: 907 case mu_cfg_short:
876 GETSNUM (node->tag_label, short, *(short*)param->data); 908 GETSNUM (node->tag_label, short, *(short*)param->data,
909 sdata->tree->debug);
877 break; 910 break;
878 911
879 case mu_cfg_ushort: 912 case mu_cfg_ushort:
880 GETUNUM (node->tag_label, unsigned short, *(unsigned short*)param->data); 913 GETUNUM (node->tag_label, unsigned short, *(unsigned short*)param->data,
914 sdata->tree->debug);
881 break; 915 break;
882 916
883 case mu_cfg_int: 917 case mu_cfg_int:
884 GETSNUM (node->tag_label, int, *(int*)param->data); 918 GETSNUM (node->tag_label, int, *(int*)param->data, sdata->tree->debug);
885 break; 919 break;
886 920
887 case mu_cfg_uint: 921 case mu_cfg_uint:
888 GETUNUM (node->tag_label, unsigned int, *(unsigned int*)param->data); 922 GETUNUM (node->tag_label, unsigned int, *(unsigned int*)param->data,
923 sdata->tree->debug);
889 break; 924 break;
890 925
891 case mu_cfg_long: 926 case mu_cfg_long:
892 GETSNUM (node->tag_label, long, *(long*)param->data); 927 GETSNUM (node->tag_label, long, *(long*)param->data,
928 sdata->tree->debug);
893 break; 929 break;
894 930
895 case mu_cfg_ulong: 931 case mu_cfg_ulong:
896 GETUNUM (node->tag_label, unsigned long, *(unsigned long*)param->data); 932 GETUNUM (node->tag_label, unsigned long, *(unsigned long*)param->data,
933 sdata->tree->debug);
897 break; 934 break;
898 935
899 case mu_cfg_size: 936 case mu_cfg_size:
900 GETUNUM (node->tag_label, size_t, *(size_t*)param->data); 937 GETUNUM (node->tag_label, size_t, *(size_t*)param->data,
938 sdata->tree->debug);
901 break; 939 break;
902 940
903 case mu_cfg_off: 941 case mu_cfg_off:
904 mu_cfg_perror (sdata->call_data, &node->locus, _("not implemented yet")); 942 _mu_cfg_perror (sdata->tree->debug, &node->locus,
943 _("not implemented yet"));
905 /* GETSNUM(node->tag_label, off_t, *(off_t*)param->data); */ 944 /* GETSNUM(node->tag_label, off_t, *(off_t*)param->data); */
906 return 1; 945 return 1;
907 946
908 case mu_cfg_time: 947 case mu_cfg_time:
909 GETUNUM (node->tag_label, time_t, *(time_t*)param->data); 948 GETUNUM (node->tag_label, time_t, *(time_t*)param->data,
949 sdata->tree->debug);
910 break; 950 break;
911 951
912 case mu_cfg_bool: 952 case mu_cfg_bool:
...@@ -930,7 +970,9 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -930,7 +970,9 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
930 break; 970 break;
931 971
932 case mu_cfg_callback: 972 case mu_cfg_callback:
933 if (param->callback (&node->locus, param->data, node->tag_label)) 973 mu_debug_set_locus (sdata->tree->debug, node->locus.file,
974 node->locus.line);
975 if (param->callback (sdata->tree->debug, param->data, node->tag_label))
934 return 1; 976 return 1;
935 break; 977 break;
936 978
...@@ -958,8 +1000,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) ...@@ -958,8 +1000,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
958 { 1000 {
959 if (mu_cfg_parser_verbose) 1001 if (mu_cfg_parser_verbose)
960 { 1002 {
961 mu_cfg_perror (sdata->call_data, 1003 _mu_cfg_perror (sdata->tree->debug, &node->locus,
962 &node->locus,
963 _("unknown section `%s'"), 1004 _("unknown section `%s'"),
964 node->tag_name); 1005 node->tag_name);
965 } 1006 }
...@@ -969,7 +1010,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) ...@@ -969,7 +1010,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
969 return MU_CFG_ITER_SKIP; 1010 return MU_CFG_ITER_SKIP;
970 if (sec->parser && 1011 if (sec->parser &&
971 sec->parser (mu_cfg_section_start, node, 1012 sec->parser (mu_cfg_section_start, node,
972 sec->data, sdata->call_data)) 1013 sec->data, sdata->call_data, sdata->tree))
973 { 1014 {
974 sdata->error++; 1015 sdata->error++;
975 return MU_CFG_ITER_SKIP; 1016 return MU_CFG_ITER_SKIP;
...@@ -1004,7 +1045,7 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data) ...@@ -1004,7 +1045,7 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data)
1004 if (sec && sec->parser) 1045 if (sec && sec->parser)
1005 { 1046 {
1006 if (sec->parser (mu_cfg_section_end, node, sec->data, 1047 if (sec->parser (mu_cfg_section_end, node, sec->data,
1007 sdata->call_data)) 1048 sdata->call_data, sdata->tree))
1008 { 1049 {
1009 sdata->error++; 1050 sdata->error++;
1010 return MU_CFG_ITER_SKIP; 1051 return MU_CFG_ITER_SKIP;
...@@ -1015,21 +1056,17 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data) ...@@ -1015,21 +1056,17 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data)
1015 } 1056 }
1016 1057
1017 int 1058 int
1018 mu_cfg_scan_tree (mu_cfg_node_t *node, 1059 mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
1019 struct mu_cfg_section *sections, 1060 void *data)
1020 void *data, mu_cfg_perror_t perror,
1021 mu_cfg_alloc_t palloc, mu_cfg_free_t pfree)
1022 { 1061 {
1023 struct scan_tree_data dat; 1062 struct scan_tree_data dat;
1063 dat.tree = tree;
1024 dat.list = NULL; 1064 dat.list = NULL;
1025 mu_cfg_perror = perror ? perror : _mu_cfg_default_perror;
1026 _mu_cfg_alloc = palloc ? palloc : malloc;
1027 _mu_cfg_free = pfree ? pfree : free;
1028 dat.call_data = data;
1029 dat.error = 0; 1065 dat.error = 0;
1066 dat.call_data = data;
1030 if (push_section (&dat, sections)) 1067 if (push_section (&dat, sections))
1031 return 1; 1068 return 1;
1032 mu_cfg_preorder (node, _scan_tree_helper, _scan_tree_end_helper, &dat); 1069 mu_cfg_preorder (tree->node, _scan_tree_helper, _scan_tree_end_helper, &dat);
1033 pop_section (&dat); 1070 pop_section (&dat);
1034 return dat.error; 1071 return dat.error;
1035 } 1072 }
......
...@@ -120,6 +120,28 @@ mu_debug_set_data (mu_debug_t debug, void *data, void (*destroy) (void*), ...@@ -120,6 +120,28 @@ mu_debug_set_data (mu_debug_t debug, void *data, void (*destroy) (void*),
120 return 0; 120 return 0;
121 } 121 }
122 122
123 static void
124 debug_format_prefix (mu_debug_t debug)
125 {
126 int need_space = 0;
127 if (debug->locus.file)
128 {
129 mu_stream_sequential_printf (debug->stream, "%s:%d:",
130 debug->locus.file, debug->locus.line);
131 need_space = 1;
132 }
133
134 if (debug->function)
135 {
136 mu_stream_sequential_printf (debug->stream, "%s:",
137 debug->function);
138 need_space = 1;
139 }
140
141 if (need_space)
142 mu_stream_sequential_write (debug->stream, " ", 1);
143 }
144
123 int 145 int
124 mu_debug_vprintf (mu_debug_t debug, size_t level, 146 mu_debug_vprintf (mu_debug_t debug, size_t level,
125 const char *format, va_list ap) 147 const char *format, va_list ap)
...@@ -133,7 +155,6 @@ mu_debug_vprintf (mu_debug_t debug, size_t level, ...@@ -133,7 +155,6 @@ mu_debug_vprintf (mu_debug_t debug, size_t level,
133 mu_transport_t tbuf; 155 mu_transport_t tbuf;
134 char *ptr, *start, *p; 156 char *ptr, *start, *p;
135 size_t nseg; 157 size_t nseg;
136 int need_space = 0;
137 158
138 if (debug->stream == NULL) 159 if (debug->stream == NULL)
139 { 160 {
...@@ -149,7 +170,11 @@ mu_debug_vprintf (mu_debug_t debug, size_t level, ...@@ -149,7 +170,11 @@ mu_debug_vprintf (mu_debug_t debug, size_t level,
149 } 170 }
150 } 171 }
151 172
173 if (mu_stream_size (debug->stream, &len) == 0 && len == 0)
174 debug_format_prefix (debug);
175
152 mu_stream_sequential_vprintf (debug->stream, format, ap); 176 mu_stream_sequential_vprintf (debug->stream, format, ap);
177
153 mu_stream_get_transport (debug->stream, &tbuf); 178 mu_stream_get_transport (debug->stream, &tbuf);
154 start = (char*) tbuf; 179 start = (char*) tbuf;
155 mu_stream_size (debug->stream, &len); 180 mu_stream_size (debug->stream, &len);
...@@ -180,26 +205,7 @@ mu_debug_vprintf (mu_debug_t debug, size_t level, ...@@ -180,26 +205,7 @@ mu_debug_vprintf (mu_debug_t debug, size_t level,
180 205
181 mu_stream_truncate (debug->stream, len); 206 mu_stream_truncate (debug->stream, len);
182 mu_stream_seek (debug->stream, len, SEEK_SET); 207 mu_stream_seek (debug->stream, len, SEEK_SET);
183 if (len)
184 return 0;
185 }
186
187 if (debug->locus.file)
188 {
189 mu_stream_sequential_printf (debug->stream, "%s:%d:",
190 debug->locus.file, debug->locus.line);
191 need_space = 1;
192 } 208 }
193
194 if (debug->function)
195 {
196 mu_stream_sequential_printf (debug->stream, "%s:",
197 debug->function);
198 need_space = 1;
199 }
200
201 if (need_space)
202 mu_stream_sequential_write (debug->stream, " ", 1);
203 } 209 }
204 else 210 else
205 vfprintf (stderr, format, ap); 211 vfprintf (stderr, format, ap);
......
...@@ -66,7 +66,7 @@ char *mimeview_file; /* Name of the file to view */ ...@@ -66,7 +66,7 @@ char *mimeview_file; /* Name of the file to view */
66 FILE *mimeview_fp; /* Its descriptor */ 66 FILE *mimeview_fp; /* Its descriptor */
67 67
68 static void 68 static void
69 set_debug_flags (mu_cfg_locus_t *locus, char *arg) 69 set_debug_flags (mu_debug_t debug, char *arg)
70 { 70 {
71 for (; *arg; arg++) 71 for (; *arg; arg++)
72 { 72 {
...@@ -147,9 +147,9 @@ static struct argp argp = { ...@@ -147,9 +147,9 @@ static struct argp argp = {
147 147
148 148
149 static int 149 static int
150 cb_debug (mu_cfg_locus_t *locus, void *data, char *arg) 150 cb_debug (mu_debug_t debug, void *data, char *arg)
151 { 151 {
152 set_debug_flags (locus, arg); 152 set_debug_flags (debug, arg);
153 return 0; 153 return 0;
154 } 154 }
155 155
......
...@@ -112,7 +112,7 @@ static struct argp_option options[] = { ...@@ -112,7 +112,7 @@ static struct argp_option options[] = {
112 112
113 #ifdef WITH_TLS 113 #ifdef WITH_TLS
114 static int 114 static int
115 cb_tls_expired (mu_cfg_locus_t *locus, void *data, char *arg) 115 cb_tls_required (mu_debug_t debug, void *data, char *arg)
116 { 116 {
117 initial_state = INITIAL; 117 initial_state = INITIAL;
118 return 0; 118 return 0;
...@@ -120,16 +120,16 @@ cb_tls_expired (mu_cfg_locus_t *locus, void *data, char *arg) ...@@ -120,16 +120,16 @@ cb_tls_expired (mu_cfg_locus_t *locus, void *data, char *arg)
120 #endif 120 #endif
121 121
122 static int 122 static int
123 cb_bulletin_source (mu_cfg_locus_t *locus, void *data, char *arg) 123 cb_bulletin_source (mu_debug_t debug, void *data, char *arg)
124 { 124 {
125 set_bulletin_source (arg); 125 set_bulletin_source (arg); /* FIXME: Error reporting? */
126 return 0; 126 return 0;
127 } 127 }
128 128
129 static int 129 static int
130 cb_bulletin_db (mu_cfg_locus_t *locus, void *data, char *arg) 130 cb_bulletin_db (mu_debug_t debug, void *data, char *arg)
131 { 131 {
132 set_bulletin_db (arg); 132 set_bulletin_db (arg); /* FIXME: Error reporting? */
133 return 0; 133 return 0;
134 } 134 }
135 135
...@@ -138,7 +138,7 @@ static struct mu_cfg_param pop3d_cfg_param[] = { ...@@ -138,7 +138,7 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
138 { "expire", mu_cfg_time, &expire }, 138 { "expire", mu_cfg_time, &expire },
139 { "delete-expired", mu_cfg_int, &expire_on_exit }, 139 { "delete-expired", mu_cfg_int, &expire_on_exit },
140 #ifdef WITH_TLS 140 #ifdef WITH_TLS
141 { "tls-required", mu_cfg_callback, NULL, cb_tls_expired }, 141 { "tls-required", mu_cfg_callback, NULL, cb_tls_required },
142 #endif 142 #endif
143 #ifdef ENABLE_LOGIN_DELAY 143 #ifdef ENABLE_LOGIN_DELAY
144 { "login-delay", mu_cfg_time, &login_delay }, 144 { "login-delay", mu_cfg_time, &login_delay },
......
...@@ -123,7 +123,7 @@ is_true_p (char *p) ...@@ -123,7 +123,7 @@ is_true_p (char *p)
123 } 123 }
124 124
125 static void 125 static void
126 set_debug_level (mu_cfg_locus_t *locus, const char *arg) 126 set_debug_level (mu_debug_t debug, const char *arg)
127 { 127 {
128 for (; *arg; arg++) 128 for (; *arg; arg++)
129 { 129 {
...@@ -150,9 +150,9 @@ set_debug_level (mu_cfg_locus_t *locus, const char *arg) ...@@ -150,9 +150,9 @@ set_debug_level (mu_cfg_locus_t *locus, const char *arg)
150 break; 150 break;
151 151
152 default: 152 default:
153 if (locus) 153 if (debug)
154 mu_error (_("%s:%d: %c is not a valid debug flag"), 154 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
155 locus->file, locus->line, *arg); 155 _("%c is not a valid debug flag"), *arg);
156 else 156 else
157 mu_error (_("%c is not a valid debug flag"), *arg); 157 mu_error (_("%c is not a valid debug flag"), *arg);
158 } 158 }
...@@ -240,24 +240,24 @@ static struct argp argp = ...@@ -240,24 +240,24 @@ static struct argp argp =
240 240
241 241
242 static int 242 static int
243 cb_debug (mu_cfg_locus_t *locus, void *data, char *arg) 243 cb_debug (mu_debug_t debug, void *data, char *arg)
244 { 244 {
245 set_debug_level (locus, arg); 245 set_debug_level (debug, arg);
246 return 0; 246 return 0;
247 } 247 }
248 248
249 static int 249 static int
250 cb_email (mu_cfg_locus_t *locus, void *data, char *arg) 250 cb_email (mu_debug_t debug, void *data, char *arg)
251 { 251 {
252 int rc = mu_set_user_email (arg); 252 int rc = mu_set_user_email (arg);
253 if (rc) 253 if (rc)
254 mu_error (_("%s:%d: Invalid email: %s"), 254 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("Invalid email: %s"),
255 locus->file, locus->line, mu_strerror (rc)); 255 mu_strerror (rc));
256 return rc; 256 return rc;
257 } 257 }
258 258
259 static int 259 static int
260 cb_ticket (mu_cfg_locus_t *locus, void *data, char *arg) 260 cb_ticket (mu_debug_t debug, void *data, char *arg)
261 { 261 {
262 free (tickets); 262 free (tickets);
263 tickets = mu_tilde_expansion (arg, "/", NULL); 263 tickets = mu_tilde_expansion (arg, "/", NULL);
......