nextcloud-desktop/src/csync.h

395 lines
11 KiB
C
Raw Normal View History

2008-02-27 20:56:47 +03:00
/*
* libcsync -- a library to sync a directory with another
*
* Copyright (c) 2006-2008 by Andreas Schneider <mail@cynapses.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2008-02-27 20:56:47 +03:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2008-02-27 20:56:47 +03:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2008-02-27 20:56:47 +03:00
*/
/**
* @file csync.h
*
* @brief Application developer interface for csync.
*
* @defgroup csyncPublicAPI csync public API
*
* @{
*/
#ifndef _CSYNC_H
#define _CSYNC_H
#include <stdbool.h>
2012-04-17 12:46:58 +04:00
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
2008-02-27 20:56:47 +03:00
#ifdef __cplusplus
extern "C" {
#endif
2009-03-26 12:40:16 +03:00
#define CSYNC_STRINGIFY(s) CSYNC_TOSTRING(s)
#define CSYNC_TOSTRING(s) #s
2009-03-26 20:23:43 +03:00
/* csync version macros */
2009-03-27 02:00:49 +03:00
#define CSYNC_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
2009-03-26 12:40:16 +03:00
#define CSYNC_VERSION_DOT(a, b, c) a ##.## b ##.## c
#define CSYNC_VERSION(a, b, c) CSYNC_VERSION_DOT(a, b, c)
2009-03-26 20:23:43 +03:00
/* csync version */
2009-03-26 12:40:16 +03:00
#define LIBCSYNC_VERSION_MAJOR 0
#define LIBCSYNC_VERSION_MINOR 49
#define LIBCSYNC_VERSION_MICRO 9
2009-03-26 12:40:16 +03:00
#define LIBCSYNC_VERSION_INT CSYNC_VERSION_INT(LIBCSYNC_VERSION_MAJOR, \
LIBCSYNC_VERSION_MINOR, \
LIBCSYNC_VERSION_MICRO)
#define LIBCSYNC_VERSION CSYNC_VERSION(LIBCSYNC_VERSION_MAJOR, \
LIBCSYNC_VERSION_MINOR, \
LIBCSYNC_VERSION_MICRO)
2008-02-27 20:56:47 +03:00
/*
* csync file declarations
*/
#define CSYNC_CONF_DIR ".csync"
#define CSYNC_CONF_FILE "csync.conf"
#define CSYNC_LOG_FILE "csync_log.conf"
#define CSYNC_EXCLUDE_FILE "csync_exclude.conf"
#define CSYNC_LOCK_FILE "lock"
typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata);
/**
* Instruction enum. In the file traversal structure, it describes
* the csync state of a file.
*/
enum csync_instructions_e {
CSYNC_INSTRUCTION_NONE = 0x00000000,
CSYNC_INSTRUCTION_EVAL = 0x00000001,
CSYNC_INSTRUCTION_REMOVE = 0x00000002,
CSYNC_INSTRUCTION_RENAME = 0x00000004,
CSYNC_INSTRUCTION_NEW = 0x00000008,
CSYNC_INSTRUCTION_CONFLICT = 0x00000010,
CSYNC_INSTRUCTION_IGNORE = 0x00000020,
CSYNC_INSTRUCTION_SYNC = 0x00000040,
CSYNC_INSTRUCTION_STAT_ERROR = 0x00000080,
CSYNC_INSTRUCTION_ERROR = 0x00000100,
/* instructions for the propagator */
CSYNC_INSTRUCTION_DELETED = 0x00000200,
CSYNC_INSTRUCTION_UPDATED = 0x00000400
};
/**
* CSync File Traversal structure.
*
* This structure is passed to the visitor function for every file
* which is seen.
* Note: The file size is missing here because type off_t is depending
* on the large file support in your build. Make sure to check
* that cmake and the callback app are compiled with the same
* setting for it, such as:
* -D_LARGEFILE64_SOURCE or -D_LARGEFILE_SOURCE
*
*/
struct csync_tree_walk_file_s {
const char *path;
/* off_t size; */
time_t modtime;
#ifdef _WIN32
2012-04-17 12:46:58 +04:00
uint32_t uid;
uint32_t gid;
#else
uid_t uid;
gid_t gid;
#endif
mode_t mode;
int type;
enum csync_instructions_e instruction;
};
typedef struct csync_tree_walk_file_s TREE_WALK_FILE;
/**
* csync handle
2008-02-27 20:56:47 +03:00
*/
typedef struct csync_s CSYNC;
2008-02-27 20:56:47 +03:00
/**
* @brief Allocate a csync context.
*
* @param csync The context variable to allocate.
2008-02-27 20:56:47 +03:00
*
* @return 0 on success, less than 0 if an error occured.
2008-02-27 20:56:47 +03:00
*/
int csync_create(CSYNC **csync, const char *local, const char *remote);
2008-02-27 20:56:47 +03:00
/**
* @brief Initialize the file synchronizer.
*
2008-07-09 12:10:00 +04:00
* This function loads the configuration, the statedb and locks the client.
*
* @param ctx The context to initialize.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_init(CSYNC *ctx);
2008-02-27 20:56:47 +03:00
/**
* @brief Update detection
*
* @param ctx The context to run the update detection on.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_update(CSYNC *ctx);
2008-02-27 20:56:47 +03:00
/**
* @brief Reconciliation
*
* @param ctx The context to run the reconciliation on.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_reconcile(CSYNC *ctx);
2008-02-27 20:56:47 +03:00
/**
* @brief Propagation
*
* @param ctx The context to run the propagation on.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_propagate(CSYNC *ctx);
2008-02-27 20:56:47 +03:00
/**
* @brief Destroy the csync context
*
2008-07-09 12:10:00 +04:00
* Writes the statedb, unlocks csync and frees the memory.
*
* @param ctx The context to destroy.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_destroy(CSYNC *ctx);
2008-02-27 20:56:47 +03:00
/**
2009-03-26 12:40:16 +03:00
* @brief Check if csync is the required version or get the version
* string.
*
* @param req_version The version required.
*
* @return If the version of csync is newer than the version
* required it will return a version string.
* NULL if the version is older.
*
* Example:
*
* @code
* if (csync_version(CSYNC_VERSION_INT(0,42,1)) == NULL) {
* fprintf(stderr, "libcsync version is too old!\n");
* exit(1);
* }
*
2009-03-26 12:40:16 +03:00
* if (debug) {
* printf("csync %s\n", csync_version(0));
* }
* @endcode
*/
2009-03-26 12:40:16 +03:00
const char *csync_version(int req_version);
2008-02-27 20:56:47 +03:00
2009-03-26 13:24:34 +03:00
/**
* @brief Add an additional exclude list.
*
* @param ctx The context to add the exclude list.
*
* @param path The path pointing to the file.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_add_exclude_list(CSYNC *ctx, const char *path);
2009-03-26 13:24:34 +03:00
/**
* @brief Get the config directory.
*
* @param ctx The csync context.
*
* @return The path of the config directory or NULL on error.
*/
const char *csync_get_config_dir(CSYNC *ctx);
/**
* @brief Change the config directory.
*
* @param ctx The csync context.
*
* @param path The path to the new config directory.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_set_config_dir(CSYNC *ctx, const char *path);
2009-03-26 13:24:34 +03:00
/**
* @brief Remove the complete config directory.
*
* @param ctx The csync context.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_remove_config_dir(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Enable the usage of the statedb. It is enabled by default.
*
* @param ctx The csync context.
*
* @return 0 on success, less than 0 if an error occured.
*/
2008-07-09 12:10:00 +04:00
int csync_enable_statedb(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Disable the usage of the statedb. It is enabled by default.
*
* @param ctx The csync context.
*
* @return 0 on success, less than 0 if an error occured.
*/
2008-07-09 12:10:00 +04:00
int csync_disable_statedb(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Check if the statedb usage is enabled.
*
* @param ctx The csync context.
*
* @return 1 if it is enabled, 0 if it is disabled.
*/
2008-07-09 12:10:00 +04:00
int csync_is_statedb_disabled(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Get the userdata saved in the context.
*
* @param ctx The csync context.
*
* @return The userdata saved in the context, NULL if an error
* occured.
*/
void *csync_get_userdata(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Save userdata to the context which is passed to the auth
* callback function.
*
* @param ctx The csync context.
*
* @param userdata The userdata to be stored in the context.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_set_userdata(CSYNC *ctx, void *userdata);
2009-03-26 13:24:34 +03:00
/**
* @brief Get the authentication callback set.
*
* @param ctx The csync context.
*
* @return The authentication callback set or NULL if an error
* occured.
*/
2008-06-24 15:36:27 +04:00
csync_auth_callback csync_get_auth_callback(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/**
* @brief Set the authentication callback.
*
* @param ctx The csync context.
*
* @param cb The authentication callback.
*
* @return 0 on success, less than 0 if an error occured.
*/
2008-06-24 15:36:27 +04:00
int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb);
2009-03-26 13:24:34 +03:00
/**
* @brief Get the path of the statedb file used.
*
* @param ctx The csync context.
*
* @return The path to the statedb file, NULL if an error occured.
*/
const char *csync_get_statedb_file(CSYNC *ctx);
/**
* @brief Enable the creation of backup copys if files are changed on both sides
*
* @param ctx The csync context.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_enable_conflictcopys(CSYNC *ctx);
/**
* @brief Flag to tell csync that only a local run is intended. Call before csync_init
*
* @param local_only Bool flag to indicate local only mode.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_set_local_only( CSYNC *ctx, bool local_only );
/**
* @brief Retrieve the flag to tell csync that only a local run is intended.
*
* @return 1: stay local only, 0: local and remote mode
*/
bool csync_get_local_only( CSYNC *ctx );
2009-03-26 13:24:34 +03:00
/* Used for special modes or debugging */
int csync_get_status(CSYNC *ctx);
2009-03-26 13:24:34 +03:00
/* Used for special modes or debugging */
int csync_set_status(CSYNC *ctx, int status);
typedef int csync_treewalk_visit_func(TREE_WALK_FILE* ,void*);
/**
* @brief Walk the local file tree and call a visitor function for each file.
*
* @param ctx The csync context.
* @param visitor A callback function to handle the file info.
* @param filter A filter, built from and'ed csync_instructions_e
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter);
/**
* @brief Walk the remote file tree and call a visitor function for each file.
*
* @param ctx The csync context.
* @param visitor A callback function to handle the file info.
* @param filter A filter, built from and'ed csync_instructions_e
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter);
2008-02-27 20:56:47 +03:00
#ifdef __cplusplus
}
#endif
/**
* }@
*/
#endif /* _CSYNC_H */
2009-05-13 12:12:07 +04:00
/* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */