diff -r 9d0505d80044 -r 7eea57f6d847 dav/config.c --- a/dav/config.c Sun Sep 24 11:31:01 2017 +0200 +++ b/dav/config.c Sun Sep 24 14:31:42 2017 +0200 @@ -139,6 +139,8 @@ ret = load_proxy(ctx->http_proxy, node, HTTP_PROXY); } else if (xstreq(node->name, "https-proxy")) { ret = load_proxy(ctx->https_proxy, node, HTTPS_PROXY); + } else if (xstreq(node->name, "namespace")) { + ret = load_namespace(node); } else { fprintf(stderr, "Unknown config element: %s\n", node->name); ret = 1; @@ -496,7 +498,63 @@ fclose(file); return k; -} +} + +static char* get_attr_content(xmlNode *node) { + // TODO: remove code duplication (util_xml_get_text) + while(node) { + if(node->type == XML_TEXT_NODE) { + return (char*)node->content; + } + node = node->next; + } + return NULL; +} + +int load_namespace(const xmlNode *node) { + const char *prefix = NULL; + const char *uri = NULL; + + xmlAttr *attr = node->properties; + while(attr) { + if(attr->type == XML_ATTRIBUTE_NODE) { + char *value = get_attr_content(attr->children); + if(!value) { + print_error( + node->line, + "missing value for attribute %s\n", (char*)attr->name); + return 1; + } + if(xstreq(attr->name, "prefix")) { + prefix = value; + } else if(xstreq(attr->name, "uri")) { + uri = value; + } else { + print_error( + node->line, + "unknown attribute %s\n", (char*)attr->name); + return 1; + } + } + attr = attr->next; + } + + if(!prefix) { + print_error(node->line, "missing prefix attribute\n"); + return 1; + } + if(!uri) { + print_error(node->line, "missing uri attribute\n"); + return 1; + } + + if(dav_get_namespace(context, prefix)) { + fprintf(stderr, "Error: namespace prefix '%s' already used\n", prefix); + return 1; + } + + return dav_add_namespace(context, prefix, uri); +} Repository* get_repository(sstr_t name) { if(!name.ptr) {