mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
csync: Add support for a log callback.
This commit is contained in:
parent
805621540a
commit
890df87d00
25
src/csync.c
25
src/csync.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 2008 by Andreas Schneider <mail@cynapses.org>
|
||||
* Copyright (c) 2008-2012 by Andreas Schneider <asn@cryptomilk.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -771,6 +771,21 @@ int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int csync_set_log_callback(CSYNC *ctx, csync_log_callback cb) {
|
||||
if (ctx == NULL || cb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctx->status & CSYNC_STATUS_INIT) {
|
||||
fprintf(stderr, "This function must be called before initialization.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->callbacks.log_function = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *csync_get_statedb_file(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
@ -805,6 +820,14 @@ csync_auth_callback csync_get_auth_callback(CSYNC *ctx) {
|
||||
return ctx->callbacks.auth_function;
|
||||
}
|
||||
|
||||
csync_log_callback csync_get_log_callback(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx->callbacks.log_function;
|
||||
}
|
||||
|
||||
int csync_set_status(CSYNC *ctx, int status) {
|
||||
if (ctx == NULL || status < 0) {
|
||||
return -1;
|
||||
|
||||
35
src/csync.h
35
src/csync.h
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 2006-2008 by Andreas Schneider <mail@cynapses.org>
|
||||
* Copyright (c) 2006-2012 by Andreas Schneider <asn@cryptomilk.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -69,9 +69,6 @@ extern "C" {
|
||||
#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.
|
||||
@ -126,6 +123,15 @@ typedef struct csync_tree_walk_file_s TREE_WALK_FILE;
|
||||
*/
|
||||
typedef struct csync_s CSYNC;
|
||||
|
||||
typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len,
|
||||
int echo, int verify, void *userdata);
|
||||
|
||||
typedef void (*csync_log_callback) (CSYNC *ctx,
|
||||
int verbosity,
|
||||
const char *function,
|
||||
const char *buffer,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* @brief Allocate a csync context.
|
||||
*
|
||||
@ -319,6 +325,27 @@ csync_auth_callback csync_get_auth_callback(CSYNC *ctx);
|
||||
*/
|
||||
int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb);
|
||||
|
||||
/**
|
||||
* @brief Get the logging callback set.
|
||||
*
|
||||
* @param ctx The csync context.
|
||||
*
|
||||
* @return The logging callback set or NULL if an error
|
||||
* occured.
|
||||
*/
|
||||
csync_log_callback csync_get_log_callback(CSYNC *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set the logging callback.
|
||||
*
|
||||
* @param ctx The csync context.
|
||||
*
|
||||
* @param cb The logging callback.
|
||||
*
|
||||
* @return 0 on success, less than 0 if an error occured.
|
||||
*/
|
||||
int csync_set_log_callback(CSYNC *ctx, csync_log_callback cb);
|
||||
|
||||
/**
|
||||
* @brief Get the path of the statedb file used.
|
||||
*
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libcsync -- a library to sync a directory with another
|
||||
*
|
||||
* Copyright (c) 2006 by Andreas Schneider <mail@cynapses.org>
|
||||
* Copyright (c) 2006-2012 by Andreas Schneider <asn@cryptomilk.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -81,6 +81,7 @@ enum csync_replica_e {
|
||||
struct csync_s {
|
||||
struct {
|
||||
csync_auth_callback auth_function;
|
||||
csync_log_callback log_function;
|
||||
void *userdata;
|
||||
} callbacks;
|
||||
c_strlist_t *excludes;
|
||||
|
||||
@ -35,6 +35,7 @@ add_cmocka_test(check_std_c_time std_tests/check_std_c_time.c ${TEST_TARGET_LIBR
|
||||
|
||||
add_cmocka_test(check_csync_create csync_tests/check_csync_create.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_csync_lock csync_tests/check_csync_lock.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_csync_log csync_tests/check_csync_log.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_csync_config csync_tests/check_csync_config.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_csync_exclude csync_tests/check_csync_exclude.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_csync_statedb_load csync_tests/check_csync_statedb_load.c ${TEST_TARGET_LIBRARIES})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user