Blame view

libmu_cfg/common.c 7.09 KB
1
/* This file is part of GNU Mailutils
2
   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 4 5 6 7 8

   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.

9
   GNU Mailutils is distributed in the hope that it will be useful, but
10 11 12 13 14
   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
15
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
16 17
*/

18 19 20
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
21
#include <stdlib.h>
22
#include <string.h>
23 24 25
#include "mailutils/libcfg.h"
#include <mailutils/debug.h>
#include <mailutils/syslog.h>
Sergey Poznyakoff authored
26
#include <mailutils/mailbox.h>
27
#include <mailutils/io.h>
28 29
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
30 31 32 33 34

static struct mu_gocs_locking locking_settings;
static struct mu_gocs_mailbox mailbox_settings;
static struct mu_gocs_source_email address_settings;
static struct mu_gocs_mailer mailer_settings;
35
static struct mu_gocs_debug debug_settings;
36 37 38 39 40 41


/* ************************************************************************* */
/* Mailbox                                                                   */
/* ************************************************************************* */

Sergey Poznyakoff authored
42
static int
43
_cb_folder (void *data, mu_config_value_t *val)
Sergey Poznyakoff authored
44
{
45
  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
46 47
    return 1;
  mu_set_folder_directory (val->v.string);
Sergey Poznyakoff authored
48 49 50
  return 0;
}

51
static struct mu_cfg_param mu_mailbox_param[] = {
52
  { "mail-spool", mu_cfg_string, &mailbox_settings.mail_spool, 0, NULL,
53 54
    N_("Use specified URL as a mailspool directory."),
    N_("url") },
Sergey Poznyakoff authored
55 56 57 58
  { "mailbox-pattern", mu_cfg_string, &mailbox_settings.mailbox_pattern,
    0, NULL,
    N_("Create mailbox URL using <pattern>."),
    N_("pattern") },
59
  { "mailbox-type", mu_cfg_string, &mailbox_settings.mailbox_type, 0, NULL,
60
    N_("Default mailbox type."), N_("protocol") },
Sergey Poznyakoff authored
61 62 63
  { "folder", mu_cfg_callback, NULL, 0, _cb_folder,
    N_("Default user mail folder"),
    N_("dir") },
64 65 66 67 68 69 70 71 72 73 74
  { NULL }
};

DCL_CFG_CAPA (mailbox);


/* ************************************************************************* */
/* Locking                                                                   */
/* ************************************************************************* */

static struct mu_cfg_param mu_locking_param[] = {
75
  /* FIXME: Flags are superfluous. */
76
  { "flags", mu_cfg_string, &locking_settings.lock_flags, 0, NULL,
77
    N_("Default locker flags (E=external, R=retry, T=time, P=pid).") },
78 79
  { "retry-timeout", mu_cfg_ulong, &locking_settings.lock_retry_timeout,
    0, NULL,
80
    N_("Set timeout for acquiring the lock.") },
81
  { "retry-count", mu_cfg_ulong, &locking_settings.lock_retry_count, 0, NULL,
82 83
    N_("Set the maximum number of times to retry acquiring the lock.") },
  { "expire-timeout", mu_cfg_ulong, &locking_settings.lock_expire_timeout,
84
    0, NULL,
85
    N_("Expire locks older than this amount of time.") },
86 87
  { "external-locker", mu_cfg_string, &locking_settings.external_locker, 
    0, NULL,
88 89
    N_("Use external locker program."),
    N_("prog") },
90 91 92 93 94 95 96 97 98 99 100
  { NULL, }
};

DCL_CFG_CAPA (locking);


/* ************************************************************************* */
/* Address                                                                   */
/* ************************************************************************* */
     
static struct mu_cfg_param mu_address_param[] = {
101
  { "email-addr", mu_cfg_string, &address_settings.address, 0, NULL,
102 103 104
    N_("Set the current user email address (default is "
       "loginname@defaultdomain)."),
    N_("email") },
105
  { "email-domain", mu_cfg_string, &address_settings.domain, 0, NULL,
106 107
    N_("Set e-mail domain for unqualified user names (default is this host)"),
    N_("domain") },
108 109 110 111 112 113 114 115 116 117 118
  { NULL }
};

DCL_CFG_CAPA (address);

     
/* ************************************************************************* */
/* Mailer                                                                    */
/* ************************************************************************* */
     
static struct mu_cfg_param mu_mailer_param[] = {
119
  { "url", mu_cfg_string, &mailer_settings.mailer, 0, NULL,
120 121
    N_("Use this URL as the default mailer"),
    N_("url") },
122 123 124 125 126 127 128 129 130 131
  { NULL }
};

DCL_CFG_CAPA (mailer);


/* ************************************************************************* */
/* Logging                                                                   */
/* ************************************************************************* */

132 133
static int
cb_facility (void *data, mu_config_value_t *val)
134
{
135
  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
136 137
    return 1;
  
138
  if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
139
    {
140
      mu_error (_("unknown syslog facility `%s'"), val->v.string);
141 142 143 144 145
      return 1;
    }
   return 0;
}

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
static int
cb_severity (void *data, mu_config_value_t *val)
{
  unsigned n;
  
  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
    return 1;
  if (mu_severity_from_string (val->v.string, &n))
    {
      mu_error (_("unknown severity `%s'"), val->v.string);
      return 1;
    }
  mu_log_severity_threshold = n;
  return 0;
}      

162
static struct mu_cfg_param mu_logging_param[] = {
163 164 165 166
  { "syslog", mu_cfg_bool, &mu_log_syslog, 0, NULL,
    N_("Send diagnostics to syslog.") },
  { "print-severity", mu_cfg_bool, &mu_log_print_severity, 0, NULL,
    N_("Print message severity levels.") },
167 168 169
  { "severity", mu_cfg_callback, NULL, 0, cb_severity,
    N_("Output only messages with a severity equal to or greater than "
       "this one.") },
170
  { "facility", mu_cfg_callback, NULL, 0, cb_facility,
171 172 173
    N_("Set syslog facility. Arg is one of the following: user, daemon, "
       "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
       "or a facility number.") },
174 175
  { "tag", mu_cfg_string, &mu_log_tag, 0, NULL,
    N_("Tag syslog messages with this string.") },
176 177 178
  { NULL }
};

179
static int logging_settings; /* Dummy variable */
180 181 182 183
DCL_CFG_CAPA (logging);


/* ************************************************************************* */
184 185 186 187
/* Debug                                                                     */
/* ************************************************************************* */

static int
188
_cb2_debug_level (const char *arg, void *data MU_ARG_UNUSED)
189
{
190
  mu_debug_parse_spec (arg);
191 192 193
  return 0;
}

194
static int
195
cb_debug_level (void *data, mu_config_value_t *val)
196
{
197
  return mu_cfg_string_value_cb (val, _cb2_debug_level, NULL);
198 199
}

200
static struct mu_cfg_param mu_debug_param[] = {
201
  { "level", mu_cfg_callback, NULL, 0, &cb_debug_level,
202 203 204
    N_("Set Mailutils debugging level.  Argument is a colon-separated list "
       "of debugging specifications in the form:\n"
       "   <object: string>[[:]=<level: number>].") },
205
  { "line-info", mu_cfg_bool, &debug_settings.line_info, 0, NULL,
206
    N_("Prefix debug messages with Mailutils source locations.") },
207 208 209 210
  { NULL }
};

DCL_CFG_CAPA (debug);