src/server/config/initconf.c

changeset 25
5dee29c7c530
parent 21
627b09ee74e4
child 44
3da1f7b6847f
equal deleted inserted replaced
24:1a7853a4257e 25:5dee29c7c530
35 InitConfig *load_init_config(char *file) { 35 InitConfig *load_init_config(char *file) {
36 FILE *in = fopen(file, "r"); 36 FILE *in = fopen(file, "r");
37 if(in == NULL) { 37 if(in == NULL) {
38 return NULL; 38 return NULL;
39 } 39 }
40 40
41 InitConfig *conf = malloc(sizeof(InitConfig)); 41 InitConfig *conf = malloc(sizeof(InitConfig));
42 conf->parser.parse = initconf_parse; 42 conf->parser.parse = initconf_parse;
43 conf->file = file; 43 conf->file = file;
44 conf->directives = NULL;
44 45
45 int r = cfg_parse_basic_file((ConfigParser*)conf, in); 46 int r = cfg_parse_basic_file((ConfigParser*)conf, in);
46 if(r != 0) { 47 if(r != 0) {
47 // TODO: free 48 // TODO: free
48 return NULL; 49 return NULL;
62 free(conf); 63 free(conf);
63 } 64 }
64 65
65 int initconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { 66 int initconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) {
66 InitConfig *conf = p; 67 InitConfig *conf = p;
67 68
68 // parse directive 69 // parse directive
69 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); 70 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp);
70 if(d == NULL) { 71 if(d == NULL) {
71 fprintf(stderr, "Error: initconf_parse: directive is null\n"); 72 fprintf(stderr, "Error: initconf_parse: directive is null\n");
72 return 0; 73 return 0;
74 d->begin = begin; 75 d->begin = begin;
75 d->end = end; 76 d->end = end;
76 if(d->type_num == 6) { 77 if(d->type_num == 6) {
77 conf->directives = ucx_dlist_append(conf->directives, d); 78 conf->directives = ucx_dlist_append(conf->directives, d);
78 } else { 79 } else {
79 fprintf(stderr, "Warning: Non Init directive in init.conf"); 80 fprintf(stderr, "Warning: Non Init directive in init.conf\n");
80 } 81 }
81 82
82 return 0; 83 return 0;
83 } 84 }

mercurial