diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-11-24 18:45:40 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-11-24 18:45:40 +0000 |
commit | fdbd31f1a9c16c0b71e6baead42bf2ed157fbe59 (patch) | |
tree | e6af9c993deb9472aa844eb30d6f306d54bd222e | |
parent | db281aca9fb0ca5fd03741ce64d28882e2413c72 (diff) | |
download | mailutils-fdbd31f1a9c16c0b71e6baead42bf2ed157fbe59.tar.gz mailutils-fdbd31f1a9c16c0b71e6baead42bf2ed157fbe59.tar.bz2 |
Improve debugging.
* imap4d/login.c, pop3d/user.c: Print user db source along with
the login name.
* include/mailutils/debug.h (mu_debug_set_print): Change
prototype.
(mu_debug_printer_fp): New data type.
(mu_debug_default_printer): New extern.
(mu_debug_syslog_printer,mu_debug_stderr_printer): New prototypes.
* libproto/include/debug0.h (struct _mu_debug): Remove unused
`buffer' and `buflen'. Add `stream'. Change signature of `_print' and
rename it to `printer'.
* mailbox/debug.c: Rewrite debugging support.
(mu_debug_default_printer): New global.
* mailbox/gocs.c (mu_gocs_logging_init): Initialize
mu_debug_default_printer.
* mailbox/memory_stream.c (_memory_truncate): Bugfix.
(_memory_get_transport2): Implement method.
* mailbox/Makefile.am (libmailutils_la_SOURCES): Add dbgstderr.c
and dbgsyslog.c
* mailbox/dbgstderr.c, mailbox/dbgsyslog.c: New files.
* maidag/maidag.c, mail.local/main.c, sieve/sieve.c: Remove
_mu_debug_printer, the default implementation will do.
* mailbox/mu_auth.c: Improve debugging.
* libsieve/comparator.c, libsieve/load.c, libsieve/sieve.l:
Include ctype.h
* include/mailutils/libargp.h: Remove option declarations.
* include/mailutils/mu_auth.h (struct mu_auth_data): New member
`source'.
(mu_auth_set_debug): New proto.
* libargp/common.c: Define option values. New option --debug-auth.
* libargp/auth.c, libargp/gsasl.c,
libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c,
libargp/tls.c, libargp/virtdomain.c: Define option values.
-rw-r--r-- | ChangeLog | 44 | ||||
-rw-r--r-- | imap4d/login.c | 3 | ||||
-rw-r--r-- | include/mailutils/debug.h | 14 | ||||
-rw-r--r-- | include/mailutils/libargp.h | 44 | ||||
-rw-r--r-- | include/mailutils/mu_auth.h | 13 | ||||
-rw-r--r-- | libargp/auth.c | 27 | ||||
-rw-r--r-- | libargp/common.c | 16 | ||||
-rw-r--r-- | libargp/gsasl.c | 2 | ||||
-rw-r--r-- | libargp/pam.c | 2 | ||||
-rw-r--r-- | libargp/radius.c | 7 | ||||
-rw-r--r-- | libargp/sieve.c | 4 | ||||
-rw-r--r-- | libargp/sql.c | 14 | ||||
-rw-r--r-- | libargp/tls.c | 7 | ||||
-rw-r--r-- | libargp/virtdomain.c | 2 | ||||
-rw-r--r-- | libproto/include/debug0.h | 6 | ||||
-rw-r--r-- | libsieve/comparator.c | 1 | ||||
-rw-r--r-- | libsieve/load.c | 1 | ||||
-rw-r--r-- | libsieve/sieve.l | 1 | ||||
-rw-r--r-- | maidag/maidag.c | 20 | ||||
-rw-r--r-- | mail.local/main.c | 14 | ||||
-rw-r--r-- | mailbox/Makefile.am | 2 | ||||
-rw-r--r-- | mailbox/dbgstderr.c | 35 | ||||
-rw-r--r-- | mailbox/dbgsyslog.c | 33 | ||||
-rw-r--r-- | mailbox/debug.c | 72 | ||||
-rw-r--r-- | mailbox/gocs.c | 8 | ||||
-rw-r--r-- | mailbox/memory_stream.c | 24 | ||||
-rw-r--r-- | mailbox/mu_auth.c | 223 | ||||
-rw-r--r-- | pop3d/user.c | 3 | ||||
-rw-r--r-- | sieve/sieve.c | 25 |
29 files changed, 459 insertions, 208 deletions
@@ -1,3 +1,47 @@ +2007-11-24 Sergey Poznyakoff <gray@gnu.org.ua> + + Improve debugging. + + * imap4d/login.c, pop3d/user.c: Print user db source along with + the login name. + * include/mailutils/debug.h (mu_debug_set_print): Change + prototype. + (mu_debug_printer_fp): New data type. + (mu_debug_default_printer): New extern. + (mu_debug_syslog_printer,mu_debug_stderr_printer): New prototypes. + + * libproto/include/debug0.h (struct _mu_debug): Remove unused + `buffer' and `buflen'. Add `stream'. Change signature of `_print' and + rename it to `printer'. + * mailbox/debug.c: Rewrite debugging support. + (mu_debug_default_printer): New global. + + * mailbox/gocs.c (mu_gocs_logging_init): Initialize + mu_debug_default_printer. + + * mailbox/memory_stream.c (_memory_truncate): Bugfix. + (_memory_get_transport2): Implement method. + + * mailbox/Makefile.am (libmailutils_la_SOURCES): Add dbgstderr.c + and dbgsyslog.c + * mailbox/dbgstderr.c, mailbox/dbgsyslog.c: New files. + * maidag/maidag.c, mail.local/main.c, sieve/sieve.c: Remove + _mu_debug_printer, the default implementation will do. + + * mailbox/mu_auth.c: Improve debugging. + + * libsieve/comparator.c, libsieve/load.c, libsieve/sieve.l: + Include ctype.h + + * include/mailutils/libargp.h: Remove option declarations. + * include/mailutils/mu_auth.h (struct mu_auth_data): New member + `source'. + (mu_auth_set_debug): New proto. + * libargp/common.c: Define option values. New option --debug-auth. + * libargp/auth.c, libargp/gsasl.c, + libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c, + libargp/tls.c, libargp/virtdomain.c: Define option values. + 2007-11-22 Sergey Poznyakoff <gray@gnu.org.ua> * libsieve/conf.c (mu_sieve_module_init): Initialize diff --git a/imap4d/login.c b/imap4d/login.c index f8f2c5933..244760afb 100644 --- a/imap4d/login.c +++ b/imap4d/login.c @@ -67,7 +67,8 @@ imap4d_login (struct imap4d_command *command, char *arg) util_chdir (homedir); namespace_init (homedir); - syslog (LOG_INFO, _("User `%s' logged in"), username); + syslog (LOG_INFO, _("User `%s' logged in (source: %s)"), username, + auth_data->source); return util_finish (command, RESP_OK, "Completed"); } diff --git a/include/mailutils/debug.h b/include/mailutils/debug.h index fb7d4b5fe..78e82ebba 100644 --- a/include/mailutils/debug.h +++ b/include/mailutils/debug.h @@ -40,11 +40,17 @@ extern int mu_debug_print (mu_debug_t debug, size_t level, const char *format, ...) MU_PRINTFLIKE(3,4); extern int mu_debug_printv (mu_debug_t debug, size_t level, const char *format, va_list argp); -extern int mu_debug_set_print (mu_debug_t, - int (*_print) (mu_debug_t, size_t level, - const char *, va_list), - void *owner); +typedef int (*mu_debug_printer_fp) (mu_debug_t, size_t level, const char *buf); + +extern int mu_debug_set_print (mu_debug_t, + mu_debug_printer_fp printer, + void *owner); +extern mu_debug_printer_fp mu_debug_default_printer; + +int mu_debug_syslog_printer (mu_debug_t, size_t, const char *); +int mu_debug_stderr_printer (mu_debug_t, size_t, const char *); + #ifdef __cplusplus } #endif diff --git a/include/mailutils/libargp.h b/include/mailutils/libargp.h index c409f66cf..c99050564 100644 --- a/include/mailutils/libargp.h +++ b/include/mailutils/libargp.h @@ -36,50 +36,6 @@ extern "C" { #endif -enum { - OPT_LOG_FACILITY = 256, - OPT_LOCK_FLAGS, - OPT_LOCK_RETRY_COUNT, - OPT_LOCK_RETRY_TIMEOUT, - OPT_LOCK_EXPIRE_TIMEOUT, - OPT_LOCK_EXTERNAL_PROGRAM, - OPT_SHOW_OPTIONS, - OPT_LICENSE, - OPT_MAILBOX_TYPE, - OPT_CRAM_PASSWD, - OPT_PAM_SERVICE, - OPT_AUTH_REQUEST, - OPT_GETPWNAM_REQUEST, - OPT_GETPWUID_REQUEST, - OPT_RADIUS_DIR, - OPT_SQL_INTERFACE, - OPT_SQL_GETPWNAM, - OPT_SQL_GETPWUID, - OPT_SQL_GETPASS, - OPT_SQL_HOST, - OPT_SQL_USER, - OPT_SQL_PASSWD, - OPT_SQL_DB, - OPT_SQL_PORT, - OPT_SQL_MU_PASSWORD_TYPE, - OPT_SQL_FIELD_MAP, - OPT_TLS, - OPT_SSL_CERT, - OPT_SSL_KEY, - OPT_SSL_CAFILE, - OPT_PWDDIR, - OPT_AUTHORIZATION, - OPT_AUTHENTICATION, - OPT_CLEAR_AUTHORIZATION, - OPT_CLEAR_AUTHENTICATION, - OPT_NO_USER_RCFILE, - OPT_NO_SITE_RCFILE, - OPT_RCFILE, - OPT_RCFILE_VERBOSE, - OPT_CLEAR_INCLUDE_PATH, - OPT_CLEAR_LIBRARY_PATH -}; - struct mu_cmdline_capa { char *name; diff --git a/include/mailutils/mu_auth.h b/include/mailutils/mu_auth.h index b11ecc9e3..75838ed1f 100644 --- a/include/mailutils/mu_auth.h +++ b/include/mailutils/mu_auth.h @@ -21,6 +21,7 @@ #include <mailutils/types.h> #include <mailutils/gocs.h> +#include <mailutils/debug.h> #define MU_AUTH_NAME "name" #define MU_AUTH_PASSWD "passwd" @@ -34,6 +35,9 @@ struct mu_auth_data { + /* Where this info comes from: */ + const char *source; + /* These are from struct passwd */ char *name; /* user name */ char *passwd; /* user password */ @@ -42,7 +46,8 @@ struct mu_auth_data char *gecos; /* real name */ char *dir; /* home directory */ char *shell; /* shell program */ - /* */ + + /* Additional fields */ char *mailbox; mu_off_t quota; @@ -77,6 +82,9 @@ enum mu_auth_key_type mu_auth_key_uid }; +void mu_auth_begin_setup (void); +void mu_auth_finish_setup (void); + extern int mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data, const void *key, void *data); @@ -117,9 +125,10 @@ extern int mu_auth_data_alloc (struct mu_auth_data **ptr, const char *shell, const char *mailbox, int change_uid); -void mu_auth_data_set_quota (struct mu_auth_data *ptr, mu_off_t q); +extern void mu_auth_data_set_quota (struct mu_auth_data *ptr, mu_off_t q); extern void mu_auth_data_free (struct mu_auth_data *ptr); extern void mu_auth_data_destroy (struct mu_auth_data **ptr); +extern mu_debug_t mu_auth_set_debug (mu_debug_t debug); extern struct mu_auth_module mu_auth_system_module; diff --git a/libargp/auth.c b/libargp/auth.c index 3add6cfd0..e0b5d86dc 100644 --- a/libargp/auth.c +++ b/libargp/auth.c @@ -20,12 +20,21 @@ # include <config.h> #endif #include "mailutils/libargp.h" +#include "mailutils/mu_auth.h" /* ************************************************************************* */ /* Traditional configuration */ /* ************************************************************************* */ +enum { + OPT_AUTHORIZATION=256, + OPT_AUTHENTICATION, + OPT_CLEAR_AUTHORIZATION, + OPT_CLEAR_AUTHENTICATION, + OPT_DEBUG_AUTH +}; + static error_t mu_auth_argp_parser (int key, char *arg, struct argp_state *state); @@ -39,6 +48,8 @@ static struct argp_option mu_auth_argp_option[] = { N_("Clear the list of authorization modules"), 0 }, { "clear-authentication", OPT_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN, N_("Clear the list of authentication modules"), 0 }, + { "debug-auth", OPT_DEBUG_AUTH, NULL, 0, + N_("Debug authentication functions") }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -54,6 +65,18 @@ static struct argp_child mu_auth_argp_child = { 0 }; +static void +auth_set_debug () +{ + mu_debug_t debug = NULL, prev; + + mu_debug_create (&debug, NULL); + mu_debug_set_level (debug, MU_DEBUG_TRACE); + prev = mu_auth_set_debug (debug); + if (prev) + mu_debug_destroy (&prev, mu_debug_get_owner (prev)); +} + static error_t mu_auth_argp_parser (int key, char *arg, struct argp_state *state) { @@ -80,6 +103,10 @@ mu_auth_argp_parser (int key, char *arg, struct argp_state *state) mu_authorization_clear_list (); break; + case OPT_DEBUG_AUTH: + auth_set_debug (); + break; + default: return ARGP_ERR_UNKNOWN; } diff --git a/libargp/common.c b/libargp/common.c index 60b7652af..8c7f7bc95 100644 --- a/libargp/common.c +++ b/libargp/common.c @@ -62,6 +62,22 @@ assign_string (char **pstr, char *val) /* Common */ /* ************************************************************************* */ +enum { + OPT_SHOW_OPTIONS=256, + OPT_NO_USER_RCFILE, + OPT_NO_SITE_RCFILE, + OPT_RCFILE, + OPT_RCFILE_VERBOSE, + OPT_LOG_FACILITY, + OPT_LOCK_FLAGS, + OPT_LOCK_RETRY_COUNT, + OPT_LOCK_RETRY_TIMEOUT, + OPT_LOCK_EXPIRE_TIMEOUT, + OPT_LOCK_EXTERNAL_PROGRAM, + OPT_LICENSE, + OPT_MAILBOX_TYPE +}; + static struct argp_option mu_common_argp_options[] = { { NULL, 0, NULL, 0, N_("Common options"), 0}, diff --git a/libargp/gsasl.c b/libargp/gsasl.c index 5682838ed..f3e65ab45 100644 --- a/libargp/gsasl.c +++ b/libargp/gsasl.c @@ -22,6 +22,8 @@ #include "mailutils/libargp.h" #include <mailutils/gsasl.h> +#define OPT_CRAM_PASSWD 256 + static struct argp_option _gsasl_argp_options[] = { {"cram-passwd", OPT_CRAM_PASSWD, N_("FILE"), OPTION_HIDDEN, N_("Specify password file for CRAM-MD5 authentication"), 0}, diff --git a/libargp/pam.c b/libargp/pam.c index 4a3f82bb4..e2c54e823 100644 --- a/libargp/pam.c +++ b/libargp/pam.c @@ -25,6 +25,8 @@ static struct mu_gocs_pam pam_settings; +#define OPT_PAM_SERVICE 256 + static error_t mu_pam_argp_parser (int key, char *arg, struct argp_state *state) { diff --git a/libargp/radius.c b/libargp/radius.c index 70a0d37e1..07644c2bc 100644 --- a/libargp/radius.c +++ b/libargp/radius.c @@ -23,6 +23,13 @@ #include "mailutils/libargp.h" #include <mailutils/radius.h> +enum { + OPT_AUTH_REQUEST = 256, + OPT_GETPWNAM_REQUEST, + OPT_GETPWUID_REQUEST, + OPT_RADIUS_DIR +}; + static struct argp_option mu_radius_argp_option[] = { { "radius-auth-request", OPT_AUTH_REQUEST, N_("REQUEST"), OPTION_HIDDEN, N_("Radius request to authenitcate the user"), 0 }, diff --git a/libargp/sieve.c b/libargp/sieve.c index df73a1dc9..aaf055d16 100644 --- a/libargp/sieve.c +++ b/libargp/sieve.c @@ -23,6 +23,10 @@ #include "mailutils/libargp.h" #include "mailutils/libsieve.h" +enum { + OPT_CLEAR_INCLUDE_PATH = 256, + OPT_CLEAR_LIBRARY_PATH +}; static struct argp_option sieve_argp_option[] = { { "includedir", 'I', N_("DIR"), 0, diff --git a/libargp/sql.c b/libargp/sql.c index 3e284de54..5844d5ea3 100644 --- a/libargp/sql.c +++ b/libargp/sql.c @@ -28,6 +28,20 @@ static int sql_requested; static struct mu_sql_module_config sql_config; /* Command-line configuration */ +enum { + OPT_SQL_INTERFACE = 256, + OPT_SQL_GETPWNAM, + OPT_SQL_GETPWUID, + OPT_SQL_GETPASS, + OPT_SQL_HOST, + OPT_SQL_USER, + OPT_SQL_PASSWD, + OPT_SQL_DB, + OPT_SQL_PORT, + OPT_SQL_MU_PASSWORD_TYPE, + OPT_SQL_FIELD_MAP, +}; + static struct argp_option mu_sql_argp_option[] = { {"sql-interface", OPT_SQL_INTERFACE, N_("NAME"), OPTION_HIDDEN, N_("Type of SQL interface to use"), }, diff --git a/libargp/tls.c b/libargp/tls.c index 62aa9b83f..8269bcb3d 100644 --- a/libargp/tls.c +++ b/libargp/tls.c @@ -23,6 +23,13 @@ #include "mailutils/libargp.h" #include <mailutils/tls.h> +enum { + OPT_TLS = 256, + OPT_SSL_CERT, + OPT_SSL_KEY, + OPT_SSL_CAFILE +}; + static struct argp_option _tls_argp_options[] = { {"ssl-cert", OPT_SSL_CERT, N_("FILE"), OPTION_HIDDEN, N_("Specify SSL certificate file"), 0}, diff --git a/libargp/virtdomain.c b/libargp/virtdomain.c index 7745a6e31..debf1ee99 100644 --- a/libargp/virtdomain.c +++ b/libargp/virtdomain.c @@ -24,6 +24,8 @@ static char *virtdir; +#define OPT_PWDDIR 256 + static error_t mu_virt_argp_parser (int key, char *arg, struct argp_state *state) { diff --git a/libproto/include/debug0.h b/libproto/include/debug0.h index f9d8083a4..fd81e00e2 100644 --- a/libproto/include/debug0.h +++ b/libproto/include/debug0.h @@ -24,6 +24,7 @@ #endif #include <mailutils/debug.h> +#include <mailutils/stream.h> #ifdef __cplusplus extern "C" { @@ -32,10 +33,9 @@ extern "C" { struct _mu_debug { size_t level; - char *buffer; - size_t buflen; + mu_stream_t stream; void *owner; - int (*_print) (mu_debug_t, size_t level, const char *, va_list); + int (*printer) (mu_debug_t, size_t level, const char *buf); }; #ifdef __cplusplus diff --git a/libsieve/comparator.c b/libsieve/comparator.c index 0978d06a4..2f4e3d82b 100644 --- a/libsieve/comparator.c +++ b/libsieve/comparator.c @@ -28,6 +28,7 @@ #include <sieve.h> #include <fnmatch.h> #include <regex.h> +#include <ctype.h> typedef struct { const char *name; diff --git a/libsieve/load.c b/libsieve/load.c index 58a60bde7..6922bc648 100644 --- a/libsieve/load.c +++ b/libsieve/load.c @@ -28,6 +28,7 @@ #include <string.h> #include <sieve.h> #include <ltdl.h> +#include <ctype.h> typedef int (*sieve_module_init_t) (mu_sieve_machine_t mach); diff --git a/libsieve/sieve.l b/libsieve/sieve.l index ada908c06..924b2aa3b 100644 --- a/libsieve/sieve.l +++ b/libsieve/sieve.l @@ -29,6 +29,7 @@ #include <sys/stat.h> #include <errno.h> #include <string.h> +#include <ctype.h> #include <mailutils/argcv.h> #include <sieve.h> #include <sieve-gram.h> diff --git a/maidag/maidag.c b/maidag/maidag.c index f961d5436..f2ad4187c 100644 --- a/maidag/maidag.c +++ b/maidag/maidag.c @@ -271,20 +271,6 @@ struct mu_cfg_param maidag_cfg_param[] = { /* Logging */ -static int -_mu_debug_printer (mu_debug_t unused, size_t level, const char *fmt, - va_list ap) -{ - if (log_to_stderr) - { - fprintf (stderr, "%s: ", (level == MU_DEBUG_ERROR) ? "ERROR" : "DEBUG"); - vfprintf (stderr, fmt, ap); - fputc ('\n', stderr); - } - else - vsyslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, fmt, ap); - return 0; -} static int _sieve_debug_printer (void *unused, const char *fmt, va_list ap) @@ -504,12 +490,6 @@ main (int argc, char *argv[]) mu_strerror (rc)); exit (EX_TEMPFAIL); } - if ((rc = mu_debug_set_print (mudebug, _mu_debug_printer, NULL))) - { - mu_error (_("mu_debug_set_print failed: %s\n"), - mu_strerror (rc)); - exit (EX_TEMPFAIL); - } } argc -= arg_index; diff --git a/mail.local/main.c b/mail.local/main.c index 535fdd999..f76a6d373 100644 --- a/mail.local/main.c +++ b/mail.local/main.c @@ -265,14 +265,6 @@ struct mu_cfg_param mail_local_cfg_param[] = { static int -_mu_debug_printer (mu_debug_t unused, size_t level, const char *fmt, - va_list ap) -{ - vsyslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, fmt, ap); - return 0; -} - -static int _sieve_debug_printer (void *unused, const char *fmt, va_list ap) { vsyslog (LOG_DEBUG, fmt, ap); @@ -396,12 +388,6 @@ main (int argc, char *argv[]) mu_strerror (rc)); exit (EX_TEMPFAIL); } - if ((rc = mu_debug_set_print (mudebug, _mu_debug_printer, NULL))) - { - mu_error (_("mu_debug_set_print failed: %s\n"), - mu_strerror (rc)); - exit (EX_TEMPFAIL); - } } argc -= arg_index; diff --git a/mailbox/Makefile.am b/mailbox/Makefile.am index 5526fe216..e2814e2d8 100644 --- a/mailbox/Makefile.am +++ b/mailbox/Makefile.am @@ -46,6 +46,8 @@ libmailutils_la_SOURCES = \ body.c\ daemon.c\ date.c\ + dbgstderr.c\ + dbgsyslog.c\ debug.c\ cfg_lexer.c\ cfg_parser.c\ diff --git a/mailbox/dbgstderr.c b/mailbox/dbgstderr.c new file mode 100644 index 000000000..c496301e9 --- /dev/null +++ b/mailbox/dbgstderr.c @@ -0,0 +1,35 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <mailutils/debug.h> +#include <stdio.h> + +int +mu_debug_stderr_printer (mu_debug_t unused, size_t level, const char *str) +{ + fprintf (stderr, "%s: %s", + (level == MU_DEBUG_ERROR) ? "ERROR" : "DEBUG", + str); + return 0; +} + + diff --git a/mailbox/dbgsyslog.c b/mailbox/dbgsyslog.c new file mode 100644 index 000000000..5111bbf25 --- /dev/null +++ b/mailbox/dbgsyslog.c @@ -0,0 +1,33 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <mailutils/debug.h> +#include <syslog.h> + +int +mu_debug_syslog_printer (mu_debug_t unused, size_t level, const char *str) +{ + syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str); + return 0; +} + + diff --git a/mailbox/debug.c b/mailbox/debug.c index ac9671d43..95dd7eb42 100644 --- a/mailbox/debug.c +++ b/mailbox/debug.c @@ -26,8 +26,11 @@ #include <string.h> #include <mailutils/errno.h> +#include <mailutils/nls.h> #include <debug0.h> +mu_debug_printer_fp mu_debug_default_printer = mu_debug_stderr_printer; + int mu_debug_create (mu_debug_t *pdebug, void *owner) { @@ -37,6 +40,7 @@ mu_debug_create (mu_debug_t *pdebug, void *owner) debug = calloc (sizeof (*debug), 1); if (debug == NULL) return ENOMEM; + debug->printer = mu_debug_default_printer; debug->owner = owner; *pdebug = debug; return 0; @@ -50,6 +54,8 @@ mu_debug_destroy (mu_debug_t *pdebug, void *owner) mu_debug_t debug = *pdebug; if (debug->owner == owner) { + mu_stream_destroy (&debug->stream, + mu_stream_get_owner (debug->stream)); free (*pdebug); *pdebug = NULL; } @@ -82,15 +88,13 @@ mu_debug_get_level (mu_debug_t debug, size_t *plevel) } int -mu_debug_set_print (mu_debug_t debug, - int (*_print) (mu_debug_t, size_t, const char *, va_list), - void *owner) +mu_debug_set_print (mu_debug_t debug, mu_debug_printer_fp printer, void *owner) { if (debug == NULL) return EINVAL; if (debug->owner != owner) return EACCES; - debug->_print = _print; + debug->printer = printer; return 0; } @@ -100,7 +104,7 @@ mu_debug_print (mu_debug_t debug, size_t level, const char *format, ...) va_list ap; va_start (ap, format); - + mu_debug_printv (debug, level, format, ap); va_end (ap); @@ -109,7 +113,8 @@ mu_debug_print (mu_debug_t debug, size_t level, const char *format, ...) } int -mu_debug_printv (mu_debug_t debug, size_t level, const char *format, va_list ap) +mu_debug_printv (mu_debug_t debug, size_t level, const char *format, + va_list ap) { if (debug == NULL || format == NULL) return EINVAL; @@ -117,8 +122,59 @@ mu_debug_printv (mu_debug_t debug, size_t level, const char *format, va_list ap) if (!(debug->level & level)) return 0; - if (debug->_print) - debug->_print (debug, level, format, ap); + if (debug->printer) + { + mu_off_t len; + mu_transport_t tbuf; + char *ptr, *start, *p; + size_t nseg; + + if (debug->stream == NULL) + { + int rc = mu_memory_stream_create (&debug->stream, NULL, 0); + if (rc) + { + fprintf (stderr, + _("cannot create memory stream for debugging output: %s\n"), + mu_strerror (rc)); + vfprintf (stderr, format, ap); + return rc; + } + } + + mu_stream_sequential_vprintf (debug->stream, format, ap); + mu_stream_get_transport (debug->stream, &tbuf); + start = (char*) tbuf; + mu_stream_size (debug->stream, &len); + ptr = start; + nseg = 0; + for (p = ptr = start; p < start + len; p++) + { + if (*p == '\n') + { + int c = *++p; + *p = 0; + debug->printer (debug, level, ptr); + *p = c; + ptr = p; + nseg++; + } + } + + if (nseg) + { + if (start[len - 1] != '\n') + { + size_t s = len - (ptr - start); + memmove (start, ptr, len); + } + else + len = 0; + + mu_stream_truncate (debug->stream, len); + mu_stream_seek (debug->stream, len, SEEK_SET); + } + } else vfprintf (stderr, format, ap); diff --git a/mailbox/gocs.c b/mailbox/gocs.c index cc6c487ad..6f616f581 100644 --- a/mailbox/gocs.c +++ b/mailbox/gocs.c @@ -30,6 +30,7 @@ #include <mailutils/error.h> #include <mailutils/errno.h> #include <mailutils/nls.h> +#include <mailutils/debug.h> #include <syslog.h> int mu_load_user_rcfile = 1; @@ -206,7 +207,12 @@ mu_gocs_logging_init (void *data) } if (p->facility) - log_facili |