hbf: add a callback when the chunk upload is finished

Also add an user_data to other callbacks
This commit is contained in:
Olivier Goffart 2013-10-16 16:46:22 +02:00
parent f9ce534687
commit e69ecd3a80
3 changed files with 18 additions and 10 deletions

View File

@ -1201,13 +1201,15 @@ static csync_vio_method_handle_t *owncloud_creat(const char *durl, mode_t mode)
return handle;
}
static int _user_want_abort()
static int _user_want_abort(void *userdata)
{
(void)userdata;
return csync_abort_requested(dav_session.csync_ctx);
}
static void _log_callback(const char *func, const char *text)
static void _log_callback(const char *func, const char *text, void *userdata)
{
(void)userdata;
csync_log(CSYNC_LOG_PRIORITY_TRACE, func, "%s", text);
}
@ -1355,7 +1357,7 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha
if (write_ctx->req)
ne_request_destroy( write_ctx->req );
if( _user_want_abort() ) {
if( _user_want_abort(0) ) {
errno = ERRNO_USER_ABORT;
break;
}

View File

@ -42,7 +42,7 @@
#define DEBUG_HBF(...) { if(transfer->log_cb) { \
char buf[1024]; \
snprintf(buf, 1024, __VA_ARGS__); \
transfer->log_cb(__FUNCTION__, buf); \
transfer->log_cb(__FUNCTION__, buf, transfer->user_data); \
} }
#endif
@ -447,7 +447,7 @@ Hbf_State hbf_transfer( ne_session *session, hbf_transfer_t *transfer, const cha
if( ! block ) state = HBF_PARAM_FAIL;
if( transfer->abort_cb ) {
int do_abort = (transfer->abort_cb)();
int do_abort = (transfer->abort_cb)(transfer->user_data);
if( do_abort ) {
state = HBF_USER_ABORTED;
transfer->start_id = block_id % transfer->block_cnt;
@ -515,6 +515,10 @@ Hbf_State hbf_transfer( ne_session *session, hbf_transfer_t *transfer, const cha
}
}
if (state == HBF_TRANSFER_SUCCESS && transfer->chunk_finished_cb) {
transfer->chunk_finished_cb(transfer, block_id, transfer->user_data);
}
} else {
state = HBF_MEMORY_FAIL;
}

View File

@ -72,13 +72,13 @@ struct hbf_block_s {
int tries;
};
/* Callback for to check on abort */
typedef int (*hbf_abort_callback) ();
typedef void (*hbf_log_callback) (const char *, const char *);
typedef struct hbf_transfer_s hbf_transfer_t;
/* Callback for to check on abort */
typedef int (*hbf_abort_callback) (void *);
typedef void (*hbf_log_callback) (const char *, const char *, void*);
typedef void (*hbf_chunk_finished_callback) (hbf_transfer_t*,int, void*);
struct hbf_transfer_s {
hbf_block_t **block_arr;
int block_cnt;
@ -95,8 +95,10 @@ struct hbf_transfer_s {
int64_t block_size;
int64_t threshold;
void *user_data;
hbf_abort_callback abort_cb;
hbf_log_callback log_cb;
hbf_chunk_finished_callback chunk_finished_cb;
int modtime_accepted;
const char *previous_etag; /* etag send as the If-Match http header */