mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
vio: Add new function csync_vio_put and csync_vio_put.
With that, modules can implement get and put functions to up- and download files from or to a given file descriptor. That is just an alternative way of the usual read/write way that is still there of course. If a module wants to implement get and put, it has to set its capabilities to true.
This commit is contained in:
parent
527da08d3b
commit
ec6f40c84e
4 changed files with 84 additions and 2 deletions
|
@ -898,7 +898,9 @@ static char*_lastDir = NULL;
|
|||
* bool atomar_copy_support
|
||||
*/
|
||||
|
||||
static csync_vio_capabilities_t _owncloud_capabilities = { true };
|
||||
static struct csync_vio_capabilities_s _owncloud_capabilities = {
|
||||
.atomar_copy_support = true,
|
||||
};
|
||||
|
||||
static csync_vio_capabilities_t *owncloud_get_capabilities(void)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <dlfcn.h> /* dlopen(), dlclose(), dlsym() ... */
|
||||
|
||||
#include "csync_private.h"
|
||||
#include "csync_util.h"
|
||||
#include "vio/csync_vio.h"
|
||||
#include "vio/csync_vio_handle_private.h"
|
||||
#include "vio/csync_vio_local.h"
|
||||
|
@ -152,6 +153,9 @@ int csync_vio_init(CSYNC *ctx, const char *module, const char *args) {
|
|||
|
||||
/* Useful defaults to the module capabilities */
|
||||
ctx->module.capabilities.atomar_copy_support = false;
|
||||
ctx->module.capabilities.put_support = false;
|
||||
ctx->module.capabilities.get_support = false;
|
||||
|
||||
/* Load the module capabilities from the module if it implements the it. */
|
||||
if( VIO_METHOD_HAS_FUNC(m, get_capabilities)) {
|
||||
ctx->module.capabilities = *(m->get_capabilities());
|
||||
|
@ -257,6 +261,67 @@ int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *fhandle) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
int csync_vio_getfd(CSYNC *ctx, csync_vio_handle_t *fhandle) {
|
||||
int fd = -1;
|
||||
(void) ctx;
|
||||
|
||||
if (fhandle == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = csync_vio_local_getfd( fhandle );
|
||||
// Return the correct handle here.
|
||||
return fd;
|
||||
|
||||
}
|
||||
|
||||
int csync_vio_put(CSYNC *ctx,
|
||||
csync_vio_handle_t *flocal,
|
||||
csync_vio_handle_t *fremote,
|
||||
csync_file_stat_t *st) {
|
||||
int rc = 0;
|
||||
csync_vio_file_stat_t *vfs = csync_vio_convert_file_stat(st);
|
||||
|
||||
if (flocal == NULL) {
|
||||
rc = -1;
|
||||
}
|
||||
if (vfs == NULL) {
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
rc = ctx->module.method->put(flocal->method_handle,
|
||||
fremote->method_handle,
|
||||
vfs);
|
||||
}
|
||||
csync_vio_file_stat_destroy(vfs);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int csync_vio_get(CSYNC *ctx,
|
||||
csync_vio_handle_t *flocal,
|
||||
csync_vio_handle_t *fremote,
|
||||
csync_file_stat_t *st) {
|
||||
int rc = 0;
|
||||
csync_vio_file_stat_t *vfs = csync_vio_convert_file_stat(st);
|
||||
|
||||
if (flocal == NULL) {
|
||||
rc = -1;
|
||||
}
|
||||
if (vfs == NULL) {
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
rc = ctx->module.method->get(flocal->method_handle,
|
||||
fremote->method_handle,
|
||||
vfs);
|
||||
}
|
||||
csync_vio_file_stat_destroy(vfs);
|
||||
return rc;
|
||||
}
|
||||
|
||||
ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_t count) {
|
||||
ssize_t rs = 0;
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
int csync_vio_init(CSYNC *ctx, const char *module, const char *args);
|
||||
void csync_vio_shutdown(CSYNC *ctx);
|
||||
|
||||
csync_vio_handle_t *csync_vio_open(CSYNC *ctx, const char *uri, int flags, mode_t mode);
|
||||
csync_vio_handle_t *csync_vio_creat(CSYNC *ctx, const char *uri, mode_t mode);
|
||||
int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *handle);
|
||||
|
@ -40,6 +39,11 @@ ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_
|
|||
ssize_t csync_vio_write(CSYNC *ctx, csync_vio_handle_t *fhandle, const void *buf, size_t count);
|
||||
off_t csync_vio_lseek(CSYNC *ctx, csync_vio_handle_t *fhandle, off_t offset, int whence);
|
||||
|
||||
int csync_vio_put(CSYNC *ctx, csync_vio_handle_t *flocal, csync_vio_handle_t *fremote, csync_file_stat_t *st);
|
||||
int csync_vio_get(CSYNC *ctx, csync_vio_handle_t *flocal, csync_vio_handle_t *fremote, csync_file_stat_t *st);
|
||||
|
||||
int csync_vio_getfd(CSYNC *ctx, csync_vio_handle_t *hnd);
|
||||
|
||||
csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name);
|
||||
int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle);
|
||||
csync_vio_file_stat_t *csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle);
|
||||
|
|
|
@ -37,6 +37,8 @@ typedef struct csync_vio_method_s csync_vio_method_t;
|
|||
|
||||
struct csync_vio_capabilities_s {
|
||||
bool atomar_copy_support;
|
||||
bool get_support;
|
||||
bool put_support;
|
||||
};
|
||||
|
||||
typedef struct csync_vio_capabilities_s csync_vio_capabilities_t;
|
||||
|
@ -76,6 +78,13 @@ typedef char* (*csync_method_get_error_string_fn)();
|
|||
|
||||
typedef int (*csync_method_commit_fn)();
|
||||
|
||||
typedef int (*csync_method_get_fn)(csync_vio_method_handle_t *flocal,
|
||||
csync_vio_method_handle_t *fremote,
|
||||
csync_vio_file_stat_t *st);
|
||||
typedef int (*csync_method_put_fn)(csync_vio_method_handle_t *flocal,
|
||||
csync_vio_method_handle_t *fremote,
|
||||
csync_vio_file_stat_t *st);
|
||||
|
||||
struct csync_vio_method_s {
|
||||
size_t method_table_size; /* Used for versioning */
|
||||
csync_method_get_capabilities_fn get_capabilities;
|
||||
|
@ -99,6 +108,8 @@ struct csync_vio_method_s {
|
|||
csync_method_set_property_fn set_property;
|
||||
csync_method_get_error_string_fn get_error_string;
|
||||
csync_method_commit_fn commit;
|
||||
csync_method_put_fn put;
|
||||
csync_method_get_fn get;
|
||||
};
|
||||
|
||||
#endif /* _CSYNC_VIO_H */
|
||||
|
|
Loading…
Reference in a new issue