dav/scfg.c

changeset 491
fdc2fb090cc7
parent 490
d94c4fd35c21
child 521
c5bbae4b3cca
equal deleted inserted replaced
490:d94c4fd35c21 491:fdc2fb090cc7
175 return TAG_FORMAT_MACOS; 175 return TAG_FORMAT_MACOS;
176 } 176 }
177 return TAG_FORMAT_UNKNOWN; 177 return TAG_FORMAT_UNKNOWN;
178 } 178 }
179 179
180 #define CHECK_VALUE(element, value) if(!(value)) \
181 print_error(element->line, "missing value element: %s\n", element->name);
182
180 static TagConfig* parse_tagconfig(xmlNode *node) { 183 static TagConfig* parse_tagconfig(xmlNode *node) {
181 TagConfig conf; 184 TagConfig conf;
182 conf.store = TAG_STORE_XATTR; 185 conf.store = TAG_STORE_XATTR;
183 conf.local_format = TAG_FORMAT_TEXT; 186 conf.local_format = TAG_FORMAT_TEXT;
184 conf.server_format = TAG_FORMAT_XML; 187 conf.server_format = TAG_FORMAT_XML;
189 192
190 // TODO: error handling 193 // TODO: error handling
191 while(c) { 194 while(c) {
192 if(c->type == XML_ELEMENT_NODE) { 195 if(c->type == XML_ELEMENT_NODE) {
193 char *value = util_xml_get_text(c); 196 char *value = util_xml_get_text(c);
194 if(xstreq(c->name, "local-store")) { 197 if(xstreq(c->name, "local-store")) {
195 if(!value) { 198 CHECK_VALUE(c, value);
196 return NULL; 199 if(xstreq(value, "xattr")) {
197 } else if(xstreq(value, "xattr")) {
198 conf.store = TAG_STORE_XATTR; 200 conf.store = TAG_STORE_XATTR;
199 } else { 201 } else {
200 return NULL; 202 return NULL;
201 } 203 }
202 204
205 if(format) { 207 if(format) {
206 conf.local_format = str2tagformat((char*)format); 208 conf.local_format = str2tagformat((char*)format);
207 xmlFree(format); 209 xmlFree(format);
208 } 210 }
209 } else if(xstreq(c->name, "detect-changes")) { 211 } else if(xstreq(c->name, "detect-changes")) {
210 if(!value) { 212 CHECK_VALUE(c, value);
211 return NULL;
212 }
213 conf.detect_changes = util_getboolean(value); 213 conf.detect_changes = util_getboolean(value);
214 } else if(xstreq(c->name, "xattr-name")) { 214 } else if(xstreq(c->name, "xattr-name")) {
215 if(!value) { 215 if(!value) {
216 return NULL; 216 return NULL;
217 } 217 }
218 conf.xattr_name = strdup(value); 218 conf.xattr_name = strdup(value);
219 } else if(xstreq(c->name, "on-conflict")) { 219 } else if(xstreq(c->name, "on-conflict")) {
220 if(!value) { 220 CHECK_VALUE(c, value);
221 return NULL;
222 }
223 if(xstreq(value, "no_conflict")) { 221 if(xstreq(value, "no_conflict")) {
224 conf.conflict = TAG_NO_CONFLICT; 222 conf.conflict = TAG_NO_CONFLICT;
225 } else if(xstreq(value, "keep_local")) { 223 } else if(xstreq(value, "keep_local")) {
226 conf.conflict = TAG_KEEP_LOCAL; 224 conf.conflict = TAG_KEEP_LOCAL;
227 } else if(xstreq(value, "keep_remote")) { 225 } else if(xstreq(value, "keep_remote")) {
250 TagConfig *tagconfig = malloc(sizeof(TagConfig)); 248 TagConfig *tagconfig = malloc(sizeof(TagConfig));
251 *tagconfig = conf; 249 *tagconfig = conf;
252 return tagconfig; 250 return tagconfig;
253 } 251 }
254 252
253 static Versioning* parse_versioning_config(xmlNode *node) {
254 Versioning v;
255 v.always = FALSE;
256 v.type = VERSIONING_SIMPLE;
257 v.collection = "/.dav-version-history";
258
259 xmlNode *c = node->children;
260 while(c) {
261 if(c->type == XML_ELEMENT_NODE) {
262 char *value = util_xml_get_text(c);
263 if(xstreq(c->name, "type")) {
264 CHECK_VALUE(c, value);
265 if(!strcmp(value, "simple")) {
266 v.type = VERSIONING_SIMPLE;
267 } else if(!strcmp(value, "deltav")) {
268 v.type = VERSIONING_DELTAV;
269 } else {
270 return NULL;
271 }
272 } else if(xstreq(c->name, "collection")) {
273 CHECK_VALUE(c, value);
274 v.collection = value;
275 } else if(xstreq(c->name, "always")) {
276 CHECK_VALUE(c, value);
277 v.always = util_getboolean(value);
278 }
279 }
280 c = c->next;
281 }
282
283 v.collection = strdup(v.collection);
284
285 Versioning *versioning = malloc(sizeof(Versioning));
286 *versioning = v;
287 return versioning;
288 }
289
255 static int scfg_load_directory(xmlNode *node) { 290 static int scfg_load_directory(xmlNode *node) {
256 char *name = NULL; 291 char *name = NULL;
257 char *path = NULL; 292 char *path = NULL;
258 char *trash = NULL; 293 char *trash = NULL;
259 char *collection = NULL; 294 char *collection = NULL;
260 char *repository = NULL; 295 char *repository = NULL;
261 char *database = NULL; 296 char *database = NULL;
262 TagConfig *tagconfig = NULL; 297 TagConfig *tagconfig = NULL;
298 Versioning *versioning = NULL;
263 UcxList *include = NULL; 299 UcxList *include = NULL;
264 UcxList *exclude = NULL; 300 UcxList *exclude = NULL;
265 UcxList *tagfilter = NULL; 301 UcxList *tagfilter = NULL;
266 int max_retry = 0; 302 int max_retry = 0;
267 int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH 303 int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH
302 } 338 }
303 } else if(xstreq(node->name, "database")) { 339 } else if(xstreq(node->name, "database")) {
304 database = value; 340 database = value;
305 } else if(xstreq(node->name, "tagconfig")) { 341 } else if(xstreq(node->name, "tagconfig")) {
306 tagconfig = parse_tagconfig(node); 342 tagconfig = parse_tagconfig(node);
343 } else if(xstreq(node->name, "versioning")) {
344 versioning = parse_versioning_config(node);
307 } else if(xstreq(node->name, "max-retry")) { 345 } else if(xstreq(node->name, "max-retry")) {
308 int64_t i; 346 int64_t i;
309 if(util_strtoint(value, &i) && i >= 0) { 347 if(util_strtoint(value, &i) && i >= 0) {
310 max_retry = (int)i; 348 max_retry = (int)i;
311 } else { 349 } else {
380 dir->path = scfg_create_path(path); 418 dir->path = scfg_create_path(path);
381 dir->collection = collection ? strdup(collection) : NULL; 419 dir->collection = collection ? strdup(collection) : NULL;
382 dir->repository = strdup(repository); 420 dir->repository = strdup(repository);
383 dir->database = strdup(database); 421 dir->database = strdup(database);
384 dir->tagconfig = tagconfig; 422 dir->tagconfig = tagconfig;
423 dir->versioning = versioning;
385 dir->max_retry = max_retry; 424 dir->max_retry = max_retry;
386 dir->allow_cmd = allow_cmd; 425 dir->allow_cmd = allow_cmd;
387 dir->backuppull = backuppull; 426 dir->backuppull = backuppull;
388 dir->lockpull = lockpull; 427 dir->lockpull = lockpull;
389 dir->lockpush = lockpush; 428 dir->lockpush = lockpush;

mercurial