27 */ |
27 */ |
28 |
28 |
29 #include <stdio.h> |
29 #include <stdio.h> |
30 #include <stdlib.h> |
30 #include <stdlib.h> |
31 #include <string.h> |
31 #include <string.h> |
|
32 #include <sys/types.h> |
|
33 #include <sys/stat.h> |
32 #include <ucx/map.h> |
34 #include <ucx/map.h> |
|
35 #include <errno.h> |
33 #include <libxml/tree.h> |
36 #include <libxml/tree.h> |
34 |
37 |
35 #include "config.h" |
38 #include "config.h" |
36 #include "utils.h" |
39 #include "utils.h" |
37 |
40 |
38 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
39 |
42 |
40 static UcxMap *repos; |
43 static UcxMap *repos; |
41 static UcxMap *keys; |
44 static UcxMap *keys; |
|
45 |
|
46 int check_config_dir() { |
|
47 char *file = util_concat_path(getenv("HOME"), ".dav"); |
|
48 int ret = 0; |
|
49 if(mkdir(file, S_IRWXU)) { |
|
50 if(errno != EEXIST) { |
|
51 ret = 1; |
|
52 } |
|
53 } |
|
54 free(file); |
|
55 return ret; |
|
56 } |
42 |
57 |
43 void load_config() { |
58 void load_config() { |
44 repos = ucx_map_new(16); |
59 repos = ucx_map_new(16); |
45 keys = ucx_map_new(16); |
60 keys = ucx_map_new(16); |
|
61 if(check_config_dir()) { |
|
62 return; |
|
63 } |
46 |
64 |
47 char *file = util_concat_path(getenv("HOME"), ".dav/config.xml"); |
65 char *file = util_concat_path(getenv("HOME"), ".dav/config.xml"); |
48 xmlDoc *doc = xmlReadFile(file, NULL, 0); |
66 xmlDoc *doc = xmlReadFile(file, NULL, 0); |
49 if(!doc) { |
67 if(!doc) { |
50 doc = xmlNewDoc(BAD_CAST "1.0"); |
68 doc = xmlNewDoc(BAD_CAST "1.0"); |