dav/config.c

changeset 32
c9d37bb97ea8
parent 21
78935b45e2ce
child 33
0bbbb0341606
equal deleted inserted replaced
31:59cdf7b7316f 32:c9d37bb97ea8
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> 32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <ucx/map.h> 33 #include <ucx/map.h>
35 #include <errno.h> 34 #include <errno.h>
36 #include <libxml/tree.h> 35 #include <libxml/tree.h>
37 36
38 #include "config.h" 37 #include "config.h"
39 #include "utils.h" 38 #include "utils.h"
40 39
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) 40 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
42 41
42 #ifdef _WIN32
43 #define ENV_HOME getenv("USERPROFILE")
44 #else
45 #define ENV_HOME getenv("HOME")
46 #endif /* _WIN32 */
47
43 static UcxMap *repos; 48 static UcxMap *repos;
44 static UcxMap *keys; 49 static UcxMap *keys;
45 50
46 int check_config_dir() { 51 int check_config_dir() {
47 char *file = util_concat_path(getenv("HOME"), ".dav"); 52 char *file = util_concat_path(ENV_HOME, ".dav");
48 int ret = 0; 53 int ret = 0;
49 if(mkdir(file, S_IRWXU)) { 54 if(util_mkdir(file, S_IRWXU)) {
50 if(errno != EEXIST) { 55 if(errno != EEXIST) {
51 ret = 1; 56 ret = 1;
52 } 57 }
53 } 58 }
54 free(file); 59 free(file);
60 keys = ucx_map_new(16); 65 keys = ucx_map_new(16);
61 if(check_config_dir()) { 66 if(check_config_dir()) {
62 return; 67 return;
63 } 68 }
64 69
65 char *file = util_concat_path(getenv("HOME"), ".dav/config.xml"); 70 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
66 xmlDoc *doc = xmlReadFile(file, NULL, 0); 71 xmlDoc *doc = xmlReadFile(file, NULL, 0);
67 if(!doc) { 72 if(!doc) {
68 doc = xmlNewDoc(BAD_CAST "1.0"); 73 doc = xmlNewDoc(BAD_CAST "1.0");
69 xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration"); 74 xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration");
70 xmlDocSetRootElement(doc, root); 75 xmlDocSetRootElement(doc, root);
198 203
199 FILE *file = NULL; 204 FILE *file = NULL;
200 if(filename[0] == '/') { 205 if(filename[0] == '/') {
201 file = fopen(filename, "r"); 206 file = fopen(filename, "r");
202 } else { 207 } else {
203 char *path = util_concat_path(getenv("HOME"), ".dav/"); 208 char *path = util_concat_path(ENV_HOME, ".dav/");
204 char *p2 = util_concat_path(path, filename); 209 char *p2 = util_concat_path(path, filename);
205 file = fopen(p2, "r"); 210 file = fopen(p2, "r");
206 free(path); 211 free(path);
207 free(p2); 212 free(p2);
208 } 213 }

mercurial