diff -r 1d2be1b31e70 -r d7c4ba50b7d8 dav/scfg.c --- a/dav/scfg.c Mon Nov 14 19:02:40 2016 +0100 +++ b/dav/scfg.c Fri Nov 18 13:39:20 2016 +0100 @@ -39,13 +39,17 @@ #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) -#define print_error(...) \ +#define print_error(lineno, ...) \ do {\ - fprintf(stderr, "Error (sync.xml): " __VA_ARGS__); \ + fprintf(stderr, "Error (sync.xml line %u): ", lineno); \ + fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "Abort.\n"); \ } while(0); -#define print_warning(...) \ - fprintf(stderr, "Warning (sync.xml): " __VA_ARGS__); +#define print_warning(lineno, ...) \ + do {\ + fprintf(stderr, "Warning (sync.xml line %u): ", lineno); \ + fprintf(stderr, __VA_ARGS__); \ + } while(0); #ifdef _WIN32 #define ENV_HOME getenv("USERPROFILE") @@ -106,7 +110,8 @@ if(xstreq(node->name, "directory")) { ret = scfg_load_directory(node); } else { - print_error("unknown config element: %s\n", node->name); + print_error(node->line, + "unknown config element: %s\n", node->name); ret = 1; } } @@ -118,17 +123,20 @@ return ret; } -static UcxList* add_regex_pattern(UcxList *list, char *value) { +static UcxList* add_regex_pattern(UcxList *list, char *value, + unsigned short xmlline) { regex_t *regex = malloc(sizeof(regex_t)); if (regcomp(regex, value, REG_EXTENDED|REG_NOSUB)) { - fprintf(stderr, "Invalid regular expression (%s) ... skipped\n", value); + print_warning(xmlline, + "Invalid regular expression (%s) ... skipped\n", value); return list; } else { return ucx_list_append(list, regex); } } -static int scfg_load_filter(xmlNode *node, UcxList **include, UcxList **exclude) { +static int scfg_load_filter(xmlNode *node, + UcxList **include, UcxList **exclude) { node = node->children; while(node) { @@ -136,18 +144,20 @@ char *value = util_xml_get_text(node); if(xstreq(node->name, "include")) { if(value) { - *include = add_regex_pattern(*include, value); + *include = add_regex_pattern(*include, value, node->line); } } else if(xstreq(node->name, "exclude")) { if(value) { - *exclude = add_regex_pattern(*exclude, value); + *exclude = add_regex_pattern(*exclude, value, node->line); } } else { - print_error("unknown filter config element: %s\n", node->name); + print_error(node->line, + "unknown filter config element: %s\n", node->name); return 1; } if(!value) { - print_error("missing value for filter: %s\n", node->name); + print_error(node->line, + "missing value for filter: %s\n", node->name); return 1; } } @@ -172,6 +182,7 @@ bool lockpull = false; bool lockpush = false; + unsigned short parentlineno = node->line; node = node->children; while(node) { if(node->type == XML_ELEMENT_NODE) { @@ -181,7 +192,8 @@ /* TODO: maybe this should only be reported, if the key is valid * But this makes the code very ugly. */ - print_error("missing value for directory element: %s\n", + print_error(node->line, + "missing value for directory element: %s\n", node->name); return 1; } @@ -206,7 +218,7 @@ if(util_strtoint(value, &i) && i >= 0) { max_retry = (int)i; } else { - print_warning("unsigned integer value " + print_warning(node->line, "unsigned integer value " "expected in element\n"); } } else if(xstreq(node->name, "backup-on-pull")) { @@ -216,8 +228,8 @@ } else if(xstreq(node->name, "lock-push")) { lockpush = util_getboolean(value); } else { - print_error("unknown directory config element: %s\n", - node->name); + print_error(node->line, + "unknown directory config element: %s\n", node->name); return 1; } } @@ -225,19 +237,22 @@ } if(!name) { - print_error("missing name element for directory\n"); + print_error(parentlineno, "missing name element for directory\n"); return 1; } if(!path) { - print_error("missing path element for directory %s\n", name); + print_error(parentlineno, + "missing path element for directory %s\n", name); return 1; } if(!repository) { - print_error("missing repository element for directory %s\n", name); + print_error(parentlineno, + "missing repository element for directory %s\n", name); return 1; } if(!database) { - print_error("missing database element for directory %s\n", name); + print_error(parentlineno, + "missing database element for directory %s\n", name); return 1; }