commit 5af17967774ade6eb0b3ea8312a7ba92904cd920
Author: Oswald Buddenhagen <[email protected]>
Date: Sun Dec 14 17:03:16 2014 +0100
de-duplicate handling of box operation (create & expunge) options
loops work just fine ...
src/config.c | 91 +++++++++++++++++++++++--------------------------
1 files changed, 43 insertions(+), 48 deletions(-)
diff --git a/src/config.c b/src/config.c
index 2025355..25080ed 100644
--- a/src/config.c
+++ b/src/config.c
@@ -143,10 +143,19 @@ parse_size( conffile_t *cfile )
return ret;
}
+static const struct {
+ int op;
+ const char *name;
+} boxOps[] = {
+ { OP_EXPUNGE, "Expunge" },
+ { OP_CREATE, "Create" },
+};
+
static int
getopt_helper( conffile_t *cfile, int *cops, channel_conf_t *conf )
{
char *arg;
+ uint i;
if (!strcasecmp( "Sync", cfile->cmd )) {
arg = cfile->val;
@@ -188,38 +197,6 @@ getopt_helper( conffile_t *cfile, int *cops,
channel_conf_t *conf )
}
while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
conf->ops[M] |= XOP_HAVE_TYPE;
- } else if (!strcasecmp( "Expunge", cfile->cmd )) {
- arg = cfile->val;
- do
- if (!strcasecmp( "Both", arg ))
- *cops |= OP_EXPUNGE;
- else if (!strcasecmp( "Master", arg ))
- conf->ops[M] |= OP_EXPUNGE;
- else if (!strcasecmp( "Slave", arg ))
- conf->ops[S] |= OP_EXPUNGE;
- else if (strcasecmp( "None", arg )) {
- error( "%s:%d: invalid Expunge arg '%s'\n",
- cfile->file, cfile->line, arg );
- cfile->err = 1;
- }
- while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
- conf->ops[M] |= XOP_HAVE_EXPUNGE;
- } else if (!strcasecmp( "Create", cfile->cmd )) {
- arg = cfile->val;
- do
- if (!strcasecmp( "Both", arg ))
- *cops |= OP_CREATE;
- else if (!strcasecmp( "Master", arg ))
- conf->ops[M] |= OP_CREATE;
- else if (!strcasecmp( "Slave", arg ))
- conf->ops[S] |= OP_CREATE;
- else if (strcasecmp( "None", arg )) {
- error( "%s:%d: invalid Create arg '%s'\n",
- cfile->file, cfile->line, arg );
- cfile->err = 1;
- }
- while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
- conf->ops[M] |= XOP_HAVE_CREATE;
} else if (!strcasecmp( "SyncState", cfile->cmd ))
conf->sync_state = expand_strdup( cfile->val );
else if (!strcasecmp( "CopyArrivalDate", cfile->cmd ))
@@ -228,8 +205,30 @@ getopt_helper( conffile_t *cfile, int *cops,
channel_conf_t *conf )
conf->max_messages = parse_int( cfile );
else if (!strcasecmp( "ExpireUnread", cfile->cmd ))
conf->expire_unread = parse_bool( cfile );
- else
+ else {
+ for (i = 0; i < as(boxOps); i++) {
+ if (!strcasecmp( boxOps[i].name, cfile->cmd )) {
+ int op = boxOps[i].op;
+ arg = cfile->val;
+ do {
+ if (!strcasecmp( "Both", arg )) {
+ *cops |= op;
+ } else if (!strcasecmp( "Master", arg
)) {
+ conf->ops[M] |= op;
+ } else if (!strcasecmp( "Slave", arg ))
{
+ conf->ops[S] |= op;
+ } else if (strcasecmp( "None", arg )) {
+ error( "%s:%d: invalid %s arg
'%s'\n",
+ cfile->file,
cfile->line, boxOps[i].name, arg );
+ cfile->err = 1;
+ }
+ } while ((arg = get_arg( cfile, ARG_OPTIONAL, 0
)));
+ conf->ops[M] |= op * (XOP_HAVE_EXPUNGE /
OP_EXPUNGE);
+ return 1;
+ }
+ }
return 0;
+ }
return 1;
}
@@ -257,7 +256,8 @@ getcline( conffile_t *cfile )
int
merge_ops( int cops, int ops[] )
{
- int aops;
+ int aops, op;
+ uint i;
aops = ops[M] | ops[S];
if (ops[M] & XOP_HAVE_TYPE) {
@@ -290,21 +290,16 @@ merge_ops( int cops, int ops[] )
ops[M] |= cops & OP_MASK_TYPE;
}
}
- if (ops[M] & XOP_HAVE_EXPUNGE) {
- if (aops & cops & OP_EXPUNGE) {
- error( "Conflicting Expunge args specified.\n" );
- return 1;
- }
- ops[M] |= cops & OP_EXPUNGE;
- ops[S] |= cops & OP_EXPUNGE;
- }
- if (ops[M] & XOP_HAVE_CREATE) {
- if (aops & cops & OP_CREATE) {
- error( "Conflicting Create args specified.\n" );
- return 1;
+ for (i = 0; i < as(boxOps); i++) {
+ op = boxOps[i].op;
+ if (ops[M] & (op * (XOP_HAVE_EXPUNGE / OP_EXPUNGE))) {
+ if (aops & cops & op) {
+ error( "Conflicting %s args specified.\n",
boxOps[i].name );
+ return 1;
+ }
+ ops[M] |= cops & op;
+ ops[S] |= cops & op;
}
- ops[M] |= cops & OP_CREATE;
- ops[S] |= cops & OP_CREATE;
}
return 0;
}
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel