dav/scfg.c

changeset 361
b6f2462ee055
parent 347
b6ff6be7aa91
child 363
e9ed8e130ccf
equal deleted inserted replaced
355:5da2cf15eb44 361:b6f2462ee055
123 } 123 }
124 124
125 return 0; 125 return 0;
126 } 126 }
127 127
128
129 static char* get_attr_content(xmlNode *node) {
130 // TODO: remove code duplication (util_xml_get_text) and config.h
131 while(node) {
132 if(node->type == XML_TEXT_NODE) {
133 return (char*)node->content;
134 }
135 node = node->next;
136 }
137 return NULL;
138 }
139
140 static TagFormat str2tagformat(const char *str) {
141 if(!strcmp(str, "text")) {
142 return TAG_FORMAT_TEXT;
143 } else if(!strcmp(str, "csv")) {
144 return TAG_FORMAT_CSV;
145 } else if(!strcmp(str, "xml")) {
146 return TAG_FORMAT_XML;
147 }
148 return TAG_FORMAT_UNKNOWN;
149 }
150
151 static TagConfig* parse_tagconfig(xmlNode *node) {
152 TagConfig conf;
153 conf.store = TAG_STORE_XATTR;
154 conf.local_format = TAG_FORMAT_TEXT;
155 conf.server_format = TAG_FORMAT_XML;
156 xmlNode *c = node->children;
157
158 // TODO: error handling
159 while(c) {
160 if(node->type == XML_ELEMENT_NODE) {
161 char *value = util_xml_get_text(c);
162 if(xstreq(c->name, "local-store")) {
163 if(!value) {
164 return NULL;
165 } else if(xstreq(value, "xattr")) {
166 conf.store = TAG_STORE_XATTR;
167 } else {
168 return NULL;
169 }
170
171 xmlAttr *attr = c->properties;
172 while(attr) {
173 if(attr->type == XML_ATTRIBUTE_NODE) {
174 const char *value = get_attr_content(attr->children);
175 if(!value) {
176 break;
177 }
178 if(xstreq(attr->name, "format")) {
179 conf.local_format = str2tagformat(value);
180 }
181 }
182 attr = attr->next;
183 }
184 }
185 }
186 c = c->next;
187 }
188
189 TagConfig *tagconfig = malloc(sizeof(TagConfig));
190 *tagconfig = conf;
191 return tagconfig;
192 }
193
128 static int scfg_load_directory(xmlNode *node) { 194 static int scfg_load_directory(xmlNode *node) {
129 char *name = NULL; 195 char *name = NULL;
130 char *path = NULL; 196 char *path = NULL;
131 char *trash = NULL; 197 char *trash = NULL;
132 char *collection = NULL; 198 char *collection = NULL;
133 char *repository = NULL; 199 char *repository = NULL;
134 char *database = NULL; 200 char *database = NULL;
201 TagConfig *tagconfig = NULL;
135 UcxList *include = NULL; 202 UcxList *include = NULL;
136 UcxList *exclude = NULL; 203 UcxList *exclude = NULL;
137 int max_retry = 0; 204 int max_retry = 0;
138 int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH | SYNC_CMD_ARCHIVE; 205 int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH | SYNC_CMD_ARCHIVE;
139 bool backuppull = false; 206 bool backuppull = false;
170 if(scfg_load_filter(node, &include, &exclude)) { 237 if(scfg_load_filter(node, &include, &exclude)) {
171 return 1; 238 return 1;
172 } 239 }
173 } else if(xstreq(node->name, "database")) { 240 } else if(xstreq(node->name, "database")) {
174 database = value; 241 database = value;
242 } else if(xstreq(node->name, "tags")) {
243 tagconfig = parse_tagconfig(node);
175 } else if(xstreq(node->name, "max-retry")) { 244 } else if(xstreq(node->name, "max-retry")) {
176 int64_t i; 245 int64_t i;
177 if(util_strtoint(value, &i) && i >= 0) { 246 if(util_strtoint(value, &i) && i >= 0) {
178 max_retry = (int)i; 247 max_retry = (int)i;
179 } else { 248 } else {
245 dir->name = strdup(name); 314 dir->name = strdup(name);
246 dir->path = scfg_create_path(path); 315 dir->path = scfg_create_path(path);
247 dir->collection = collection ? strdup(collection) : NULL; 316 dir->collection = collection ? strdup(collection) : NULL;
248 dir->repository = strdup(repository); 317 dir->repository = strdup(repository);
249 dir->database = strdup(database); 318 dir->database = strdup(database);
319 dir->tagconfig = tagconfig;
250 dir->max_retry = max_retry; 320 dir->max_retry = max_retry;
251 dir->allow_cmd = allow_cmd; 321 dir->allow_cmd = allow_cmd;
252 dir->backuppull = backuppull; 322 dir->backuppull = backuppull;
253 dir->lockpull = lockpull; 323 dir->lockpull = lockpull;
254 dir->lockpush = lockpush; 324 dir->lockpush = lockpush;

mercurial