diff -r 99a34860c105 -r d938228c382e src/server/config/objconf.c --- a/src/server/config/objconf.c Wed Nov 02 19:19:01 2022 +0100 +++ b/src/server/config/objconf.c Sun Nov 06 15:53:32 2022 +0100 @@ -30,6 +30,8 @@ #include +#include + /* dev notes: * * to free ObjectConfig, free: @@ -47,9 +49,9 @@ ObjectConfig *conf = malloc(sizeof(ObjectConfig)); conf->parser.parse = objconf_parse; conf->file = file; - conf->conditions = NULL; + //conf->conditions = NULL; conf->levels = NULL; - conf->objects = NULL; + conf->objects = cxPointerLinkedListCreate(cxDefaultAllocator, cx_cmp_ptr); //conf->lines = NULL; int r = cfg_parse_basic_file((ConfigParser*)conf, in); @@ -70,13 +72,13 @@ } // free mempool - ucx_mempool_destroy(conf->parser.mp->pool); + //ucx_mempool_destroy(conf->parser.mp->pool); free(conf); } -int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { +int objconf_parse(void *p, ConfigLine *begin, ConfigLine *end, cxmutstr line) { ObjectConfig *conf = p; begin->type = cfg_get_line_type(line); @@ -89,8 +91,8 @@ } tag->begin = begin; tag->end = end; - tag->type_num = cfg_get_tag_type(tag->name); - //printf("line {%s}\n", sstrdub(ll).ptr); + tag->type_num = cfg_get_tag_type(cx_strcast(tag->name)); + //printf("line {%s}\n", cx_strdub(ll).ptr); if(objconf_on_begin_tag(conf, tag) != 0) { fprintf(stderr, "1error\n"); exit(-1); @@ -98,7 +100,7 @@ break; } case LINE_END_TAG: { - sstr_t tag = cfg_get_end_tag_name(line); + cxmutstr tag = cfg_get_end_tag_name(line); if(objconf_on_end_tag(conf, tag) != 0) { fprintf(stderr, "2error\n"); exit(-1); @@ -122,9 +124,9 @@ } int objconf_on_begin_tag(ObjectConfig *conf, ConfigTag *tag) { - UcxAllocator *mp = conf->parser.mp; + CxAllocator *mp = conf->parser.mp; if(tag->type_num != TAG_OBJECT) { - ConfigParserLevel *l = conf->levels->data; + ConfigParserLevel *l = conf->levels; if(l->tag->type_num != TAG_OBJECT) { tag->parent = l->tag; } @@ -137,31 +139,35 @@ obj->begin = tag->begin; obj->end = tag->end; - obj->name = cfg_param_get(tag->param, sstr("name")); - obj->ppath = cfg_param_get(tag->param, sstr("ppath")); + obj->name = cfg_param_get(tag->param, cx_str("name")); + obj->ppath = cfg_param_get(tag->param, cx_str("ppath")); conf->obj = obj; - conf->objects = ucx_list_append_a(mp, conf->objects, obj); + //conf->objects = ucx_list_append_a(mp, conf->objects, obj); + cxListAdd(conf->objects, obj); // create tree level object ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); lvl->iftag = NULL; lvl->levelnum = 1; lvl->tag = tag; - conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); + lvl->next = NULL; + //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); + CFG_LEVEL_PREPEND(&conf->levels, lvl); break; } case TAG_IF: { // create tree level object - ConfigParserLevel *last_lvl = conf->levels->data; + ConfigParserLevel *last_lvl = conf->levels; ConfigParserLevel *lvl = OBJ_NEW(mp, ConfigParserLevel); lvl->iftag = NULL; lvl->levelnum = last_lvl->levelnum + 1; lvl->tag = tag; - conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); + //conf->levels = ucx_list_prepend_a(mp, conf->levels, lvl); + CFG_LEVEL_PREPEND(&conf->levels, lvl); last_lvl->iftag = tag; break; @@ -170,7 +176,7 @@ } case TAG_ELSE: { // create tree level object - ConfigParserLevel *last_lvl = conf->levels->data; + ConfigParserLevel *last_lvl = conf->levels; tag->iftag = last_lvl->iftag; ConfigParserLevel *lvl = OBJ_NEW( @@ -180,7 +186,8 @@ lvl->iftag = last_lvl->tag; lvl->levelnum = last_lvl->levelnum + 1; lvl->tag = tag; - conf->levels = ucx_list_prepend(conf->levels, lvl); + //conf->levels = ucx_list_prepend(conf->levels, lvl); + CFG_LEVEL_PREPEND(&conf->levels, lvl); break; } @@ -200,8 +207,8 @@ return 0; } -int objconf_on_end_tag(ObjectConfig *conf, sstr_t tagname) { - int type = cfg_get_tag_type(tagname); +int objconf_on_end_tag(ObjectConfig *conf, cxmutstr tagname) { + int type = cfg_get_tag_type(cx_strcast(tagname)); if(type == -1) { log_ereport(LOG_FAILURE, "objconf: unknown tag"); return 1; @@ -211,17 +218,20 @@ } // remove level + /* conf->levels = ucx_list_remove_a( conf->parser.mp, conf->levels, conf->levels); + */ + conf->levels = conf->levels->next; } return 0; } int objconf_on_directive(ObjectConfig *conf, ConfigDirective *dir) { - ConfigParserLevel *lvl = conf->levels->data; + ConfigParserLevel *lvl = conf->levels; // check if we have a condition for the directive // if the level tag is not an object tag, use it as condition @@ -230,10 +240,17 @@ } // add directive to current object + /* conf->obj->directives[dir->type_num] = ucx_list_append_a( conf->parser.mp, conf->obj->directives[dir->type_num], dir); + */ + + ConfigDirectiveList *dir_entry = cxMalloc(conf->parser.mp, sizeof(ConfigDirectiveList)); + dir_entry->directive = dir; + dir_entry->next = NULL; + CFG_DIRECTIVES_ADD(&conf->obj->directives[dir->type_num], dir_entry); return 0; }