application/config.c

changeset 50
9c25e2616bfa
parent 49
2f71f4ee247a
equal deleted inserted replaced
49:2f71f4ee247a 50:9c25e2616bfa
116 fclose(file); 116 fclose(file);
117 117
118 return cx_mutstrn(buf.space, buf.size); 118 return cx_mutstrn(buf.space, buf.size);
119 } 119 }
120 120
121 int load_config(DavContext* ctx) { 121 int load_config(DavContext *ctx) {
122 context = ctx; 122 context = ctx;
123 // TODO: free the config somewhere 123 // TODO: free the config somewhere
124 repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); 124 repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
125 keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); 125 keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
126 126
127 char* pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt"); 127 char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
128 pstore = pwdstore_open(pwfile); 128 pstore = pwdstore_open(pwfile);
129 free(pwfile); 129 free(pwfile);
130 130
131 char* file = util_concat_path(ENV_HOME, ".dav/config.xml"); 131 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
132 132
133 struct stat s; 133 struct stat s;
134 if (stat(file, &s)) { 134 if(stat(file, &s)) {
135 switch (errno) { 135 switch(errno) {
136 case ENOENT: { 136 case ENOENT: {
137 return 0; 137 davconfig = dav_config_new(NULL);
138 } 138 return 0;
139 default: { 139 }
140 perror("Cannot load config.xml"); 140 default: {
141 } 141 perror("Cannot load config.xml");
142 } 142 }
143 return 1; 143 }
144 } 144 return 1;
145 145 }
146
146 cxmutstr config_content = config_load_file(file); 147 cxmutstr config_content = config_load_file(file);
147 int config_error; 148 int config_error;
148 davconfig = dav_config_load(config_content, &config_error); 149 davconfig = dav_config_load(config_content, &config_error);
149 free(config_content.ptr); 150 free(config_content.ptr);
150 free(file); 151 free(file);
151 152
152 if (!davconfig) { 153 if(!davconfig) {
153 fprintf(stderr, "Cannot load config.xml\n"); 154 fprintf(stderr, "Cannot load config.xml\n");
154 return 1; 155 return 1;
155 } 156 }
156 157
158 if(dav_config_register_namespaces(davconfig, ctx)) {
159 return 1;
160 }
161
157 return dav_config_register_keys(davconfig, ctx, load_key_file); 162 return dav_config_register_keys(davconfig, ctx, load_key_file);
158 } 163 }
159 164
160 DavConfig* get_config(void) { 165 DavConfig* get_config(void) {
161 return davconfig; 166 return davconfig;

mercurial