Tue, 09 Jul 2013 17:16:26 +0200
replaced propfind parser with new libxml2 parser
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2013 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef CFG_CONF_H #define CFG_CONF_H #include <stdio.h> #include <stdlib.h> #include "../ucx/list.h" #include "../ucx/dlist.h" #include "../ucx/map.h" #include "../ucx/mempool.h" #include "../ucx/string.h" #ifdef __cplusplus extern "C" { #endif // mempool malloc macro #define OBJ_NEW(pool, type) (type*)ucx_mempool_malloc(pool, sizeof(type)) #define OBJ_NEW_N(pool, type) (type*)ucx_mempool_calloc(pool, 1, sizeof(type)) // line types #define LINE_OTHER 0 #define LINE_DIRECTIVE 1 #define LINE_BEGIN_TAG 2 #define LINE_END_TAG 3 #define LINE_MULTI 4 #define LINE_NOCONTENT 5 // only comment or space #define LINE_ERROR 6 // parse error on this line // tag types #define TAG_OBJECT 0 #define TAG_IF 1 #define TAG_ELSEIF 2 #define TAG_ELSE 3 #define TAG_CLIENT 4 typedef struct _cfg_line { sstr_t line; // raw line string void *object; // pointer to data struct int type; // type, see line types } ConfigLine; typedef int (*cfg_parse_f)(void *, ConfigLine *, ConfigLine *, sstr_t); typedef struct _cfg_param { sstr_t name; sstr_t value; } ConfigParam; typedef struct _cfg_parser { UcxMempool *mp; UcxDlist *lines; cfg_parse_f parse; } ConfigParser; typedef struct _conf_tag ConfigTag; struct _conf_tag { ConfigLine *begin; ConfigLine *end; sstr_t name; UcxList *param; sstr_t param_str; ConfigTag *parent; ConfigTag *iftag; // only used by <ElseIf> and <Else> int type_num; }; typedef struct _conf_directive { ConfigLine *begin; ConfigLine *end; sstr_t directive_type; sstr_t value; //UcxList *param; ConfigTag *condition; int type_num; } ConfigDirective; int cfg_parse_basic_file(ConfigParser *parser, FILE *in); sstr_t cfg_readln(FILE *file); sstr_t cfg_trim_comment(sstr_t line); sstr_t cfg_param(sstr_t params, sstr_t *name, sstr_t *value); sstr_t cfg_param_get(UcxList *list, sstr_t name); ConfigDirective* cfg_parse_directive(sstr_t line, UcxMempool *mp); UcxList* cfg_param_list(sstr_t param_str, UcxMempool *mp); int cfg_get_directive_type_num(sstr_t type); int cfg_get_basic_type(sstr_t line); int cfg_get_line_type(sstr_t line); int cfg_get_tag_type(sstr_t tag); sstr_t cfg_get_end_tag_name(sstr_t line); ConfigTag* cfg_parse_begin_tag(sstr_t line, UcxMempool *mp); ConfigDirective* cfg_directivelist_get(UcxDlist *dirs, sstr_t name); sstr_t cfg_directivelist_get_str(UcxDlist *dirs, sstr_t name); sstr_t cfg_directive_pstr1(ConfigDirective *dir); void cfg_list_destr(UcxMempool *mp, UcxList *list); void cfg_dlist_destr(UcxMempool *mp, UcxDlist *list); void cfg_map_destr(UcxMempool *mp, UcxMap *map); UcxList* cfg_list_append(UcxMempool *mp, UcxList *list, void *data); UcxDlist* cfg_dlist_append(UcxMempool *mp, UcxDlist *list, void *data); #ifdef __cplusplus } #endif #endif /* CFG_CONF_H */