Wed, 13 Jul 2016 14:38:17 +0200
merge sync config parser changes
dav/scfg.c | file | annotate | diff | comparison | revisions |
--- a/dav/scfg.c Wed Jul 13 14:11:34 2016 +0200 +++ b/dav/scfg.c Wed Jul 13 14:38:17 2016 +0200 @@ -120,6 +120,27 @@ } } +static int scfg_load_filter(xmlNode *node, UcxList **include, UcxList **exclude) { + node = node->children; + + while(node) { + if(node->type == XML_ELEMENT_NODE) { + char *value = util_xml_get_text(node); + if(!value) { + return 1; + } else if(xstreq(node->name, "include")) { + *include = add_regex_pattern(*include, value); + } else if(xstreq(node->name, "exclude")) { + *exclude = add_regex_pattern(*exclude, value); + } + } + + node = node->next; + } + + return 0; +} + int scfg_load_directory(xmlNode *node) { char *name = NULL; char *path = NULL; @@ -129,7 +150,7 @@ char *database = NULL; UcxList *include = NULL; UcxList *exclude = NULL; - int max_retry = DAV_MAX_RETRY; + int max_retry = 0; bool backuppull = false; bool lockpull = false; bool lockpush = false; @@ -150,18 +171,18 @@ collection = value; } else if(xstreq(node->name, "repository")) { repository = value; + } else if(xstreq(node->name, "filter")) { + if(scfg_load_filter(node, &include, &exclude)) { + return -1; + } } else if(xstreq(node->name, "database")) { database = value; - } else if(xstreq(node->name, "include")) { - include = add_regex_pattern(include, value); - } else if(xstreq(node->name, "exclude")) { - exclude = add_regex_pattern(exclude, value); } else if(xstreq(node->name, "max-retry")) { int64_t i; - if(util_strtoint(value, &i)) { + if(util_strtoint(value, &i) && i >= 0) { max_retry = (int)i; } else { - fprintf(stderr, "Warnung: sync.xml: integer value " + fprintf(stderr, "Warning: sync.xml: unsigned integer value " "expected in <max-retry> element\n"); } } else if(xstreq(node->name, "backup-on-pull")) {
--- a/dav/scfg.h Wed Jul 13 14:11:34 2016 +0200 +++ b/dav/scfg.h Wed Jul 13 14:38:17 2016 +0200 @@ -38,7 +38,6 @@ extern "C" { #endif -#define DAV_MAX_RETRY 1 typedef struct SyncDirectory { char *name;
--- a/dav/sync.c Wed Jul 13 14:11:34 2016 +0200 +++ b/dav/sync.c Wed Jul 13 14:38:17 2016 +0200 @@ -1099,7 +1099,7 @@ int ret = -1; int created = 0; - for(int i=0;i<dir->max_retry;i++) { + for(int i=0;i<=dir->max_retry;i++) { if(!created && dav_create(res)) { continue; } @@ -1166,7 +1166,7 @@ int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local) { res->iscollection = 1; int ret = -1; - for(int i=0;i<dir->max_retry;i++) { + for(int i=0;i<=dir->max_retry;i++) { if(dav_create(res)) { continue; }