replace global_* with a channel_conf_t instance

this makes the (growing) list of getopt_helper()'s parameters
manageable. the few wasted bytes are worth it.
This commit is contained in:
Oswald Buddenhagen 2013-11-24 19:32:42 +01:00
parent 1e427f5cd5
commit c0ba0c7ecf
4 changed files with 29 additions and 31 deletions

View File

@ -34,11 +34,10 @@
driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver }; driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver };
channel_conf_t global_conf;
store_conf_t *stores; store_conf_t *stores;
channel_conf_t *channels; channel_conf_t *channels;
group_conf_t *groups; group_conf_t *groups;
int global_ops[2];
char *global_sync_state;
int FSyncLevel = FSYNC_NORMAL; int FSyncLevel = FSYNC_NORMAL;
#define ARG_OPTIONAL 0 #define ARG_OPTIONAL 0
@ -152,7 +151,7 @@ parse_size( conffile_t *cfile )
} }
static int static int
getopt_helper( conffile_t *cfile, int *cops, int ops[], char **sync_state ) getopt_helper( conffile_t *cfile, int *cops, channel_conf_t *conf )
{ {
char *arg; char *arg;
@ -172,21 +171,21 @@ getopt_helper( conffile_t *cfile, int *cops, int ops[], char **sync_state )
else if (!strcasecmp( "Flags", arg )) else if (!strcasecmp( "Flags", arg ))
*cops |= OP_FLAGS; *cops |= OP_FLAGS;
else if (!strcasecmp( "PullReNew", arg )) else if (!strcasecmp( "PullReNew", arg ))
ops[S] |= OP_RENEW; conf->ops[S] |= OP_RENEW;
else if (!strcasecmp( "PullNew", arg )) else if (!strcasecmp( "PullNew", arg ))
ops[S] |= OP_NEW; conf->ops[S] |= OP_NEW;
else if (!strcasecmp( "PullDelete", arg )) else if (!strcasecmp( "PullDelete", arg ))
ops[S] |= OP_DELETE; conf->ops[S] |= OP_DELETE;
else if (!strcasecmp( "PullFlags", arg )) else if (!strcasecmp( "PullFlags", arg ))
ops[S] |= OP_FLAGS; conf->ops[S] |= OP_FLAGS;
else if (!strcasecmp( "PushReNew", arg )) else if (!strcasecmp( "PushReNew", arg ))
ops[M] |= OP_RENEW; conf->ops[M] |= OP_RENEW;
else if (!strcasecmp( "PushNew", arg )) else if (!strcasecmp( "PushNew", arg ))
ops[M] |= OP_NEW; conf->ops[M] |= OP_NEW;
else if (!strcasecmp( "PushDelete", arg )) else if (!strcasecmp( "PushDelete", arg ))
ops[M] |= OP_DELETE; conf->ops[M] |= OP_DELETE;
else if (!strcasecmp( "PushFlags", arg )) else if (!strcasecmp( "PushFlags", arg ))
ops[M] |= OP_FLAGS; conf->ops[M] |= OP_FLAGS;
else if (!strcasecmp( "All", arg ) || !strcasecmp( "Full", arg )) else if (!strcasecmp( "All", arg ) || !strcasecmp( "Full", arg ))
*cops |= XOP_PULL|XOP_PUSH; *cops |= XOP_PULL|XOP_PUSH;
else if (strcasecmp( "None", arg ) && strcasecmp( "Noop", arg )) { else if (strcasecmp( "None", arg ) && strcasecmp( "Noop", arg )) {
@ -195,41 +194,41 @@ getopt_helper( conffile_t *cfile, int *cops, int ops[], char **sync_state )
cfile->err = 1; cfile->err = 1;
} }
while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 ))); while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
ops[M] |= XOP_HAVE_TYPE; conf->ops[M] |= XOP_HAVE_TYPE;
} else if (!strcasecmp( "Expunge", cfile->cmd )) { } else if (!strcasecmp( "Expunge", cfile->cmd )) {
arg = cfile->val; arg = cfile->val;
do do
if (!strcasecmp( "Both", arg )) if (!strcasecmp( "Both", arg ))
*cops |= OP_EXPUNGE; *cops |= OP_EXPUNGE;
else if (!strcasecmp( "Master", arg )) else if (!strcasecmp( "Master", arg ))
ops[M] |= OP_EXPUNGE; conf->ops[M] |= OP_EXPUNGE;
else if (!strcasecmp( "Slave", arg )) else if (!strcasecmp( "Slave", arg ))
ops[S] |= OP_EXPUNGE; conf->ops[S] |= OP_EXPUNGE;
else if (strcasecmp( "None", arg )) { else if (strcasecmp( "None", arg )) {
error( "%s:%d: invalid Expunge arg '%s'\n", error( "%s:%d: invalid Expunge arg '%s'\n",
cfile->file, cfile->line, arg ); cfile->file, cfile->line, arg );
cfile->err = 1; cfile->err = 1;
} }
while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 ))); while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
ops[M] |= XOP_HAVE_EXPUNGE; conf->ops[M] |= XOP_HAVE_EXPUNGE;
} else if (!strcasecmp( "Create", cfile->cmd )) { } else if (!strcasecmp( "Create", cfile->cmd )) {
arg = cfile->val; arg = cfile->val;
do do
if (!strcasecmp( "Both", arg )) if (!strcasecmp( "Both", arg ))
*cops |= OP_CREATE; *cops |= OP_CREATE;
else if (!strcasecmp( "Master", arg )) else if (!strcasecmp( "Master", arg ))
ops[M] |= OP_CREATE; conf->ops[M] |= OP_CREATE;
else if (!strcasecmp( "Slave", arg )) else if (!strcasecmp( "Slave", arg ))
ops[S] |= OP_CREATE; conf->ops[S] |= OP_CREATE;
else if (strcasecmp( "None", arg )) { else if (strcasecmp( "None", arg )) {
error( "%s:%d: invalid Create arg '%s'\n", error( "%s:%d: invalid Create arg '%s'\n",
cfile->file, cfile->line, arg ); cfile->file, cfile->line, arg );
cfile->err = 1; cfile->err = 1;
} }
while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 ))); while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
ops[M] |= XOP_HAVE_CREATE; conf->ops[M] |= XOP_HAVE_CREATE;
} else if (!strcasecmp( "SyncState", cfile->cmd )) } else if (!strcasecmp( "SyncState", cfile->cmd ))
*sync_state = expand_strdup( cfile->val ); conf->sync_state = expand_strdup( cfile->val );
else else
return 0; return 0;
return 1; return 1;
@ -407,7 +406,7 @@ load_config( const char *where, int pseudo )
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 )) {
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 );
cfile.err = 1; cfile.err = 1;
} }
@ -473,7 +472,7 @@ load_config( const char *where, int pseudo )
else if (!strcasecmp( "Thorough", arg )) else if (!strcasecmp( "Thorough", arg ))
FSyncLevel = FSYNC_THOROUGH; FSyncLevel = FSYNC_THOROUGH;
} }
else if (!getopt_helper( &cfile, &gcops, global_ops, &global_sync_state )) else if (!getopt_helper( &cfile, &gcops, &global_conf ))
{ {
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 );
@ -485,9 +484,9 @@ load_config( const char *where, int pseudo )
} }
} }
fclose (cfile.fp); fclose (cfile.fp);
cfile.err |= merge_ops( gcops, global_ops ); cfile.err |= merge_ops( gcops, global_conf.ops );
if (!global_sync_state) if (!global_conf.sync_state)
global_sync_state = expand_strdup( "~/." EXE "/" ); global_conf.sync_state = expand_strdup( "~/." EXE "/" );
if (!cfile.err && pseudo) if (!cfile.err && pseudo)
unlink( where ); unlink( where );
return cfile.err; return cfile.err;

View File

@ -484,10 +484,9 @@ void sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan,
#define N_DRIVERS 2 #define N_DRIVERS 2
extern driver_t *drivers[N_DRIVERS]; extern driver_t *drivers[N_DRIVERS];
extern channel_conf_t global_conf;
extern channel_conf_t *channels; extern channel_conf_t *channels;
extern group_conf_t *groups; extern group_conf_t *groups;
extern int global_ops[2];
extern char *global_sync_state;
#define FSYNC_NONE 0 #define FSYNC_NONE 0
#define FSYNC_NORMAL 1 #define FSYNC_NORMAL 1

View File

@ -179,9 +179,9 @@ merge_actions( channel_conf_t *chan, int ops[], int have, int mask, int def )
chan->ops[S] &= ~mask; chan->ops[S] &= ~mask;
chan->ops[S] |= ops[S] & mask; chan->ops[S] |= ops[S] & mask;
} else if (!(chan->ops[M] & have)) { } else if (!(chan->ops[M] & have)) {
if (global_ops[M] & have) { if (global_conf.ops[M] & have) {
chan->ops[M] |= global_ops[M] & mask; chan->ops[M] |= global_conf.ops[M] & mask;
chan->ops[S] |= global_ops[S] & mask; chan->ops[S] |= global_conf.ops[S] & mask;
} else { } else {
chan->ops[M] |= def; chan->ops[M] |= def;
chan->ops[S] |= def; chan->ops[S] |= def;

View File

@ -670,7 +670,7 @@ box_selected( int sts, void *aux )
return; return;
chan = svars->chan; chan = svars->chan;
if (!strcmp( chan->sync_state ? chan->sync_state : global_sync_state, "*" )) { if (!strcmp( chan->sync_state ? chan->sync_state : global_conf.sync_state, "*" )) {
if (!ctx[S]->path) { if (!ctx[S]->path) {
error( "Error: store '%s' does not support in-box sync state\n", chan->stores[S]->name ); error( "Error: store '%s' does not support in-box sync state\n", chan->stores[S]->name );
sbail: sbail:
@ -685,7 +685,7 @@ box_selected( int sts, void *aux )
nfasprintf( &svars->dname, "%s%s", chan->sync_state, csname ); nfasprintf( &svars->dname, "%s%s", chan->sync_state, csname );
else { else {
cmname = clean_strdup( ctx[M]->name ); cmname = clean_strdup( ctx[M]->name );
nfasprintf( &svars->dname, "%s:%s:%s_:%s:%s", global_sync_state, nfasprintf( &svars->dname, "%s:%s:%s_:%s:%s", global_conf.sync_state,
chan->stores[M]->name, cmname, chan->stores[S]->name, csname ); chan->stores[M]->name, cmname, chan->stores[S]->name, csname );
free( cmname ); free( cmname );
} }