src/server/config/serverconfig.h

Sat, 24 Sep 2022 16:19:24 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 24 Sep 2022 16:19:24 +0200
branch
webdav
changeset 384
f9e9f2b3e299
parent 269
3dfbd0b91950
child 415
d938228c382e
permissions
-rw-r--r--

remove debug code

/*
 * 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 <ucx/list.h>
#include <ucx/map.h>
#include <ucx/mempool.h>

#ifdef __cplusplus
extern "C" {
#endif


typedef struct ServerConfig    ServerConfig;
typedef struct ConfigNode      ConfigNode;
typedef struct ConfigArg       ConfigArg;
typedef struct CFGToken        CFGToken;

typedef enum ConfigNodeType    ConfigNodeType;
typedef enum CFGTokenType      CFGTokenType;

struct ServerConfig {
    UcxMempool *mp;
    ConfigNode *root;
    sstr_t 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 {
    sstr_t text_begin;
    sstr_t text_end; 
    ConfigNodeType type;
    
    sstr_t name;
    UcxList *args;
    UcxList *children;
};

struct ConfigArg {
    sstr_t name;
    sstr_t value;
};


enum CFGTokenType {
    CFG_NO_TOKEN = 0,
    CFG_TOKEN_COMMENT,
    CFG_TOKEN_SPACE,
    CFG_TOKEN_NEWLINE,
    CFG_TOKEN
};

struct CFGToken {
    scstr_t content;
    CFGTokenType type;
};

ServerConfig* serverconfig_load(const char *file);

ServerConfig* serverconfig_parse(scstr_t content);

void serverconfig_free(ServerConfig *cfg);

ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, scstr_t name);

UcxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, scstr_t name);

scstr_t serverconfig_directive_value(ConfigNode *obj, scstr_t name);

sstr_t serverconfig_arg_name_value(UcxAllocator *a, scstr_t str, scstr_t *name);

#ifdef __cplusplus
}
#endif

#endif /* WS_CONFIG_SERVERCONFIG_H */

mercurial