UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2019 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 SCFG_H 30 #define SCFG_H 31 32 #include <cx/string.h> 33 #include <stdbool.h> 34 #include <libidav/webdav.h> 35 36 #ifdef _WIN32 37 #include "pcreposix.h" 38 #else 39 #include <regex.h> 40 #endif 41 42 #include "db.h" 43 #include "tags.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 #define SYNC_CMD_PULL 1 50 #define SYNC_CMD_PUSH 2 51 #define SYNC_CMD_ARCHIVE 4 52 #define SYNC_CMD_RESTORE 8 53 54 #define SYNC_SYMLINK_SYNC 1 55 #define SYNC_SYMLINK_IGNORE_EXTERN 2 56 #define SYNC_SYMLINK_IGNORE_INTERN 4 57 58 #define DEFAULT_TAG_XATTR "tags" 59 #define MACOS_TAG_XATTR "com.apple.metadata:_kMDItemUserTags" 60 61 #define VERSIONING_DEFAULT_PATH "/.dav-version-history" 62 63 #define SYNC_SYMLINK(dir) \ 64 (((dir)->symlink & SYNC_SYMLINK_SYNC) == SYNC_SYMLINK_SYNC) 65 66 #define SYNC_HASHING(dir) ((dir)->hashing) 67 #define SYNC_STORE_HASH(dir) ((dir)->store_hash) 68 69 typedef struct TagConfig TagConfig; 70 typedef struct Versioning Versioning; 71 typedef struct SplitConfig SplitConfig; 72 typedef struct Filter Filter; 73 74 enum PushStrategy { 75 PUSH_STRATEGY_METADATA = 0, 76 PUSH_STRATEGY_HASH 77 }; 78 typedef enum PushStrategy PushStrategy; 79 80 struct Filter { 81 CxList *include; 82 CxList *exclude; 83 CxList *tags; 84 }; 85 86 typedef struct SyncDirectory { 87 char *name; 88 char *path; 89 char *trash; 90 char *collection; 91 char *repository; 92 char *database; 93 char *logfile; 94 TagConfig *tagconfig; 95 Versioning *versioning; 96 Filter filter; 97 CxList *splitconfig; 98 uint32_t metadata; 99 int max_retry; 100 int allow_cmd; 101 uint32_t symlink; 102 time_t lock_timeout; 103 PushStrategy push_strategy; 104 bool backuppull; 105 bool lockpull; 106 bool lockpush; 107 bool hashing; 108 bool store_hash; 109 bool pull_skip_hashing; 110 uint32_t db_settings; 111 } SyncDirectory; 112 113 struct SplitConfig { 114 /* 115 * resource filter or NULL 116 */ 117 Filter *filter; 118 /* 119 * minimum file size for activating file splitting 120 * a value of -1 means no size restriction 121 */ 122 int64_t minsize; 123 /* 124 * split files into blocks with this size 125 */ 126 size_t blocksize; 127 }; 128 129 130 enum TagFormat { 131 TAG_FORMAT_TEXT = 0, 132 TAG_FORMAT_CSV, 133 TAG_FORMAT_XML, 134 TAG_FORMAT_MACOS, 135 TAG_FORMAT_UNKNOWN 136 }; 137 typedef enum TagFormat TagFormat; 138 139 enum TagStore { 140 TAG_STORE_XATTR = 0, 141 TAG_STORE_UNKNOWN 142 }; 143 typedef enum TagStore TagStore; 144 145 enum TagConflict { 146 TAG_NO_CONFLICT = 0, 147 TAG_KEEP_LOCAL, 148 TAG_KEEP_REMOTE, 149 TAG_MERGE 150 }; 151 typedef enum TagConflict TagConflict; 152 153 struct TagConfig { 154 TagStore store; 155 TagFormat local_format; 156 TagFormat server_format; 157 char *xattr_name; 158 TagConflict conflict; 159 bool detect_changes; 160 }; 161 162 enum VersioningType { 163 VERSIONING_SIMPLE = 0, 164 VERSIONING_DELTAV 165 }; 166 typedef enum VersioningType VersioningType; 167 168 struct Versioning { 169 VersioningType type; 170 char *collection; 171 bool always; 172 }; 173 174 int load_sync_config(); 175 176 CxIterator scfg_directory_iterator(); 177 SyncDirectory* scfg_get_dir(const char *name); 178 179 int scfg_check_dir(SyncDirectory *dir); 180 181 char* scfg_create_path(const char *cfg); 182 183 int add_directory(SyncDirectory *dir); 184 185 char* generate_db_name(const char *basename); 186 187 void free_filter(Filter filter); 188 189 void free_sync_config(); 190 191 192 #ifdef __cplusplus 193 } 194 #endif 195 196 #endif /* SCFG_H */ 197 198