diff -r cff9c4101dd7 -r a9bbd82d2dce src/server/config/conf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/config/conf.h Sun Jan 15 17:00:16 2012 +0100 @@ -0,0 +1,98 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 ACONF_H +#define ACONF_H + +#include +#include + +#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 + +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; + + +int cfg_parse_basic_file(ConfigParser *parser, FILE *in); + +sstr_t cfg_readln(FILE *file); + +int cfg_get_basic_type(sstr_t line); + +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); + +int cfg_get_directive_type_num(sstr_t type); + + +#ifdef __cplusplus +} +#endif + +#endif /* ACONF_H */ +