--- a/dav/scfg.c Tue Aug 05 13:05:03 2014 +0200 +++ b/dav/scfg.c Tue Aug 05 14:00:35 2014 +0200 @@ -29,7 +29,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> - #include <libidav/utils.h> #include <ucx/map.h> @@ -76,12 +75,24 @@ return ret; } +static UcxList* add_regex_pattern(UcxList *list, char *value) { + regex_t *regex = malloc(sizeof(regex_t)); + if (regcomp(regex, value, REG_EXTENDED|REG_NOSUB)) { + fprintf(stderr, "Invalid regular expression (%s) ... skipped\n", value); + return list; + } else { + return ucx_list_append(list, regex); + } +} + int scfg_load_directory(xmlNode *node) { char *name = NULL; char *path = NULL; char *collection = NULL; char *repository = NULL; char *database = NULL; + UcxList *include = NULL; + UcxList *exclude = NULL; node = node->children; while(node) { @@ -99,6 +110,10 @@ repository = value; } 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); } } node = node->next; @@ -127,6 +142,20 @@ dir->collection = collection ? strdup(collection) : NULL; dir->repository = strdup(repository); dir->database = strdup(database); + if (include) { + dir->include = include; + } else { + regex_t *matchall = malloc(sizeof(regex_t)); + regcomp(matchall, ".*", REG_NOSUB); + dir->include = ucx_list_append(NULL, matchall); + } + if (exclude) { + dir->exclude = exclude; + } else { + regex_t *matchnothing = malloc(sizeof(regex_t)); + regcomp(matchnothing, "///", REG_NOSUB); + dir->exclude = ucx_list_append(NULL, matchnothing); + } ucx_map_cstr_put(directories, name, dir); @@ -134,20 +163,23 @@ } void scfg_print_example() { - fprintf(stderr, "example sync.xml\n\n"); - fprintf(stderr, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); - fprintf(stderr, "<configuration>\n"); - fprintf(stderr, " <directory>\n"); - fprintf(stderr, " <!-- identifier -->\n"); - fprintf(stderr, " <name>documents</name>\n\n"); - fprintf(stderr, " <!-- local path to the directory -->\n"); - fprintf(stderr, " <path>/home/user/Documents</path>\n\n"); - fprintf(stderr, " <!-- repository name specified in config.xml -->\n"); - fprintf(stderr, " <repository>server</repository>\n\n"); - fprintf(stderr, " <!-- database file name -->\n"); - fprintf(stderr, " <database>documents-db.xml</database>\n"); - fprintf(stderr, " </directory>\n"); - fprintf(stderr, "</configuration>\n"); + fprintf(stderr, + "example sync.xml\n\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<configuration>\n" + " <directory>\n" + " <!-- identifier -->\n" + " <name>documents</name>\n\n" + " <!-- local path to the directory -->\n" + " <path>/home/user/Documents</path>\n\n" + " <!-- repository name specified in config.xml -->\n" + " <repository>server</repository>\n\n" + " <!-- collection to synchronize (optional) -->\n" + " <collection>somecol</collection>\n\n" + " <!-- database file name -->\n" + " <database>documents-db.xml</database>\n" + " </directory>\n" + "</configuration>\n"); } SyncDirectory* scfg_get_dir(char *name) {