mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-29 04:08:54 +03:00
Add virtual IO plugin system.
This is the initial commit of the vio plugin system. The idea is based on gnomevfs.
This commit is contained in:
parent
3e33f5d52c
commit
ab39159607
14 changed files with 749 additions and 0 deletions
|
@ -35,6 +35,7 @@ macro_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_CURRENT_BI
|
|||
|
||||
add_subdirectory(iniparser/src)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(modules)
|
||||
add_subdirectory(client)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(doc)
|
||||
|
|
34
modules/CMakeLists.txt
Normal file
34
modules/CMakeLists.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
project(modules)
|
||||
|
||||
find_package(Libsmbclient REQUIRED)
|
||||
|
||||
set(MODULES_PUBLIC_INCLUDE_DIRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
CACHE INTERNAL "smb_plugin include directories"
|
||||
)
|
||||
|
||||
set(MODULES_PRIVATE_INCLUDE_DIRS
|
||||
${CSTDLIB_PUBLIC_INCLUDE_DIRS}
|
||||
${CSYNC_PUBLIC_INCLUDE_DIRS}
|
||||
${LIBSMBCLIENT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(SMB_PLUGIN
|
||||
csync_smb
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${MODULES_PUBLIC_INCLUDE_DIRS}
|
||||
${MODULES_PRIVATE_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
macro_add_plugin(${SMB_PLUGIN} csync_smb.c)
|
||||
target_link_libraries(${SMB_PLUGIN} ${LIBSMBCLIENT_LIBRARIES} ${CSTDLIB_LIBRARY})
|
||||
|
||||
INSTALL(
|
||||
TARGETS
|
||||
${SMB_PLUGIN}
|
||||
DESTINATION
|
||||
${PLUGIN_INSTALL_DIR}
|
||||
)
|
||||
|
230
modules/csync_smb.c
Normal file
230
modules/csync_smb.c
Normal file
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 2008 by Andreas Schneider <mail@cynapses.org>
|
||||
*
|
||||
* This program is free software = NULL, you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation = NULL, either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY = NULL, without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program = NULL, if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* vim: ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libsmbclient.h>
|
||||
|
||||
#include "c_lib.h"
|
||||
#include "vio/csync_vio_module.h"
|
||||
|
||||
SMBCCTX *smb_context;
|
||||
|
||||
/*
|
||||
* Authentication callback for libsmbclient
|
||||
*/
|
||||
static void get_auth_data_fn(const char *pServer,
|
||||
const char *pShare,
|
||||
char *pWorkgroup, int maxLenWorkgroup,
|
||||
char *pUsername, int maxLenUsername,
|
||||
char *pPassword, int maxLenPassword) {
|
||||
/* FIXME: need to handle non kerberos authentication for libsmbclient
|
||||
* here, currently it is only a placeholder so that libsmbclient can be
|
||||
* initialized */
|
||||
return;
|
||||
}
|
||||
|
||||
typedef struct smb_fhandle_s {
|
||||
int fd;
|
||||
} smb_fhandle_t;
|
||||
|
||||
|
||||
/*
|
||||
* file functions
|
||||
*/
|
||||
|
||||
static csync_vio_method_handle_t *_open(const char *durl, int flags, mode_t mode) {
|
||||
smb_fhandle_t *handle = NULL;
|
||||
int fd = -1;
|
||||
|
||||
if ((fd = smbc_open(durl, flags, mode)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = c_malloc(sizeof(smb_fhandle_t));
|
||||
if (handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->fd = fd;
|
||||
return (csync_vio_method_handle_t *) handle;
|
||||
}
|
||||
|
||||
static csync_vio_method_handle_t *_creat(const char *durl, mode_t mode) {
|
||||
smb_fhandle_t *handle = NULL;
|
||||
int fd = -1;
|
||||
|
||||
if ((fd = smbc_creat(durl, mode)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = c_malloc(sizeof(smb_fhandle_t));
|
||||
if (handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->fd = fd;
|
||||
return (csync_vio_method_handle_t *) handle;
|
||||
}
|
||||
|
||||
static int _close(csync_vio_method_handle_t *fhandle) {
|
||||
int rc = -1;
|
||||
smb_fhandle_t *handle = NULL;
|
||||
|
||||
handle = (smb_fhandle_t *) fhandle;
|
||||
|
||||
rc = smbc_close(handle->fd);
|
||||
|
||||
SAFE_FREE(handle);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static ssize_t _read(csync_vio_method_handle_t *fhandle, void *buf, size_t count) {
|
||||
smb_fhandle_t *handle = NULL;
|
||||
|
||||
handle = (smb_fhandle_t *) fhandle;
|
||||
|
||||
return smbc_read(handle->fd, buf, count);
|
||||
}
|
||||
|
||||
static ssize_t _write(csync_vio_method_handle_t *fhandle, const void *buf, size_t count) {
|
||||
smb_fhandle_t *handle = NULL;
|
||||
|
||||
handle = (smb_fhandle_t *) fhandle;
|
||||
|
||||
return smbc_write(handle->fd, (char *) buf, count);
|
||||
}
|
||||
|
||||
static off_t _lseek(csync_vio_method_handle_t *fhandle, off_t offset, int whence) {
|
||||
smb_fhandle_t *handle = NULL;
|
||||
|
||||
handle = (smb_fhandle_t *) fhandle;
|
||||
|
||||
return smbc_lseek(handle->fd, offset, whence);
|
||||
}
|
||||
|
||||
/*
|
||||
* directory functions
|
||||
*/
|
||||
|
||||
typedef struct smb_dhandle_s {
|
||||
int dh;
|
||||
char *path;
|
||||
} smb_dhandle_t;
|
||||
|
||||
static csync_vio_method_handle_t *_opendir(const char *name) {
|
||||
smb_dhandle_t *handle = NULL;
|
||||
|
||||
handle = c_malloc(sizeof(smb_dhandle_t));
|
||||
if (handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->dh = smbc_opendir(name);
|
||||
handle->path = c_strdup(name);
|
||||
|
||||
return (csync_vio_method_handle_t *) handle;
|
||||
}
|
||||
|
||||
static int _closedir(csync_vio_method_t *dhandle) {
|
||||
smb_dhandle_t *handle = NULL;
|
||||
int rc = -1;
|
||||
|
||||
handle = (smb_dhandle_t *) dhandle;
|
||||
|
||||
rc = smbc_closedir(handle->dh);
|
||||
|
||||
SAFE_FREE(handle->path);
|
||||
SAFE_FREE(handle);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static csync_vio_file_stat_t *_readdir(csync_vio_method_handle_t *dhandle) {
|
||||
smbc_dirent *dirent = NULL;
|
||||
smb_dhandle_t *handle = NULL;
|
||||
|
||||
handle = (smb_dhandle_t *) dhandle;
|
||||
|
||||
dirent = smbc_opendir(handle->dh);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
csync_vio_method_t method = {
|
||||
.method_table_size = sizeof(csync_vio_method_t),
|
||||
.open = _open,
|
||||
.creat = _creat,
|
||||
.close = _close,
|
||||
.read = _read,
|
||||
.write = _write,
|
||||
.lseek = _lseek,
|
||||
.opendir = _opendir,
|
||||
.closedir = _closedir,
|
||||
.readdir = NULL,
|
||||
.mkdir = NULL,
|
||||
.rmdir = NULL,
|
||||
.stat = NULL,
|
||||
.rename = NULL,
|
||||
.unlink = NULL,
|
||||
.chmod = NULL,
|
||||
.chwon = NULL,
|
||||
.utimes = NULL
|
||||
};
|
||||
|
||||
csync_vio_method_t *vio_module_init(const char *method_name, const char *args) {
|
||||
smb_context = smbc_new_context();
|
||||
|
||||
if (smb_context == NULL) {
|
||||
fprintf(stderr, "csync_smb: Failed to create new smbc context\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* set debug level and authentication function callback */
|
||||
smb_context->debug = 0;
|
||||
smb_context->callbacks.auth_fn = get_auth_data_fn;
|
||||
|
||||
if (smbc_init_context(smb_context) == NULL) {
|
||||
fprintf(stderr, "CSYNC_SMB: Failed to initialize the smbc context");
|
||||
smbc_free_context(smb_context, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS)
|
||||
smb_context->flags |= (SMB_CTX_FLAG_USE_KERBEROS | SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS);
|
||||
#endif
|
||||
|
||||
smbc_set_context(smb_context);
|
||||
|
||||
return &method;
|
||||
}
|
||||
|
||||
void vio_module_shutdown(csync_vio_method_t *method) {
|
||||
if (smb_context != NULL) {
|
||||
/*
|
||||
* If we have a context, all connections and files will be closed even
|
||||
* if they are busy.
|
||||
*/
|
||||
smbc_free_context(smb_context, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,9 @@ set(csync_SRCS
|
|||
csync_journal.c
|
||||
csync_lock.c
|
||||
csync_util.c
|
||||
|
||||
vio/csync_vio.c
|
||||
vio/csync_vio_handle.c
|
||||
)
|
||||
|
||||
set(csync_HDRS
|
||||
|
|
27
src/vio/csync_vio.c
Normal file
27
src/vio/csync_vio.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#include "vio/csync_vio.h"
|
||||
|
||||
int csync_vfs_init(void) {
|
||||
return 0;
|
||||
}
|
55
src/vio/csync_vio.h
Normal file
55
src/vio/csync_vio.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_H
|
||||
#define _CSYNC_VIO_H
|
||||
|
||||
#include "vio/csync_vio_handle.h"
|
||||
#include "vio/csync_vio_file_stat.h"
|
||||
|
||||
int csync_vfs_init(void);
|
||||
int csync_vfs_shutdown(void);
|
||||
|
||||
csync_vio_handle_t *csync_vfs_open(const char *uri, int flags, mode_t mode);
|
||||
csync_vio_handle_t *csync_vfs_creat(const char *uri, mode_t mode);
|
||||
int csync_vio_close(csync_vio_handle_t *handle);
|
||||
ssize_t csync_vio_read(csync_vio_handle_t *fhandle, void *buf, size_t count);
|
||||
ssize_t csync_vio_write(csync_vio_handle_t *fhandle, const void *buf, size_t count);
|
||||
off_t csync_vio_seek(csync_vio_handle_t *fhandle, off_t offset, int whence);
|
||||
|
||||
csync_vio_handle_t *csync_vio_opendir(const char *name);
|
||||
int csync_vio_closedir(csync_vio_handle_t *dhandle);
|
||||
csync_vio_file_stat_t *csync_vio_readdir(csync_vio_handle_t *dhandle);
|
||||
|
||||
int csync_vio_mkdir(const char *uri, mode_t mode);
|
||||
int csync_vio_rmdir(const char *uri);
|
||||
|
||||
int csync_vio_stat(const char *uri, csync_vio_file_stat_t *buf);
|
||||
int csync_vio_rename(const char *olduri, const char *newuri);
|
||||
int csync_vio_unlink(const char *uri);
|
||||
|
||||
int csync_vio_chmod(const char *uri, mode_t mode);
|
||||
int csync_vio_chown(const char *uri, uid_t owner, gid_t group);
|
||||
|
||||
int csync_vio_utimes(const char *uri, const struct timeval times[2]);
|
||||
|
||||
#endif /* _CSYNC_VIO_H */
|
97
src/vio/csync_vio_file_stat.h
Normal file
97
src/vio/csync_vio_file_stat.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_FILE_INFO_H
|
||||
#define _CSYNC_VIO_FILE_INFO_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct csync_vio_file_stat_s csync_vio_file_stat_t;
|
||||
|
||||
enum csync_vio_file_flags_e {
|
||||
CSYNC_VIO_FILE_FLAGS_NONE = 0,
|
||||
CSYNC_VIO_FILE_FLAGS_SYMLINK = 1 << 0,
|
||||
CSYNC_VIO_FILE_FLAGS_LOCAL = 1 << 1
|
||||
};
|
||||
|
||||
enum csync_vio_file_type_e {
|
||||
CSYNC_VIO_FILE_TYPE_UNKNOWN,
|
||||
CSYNC_VIO_FILE_TYPE_REGULAR,
|
||||
CSYNC_VIO_FILE_TYPE_DIRECTORY,
|
||||
CSYNC_VIO_FILE_TYPE_FIFO,
|
||||
CSYNC_VIO_FILE_TYPE_SOCKET,
|
||||
CSYNC_VIO_FILE_TYPE_CHARACTER_DEVICE,
|
||||
CSYNC_VIO_FILE_TYPE_BLOCK_DEVICE,
|
||||
CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK
|
||||
};
|
||||
|
||||
enum csync_vio_file_stat_fields_e {
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_NONE = 0,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_TYPE = 1 << 0,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_PERMISSIONS = 1 << 1,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_FLAGS = 1 << 2,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_DEVICE = 1 << 3,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_INODE = 1 << 4,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_LINK_COUNT = 1 << 5,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_SIZE = 1 << 6,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_BLOCK_COUNT = 1 << 7,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_IO_BLOCK_SIZE = 1 << 8,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_ATIME = 1 << 9,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_MTIME = 1 << 10,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_CTIME = 1 << 11,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_SYMLINK_NAME = 1 << 12,
|
||||
CSYNC_VIO_FILE_INFO_FIELDS_ACL = 1 << 13,
|
||||
};
|
||||
|
||||
|
||||
struct csync_vio_file_stat_s {
|
||||
char *name;
|
||||
|
||||
enum csync_vio_file_stat_fields_e fields;
|
||||
enum csync_vio_file_type_e type;
|
||||
mode_t mode;
|
||||
|
||||
enum csync_vio_file_flags_e flags;
|
||||
|
||||
dev_t device;
|
||||
ino_t inode;
|
||||
nlink_t link_count;
|
||||
|
||||
off_t size;
|
||||
off_t blksize;
|
||||
unsigned long blkcount;
|
||||
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
time_t ctime;
|
||||
|
||||
char *symlink_name;
|
||||
void *acl;
|
||||
|
||||
void *reserved1;
|
||||
void *reserved2;
|
||||
void *reserved3;
|
||||
};
|
||||
|
||||
#endif /* _CSYNC_VIO_METHOD_H */
|
53
src/vio/csync_vio_handle.c
Normal file
53
src/vio/csync_vio_handle.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#include "c_lib.h"
|
||||
|
||||
#include "vio/csync_vio_handle.h"
|
||||
#include "vio/csync_vio_handle_private.h"
|
||||
|
||||
csync_vio_handle_t *csync_vio_handle_new(char *uri, csync_vio_method_handle_t *method_handle) {
|
||||
csync_vio_handle_t *new = NULL;
|
||||
|
||||
if (uri == NULL || method_handle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new = c_malloc(sizeof(csync_vio_handle_t));
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new->uri = uri;
|
||||
new->method_handle = method_handle;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
void csync_vio_handle_destroy(csync_vio_handle_t *handle) {
|
||||
if (handle == NULL || handle->uri == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SAFE_FREE(handle->uri);
|
||||
SAFE_FREE(handle);
|
||||
}
|
29
src/vio/csync_vio_handle.h
Normal file
29
src/vio/csync_vio_handle.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_HANDLE_H
|
||||
#define _CSYNC_VIO_HANDLE_H
|
||||
|
||||
typedef void *csync_vio_method_handle_t;
|
||||
typedef struct csync_vio_handle_s csync_vio_handle_t;
|
||||
|
||||
#endif /* _CSYNC_VIO_HANDLE_H */
|
35
src/vio/csync_vio_handle_private.h
Normal file
35
src/vio/csync_vio_handle_private.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_HANDLE_PRIVATE_H
|
||||
#define _CSYNC_VIO_HANDLE_PRIVATE_H
|
||||
|
||||
struct csync_vio_handle_s {
|
||||
char *uri;
|
||||
|
||||
csync_vio_method_handle_t *method_handle;
|
||||
};
|
||||
|
||||
csync_vio_handle_t *csync_vio_handle_new(char *uri, csync_vio_method_handle_t *method_handle);
|
||||
void csync_vio_handle_destroy(csync_vio_handle_t *handle);
|
||||
|
||||
#endif /* _CSYNC_VIO_HANDLE_PRIVATE_H */
|
80
src/vio/csync_vio_method.h
Normal file
80
src/vio/csync_vio_method.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_METHOD_H
|
||||
#define _CSYNC_VIO_METHOD_H
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "vio/csync_vio_file_stat.h"
|
||||
#include "vio/csync_vio_handle.h"
|
||||
|
||||
typedef struct csync_vio_method_s csync_vio_method_t;
|
||||
|
||||
typedef csync_vio_method_t *(*csync_vio_method_init_fn)(const char *method_name, const char *config_args);
|
||||
typedef void (*csync_vio_method_finish_fn)(csync_vio_method_t *method);
|
||||
|
||||
typedef csync_vio_method_handle_t *(*csync_method_open_fn)(const char *durl, int flags, mode_t mode);
|
||||
typedef csync_vio_method_handle_t *(*csync_method_creat_fn)(const char *durl, mode_t mode);
|
||||
typedef int (*csync_method_close_fn)(csync_vio_method_handle_t *fhandle);
|
||||
typedef ssize_t (*csync_method_read_fn)(csync_vio_method_handle_t *fhandle, void *buf, size_t count);
|
||||
typedef ssize_t (*csync_method_write_fn)(csync_vio_method_handle_t *fhandle, const void *buf, size_t count);
|
||||
typedef off_t (*csync_method_lseek_fn)(csync_vio_method_handle_t *fhandle, off_t offset, int whence);
|
||||
|
||||
typedef csync_vio_method_handle_t *(*csync_method_opendir_fn)(const char *name);
|
||||
typedef int (*csync_method_closedir_fn)(csync_vio_method_t *dhandle);
|
||||
typedef csync_vio_file_stat_t *(*csync_method_readdir_fn)(csync_vio_method_handle_t *dhandle);
|
||||
|
||||
typedef int (*csync_method_mkdir_fn)(const char *uri, mode_t mode);
|
||||
typedef int (*csync_method_rmdir_fn)(const char *uri);
|
||||
|
||||
typedef int (*csync_method_stat_fn)(const char *uri, csync_vio_file_stat_t *buf);
|
||||
typedef int (*csync_method_rename_fn)(const char *olduri, const char *newuri);
|
||||
typedef int (*csync_method_unlink_fn)(const char *uri);
|
||||
|
||||
typedef int (*csync_method_chmod_fn)(const char *uri, mode_t mode);
|
||||
typedef int (*csync_method_chown_fn)(const char *uri, uid_t owner, gid_t group);
|
||||
|
||||
typedef int (*csync_method_utimes_fn)(const char *uri, const struct timeval times[2]);
|
||||
|
||||
struct csync_vio_method_s {
|
||||
size_t method_table_size; /* Used for versioning */
|
||||
csync_method_open_fn open;
|
||||
csync_method_creat_fn creat;
|
||||
csync_method_close_fn close;
|
||||
csync_method_read_fn read;
|
||||
csync_method_write_fn write;
|
||||
csync_method_lseek_fn lseek;
|
||||
csync_method_opendir_fn opendir;
|
||||
csync_method_closedir_fn closedir;
|
||||
csync_method_readdir_fn readdir;
|
||||
csync_method_mkdir_fn mkdir;
|
||||
csync_method_rmdir_fn rmdir;
|
||||
csync_method_stat_fn stat;
|
||||
csync_method_rename_fn rename;
|
||||
csync_method_unlink_fn unlink;
|
||||
csync_method_chmod_fn chmod;
|
||||
csync_method_chown_fn chwon;
|
||||
csync_method_utimes_fn utimes;
|
||||
};
|
||||
|
||||
#endif /* _CSYNC_VIO_H */
|
31
src/vio/csync_vio_module.h
Normal file
31
src/vio/csync_vio_module.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* vim: ft=c.doxygen ts=2 sw=2 et cindent
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_VIO_MODULE_H
|
||||
#define _CSYNC_VIO_MODULE_H
|
||||
|
||||
#include "vio/csync_vio_method.h"
|
||||
|
||||
extern csync_vio_method_t *vio_module_init (const char *method_name, const char *args);
|
||||
extern void vio_module_shutdown(csync_vio_method_t *method);
|
||||
|
||||
#endif /* _CSYNC_VIO_MODULE_H */
|
|
@ -36,3 +36,6 @@ macro_add_check_test(check_csync_config csync_tests/check_csync_config.c ${TEST_
|
|||
macro_add_check_test(check_csync_exclude csync_tests/check_csync_exclude.c ${TEST_TARGET_LIBRARIES})
|
||||
macro_add_check_test(check_csync_journal csync_tests/check_csync_journal.c ${TEST_TARGET_LIBRARIES})
|
||||
|
||||
# vio
|
||||
macro_add_check_test(check_vio_handle vio_tests/check_vio_handle.c ${TEST_TARGET_LIBRARIES})
|
||||
|
||||
|
|
71
tests/vio_tests/check_vio_handle.c
Normal file
71
tests/vio_tests/check_vio_handle.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#define _GNU_SOURCE /* asprintf */
|
||||
#include <string.h>
|
||||
|
||||
#include "support.h"
|
||||
|
||||
#include "vio/csync_vio_handle.h"
|
||||
#include "vio/csync_vio_handle_private.h"
|
||||
|
||||
START_TEST (check_csync_vio_handle_new)
|
||||
{
|
||||
int *number = NULL;
|
||||
csync_vio_handle_t *handle = NULL;
|
||||
|
||||
number = c_malloc(sizeof(int));
|
||||
*number = 42;
|
||||
|
||||
handle = csync_vio_handle_new(c_strdup("/tmp"), (csync_vio_method_handle_t *) number);
|
||||
fail_if(handle == NULL, NULL);
|
||||
fail_unless(strcmp(handle->uri, "/tmp") == 0, NULL);
|
||||
|
||||
SAFE_FREE(handle->method_handle);
|
||||
|
||||
csync_vio_handle_destroy(handle);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_vio_handle_new_null)
|
||||
{
|
||||
int *number = NULL;
|
||||
csync_vio_handle_t *handle = NULL;
|
||||
|
||||
number = c_malloc(sizeof(int));
|
||||
*number = 42;
|
||||
|
||||
handle = csync_vio_handle_new(NULL, (csync_vio_method_handle_t *) number);
|
||||
fail_unless(handle == NULL, NULL);
|
||||
|
||||
handle = csync_vio_handle_new("/tmp", NULL);
|
||||
fail_unless(handle == NULL, NULL);
|
||||
|
||||
SAFE_FREE(number);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
static Suite *csync_vio_suite(void) {
|
||||
Suite *s = suite_create("csync_vio_handle");
|
||||
|
||||
create_case(s, "check_csync_vio_handle_new", check_csync_vio_handle_new);
|
||||
create_case(s, "check_csync_vio_handle_new_null", check_csync_vio_handle_new_null);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int nf;
|
||||
|
||||
Suite *s = csync_vio_suite();
|
||||
|
||||
SRunner *sr;
|
||||
sr = srunner_create(s);
|
||||
#if 0
|
||||
srunner_set_fork_status(sr, CK_NOFORK);
|
||||
#endif
|
||||
srunner_run_all(sr, CK_VERBOSE);
|
||||
nf = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in a new issue