"Fossies" - the Fresh Open Source Software Archive

Member "ownCloud-2.9.1.5500/src/csync/csync.h" (13 Oct 2021, 8037 Bytes) of package /linux/misc/ownCloud-2.9.1.5500.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "csync.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.0.5150_vs_2.9.1.5500.

    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 // clang-format off
  107 enum SyncInstruction {
  108     CSYNC_INSTRUCTION_NONE            = 0,       /* Nothing to do (UPDATE|RECONCILE) */
  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_NEW             = 1 << 3,  /* The file is new compared to the db (UPDATE) */
  112     CSYNC_INSTRUCTION_CONFLICT        = 1 << 4,  /* The file need to be downloaded because it is a conflict (RECONCILE) */
  113     CSYNC_INSTRUCTION_IGNORE          = 1 << 5,  /* The file is ignored (UPDATE|RECONCILE) */
  114     CSYNC_INSTRUCTION_SYNC            = 1 << 6,  /* The file need to be pushed to the other remote (RECONCILE) */
  115     CSYNC_INSTRUCTION_ERROR           = 1 << 8,
  116     CSYNC_INSTRUCTION_TYPE_CHANGE     = 1 << 9,  /* Like NEW, but deletes the old entity first (RECONCILE)
  117                                                     Used when the type of something changes from directory to file
  118                                                     or back. */
  119     CSYNC_INSTRUCTION_UPDATE_METADATA = 1 << 10, /* If the etag has been updated and need to be writen to the db,
  120                                                     but without any propagation (UPDATE|RECONCILE) */
  121 
  122     // TODO:
  123     CSYNC_INSTRUCTION_EVAL_RENAME     = 1 << 11, // DEPRECATED REMOVED
  124     CSYNC_INSTRUCTION_STAT_ERROR      = 1 << 7, // DEPRECATED REMOVED
  125     CSYNC_INSTRUCTION_EVAL            = 1 << 0, // DEPRECATED REMOVED
  126 };
  127 // clang-format on
  128 Q_FLAG_NS(SyncInstruction)
  129 Q_DECLARE_FLAGS(SyncInstructions, SyncInstruction)
  130 Q_DECLARE_OPERATORS_FOR_FLAGS(SyncInstructions)
  131 
  132 // This enum is used with BITFIELD(3) and BITFIELD(4) in several places.
  133 // Also, this value is stored in the database, so beware of value changes.
  134 enum ItemType {
  135     ItemTypeFile = 0,
  136     ItemTypeSoftLink = 1,
  137     ItemTypeDirectory = 2,
  138     ItemTypeSkip = 3,
  139 
  140     /** The file is a dehydrated placeholder, meaning data isn't available locally */
  141     ItemTypeVirtualFile = 4,
  142 
  143     /** A ItemTypeVirtualFile that wants to be hydrated.
  144      *
  145      * Actions may put this in the db as a request to a future sync, such as
  146      * implicit hydration (when the user wants to access file data) when using
  147      * suffix vfs. For pin-state driven hydrations changing the database is
  148      * not necessary.
  149      *
  150      * For some vfs plugins the placeholder files on disk may be marked for
  151      * (de-)hydration (like with a file attribute) and then the local discovery
  152      * will return this item type.
  153      *
  154      * The discovery will also use this item type to mark entries for hydration
  155      * if an item's pin state mandates it, such as when encountering a AlwaysLocal
  156      * file that is dehydrated.
  157      */
  158     ItemTypeVirtualFileDownload = 5,
  159 
  160     /** A ItemTypeFile that wants to be dehydrated.
  161      *
  162      * Similar to ItemTypeVirtualFileDownload, but there's currently no situation
  163      * where it's stored in the database since there is no action that triggers a
  164      * file dehydration without changing the pin state.
  165      */
  166     ItemTypeVirtualFileDehydration = 6,
  167 };
  168 Q_ENUM_NS(ItemType)
  169 }
  170 
  171 using namespace CSyncEnums;
  172 using CSYNC_STATUS = CSyncEnums::csync_status_codes_e;
  173 typedef struct csync_file_stat_s csync_file_stat_t;
  174 
  175 struct OCSYNC_EXPORT csync_file_stat_s {
  176   time_t modtime;
  177   int64_t size;
  178   uint64_t inode;
  179 
  180   OCC::RemotePermissions remotePerm;
  181   ItemType type BITFIELD(4);
  182   bool child_modified BITFIELD(1);
  183   bool has_ignored_files BITFIELD(1); // Specify that a directory, or child directory contains ignored files.
  184   bool is_hidden BITFIELD(1); // Not saved in the DB, only used during discovery for local files.
  185 
  186   QByteArray path;
  187   QByteArray rename_path;
  188   QByteArray etag;
  189   QByteArray file_id;
  190   QByteArray directDownloadUrl;
  191   QByteArray directDownloadCookies;
  192   QByteArray original_path; // only set if locale conversion fails
  193 
  194   // In the local tree, this can hold a checksum and its type if it is
  195   //   computed during discovery for some reason.
  196   // In the remote tree, this will have the server checksum, if available.
  197   // In both cases, the format is "SHA1:baff".
  198   QByteArray checksumHeader;
  199 
  200   CSYNC_STATUS error_status;
  201 
  202   SyncInstructions instruction; /* u32 */
  203 
  204   csync_file_stat_s()
  205     : modtime(0)
  206     , size(0)
  207     , inode(0)
  208     , type(ItemTypeSkip)
  209     , child_modified(false)
  210     , has_ignored_files(false)
  211     , is_hidden(false)
  212     , error_status(CSYNC_STATUS_OK)
  213     , instruction(CSYNC_INSTRUCTION_NONE)
  214   { }
  215 };
  216 
  217 OCSYNC_EXPORT QDebug operator<<(QDebug debug, const SyncInstructions &job);
  218 
  219 /**
  220  * }@
  221  */
  222 #endif /* _CSYNC_H */
  223 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */