libidav/config.h

Sun, 07 Apr 2024 10:26:25 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 07 Apr 2024 10:26:25 +0200
changeset 809
8e6d8f0327cf
parent 796
81e0f67386a6
child 823
04c60a353331
permissions
-rw-r--r--

update uwproj

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

#include "webdav.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct DavConfig         DavConfig;
typedef struct DavCfgRepository  DavCfgRepository;
typedef struct DavCfgProxy       DavCfgProxy;
typedef struct DavCfgKey         DavCfgKey;
typedef struct DavCfgNamespace   DavCfgNamespace;
typedef struct DavCfgSecretStore DavCfgSecretStore;

typedef struct CfgString  CfgString;
typedef struct CfgInt     CfgInt;
typedef struct CfgUInt    CfgUInt;
typedef struct CfgBool    CfgBool;

typedef enum dav_cfg_key_type DavCfgKeyType;

typedef cxmutstr (*dav_loadkeyfile_func)(const char *filename);

#define DAV_HTTP_PROXY 1
#define DAV_HTTPS_PROXY 2
    
enum dav_cfg_key_type {
    DAV_KEY_TYPE_AES256 = 0,
    DAV_KEY_TYPE_AES128,
    DAV_KEY_TYPE_UNKNOWN
};

struct DavConfig {
    CxMempool         *mp;
    
    DavCfgRepository  *repositories;
    DavCfgKey         *keys;
    DavCfgNamespace   *namespaces;
    DavCfgProxy       *http_proxy;
    DavCfgProxy       *https_proxy;
    DavCfgSecretStore *secretstore;
    
    xmlDoc *doc;
};

struct CfgString {
    cxmutstr value;
    xmlNode *node;
};

struct CfgInt {
    int64_t value;
    xmlNode *node;
};

struct CfgUInt {
    uint64_t value;
    xmlNode *node;
};

struct CfgBool {
    bool value;
    xmlNode *node;
};


struct DavCfgRepository {
    xmlNode *node;
    
    CfgString     name;
    CfgString     url;
    CfgString     user;
    CfgString     password;
    CfgString     stored_user;
    CfgString     default_key;
    CfgString     cert;
    CfgBool       verification;
    
    CfgBool       full_encryption;
    CfgBool       content_encryption;
    CfgBool       decrypt_content;
    CfgBool       decrypt_name;
    CfgBool       decrypt_properties;
    
    CfgInt        ssl_version;
    CfgUInt       authmethods;
    
    int           unknown_elements;
    
    DavCfgRepository    *prev;
    DavCfgRepository    *next;
};

struct DavCfgProxy {
    CfgString  url;
    CfgString  user;
    CfgString  password;
    CfgString  noproxy;
    
    int     unknown_elements;
};

struct DavCfgKey {
    CfgString  name;
    CfgString  file;
    DavCfgKeyType type;
    xmlNode *type_node;
    
    DavCfgKey *prev;
    DavCfgKey *next;
    
    int       unknown_elements;
};

struct DavCfgNamespace {
    xmlNode *node;
    cxmutstr prefix;
    cxmutstr uri;
    
    DavCfgNamespace *prev;
    DavCfgNamespace *next;
};

struct DavCfgSecretStore {
    CfgString unlock_cmd;
    CfgString lock_cmd;
};

enum DavConfigError {
    DAV_CONFIG_ERROR_XML = 0
};

DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error);

void dav_config_free(DavConfig *config);

CxBuffer* dav_config2buf(DavConfig *config);

void dav_config_add_repository(DavConfig *config, DavCfgRepository *repo);

DavCfgRepository* dav_repository_new(DavConfig *config);
void dav_repository_free(DavConfig *config, DavCfgRepository *repo);
void dav_repository_remove_and_free(DavConfig *config, DavCfgRepository *repo);
int dav_repository_get_flags(DavCfgRepository *repo);
void dav_repository_set_url(DavConfig *config, DavCfgRepository *repo, cxstring newurl);
void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password);
cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo);

int dav_cfg_string_set_value(DavConfig *config, CfgString *str, xmlNode *node);
void dav_cfg_bool_set_value(DavConfig *config, CfgBool *cbool, xmlNode *node);

DavCfgRepository* dav_config_get_repository(DavConfig *config, cxstring name);
DavCfgRepository* dav_config_url2repo(DavConfig *config, const char *url, char **path);
DavCfgRepository* dav_config_url2repo_s(DavConfig *config, cxstring url, cxmutstr *path);

int dav_config_keytype(DavCfgKeyType type);
int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey);

#ifdef __cplusplus
}
#endif

#endif /* LIBIDAV_CONFIG_H */

mercurial