diff -r 5b9f20aa88c2 -r 9a4857d6444e dav/scfg.c --- a/dav/scfg.c Thu Mar 21 10:51:14 2019 +0100 +++ b/dav/scfg.c Fri Mar 22 13:07:31 2019 +0100 @@ -250,6 +250,85 @@ return tagconfig; } +static SplitConfig* parse_split(xmlNode *node) { + char *pattern = NULL; + char *minsize = NULL; + char *blocksize = NULL; + + xmlNode *c = node->children; + while(c) { + char *value = util_xml_get_text(c); + if(xstreq(c->name, "pattern")) { + pattern = value; + } else if(xstreq(c->name, "minsize")) { + minsize = value; + } else if(xstreq(c->name, "blocksize")) { + blocksize = value; + } + c = c->next; + } + + uint64_t sz = 0; + if(!blocksize) { + fprintf(stderr, "splitconfig: no blocksize specified\n"); + return NULL; + } + size_t bsz_len = strlen(blocksize); + if(bsz_len < 2) { + fprintf(stderr, "splitconfig: blocksize too small\n"); + return NULL; + } + + if(!util_szstrtouint(blocksize, &sz)) { + fprintf(stderr, "splitconfig: blocksize is not a number\n"); + return NULL; + } + + if(!pattern && !minsize) { + fprintf(stderr, "splitconfig: pattern or minsize must be specified\n"); + return NULL; + } + + int64_t minsz = -1; + if(minsize) { + uint64_t m; + if(!util_szstrtouint(minsize, &m)) { + fprintf(stderr, "splitconfig: minsize is not a number\n"); + return NULL; + } + minsz = (int64_t)m; + } + + SplitConfig *sc = calloc(1, sizeof(SplitConfig)); + sc->pattern = pattern ? strdup(pattern) : NULL; + sc->minsize = minsz; + sc->blocksize = (size_t)sz; + return sc; +} + +static UcxList* parse_splitconfig(xmlNode *node, int *error) { + UcxList *splitconfig = NULL; + int err = 0; + xmlNode *c = node->children; + while(c) { + if(c->type == XML_ELEMENT_NODE && xstreq(c->name, "split")) { + SplitConfig *sc = parse_split(c); + if(sc) { + splitconfig = ucx_list_append(splitconfig, sc); + } else { + err = 1; + break; + } + } + c = c->next; + } + + if(error) { + *error = err; + } + return splitconfig; +} + static Versioning* parse_versioning_config(xmlNode *node) { Versioning v; v.always = FALSE; @@ -299,6 +378,7 @@ UcxList *include = NULL; UcxList *exclude = NULL; UcxList *tagfilter = NULL; + UcxList *splitconfig = NULL; int max_retry = 0; int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH | SYNC_CMD_ARCHIVE | SYNC_CMD_RESTORE; @@ -341,6 +421,12 @@ database = value; } else if(xstreq(node->name, "tagconfig")) { tagconfig = parse_tagconfig(node); + } else if(xstreq(node->name, "splitconfig")) { + int err = 0; + splitconfig = parse_splitconfig(node, &err); + if(err) { + return 1; + } } else if(xstreq(node->name, "metadata")) { char *error = NULL; metadata = parse_finfo_settings(value, &error);