Sat, 31 Oct 2015 18:02:07 +0100
fixed ssl
/* * 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/map.h> #include <ucx/mempool.h> #include <ucx/string.h> #include "../util/object.h" #ifdef __cplusplus extern "C" { #endif // mempool malloc macro #define OBJ_NEW(p, type) (type*)(p)->malloc((p)->pool, sizeof(type)) #define OBJ_NEW_N(p, type) (type*)(p)->calloc((p)->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 #define INIT_DIRECTIVE 16 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 { UcxAllocator *mp; UcxList *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, UcxAllocator *mp); UcxList* cfg_param_list(sstr_t param_str, UcxAllocator *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, UcxAllocator *mp); ConfigDirective* cfg_directivelist_get(UcxList *dirs, sstr_t name); sstr_t cfg_directivelist_get_str(UcxList *dirs, sstr_t name); sstr_t cfg_directive_pstr1(ConfigDirective *dir); void cfg_map_destr(UcxMempool *mp, UcxMap *map); #ifdef __cplusplus } #endif #endif /* CFG_CONF_H */