Sun, 06 Nov 2022 15:53:32 +0100
switch from ucx 2 to 3
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2020 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 WS_CONFIG_SERVERCONFIG_H #define WS_CONFIG_SERVERCONFIG_H #include <cx/linked_list.h> #include <cx/hash_map.h> #include <cx/mempool.h> #include <cx/string.h> #include "conf.h" #ifdef __cplusplus extern "C" { #endif #define CFG_NODE_ADD(list_begin, list_end, elm) \ cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigNode, prev), offsetof(ConfigNode, next), elm) typedef struct ServerConfig ServerConfig; typedef struct ConfigNode ConfigNode; typedef struct CFGToken CFGToken; typedef enum ConfigNodeType ConfigNodeType; typedef enum CFGTokenType CFGTokenType; struct ServerConfig { CxMempool *mp; ConfigNode *root; cxmutstr tab; }; enum ConfigNodeType { CONFIG_NODE_SPACE = 0, CONFIG_NODE_COMMENT, CONFIG_NODE_OBJECT, CONFIG_NODE_DIRECTIVE, CONFIG_NODE_OPEN_OBJECT, CONFIG_NODE_CLOSE_OBJECT }; struct ConfigNode { cxmutstr text_begin; cxmutstr text_end; ConfigNodeType type; cxmutstr name; ConfigParam *args; ConfigNode *children_begin; ConfigNode *children_end; ConfigNode *prev; ConfigNode *next; }; typedef struct ConfigNodeStack ConfigNodeStack; struct ConfigNodeStack { ConfigNode *node; ConfigNodeStack *next; }; enum CFGTokenType { CFG_NO_TOKEN = 0, CFG_TOKEN_COMMENT, CFG_TOKEN_SPACE, CFG_TOKEN_NEWLINE, CFG_TOKEN }; struct CFGToken { cxstring content; CFGTokenType type; }; ServerConfig* serverconfig_load(const char *file); ServerConfig* serverconfig_parse(cxstring content); void serverconfig_free(ServerConfig *cfg); ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); cxstring serverconfig_directive_value(ConfigNode *obj, cxstring name); cxmutstr serverconfig_arg_name_value(CxAllocator *a, cxstring str, cxstring *name); #ifdef __cplusplus } #endif #endif /* WS_CONFIG_SERVERCONFIG_H */