store config error status in conffile_t object
this makes passing it around more straight-forward
This commit is contained in:
parent
725a122e91
commit
16e5aade3f
37
src/config.c
37
src/config.c
|
@ -296,7 +296,7 @@ load_config( const char *where, int pseudo )
|
||||||
group_conf_t *group, **groupapp = &groups;
|
group_conf_t *group, **groupapp = &groups;
|
||||||
string_list_t *chanlist, **chanlistapp;
|
string_list_t *chanlist, **chanlistapp;
|
||||||
char *arg, *p;
|
char *arg, *p;
|
||||||
int err, len, cops, gcops, max_size, ms, i;
|
int len, cops, gcops, max_size, ms, i;
|
||||||
char path[_POSIX_PATH_MAX];
|
char path[_POSIX_PATH_MAX];
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
@ -317,14 +317,15 @@ load_config( const char *where, int pseudo )
|
||||||
cfile.buf = buf;
|
cfile.buf = buf;
|
||||||
cfile.bufl = sizeof(buf) - 1;
|
cfile.bufl = sizeof(buf) - 1;
|
||||||
cfile.line = 0;
|
cfile.line = 0;
|
||||||
|
cfile.err = 0;
|
||||||
|
|
||||||
gcops = err = 0;
|
gcops = 0;
|
||||||
reloop:
|
reloop:
|
||||||
while (getcline( &cfile )) {
|
while (getcline( &cfile )) {
|
||||||
if (!cfile.cmd)
|
if (!cfile.cmd)
|
||||||
continue;
|
continue;
|
||||||
for (i = 0; i < N_DRIVERS; i++)
|
for (i = 0; i < N_DRIVERS; i++)
|
||||||
if (drivers[i]->parse_store( &cfile, &store, &err )) {
|
if (drivers[i]->parse_store( &cfile, &store )) {
|
||||||
if (store) {
|
if (store) {
|
||||||
if (!store->path)
|
if (!store->path)
|
||||||
store->path = "";
|
store->path = "";
|
||||||
|
@ -362,7 +363,7 @@ load_config( const char *where, int pseudo )
|
||||||
if (*cfile.val != ':' || !(p = strchr( cfile.val + 1, ':' ))) {
|
if (*cfile.val != ':' || !(p = strchr( cfile.val + 1, ':' ))) {
|
||||||
error( "%s:%d: malformed mailbox spec\n",
|
error( "%s:%d: malformed mailbox spec\n",
|
||||||
cfile.file, cfile.line );
|
cfile.file, cfile.line );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
@ -373,24 +374,24 @@ load_config( const char *where, int pseudo )
|
||||||
}
|
}
|
||||||
error( "%s:%d: unknown store '%s'\n",
|
error( "%s:%d: unknown store '%s'\n",
|
||||||
cfile.file, cfile.line, cfile.val + 1 );
|
cfile.file, cfile.line, cfile.val + 1 );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
continue;
|
continue;
|
||||||
stpcom:
|
stpcom:
|
||||||
if (*++p)
|
if (*++p)
|
||||||
channel->boxes[ms] = nfstrdup( p );
|
channel->boxes[ms] = nfstrdup( p );
|
||||||
} else if (!getopt_helper( &cfile, &cops, channel->ops, &channel->sync_state )) {
|
} else if (!getopt_helper( &cfile, &cops, channel->ops, &channel->sync_state )) {
|
||||||
error( "%s:%d: unknown keyword '%s'\n", cfile.file, cfile.line, cfile.cmd );
|
error( "%s:%d: unknown keyword '%s'\n", cfile.file, cfile.line, cfile.cmd );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!channel->stores[M]) {
|
if (!channel->stores[M]) {
|
||||||
error( "channel '%s' refers to no master store\n", channel->name );
|
error( "channel '%s' refers to no master store\n", channel->name );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
} else if (!channel->stores[S]) {
|
} else if (!channel->stores[S]) {
|
||||||
error( "channel '%s' refers to no slave store\n", channel->name );
|
error( "channel '%s' refers to no slave store\n", channel->name );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
} else if (merge_ops( cops, channel->ops ))
|
} else if (merge_ops( cops, channel->ops ))
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
else {
|
else {
|
||||||
if (max_size >= 0)
|
if (max_size >= 0)
|
||||||
channel->stores[M]->max_size = channel->stores[S]->max_size = max_size;
|
channel->stores[M]->max_size = channel->stores[S]->max_size = max_size;
|
||||||
|
@ -429,7 +430,7 @@ load_config( const char *where, int pseudo )
|
||||||
{
|
{
|
||||||
error( "%s:%d: unknown keyword '%s'\n",
|
error( "%s:%d: unknown keyword '%s'\n",
|
||||||
cfile.file, cfile.line, cfile.cmd );
|
cfile.file, cfile.line, cfile.cmd );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -438,7 +439,7 @@ load_config( const char *where, int pseudo )
|
||||||
{
|
{
|
||||||
error( "%s:%d: unknown section keyword '%s'\n",
|
error( "%s:%d: unknown section keyword '%s'\n",
|
||||||
cfile.file, cfile.line, cfile.cmd );
|
cfile.file, cfile.line, cfile.cmd );
|
||||||
err = 1;
|
cfile.err = 1;
|
||||||
while (getcline( &cfile ))
|
while (getcline( &cfile ))
|
||||||
if (!cfile.cmd)
|
if (!cfile.cmd)
|
||||||
goto reloop;
|
goto reloop;
|
||||||
|
@ -446,16 +447,16 @@ load_config( const char *where, int pseudo )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (cfile.fp);
|
fclose (cfile.fp);
|
||||||
err |= merge_ops( gcops, global_ops );
|
cfile.err |= merge_ops( gcops, global_ops );
|
||||||
if (!global_sync_state)
|
if (!global_sync_state)
|
||||||
global_sync_state = expand_strdup( "~/." EXE "/" );
|
global_sync_state = expand_strdup( "~/." EXE "/" );
|
||||||
if (!err && pseudo)
|
if (!cfile.err && pseudo)
|
||||||
unlink( where );
|
unlink( where );
|
||||||
return err;
|
return cfile.err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_generic_store( store_conf_t *store, conffile_t *cfg, int *err )
|
parse_generic_store( store_conf_t *store, conffile_t *cfg )
|
||||||
{
|
{
|
||||||
if (!strcasecmp( "Trash", cfg->cmd ))
|
if (!strcasecmp( "Trash", cfg->cmd ))
|
||||||
store->trash = nfstrdup( cfg->val );
|
store->trash = nfstrdup( cfg->val );
|
||||||
|
@ -471,15 +472,15 @@ parse_generic_store( store_conf_t *store, conffile_t *cfg, int *err )
|
||||||
int sl = strlen( cfg->val );
|
int sl = strlen( cfg->val );
|
||||||
if (sl != 1) {
|
if (sl != 1) {
|
||||||
error( "%s:%d: malformed flattened hierarchy delimiter\n", cfg->file, cfg->line );
|
error( "%s:%d: malformed flattened hierarchy delimiter\n", cfg->file, cfg->line );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
} else if (cfg->val[0] == '/') {
|
} else if (cfg->val[0] == '/') {
|
||||||
error( "%s:%d: flattened hierarchy delimiter cannot be the canonical delimiter '/'\n", cfg->file, cfg->line );
|
error( "%s:%d: flattened hierarchy delimiter cannot be the canonical delimiter '/'\n", cfg->file, cfg->line );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
} else {
|
} else {
|
||||||
store->flat_delim = cfg->val[0];
|
store->flat_delim = cfg->val[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error( "%s:%d: unknown keyword '%s'\n", cfg->file, cfg->line, cfg->cmd );
|
error( "%s:%d: unknown keyword '%s'\n", cfg->file, cfg->line, cfg->cmd );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1876,7 +1876,7 @@ imap_commit( store_t *gctx )
|
||||||
imap_server_conf_t *servers, **serverapp = &servers;
|
imap_server_conf_t *servers, **serverapp = &servers;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
imap_parse_store( conffile_t *cfg, store_conf_t **storep )
|
||||||
{
|
{
|
||||||
imap_store_conf_t *store;
|
imap_store_conf_t *store;
|
||||||
imap_server_conf_t *server, *srv, sserver;
|
imap_server_conf_t *server, *srv, sserver;
|
||||||
|
@ -1937,7 +1937,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
else if (!strcasecmp( "PipelineDepth", cfg->cmd )) {
|
else if (!strcasecmp( "PipelineDepth", cfg->cmd )) {
|
||||||
if ((server->max_in_progress = parse_int( cfg )) < 1) {
|
if ((server->max_in_progress = parse_int( cfg )) < 1) {
|
||||||
error( "%s:%d: PipelineDepth must be at least 1\n", cfg->file, cfg->line );
|
error( "%s:%d: PipelineDepth must be at least 1\n", cfg->file, cfg->line );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LIBSSL
|
#ifdef HAVE_LIBSSL
|
||||||
|
@ -1946,7 +1946,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
if (access( server->sconf.cert_file, R_OK )) {
|
if (access( server->sconf.cert_file, R_OK )) {
|
||||||
sys_error( "%s:%d: CertificateFile '%s'",
|
sys_error( "%s:%d: CertificateFile '%s'",
|
||||||
cfg->file, cfg->line, server->sconf.cert_file );
|
cfg->file, cfg->line, server->sconf.cert_file );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp( "RequireSSL", cfg->cmd ))
|
} else if (!strcasecmp( "RequireSSL", cfg->cmd ))
|
||||||
server->require_ssl = parse_bool( cfg );
|
server->require_ssl = parse_bool( cfg );
|
||||||
|
@ -1969,7 +1969,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
if (srv->name && !strcmp( srv->name, cfg->val ))
|
if (srv->name && !strcmp( srv->name, cfg->val ))
|
||||||
goto gotsrv;
|
goto gotsrv;
|
||||||
error( "%s:%d: unknown IMAP account '%s'\n", cfg->file, cfg->line, cfg->val );
|
error( "%s:%d: unknown IMAP account '%s'\n", cfg->file, cfg->line, cfg->val );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
continue;
|
continue;
|
||||||
gotsrv:
|
gotsrv:
|
||||||
store->server = srv;
|
store->server = srv;
|
||||||
|
@ -1980,11 +1980,11 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
else if (!strcasecmp( "PathDelimiter", cfg->cmd ))
|
else if (!strcasecmp( "PathDelimiter", cfg->cmd ))
|
||||||
store->delimiter = *cfg->val;
|
store->delimiter = *cfg->val;
|
||||||
else
|
else
|
||||||
parse_generic_store( &store->gen, cfg, err );
|
parse_generic_store( &store->gen, cfg );
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
error( "%s:%d: unknown/misplaced keyword '%s'\n", cfg->file, cfg->line, cfg->cmd );
|
error( "%s:%d: unknown/misplaced keyword '%s'\n", cfg->file, cfg->line, cfg->cmd );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
acc_opt = 1;
|
acc_opt = 1;
|
||||||
|
@ -1995,7 +1995,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
error( "IMAP store '%s' has incomplete/missing connection details\n", store->gen.name );
|
error( "IMAP store '%s' has incomplete/missing connection details\n", store->gen.name );
|
||||||
else
|
else
|
||||||
error( "IMAP account '%s' has incomplete/missing connection details\n", server->name );
|
error( "IMAP account '%s' has incomplete/missing connection details\n", server->name );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2006,7 +2006,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
store->server->name = store->gen.name;
|
store->server->name = store->gen.name;
|
||||||
} else if (acc_opt) {
|
} else if (acc_opt) {
|
||||||
error( "IMAP store '%s' has both Account and account-specific options\n", store->gen.name );
|
error( "IMAP store '%s' has both Account and account-specific options\n", store->gen.name );
|
||||||
*err = 1;
|
cfg->err = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -1417,7 +1417,7 @@ maildir_commit( store_t *gctx )
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
maildir_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
maildir_parse_store( conffile_t *cfg, store_conf_t **storep )
|
||||||
{
|
{
|
||||||
maildir_store_conf_t *store;
|
maildir_store_conf_t *store;
|
||||||
|
|
||||||
|
@ -1437,7 +1437,7 @@ maildir_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
|
||||||
store->alt_map = parse_bool( cfg );
|
store->alt_map = parse_bool( cfg );
|
||||||
#endif /* USE_DB */
|
#endif /* USE_DB */
|
||||||
else
|
else
|
||||||
parse_generic_store( &store->gen, cfg, err );
|
parse_generic_store( &store->gen, cfg );
|
||||||
if (!store->inbox)
|
if (!store->inbox)
|
||||||
store->inbox = expand_strdup( "~/Maildir" );
|
store->inbox = expand_strdup( "~/Maildir" );
|
||||||
*storep = &store->gen;
|
*storep = &store->gen;
|
||||||
|
|
|
@ -113,6 +113,7 @@ typedef struct {
|
||||||
char *buf;
|
char *buf;
|
||||||
int bufl;
|
int bufl;
|
||||||
int line;
|
int line;
|
||||||
|
int err;
|
||||||
char *cmd, *val, *rest;
|
char *cmd, *val, *rest;
|
||||||
} conffile_t;
|
} conffile_t;
|
||||||
|
|
||||||
|
@ -267,7 +268,7 @@ struct driver {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* Parse configuration. */
|
/* Parse configuration. */
|
||||||
int (*parse_store)( conffile_t *cfg, store_conf_t **storep, int *err );
|
int (*parse_store)( conffile_t *cfg, store_conf_t **storep );
|
||||||
|
|
||||||
/* Close remaining server connections. All stores must be disowned first. */
|
/* Close remaining server connections. All stores must be disowned first. */
|
||||||
void (*cleanup)( void );
|
void (*cleanup)( void );
|
||||||
|
@ -486,7 +487,7 @@ int parse_size( conffile_t *cfile );
|
||||||
int getcline( conffile_t *cfile );
|
int getcline( conffile_t *cfile );
|
||||||
int merge_ops( int cops, int ops[] );
|
int merge_ops( int cops, int ops[] );
|
||||||
int load_config( const char *filename, int pseudo );
|
int load_config( const char *filename, int pseudo );
|
||||||
void parse_generic_store( store_conf_t *store, conffile_t *cfg, int *err );
|
void parse_generic_store( store_conf_t *store, conffile_t *cfg );
|
||||||
|
|
||||||
/* drv_*.c */
|
/* drv_*.c */
|
||||||
extern driver_t maildir_driver, imap_driver;
|
extern driver_t maildir_driver, imap_driver;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user