Commit 0611cd20 0611cd202d4bc40becd9ed148d4a2adf6c4541fa by Sergey Poznyakoff
2 parents 8bff160c 60610d82
Showing 186 changed files with 1538 additions and 1445 deletions
......@@ -94,6 +94,7 @@ SUBDIRS = . \
sql\
libmu_auth\
libproto\
libmu_compat\
testsuite\
lib\
libmu_argp\
......
GNU mailutils TODO list. 2010-12-02
GNU mailutils TODO list. 2010-12-06
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free
Software Foundation, Inc.
......@@ -6,8 +6,6 @@ Software Foundation, Inc.
* prog_stream: find a way to initialize start directory value and environment
* stream: associate with input location (mu_locus_t or the like).
* redo the support of the default user email and mail domain.
* use the above in message_stream.
......@@ -18,8 +16,6 @@ See also mu_rfc2822_in_reply_to.
* mail: rewrite I/O support using streams.
* redo debugging & logging support the way it is implemented in dico/mailfromd
* re-implement imap4 client (in progress)
* re-implement nntp client
......@@ -129,6 +125,12 @@ libmailbox?
** mimeview: support nametemplate
* stream: associate with input location (mu_locus_t or the like).
This is already implemented in logstream. Does it make sense for
streams in general?
Local variables:
mode: outline
......
......@@ -371,11 +371,11 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
fp = open_rc (BIFF_RC, tty);
if (fp)
{
unsigned line = 1, n;
mu_debug_t debug;
unsigned n;
char *cwd = mu_getcwd ();
char *rcname;
struct mu_locus locus;
rcname = mu_make_file_name (cwd, BIFF_RC);
free (cwd);
if (!rcname)
......@@ -385,8 +385,9 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
return;
}
mu_diag_get_debug (&debug);
locus.mu_file = rcname;
locus.mu_line = 1;
locus.mu_col = 0;
while ((n = act_getline (fp, &stmt, &size)))
{
struct mu_wordsplit ws;
......@@ -395,7 +396,7 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
if (mu_wordsplit (stmt, &ws, MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT)
&& ws.ws_wordc)
{
mu_debug_set_locus (debug, rcname, line);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM_SET_LOCUS, &locus);
if (strcmp (ws.ws_wordv[0], "beep") == 0)
{
/* FIXME: excess arguments are ignored */
......@@ -431,7 +432,8 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
}
else
{
fprintf (tty, _(".biffrc:%d: unknown keyword"), line);
fprintf (tty, _(".biffrc:%d: unknown keyword"),
locus.mu_line);
fprintf (tty, "\r\n");
mu_diag_output (MU_DIAG_ERROR, _("unknown keyword %s"),
ws.ws_wordv[0]);
......@@ -440,10 +442,10 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
}
}
mu_wordsplit_free (&ws);
line += n;
locus.mu_line += n;
}
fclose (fp);
mu_debug_set_locus (debug, NULL, 0);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
free (rcname);
}
......
......@@ -552,6 +552,7 @@ main (int argc, char **argv)
/* FIXME mu_m_server_set_pidfile (); */
mu_m_server_set_default_port (server, 512);
/* FIXME: timeout is not needed. How to disable it? */
mu_log_syslog = 1;
if (mu_app_init (&argp, comsat_argp_capa, comsat_cfg_param, argc, argv, 0,
&ind, server))
......@@ -564,6 +565,7 @@ main (int argc, char **argv)
argc -= ind;
argv += ind;
mu_stdstream_strerr_setup (MU_STRERR_STDERR);
if (argc < 2 || argc > 2)
{
mu_error (_("mailbox URL and message QID are required in test mode"));
......@@ -590,17 +592,8 @@ main (int argc, char **argv)
exit (0);
}
/* Set up error messaging */
openlog (MU_LOG_TAG (), LOG_PID, mu_log_facility);
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
mu_debug_default_printer = mu_debug_syslog_printer;
}
mu_stdstream_strerr_setup (mu_log_syslog ?
MU_STRERR_SYSLOG : MU_STRERR_STDERR);
if (mu_m_server_mode (server) == MODE_DAEMON)
{
......
......@@ -52,6 +52,7 @@
#include <mailutils/util.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/mu_auth.h>
#include <mailutils/wordsplit.h>
#include <mailutils/nls.h>
......
......@@ -1205,6 +1205,7 @@ AC_ARG_WITH([mh-bindir],
# Initialize the (autotest) test suite.
AC_CONFIG_TESTDIR(libmailutils/tests)
AC_CONFIG_TESTDIR(testsuite)
AC_CONFIG_TESTDIR(libmu_compat/tests)
AC_CONFIG_TESTDIR(frm/tests)
AC_CONFIG_TESTDIR(maidag/tests)
AC_CONFIG_TESTDIR(messages/tests)
......@@ -1214,6 +1215,8 @@ AC_CONFIG_TESTDIR(mh/tests)
AC_CONFIG_FILES([libmailutils/tests/Makefile
libmailutils/tests/atlocal
libmu_compat/tests/Makefile
libmu_compat/tests/atlocal
testsuite/Makefile
testsuite/atlocal
frm/tests/Makefile
......@@ -1368,6 +1371,7 @@ AC_CONFIG_FILES([
libproto/pop/Makefile
libproto/nntp/Makefile
libproto/imap/Makefile
libmu_compat/Makefile
maidag/Makefile
mail/Makefile
mail/testsuite/Makefile
......@@ -1384,6 +1388,7 @@ AC_CONFIG_FILES([
libmailutils/server/Makefile
libmailutils/string/Makefile
libmailutils/stream/Makefile
libmailutils/stdstream/Makefile
libmailutils/url/Makefile
libmailutils/Makefile
messages/Makefile
......
......@@ -199,7 +199,7 @@ main (int argc, char **argv)
break;
case 'd':
mu_global_debug_from_string (optarg, "command line");
mu_debug_parse_spec (optarg);
break;
case 'a':
......
......@@ -207,7 +207,7 @@ main (int argc, char **argv)
break;
case 'd':
mu_global_debug_from_string (optarg, "command line");
mu_debug_parse_spec (optarg);
break;
default:
......
......@@ -111,12 +111,8 @@ main (int argc, char *argv[])
MU_ASSERT (mu_message_set_stream (msg, in, NULL));
MU_ASSERT (mu_mailer_create (&mailer, optmailer));
if (optdebug)
{
mu_debug_t debug;
mu_mailer_get_debug (mailer, &debug);
mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
}
mu_debug_set_category_level (MU_DEBCAT_MAILER,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
MU_ASSERT (mu_mailer_open (mailer, 0));
......
......@@ -343,9 +343,8 @@ com_verbose (char *arg)
{
if (verbose)
{
mu_debug_t debug;
mu_debug_create (&debug, NULL);
mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
mu_debug_set_category_level (MU_DEBCAT_REMOTE,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
status = mu_nntp_set_debug (nntp, debug);
}
else
......
......@@ -86,11 +86,7 @@ numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE)
{
mu_sieve_locus_t locus;
mu_sieve_get_locus (mach, &locus);
mu_sieve_debug (mach, "%s:%lu: NUMADDR\n",
locus.source_file,
(unsigned long) locus.source_line);
mu_sieve_debug (mach, "NUMADDR");
}
/* Retrieve required arguments: */
......
......@@ -550,9 +550,8 @@ frm_scan (char *mailbox_name, frm_select_t fun, size_t *total)
if (frm_debug)
{
mu_debug_t debug;
mu_mailbox_get_debug (mbox, &debug);
mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
mu_debug_set_category_level (MU_DEBCAT_MAILBOX,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
}
mu_mailbox_get_url (mbox, &url);
......
......@@ -135,21 +135,19 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state)
}
static int
cb_mode (mu_debug_t debug, void *data, mu_config_value_t *val)
cb_mode (void *data, mu_config_value_t *val)
{
char *p;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
home_dir_mode = strtoul (val->v.string, &p, 8);
if (p[0] || (home_dir_mode & ~0777))
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid mode specification: %s"),
val->v.string);
mu_error (_("invalid mode specification: %s"), val->v.string);
return 0;
}
int
parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url)
parse_preauth_scheme (const char *scheme, mu_url_t url)
{
int rc = 0;
if (strcmp (scheme, "stdio") == 0)
......@@ -160,9 +158,7 @@ parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url)
rc = mu_url_aget_path (url, &path);
if (rc)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("URL error: cannot get path: %s"),
mu_strerror (rc));
mu_error (_("URL error: cannot get path: %s"), mu_strerror (rc));
return 1;
}
preauth_program = path;
......@@ -182,7 +178,7 @@ parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url)
}
else
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("unknown preauth scheme"));
mu_error (_("unknown preauth scheme"));
rc = 1;
}
......@@ -194,14 +190,14 @@ parse_preauth_scheme (mu_debug_t debug, const char *scheme, mu_url_t url)
preauth stdio
*/
static int
cb_preauth (mu_debug_t debug, void *data, mu_config_value_t *val)
cb_preauth (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (strcmp (val->v.string, "stdio") == 0)
preauth_mode = preauth_stdio;
else if (strcmp (val->v.string, "ident") == 0)
return parse_preauth_scheme (debug, val->v.string, NULL);
return parse_preauth_scheme (val->v.string, NULL);
else if (val->v.string[0] == '/')
{
preauth_program = xstrdup (val->v.string);
......@@ -223,12 +219,11 @@ cb_preauth (mu_debug_t debug, void *data, mu_config_value_t *val)
if (rc)
{
mu_url_destroy (&url);
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("URL error: %s"), mu_strerror (rc));
mu_error (_("URL error: %s"), mu_strerror (rc));
return 1;
}
rc = parse_preauth_scheme (debug, scheme, url);
rc = parse_preauth_scheme (scheme, url);
mu_url_destroy (&url);
free (scheme);
return rc;
......@@ -237,14 +232,13 @@ cb_preauth (mu_debug_t debug, void *data, mu_config_value_t *val)
}
static int
cb_mailbox_mode (mu_debug_t debug, void *data, mu_config_value_t *val)
cb_mailbox_mode (void *data, mu_config_value_t *val)
{
const char *p;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_parse_stream_perm_string ((int *)data, val->v.string, &p))
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid mode string near %s"), p);
mu_error (_("invalid mode string near %s"), p);
return 0;
}
......@@ -533,6 +527,8 @@ main (int argc, char **argv)
mu_m_server_set_timeout (server, 1800); /* RFC2060: 30 minutes. */
mu_m_server_set_strexit (server, mu_strexit);
mu_log_syslog = 1;
if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param,
argc, argv, 0, NULL, server))
exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
......@@ -584,19 +580,8 @@ main (int argc, char **argv)
/* Set the signal handlers. */
mu_set_signals (imap4d_master_signal, sigtab, MU_ARRAY_SIZE (sigtab));
/* Set up for syslog. */
openlog (MU_LOG_TAG (), LOG_PID, mu_log_facility);
/* Redirect any stdout error from the library to syslog, they
should not go to the client. */
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
mu_debug_default_printer = mu_debug_syslog_printer;
}
mu_stdstream_strerr_setup (mu_log_syslog ?
MU_STRERR_SYSLOG : MU_STRERR_STDERR);
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */
......
......@@ -92,6 +92,7 @@
#include <mailutils/parse822.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/tls.h>
#include <mailutils/url.h>
#include <mailutils/daemon.h>
......
......@@ -55,12 +55,9 @@ io_setio (int ifd, int ofd)
if (imap4d_transcript)
{
int rc;
mu_debug_t debug;
mu_stream_t dstr, xstr;
mu_diag_get_debug (&debug);
rc = mu_dbgstream_create (&dstr, debug, MU_DIAG_DEBUG, 0);
rc = mu_dbgstream_create (&dstr, MU_DIAG_DEBUG);
if (rc)
mu_error (_("cannot create debug stream; transcript disabled: %s"),
mu_strerror (rc));
......
......@@ -677,10 +677,9 @@ set_xscript_level (int xlev)
{
if (xlev != MU_XSCRIPT_NORMAL)
{
mu_log_level_t n = xlev == MU_XSCRIPT_SECURE ?
MU_DEBUG_TRACE6 : MU_DEBUG_TRACE7;
if (mu_global_debug_level ("imap4") & MU_DEBUG_LEVEL_MASK (n))
if (mu_debug_level_p (MU_DEBCAT_REMOTE,
MU_XSCRIPT_SECURE ?
MU_DEBUG_TRACE6 : MU_DEBUG_TRACE7))
return MU_XSCRIPT_NORMAL;
}
......
Makefile
Makefile.in
debug.h
errno.h
types.h
\ No newline at end of file
types.h
......
......@@ -15,14 +15,11 @@
## You should have received a copy of the GNU General Public License
## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
BUILT_SOURCES=errno.h debug.h
EXTRA_DIST=errno.hin debug.hm4 types.hin
BUILT_SOURCES=errno.h
EXTRA_DIST=errno.hin types.hin
errno.h: $(top_srcdir)/libmailutils/diag/errors errno.hin
$(AM_V_GEN)$(AWK) -f $(mu_aux_dir)/generr.awk $^ > $@
debug.h: $(mu_aux_dir)/debugdef.m4 debug.hm4
$(AM_V_GEN)m4 $(mu_aux_dir)/debugdef.m4 debug.hm4 > debug.h
types.h: $(top_srcdir)/include/mailutils/types.hin Makefile
$(AM_V_GEN)sed 's/_MU_OFF_TYPE_/$(MU_OFF_TYPE)/;s/_MU_DEFAULT_RECORD_/$(MU_DEFAULT_RECORD)/' $(top_srcdir)/include/mailutils/types.hin > $@
DISTCLEANFILES = types.h
......@@ -61,6 +58,7 @@ pkginclude_HEADERS = \
libcfg.h\
list.h\
locker.h\
log.h\
mailbox.h\
mailcap.h\
mailer.h\
......@@ -90,6 +88,7 @@ pkginclude_HEADERS = \
server.h\
sieve.h\
smtp.h\
stdstream.h\
stream.h\
syslog.h\
sql.h\
......
......@@ -45,8 +45,6 @@ struct in_addr;
int mu_acl_create (mu_acl_t *acl);
int mu_acl_destroy (mu_acl_t *acl);
int mu_acl_count (mu_acl_t acl, size_t *pcount);
int mu_acl_get_debug (mu_acl_t acl, mu_debug_t *pdebug);
int mu_acl_set_debug (mu_acl_t acl, mu_debug_t debug);
int mu_acl_get_iterator (mu_acl_t acl, mu_iterator_t *pitr);
int mu_acl_append (mu_acl_t acl, mu_acl_action_t act, void *data,
struct sockaddr *sa, int salen,
......
......@@ -24,6 +24,8 @@
#include <unistd.h>
#include <string.h>
#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -37,20 +39,22 @@ enum mu_argcv_escape
mu_argcv_escape_c
/* mu_argcv_escape_sh */
};
int mu_argcv_join (int argc, char **argv, char *delim,
enum mu_argcv_escape esc,
char **pstring);
int mu_argcv_string (int argc, char **argv, char **string);
void mu_argcv_remove (int *pargc, char ***pargv,
int (*sel) (const char *, void *), void *);
int mu_argcv_string (int argc, char **argv, char **string);
/* Deprecated interfaces */
#define MU_ARGCV_RETURN_DELIMS 0x01
#ifndef MU_ARCGV_DEPRECATED
# define MU_ARCGV_DEPRECATED __attribute__((deprecated))
#endif
# define MU_ARCGV_DEPRECATED MU_DEPRECATED
#endif
int mu_argcv_get (const char *command, const char *delim,
const char *cmnt,
......
......@@ -77,7 +77,7 @@ int mu_wicket_set_get_ticket (mu_wicket_t wicket,
int mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename);
struct mu_debug_locus;
int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
int mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus *loc,
mu_url_t url, int parse_flags,
mu_url_t *pticket_url);
int mu_wicket_file_match_url (const char *name, mu_url_t url,
......
......@@ -31,7 +31,6 @@ extern "C" {
typedef enum mu_cfg_node_type mu_cfg_node_type_t;
typedef struct mu_cfg_node mu_cfg_node_t;
typedef struct mu_cfg_locus mu_cfg_locus_t;
typedef struct mu_cfg_tree mu_cfg_tree_t;
#define MU_CFG_STRING 0
......@@ -62,15 +61,9 @@ enum mu_cfg_node_type
mu_cfg_node_param
};
struct mu_cfg_locus
{
char *file;
size_t line;
};
struct mu_cfg_node
{
mu_cfg_locus_t locus;
struct mu_locus locus;
enum mu_cfg_node_type type;
char *tag;
mu_config_value_t *label;
......@@ -80,7 +73,6 @@ struct mu_cfg_node
struct mu_cfg_tree
{
mu_list_t nodes; /* a list of mu_cfg_node_t */
mu_debug_t debug;
mu_opool_t pool;
};
......@@ -88,18 +80,10 @@ int mu_cfg_parse (mu_cfg_tree_t **ptree);
int mu_cfg_tree_union (mu_cfg_tree_t **pa, mu_cfg_tree_t **pb);
int mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, int flags);
extern mu_cfg_locus_t mu_cfg_locus;
extern struct mu_locus mu_cfg_locus;
mu_opool_t mu_cfg_lexer_pool (void);
void mu_cfg_vperror (mu_debug_t, const mu_cfg_locus_t *,
const char *fmt, va_list ap);
void mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *,
const char *, ...) MU_PRINTFLIKE(3,4);
void mu_cfg_parse_error (const char *, ...) MU_PRINTFLIKE(1,2);
void mu_cfg_format_error (mu_debug_t debug, size_t, const char *fmt, ...)
MU_PRINTFLIKE(3,4);
#define MU_CFG_ITER_OK 0
#define MU_CFG_ITER_SKIP 1
#define MU_CFG_ITER_STOP 2
......@@ -144,7 +128,7 @@ enum mu_cfg_param_data_type
#define MU_CFG_TYPE(t) ((t) & ~MU_CFG_LIST_MASK)
#define MU_CFG_IS_LIST(t) ((t) & MU_CFG_LIST_MASK)
typedef int (*mu_cfg_callback_t) (mu_debug_t, void *, mu_config_value_t *);
typedef int (*mu_cfg_callback_t) (void *, mu_config_value_t *);
struct mu_cfg_param
{
......@@ -245,8 +229,6 @@ int mu_config_register_plain_section (const char *parent_path,
const char *ident,
struct mu_cfg_param *params);
mu_debug_t mu_cfg_get_debug (void);
#define MU_PARSE_CONFIG_GLOBAL 0x1
#define MU_PARSE_CONFIG_VERBOSE 0x2
#define MU_PARSE_CONFIG_DUMP 0x4
......@@ -282,10 +264,9 @@ void mu_format_config_tree (mu_stream_t stream, const char *progname,
int mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname,
struct mu_cfg_param *progparam,
int flags, void *target_ptr);
int mu_cfg_assert_value_type (mu_config_value_t *val, int type,
mu_debug_t debug);
int mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
int (*fun) (mu_debug_t, const char *, void *),
int mu_cfg_assert_value_type (mu_config_value_t *val, int type);
int mu_cfg_string_value_cb (mu_config_value_t *val,
int (*fun) (const char *, void *),
void *data);
int mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file,
......@@ -297,10 +278,9 @@ int mu_get_config (const char *file, const char *progname,
void *target_ptr) MU_CFG_DEPRECATED;
int mu_cfg_tree_create (struct mu_cfg_tree **ptree);
void mu_cfg_tree_set_debug (struct mu_cfg_tree *tree, mu_debug_t debug);
mu_cfg_node_t *mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
enum mu_cfg_node_type type,
const mu_cfg_locus_t *loc,
const struct mu_locus *loc,
const char *tag,
const char *label,
mu_list_t nodelist);
......
......@@ -23,82 +23,54 @@
#include <mailutils/types.h>
#include <mailutils/error.h>
#define MU_DEBUG(d,l,s) MU_DEBUG1(d,l,"%s",s)
#include <mailutils/sys/debcat.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int mu_debug_line_info;
#define MU_DEBUG_ERROR 0
#define MU_DEBUG_TRACE0 1
#define MU_DEBUG_TRACE MU_DEBUG_TRACE0
#define MU_DEBUG_TRACE1 2
#define MU_DEBUG_TRACE1 2
#define MU_DEBUG_TRACE2 3
#define MU_DEBUG_TRACE3 4
#define MU_DEBUG_TRACE4 5
#define MU_DEBUG_TRACE5 6
#define MU_DEBUG_TRACE6 7
#define MU_DEBUG_TRACE7 8
#define MU_DEBUG_PROT 9
#define MU_DEBUG_TRACE7 8
#define MU_DEBUG_TRACE8 9
#define MU_DEBUG_TRACE9 10
#define MU_DEBUG_PROT 11
#define MU_DEBUG_LEVEL_MASK(lev) (1 << (lev))
#define MU_DEBUG_LEVEL_UPTO(lev) ((1 << ((lev)+1)) - 1)
#define MU_DEBUG_INHERIT 0xf0000
#define MU_DEBUG_EXTRACT_LEVEL(s) ((s) & ~MU_DEBUG_INHERIT)
struct mu_debug_locus
{
const char *file;
int line;
};
int mu_debug_create (mu_debug_t *, void *);
void mu_debug_destroy (mu_debug_t *, void *);
void *mu_debug_get_owner (mu_debug_t);
int mu_debug_set_level (mu_debug_t, mu_log_level_t);
int mu_debug_get_level (mu_debug_t, mu_log_level_t *);
int mu_debug_set_locus (mu_debug_t, const char *, int);
int mu_debug_get_locus (mu_debug_t, struct mu_debug_locus *);
int mu_debug_set_function (mu_debug_t, const char *);
int mu_debug_get_function (mu_debug_t, const char **);
int mu_debug_print (mu_debug_t, mu_log_level_t, const char *, ...)
MU_PRINTFLIKE(3,4);
int mu_debug_printv (mu_debug_t, mu_log_level_t, const char *, va_list);
int mu_debug_check_level (mu_debug_t, mu_log_level_t);
int mu_debug_printf (mu_debug_t, mu_log_level_t, const char *, ...)
MU_PRINTFLIKE(3,4);
int mu_debug_vprintf (mu_debug_t, mu_log_level_t, const char *, va_list);
extern int mu_debug_line_info;
typedef int (*mu_debug_printer_fp) (void*, mu_log_level_t, const char *);
int mu_debug_set_print (mu_debug_t, mu_debug_printer_fp, void *);
int mu_debug_set_data (mu_debug_t, void *, void (*) (void*), void *);
extern mu_debug_printer_fp mu_debug_default_printer;
int mu_debug_syslog_printer (void *, mu_log_level_t, const char *);
int mu_debug_stderr_printer (void *, mu_log_level_t, const char *);
mu_log_level_t mu_global_debug_level (const char *);
int mu_global_debug_set_level (const char *, mu_log_level_t);
int mu_global_debug_clear_level (const char *);
int mu_global_debug_from_string (const char *, const char *);
int mu_debug_level_from_string (const char *string, mu_log_level_t *plev,
mu_debug_t debug);
struct sockaddr;
void mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
char *bufptr, size_t buflen,
size_t *plen);
char *mu_sockaddr_to_astr (const struct sockaddr *sa, int salen);
size_t mu_debug_register_category (char *name);
size_t mu_debug_next_handle (void);
int mu_debug_level_p (int catn, int level);
void mu_debug_enable_category (const char *catname, size_t catlen, int level);
void mu_debug_disable_category (const char *catname, size_t catlen);
int mu_debug_category_level (const char *catname, size_t catlen, int *plev);
void mu_debug_parse_spec (const char *spec);
void mu_debug_set_category_level (int catn, int level);
void mu_debug_clear_all (void);
void mu_debug_log (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_debug_log_begin (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_debug_log_cont (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_debug_log_end (const char *fmt, ...) MU_PRINTFLIKE(1,2);
#define MU_ASSERT(expr) \
......@@ -115,8 +87,22 @@ char *mu_sockaddr_to_astr (const struct sockaddr *sa, int salen);
while (0)
forloop(`i',1,11,`MKDEBUG(i)')
#define mu_debug(cat,lev,s) \
do \
if (mu_debug_level_p (cat, lev)) \
{ \
if (mu_debug_line_info) \
{ \
mu_debug_log_begin ("\033X<%d>%s:%d: ", \
MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
mu_debug_log_end s; \
} \
else \
mu_debug_log s; \
} \
while (0)
#ifdef __cplusplus
}
#endif
......
......@@ -22,6 +22,7 @@
#include <stdarg.h>
#include <mailutils/types.h>
#include <mailutils/log.h>
#include <mailutils/debug.h>
#ifdef __cplusplus
......@@ -30,32 +31,32 @@ extern "C" {
extern const char *mu_program_name;
#define MU_DIAG_EMERG 0
#define MU_DIAG_ALERT 1
#define MU_DIAG_CRIT 2
#define MU_DIAG_ERROR 3
#define MU_DIAG_EMERG MU_LOG_EMERG
#define MU_DIAG_ALERT MU_LOG_ALERT
#define MU_DIAG_CRIT MU_LOG_CRIT
#define MU_DIAG_ERROR MU_LOG_ERROR
#define MU_DIAG_ERR MU_DIAG_ERROR
#define MU_DIAG_WARNING 4
#define MU_DIAG_NOTICE 5
#define MU_DIAG_INFO 6
#define MU_DIAG_DEBUG 7
#define MU_DIAG_WARNING MU_LOG_WARNING
#define MU_DIAG_NOTICE MU_LOG_NOTICE
#define MU_DIAG_INFO MU_LOG_INFO
#define MU_DIAG_DEBUG MU_LOG_DEBUG
void mu_set_program_name (const char *);
void mu_diag_init (void);
void mu_diag_get_debug (mu_debug_t *);
void mu_diag_set_debug (mu_debug_t);
void mu_diag_vprintf (mu_log_level_t, const char *, va_list);
void mu_diag_printf (mu_log_level_t, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_diag_voutput (mu_log_level_t, const char *, va_list);
void mu_diag_output (mu_log_level_t, const char *, ...) MU_PRINTFLIKE(2,3);
int mu_diag_syslog_printer (void *, mu_log_level_t, const char *);
int mu_diag_stderr_printer (void *, mu_log_level_t, const char *);
void mu_diag_vprintf (int, const char *, va_list);
void mu_diag_cont_vprintf (const char *, va_list);
void mu_diag_printf (int, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_diag_cont_printf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_diag_voutput (int, const char *, va_list);
void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_diag_at_locus (int level, struct mu_locus const *loc,
const char *fmt, ...);
int mu_diag_level_to_syslog (mu_log_level_t level);
const char *mu_diag_level_to_string (mu_log_level_t level);
int mu_diag_level_to_syslog (int level);
const char *mu_diag_level_to_string (int level);
void mu_diag_funcall (mu_log_level_t level, const char *func,
void mu_diag_funcall (int level, const char *func,
const char *arg, int err);
#ifdef __cplusplus
......
......@@ -28,15 +28,9 @@
extern "C" {
#endif
typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap);
extern int mu_verror (const char *fmt, va_list ap);
extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
extern void mu_error_set_print (mu_error_pfn_t) __attribute__((deprecated));
int mu_default_error_printer (const char *fmt, va_list ap);
int mu_syslog_error_printer (const char *fmt, va_list ap);
#ifdef __cplusplus
}
#endif
......
......@@ -76,11 +76,6 @@ extern int mu_folder_get_match (mu_folder_t folder,
/* Notifications. */
extern int mu_folder_get_observable (mu_folder_t, mu_observable_t *);
/* Debug. */
extern int mu_folder_has_debug (mu_folder_t folder);
extern int mu_folder_get_debug (mu_folder_t, mu_debug_t *);
extern int mu_folder_set_debug (mu_folder_t, mu_debug_t);
/* Authentication. */
extern int mu_folder_get_authority (mu_folder_t, mu_authority_t *);
extern int mu_folder_set_authority (mu_folder_t, mu_authority_t);
......
......@@ -26,16 +26,9 @@
extern "C" {
#endif
struct mu_gocs_logging
{
int facility;
char *tag;
};
struct mu_gocs_debug
{
char *string;
char *errpfx;
int line_info;
};
......
......@@ -69,7 +69,7 @@ extern void mu_scm_message_add_owner (SCM MESG, SCM owner);
extern void mu_scm_mutil_init (void);
SCM mu_scm_make_debug_port (mu_debug_t debug, mu_log_level_t level);
SCM mu_scm_make_debug_port (int level);
void mu_scm_debug_port_init (void);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_LOG_H
#define _MAILUTILS_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <mailutils/types.h>
#define MU_LOG_DEBUG 0
#define MU_LOG_INFO 1
#define MU_LOG_NOTICE 2
#define MU_LOG_WARNING 3
#define MU_LOG_ERROR 4
#define MU_LOG_CRIT 5
#define MU_LOG_ALERT 6
#define MU_LOG_EMERG 7
#define MU_LOGMODE_SEVERITY 0x0001
#define MU_LOGMODE_LOCUS 0x0002
int mu_log_stream_create (mu_stream_t *, mu_stream_t);
int mu_syslog_stream_create (mu_stream_t *, int);
extern char *_mu_severity_str[];
extern int _mu_severity_num;
#ifdef __cplusplus
}
#endif
#endif
......@@ -102,11 +102,6 @@ extern int mu_mailbox_set_property (mu_mailbox_t, mu_property_t);
/* URL. */
extern int mu_mailbox_get_url (mu_mailbox_t, mu_url_t *);
/* For any debuging */
extern int mu_mailbox_has_debug (mu_mailbox_t);
extern int mu_mailbox_get_debug (mu_mailbox_t, mu_debug_t *);
extern int mu_mailbox_set_debug (mu_mailbox_t, mu_debug_t);
/* Events. */
extern int mu_mailbox_get_observable (mu_mailbox_t, mu_observable_t *);
......
......@@ -56,8 +56,6 @@ extern int mu_mailer_get_stream (mu_mailer_t, mu_stream_t *)
__attribute__ ((deprecated));
extern int mu_mailer_get_streamref (mu_mailer_t, mu_stream_t *);
extern int mu_mailer_set_stream (mu_mailer_t, mu_stream_t);
extern int mu_mailer_get_debug (mu_mailer_t, mu_debug_t *);
extern int mu_mailer_set_debug (mu_mailer_t, mu_debug_t);
extern int mu_mailer_get_observable (mu_mailer_t, mu_observable_t *);
extern int mu_mailer_get_url (mu_mailer_t, mu_url_t *);
......
......@@ -59,11 +59,12 @@
#include <mailutils/url.h>
#include <mailutils/gocs.h>
#include <mailutils/version.h>
#include <mailutils/vartab.h>
#include <mailutils/io.h>
#include <mailutils/secret.h>
#include <mailutils/cctype.h>
#include <mailutils/cstr.h>
#include <mailutils/wordsplit.h>
#include <mailutils/log.h>
#include <mailutils/stdstream.h>
/* EOF */
......
......@@ -186,8 +186,7 @@ extern int mu_message_aget_decoded_attachment_name (mu_message_t msg,
char **name,
char **plang);
extern int mu_message_save_to_mailbox (mu_message_t msg,
mu_debug_t debug, const char *toname,
extern int mu_message_save_to_mailbox (mu_message_t msg, const char *toname,
int perms);
......
......@@ -130,8 +130,6 @@ extern int mu_auth_data_alloc (struct mu_auth_data **ptr,
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;
extern struct mu_auth_module mu_auth_generic_module;
......
......@@ -43,8 +43,6 @@ extern int mu_nntp_disconnect (mu_nntp_t nntp);
extern int mu_nntp_set_timeout (mu_nntp_t nntp, int timeout);
extern int mu_nntp_get_timeout (mu_nntp_t nntp, int *timeout);
extern int mu_nntp_set_debug (mu_nntp_t nntp, mu_debug_t debug);
extern int mu_nntp_stls (mu_nntp_t nntp);
......
......@@ -27,8 +27,6 @@ extern "C" {
int mu_progmailer_create (mu_progmailer_t *pm);
int mu_progmailer_set_command (mu_progmailer_t pm, const char *command);
int mu_progmailer_sget_command (mu_progmailer_t pm, const char **command);
/* FIXME: missing _aget_ and _get_ */
int mu_progmailer_set_debug (mu_progmailer_t pm, mu_debug_t debug);
int mu_progmailer_open (mu_progmailer_t pm, char **argv);
int mu_progmailer_send (mu_progmailer_t pm, mu_message_t msg);
int mu_progmailer_close (mu_progmailer_t pm);
......
......@@ -58,8 +58,6 @@ int mu_ip_server_create (mu_ip_server_t *psrv, struct sockaddr *addr,
int len, int type);
int mu_ip_server_destroy (mu_ip_server_t *psrv);
int mu_ip_server_get_type (mu_ip_server_t srv, int *ptype);
int mu_ip_server_set_debug (mu_ip_server_t srv, mu_debug_t debug);
int mu_ip_server_get_debug (mu_ip_server_t srv, mu_debug_t *pdebug);
int mu_ip_server_set_ident (mu_ip_server_t srv, const char *ident);
int mu_ip_server_set_acl (mu_ip_server_t srv, mu_acl_t acl);
int mu_ip_server_set_conn (mu_ip_server_t srv, mu_ip_server_conn_fp conn);
......
......@@ -32,21 +32,10 @@ extern "C" {
typedef struct mu_sieve_machine *mu_sieve_machine_t;
typedef struct
{
char *source_file;
size_t source_line;
}
mu_sieve_locus_t;
typedef int (*mu_sieve_handler_t) (mu_sieve_machine_t mach,
mu_list_t args, mu_list_t tags);
typedef int (*mu_sieve_printf_t) (void *data, const char *fmt, va_list ap);
typedef int (*mu_sieve_parse_error_t) (void *data,
const char *filename, int lineno,
const char *fmt, va_list ap);
typedef void (*mu_sieve_action_log_t) (void *data,
const mu_sieve_locus_t * locus,
mu_stream_t stream,
size_t msgno, mu_message_t msg,
const char *action,
const char *fmt, va_list ap);
......@@ -202,7 +191,10 @@ int mu_sieve_vlist_compare (mu_sieve_value_t * a, mu_sieve_value_t * b,
void *data, size_t * count);
/* Functions to create and destroy sieve machine */
int mu_sieve_machine_init (mu_sieve_machine_t * mach, void *data);
int mu_sieve_machine_init (mu_sieve_machine_t *mach);
int mu_sieve_machine_init_ex (mu_sieve_machine_t *pmach,
void *data,
mu_stream_t errstream);
int mu_sieve_machine_dup (mu_sieve_machine_t const in,
mu_sieve_machine_t *out);
int mu_sieve_machine_inherit (mu_sieve_machine_t const in,
......@@ -212,21 +204,19 @@ int mu_sieve_machine_add_destructor (mu_sieve_machine_t mach,
mu_sieve_destructor_t destr, void *ptr);
/* Functions for accessing sieve machine internals */
void mu_sieve_get_diag_stream (mu_sieve_machine_t mach, mu_stream_t *pstr);
void mu_sieve_set_diag_stream (mu_sieve_machine_t mach, mu_stream_t str);
void *mu_sieve_get_data (mu_sieve_machine_t mach);
void mu_sieve_set_data (mu_sieve_machine_t mach, void *);
mu_message_t mu_sieve_get_message (mu_sieve_machine_t mach);
size_t mu_sieve_get_message_num (mu_sieve_machine_t mach);
int mu_sieve_get_debug_level (mu_sieve_machine_t mach);
mu_mailer_t mu_sieve_get_mailer (mu_sieve_machine_t mach);
int mu_sieve_get_locus (mu_sieve_machine_t mach, mu_sieve_locus_t *);
int mu_sieve_get_locus (mu_sieve_machine_t mach, struct mu_locus *);
char *mu_sieve_get_daemon_email (mu_sieve_machine_t mach);
const char *mu_sieve_get_identifier (mu_sieve_machine_t mach);
void mu_sieve_set_error (mu_sieve_machine_t mach,
mu_sieve_printf_t error_printer);
void mu_sieve_set_parse_error (mu_sieve_machine_t mach,
mu_sieve_parse_error_t p);
void mu_sieve_set_debug (mu_sieve_machine_t mach, mu_sieve_printf_t debug);
void mu_sieve_set_debug_object (mu_sieve_machine_t mach, mu_debug_t dbg);
void mu_sieve_set_debug_level (mu_sieve_machine_t mach, int level);
void mu_sieve_set_logger (mu_sieve_machine_t mach,
mu_sieve_action_log_t logger);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_STDSTREAM_H
#define _MAILUTILS_STDSTREAM_H
#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
#endif
extern mu_stream_t mu_strin;
extern mu_stream_t mu_strout;
extern mu_stream_t mu_strerr;
extern const char *mu_program_name;
#define MU_STRERR_STDERR 0
#define MU_STRERR_SYSLOG 1
/* #define MU_STRERR_FILE 2 */
void mu_stdstream_setup (void);
int mu_stdstream_strerr_create (mu_stream_t *str, int type, int facility,
int priority, const char *tag,
const char *fname);
int mu_stdstream_strerr_setup (int type);
int mu_printf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
#ifdef __cplusplus
}
#endif
#endif
......@@ -76,7 +76,7 @@ enum mu_buffer_type
#define MU_IOCTL_GET_ECHO 12
#define MU_IOCTL_SET_ECHO 13
/* The following ioctls are for nullstreams only: */
#define MU_IOCTL_NULLSTREAM_SET_PATTERN 14
/* Set read pattern.
......@@ -89,6 +89,34 @@ enum mu_buffer_type
/* Limit stream size. Argument: mu_off_t *psize; */
#define MU_IOCTL_NULLSTREAM_CLRSIZE 17
/* Lift the size limit. Argument: NULL */
/* The following are for logstreams */
/* Get or set logging severity.
Arg: unsigned *
*/
#define MU_IOCTL_LOGSTREAM_GET_SEVERITY 18
#define MU_IOCTL_LOGSTREAM_SET_SEVERITY 19
/* Get or set locus.
Arg: struct mu_locus *
*/
#define MU_IOCTL_LOGSTREAM_GET_LOCUS 20
#define MU_IOCTL_LOGSTREAM_SET_LOCUS 21
/* Get or set log mode.
Arg: int *
*/
#define MU_IOCTL_LOGSTREAM_GET_MODE 22
#define MU_IOCTL_LOGSTREAM_SET_MODE 23
/* Advance locus line.
Arg: NULL (increment by 1)
int *
*/
#define MU_LOGSTREAM_ADVANCE_LOCUS_LINE 24
/* Advance locus column.
Arg: NULL (increment by 1)
int *
*/
#define MU_LOGSTREAM_ADVANCE_LOCUS_COL 25
#define MU_TRANSPORT_INPUT 0
#define MU_TRANSPORT_OUTPUT 1
......@@ -240,8 +268,7 @@ int mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport,
const char *prefix[]);
int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out);
int mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug,
mu_log_level_t level, int flags);
int mu_dbgstream_create(mu_stream_t *pref, int severity);
int mu_rdcache_stream_create (mu_stream_t *pstream, mu_stream_t transport,
int flags);
......
Makefile
Makefile.in
debcat.h
......
......@@ -20,8 +20,7 @@ sysinclude_HEADERS = \
attribute.h\
auth.h\
body.h\
dbgstream.h\
debug.h\
debcat.h\
envelope.h\
file_stream.h\
filter.h\
......@@ -33,6 +32,7 @@ sysinclude_HEADERS = \
iterator.h\
iostream.h\
list.h\
logstream.h\
mailbox.h\
mailer.h\
mapfile_stream.h\
......@@ -53,7 +53,14 @@ sysinclude_HEADERS = \
streamref.h\
streamtrans.h\
stream.h\
syslogstream.h\
temp_file_stream.h\
tls-stream.h\
url.h\
xscript-stream.h
BUILT_SOURCES = debcat.h
debcat.h: $(top_srcdir)/libmailutils/diag/debcat
$(AM_V_GEN)$(AWK) -f $(mu_aux_dir)/debcat.awk $^ > $@
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2005, 2007, 2010 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, see
<http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_SYS_DEBUG_H
# define _MAILUTILS_SYS_DEBUG_H
#include <mailutils/debug.h>
#include <mailutils/stream.h>
#ifdef __cplusplus
extern "C" {
#endif
struct _mu_debug
{
size_t level;
mu_stream_t stream;
void *owner;
struct mu_debug_locus locus;
const char *function;
void *data;
mu_debug_printer_fp printer;
void (*destroy) (void *data);
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_DEBUG_H */
......@@ -37,7 +37,6 @@ struct _mu_folder
/* Data */
mu_authority_t authority;
mu_observable_t observable;
mu_debug_t debug;
mu_property_t property;
mu_stream_t stream;
mu_monitor_t monitor;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_SYS_LOGSTREAM_H
#define _MAILUTILS_SYS_LOGSTREAM_H
#include <mailutils/types.h>
#include <mailutils/sys/stream.h>
struct _mu_log_stream
{
struct _mu_stream base;
mu_stream_t transport;
unsigned severity;
int logmode;
struct mu_locus locus;
};
#endif
......@@ -34,7 +34,6 @@ struct _mu_mailbox
{
/* Data */
mu_observable_t observable;
mu_debug_t debug;
mu_property_t property;
mu_locker_t locker;
mu_stream_t stream;
......
......@@ -37,7 +37,6 @@ struct _mu_mailer
{
mu_stream_t stream;
mu_observable_t observable;
mu_debug_t debug;
mu_url_t url;
int flags;
mu_monitor_t monitor;
......
......@@ -141,8 +141,6 @@ struct _mu_nntp
unsigned timeout; /* Default is 10 minutes. */
mu_debug_t debug; /* debugging trace. */
enum mu_nntp_state state; /* Indicate the state of the running command. */
mu_stream_t carrier; /* TCP Connection. */
......
......@@ -14,18 +14,17 @@
You should have received a copy of the GNU Lesser General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_SYS_DBGSTREAM_H
# define _MAILUTILS_SYS_DBGSTREAM_H
#ifndef _MAILUTILS_SYS_SYSLOGSTREAM_H
#define _MAILUTILS_SYS_SYSLOGSTREAM_H
# include <mailutils/types.h>
# include <mailutils/stream.h>
# include <mailutils/sys/stream.h>
#include <mailutils/types.h>
#include <mailutils/sys/stream.h>
struct _mu_dbgstream
struct _mu_syslog_stream
{
struct _mu_stream stream;
mu_debug_t debug;
mu_log_level_t level;
struct _mu_stream base;
int prio;
};
#endif
......
......@@ -24,8 +24,10 @@
extern "C" {
#endif
extern int mu_log_syslog;
extern int mu_log_facility;
extern char *mu_log_tag;
extern int mu_log_print_severity;
#define MU_LOG_TAG() (mu_log_tag ? mu_log_tag : mu_program_name)
int mu_string_to_syslog_facility (const char *str, int *pfacility);
......
......@@ -33,6 +33,10 @@
# define MU_PRINTFLIKE(fmt,narg) __attribute__ ((__format__ (__printf__, fmt, narg)))
#endif
#ifndef MU_DEPRECATED
# define MU_DEPRECATED __attribute__ ((deprecated))
#endif
#ifdef __cplusplus
extern "C" {
#endif
......@@ -44,7 +48,6 @@ struct mu_address;
struct _mu_attribute;
struct _mu_authority;
struct _mu_body;
struct _mu_debug;
struct _mu_envelope;
struct _mu_filter;
struct _mu_filter_record;
......@@ -79,7 +82,6 @@ typedef struct mu_address *mu_address_t;
typedef struct _mu_attribute *mu_attribute_t;
typedef struct _mu_authority *mu_authority_t;
typedef struct _mu_body *mu_body_t;
typedef struct _mu_debug *mu_debug_t;
typedef struct _mu_envelope *mu_envelope_t;
typedef struct _mu_filter *mu_filter_t;
typedef struct _mu_filter_record *mu_filter_record_t;
......@@ -129,6 +131,13 @@ typedef struct _mu_mime_io_buffer *mu_mime_io_buffer_t;
#define MU_DEFAULT_RECORD _MU_DEFAULT_RECORD_
struct mu_locus
{
char *mu_file;
unsigned mu_line;
unsigned mu_col;
};
enum mu_gocs_op
{
mu_gocs_op_set,
......
......@@ -20,17 +20,27 @@
#include <mailutils/types.h>
#ifdef MU_SUPPRESS_DEPRECATION
# undef MU_DEPRECATED
# define MU_DEPRECATED
#else
# warning "Mailutils support for vartab functions has been deprecated."
# warning "Revise your code to use <mailutils/wordsplit.h>."
#endif
typedef int (*mu_var_expansion_fp) (const char *name, void *data, char **p);
typedef void (*mu_var_free_fp) (void *data, char *value);
int mu_vartab_create (mu_vartab_t *pvar);
int mu_vartab_destroy (mu_vartab_t *pvar);
int mu_vartab_create (mu_vartab_t *pvar) MU_DEPRECATED;
int mu_vartab_destroy (mu_vartab_t *pvar) MU_DEPRECATED;
int mu_vartab_define (mu_vartab_t var, const char *name, const char *value,
int isstatic);
int isstatic) MU_DEPRECATED;
int mu_vartab_define_exp (mu_vartab_t var, const char *name,
mu_var_expansion_fp fun, mu_var_free_fp free,
void *data);
int mu_vartab_count (mu_vartab_t vt, size_t *pcount);
int mu_vartab_getvar (mu_vartab_t vt, const char *name, const char **pvalue);
int mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres);
void *data) MU_DEPRECATED;
int mu_vartab_count (mu_vartab_t vt, size_t *pcount) MU_DEPRECATED;
int mu_vartab_getvar (mu_vartab_t vt, const char *name, const char **pvalue)
MU_DEPRECATED;
int mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres)
MU_DEPRECATED;
#endif
......
......@@ -18,7 +18,7 @@
#ifndef _MAILUTILS_VERSION_H
#define _MAILUTILS_VERSION_H
#include <stdio.h>
#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
......@@ -31,8 +31,9 @@ struct mu_conf_option
};
extern void mu_print_options (void);
extern void mu_fprint_options (FILE *fp, int verbose);
extern void mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt,
extern void mu_format_options (mu_stream_t, int verbose);
extern void mu_format_conf_option (mu_stream_t,
const struct mu_conf_option *opt,
int verbose);
extern const struct mu_conf_option *mu_check_option (char *name);
......
......@@ -19,14 +19,6 @@
extern int mu_tcp_wrapper_enable;
const char *mu_tcp_wrapper_daemon;
extern int mu_tcp_wrapper_cb_hosts_allow (mu_debug_t debug, void *data,
char *arg);
extern int mu_tcp_wrapper_cb_hosts_deny (mu_debug_t debug, void *data,
char *arg);
extern int mu_tcp_wrapper_cb_hosts_allow_syslog (mu_debug_t debug, void *data,
char *arg);
extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data,
char *arg);
extern int mu_tcpwrapper_access (int fd);
extern void mu_tcpwrapper_cfg_init (void);
extern int mu_tcp_wrapper_prefork (int fd, void *data,
......
......@@ -17,7 +17,7 @@
# <http://www.gnu.org/licenses/>.
SUBDIRS = auth base address cfg diag filter mailbox mailer mime\
server string stream property url . tests
server string stream stdstream property url . tests
lib_LTLIBRARIES = libmailutils.la
......@@ -38,6 +38,7 @@ libmailutils_la_LIBADD = \
server/libserver.la\
string/libstring.la\
stream/libstream.la\
stdstream/libstdstream.la\
url/liburl.la
libmailutils_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
......
......@@ -50,12 +50,10 @@
#include <mailutils/nls.h>
#include <mailutils/debug.h>
static mu_debug_t mu_auth_debug;
#define S(s) ((s) ? (s) : "(none)")
#define DEBUG_AUTH(a) \
MU_DEBUG11 (mu_auth_debug, MU_DEBUG_TRACE, \
"source=%s, name=%s, passwd=%s, uid=%lu, gid=%lu, " \
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE, \
("source=%s, name=%s, passwd=%s, uid=%lu, gid=%lu, " \
"gecos=%s, dir=%s, shell=%s, mailbox=%s, quota=%lu, " \
"change_uid=%d\n", \
S ((a)->source), \
......@@ -68,17 +66,8 @@ static mu_debug_t mu_auth_debug;
S ((a)->shell), \
S ((a)->mailbox), \
(unsigned long) (a)->quota, \
(a)->change_uid)
(a)->change_uid))
mu_debug_t
mu_auth_set_debug (mu_debug_t debug)
{
mu_debug_t prev = mu_auth_debug;
mu_auth_debug = debug;
return prev;
}
/* memory allocation */
int
mu_auth_data_alloc (struct mu_auth_data **ptr,
......@@ -202,10 +191,11 @@ mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
mu_iterator_next (itr))
{
mu_iterator_current (itr, (void **)&ep);
MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, "Trying %s...", ep->name);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE,
("Trying %s...", ep->name));
rc = ep->fun (return_data, key, ep->func_data, data);
MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE,
"result: %d=%s\n", rc, mu_strerror (rc));
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE,
("result: %d=%s\n", rc, mu_strerror (rc)));
if (rc == 0)
{
if (return_data)
......@@ -254,22 +244,21 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
switch (type)
{
case mu_auth_key_name:
MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE,
"Getting auth info for user %s\n",
(char*) key);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE,
("Getting auth info for user %s", (char*) key));
list = mu_auth_by_name_list;
break;
case mu_auth_key_uid:
MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE,
"Getting auth info for UID %lu\n",
(unsigned long) *(uid_t*) key);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE,
("Getting auth info for UID %lu",
(unsigned long) *(uid_t*) key));
list = mu_auth_by_uid_list;
break;
default:
MU_DEBUG1 (mu_auth_debug, MU_DEBUG_ERROR,
"Unknown mu_auth_key_type: %d\n", type);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_ERROR,
("Unknown mu_auth_key_type: %d", type));
return EINVAL;
}
return mu_auth_runlist (list, auth, key, NULL);
......@@ -300,9 +289,9 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
{
if (!auth_data)
return EINVAL;
MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE,
"mu_authenticate, user %s, source %s\n",
auth_data->name, auth_data->source);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE,
("mu_authenticate, user %s, source %s\n",
auth_data->name, auth_data->source));
if (!mu_authenticate_list)
mu_auth_begin_setup ();
return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass);
......
......@@ -20,7 +20,6 @@ noinst_LTLIBRARIES = libbase.la
libbase_la_SOURCES = \
alloc.c\
amd.c\
argcv.c\
argcvfree.c\
argcvjoin.c\
argcvrem.c\
......@@ -65,7 +64,6 @@ libbase_la_SOURCES = \
ticket.c\
tilde.c\
usremail.c\
vartab.c\
version.c\
wicket.c
......
......@@ -311,7 +311,7 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
mailbox->_get_size = amd_get_size;
mailbox->_remove = amd_remove_mbox;
MU_DEBUG1 (mailbox->debug, MU_DEBUG_TRACE1, "amd_init(%s)\n", amd->name);
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1, ("amd_init(%s)", amd->name));
*pamd = amd;
return 0;
}
......
......@@ -22,7 +22,11 @@
#include <mailutils/nls.h>
#include <mailutils/version.h>
#include <mailutils/cstr.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <confpaths.h>
......@@ -121,27 +125,41 @@ static struct mu_conf_option mu_conf_option[] = {
};
void
mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt, int verbose)
mu_format_conf_option (mu_stream_t stream, const struct mu_conf_option *opt,
int verbose)
{
fprintf (fp, "%s", opt->name);
mu_stream_printf (stream, "%s", opt->name);
if (verbose && opt->descr)
fprintf (fp, " \t- %s", _(opt->descr));
fputc('\n', fp);
mu_stream_printf (stream, " \t- %s", _(opt->descr));
mu_stream_printf (stream, "\n");
}
void
mu_fprint_options (FILE *fp, int verbose)
mu_format_options (mu_stream_t stream, int verbose)
{
int i;
for (i = 0; mu_conf_option[i].name; i++)
mu_fprint_conf_option (fp, mu_conf_option + i, verbose);
mu_format_conf_option (stream, mu_conf_option + i, verbose);
}
void
mu_print_options ()
{
mu_fprint_options (stdout, 1);
if (mu_strout)
mu_stream_ref (mu_strout);
else
{
int rc = mu_stdio_stream_create (&mu_strout, MU_STDOUT_FD, 0);
if (rc)
{
fprintf (stderr, "mu_stdio_stream_create(%d): %s\n",
MU_STDOUT_FD, mu_strerror (rc));
abort ();
}
}
mu_format_options (mu_strout, 1);
mu_stream_unref (mu_strout);
}
const struct mu_conf_option *
......
......@@ -246,7 +246,7 @@ _file_wicket_get_ticket (mu_wicket_t wicket, void *data,
}
int
mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus *loc,
mu_url_t url, int parse_flags,
mu_url_t *pticket_url)
{
......@@ -257,7 +257,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
size_t len;
mu_url_t pret = NULL;
int weight = 0;
int line = loc->line;
int line = loc->mu_line;
while ((rc = mu_stream_getline (stream, &buf, &bufsize, &len)) == 0
&& len > 0)
......@@ -266,7 +266,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
int err;
int n;
loc->line++;
loc->mu_line++;
p = mu_str_stripws (buf);
/* Skip empty lines and comments. */
......@@ -277,14 +277,14 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
{
/* Skip erroneous entry */
mu_error (_("%s:%u: cannot create URL: %s"),
loc->file, loc->line, mu_strerror (err));
loc->mu_file, loc->mu_line, mu_strerror (err));
continue;
}
if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET))
{
mu_error (_("%s:%u: URL is missing required parts"),
loc->file, loc->line);
loc->mu_file, loc->mu_line);
mu_url_destroy (&u);
continue;
}
......@@ -299,7 +299,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
{
pret = u;
weight = n;
line = loc->line;
line = loc->mu_line;
if (weight == 0)
break;
}
......@@ -311,7 +311,7 @@ mu_wicket_stream_match_url (mu_stream_t stream, struct mu_debug_locus *loc,
if (pret)
{
*pticket_url = pret;
loc->line = line;
loc->mu_line = line;
}
else
rc = MU_ERR_NOENT;
......@@ -327,13 +327,14 @@ mu_wicket_file_match_url (const char *name, mu_url_t url,
{
mu_stream_t stream;
int rc;
struct mu_debug_locus loc;
struct mu_locus loc;
rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
if (rc)
return rc;
loc.file = name;
loc.line = 0;
loc.mu_file = (char*) name;
loc.mu_line = 0;
loc.mu_col = 0;
rc = mu_wicket_stream_match_url (stream, &loc, url, parse_flags,
pticket_url);
mu_stream_close (stream);
......
......@@ -463,7 +463,7 @@ struct include_data
};
static int
_cb_include (mu_debug_t debug, void *data, mu_config_value_t *val)
_cb_include (void *data, mu_config_value_t *val)
{
int ret = 0;
struct stat sb;
......@@ -471,7 +471,7 @@ _cb_include (mu_debug_t debug, void *data, mu_config_value_t *val)
struct include_data *idp = data;
char *tmp = NULL;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
dirname = val->v.string;
......@@ -500,15 +500,13 @@ _cb_include (mu_debug_t debug, void *data, mu_config_value_t *val)
}
else if (errno == ENOENT)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("include file or directory does not exist"));
mu_error (_("include file or directory does not exist"));
ret = 1;
}
else
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("cannot stat include file or directory: %s"),
mu_strerror (errno));
mu_error (_("cannot stat include file or directory: %s"),
mu_strerror (errno));
ret = 1;
}
free (tmp);
......@@ -672,12 +670,11 @@ _first_value_ptr (mu_config_value_t *val)
}
int
mu_cfg_assert_value_type (mu_config_value_t *val, int type, mu_debug_t debug)
mu_cfg_assert_value_type (mu_config_value_t *val, int type)
{
if (!val)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("required argument missing"));
mu_error (_("required argument missing"));
return 1;
}
......@@ -696,17 +693,15 @@ mu_cfg_assert_value_type (mu_config_value_t *val, int type, mu_debug_t debug)
if (val->type != type)
{
/* FIXME */
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("unexpected value: %s"),
_first_value_ptr (val));
mu_error (_("unexpected value: %s"), _first_value_ptr (val));
return 1;
}
return 0;
}
int
mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
int (*fun) (mu_debug_t, const char *, void *),
mu_cfg_string_value_cb (mu_config_value_t *val,
int (*fun) (const char *, void *),
void *data)
{
int rc = 0;
......@@ -714,7 +709,7 @@ mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
switch (val->type)
{
case MU_CFG_STRING:
return fun (debug, val->v.string, data);
return fun (val->v.string, data);
break;
case MU_CFG_ARRAY:
......@@ -724,9 +719,9 @@ mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i],
MU_CFG_STRING, debug))
MU_CFG_STRING))
return 1;
fun (debug, val->v.arg.v[i].v.string, data);
fun (val->v.arg.v[i].v.string, data);
}
}
break;
......@@ -740,12 +735,12 @@ mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
{
mu_config_value_t *pval;
mu_iterator_current (itr, (void*) &pval);
if (mu_cfg_assert_value_type (pval, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (pval, MU_CFG_STRING))
{
rc = 1;
break;
}
fun (debug, pval->v.string, data);
fun (pval->v.string, data);
}
mu_iterator_destroy (&itr);
}
......
......@@ -133,10 +133,10 @@ format_node (const mu_cfg_node_t *node, void *data)
{
struct tree_print *tp = data;
if ((tp->flags & MU_CFG_FMT_LOCUS) && node->locus.file)
if ((tp->flags & MU_CFG_FMT_LOCUS) && node->locus.mu_file)
mu_stream_printf (tp->stream, "# %lu \"%s\"\n",
(unsigned long) node->locus.line,
node->locus.file);
(unsigned long) node->locus.mu_line,
node->locus.mu_file);
format_level (tp->stream, tp->level);
switch (node->type)
{
......
......@@ -32,6 +32,9 @@
#include <mailutils/debug.h>
#include <mailutils/syslog.h>
#include <mailutils/registrar.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
#include <mailutils/log.h>
#include <syslog.h>
int mu_load_user_rcfile = 1;
......@@ -208,27 +211,9 @@ mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
int
mu_gocs_logging_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_logging *p = data;
if (op == mu_gocs_op_set)
{
if (!p)
{
static struct mu_gocs_logging default_gocs_logging = { LOG_FACILITY };
p = &default_gocs_logging;
}
if (p->facility)
{
mu_log_facility = p->facility;
mu_debug_default_printer = mu_debug_syslog_printer;
}
else
mu_debug_default_printer = mu_debug_stderr_printer;
if (p->tag)
mu_log_tag = strdup (p->tag);
}
if (mu_log_syslog >= 0)
mu_stdstream_strerr_setup (mu_log_syslog ?
MU_STRERR_SYSLOG : MU_STRERR_STDERR);
return 0;
}
......@@ -238,11 +223,8 @@ mu_gocs_debug_init (enum mu_gocs_op op, void *data)
if (op == mu_gocs_op_set && data)
{
struct mu_gocs_debug *p = data;
if (p->string && p->errpfx)
{
mu_global_debug_from_string (p->string, p->errpfx);
free (p->errpfx);
}
if (p->string)
mu_debug_parse_spec (p->string);
if (p->line_info >= 0)
mu_debug_line_info = p->line_info;
}
......
......@@ -49,8 +49,7 @@ extern void mu_cfg_set_debug (void);
static void
mu_cfg_set_lex_debug (void)
{
yy_flex_debug = mu_debug_check_level (mu_cfg_get_debug (),
MU_DEBUG_TRACE2);
yy_flex_debug = mu_debug_level_p (MU_DEBCAT_CONFIG, MU_DEBUG_TRACE2);
}
static void _mu_line_add_unescape_last (char *text, size_t len);
......@@ -81,22 +80,17 @@ P [1-9][0-9]*
"/*" BEGIN(COMMENT);
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
<COMMENT>\n ++mu_cfg_locus.line;
<COMMENT>\n ++mu_cfg_locus.mu_line;
<COMMENT>"*"+"/" BEGIN (INITIAL);
/* End-of-line comments */
#debug=.*\n {
mu_log_level_t lev;
mu_debug_t dbg = mu_cfg_get_debug ();
if (mu_debug_level_from_string (yytext + 7, &lev, dbg) == 0)
{
mu_debug_set_level (dbg, lev);
mu_cfg_set_debug ();
mu_cfg_set_lex_debug ();
}
}
#.*\n { mu_cfg_locus.line++; }
mu_debug_parse_spec (yytext + 7);
mu_cfg_set_debug ();
mu_cfg_set_lex_debug ();
}
#.*\n { mu_cfg_locus.mu_line++; }
#.* /* end-of-file comment */;
"//".*\n { mu_cfg_locus.line++; }
"//".*\n { mu_cfg_locus.mu_line++; }
"//".* /* end-of-file comment */;
/* Identifiers */
<INITIAL>{ID} {
......@@ -134,7 +128,7 @@ P [1-9][0-9]*
"<<"(-" "?)?\"{ID}\"[ \t]*\n {
BEGIN (ML);
multiline_begin (yytext+2);
mu_cfg_locus.line++;
mu_cfg_locus.mu_line++;
}
<ML>.*\n { char *p = multiline_strip_tabs (yytext);
......@@ -147,17 +141,20 @@ P [1-9][0-9]*
yylval.string = multiline_finish ();
return MU_TOK_MSTRING;
}
mu_cfg_locus.line++;
mu_cfg_locus.mu_line++;
multiline_add (p); }
{WS} ;
/* Other tokens */
\n { mu_cfg_locus.line++; }
\n { mu_cfg_locus.mu_line++; }
[,;{}()] return yytext[0];
. { if (mu_isprint (yytext[0]))
mu_cfg_parse_error (_("stray character %c"), yytext[0]);
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("stray character %c"), yytext[0]);
else
mu_cfg_parse_error (_("stray character \\%03o"),
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("stray character \\%03o"),
(unsigned char) yytext[0]);
mu_cfg_error_count++;
}
%%
......@@ -174,7 +171,11 @@ unescape_to_line (int c)
{
char t = mu_wordsplit_c_unquote_char (c);
if (t == c && t != '\\' && t != '\"')
mu_cfg_parse_error (_("unknown escape sequence '\\%c'"), c);
{
mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
_("unknown escape sequence '\\%c'"), c);
mu_cfg_error_count++;
}
mu_opool_append_char (pool, t);
}
}
......@@ -360,10 +361,10 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
to this copy. Free full_name: it is not used after that. */
_mu_line_begin ();
_mu_line_add (full_name, strlen (full_name));
mu_cfg_locus.file = _mu_line_finish ();
mu_cfg_locus.mu_file = _mu_line_finish ();
free (full_name);
/* 2. Initialize line number */
mu_cfg_locus.line = 1;
mu_cfg_locus.mu_line = 1;
/* Parse configuration */
yyrestart (fp);
......@@ -371,7 +372,7 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
fclose (fp);
if (flags & MU_PARSE_CONFIG_VERBOSE)
mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"),
mu_cfg_locus.file);
mu_cfg_locus.mu_file);
return rc == 0 ? 0 : MU_ERR_FAILURE;
}
......
......@@ -20,16 +20,14 @@ noinst_LTLIBRARIES = libdiag.la
libdiag_la_SOURCES = \
debug.c\
diag.c\
gdebug.c\
muerror.c\
muerrno.c\
syslog.c\
dbgstderr.c\
dbgsyslog.c
syslog.c
INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
EXTRA_DIST = \
debcat\
errors\
muerrno.cin
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 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, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/debug.h>
#include <stdio.h>
int
mu_debug_stderr_printer (void *unused, mu_log_level_t level, const char *str)
{
fprintf (stderr, "%s: %s",
(level == MU_DEBUG_ERROR) ? "ERROR" : "DEBUG",
str);
return 0;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 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, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/debug.h>
#include <syslog.h>
int
mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
{
syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
return 0;
}
# List of default debug categories for GNU Mailutils.
# Copyright (C) 2010 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, see
# <http://www.gnu.org/licenses/>.
address
attribute
auth
body
config
envelope
filter
folder
header
iterator
list
locker
mailbox
mailer
message
mime
mailcap
property
remote
stream
ticket
url
wicket
assoc
acl
server
......@@ -27,9 +27,10 @@
#include <mailutils/diag.h>
#include <mailutils/nls.h>
#include <mailutils/errno.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
const char *mu_program_name;
mu_debug_t mu_diag_debug;
void
mu_set_program_name (const char *name)
......@@ -56,71 +57,76 @@ mu_set_program_name (const char *name)
void
mu_diag_init ()
{
if (!mu_diag_debug)
{
int rc = mu_debug_create (&mu_diag_debug, NULL);
if (rc)
{
fprintf (stderr,
_("cannot initialize debug object for diagnostics: %s\n"),
mu_strerror (rc));
/* That's a fatal error */
abort ();
}
mu_debug_set_print (mu_diag_debug, mu_diag_stderr_printer, NULL);
}
if (!mu_strerr)
mu_stdstream_setup ();
}
void
mu_diag_get_debug (mu_debug_t *pdebug)
mu_diag_voutput (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
*pdebug = mu_diag_debug;
mu_diag_init ();
mu_stream_printf (mu_strerr, "\033s<%d>", level);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_write (mu_strerr, "\n", 1, NULL);
}
void
mu_diag_set_debug (mu_debug_t debug)
mu_diag_output (int level, const char *fmt, ...)
{
if (mu_diag_debug)
mu_debug_destroy (&mu_diag_debug, NULL);
mu_diag_debug = debug;
va_list ap;
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
void
mu_diag_vprintf (mu_log_level_t level, const char *fmt, va_list ap)
mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...)
{
mu_diag_init ();
mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
va_list ap;
va_start (ap, fmt);
mu_stream_printf (mu_strerr, "\033f<%d>%s\033l<%u>\033c<%u>",
strlen (loc->mu_file), loc->mu_file, loc->mu_line,
loc->mu_col);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
void
mu_diag_printf (mu_log_level_t level, const char *fmt, ...)
mu_diag_vprintf (int level, const char *fmt, va_list ap)
{
va_list ap;
va_start (ap, fmt);
mu_diag_vprintf (level, fmt, ap);
va_end (ap);
mu_diag_init ();
mu_stream_printf (mu_strerr, "\033<%d>", level);
mu_stream_vprintf (mu_strerr, fmt, ap);
}
void
mu_diag_voutput (mu_log_level_t level, const char *fmt, va_list ap)
mu_diag_cont_vprintf (const char *fmt, va_list ap)
{
mu_diag_init ();
mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
mu_debug_printf (mu_diag_debug, level, "\n");
mu_diag_init ();
mu_stream_vprintf (mu_strerr, fmt, ap);
}
void
mu_diag_output (mu_log_level_t level, const char *fmt, ...)
mu_diag_printf (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
mu_diag_vprintf (level, fmt, ap);
va_end (ap);
}
void
mu_diag_cont_printf (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_cont_vprintf (fmt, ap);
va_end (ap);
}
const char *
mu_diag_level_to_string (mu_log_level_t level)
mu_diag_level_to_string (int level)
{
switch (level)
{
......@@ -151,17 +157,6 @@ mu_diag_level_to_string (mu_log_level_t level)
return _("unknown");
}
int
mu_diag_stderr_printer (void *data, mu_log_level_t level, const char *buf)
{
if (mu_program_name)
fprintf (stderr, "%s: ", mu_program_name);
if (level != MU_DIAG_ERROR)
fprintf (stderr, "%s: ", mu_diag_level_to_string (level));
fputs (buf, stderr);
return 0;
}
void
mu_diag_funcall (mu_log_level_t level, const char *func,
const char *arg, int err)
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2009, 2010
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, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mailutils/cctype.h>
#include <mailutils/assoc.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/wordsplit.h>
#include <mailutils/debug.h>
#include <mailutils/cfg.h>
#include <mailutils/nls.h>
int mu_debug_line_info = 0;
struct debug_level
{
unsigned level;
};
static mu_assoc_t debug_table;
mu_log_level_t
mu_global_debug_level (const char *object_name)
{
struct debug_level *p = mu_assoc_ref (debug_table, object_name);
if (p)
return p->level;
return 0;
}
int
mu_global_debug_set_level (const char *object_name, mu_log_level_t level)
{
int rc;
struct debug_level *dbg;
if (!debug_table)
{
rc = mu_assoc_create (&debug_table, sizeof(struct debug_level), 0);
if (rc)
return rc;
}
rc = mu_assoc_ref_install (debug_table, object_name, (void**) &dbg);
if (rc == 0 || rc == MU_ERR_EXISTS)
dbg->level = level;
return rc;
}
int
mu_global_debug_clear_level (const char *object_name)
{
int rc = 0;
if (!object_name)
mu_assoc_clear (debug_table);
else
rc = mu_assoc_remove (debug_table, object_name);
return rc;
}
int
decode_debug_level (const char *p, int *lev)
{
if (strcmp (p, "error") == 0)
*lev = MU_DEBUG_ERROR;
else if (strncmp (p, "trace", 5) == 0 && mu_isdigit (p[5]) && p[6] == 0)
*lev = MU_DEBUG_TRACE0 + atoi (p + 5);
else if (strcmp (p, "proto") == 0)
*lev = MU_DEBUG_PROT;
else
return 1;
return 0;
}
int
mu_debug_level_from_string (const char *string, mu_log_level_t *plev,
mu_debug_t debug)
{
char *q;
unsigned level = MU_DEBUG_INHERIT;
if (mu_isdigit (*string))
{
level = strtoul (string, &q, 0);
if (*q)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid debugging specification `%s': "
"expected levels or number after `=', "
"but found `%s'"),
string, string);
return MU_ERR_FAILURE;
}
}
else
{
size_t i;
struct mu_wordsplit ws;
if (mu_wordsplit (string, &ws,
MU_WRDSF_DELIM|MU_WRDSF_SQUEEZE_DELIMS|
MU_WRDSF_WS|
MU_WRDSF_NOVAR|MU_WRDSF_NOCMD))
{
mu_error (_("cannot split line `%s': %s"), string,
mu_wordsplit_strerror (&ws));
return MU_ERR_FAILURE;
}
for (i = 0; i < ws.ws_wordc; i++)
{
int flag;
int revert = 0;
int upto = 0;
const char *q = ws.ws_wordv[i];
if (*q == '!')
{
q++;
revert = 1;
}
if (*q == '<')
{
q++;
upto = 1;
}
if (decode_debug_level (q, &flag))
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid debugging level `%s'"),
q);
else if (revert)
{
if (upto)
level &= ~MU_DEBUG_LEVEL_UPTO (flag);
else
level &= ~MU_DEBUG_LEVEL_MASK (flag);
}
else
{
if (upto)
level |= MU_DEBUG_LEVEL_UPTO (flag);
else
level |= MU_DEBUG_LEVEL_MASK (flag);
}
}
mu_wordsplit_free (&ws);
}
*plev = level;
return 0;
}
int
mu_global_debug_from_string (const char *string, const char *errpfx)
{
struct mu_wordsplit ws;
size_t i;
ws.ws_delim = ";";
if (mu_wordsplit (string, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_WS))
{
mu_error (_("cannot split line `%s': %s"), string,
mu_wordsplit_strerror (&ws));
return errno;
}
for (i = 0; i < ws.ws_wordc; i++)
{
char *p;
mu_log_level_t level = MU_DEBUG_INHERIT;
char *object_name = ws.ws_wordv[i];
for (p = object_name; *p && *p != '='; p++)
;
if (*p == '=')
{
/* FIXME: Use mu_debug_level_from_string */
char *q;
*p++ = 0;
if (mu_isdigit (*p))
{
level = strtoul (p, &q, 0);
if (*q)
{
mu_error ("%s: invalid debugging specification `%s': "
"expected levels or number after `=', "
"but found `%s'",
errpfx, ws.ws_wordv[i], p);
break;
}
}
else
{
size_t j;
struct mu_wordsplit ws1;
ws.ws_delim = ",";
if (mu_wordsplit (p, &ws1,
MU_WRDSF_DELIM|MU_WRDSF_NOVAR|MU_WRDSF_NOCMD))
{
mu_error (_("cannot split line `%s': %s"), p,
mu_wordsplit_strerror (&ws));
return MU_ERR_FAILURE;
}
for (j = 0; j < ws1.ws_wordc; j++)
{
int flag;
int revert = 0;
int upto = 0;
const char *q = ws1.ws_wordv[j];
if (*q == '!')
{
q++;
revert = 1;
}
if (*q == '<')
{
q++;
upto = 1;
}
if (decode_debug_level (q, &flag))
mu_error ("%s: invalid debugging level `%s'",
errpfx, q);
else if (revert)
{
if (upto)
level &= ~MU_DEBUG_LEVEL_UPTO (flag);
else
level &= ~MU_DEBUG_LEVEL_MASK (flag);
}
else
{
if (upto)
level |= MU_DEBUG_LEVEL_UPTO (flag);
else
level |= MU_DEBUG_LEVEL_MASK (flag);
}
}
mu_wordsplit_free (&ws1);
}
}
else
level |= MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT);
if (p[-1] == ':')
{
p[-1] = 0;
level &= ~MU_DEBUG_INHERIT;
}
mu_global_debug_set_level (object_name, level);
}
mu_wordsplit_free (&ws);
return 0;
}
......@@ -46,71 +46,6 @@ mu_error (const char *fmt, ...)
return 0;
}
/* Compatibility layer */
int
mu_default_error_printer (const char *fmt, va_list ap)
{
if (mu_program_name)
fprintf (stderr, "%s: ", mu_program_name);
vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
return 0;
}
int
mu_syslog_error_printer (const char *fmt, va_list ap)
{
#ifdef HAVE_VSYSLOG
vsyslog (LOG_CRIT, fmt, ap);
#else
char buf[128];
vsnprintf (buf, sizeof buf, fmt, ap);
syslog (LOG_CRIT, "%s", buf);
#endif
return 0;
}
static void
compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
pfn (fmt, ap);
va_end (ap);
}
static int
compat_error_printer (void *data, mu_log_level_t level, const char *buf)
{
if (!data)
mu_diag_stderr_printer (NULL, level, buf);
else
{
int len = strlen (buf);
if (len > 0 && buf[len-1] == '\n')
len--;
compat_error_printer0 (data, "%-.*s", len, buf);
}
return 0;
}
void
mu_error_set_print (mu_error_pfn_t pfn)
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, compat_error_printer, NULL);
mu_debug_set_data (debug, pfn, NULL, NULL);
#if 0
{
static int warned;
if (!warned)
{
warned = 1;
mu_diag_output ("this program uses mu_error_set_print, which is deprecated");
}
#endif
}
......
......@@ -126,20 +126,9 @@ mu_diag_level_to_syslog (mu_log_level_t level)
return LOG_EMERG;
}
int
mu_diag_syslog_printer (void *data, mu_log_level_t level, const char *buf)
{
int len = strlen (buf);
if (len > 0 && buf[len-1] == '\n')
{
len--;
if (len > 0 && buf[len-1] == '\r')
len--;
}
syslog (mu_diag_level_to_syslog (level), "%-.*s", len, buf);
return 0;
}
int mu_log_syslog = 0;
int mu_log_facility = LOG_FACILITY;
char *mu_log_tag = NULL;
int mu_log_print_severity = 0;
......
......@@ -355,43 +355,6 @@ mu_folder_get_match (mu_folder_t folder, mu_folder_match_fp *pmatch)
return 0;
}
int
mu_folder_has_debug (mu_folder_t folder)
{
if (folder == NULL)
return 0;
return folder->debug ? 1 : 0;
}
int
mu_folder_set_debug (mu_folder_t folder, mu_debug_t debug)
{
if (folder == NULL)
return EINVAL;
if (folder->debug)
mu_debug_destroy (&folder->debug, folder);
folder->debug = debug;
return 0;
}
int
mu_folder_get_debug (mu_folder_t folder, mu_debug_t *pdebug)
{
if (folder == NULL)
return EINVAL;
if (pdebug == NULL)
return MU_ERR_OUT_PTR_NULL;
if (folder->debug == NULL)
{
int status = mu_debug_create (&folder->debug, folder);
if (status != 0)
return status;
}
*pdebug = folder->debug;
return 0;
}
void
mu_list_response_free (void *data)
{
......
......@@ -79,7 +79,6 @@ _mailbox_create_from_record (mu_mailbox_t *pmbox,
mu_url_t url,
const char *name)
{
mu_log_level_t level;
int (*m_init) (mu_mailbox_t) = NULL;
mu_record_get_mailbox (record, &m_init);
......@@ -143,23 +142,7 @@ _mailbox_create_from_record (mu_mailbox_t *pmbox,
mu_mailbox_destroy (&mbox);
}
else
{
*pmbox = mbox;
level = mu_global_debug_level ("mailbox");
if (level)
{
int status = mu_debug_create (&mbox->debug, mbox);
if (status)
return 0; /* FIXME: don't want to bail out just because I
failed to create a *debug* object. But I may
be wrong... */
mu_debug_set_level (mbox->debug, level);
if (level & MU_DEBUG_INHERIT)
mu_folder_set_debug (mbox->folder, mbox->debug);
}
}
*pmbox = mbox;
return status;
}
return MU_ERR_NO_HANDLER;
......@@ -265,9 +248,6 @@ mu_mailbox_destroy (mu_mailbox_t *pmbox)
if (mbox->locker)
mu_locker_destroy (&mbox->locker);
if (mbox->debug)
mu_debug_destroy (&mbox->debug, mbox);
if (mbox->folder)
mu_folder_destroy (&mbox->folder);
......@@ -684,49 +664,6 @@ mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
}
int
mu_mailbox_has_debug (mu_mailbox_t mailbox)
{
if (mailbox == NULL)
return 0;
return mailbox->debug ? 1 : 0;
}
int
mu_mailbox_set_debug (mu_mailbox_t mbox, mu_debug_t debug)
{
if (mbox == NULL)
return MU_ERR_MBX_NULL;
if (mbox->debug)
mu_debug_destroy (&mbox->debug, mbox);
mbox->debug = debug;
/* FIXME: Honor MU_DEBUG_INHERIT */
if (!mu_folder_has_debug (mbox->folder))
mu_folder_set_debug (mbox->folder, debug);
return 0;
}
int
mu_mailbox_get_debug (mu_mailbox_t mbox, mu_debug_t *pdebug)
{
if (mbox == NULL)
return MU_ERR_MBX_NULL;
if (pdebug == NULL)
return MU_ERR_OUT_PTR_NULL;
if (mbox->debug == NULL)
{
int status = mu_debug_create (&mbox->debug, mbox);
if (status != 0)
return status;
/* FIXME: MU_DEBUG_INHERIT?? */
if (!mu_folder_has_debug (mbox->folder))
mu_folder_set_debug (mbox->folder, mbox->debug);
}
*pdebug = mbox->debug;
return 0;
}
int
mu_mailbox_get_url (mu_mailbox_t mbox, mu_url_t *purl)
{
if (mbox == NULL)
......
......@@ -350,8 +350,8 @@ attach_auth_ticket (mu_mailbox_t mbox)
mu_wicket_t wicket;
int rc;
MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
"Reading user ticket file %s\n", filename);
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
("Reading user ticket file %s", filename));
if ((rc = mu_file_wicket_create (&wicket, filename)) == 0)
{
mu_ticket_t ticket;
......@@ -359,18 +359,18 @@ attach_auth_ticket (mu_mailbox_t mbox)
if ((rc = mu_wicket_get_ticket (wicket, NULL, &ticket)) == 0)
{
rc = mu_authority_set_ticket (auth, ticket);
MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
"Retrieved and set ticket: %d\n", rc);
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
("Retrieved and set ticket: %d", rc));
}
else
MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
"Error retrieving ticket: %s\n",
mu_strerror (rc));
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
("Error retrieving ticket: %s\n",
mu_strerror (rc)));
mu_wicket_destroy (&wicket);
}
else
MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
"Error creating wicket: %s\n", mu_strerror (rc));
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
("Error creating wicket: %s\n", mu_strerror (rc)));
free (filename);
}
}
......
......@@ -1252,39 +1252,34 @@ mu_message_get_observable (mu_message_t msg, mu_observable_t *pobservable)
}
int
mu_message_save_to_mailbox (mu_message_t msg,
mu_debug_t debug,
const char *toname, int perms)
mu_message_save_to_mailbox (mu_message_t msg, const char *toname, int perms)
{
int rc = 0;
mu_mailbox_t to = 0;
if ((rc = mu_mailbox_create_default (&to, toname)))
{
MU_DEBUG2 (debug, MU_DEBUG_ERROR,
"mu_mailbox_create_default (%s) failed: %s\n", toname,
mu_strerror (rc));
mu_debug (MU_DEBCAT_MESSAGE, MU_DEBUG_ERROR,
("mu_mailbox_create_default (%s) failed: %s\n", toname,
mu_strerror (rc)));
goto end;
}
if (debug && (rc = mu_mailbox_set_debug (to, debug)))
goto end;
if ((rc = mu_mailbox_open (to,
MU_STREAM_WRITE | MU_STREAM_CREAT
| (perms & MU_STREAM_IMASK))))
{
MU_DEBUG2 (debug, MU_DEBUG_ERROR,
"mu_mailbox_open (%s) failed: %s\n", toname,
mu_strerror (rc));
mu_debug (MU_DEBCAT_MESSAGE, MU_DEBUG_ERROR,
("mu_mailbox_open (%s) failed: %s", toname,
mu_strerror (rc)));
goto end;
}
if ((rc = mu_mailbox_append_message (to, msg)))
{
MU_DEBUG2 (debug, MU_DEBUG_ERROR,
"mu_mailbox_append_message (%s) failed: %s\n", toname,
mu_strerror (rc));
mu_debug (MU_DEBCAT_MESSAGE, MU_DEBUG_ERROR,
("mu_mailbox_append_message (%s) failed: %s", toname,
mu_strerror (rc)));
goto end;
}
......@@ -1293,9 +1288,9 @@ end:
if (!rc)
{
if ((rc = mu_mailbox_close (to)))
MU_DEBUG2 (debug, MU_DEBUG_ERROR,
"mu_mailbox_close (%s) failed: %s\n", toname,
mu_strerror (rc));
mu_debug (MU_DEBCAT_MESSAGE, MU_DEBUG_ERROR,
("mu_mailbox_close (%s) failed: %s", toname,
mu_strerror (rc)));
}
else
mu_mailbox_close (to);
......
......@@ -33,6 +33,7 @@
#include <mailutils/cstr.h>
#include <mailutils/address.h>
#include <mailutils/debug.h>
#include <mailutils/sys/debcat.h>
#include <mailutils/errno.h>
#include <mailutils/iterator.h>
#include <mailutils/list.h>
......@@ -90,19 +91,6 @@ mu_mailer_get_url_default (const char **url)
return 0;
}
static void
set_default_debug (mu_mailer_t mailer)
{
mu_log_level_t level = mu_global_debug_level ("mailer");
if (level)
{
mu_debug_t debug;
if (mu_mailer_get_debug (mailer, &debug))
return;
mu_debug_set_level (debug, level);
}
}
int
mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
{
......@@ -149,7 +137,6 @@ mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
mailer->url = url;
*pmailer = mailer;
set_default_debug (mailer);
return status;
}
}
......@@ -206,9 +193,6 @@ mu_mailer_destroy (mu_mailer_t * pmailer)
if (mailer->url)
mu_url_destroy (&(mailer->url));
if (mailer->debug)
mu_debug_destroy (&(mailer->debug), mailer);
if (mailer->property)
mu_property_destroy (&mailer->property);
......@@ -382,9 +366,9 @@ _set_from (mu_address_t *pfrom, mu_message_t msg, mu_address_t from,
/* Use the From: header. */
case 0:
MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
"mu_mailer_send_message(): using From: %s\n",
mail_from);
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE,
("mu_mailer_send_message(): using From: %s",
mail_from));
break;
case MU_ERR_NOENT:
......@@ -396,14 +380,14 @@ _set_from (mu_address_t *pfrom, mu_message_t msg, mu_address_t from,
mail_from = mu_get_user_email (NULL);
if (mail_from)
MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
"mu_mailer_send_message(): using user's address: %s\n",
mail_from);
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE,
("mu_mailer_send_message(): using user's address: %s",
mail_from));
else
{
MU_DEBUG (mailer->debug, MU_DEBUG_ERROR,
"mu_mailer_send_message(): "
"no user's address, failing\n");
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("mu_mailer_send_message(): "
"no user's address, failing"));
return errno;
}
/* FIXME: should we add the From: header? */
......@@ -440,9 +424,9 @@ _set_to (mu_address_t *paddr, mu_message_t msg, mu_address_t to,
default:
return status;
}
MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
"mu_mailer_send_message(): using RCPT TO: %s\n",
rcpt_to);
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE,
("mu_mailer_send_message(): using RCPT TO: %s",
rcpt_to));
status = mu_address_create (paddr, rcpt_to);
}
......@@ -741,33 +725,6 @@ mu_mailer_get_property (mu_mailer_t mailer, mu_property_t * pproperty)
}
int
mu_mailer_set_debug (mu_mailer_t mailer, mu_debug_t debug)
{
if (mailer == NULL)
return EINVAL;
mu_debug_destroy (&(mailer->debug), mailer);
mailer->debug = debug;
return 0;
}
int
mu_mailer_get_debug (mu_mailer_t mailer, mu_debug_t * pdebug)
{
if (mailer == NULL)
return EINVAL;
if (pdebug == NULL)
return MU_ERR_OUT_PTR_NULL;
if (mailer->debug == NULL)
{
int status = mu_debug_create (&(mailer->debug), mailer);
if (status != 0)
return status;
}
*pdebug = mailer->debug;
return 0;
}
int
mu_mailer_get_url (mu_mailer_t mailer, mu_url_t * purl)
{
if (!mailer)
......
......@@ -47,7 +47,6 @@ struct _mu_progmailer
int fd;
pid_t pid;
RETSIGTYPE (*sighandler)();
mu_debug_t debug;
char *command;
};
......@@ -63,7 +62,6 @@ mu_progmailer_create (struct _mu_progmailer **ppm)
pm->fd = -1;
pm->pid = -1;
pm->sighandler = SIG_ERR;
pm->debug = NULL;
pm->command = NULL;
*ppm = pm;
return 0;
......@@ -95,15 +93,6 @@ mu_progmailer_sget_command (mu_progmailer_t pm, const char **command)
return 0;
}
int
mu_progmailer_set_debug (mu_progmailer_t pm, mu_debug_t debug)
{
if (!pm)
return EINVAL;
pm->debug = debug;
return 0;
}
void
mu_progmailer_destroy (struct _mu_progmailer **ppm)
{
......@@ -128,8 +117,8 @@ mu_progmailer_open (struct _mu_progmailer *pm, char **argv)
if ((pm->sighandler = signal (SIGCHLD, SIG_DFL)) == SIG_ERR)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"setting SIGCHLD failed: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("setting SIGCHLD failed: %s", mu_strerror (status)));
return status;
}
......@@ -150,20 +139,23 @@ mu_progmailer_open (struct _mu_progmailer *pm, char **argv)
else if (pm->pid == -1)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"fork failed: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("fork failed: %s", mu_strerror (status)));
}
}
else
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"pipe() failed: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("pipe() failed: %s\n", mu_strerror (status)));
}
if (mu_debug_level_p (MU_DEBCAT_MAILER, 10))
{
mu_debug_log_begin ("exec %s argv:", pm->command);
for (i = 0; argv[i]; i++)
mu_debug_log_cont (" %s", argv[i]);
mu_debug_log_end ("");
}
MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, "exec %s argv:", pm->command);
for (i = 0; argv[i]; i++)
MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, " %s", argv[i]);
MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "\n");
close (tunnel[0]);
if (status != 0)
......@@ -190,11 +182,11 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
status = mu_header_get_streamref (hdr, &stream);
if (status)
{
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"cannot get header stream: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("cannot get header stream: %s", mu_strerror (status)));
return status;
}
MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending headers...\n");
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE, ("Sending headers..."));
mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
while ((status = mu_stream_readline (stream, buffer, sizeof (buffer),
&len)) == 0
......@@ -202,13 +194,13 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
{
if (mu_c_strncasecmp (buffer, MU_HEADER_FCC, sizeof (MU_HEADER_FCC) - 1))
{
MU_DEBUG1 (pm->debug, MU_DEBUG_PROT, "Header: %s", buffer);
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_PROT, ("Header: %s", buffer));
if (write (pm->fd, buffer, len) == -1)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
"write failed: %s\n", strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("write failed: %s", strerror (status)));
break;
}
}
......@@ -221,19 +213,19 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
"write failed: %s\n", strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("write failed: %s", strerror (status)));
}
}
mu_stream_destroy (&stream);
MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending body...\n");
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE, ("Sending body..."));
mu_message_get_body (msg, &body);
status = mu_body_get_streamref (body, &stream);
if (status)
{
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"cannot get body stream: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("cannot get body stream: %s\n", mu_strerror (status)));
return status;
}
......@@ -246,8 +238,8 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
"write failed: %s\n", strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("write failed: %s\n", strerror (status)));
break;
}
}
......@@ -265,17 +257,17 @@ mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
else
{
status = errno;
MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
"waitpid(%lu) failed: %s\n",
(unsigned long) pm->pid, strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("waitpid(%lu) failed: %s\n",
(unsigned long) pm->pid, strerror (status)));
}
}
else if (WIFEXITED (exit_status))
{
exit_status = WEXITSTATUS (exit_status);
MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
"%s exited with: %d\n",
pm->command, exit_status);
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE,
("%s exited with: %d\n",
pm->command, exit_status));
status = (exit_status == 0) ? 0 : MU_ERR_PROCESS_EXITED;
}
else if (WIFSIGNALED (exit_status))
......@@ -305,8 +297,8 @@ mu_progmailer_close (struct _mu_progmailer *pm)
&& signal (SIGCHLD, pm->sighandler) == SIG_ERR)
{
status = errno;
MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
"resetting SIGCHLD failed: %s\n", mu_strerror (status));
mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
("resetting SIGCHLD failed: %s\n", mu_strerror (status)));
}
pm->sighandler = SIG_ERR;
return status;
......
......@@ -33,6 +33,7 @@
#include <mailutils/wordsplit.h>
#include <mailutils/list.h>
#include <mailutils/debug.h>
#include <mailutils/sys/debcat.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/kwd.h>
......@@ -49,7 +50,6 @@ struct _mu_acl_entry
struct _mu_acl
{
mu_debug_t debug;
mu_list_t aclist;
};
......@@ -118,7 +118,6 @@ mu_acl_create (mu_acl_t *pacl)
{
int rc;
mu_acl_t acl;
mu_log_level_t level;
acl = calloc (1, sizeof (*acl));
if (!acl)
......@@ -130,14 +129,6 @@ mu_acl_create (mu_acl_t *pacl)
*pacl = acl;
mu_list_set_destroy_item (acl->aclist, _destroy_acl_entry);
level = mu_global_debug_level ("acl");
if (level)
{
int status = mu_debug_create (&acl->debug, NULL);
if (status == 0)
mu_debug_set_level (acl->debug, level);
}
return rc;
}
......@@ -157,33 +148,12 @@ mu_acl_destroy (mu_acl_t *pacl)
return EINVAL;
acl = *pacl;
mu_list_destroy (&acl->aclist);
mu_debug_destroy (&acl->debug, NULL);
free (acl);
*pacl = acl;
return 0;
}
int
mu_acl_get_debug (mu_acl_t acl, mu_debug_t *pdebug)
{
if (!acl)
return EINVAL;
if (!pdebug)
return MU_ERR_OUT_NULL;
*pdebug = acl->debug;
return 0;
}
int
mu_acl_set_debug (mu_acl_t acl, mu_debug_t debug)
{
if (!acl)
return EINVAL;
acl->debug = debug;
return 0;
}
int
mu_acl_get_iterator (mu_acl_t acl, mu_iterator_t *pitr)
{
if (!acl)
......@@ -204,16 +174,16 @@ mu_acl_append (mu_acl_t acl, mu_acl_action_t act,
rc = mu_acl_entry_create (&ent, act, data, sa, salen, netmask);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot allocate ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot allocate ACL entry: %s", mu_strerror (rc)));
return ENOMEM;
}
rc = mu_list_append (acl->aclist, ent);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot append ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot append ACL entry: %s", mu_strerror (rc)));
free (ent);
}
return rc;
......@@ -231,15 +201,15 @@ mu_acl_prepend (mu_acl_t acl, mu_acl_action_t act, void *data,
rc = mu_acl_entry_create (&ent, act, data, sa, salen, netmask);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot allocate ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot allocate ACL entry: %s", mu_strerror (rc)));
return ENOMEM;
}
rc = mu_list_prepend (acl->aclist, ent);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot prepend ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot prepend ACL entry: %s", mu_strerror (rc)));
free (ent);
}
return rc;
......@@ -260,22 +230,22 @@ mu_acl_insert (mu_acl_t acl, size_t pos, int before,
rc = mu_list_get (acl->aclist, pos, &ptr);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "No such entry %lu",
(unsigned long) pos);
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("No such entry %lu", (unsigned long) pos));
return rc;
}
rc = mu_acl_entry_create (&ent, act, data, sa, salen, netmask);
if (!ent)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot allocate ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot allocate ACL entry: %s", mu_strerror (rc)));
return ENOMEM;
}
rc = mu_list_insert (acl->aclist, ptr, ent, before);
if (rc)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, "Cannot insert ACL entry: %s",
mu_strerror (rc));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot insert ACL entry: %s", mu_strerror (rc)));
free (ent);
}
return rc;
......@@ -311,8 +281,7 @@ mu_acl_string_to_action (const char *str, mu_acl_action_t *pres)
((salen < mu_offsetof (struct sockaddr_un,sun_path)) ? "" : (sa)->sun_path)
static void
debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa,
int salen)
debug_sockaddr (struct sockaddr *sa, int salen)
{
switch (sa->sa_family)
{
......@@ -320,8 +289,8 @@ debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa,
{
struct sockaddr_in s_in = *(struct sockaddr_in *)sa;
s_in.sin_addr.s_addr = htonl (s_in.sin_addr.s_addr);
mu_debug_printf (dbg, lvl, "{AF_INET %s:%d}",
inet_ntoa (s_in.sin_addr), ntohs (s_in.sin_port));
mu_debug_log_cont ("{AF_INET %s:%d}",
inet_ntoa (s_in.sin_addr), ntohs (s_in.sin_port));
break;
}
......@@ -329,14 +298,14 @@ debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa,
{
struct sockaddr_un *s_un = (struct sockaddr_un *)sa;
if (MU_S_UN_NAME(s_un, salen)[0] == 0)
mu_debug_printf (dbg, lvl, "{AF_UNIX}");
mu_debug_log_cont ("{AF_UNIX}");
else
mu_debug_printf (dbg, lvl, "{AF_UNIX %s}", s_un->sun_path);
mu_debug_log_cont ("{AF_UNIX %s}", s_un->sun_path);
break;
}
default:
mu_debug_printf (dbg, lvl, "{Unsupported family: %d}", sa->sa_family);
mu_debug_log_cont ("{Unsupported family: %d}", sa->sa_family);
}
}
......@@ -425,24 +394,23 @@ mu_sockaddr_to_astr (const struct sockaddr *sa, int salen)
}
int
_acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa,
int salen)
_acl_match (struct _mu_acl_entry *ent, struct sockaddr *sa, int salen)
{
#define RESMATCH(word) \
if (mu_debug_check_level (debug, MU_DEBUG_TRACE0)) \
mu_debug_printf (debug, MU_DEBUG_TRACE0, "%s; ", word);
if (mu_debug_level_p (MU_DEBCAT_ACL, 10)) \
mu_debug_log_end ("%s; ", word);
if (mu_debug_check_level (debug, MU_DEBUG_TRACE0))
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
{
struct in_addr a;
__MU_DEBUG1 (debug, MU_DEBUG_TRACE0, "%s", "Does ");
debug_sockaddr (debug, MU_DEBUG_TRACE0, sa, salen);
mu_debug_printf (debug, MU_DEBUG_TRACE0, " match ");
debug_sockaddr (debug, MU_DEBUG_TRACE0, ent->sa, salen);
mu_debug_log_begin ("Does ");
debug_sockaddr (sa, salen);
mu_debug_log_cont (" match ");
debug_sockaddr (ent->sa, salen);
a.s_addr = ent->netmask;
a.s_addr = htonl (a.s_addr);
mu_debug_printf (debug, MU_DEBUG_TRACE0, " netmask %s? ", inet_ntoa (a));
mu_debug_log_cont (" netmask %s? ", inet_ntoa (a));
}
if (ent->sa->sa_family != sa->sa_family)
......@@ -497,7 +465,6 @@ _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa,
struct run_closure
{
unsigned idx;
mu_debug_t debug;
struct sockaddr *sa;
char *numbuf;
char *portbuf;
......@@ -572,7 +539,7 @@ expand_arg (const char *cmdline, struct run_closure *rp, char **s)
struct mu_wordsplit ws;
const char *env[3];
MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "Expanding \"%s\" => ", cmdline);
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_TRACE, ("Expanding \"%s\"", cmdline));
env[0] = "family";
switch (rp->sa->sa_family)
{
......@@ -599,15 +566,16 @@ expand_arg (const char *cmdline, struct run_closure *rp, char **s)
mu_wordsplit_free (&ws);
if (!*s)
{
MU_DEBUG (rp->debug, MU_DEBUG_TRACE0, "failed: not enough memory. ");
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("failed: not enough memory."));
return ENOMEM;
}
MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "\"%s\". ", *s);
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_TRACE, ("Expansion: \"%s\". ", *s));
}
else
{
MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "failed: %s",
mu_wordsplit_strerror (&ws));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("failed: %s", mu_wordsplit_strerror (&ws)));
rc = errno;
}
return rc;
......@@ -645,8 +613,8 @@ spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp)
if (pid == (pid_t)-1)
{
MU_DEBUG1 (rp->debug, MU_DEBUG_ERROR, "cannot fork: %s",
mu_strerror (errno));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("cannot fork: %s", mu_strerror (errno)));
return errno;
}
......@@ -657,15 +625,15 @@ spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp)
if (WIFEXITED (status))
{
status = WEXITSTATUS (status);
MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0,
"Program finished with code %d.", status);
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_TRACE,
("Program finished with code %d.", status));
*pstatus = status;
}
else if (WIFSIGNALED (status))
{
MU_DEBUG1 (rp->debug, MU_DEBUG_ERROR,
"Program terminated on signal %d.",
WTERMSIG (status));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Program terminated on signal %d.",
WTERMSIG (status)));
return MU_ERR_PROCESS_SIGNALED;
}
else
......@@ -685,14 +653,14 @@ _run_entry (void *item, void *data)
rp->idx++;
if (mu_debug_check_level (rp->debug, MU_DEBUG_TRACE0))
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
{
const char *s = "undefined";
mu_acl_action_to_string (ent->action, &s);
__MU_DEBUG2 (rp->debug, MU_DEBUG_TRACE0, "%d:%s: ", rp->idx, s);
mu_debug_log_begin ("%d:%s: ", rp->idx, s);
}
if (_acl_match (rp->debug, ent, rp->sa, rp->salen) == 0)
if (_acl_match (ent, rp->sa, rp->salen) == 0)
{
switch (ent->action)
{
......@@ -709,17 +677,19 @@ _run_entry (void *item, void *data)
case mu_acl_log:
{
char *s;
mu_debug_t dbg = NULL;
mu_diag_get_debug (&dbg);
if (ent->arg && expand_arg (ent->arg, rp, &s) == 0)
{
mu_debug_printf (dbg, MU_DIAG_INFO, "%s\n", s);
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
mu_debug_log_end ("%s", s);
free (s);
}
else
{
debug_sockaddr (dbg, MU_DIAG_INFO, rp->sa, rp->salen);
mu_debug_printf (dbg, MU_DIAG_INFO, "\n");
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
{
debug_sockaddr (rp->sa, rp->salen);
mu_debug_log_end ("");
}
}
}
break;
......@@ -751,8 +721,8 @@ _run_entry (void *item, void *data)
}
}
if (mu_debug_check_level (rp->debug, MU_DEBUG_TRACE0))
mu_debug_printf (rp->debug, MU_DEBUG_TRACE0, "\n");
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
mu_debug_log_end ("");
return status;
}
......@@ -777,15 +747,14 @@ mu_acl_check_sockaddr (mu_acl_t acl, const struct sockaddr *sa, int salen,
}
r.salen = salen;
if (mu_debug_check_level (acl->debug, MU_DEBUG_TRACE0))
if (mu_debug_level_p (MU_DEBCAT_ACL, 10))
{
__MU_DEBUG1 (acl->debug, MU_DEBUG_TRACE0, "%s", "Checking sockaddr ");
debug_sockaddr (acl->debug, MU_DEBUG_TRACE0, r.sa, r.salen);
mu_debug_printf (acl->debug, MU_DEBUG_TRACE0, "\n");
mu_debug_log_begin ("Checking sockaddr ");
debug_sockaddr (r.sa, r.salen);
mu_debug_log_end ("");
}
r.idx = 0;
r.debug = acl->debug;
r.result = pres;
*r.result = mu_acl_result_undefined;
r.numbuf = r.portbuf = NULL;
......@@ -826,9 +795,9 @@ mu_acl_check_fd (mu_acl_t acl, int fd, mu_acl_result_t *pres)
if (getpeername (fd, (struct sockaddr *) &cs, &len) < 0)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR,
"Cannot obtain IP address of client: %s",
mu_strerror (errno));
mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
("Cannot obtain IP address of client: %s",
mu_strerror (errno)));
return MU_ERR_FAILURE;
}
......
......@@ -43,7 +43,6 @@ struct _mu_ip_server
int addrlen;
int fd;
int type;
mu_debug_t debug;
mu_acl_t acl;
mu_ip_server_conn_fp f_conn;
mu_ip_server_intr_fp f_intr;
......@@ -71,7 +70,6 @@ mu_ip_server_create (mu_ip_server_t *psrv, struct sockaddr *addr,
int addrlen, int type)
{
struct _mu_ip_server *srv;
mu_log_level_t level;
switch (type)
{
......@@ -95,12 +93,6 @@ mu_ip_server_create (mu_ip_server_t *psrv, struct sockaddr *addr,
memcpy (srv->addr, addr, addrlen);
srv->addrlen = addrlen;
srv->type = type;
level = mu_global_debug_level ("ip_server");
if (level)
{
mu_debug_create (&srv->debug, NULL);
mu_debug_set_level (srv->debug, level);
}
srv->fd = -1;
switch (type)
{
......@@ -138,25 +130,6 @@ mu_ip_server_destroy (mu_ip_server_t *psrv)
}
int
mu_ip_server_set_debug (mu_ip_server_t srv, mu_debug_t debug)
{
if (!srv)
return EINVAL;
mu_debug_destroy (&srv->debug, NULL);
srv->debug = debug;
return 0;
}
int
mu_ip_server_get_debug (mu_ip_server_t srv, mu_debug_t *pdebug)
{
if (!srv)
return EINVAL;
*pdebug = srv->debug;
return 0;
}
int
mu_ip_server_get_type (mu_ip_server_t srv, int *ptype)
{
if (!srv)
......@@ -274,12 +247,10 @@ mu_ip_server_open (mu_ip_server_t srv)
if (!srv || srv->fd != -1)
return EINVAL;
if (mu_debug_check_level (srv->debug, MU_DEBUG_TRACE0))
if (mu_debug_level_p (MU_DEBCAT_SERVER, MU_DEBUG_TRACE0))
{
char *p = mu_sockaddr_to_astr (srv->addr, srv->addrlen);
__MU_DEBUG2 (srv->debug, MU_DEBUG_TRACE0,
"opening server \"%s\" %s\n", IDENTSTR (srv),
p);
mu_debug_log ("opening server \"%s\" %s", IDENTSTR (srv), p);
free (p);
}
......@@ -287,8 +258,8 @@ mu_ip_server_open (mu_ip_server_t srv)
((srv->type == MU_IP_UDP) ? SOCK_DGRAM : SOCK_STREAM), 0);
if (fd == -1)
{
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: socket: %s\n", IDENTSTR (srv), mu_strerror (errno));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: socket: %s", IDENTSTR (srv), mu_strerror (errno)));
return errno;
}
......@@ -303,26 +274,26 @@ mu_ip_server_open (mu_ip_server_t srv)
{
if (errno != ENOENT)
{
MU_DEBUG3 (srv->debug, MU_DEBUG_ERROR,
_("%s: file %s exists but cannot be stat'd: %s"),
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: file %s exists but cannot be stat'd: %s",
IDENTSTR (srv),
s_un->sun_path,
mu_strerror (errno));
mu_strerror (errno)));
return EAGAIN;
}
}
else if (!S_ISSOCK (st.st_mode))
{
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
_("%s: file %s is not a socket"),
IDENTSTR (srv), s_un->sun_path);
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: file %s is not a socket",
IDENTSTR (srv), s_un->sun_path));
return EAGAIN;
}
else if (unlink (s_un->sun_path))
{
MU_DEBUG3 (srv->debug, MU_DEBUG_ERROR,
_("%s: cannot unlink file %s: %s"),
IDENTSTR (srv), s_un->sun_path, mu_strerror (errno));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: cannot unlink file %s: %s",
IDENTSTR (srv), s_un->sun_path, mu_strerror (errno)));
return EAGAIN;
}
}
......@@ -339,8 +310,8 @@ mu_ip_server_open (mu_ip_server_t srv)
if (bind (fd, srv->addr, srv->addrlen) == -1)
{
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: bind: %s\n", IDENTSTR (srv), mu_strerror (errno));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: bind: %s", IDENTSTR (srv), mu_strerror (errno)));
close (fd);
return errno;
}
......@@ -349,8 +320,8 @@ mu_ip_server_open (mu_ip_server_t srv)
{
if (listen (fd, srv->v.tcp_data.backlog) == -1)
{
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: listen: %s\n", IDENTSTR (srv), mu_strerror (errno));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: listen: %s", IDENTSTR (srv), mu_strerror (errno)));
close (fd);
return errno;
}
......@@ -365,12 +336,10 @@ mu_ip_server_shutdown (mu_ip_server_t srv)
{
if (!srv || srv->fd != -1)
return EINVAL;
if (mu_debug_check_level (srv->debug, MU_DEBUG_TRACE0))
if (mu_debug_level_p (MU_DEBCAT_SERVER, MU_DEBUG_TRACE0))
{
char *p = mu_sockaddr_to_astr (srv->addr, srv->addrlen);
__MU_DEBUG2 (srv->debug, MU_DEBUG_TRACE0,
"closing server \"%s\" %s\n", IDENTSTR (srv),
p);
mu_debug_log ("closing server \"%s\" %s", IDENTSTR (srv), p);
free (p);
}
close (srv->fd);
......@@ -411,9 +380,9 @@ mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data)
mu_acl_result_t res;
int rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res);
if (rc)
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: mu_acl_check_sockaddr: %s\n",
IDENTSTR (srv), strerror (rc));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: mu_acl_check_sockaddr: %s",
IDENTSTR (srv), strerror (rc)));
if (res == mu_acl_result_deny)
{
char *p = mu_sockaddr_to_astr (&client.sa, size);
......@@ -477,9 +446,9 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data)
0, &client.sa, &salen);
if (size < 0)
{
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: recvfrom: %s",
IDENTSTR (srv), strerror (errno));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: recvfrom: %s",
IDENTSTR (srv), strerror (errno)));
return MU_ERR_FAILURE;
}
srv->v.udp_data.rdsize = size;
......@@ -489,9 +458,9 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data)
mu_acl_result_t res;
int rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res);
if (rc)
MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
"%s: mu_acl_check_sockaddr: %s\n",
IDENTSTR (srv), strerror (rc));
mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR,
("%s: mu_acl_check_sockaddr: %s\n",
IDENTSTR (srv), strerror (rc)));
if (res == mu_acl_result_deny)
{
char *p = mu_sockaddr_to_astr (srv->addr, srv->addrlen);
......
......@@ -758,7 +758,7 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
unsigned short
get_port (mu_debug_t debug, const char *p)
get_port (const char *p)
{
if (p)
{
......@@ -768,8 +768,7 @@ get_port (mu_debug_t debug, const char *p)
{
if (n > USHRT_MAX)
{
mu_debug_printf (debug, MU_DIAG_ERROR,
_("invalid port number: %s\n"), p);
mu_error (_("invalid port number: %s"), p);
return 1;
}
......@@ -847,7 +846,7 @@ is_ip_addr (const char *arg)
}
int
_mu_m_server_parse_url (mu_debug_t debug, const char *arg, union m_sockaddr *s,
_mu_m_server_parse_url (const char *arg, union m_sockaddr *s,
int *psalen, struct sockaddr *defsa)
{
char *p;
......@@ -858,7 +857,7 @@ _mu_m_server_parse_url (mu_debug_t debug, const char *arg, union m_sockaddr *s,
s->s_sa.sa_family = AF_INET;
else if (get_family (&arg, &s->s_sa.sa_family))
{
mu_debug_printf (debug, MU_DIAG_ERROR, _("invalid family\n"));
mu_error (_("invalid family"));
return EINVAL;
}
......@@ -866,7 +865,7 @@ _mu_m_server_parse_url (mu_debug_t debug, const char *arg, union m_sockaddr *s,
{
case AF_INET:
*psalen = sizeof (s->s_in);
if ((n = get_port (debug, arg)))
if ((n = get_port (arg)))
{
s->s_in.sin_addr.s_addr = htonl (INADDR_ANY);
s->s_in.sin_port = htons (n);
......@@ -883,18 +882,16 @@ _mu_m_server_parse_url (mu_debug_t debug, const char *arg, union m_sockaddr *s,
s->s_in.sin_addr.s_addr = *(unsigned long *)hp->h_addr;
else
{
mu_debug_printf (debug, MU_DIAG_ERROR,
_("invalid IP address: %s\n"), arg);
mu_error (_("invalid IP address: %s"), arg);
return EINVAL;
}
}
if (p)
{
n = get_port (debug, p);
n = get_port (p);
if (!n)
{
mu_debug_printf (debug, MU_DIAG_ERROR,
_("invalid port number: %s\n"), p);
mu_error (_("invalid port number: %s"), p);
return EINVAL;
}
s->s_in.sin_port = n;
......@@ -903,8 +900,7 @@ _mu_m_server_parse_url (mu_debug_t debug, const char *arg, union m_sockaddr *s,
s->s_in.sin_port = ((struct sockaddr_in*)defsa)->sin_port;
else
{
mu_debug_printf (debug, MU_DIAG_ERROR,
_("missing port number\n"));
mu_error (_("missing port number"));
return EINVAL;
}
}
......@@ -931,10 +927,8 @@ mu_m_server_parse_url (mu_m_server_t msrv, char *arg,
int rc;
union m_sockaddr s;
int salen;
mu_debug_t debug;
mu_diag_get_debug (&debug);
rc = _mu_m_server_parse_url (debug, arg, &s, &salen, &msrv->defaddr.s.s_sa);
rc = _mu_m_server_parse_url (arg, &s, &salen, &msrv->defaddr.s.s_sa);
if (rc)
return rc;
if (sa)
......@@ -948,12 +942,11 @@ mu_m_server_parse_url (mu_m_server_t msrv, char *arg,
}
static int
server_block_begin (mu_debug_t debug, const char *arg, mu_m_server_t msrv,
void **pdata)
server_block_begin (const char *arg, mu_m_server_t msrv, void **pdata)
{
union m_sockaddr s;
int salen;
if (_mu_m_server_parse_url (debug, arg, &s, &salen, &msrv->defaddr.s.s_sa))
if (_mu_m_server_parse_url (arg, &s, &salen, &msrv->defaddr.s.s_sa))
return 1;
*pdata = add_server (msrv, &s.s_sa, salen, msrv->deftype);
return 0;
......@@ -973,7 +966,7 @@ server_section_parser (enum mu_cfg_section_stage stage,
if (node->label == NULL || node->label->type != MU_CFG_STRING)
return 1;
/* FIXME: should not modify 2nd arg, or it should not be const */
return server_block_begin (tree->debug, node->label->v.string,
return server_block_begin (node->label->v.string,
*section_data, section_data);
}
break;
......@@ -990,11 +983,11 @@ server_section_parser (enum mu_cfg_section_stage stage,
}
static int
_cb_daemon_mode (mu_debug_t debug, void *data, mu_config_value_t *val)
_cb_daemon_mode (void *data, mu_config_value_t *val)
{
int *pmode = data;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (strcmp (val->v.string, "inetd") == 0
|| strcmp (val->v.string, "interactive") == 0)
......@@ -1003,21 +996,21 @@ _cb_daemon_mode (mu_debug_t debug, void *data, mu_config_value_t *val)
*pmode = MODE_DAEMON;
else
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("unknown daemon mode"));
mu_error (_("unknown daemon mode"));
return 1;
}
return 0;
}
static int
_cb_port (mu_debug_t debug, void *data, mu_config_value_t *val)
_cb_port (void *data, mu_config_value_t *val)
{
struct m_default_address *ap = data;
unsigned short num;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
num = get_port (debug, val->v.string);
num = get_port (val->v.string);
if (!num)
return 1;
ap->s.s_in.sin_family = AF_INET;
......
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2010 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, see
# <http://www.gnu.org/licenses/>.
noinst_LTLIBRARIES = libstdstream.la
libstdstream_la_SOURCES = \
basestr.c\
dbgstream.c\
strerr.c
INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <mailutils/types.h>
#include <mailutils/errno.h>
#include <mailutils/log.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
mu_stream_t mu_strin;
mu_stream_t mu_strout;
mu_stream_t mu_strerr;
void
mu_stdstream_setup ()
{
int rc;
int fd;
/* If the streams are already open, close them */
mu_stream_destroy (&mu_strin);
mu_stream_destroy (&mu_strout);
mu_stream_destroy (&mu_strerr);
/* Ensure that first 3 descriptors are open in proper mode */
fd = open ("/dev/null", O_WRONLY);
switch (fd)
{
case 2:
/* keep it open */;
break;
case 1:
/* keep it open and try 0 */
fd = open ("/dev/null", O_RDONLY);
if (fd != 0)
close (fd);
break;
default:
close (fd);
break;
}
/* Create the corresponding streams */
rc = mu_stdio_stream_create (&mu_strin, MU_STDIN_FD, 0);
if (rc)
{
fprintf (stderr, "mu_stdio_stream_create(%d): %s\n",
MU_STDIN_FD, mu_strerror (rc));
abort ();
}
rc = mu_stdio_stream_create (&mu_strout, MU_STDOUT_FD, 0);
if (rc)
{
fprintf (stderr, "mu_stdio_stream_create(%d): %s\n",
MU_STDOUT_FD, mu_strerror (rc));
abort ();
}
if (mu_stdstream_strerr_create (&mu_strerr, MU_STRERR_STDERR, 0, 0,
mu_program_name, NULL))
abort ();
/* FIXME: atexit (flushall) */
}
int
mu_printf (const char *fmt, ...)
{
int rc;
va_list ap;
va_start (ap, fmt);
rc = mu_stream_vprintf (mu_strout, fmt, ap);
va_end (ap);
return rc;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/types.h>
#include <mailutils/stream.h>
#include <mailutils/log.h>
#include <mailutils/stdstream.h>
int
mu_dbgstream_create (mu_stream_t *pstr, int severity)
{
int rc;
mu_transport_t trans[2];
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_GET_TRANSPORT, trans);
if (rc)
return rc;
rc = mu_log_stream_create (pstr, (mu_stream_t) trans[0]);
if (rc)
return rc;
mu_stream_ioctl (*pstr, MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
return 0;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <mailutils/types.h>
#include <mailutils/nls.h>
#include <mailutils/io.h>
#include <mailutils/errno.h>
#include <mailutils/log.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
#include <mailutils/filter.h>
#include <mailutils/syslog.h>
int
mu_stdstream_strerr_create (mu_stream_t *plogger, int type, int facility,
int priority, const char *tag,
const char *fname MU_ARG_UNUSED)
{
int rc;
mu_stream_t transport;
switch (type)
{
case MU_STRERR_STDERR:
{
mu_stream_t str;
rc = mu_stdio_stream_create (&str, MU_STDERR_FD, 0);
if (rc)
{
fprintf (stderr, _("%s: cannot open error stream: %s\n"),
tag, mu_strerror (rc));
return MU_ERR_FAILURE;
}
if (!tag)
transport = str;
else
{
char *fltargs[3] = { "INLINE-COMMENT", };
mu_asprintf (&fltargs[1], "%s: ", tag);
fltargs[2] = NULL;
rc = mu_filter_create_args (&transport, str,
"INLINE-COMMENT",
2, (const char**)fltargs,
MU_FILTER_ENCODE, MU_STREAM_WRITE);
mu_stream_unref (str);
free (fltargs[1]);
if (rc)
{
fprintf (stderr,
_("%s: cannot open output filter stream: %s"),
tag, mu_strerror (rc));
return MU_ERR_FAILURE;
}
mu_stream_set_buffer (transport, mu_buffer_line, 0);
}
}
break;
case MU_STRERR_SYSLOG:
openlog (tag, LOG_PID, facility);
rc = mu_syslog_stream_create (&transport, priority);
if (rc)
{
fprintf (stderr, _("%s: cannot create syslog stream: %s\n"),
tag, mu_strerror (rc));
return MU_ERR_FAILURE;
}
break;
default:
fprintf (stderr, _("%s: cannot create error stream: %s\n"),
tag, mu_strerror (EINVAL));
return EINVAL;
}
rc = mu_log_stream_create (plogger, transport);
mu_stream_unref (transport);
if (rc)
{
fprintf (stderr, _("%s: cannot open logger stream: %s\n"),
tag , mu_strerror (rc));
return MU_ERR_FAILURE;
}
return 0;
}
int
mu_stdstream_strerr_setup (int type)
{
mu_stream_t str;
if (mu_stdstream_strerr_create (&str, type,
mu_log_facility, LOG_ERR,
mu_log_tag, NULL) == 0)
{
if (mu_log_print_severity)
{
int mode = MU_LOGMODE_SEVERITY;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
}
mu_stream_destroy (&mu_strerr);
mu_strerr = str;
}
return 0;
}
......@@ -18,10 +18,10 @@
noinst_LTLIBRARIES = libstream.la
libstream_la_SOURCES = \
dbgstream.c\
file_stream.c\
fltstream.c\
iostream.c\
logstream.c\
mapfile_stream.c\
memory_stream.c\
message_stream.c\
......@@ -35,6 +35,7 @@ libstream_la_SOURCES = \
stream_vprintf.c\
streamcpy.c\
streamref.c\
syslogstream.c\
tcp.c\
temp_file_stream.c\
xscript-stream.c
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2004,
2005, 2006, 2007, 2008, 2009, 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mailutils/types.h>
#include <mailutils/alloc.h>
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/stream.h>
#include <mailutils/sys/stream.h>
#include <mailutils/sys/dbgstream.h>
#include <mailutils/debug.h>
static int
_dbg_write (struct _mu_stream *str, const char *buf, size_t size,
size_t *pnwrite)
{
struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str;
if (pnwrite)
*pnwrite = size;
while (size > 0 && (buf[size-1] == '\n' || buf[size-1] == '\r'))
size--;
if (size)
mu_debug_printf (sp->debug, sp->level, "%.*s\n", size, buf);
return 0;
}
static int
_dbg_flush (struct _mu_stream *str)
{
struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str;
mu_debug_printf (sp->debug, sp->level, "\n");
return 0;
}
static void
_dbg_done (struct _mu_stream *str)
{
struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str;
if (str->flags & MU_STREAM_AUTOCLOSE)
mu_debug_destroy (&sp->debug, NULL);
}
int
mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, mu_log_level_t level,
int flags)
{
int rc;
mu_stream_t stream;
struct _mu_dbgstream *sp;
sp = (struct _mu_dbgstream *)
_mu_stream_create (sizeof (*sp), MU_STREAM_WRITE |
(flags & MU_STREAM_AUTOCLOSE));
if (!sp)
return ENOMEM;
sp->stream.write = _dbg_write;
sp->stream.flush = _dbg_flush;
sp->stream.done = _dbg_done;
sp->debug = debug;
sp->level = level;
stream = (mu_stream_t) sp;
mu_stream_set_buffer (stream, mu_buffer_line, 0);
rc = mu_stream_open (stream);
if (rc)
mu_stream_destroy (&stream);
else
*pref = stream;
return rc;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mailutils/types.h>
#include <mailutils/errno.h>
#include <mailutils/cctype.h>
#include <mailutils/log.h>
#include <mailutils/nls.h>
#include <mailutils/stream.h>
#include <mailutils/sys/logstream.h>
char *_mu_severity_str[] = {
N_("debug"),
N_("info"),
N_("notice"),
N_("warning"),
N_("error"),
N_("crit"),
N_("alert"),
N_("emerg"),
};
int _mu_severity_num = MU_ARRAY_SIZE (_mu_severity_str);
static int
_locus_set_file (struct mu_locus *loc, const char *file, size_t len)
{
free (loc->mu_file);
if (file)
{
loc->mu_file = malloc (len + 1);
if (!loc->mu_file)
return ENOMEM;
memcpy (loc->mu_file, file, len);
loc->mu_file[len] = 0;
}
else
loc->mu_file = NULL;
return 0;
}
#define _locus_set_line(loc, line) ((loc)->mu_line = line)
#define _locus_set_col(loc, col) ((loc)->mu_col = col)
static int
_log_write (struct _mu_stream *str, const char *buf, size_t size,
size_t *pnwrite)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
unsigned severity = sp->severity;
int logmode = sp->logmode;
struct mu_locus loc = sp->locus;
const char *fname = NULL;
unsigned flen = 0;
int save_locus = 0;
int rc;
int escape_error = 0;
#define NEXT do { buf++; size--; if (size == 0) return EINVAL; } while (0)
#define READNUM(n) do { \
unsigned __x = 0; \
if (*buf != '<') \
return EINVAL; \
NEXT; \
while (*buf != '>') \
{ \
if (!mu_isdigit (*buf)) \
return EINVAL; \
__x = __x * 10 + (*buf - '0'); \
NEXT; \
} \
NEXT; \
n = __x; \
} while (0)
/* Tell them we've consumed everything */
*pnwrite = size;
/* Process escapes */
while (!escape_error && *buf == '\033')
{
int code;
unsigned n;
NEXT;
code = *buf;
NEXT;
switch (code)
{
case 'S':
/* Save locus */
save_locus = 1;
break;
case 's':
/* Severity code in decimal (single digit) */
if (*buf == '<')
READNUM (severity);
else if (mu_isdigit (*buf))
{
severity = *buf - '0';
NEXT;
}
else
return EINVAL;
break;
case 'O':
/* Flags on. Followed by a bitmask of MU_LOGMODE_*, in decimal */
READNUM (n);
logmode |= n;
break;
case 'X':
/* Flags off. Followed by a bitmask of MU_LOGMODE_*, in decimal */
READNUM (n);
logmode &= ~n;
break;
case 'l':
/* Input line (decimal) */
READNUM (n);
_locus_set_line (&loc, n);
break;
case 'c':
/* Column in input line (decimal) */
READNUM (n);
_locus_set_col (&loc, n);
break;
case 'f':
/* File name. Format: <N>S */
READNUM (flen);
fname = buf;
buf += flen;
size -= flen;
break;
default:
buf -= 2;
size += 2;
escape_error = 1;
}
}
if (severity >= _mu_severity_num)
severity = MU_LOG_EMERG;
mu_stream_ioctl (sp->transport, MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
if (logmode & MU_LOGMODE_LOCUS)
{
if (fname)
_locus_set_file (&loc, fname, flen);
if (loc.mu_file)
{
mu_stream_write (sp->transport, loc.mu_file,
strlen (loc.mu_file), NULL);
mu_stream_write (sp->transport, ":", 1, NULL);
if (loc.mu_line)
mu_stream_printf (sp->transport, "%u", loc.mu_line);
mu_stream_write (sp->transport, ":", 1, NULL);
if (loc.mu_col)
mu_stream_printf (sp->transport, "%u:", loc.mu_col);
mu_stream_write (sp->transport, " ", 1, NULL);
}
}
if (save_locus)
{
_locus_set_file (&sp->locus, loc.mu_file, strlen (loc.mu_file));
_locus_set_line (&sp->locus, loc.mu_line);
_locus_set_col (&sp->locus, loc.mu_col);
}
if (fname)
free (loc.mu_file);
if (logmode & MU_LOGMODE_SEVERITY)
{
char *s = gettext (_mu_severity_str[severity]);
rc = mu_stream_write (sp->transport, s, strlen (s), NULL);
if (rc)
return rc;
mu_stream_write (sp->transport, ": ", 2, NULL);
}
return mu_stream_write (sp->transport, buf, size, NULL);
}
static int
_log_flush (struct _mu_stream *str)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
return mu_stream_flush (sp->transport);
}
static void
_log_done (struct _mu_stream *str)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
if (str->flags & MU_STREAM_AUTOCLOSE)
mu_stream_destroy (&sp->transport);
}
static int
_log_close (struct _mu_stream *str)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
if (str->flags & MU_STREAM_AUTOCLOSE)
return mu_stream_close (sp->transport);
return 0;
}
static int
_log_setbuf_hook (mu_stream_t str, enum mu_buffer_type type, size_t size)
{
if (type != mu_buffer_line)
return EACCES;
return 0;
}
static int
_log_ctl (struct _mu_stream *str, int op, void *arg)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
mu_transport_t *ptrans;
switch (op)
{
case MU_IOCTL_GET_TRANSPORT:
if (!arg)
return EINVAL;
ptrans = arg;
ptrans[0] = (mu_transport_t) sp->transport;
ptrans[1] = NULL;
break;
case MU_IOCTL_SET_TRANSPORT:
if (!arg)
return EINVAL;
ptrans = arg;
if (ptrans[0])
sp->transport = (mu_stream_t) ptrans[0];
break;
case MU_IOCTL_LOGSTREAM_GET_SEVERITY:
if (!arg)
return EINVAL;
*(unsigned*)arg = sp->severity;
break;
case MU_IOCTL_LOGSTREAM_SET_SEVERITY:
if (!arg)
return EINVAL;
if (*(unsigned*)arg >= _mu_severity_num)
return EINVAL;
sp->severity = *(unsigned*)arg;
break;
case MU_IOCTL_LOGSTREAM_GET_MODE:
if (!arg)
return EINVAL;
*(int*)arg = sp->logmode;
break;
case MU_IOCTL_LOGSTREAM_SET_MODE:
if (!arg)
return EINVAL;
sp->logmode = *(int*)arg;
break;
case MU_IOCTL_LOGSTREAM_GET_LOCUS:
{
struct mu_locus *ploc = arg;
if (!arg)
return EINVAL;
if (sp->locus.mu_file)
{
ploc->mu_file = strdup (sp->locus.mu_file);
if (!ploc->mu_file)
return ENOMEM;
}
else
ploc->mu_file = NULL;
ploc->mu_line = sp->locus.mu_line;
ploc->mu_col = sp->locus.mu_col;
break;
}
case MU_IOCTL_LOGSTREAM_SET_LOCUS:
{
struct mu_locus *ploc = arg;
if (!arg)
{
free (sp->locus.mu_file);
sp->locus.mu_file = NULL;
sp->locus.mu_line = 0;
sp->locus.mu_col = 0;
}
else
{
if (ploc->mu_file)
_locus_set_file (&sp->locus, ploc->mu_file,
strlen (ploc->mu_file));
if (ploc->mu_line)
_locus_set_line (&sp->locus, ploc->mu_line);
if (ploc->mu_col)
_locus_set_col (&sp->locus, ploc->mu_col);
}
break;
}
case MU_LOGSTREAM_ADVANCE_LOCUS_LINE:
if (!arg)
sp->locus.mu_line++;
else
sp->locus.mu_line += *(int*)arg;
break;
case MU_LOGSTREAM_ADVANCE_LOCUS_COL:
if (!arg)
sp->locus.mu_col++;
else
sp->locus.mu_col += *(int*)arg;
break;
default:
return ENOSYS;
}
return 0;
}
int
mu_log_stream_create (mu_stream_t *pstr, mu_stream_t transport)
{
struct _mu_log_stream *sp;
mu_stream_t stream;
int rc;
sp = (struct _mu_log_stream *)
_mu_stream_create (sizeof (*sp), MU_STREAM_WRITE);
if (!sp)
return ENOMEM;
sp->base.write = _log_write;
sp->base.flush = _log_flush;
sp->base.close = _log_close;
sp->base.done = _log_done;
sp->base.setbuf_hook = _log_setbuf_hook;
sp->base.ctl = _log_ctl;
sp->transport = transport;
mu_stream_ref (transport);
sp->severity = MU_LOG_ERROR;
sp->logmode = 0;
stream = (mu_stream_t) sp;
mu_stream_set_buffer (stream, mu_buffer_line, 0);
rc = mu_stream_open (stream);
if (rc)
mu_stream_destroy (&stream);
else
*pstr = stream;
return rc;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 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, 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <syslog.h>
#include <errno.h>
#include <string.h>
#include <mailutils/errno.h>
#include <mailutils/stream.h>
#include <mailutils/sys/syslogstream.h>
static int
_syslog_stream_write (struct _mu_stream *stream, const char *buf,
size_t size, size_t *pret)
{
struct _mu_syslog_stream *lsp = (struct _mu_syslog_stream *)stream;
*pret = size;
if (size > 0 && buf[size-1] == '\n')
size--;
if (size == 0)
return 0;
syslog (lsp->prio, "%*.*s", (int) size, (int) size, buf);
return 0;
}
static int sev2prio[] = {
LOG_DEBUG,
LOG_INFO,
LOG_NOTICE,
LOG_WARNING,
LOG_ERR,
LOG_CRIT,
LOG_ALERT,
LOG_EMERG
};
static int
_syslog_ctl (struct _mu_stream *str, int op, void *arg)
{
struct _mu_syslog_stream *sp = (struct _mu_syslog_stream *)str;
unsigned n;
switch (op)
{
case MU_IOCTL_LOGSTREAM_GET_SEVERITY:
if (!arg)
return EINVAL;
for (n = 0; n < MU_ARRAY_SIZE (sev2prio); n++)
if (sev2prio[n] == sp->prio)
{
*(int*)arg = n;
break;
}
return MU_ERR_FAILURE;
case MU_IOCTL_LOGSTREAM_SET_SEVERITY:
if (!arg)
return EINVAL;
n = *(unsigned*)arg;
if (n < MU_ARRAY_SIZE (sev2prio))
sp->prio = sev2prio[n];
else
return EINVAL;
break;
default:
return ENOSYS;
}
return 0;
}
int
_syslog_setbuf_hook (mu_stream_t str, enum mu_buffer_type type, size_t size)
{
if (type != mu_buffer_line)
return EACCES;
return 0;
}
int
mu_syslog_stream_create (mu_stream_t *pstream, int prio)
{
struct _mu_syslog_stream *str =
(struct _mu_syslog_stream *) _mu_stream_create (sizeof (*str),
MU_STREAM_WRITE);
if (!str)
return ENOMEM;
str->prio = prio;
str->base.write = _syslog_stream_write;
str->base.ctl = _syslog_ctl;
str->base.setbuf_hook = _syslog_setbuf_hook;
*pstream = (mu_stream_t) str;
mu_stream_set_buffer (*pstream, mu_buffer_line, 0);
return 0;
}
This diff is collapsed. Click to expand it.