39 } |
39 } |
40 |
40 |
41 ServerConfig *conf = malloc(sizeof(ServerConfig)); |
41 ServerConfig *conf = malloc(sizeof(ServerConfig)); |
42 conf->parser.parse = serverconf_parse; |
42 conf->parser.parse = serverconf_parse; |
43 conf->file = file; |
43 conf->file = file; |
44 conf->objects = ucx_map_new(161); |
44 conf->objects = ucx_map_new(16); |
45 |
|
46 conf->obj = NULL; |
45 conf->obj = NULL; |
47 |
46 |
48 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
47 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
|
48 cfg_map_destr(conf->parser.mp, conf->objects); |
49 if(r != 0) { |
49 if(r != 0) { |
50 // TODO: free |
50 // TODO: free |
51 return NULL; |
51 return NULL; |
52 } |
52 } |
53 |
53 |
55 |
55 |
56 return conf; |
56 return conf; |
57 } |
57 } |
58 |
58 |
59 void free_server_config(ServerConfig *conf) { |
59 void free_server_config(ServerConfig *conf) { |
60 // TODO |
60 ucx_mempool_free(conf->parser.mp); |
|
61 free(conf); |
61 } |
62 } |
62 |
63 |
63 int serverconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line){ |
64 int serverconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line){ |
64 ServerConfig *conf = p; |
65 ServerConfig *conf = p; |
|
66 UcxMempool *mp = conf->parser.mp; |
65 |
67 |
66 begin->type = cfg_get_line_type(line); |
68 begin->type = cfg_get_line_type(line); |
67 switch(begin->type) { |
69 switch(begin->type) { |
68 case LINE_BEGIN_TAG: { |
70 case LINE_BEGIN_TAG: { |
69 ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp); |
71 ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp); |
77 obj->end = end; |
79 obj->end = end; |
78 obj->directives = NULL; |
80 obj->directives = NULL; |
79 |
81 |
80 // add object to server config |
82 // add object to server config |
81 UcxList *list = ucx_map_sstr_get(conf->objects, obj->type); |
83 UcxList *list = ucx_map_sstr_get(conf->objects, obj->type); |
82 list = ucx_list_append(list, obj); |
84 list = cfg_list_append(mp, list, obj); |
83 ucx_map_sstr_put(conf->objects, obj->type, list); |
85 ucx_map_sstr_put(conf->objects, obj->type, list); |
84 conf->obj = obj; |
86 conf->obj = obj; |
85 |
87 |
86 break; |
88 break; |
87 } |
89 } |
105 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); |
107 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); |
106 d->begin = begin; |
108 d->begin = begin; |
107 d->end = end; |
109 d->end = end; |
108 |
110 |
109 //printf("%s.%s\n", conf->obj->type.ptr, d->directive_type.ptr); |
111 //printf("%s.%s\n", conf->obj->type.ptr, d->directive_type.ptr); |
110 conf->obj->directives = ucx_dlist_append(conf->obj->directives, d); |
112 conf->obj->directives = cfg_dlist_append(mp, conf->obj->directives, d); |
111 } |
113 } |
112 } |
114 } |
113 return 0; |
115 return 0; |
114 } |
116 } |