UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2024 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 IDAV_SETTINGS_H 30 #define IDAV_SETTINGS_H 31 32 #include "application.h" 33 #include "config.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 40 typedef struct SettingsWindow { 41 UiObject *obj; 42 43 DavConfig *config; 44 PwdStore *pwdstore; 45 46 UiList *repos; 47 /* 48 * 0: repo list page 49 * 1: edit repo page 50 */ 51 UiInteger *repo_tabview; 52 53 DavBool repo_new; 54 UiString *repo_name; 55 UiString *repo_url; 56 /* 57 * value: char* credential id 58 * 59 * '-' entry + list of all credentials 60 * This list contains the same credential pointers as credentials_users 61 * and therefore doesn't need a destructor. 62 * Both lists are updated at the same time 63 */ 64 UiList *repo_credentials; 65 UiString *repo_user; 66 UiString *repo_password; 67 /* 68 * checkbox value 69 */ 70 UiInteger *repo_encryption; 71 UiList *repo_keys; 72 /* 73 * value: char* tls version name 74 * 75 * static list of TLS version strings 76 */ 77 UiList *repo_tls_versions; 78 UiString *repo_cacert; 79 UiInteger *repo_disable_verification; 80 81 DavBool credentials_new; 82 DavBool credentials_modified; 83 DavBool credentials_list_needs_update; 84 DavBool credentials_ignore_selectionevent; 85 char *credentials_selected_id; 86 int credentials_selected_index; 87 int credentials_location_selected_index; 88 /* 89 * value: char* credentials id 90 * 91 * List of pwdstore locations and noloc credentials 92 * The value is a copy (allocated by the UiContext) 93 */ 94 UiList *credentials_users; 95 UiString *credentials_id; 96 UiString *credentials_user; 97 UiString *credentials_password; 98 /* 99 * value: char* url 100 * 101 * List of credential locations (PwdIndexEntry locations) 102 * The value is a copy (allocated by the UiContext) 103 */ 104 UiList *credentials_locations; 105 106 /* 107 * value: char* key name 108 * 109 * List of encryption keys (DavKey) 110 * The value is a copy (allocated by the UiContext) 111 */ 112 UiList *keys_list; 113 UiString *key_name; 114 UiString *key_file; 115 UiString *key_type; 116 UiInteger *key_secretstore; 117 int keys_selected_index; 118 119 int selected_repo; 120 } SettingsWindow; 121 122 typedef struct SettingsNewKeyDialog { 123 SettingsWindow *settings; 124 125 UiString *name; 126 UiString *file; 127 UiString *import_path; 128 UiString *message; 129 /* 130 * value: char* key type name 131 * 132 * Static list of DavKey type names 133 */ 134 UiList *type; 135 UiInteger *secretstore; 136 137 DavBool add_to_repo; 138 } SettingsNewKeyDialog; 139 140 typedef struct SettingsNewCredentialsDialog { 141 SettingsWindow *settings; 142 143 UiString *id; 144 UiString *user; 145 UiString *password; 146 UiInteger *addlocation; 147 UiString *message; 148 char *url; 149 } SettingsNewCredentialsDialog; 150 151 void settings_window_open(); 152 153 void settings_credentials_decrypt(SettingsWindow *settings); 154 155 void settings_ok(UiEvent *event, void *userdata); 156 157 void settings_cancel(UiEvent *event, void *userdata); 158 159 void settings_init(UiObject *obj, SettingsWindow *settings); 160 161 /* 162 * Open repository edit page for the repository settings->repos[repo_index] 163 * This function will set settings->selected_repo to repo_index 164 */ 165 void settings_edit_repository(SettingsWindow *settings, int repo_index); 166 167 /* 168 * Store settings from the settings window into the DavCfgRepository object. 169 * 170 * This functions unsets settings->selected_repo and should only be called 171 * when switching back to the repo list or closing the settings window 172 */ 173 void settings_store_repository(SettingsWindow *settings); 174 175 void settings_clear_repository(SettingsWindow *settings); 176 177 178 void settings_update_repolist(SettingsWindow *settings); 179 180 void* settings_repolist_getvalue(DavCfgRepository *repo, int col); 181 182 void settings_reload_repo_keys(SettingsWindow *settings); 183 void settings_reload_keys(SettingsWindow *settings); 184 185 const char* dav_tlsversion2str(int value); 186 187 void settings_reload_credentials(SettingsWindow *settings); 188 void settings_reload_repo_credentials(SettingsWindow *settings); 189 190 /* 191 * select credentials with the specified id and fill the credentials form 192 * 193 * if the id is specified, settings->credentials_id will be adjusted 194 * id no id is specified, credentials with the id settings->credentials_id 195 * are selected 196 */ 197 void settings_credentials_select(SettingsWindow *settings, const char *id); 198 199 /* 200 * clear the credentials form 201 */ 202 void settings_credentials_clear(SettingsWindow *settings); 203 204 int settings_credentials_save(SettingsWindow *settings); 205 206 void *keylist_getvalue(void *data, int col); 207 208 void settings_edit_key(SettingsWindow *settings, DavCfgKey *key); 209 210 void settings_clear_key(SettingsWindow *settings); 211 212 213 214 215 216 217 #ifdef __cplusplus 218 } 219 #endif 220 221 #endif /* IDAV_SETTINGS_H */ 222 223