Commit 6bd4a8b2 6bd4a8b2ed555986e20ad09e11d6a95470a9be71 by Sergey Poznyakoff

* include/mailutils/argp.h (mu_argp_set_config_param): New

function.
* include/mailutils/cfg.h (mu_cfg_time): New value
(struct mu_cfg_section): Rewamp using lists.
(enum mu_cfg_cont_type, struct mu_cfg_cont): New types.
(mu_config_create_container, mu_config_clone_container)
(mu_config_destroy_container): New functions.
(mu_parse_config): New function.
* include/mailutils/mu_auth.h (mu_authentication_clear_list)
(mu_authorization_clear_list): New functions.
* mailbox/cfg_lexer.c: Add missing includes
(mu_config_create_container, mu_config_clone_container)
(mu_config_destroy_container): New functions.
(mu_parse_config): New function.
(_mu_config_register_section): New function.
(mu_config_register_section): New function.
(_mu_parse_config): Fully implement system-wide/per-user
configuration semantics.
(mu_parse_config): Take two more arguments.
* mailbox/cfg_parser.h: Remove automatically generated file.
* mailbox/cfg_parser.y (find_container): New function
(find_subsection,find_param): Rewrite using find_container
(parse_param): Implement new data type mu_cfg_time (time_t value).
(_scan_tree_helper): Complain about unknown sections only if
MU_CONFIG_VERBOSE environment variable is set.
* mailbox/mu_argp.c (assign_string): Bugfix.
(mu_argp_set_config_param): New function.
(mu_argp_parse): Remove eventual `lt-' prefix from program names.
* mailbox/mu_auth.c: New options --clear-authorization and
--clear-authentication.
(mu_authorization_clear_list,mu_authentication_clear_list): New
functions.

* include/mailutils/refcount.h (struct _mu_refcount): Move ro
refcount.c
(mu_refcount_inc,mu_refcount_dec): Change return value.
(mu_refcount_value): New function.
* mailbox/refcount.c (struct _mu_refcount): Moved from refcount.h
(mu_refcount_value): New function.
(mu_refcount_create,mu_refcount_destroy,mu_refcount_inc)
(mu_refcount_dec): Fix monitor usage.
(mu_refcount_inc,mu_refcount_dec): Fix return type.

* mailbox/Makefile.am (libmailutils_la_SOURCES): Add refcount.c
* dotlock/dotlock.c, imap4d/imap4d.c, mail.local/main.c,
mail.remote/mail.remote.c, mimeview/mimeview.c,
movemail/movemail.c, pop3d/pop3d.c, pop3d/signal.c,
readmsg/readmsg.c, sieve/sieve.c: Implement new configuration.

* testsuite/lib/mailutils.exp: Set MU_CONFIG_FLAVOR envar to
`none' to avoid reading configuration files.
1 parent 6c26e9b6
2007-11-08 Sergey Poznyakoff <gray@gnu.org.ua>
* include/mailutils/argp.h (mu_argp_set_config_param): New
function.
* include/mailutils/cfg.h (mu_cfg_time): New value
(struct mu_cfg_section): Rewamp using lists.
(enum mu_cfg_cont_type, struct mu_cfg_cont): New types.
(mu_config_create_container, mu_config_clone_container)
(mu_config_destroy_container): New functions.
(mu_parse_config): New function.
* include/mailutils/mu_auth.h (mu_authentication_clear_list)
(mu_authorization_clear_list): New functions.
* mailbox/cfg_lexer.c: Add missing includes
(mu_config_create_container, mu_config_clone_container)
(mu_config_destroy_container): New functions.
(mu_parse_config): New function.
(_mu_config_register_section): New function.
(mu_config_register_section): New function.
(_mu_parse_config): Fully implement system-wide/per-user
configuration semantics.
(mu_parse_config): Take two more arguments.
* mailbox/cfg_parser.h: Remove automatically generated file.
* mailbox/cfg_parser.y (find_container): New function
(find_subsection,find_param): Rewrite using find_container
(parse_param): Implement new data type mu_cfg_time (time_t value).
(_scan_tree_helper): Complain about unknown sections only if
MU_CONFIG_VERBOSE environment variable is set.
* mailbox/mu_argp.c (assign_string): Bugfix.
(mu_argp_set_config_param): New function.
(mu_argp_parse): Remove eventual `lt-' prefix from program names.
* mailbox/mu_auth.c: New options --clear-authorization and
--clear-authentication.
(mu_authorization_clear_list,mu_authentication_clear_list): New
functions.
* include/mailutils/refcount.h (struct _mu_refcount): Move ro
refcount.c
(mu_refcount_inc,mu_refcount_dec): Change return value.
(mu_refcount_value): New function.
* mailbox/refcount.c (struct _mu_refcount): Moved from refcount.h
(mu_refcount_value): New function.
(mu_refcount_create,mu_refcount_destroy,mu_refcount_inc)
(mu_refcount_dec): Fix monitor usage.
(mu_refcount_inc,mu_refcount_dec): Fix return type.
* mailbox/Makefile.am (libmailutils_la_SOURCES): Add refcount.c
* dotlock/dotlock.c, imap4d/imap4d.c, mail.local/main.c,
mail.remote/mail.remote.c, mimeview/mimeview.c,
movemail/movemail.c, pop3d/pop3d.c, pop3d/signal.c,
readmsg/readmsg.c, sieve/sieve.c: Implement new configuration.
* testsuite/lib/mailutils.exp: Set MU_CONFIG_FLAVOR envar to
`none' to avoid reading configuration files.
2007-11-06 Sergey Poznyakoff <gray@gnu.org.ua>
* mailbox/message.c (message_stream_size): Bugfix.
......
......@@ -70,7 +70,7 @@ static const char *file;
static int unlock;
static int flags;
static int retries;
static int force;
static time_t force;
static int debug;
static error_t
......@@ -102,9 +102,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
force = atoi (arg);
if (force <= 0)
argp_error (state, _("MINUTES must be greater than 0"));
force *= 60;
}
flags |= MU_LOCKER_TIME;
break;
case ARGP_KEY_ARG:
......@@ -122,6 +120,21 @@ parse_opt (int key, char *arg, struct argp_state *state)
return 0;
}
struct mu_cfg_param dotlock_cfg_param[] = {
{ "force", mu_cfg_time, &force },
{ "retry", mu_cfg_int, &retries },
{ "debug", mu_cfg_bool, &debug },
{ NULL }
};
const char *dotlock_capa[] = {
"license",
NULL
};
int
main (int argc, char *argv[])
{
......@@ -140,8 +153,15 @@ main (int argc, char *argv[])
mu_argp_init (program_version, NULL);
argp_err_exit_status = MU_DL_EX_ERROR;
argp_parse (&argp, argc, argv, 0, NULL, NULL);
mu_argp_set_config_param (dotlock_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, dotlock_capa, NULL, NULL);
if (force)
{
force *= 60;
flags |= MU_LOCKER_TIME;
}
if ((err = mu_locker_create (&locker, file, flags)))
{
if (debug)
......
......@@ -204,7 +204,7 @@ main (int argc, char **argv)
#ifdef WITH_GSASL
mu_gsasl_init_argp ();
#endif
mu_config_register_plain_section (NULL, NULL, imap4d_cfg_param);
mu_argp_set_config_param (imap4d_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param);
if (login_disabled)
......
......@@ -60,7 +60,8 @@ extern int mu_register_capa (const char *name, struct argp_child *child,
extern void mu_print_options (void);
extern const char *mu_check_option (char *name);
extern void mu_argp_set_config_param (struct mu_cfg_param *);
#ifdef __cplusplus
}
#endif
......
......@@ -98,6 +98,7 @@ enum mu_cfg_param_data_type
mu_cfg_ulong,
mu_cfg_size,
mu_cfg_off,
mu_cfg_time,
mu_cfg_bool,
mu_cfg_ipv4,
mu_cfg_cidr,
......@@ -130,8 +131,26 @@ struct mu_cfg_section
const char *ident;
mu_cfg_section_fp parser;
void *data;
struct mu_cfg_section *subsec;
struct mu_cfg_param *param;
mu_list_t /* of mu_cfg_cont/mu_cfg_section */ subsec;
mu_list_t /* of mu_cfg_cont/mu_cfg_param */ param;
};
enum mu_cfg_cont_type
{
mu_cfg_cont_section,
mu_cfg_cont_param
};
struct mu_cfg_cont
{
enum mu_cfg_cont_type type;
mu_refcount_t refcount;
union
{
const char *ident;
struct mu_cfg_section section;
struct mu_cfg_param param;
} v;
};
typedef struct mu_cfg_cidr mu_cfg_cidr_t;
......@@ -142,6 +161,11 @@ struct mu_cfg_cidr
unsigned long mask;
};
int mu_config_create_container (struct mu_cfg_cont **pcont,
enum mu_cfg_cont_type type);
int mu_config_clone_container (struct mu_cfg_cont *cont);
void mu_config_destroy_container (struct mu_cfg_cont **pcont);
int mu_cfg_scan_tree (mu_cfg_node_t *node,
struct mu_cfg_section *sections,
void *data, mu_cfg_perror_t perror,
......@@ -159,4 +183,7 @@ int mu_config_register_plain_section (const char *parent_path,
const char *ident,
struct mu_cfg_param *params);
int mu_parse_config (char *file, char *progname,
struct mu_cfg_param *progparam, int global);
#endif
......
......@@ -103,6 +103,8 @@ extern void mu_auth_register_module (struct mu_auth_module *mod);
extern void mu_authorization_add_module_list (const char *modlist);
extern void mu_authentication_add_module_list (const char *modlist);
extern void mu_authentication_clear_list (void);
extern void mu_authorization_clear_list (void);
extern void mu_auth_init (void);
extern int mu_auth_data_alloc (struct mu_auth_data **ptr,
......
......@@ -26,17 +26,11 @@
extern "C" {
#endif
/* FIXME: Declaration should be hidden in mailutils/sys/refcount.h */
struct _mu_refcount
{
unsigned int ref;
mu_monitor_t lock;
};
extern int mu_refcount_create (mu_refcount_t *);
extern void mu_refcount_destroy (mu_refcount_t *);
extern int mu_refcount_inc (mu_refcount_t);
extern int mu_refcount_dec (mu_refcount_t);
extern unsigned mu_refcount_value (mu_refcount_t);
extern unsigned mu_refcount_inc (mu_refcount_t);
extern unsigned mu_refcount_dec (mu_refcount_t);
#ifdef __cplusplus
}
......
......@@ -128,6 +128,52 @@ char *saved_envelope; /* A hack to spare mu_envelope_ calls */
#define D_DEFAULT "9s"
static void
set_debug_flags (const mu_cfg_locus_t *locus, const char *arg)
{
for (; *arg; arg++);
{
switch (*arg)
{
case 'g':
#ifdef WITH_GUILE
debug_guile = 1;
#endif
break;
case 't':
sieve_debug_flags |= MU_SIEVE_DEBUG_TRACE;
break;
case 'i':
sieve_debug_flags |= MU_SIEVE_DEBUG_INSTR;
break;
case 'l':
sieve_enable_log = 1;
break;
case 'T':
debug_flags |= MU_DEBUG_TRACE;
break;
case 'P':
debug_flags |= MU_DEBUG_PROT;
break;
default:
if (isdigit (*arg))
debug_level = *arg - '0';
else if (locus)
mu_error (_("%s:%d: %c is not a valid debug flag"),
locus->file, locus->line, *arg);
else
mu_error (_("%c is not a valid debug flag"), *arg);
break;
}
}
}
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
......@@ -176,47 +222,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
break;
case 'x':
do
{
if (!arg)
arg = D_DEFAULT;
switch (*arg)
{
case 'g':
#ifdef WITH_GUILE
debug_guile = 1;
#endif
break;
case 't':
sieve_debug_flags |= MU_SIEVE_DEBUG_TRACE;
break;
case 'i':
sieve_debug_flags |= MU_SIEVE_DEBUG_INSTR;
break;
case 'l':
sieve_enable_log = 1;
break;
case 'T':
debug_flags |= MU_DEBUG_TRACE;
break;
case 'P':
debug_flags |= MU_DEBUG_PROT;
break;
default:
if (isdigit (*arg))
debug_level = *arg - '0';
else
argp_error (state, _("%c is not a valid debug flag"), *arg);
break;
}
}
while (*++arg);
if (!arg)
arg = D_DEFAULT;
set_debug_flags (NULL, arg);
break;
default:
......@@ -228,6 +236,34 @@ parse_opt (int key, char *arg, struct argp_state *state)
return 0;
}
static int
cb_debug (mu_cfg_locus_t *locus, void *data, char *arg)
{
set_debug_flags (locus, arg);
return 0;
}
struct mu_cfg_param mail_local_cfg_param[] = {
{ "ex-multiple-delivery-success", mu_cfg_bool, &multiple_delivery },
{ "ex-quota-tempfail", mu_cfg_bool, &ex_quota_tempfail },
{ "from", mu_cfg_string, &from },
#ifdef USE_DBM
{ "quota-db", mu_cfg_string, &quotadbname },
#endif
#ifdef USE_SQL
{ "quota-query", mu_cfg_string, &quota_query },
#endif
{ "sieve", mu_cfg_string, &sieve_pattern },
{ "message-id-header", mu_cfg_string, &message_id_header },
#ifdef WITH_GUILE
{ "source", mu_cfg_string, &progfile_pattern },
#endif
{ "debug", mu_cfg_callback, NULL, cb_debug },
{ NULL }
};
static int
_mu_debug_printer (mu_debug_t unused, size_t level, const char *fmt,
......@@ -246,7 +282,8 @@ _sieve_debug_printer (void *unused, const char *fmt, va_list ap)
static void
_sieve_action_log (void *user_name,
const mu_sieve_locus_t *locus, size_t msgno, mu_message_t msg,
const mu_sieve_locus_t *locus, size_t msgno,
mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
char *text = NULL;
......@@ -334,6 +371,7 @@ main (int argc, char *argv[])
mu_argp_init (program_version, NULL);
mu_sieve_argp_init ();
/* Parse command line */
mu_argp_set_config_param (mail_local_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, NULL);
uid = getuid ();
......
......@@ -119,6 +119,15 @@ static struct argp argp = {
doc,
};
struct mu_cfg_param mail_remote_cfg_param[] = {
{ "from", mu_cfg_string, &optfrom },
{ "read-recipients", mu_cfg_string, &read_recipients },
{ "debug", mu_cfg_int, &optdebug },
{ NULL}
};
static const char *capa[] = {
"auth",
"common",
......@@ -162,6 +171,7 @@ main (int argc, char **argv)
MU_AUTH_REGISTER_ALL_MODULES();
mu_argp_init (program_version, NULL);
mu_argp_set_config_param (mail_remote_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, capa, &optind, NULL);
if (optfrom)
......
......@@ -84,6 +84,7 @@ parse822.c \
parsedate.c \
property.c \
registrar.c \
refcount.c \
rfc2047.c \
socket_stream.c \
stream.c \
......
......@@ -26,6 +26,8 @@
#include <mailutils/cfg.h>
#include <mailutils/errno.h>
#include <mailutils/error.h>
#include <mailutils/list.h>
#include <mailutils/iterator.h>
static mu_cfg_node_t *parse_tree;
mu_cfg_locus_t mu_cfg_locus;
......@@ -487,21 +489,43 @@ struct scan_tree_data
int error;
};
static struct mu_cfg_cont *
find_container (mu_list_t list, const char *ident, size_t len)
{
mu_iterator_t iter;
struct mu_cfg_cont *ret = NULL;
if (len == 0)
len = strlen (ident);
mu_list_get_iterator (list, &iter);
for (mu_iterator_first (iter); !mu_iterator_is_done (iter);
mu_iterator_next (iter))
{
struct mu_cfg_cont *cont;
mu_iterator_current (iter, (void**) &cont);
if (strlen (cont->v.ident) == len
&& memcmp (cont->v.ident, ident, len) == 0)
{
ret = cont;
break;
}
}
mu_iterator_destroy (&iter);
return ret;
}
static struct mu_cfg_section *
find_subsection (struct mu_cfg_section *sec, const char *ident, size_t len)
{
if (sec)
{
sec = sec->subsec;
if (sec)
if (sec->subsec)
{
if (len == 0)
len = strlen (ident);
for (; sec->ident; sec++)
if (strlen (sec->ident) == len
&& memcmp (sec->ident, ident, len) == 0)
return sec;
struct mu_cfg_cont *cont = find_container (sec->subsec, ident, len);
if (cont)
return &cont->v.section;
}
}
return NULL;
......@@ -512,14 +536,11 @@ find_param (struct mu_cfg_section *sec, const char *ident, size_t len)
{
if (sec)
{
struct mu_cfg_param *p = sec->param;
if (p)
if (sec->param)
{
if (len == 0)
len = strlen (ident);
for (; p->ident; p++)
if (strlen (p->ident) == len && memcmp (p->ident, ident, len) == 0)
return p;
struct mu_cfg_cont *cont = find_container (sec->param, ident, len);
if (cont)
return &cont->v.param;
}
}
return NULL;
......@@ -874,6 +895,10 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
/* GETSNUM(node->tag_label, off_t, *(off_t*)param->data); */
return 1;
case mu_cfg_time:
GETUNUM (node->tag_label, time_t, *(time_t*)param->data);
break;
case mu_cfg_bool:
if (parse_bool (sdata, node, (int*) param->data))
return 1;
......@@ -921,11 +946,14 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
sec = find_subsection (sdata->list->sec, node->tag_name, 0);
if (!sec)
{
mu_cfg_perror (sdata->call_data,
&node->locus,
_("unknown section `%s'"),
node->tag_name);
sdata->error++;
if (getenv ("MU_CONFIG_VERBOSE"))
{
mu_cfg_perror (sdata->call_data,
&node->locus,
_("unknown section `%s'"),
node->tag_name);
sdata->error++;
}
return MU_CFG_ITER_SKIP;
}
if (!sec->subsec && !sec->param)
......
......@@ -252,7 +252,7 @@ assign_string (char **pstr, char *val)
{
size_t size = strlen (val);
char *p = realloc (*pstr, size + 1);
if (!*p)
if (!p)
{
mu_error ("%s", mu_strerror (ENOMEM));
exit (1);
......@@ -1291,6 +1291,14 @@ mu_create_argcv (const char *capa[],
/* ************************************************************************* */
static struct mu_cfg_param *prog_param;
void
mu_argp_set_config_param (struct mu_cfg_param *p)
{
prog_param = p;
}
static void
read_configs (char *progname, enum mu_config_flavor cfl[CF_SIZE])
{
......@@ -1307,7 +1315,7 @@ read_configs (char *progname, enum mu_config_flavor cfl[CF_SIZE])
{
case mu_config_auto:
case mu_config_resource:
mu_parse_config (MU_CONFIG_FILE, progname);
mu_parse_config (MU_CONFIG_FILE, progname, prog_param, 1);
break;
default:
......@@ -1329,7 +1337,7 @@ read_configs (char *progname, enum mu_config_flavor cfl[CF_SIZE])
strcpy (file_name, "~/.");
strcat (file_name, progname);
mu_parse_config (file_name, progname);
mu_parse_config (file_name, progname, prog_param, 0);
free (file_name);
}
......@@ -1365,6 +1373,9 @@ mu_argp_parse (const struct argp *argp,
else
progname = (*pargv)[0];
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
get_default_config_flavor (progname, cfl);
if (!argp)
......
......@@ -248,6 +248,8 @@ mu_authenticate (struct mu_auth_data *auth_data, char *pass)
#define ARG_AUTHORIZATION 1
#define ARG_AUTHENTICATION 2
#define ARG_CLEAR_AUTHORIZATION 3
#define ARG_CLEAR_AUTHENTICATION 4
static error_t mu_auth_argp_parser (int key, char *arg,
struct argp_state *state);
......@@ -258,6 +260,10 @@ static struct argp_option mu_auth_argp_option[] = {
N_("Set the list of modules to be used for authentication"), 0 },
{ "authorization", ARG_AUTHORIZATION, N_("MODLIST"), OPTION_HIDDEN,
N_("Set list of modules to be used for authorization"), 0 },
{ "clear-authorization", ARG_CLEAR_AUTHORIZATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authorization modules"), 0 },
{ "clear-authentication", ARG_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authentication modules"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
......@@ -291,6 +297,14 @@ mu_auth_argp_parser (int key, char *arg, struct argp_state *state)
mu_authentication_add_module_list (arg);
break;
case ARG_CLEAR_AUTHENTICATION:
mu_authentication_clear_list ();
break;
case ARG_CLEAR_AUTHORIZATION:
mu_authorization_clear_list ();
break;
default:
return ARGP_ERR_UNKNOWN;
}
......@@ -304,14 +318,20 @@ mu_auth_argp_parser (int key, char *arg, struct argp_state *state)
static int
cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg)
{
mu_authentication_add_module_list (arg);/*FIXME: error reporting*/
if (strcmp (arg, "clear") == 0)
mu_authentication_clear_list ();
else
mu_authentication_add_module_list (arg);/*FIXME: error reporting*/
return 0;
}
static int
cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg)
{
mu_authorization_add_module_list (arg);
if (strcmp (arg, "clear") == 0)
mu_authorization_clear_list ();
else
mu_authorization_add_module_list (arg);
return 0;
}
......@@ -451,6 +471,7 @@ _add_module_list (const char *modlist, int (*fun)(const char *name))
}
}
int
mu_authorization_add_module (const char *name)
{
......@@ -472,6 +493,14 @@ mu_authorization_add_module_list (const char *modlist)
_add_module_list (modlist, mu_authorization_add_module);
}
void
mu_authorization_clear_list ()
{
mu_list_destroy (&_tmp_auth_by_name_list);
mu_list_destroy (&_tmp_auth_by_uid_list);
}
int
mu_authentication_add_module (const char *name)
{
......@@ -492,6 +521,13 @@ mu_authentication_add_module_list (const char *modlist)
_add_module_list (modlist, mu_authentication_add_module);
}
void
mu_authentication_clear_list ()
{
mu_list_destroy (&_tmp_authenticate_list);
}
/* ************************************************************************ */
/* Setup functions. Note that:
......
......@@ -23,9 +23,16 @@
#include <stdlib.h>
#include <errno.h>
#include <mailutils/errno.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
struct _mu_refcount
{
unsigned int ref;
mu_monitor_t lock;
};
int
mu_refcount_create (mu_refcount_t *prefcount)
{
......@@ -37,7 +44,7 @@ mu_refcount_create (mu_refcount_t *prefcount)
if (refcount != NULL)
{
refcount->ref = 1;
status = monitor_create (&(refcount->lock));
status = mu_monitor_create (&refcount->lock, 0, refcount);
if (status == 0)
{
*prefcount = refcount;
......@@ -54,41 +61,47 @@ mu_refcount_create (mu_refcount_t *prefcount)
return status;
}
unsigned
mu_refcount_value (mu_refcount_t refcount)
{
return refcount ? refcount->ref : 0;
}
void
mu_refcount_destroy (mu_refcount_t *prefcount)
{
if (prefcount && *prefcount)
{
mu_refcount_t refcount = *prefcount;
monitor_destroy (&refcount->lock);
mu_monitor_destroy (&refcount->lock, refcount);
free (refcount);
*prefcount = NULL;
}
}
int
unsigned
mu_refcount_inc (mu_refcount_t refcount)
{
int count = 0;
if (refcount)
{
monitor_lock (refcount->lock);
mu_monitor_wrlock (refcount->lock);
count = ++refcount->ref;
monitor_unlock (refcount->lock);
mu_monitor_wrlock (refcount->lock);
}
return count;
}
int
unsigned
mu_refcount_dec (mu_refcount_t refcount)
{
int count = 0;
if (refcount)
{
monitor_lock (refcount->lock);
mu_monitor_wrlock (refcount->lock);
if (refcount->ref)
count = --refcount->ref;
monitor_unlock (refcount->lock);
mu_monitor_wrlock (refcount->lock);
}
return count;
}
......
......@@ -63,6 +63,27 @@ static int interactive = -1;
char *mimeview_file; /* Name of the file to view */
FILE *mimeview_fp; /* Its descriptor */
static void
set_debug_flags (mu_cfg_locus_t *locus, char *arg)
{
for (; *arg; arg++)
{
switch (*arg)
{
case 'l':
mimetypes_lex_debug (1);
break;
case 'g':
mimetypes_gram_debug (1);
break;
default:
debug_level = *arg - '0';
}
}
}
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
......@@ -88,22 +109,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 'd':
if (!arg)
arg = "9";
for (; *arg; arg++)
{
switch (*arg)
{
case 'l':
mimetypes_lex_debug (1);
break;
case 'g':
mimetypes_gram_debug (1);
break;
default:
debug_level = *arg - '0';
}
}
set_debug_flags (NULL, arg);
break;
case 'h':
......@@ -137,6 +143,23 @@ static struct argp argp = {
NULL, NULL
};
static int
cb_debug (mu_cfg_locus_t *locus, void *data, char *arg)
{
set_debug_flags (locus, arg);
return 0;
}
struct mu_cfg_param mimeview_cfg_param[] = {
{"debug", mu_cfg_callback, NULL, cb_debug },
{"mimetypes", mu_cfg_string, &mimetypes_config },
{"metamail", mu_cfg_string, &metamail },
{ NULL }
};
static const char *capa[] = {
"common",
"license",
......@@ -239,6 +262,7 @@ main (int argc, char **argv)
mu_init_nls ();
mu_argp_init (program_version, NULL);
mu_argp_set_config_param (mimeview_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL);
argc -= index;
......
......@@ -77,6 +77,14 @@ static struct argp argp = {
NULL, NULL
};
struct mu_cfg_param movemail_cfg_param[] = {
{ "preserve", mu_cfg_bool, &preserve_mail },
{ "reverse", mu_cfg_bool, &reverse_order },
{ NULL }
};
static const char *mail_capa[] = {
"common",
"license",
......@@ -84,7 +92,7 @@ static const char *mail_capa[] = {
#ifdef WITH_TLS
"tls",
#endif
NULL
NULL
};
int
......@@ -281,13 +289,14 @@ main (int argc, char **argv)
mu_register_all_mbox_formats ();
/* argument parsing */
mu_error_set_print (movemail_error_printer);
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
#endif
mu_argp_set_config_param (movemail_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, &index, NULL);
argc -= index;
......
......@@ -74,39 +74,33 @@ static char doc[] = N_("GNU pop3d -- the POP3 daemon");
static struct argp_option options[] = {
#define GRP 0
{ NULL, 0, NULL, 0,
N_("General options"), GRP },
{"undelete", 'u', NULL, 0,
{"undelete", 'u', NULL, OPTION_HIDDEN,
N_("Undelete all messages on startup"), GRP+1},
{"expire", OPT_EXPIRE, N_("DAYS"), 0,
{"expire", OPT_EXPIRE, N_("DAYS"), OPTION_HIDDEN,
N_("Expire read messages after the given number of days"), GRP+1},
{"delete-expired", OPT_EXPIRE_ON_EXIT, NULL, 0,
{"delete-expired", OPT_EXPIRE_ON_EXIT, NULL, OPTION_HIDDEN,
N_("Delete expired messages upon closing the mailbox"), GRP+1},
#ifdef WITH_TLS
{"tls-required", OPT_TLS_REQUIRED, NULL, 0,
{"tls-required", OPT_TLS_REQUIRED, NULL, OPTION_HIDDEN,
N_("Always require STLS before entering authentication phase")},
#endif
#undef GRP
#define GRP 10
#ifdef ENABLE_LOGIN_DELAY
{ NULL, 0, NULL, 0,
N_("Login delay control"), GRP },
{"login-delay", OPT_LOGIN_DELAY, N_("SECONDS"), 0,
{"login-delay", OPT_LOGIN_DELAY, N_("SECONDS"), OPTION_HIDDEN,
N_("Allowed delay between the two successive logins"), GRP+1},
{"stat-file", OPT_STAT_FILE, N_("FILENAME"), 0,
{"stat-file", OPT_STAT_FILE, N_("FILENAME"), OPTION_HIDDEN,
N_("Name of login statistics file"), GRP+1},
#endif
#undef GRP
#define GRP 20
{ NULL, 0, NULL, 0,
N_("Bulletin control"), GRP },
{ "bulletin-source", OPT_BULLETIN_SOURCE, N_("MBOX"), 0,
{ "bulletin-source", OPT_BULLETIN_SOURCE, N_("MBOX"), OPTION_HIDDEN,
N_("Set source mailbox to get bulletins from"), GRP+1 },
#ifdef USE_DBM
{ "bulletin-db", OPT_BULLETIN_DB, N_("FILE"), 0,
{ "bulletin-db", OPT_BULLETIN_DB, N_("FILE"), OPTION_HIDDEN,
N_("Set the bulletin database file name"), GRP+1 },
#endif
#undef GRP
......@@ -114,6 +108,43 @@ static struct argp_option options[] = {
{NULL, 0, NULL, 0, NULL, 0}
};
#ifdef WITH_TLS
static int
cb_tls_expired (mu_cfg_locus_t *locus, void *data, char *arg)
{
initial_state = INITIAL;
return 0;
}
#endif
static int
cb_bulletin_source (mu_cfg_locus_t *locus, void *data, char *arg)
{
set_bulletin_source (arg);
return 0;
}
static int
cb_bulletin_db (mu_cfg_locus_t *locus, void *data, char *arg)
{
set_bulletin_source (arg);
return 0;
}
static struct mu_cfg_param pop3d_cfg_param[] = {
{ "undelete", mu_cfg_int, &undelete_on_startup },
{ "expire", mu_cfg_time, &expire },
{ "delete-expired", mu_cfg_int, &expire_on_exit },
#ifdef WITH_TLS
{ "tls-required", mu_cfg_callback, NULL, cb_tls_expired },
#endif
{ "login-delay", mu_cfg_time, &login_delay },
{ "stat-file", mu_cfg_string, &login_stat_file },
{ "bulletin-source", mu_cfg_callback, NULL, cb_bulletin_source },
{ "bulletin-db", mu_cfg_callback, NULL, cb_bulletin_db },
{ NULL }
};
static struct argp argp = {
options,
pop3d_parse_opt,
......@@ -221,8 +252,12 @@ main (int argc, char **argv)
#ifdef WITH_TLS
mu_tls_init_argp ();
#endif /* WITH_TLS */
mu_argp_set_config_param (pop3d_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, pop3d_argp_capa, NULL, &daemon_param);
if (expire == 0)
expire_on_exit = 1;
#ifdef USE_LIBPAM
if (!pam_service)
pam_service = "gnu-pop3d";
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
......
......@@ -114,6 +114,18 @@ readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
return 0;
}
struct mu_cfg_param readmsg_cfg_param[] = {
{ "debug", mu_cfg_int, &dbug },
{ "header", mu_cfg_bool, &all_header },
{ "weedlist", mu_cfg_string, &weedlist },
{ "folder", mu_cfg_string, &mailbox_name },
{ "no-header", mu_cfg_bool, &no_header },
{ "form-feeds", mu_cfg_bool, &form_feed },
{ "show-all-match", mu_cfg_bool, &show_all },
{ NULL }
};
static int
string_starts_with (const char * s1, const char *s2)
{
......@@ -268,6 +280,7 @@ main (int argc, char **argv)
#ifdef WITH_TLS
mu_tls_init_client_argp ();
#endif
mu_argp_set_config_param (readmsg_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, readmsg_argp_capa, &index, NULL);
/* register the formats. */
......
......@@ -97,17 +97,15 @@ static struct argp_option options[] =
{0}
};
struct options {
int keep_going;
int compile_only;
char *mbox;
char *tickets;
int tickets_default;
int debug_level;
int sieve_debug;
int verbose;
char *script;
};
int keep_going;
int compile_only;
char *mbox_url;
char *tickets;
int tickets_default;
int debug_level;
int sieve_debug;
int verbose;
char *script;
static int sieve_print_locus = 1; /* Should the log messages include the
locus */
......@@ -123,25 +121,50 @@ is_true_p (char *p)
return rc;
}
static void
set_debug_level (mu_cfg_locus_t *locus, const char *arg)
{
for (; *arg; arg++)
{
switch (*arg)
{
case 'T':
debug_level |= MU_DEBUG_TRACE;
break;
case 'P':
debug_level |= MU_DEBUG_PROT;
break;
case 'g':
mu_sieve_yydebug = 1;
break;
case 't':
sieve_debug |= MU_SIEVE_DEBUG_TRACE;
break;
case 'i':
sieve_debug |= MU_SIEVE_DEBUG_INSTR;
break;
default:
if (locus)
mu_error (_("%s:%d: %c is not a valid debug flag"),
locus->file, locus->line, *arg);
else
mu_error (_("%c is not a valid debug flag"), *arg);
}
}
}
static error_t
parser (int key, char *arg, struct argp_state *state)
{
struct options *opts = state->input;
int rc;
switch (key)
{
case ARGP_KEY_INIT:
if (!opts->tickets)
{
opts->tickets = mu_tilde_expansion ("~/.tickets", "/", NULL);
opts->tickets_default = 1;
}
if (!opts->debug_level)
opts->debug_level = MU_DEBUG_ERROR;
log_facility = 0;
break;
case 'e':
rc = mu_set_user_email (arg);
if (rc)
......@@ -149,69 +172,41 @@ parser (int key, char *arg, struct argp_state *state)
break;
case 'n':
opts->sieve_debug |= MU_SIEVE_DRY_RUN;
sieve_debug |= MU_SIEVE_DRY_RUN;
break;
case 'k':
opts->keep_going = 1;
keep_going = 1;
break;
case 'c':
opts->compile_only = 1;
compile_only = 1;
break;
case 'D':
opts->compile_only = 2;
compile_only = 2;
break;
case 'f':
if (opts->mbox)
argp_error (state, _("Only one MBOX can be specified"));
opts->mbox = strdup (arg);
if (mbox_url)
free (mbox_url);
mbox_url = strdup (arg);
break;
case 't':
free (opts->tickets);
opts->tickets = mu_tilde_expansion (arg, "/", NULL);
opts->tickets_default = 0;
free (tickets);
tickets = mu_tilde_expansion (arg, "/", NULL);
tickets_default = 0;
break;
case 'd':
if (!arg)
arg = D_DEFAULT;
for (; *arg; arg++)
{
switch (*arg)
{
case 'T':
opts->debug_level |= MU_DEBUG_TRACE;
break;
case 'P':
opts->debug_level |= MU_DEBUG_PROT;
break;
case 'g':
mu_sieve_yydebug = 1;
break;
case 't':
opts->sieve_debug |= MU_SIEVE_DEBUG_TRACE;
break;
case 'i':
opts->sieve_debug |= MU_SIEVE_DEBUG_INSTR;
break;
default:
argp_error (state, _("%c is not a valid debug flag"), *arg);
break;
}
}
set_debug_level (NULL, arg);
break;
case 'v':
opts->verbose = 1;
verbose = 1;
break;
case ARG_LINE_INFO:
......@@ -219,9 +214,9 @@ parser (int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_ARG:
if (opts->script)
if (script)
argp_error (state, _("Only one SCRIPT can be specified"));
opts->script = mu_tilde_expansion (arg, "/", NULL);
script = mu_tilde_expansion (arg, "/", NULL);
break;
case ARGP_KEY_NO_ARGS:
......@@ -242,6 +237,45 @@ static struct argp argp =
doc
};
static int
cb_debug (mu_cfg_locus_t *locus, void *data, char *arg)
{
set_debug_level (locus, arg);
return 0;
}
static int
cb_email (mu_cfg_locus_t *locus, void *data, char *arg)
{
int rc = mu_set_user_email (arg);
if (rc)
mu_error (_("%s:%d: Invalid email: %s"),
locus->file, locus->line, mu_strerror (rc));
return rc;
}
static int
cb_ticket (mu_cfg_locus_t *locus, void *data, char *arg)
{
free (tickets);
tickets = mu_tilde_expansion (arg, "/", NULL);
tickets_default = 0;
return 0;
}
static struct mu_cfg_param sieve_cfg_param[] = {
{ "keep-going", mu_cfg_int, &keep_going },
{ "mbox-url", mu_cfg_string, &mbox_url },
{ "ticket", mu_cfg_callback, NULL, cb_ticket },
{ "debug", mu_cfg_callback, NULL, cb_debug },
{ "verbose", mu_cfg_bool, &verbose },
{ "line-info", mu_cfg_bool, &sieve_print_locus },
{ "email", mu_cfg_callback, NULL, cb_email },
{ NULL }
};
static const char *sieve_argp_capa[] =
{
"common",
......@@ -348,7 +382,6 @@ main (int argc, char *argv[])
mu_debug_t debug = 0;
mu_mailbox_t mbox = 0;
int rc;
struct options opts = {0};
int (*debugfp) (mu_debug_t, size_t level, const char *, va_list);
/* Native Language Support */
......@@ -360,9 +393,15 @@ main (int argc, char *argv[])
#endif
mu_sieve_argp_init ();
mu_register_all_formats ();
tickets = mu_tilde_expansion ("~/.tickets", "/", NULL);
tickets_default = 1;
debug_level = MU_DEBUG_ERROR;
log_facility = 0;
mu_argp_set_config_param (sieve_cfg_param);
rc = mu_argp_parse (&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa,
0, &opts);
0, 0);
if (rc)
return 1;
......@@ -382,34 +421,34 @@ main (int argc, char *argv[])
openlog ("sieve", LOG_PID, log_facility);
mu_error_set_print (mu_syslog_error_printer);
mu_sieve_set_debug (mach, sieve_syslog_debug_printer);
if (opts.verbose)
if (verbose)
mu_sieve_set_logger (mach, syslog_action_log);
debugfp = syslog_debug_print;
}
else
{
mu_sieve_set_debug (mach, sieve_stderr_debug_printer);
if (opts.verbose)
if (verbose)
mu_sieve_set_logger (mach, stdout_action_log);
debugfp = stderr_debug_print;
}
rc = mu_sieve_compile (mach, opts.script);
rc = mu_sieve_compile (mach, script);
if (rc)
return 1;
/* We can finish if its only a compilation check. */
if (opts.compile_only)
if (compile_only)
{
if (opts.compile_only == 2)
if (compile_only == 2)
mu_sieve_disass (mach);
return 0;
}
/* Create a ticket, if we can. */
if (opts.tickets)
if (tickets)
{
if ((rc = mu_wicket_create (&wicket, opts.tickets)) == 0)
if ((rc = mu_wicket_create (&wicket, tickets)) == 0)
{
if ((rc = mu_wicket_get_ticket (wicket, &ticket, 0, 0)) != 0)
{
......@@ -417,10 +456,10 @@ main (int argc, char *argv[])
goto cleanup;
}
}
else if (!(opts.tickets_default && errno == ENOENT))
else if (!(tickets_default && errno == ENOENT))
{
mu_error (_("mu_wicket_create `%s' failed: %s"),
opts.tickets, mu_strerror (rc));
tickets, mu_strerror (rc));
goto cleanup;
}
if (ticket)
......@@ -428,14 +467,14 @@ main (int argc, char *argv[])
}
/* Create a debug object, if needed. */
if (opts.debug_level)
if (debug_level)
{
if ((rc = mu_debug_create (&debug, mach)))
{
mu_error (_("mu_debug_create failed: %s"), mu_strerror (rc));
goto cleanup;
}
if ((rc = mu_debug_set_level (debug, opts.debug_level)))
if ((rc = mu_debug_set_level (debug, debug_level)))
{
mu_error (_("mu_debug_set_level failed: %s"),
mu_strerror (rc));
......@@ -449,14 +488,14 @@ main (int argc, char *argv[])
}
}
mu_sieve_set_debug_level (mach, debug, opts.sieve_debug);
mu_sieve_set_debug_level (mach, debug, sieve_debug);
/* Create, give a ticket to, and open the mailbox. */
if ((rc = mu_mailbox_create_default (&mbox, opts.mbox)) != 0)
if ((rc = mu_mailbox_create_default (&mbox, mbox_url)) != 0)
{
if (opts.mbox)
if (mbox)
mu_error (_("Could not create mailbox `%s': %s"),
opts.mbox, mu_strerror (rc));
mbox_url, mu_strerror (rc));
else
mu_error (_("Could not create default mailbox: %s"),
mu_strerror (rc));
......@@ -498,16 +537,16 @@ main (int argc, char *argv[])
}
/* Open the mailbox read-only if we aren't going to modify it. */
if (opts.sieve_debug & MU_SIEVE_DRY_RUN)
if (sieve_debug & MU_SIEVE_DRY_RUN)
rc = mu_mailbox_open (mbox, MU_STREAM_READ);
else
rc = mu_mailbox_open (mbox, MU_STREAM_RDWR);
if (rc != 0)
{
if (opts.mbox)
if (mbox)
mu_error (_("Opening mailbox `%s' failed: %s"),
opts.mbox, mu_strerror (rc));
mbox_url, mu_strerror (rc));
else
mu_error (_("Opening default mailbox failed: %s"),
mu_strerror (rc));
......@@ -519,7 +558,7 @@ main (int argc, char *argv[])
rc = mu_sieve_mailbox (mach, mbox);
cleanup:
if (mbox && !(opts.sieve_debug & MU_SIEVE_DRY_RUN))
if (mbox && !(sieve_debug & MU_SIEVE_DRY_RUN))
{
int e;
......@@ -529,9 +568,9 @@ cleanup:
on a later message. */
if ((e = mu_mailbox_expunge (mbox)) != 0)
{
if (opts.mbox)
if (mbox)
mu_error (_("Expunge on mailbox `%s' failed: %s"),
opts.mbox, mu_strerror (e));
mbox_url, mu_strerror (e));
else
mu_error (_("Expunge on default mailbox failed: %s"),
mu_strerror (e));
......
......@@ -21,6 +21,7 @@ verbose "STARTED" 1
# Make sure we use POSIX locale
set env(LC_ALL) "C"
set env(MU_CONFIG_FLAVOR) "none"
proc mu_init {args} {
global TOOL_EXECUTABLE
......