1 /* 2 * libcsync -- a library to sync a directory with another 3 * 4 * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org> 5 * Copyright (c) 2012-2013 by Klaas Freitag <freitag@owncloud.com> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 /** 23 * @file csync.h 24 * 25 * @brief Application developer interface for csync. 26 * 27 * @defgroup csyncPublicAPI csync public API 28 * 29 * @{ 30 */ 31 32 #ifndef _CSYNC_H 33 #define _CSYNC_H 34 35 #include "std/c_private.h" 36 #include "ocsynclib.h" 37 38 #include <sys/stat.h> 39 #include <stdbool.h> 40 #include <stdint.h> 41 #include <sys/types.h> 42 #include <config_csync.h> 43 #include <functional> 44 #include <memory> 45 #include <QByteArray> 46 #include "common/remotepermissions.h" 47 48 namespace OCC { 49 class SyncJournalFileRecord; 50 } 51 52 #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG) && (__GNUC__ * 100 + __GNUC_MINOR__ < 408) 53 // openSuse 12.3 didn't like enum bitfields. 54 #define BITFIELD(size) 55 #elif defined(Q_CC_MSVC) 56 // MSVC stores enum and bool as signed, so we need to add a bit for the sign 57 #define BITFIELD(size) :(size+1) 58 #else 59 #define BITFIELD(size) :size 60 #endif 61 62 namespace CSyncEnums { 63 OCSYNC_EXPORT Q_NAMESPACE 64 65 enum csync_status_codes_e { 66 CSYNC_STATUS_OK = 0, 67 68 CSYNC_STATUS_ERROR = 1024, /* don't use this code, 69 */ 70 CSYNC_STATUS_UNSUCCESSFUL, /* Unspecific problem happend */ 71 CSYNC_STATUS_STATEDB_LOAD_ERROR, /* Statedb can not be loaded. */ 72 CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */ 73 CSYNC_STATUS_TIMEOUT, /* UNUSED */ 74 CSYNC_STATUS_HTTP_ERROR, /* UNUSED */ 75 CSYNC_STATUS_PERMISSION_DENIED, /* */ 76 CSYNC_STATUS_NOT_FOUND, 77 CSYNC_STATUS_FILE_EXISTS, 78 CSYNC_STATUS_OUT_OF_SPACE, 79 CSYNC_STATUS_SERVICE_UNAVAILABLE, 80 CSYNC_STATUS_STORAGE_UNAVAILABLE, 81 CSYNC_STATUS_FILE_SIZE_ERROR, 82 CSYNC_STATUS_OPENDIR_ERROR, 83 CSYNC_STATUS_READDIR_ERROR, 84 CSYNC_STATUS_OPEN_ERROR, 85 CSYNC_STATUS_ABORTED, 86 /* Codes for file individual status: */ 87 CSYNC_STATUS_INDIVIDUAL_IS_SYMLINK, 88 CSYNC_STATUS_INDIVIDUAL_IGNORE_LIST, 89 CSYNC_STATUS_INDIVIDUAL_IS_INVALID_CHARS, 90 CSYNC_STATUS_INDIVIDUAL_TRAILING_SPACE, 91 CSYNC_STATUS_INDIVIDUAL_EXCLUDE_LONG_FILENAME, 92 CSYNC_STATUS_INDIVIDUAL_EXCLUDE_HIDDEN, 93 CSYNC_STATUS_INVALID_CHARACTERS, 94 CSYNC_STATUS_INDIVIDUAL_STAT_FAILED, 95 CSYNC_STATUS_FORBIDDEN, 96 CSYNC_STATUS_INDIVIDUAL_TOO_DEEP, 97 CSYNC_STATUS_INDIVIDUAL_IS_CONFLICT_FILE, 98 CSYNC_STATUS_INDIVIDUAL_CANNOT_ENCODE 99 }; 100 Q_ENUM_NS(csync_status_codes_e) 101 102 /** 103 * Instruction enum. In the file traversal structure, it describes 104 * the csync state of a file. 105 */ 106 enum SyncInstructions { 107 CSYNC_INSTRUCTION_NONE = 0, /* Nothing to do (UPDATE|RECONCILE) */ 108 CSYNC_INSTRUCTION_EVAL = 1 << 0, /* There was changed compared to the DB (UPDATE) */ 109 CSYNC_INSTRUCTION_REMOVE = 1 << 1, /* The file need to be removed (RECONCILE) */ 110 CSYNC_INSTRUCTION_RENAME = 1 << 2, /* The file need to be renamed (RECONCILE) */ 111 CSYNC_INSTRUCTION_EVAL_RENAME = 1 << 11, /* The file is new, it is the destination of a rename (UPDATE) */ 112 CSYNC_INSTRUCTION_NEW = 1 << 3, /* The file is new compared to the db (UPDATE) */ 113 CSYNC_INSTRUCTION_CONFLICT = 1 << 4, /* The file need to be downloaded because it is a conflict (RECONCILE) */ 114 CSYNC_INSTRUCTION_IGNORE = 1 << 5, /* The file is ignored (UPDATE|RECONCILE) */ 115 CSYNC_INSTRUCTION_SYNC = 1 << 6, /* The file need to be pushed to the other remote (RECONCILE) */ 116 CSYNC_INSTRUCTION_STAT_ERROR = 1 << 7, 117 CSYNC_INSTRUCTION_ERROR = 1 << 8, 118 CSYNC_INSTRUCTION_TYPE_CHANGE = 1 << 9, /* Like NEW, but deletes the old entity first (RECONCILE) 119 Used when the type of something changes from directory to file 120 or back. */ 121 CSYNC_INSTRUCTION_UPDATE_METADATA = 1 << 10, /* If the etag has been updated and need to be writen to the db, 122 but without any propagation (UPDATE|RECONCILE) */ 123 }; 124 125 Q_ENUM_NS(SyncInstructions) 126 127 // This enum is used with BITFIELD(3) and BITFIELD(4) in several places. 128 // Also, this value is stored in the database, so beware of value changes. 129 enum ItemType { 130 ItemTypeFile = 0, 131 ItemTypeSoftLink = 1, 132 ItemTypeDirectory = 2, 133 ItemTypeSkip = 3, 134 135 /** The file is a dehydrated placeholder, meaning data isn't available locally */ 136 ItemTypeVirtualFile = 4, 137 138 /** A ItemTypeVirtualFile that wants to be hydrated. 139 * 140 * Actions may put this in the db as a request to a future sync, such as 141 * implicit hydration (when the user wants to access file data) when using 142 * suffix vfs. For pin-state driven hydrations changing the database is 143 * not necessary. 144 * 145 * For some vfs plugins the placeholder files on disk may be marked for 146 * (de-)hydration (like with a file attribute) and then the local discovery 147 * will return this item type. 148 * 149 * The discovery will also use this item type to mark entries for hydration 150 * if an item's pin state mandates it, such as when encountering a AlwaysLocal 151 * file that is dehydrated. 152 */ 153 ItemTypeVirtualFileDownload = 5, 154 155 /** A ItemTypeFile that wants to be dehydrated. 156 * 157 * Similar to ItemTypeVirtualFileDownload, but there's currently no situation 158 * where it's stored in the database since there is no action that triggers a 159 * file dehydration without changing the pin state. 160 */ 161 ItemTypeVirtualFileDehydration = 6, 162 }; 163 Q_ENUM_NS(ItemType) 164 } 165 166 using namespace CSyncEnums; 167 using CSYNC_STATUS = CSyncEnums::csync_status_codes_e; 168 typedef struct csync_file_stat_s csync_file_stat_t; 169 170 struct OCSYNC_EXPORT csync_file_stat_s { 171 time_t modtime; 172 int64_t size; 173 uint64_t inode; 174 175 OCC::RemotePermissions remotePerm; 176 ItemType type BITFIELD(4); 177 bool child_modified BITFIELD(1); 178 bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files. 179 bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files. 180 181 QByteArray path; 182 QByteArray rename_path; 183 QByteArray etag; 184 QByteArray file_id; 185 QByteArray directDownloadUrl; 186 QByteArray directDownloadCookies; 187 QByteArray original_path; // only set if locale conversion fails 188 189 // In the local tree, this can hold a checksum and its type if it is 190 // computed during discovery for some reason. 191 // In the remote tree, this will have the server checksum, if available. 192 // In both cases, the format is "SHA1:baff". 193 QByteArray checksumHeader; 194 195 CSYNC_STATUS error_status; 196 197 SyncInstructions instruction; /* u32 */ 198 csync_file_stat_scsync_file_stat_s199 csync_file_stat_s() 200 : modtime(0) 201 , size(0) 202 , inode(0) 203 , type(ItemTypeSkip) 204 , child_modified(false) 205 , has_ignored_files(false) 206 , is_hidden(false) 207 , error_status(CSYNC_STATUS_OK) 208 , instruction(CSYNC_INSTRUCTION_NONE) 209 { } 210 }; 211 212 time_t OCSYNC_EXPORT oc_httpdate_parse( const char *date ); 213 214 /** 215 * }@ 216 */ 217 #endif /* _CSYNC_H */ 218 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */ 219