97 int load_config(DavContext *ctx) { |
97 int load_config(DavContext *ctx) { |
98 context = ctx; |
98 context = ctx; |
99 // TODO: free the config somewhere |
99 // TODO: free the config somewhere |
100 repos = ucx_map_new(16); |
100 repos = ucx_map_new(16); |
101 keys = ucx_map_new(16); |
101 keys = ucx_map_new(16); |
102 if(check_config_dir()) { |
|
103 return 1; |
|
104 } |
|
105 |
102 |
106 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
103 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
107 |
104 |
108 struct stat s; |
105 struct stat s; |
109 if(stat(file, &s)) { |
106 if(stat(file, &s)) { |
110 switch(errno) { |
107 switch(errno) { |
111 case ENOENT: { |
108 case ENOENT: { |
112 create_default_config(file); |
|
113 return 0; |
109 return 0; |
114 } |
110 } |
115 default: { |
111 default: { |
116 perror("Cannot load config.xml"); |
112 perror("Cannot load config.xml"); |
117 } |
113 } |
587 } |
583 } |
588 return ucx_map_cstr_get(keys, name); |
584 return ucx_map_cstr_get(keys, name); |
589 } |
585 } |
590 |
586 |
591 int add_repository(Repository *repo) { |
587 int add_repository(Repository *repo) { |
|
588 if(check_config_dir()) { |
|
589 fprintf(stderr, "Cannot create .dav directory\n"); |
|
590 return 1; |
|
591 } |
|
592 |
592 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
593 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
|
594 struct stat s; |
|
595 if(stat(file, &s)) { |
|
596 switch(errno) { |
|
597 case ENOENT: { |
|
598 create_default_config(file); |
|
599 break; |
|
600 } |
|
601 default: { |
|
602 perror("Cannot load config.xml"); |
|
603 free(file); |
|
604 return 1; |
|
605 } |
|
606 } |
|
607 } |
|
608 |
593 xmlDoc *doc = xmlReadFile(file, NULL, 0); |
609 xmlDoc *doc = xmlReadFile(file, NULL, 0); |
594 if(!doc) { |
610 if(!doc) { |
595 free(file); |
611 free(file); |
596 fprintf(stderr, "Cannot load config.xml\n"); |
612 fprintf(stderr, "Cannot load config.xml\n"); |
597 return 1; |
613 return 1; |