src/server/daemon/location.h

Sun, 23 Nov 2025 12:44:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Nov 2025 12:44:59 +0100
changeset 635
b85d45fd3b01
child 636
40f069ddda37
permissions
-rw-r--r--

add location config parser

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2025 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 LOCATION_H
#define LOCATION_H

#include <cx/string.h>
#include <cx/hash_map.h>
#include <regex.h>
#include "../public/nsapi.h"
#include "../config/serverconfig.h"
#include "../util/strreplace.h"
#include "../webdav/webdav.h"


#ifdef __cplusplus
extern "C" {
#endif
    
typedef struct WSLocation       WSLocation;
typedef struct WSLocationConfig WSLocationConfig;

typedef enum WSLocationMatch {
    WS_LOCATION_MATCH_EXACT = 0,
    WS_LOCATION_MATCH_PREFIX,
    WS_LOCATION_MATCH_CS_REGEX,
    WS_LOCATION_MATCH_CI_REGEX
} WSLocationMatch;
    
struct WSLocationConfig {
    /*
     * Activate dirindex setting
     */
    WSBool set_dirindex;
    
    /*
     * Enable/Disable directory index
     */
    WSBool dirindex;
    
    /*
     * Activate forcetls setting
     */
    WSBool set_forcetls;
    
    /*
     * force TLS
     */
    WSBool forcetls;
    
    /*
     * obj.conf object name
     */
    cxmutstr name;
    
    /*
     * VFS type
     */
    cxmutstr vfs;
    
    /*
     * Document root path
     */
    cxmutstr docroot;
    
    /*
     * Redirect URL
     * Can contain references to regex capture groups (redirect match regex,
     * if available, or the location regex)
     */
    StringTemplate *redirect;
    
    /*
     * Redirect match regex
     */
    regex_t redirect_match;
    
    /*
     * Status code for redirect response
     */
    int redirect_status;
    
    /*
     * WebDAV settings
     * If dav is set, "webdav" is added to the obj.conf object list,
     * unless name is also set
     */
    WebdavRepository *dav;
    
    /*
     * List of ACL names, that should be added to the request ACL list
     * value: char*
     */
    CxList *acls;
};

struct WSLocation {
    WSLocationMatch match;
    cxmutstr match_string;
    regex_t regex;
    
    /*
     * standard location settings
     */
    WSLocationConfig config;
    
    /*
     * extended settings
     * key: directive name
     * value: char*
     */
    CxMap *ext_config;
    
    WSLocation *children_begin;
    WSLocation *children_end;
    WSLocation *prev;
    WSLocation *next;
};

WSLocation* cfg_location_get(const CxAllocator *a, ConfigNode *obj);

#ifdef __cplusplus
}
#endif

#endif /* LOCATION_H */

mercurial