summaryrefslogtreecommitdiff
path: root/libcfg/common.c
blob: 6e95f21068091f238371ce5c74ab9096d92e03b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* This file is part of GNU Mailutils
   Copyright (C) 2007 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.

   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "mailutils/libcfg.h"
#include <string.h>
#include <mailutils/daemon.h>

static struct mu_gocs_daemon daemon_settings;
static struct mu_gocs_locking locking_settings;
static struct mu_gocs_logging logging_settings;
static struct mu_gocs_mailbox mailbox_settings;
static struct mu_gocs_source_email address_settings;
static struct mu_gocs_mailer mailer_settings;

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

static struct mu_cfg_param mu_mailbox_param[] = {
  { "mail-spool", mu_cfg_string, &mailbox_settings.mail_spool },
  { "mailbox-type", mu_cfg_string, &mailbox_settings.mailbox_type },
  { NULL }
};

DCL_CFG_CAPA (mailbox);

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

static struct mu_cfg_param mu_locking_param[] = {
  { "lock-flags", mu_cfg_string, &locking_settings.lock_flags },
  { "lock-retry-timeout", mu_cfg_ulong, &locking_settings.lock_retry_timeout },
  { "lock-retry-count", mu_cfg_ulong, &locking_settings.lock_retry_count },
  { "lock-expire-timeout", mu_cfg_ulong,
    &locking_settings.lock_expire_timeout },
  { "external-locker", mu_cfg_string, &locking_settings.external_locker },
  { NULL, }
};

DCL_CFG_CAPA (locking);


/* ************************************************************************* */
/* Address                                                                   */
/* ************************************************************************* */
     
static struct mu_cfg_param mu_address_param[] = {
  { "email-addr", mu_cfg_string, &address_settings.address },
  { "email-domain", mu_cfg_string, &address_settings.domain },
  { NULL }
};

DCL_CFG_CAPA (address);

     
/* ************************************************************************* */
/* Mailer                                                                    */
/* ************************************************************************* */
     
static struct mu_cfg_param mu_mailer_param[] = {
  { "url", mu_cfg_string, &mailer_settings.mailer },
  { NULL }
};

DCL_CFG_CAPA (mailer);

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

int
cb_facility (mu_cfg_locus_t *locus, void *data, char *arg)
{
  if (mu_string_to_syslog_facility (arg, &logging_settings.facility))
    {
      mu_error (_("%s:%d: Unknown syslog facility `%s'"), 
                locus->file, locus->line, arg);
      return 1;
    }
   return 0;
}

static struct mu_cfg_param mu_logging_param[] = {
  { "facility", mu_cfg_callback, NULL, cb_facility },
  { NULL }
};

DCL_CFG_CAPA (logging);


/* ************************************************************************* */
/* Daemon                                                                    */
/* ************************************************************************* */

static int
_cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg)
{
  if (strcmp (arg, "inetd") == 0
      || strcmp (arg, "interactive") == 0)
    daemon_settings.mode = MODE_INTERACTIVE;
  else if (strcmp (arg, "daemon") == 0)
    daemon_settings.mode = MODE_DAEMON;
  else
    {
      mu_error ("%s:%d: unknown daemon mode", locus->file, locus->line);
      return 1;
    }
  return 0;
}
  
static struct mu_cfg_param mu_daemon_param[] = {
  { "max-children", mu_cfg_ulong, &daemon_settings.maxchildren },
  { "mode", mu_cfg_callback, NULL, _cb_daemon_mode },
  { "transcript", mu_cfg_bool, &daemon_settings.transcript },
  { "pidfile", mu_cfg_string, &daemon_settings.pidfile },
  { "port", mu_cfg_ushort, &daemon_settings.port },
  { "timeout", mu_cfg_ulong, &daemon_settings.timeout },
  { NULL }
};

int									      
mu_daemon_section_parser
   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,	      
    void *section_data, void *call_data)				      
{									      
  switch (stage)							      
    {									      
    case mu_cfg_section_start:
      daemon_settings = mu_gocs_daemon;
      break;								      
      									      
    case mu_cfg_section_end:						      
      mu_gocs_store ("daemon", &daemon_settings);	      
    }									      
  return 0;								      
}

struct mu_cfg_capa mu_daemon_cfg_capa = {                
  "daemon",  mu_daemon_param, mu_daemon_section_parser
};

Return to:

Send suggestions and report system problems to the System administrator.