UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2023 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef LIBIDAV_CONFIG_H 30 #define LIBIDAV_CONFIG_H 31 32 #include "webdav.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 typedef struct DavConfig DavConfig; 39 typedef struct DavCfgRepository DavCfgRepository; 40 typedef struct DavCfgProxy DavCfgProxy; 41 typedef struct DavCfgKey DavCfgKey; 42 typedef struct DavCfgNamespace DavCfgNamespace; 43 typedef struct DavCfgSecretStore DavCfgSecretStore; 44 45 typedef struct CfgString CfgString; 46 typedef struct CfgInt CfgInt; 47 typedef struct CfgUInt CfgUInt; 48 typedef struct CfgBool CfgBool; 49 50 typedef enum dav_cfg_key_type DavCfgKeyType; 51 52 typedef cxmutstr (*dav_loadkeyfile_func)(const char *filename); 53 54 #define DAV_HTTP_PROXY 1 55 #define DAV_HTTPS_PROXY 2 56 57 enum dav_cfg_key_type { 58 DAV_KEY_TYPE_AES256 = 0, 59 DAV_KEY_TYPE_AES128, 60 DAV_KEY_TYPE_UNKNOWN 61 }; 62 63 struct DavConfig { 64 CxMempool *mp; 65 66 DavCfgRepository *repositories; 67 DavCfgKey *keys; 68 DavCfgNamespace *namespaces; 69 DavCfgProxy *http_proxy; 70 DavCfgProxy *https_proxy; 71 DavCfgSecretStore *secretstore; 72 73 xmlDoc *doc; 74 }; 75 76 struct CfgString { 77 cxmutstr value; 78 xmlNode *node; 79 }; 80 81 struct CfgInt { 82 int64_t value; 83 xmlNode *node; 84 }; 85 86 struct CfgUInt { 87 uint64_t value; 88 xmlNode *node; 89 }; 90 91 struct CfgBool { 92 bool value; 93 xmlNode *node; 94 }; 95 96 97 struct DavCfgRepository { 98 xmlNode *node; 99 100 CfgString name; 101 CfgString url; 102 CfgString user; 103 CfgString password; 104 CfgString stored_user; 105 CfgString default_key; 106 CfgString cert; 107 CfgBool verification; 108 109 CfgBool full_encryption; 110 CfgBool content_encryption; 111 CfgBool decrypt_content; 112 CfgBool decrypt_name; 113 CfgBool decrypt_properties; 114 115 CfgInt ssl_version; 116 CfgUInt authmethods; 117 118 int unknown_elements; 119 120 DavCfgRepository *prev; 121 DavCfgRepository *next; 122 }; 123 124 struct DavCfgProxy { 125 CfgString url; 126 CfgString user; 127 CfgString password; 128 CfgString noproxy; 129 130 int unknown_elements; 131 }; 132 133 struct DavCfgKey { 134 xmlNode *node; 135 136 CfgString name; 137 CfgString file; 138 DavCfgKeyType type; 139 xmlNode *type_node; 140 141 DavCfgKey *prev; 142 DavCfgKey *next; 143 144 int unknown_elements; 145 }; 146 147 struct DavCfgNamespace { 148 xmlNode *node; 149 cxmutstr prefix; 150 cxmutstr uri; 151 152 DavCfgNamespace *prev; 153 DavCfgNamespace *next; 154 }; 155 156 struct DavCfgSecretStore { 157 CfgString unlock_cmd; 158 CfgString lock_cmd; 159 }; 160 161 enum DavConfigError { 162 DAV_CONFIG_ERROR_XML = 0 163 }; 164 165 DavConfig* dav_config_new(xmlDoc *doc); 166 167 DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error); 168 169 void dav_config_free(DavConfig *config); 170 171 CxBuffer* dav_config2buf(DavConfig *config); 172 173 void dav_config_add_repository(DavConfig *config, DavCfgRepository *repo); 174 175 DavCfgRepository* dav_repository_new(DavConfig *config); 176 void dav_repository_free(DavConfig *config, DavCfgRepository *repo); 177 void dav_repository_remove_and_free(DavConfig *config, DavCfgRepository *repo); 178 int dav_repository_get_flags(DavCfgRepository *repo); 179 void dav_repository_set_url(DavConfig *config, DavCfgRepository *repo, cxstring newurl); 180 void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password); 181 cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo); 182 183 void dav_config_add_key(DavConfig *config, DavCfgKey *key); 184 185 DavCfgKey* dav_key_new(DavConfig *config); 186 void dav_key_remove_and_free(DavConfig *config, DavCfgKey *key); 187 188 int dav_str2ssl_version(const char *str); 189 190 int dav_cfg_string_set_node_value(DavConfig *config, CfgString *str, xmlNode *node); 191 void dav_cfg_bool_set_node_value(DavConfig *config, CfgBool *cbool, xmlNode *node); 192 193 void dav_cfg_string_set_value(DavConfig *config, CfgString *str, xmlNode *parent, cxstring new_value, const char *nodename); 194 void dav_cfg_bool_set_value(DavConfig *config, CfgBool *cbool, xmlNode *parent, DavBool new_value, const char *nodename); 195 void dav_cfg_int_set_value(DavConfig *config, CfgInt *cint, xmlNode *parent, int64_t new_value, const char *nodename); 196 void dav_cfg_uint_set_value(DavConfig *config, CfgUInt *cint, xmlNode *parent, uint64_t new_value, const char *nodename); 197 198 void dav_cfg_string_remove(CfgString *str); 199 void dav_cfg_bool_remove(CfgBool *cbool); 200 void dav_cfg_int_remove(CfgInt *cint); 201 void dav_cfg_uint_remove(CfgUInt *cint); 202 203 DavCfgRepository* dav_config_get_repository(DavConfig *config, cxstring name); 204 DavCfgRepository* dav_config_url2repo(DavConfig *config, const char *url, char **path); 205 DavCfgRepository* dav_config_url2repo_s(DavConfig *config, cxstring url, cxmutstr *path); 206 207 int dav_config_keytype(DavCfgKeyType type); 208 const char* dav_config_keytype_str(DavCfgKeyType type); 209 int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey); 210 211 int dav_config_register_namespaces(DavConfig *config, DavContext *ctx); 212 213 #ifdef __cplusplus 214 } 215 #endif 216 217 #endif /* LIBIDAV_CONFIG_H */ 218 219