dav/scfg.c

changeset 361
b6f2462ee055
parent 347
b6ff6be7aa91
child 363
e9ed8e130ccf
--- a/dav/scfg.c	Mon Dec 18 16:24:32 2017 +0100
+++ b/dav/scfg.c	Mon Jan 01 19:53:36 2018 +0100
@@ -125,6 +125,72 @@
     return 0;
 }
 
+
+static char* get_attr_content(xmlNode *node) {
+    // TODO: remove code duplication (util_xml_get_text) and config.h
+    while(node) {
+        if(node->type == XML_TEXT_NODE) {
+            return (char*)node->content;
+        }
+        node = node->next;
+    }
+    return NULL;
+}
+
+static TagFormat str2tagformat(const char *str) {
+    if(!strcmp(str, "text")) {
+        return TAG_FORMAT_TEXT;
+    } else if(!strcmp(str, "csv")) {
+        return TAG_FORMAT_CSV;
+    } else if(!strcmp(str, "xml")) {
+        return TAG_FORMAT_XML;
+    }
+    return TAG_FORMAT_UNKNOWN;
+}
+
+static TagConfig* parse_tagconfig(xmlNode *node) {
+    TagConfig conf;
+    conf.store = TAG_STORE_XATTR;
+    conf.local_format = TAG_FORMAT_TEXT;
+    conf.server_format = TAG_FORMAT_XML;
+    xmlNode *c = node->children;
+    
+    // TODO: error handling
+    while(c) {
+        if(node->type == XML_ELEMENT_NODE) {
+            char *value = util_xml_get_text(c);
+            if(xstreq(c->name, "local-store")) {  
+                if(!value) {
+                    return NULL;
+                } else if(xstreq(value, "xattr")) {
+                    conf.store = TAG_STORE_XATTR;
+                } else {
+                    return NULL;
+                }
+                
+                xmlAttr *attr = c->properties;
+                while(attr) {
+                    if(attr->type == XML_ATTRIBUTE_NODE) {
+                        const char *value = get_attr_content(attr->children);
+                        if(!value) {
+                            break;
+                        }
+                        if(xstreq(attr->name, "format")) {
+                            conf.local_format = str2tagformat(value);
+                        }
+                    }
+                    attr = attr->next;
+                }
+            }
+        }
+        c = c->next;
+    }
+    
+    TagConfig *tagconfig = malloc(sizeof(TagConfig));
+    *tagconfig = conf;
+    return tagconfig;
+}
+
 static int scfg_load_directory(xmlNode *node) {
     char *name = NULL;
     char *path = NULL;
@@ -132,6 +198,7 @@
     char *collection = NULL;
     char *repository = NULL;
     char *database = NULL;
+    TagConfig *tagconfig = NULL;
     UcxList *include = NULL;
     UcxList *exclude = NULL;
     int max_retry = 0;
@@ -172,6 +239,8 @@
                 }
             } else if(xstreq(node->name, "database")) {
                 database = value;
+            } else if(xstreq(node->name, "tags")) {
+                tagconfig = parse_tagconfig(node);
             } else if(xstreq(node->name, "max-retry")) {
                 int64_t i;
                 if(util_strtoint(value, &i) && i >= 0) {
@@ -247,6 +316,7 @@
     dir->collection = collection ? strdup(collection) : NULL;
     dir->repository = strdup(repository);
     dir->database = strdup(database);
+    dir->tagconfig = tagconfig;
     dir->max_retry = max_retry;
     dir->allow_cmd = allow_cmd;
     dir->backuppull = backuppull;

mercurial