mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
Added error_string handling with modules
This commit is contained in:
parent
e3ef10765b
commit
ecf09c4077
7 changed files with 47 additions and 12 deletions
|
@ -147,6 +147,8 @@ struct dav_session_s {
|
|||
|
||||
char *session_key;
|
||||
|
||||
char *error_string;
|
||||
|
||||
int read_timeout;
|
||||
|
||||
long int prev_delta;
|
||||
|
@ -201,6 +203,13 @@ static void clean_caches() {
|
|||
char _buffer[PUT_BUFFER_SIZE];
|
||||
|
||||
/* ***************************************************************************** */
|
||||
static void set_error_message( const char *msg )
|
||||
{
|
||||
SAFE_FREE(dav_session.error_string);
|
||||
if( msg )
|
||||
dav_session.error_string = c_strdup(msg);
|
||||
}
|
||||
|
||||
static void set_errno_from_http_errcode( int err ) {
|
||||
int new_errno = 0;
|
||||
|
||||
|
@ -279,9 +288,11 @@ static int http_result_code_from_session() {
|
|||
char *q;
|
||||
int err;
|
||||
|
||||
set_error_message(p); /* remember the error message */
|
||||
|
||||
err = strtol(p, &q, 10);
|
||||
if (p == q) {
|
||||
err = EIO;
|
||||
err = ERRNO_ERROR_STRING;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -289,8 +300,8 @@ static int http_result_code_from_session() {
|
|||
static void set_errno_from_session() {
|
||||
int err = http_result_code_from_session();
|
||||
|
||||
if( err == EIO ) {
|
||||
errno = EIO;
|
||||
if( err == EIO || err == ERRNO_ERROR_STRING) {
|
||||
errno = err;
|
||||
} else {
|
||||
set_errno_from_http_errcode(err);
|
||||
}
|
||||
|
@ -337,7 +348,6 @@ static void set_errno_from_neon_errcode( int neon_code ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* cleanPath to return an escaped path of an uri */
|
||||
static char *_cleanPath( const char* uri ) {
|
||||
int rc = 0;
|
||||
|
@ -428,8 +438,9 @@ static int verify_sslcert(void *userdata, int failures,
|
|||
if( buf[0] == 'y' || buf[0] == 'Y') {
|
||||
ret = 0;
|
||||
} else {
|
||||
DEBUG_WEBDAV("Authentication callback replied %s", buf );
|
||||
}
|
||||
DEBUG_WEBDAV("Authentication callback replied %s", buf );
|
||||
|
||||
}
|
||||
}
|
||||
DEBUG_WEBDAV("## VERIFY_SSL CERT: %d", ret );
|
||||
return ret;
|
||||
|
@ -992,7 +1003,7 @@ static struct listdir_context *fetch_resource_list(const char *uri, int depth)
|
|||
DEBUG_WEBDAV("ERROR: Request failed: status %d (%s)", req_status->code,
|
||||
req_status->reason_phrase);
|
||||
ret = NE_CONNECT;
|
||||
|
||||
set_error_message(req_status->reason_phrase);
|
||||
if (_progresscb) {
|
||||
_progresscb(uri, CSYNC_NOTIFY_ERROR, req_status->code, (long long)(req_status->reason_phrase) ,dav_session.userdata);
|
||||
}
|
||||
|
@ -1017,6 +1028,7 @@ static struct listdir_context *fetch_resource_list(const char *uri, int depth)
|
|||
DEBUG_WEBDAV("ERROR: Content type of propfind request not XML: %s.",
|
||||
content_type ? content_type: "<empty>");
|
||||
errno = ERRNO_WRONG_CONTENT;
|
||||
set_error_message("Server error: PROPFIND reply is not XML formatted!");
|
||||
ret = NE_CONNECT;
|
||||
}
|
||||
}
|
||||
|
@ -1042,8 +1054,8 @@ static struct listdir_context *fetch_resource_list(const char *uri, int depth)
|
|||
} else if( dav_session.time_delta_cnt > 1 ) {
|
||||
if( time_diff_delta > 5 ) {
|
||||
DEBUG_WEBDAV("WRN: The time delta changed more than 5 second");
|
||||
errno = ERRNO_TIMEDELTA;
|
||||
ret = OC_TIMEDELTA_FAIL;
|
||||
// errno = ERRNO_TIMEDELTA;
|
||||
// ret = OC_TIMEDELTA_FAIL;
|
||||
} else {
|
||||
DEBUG_WEBDAV("Ok: Time delta remained (almost) the same: %llu.", (unsigned long long) time_diff);
|
||||
}
|
||||
|
@ -1923,6 +1935,11 @@ static int owncloud_chown(const char *uri, uid_t owner, gid_t group) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char *owncloud_error_string()
|
||||
{
|
||||
return dav_session.error_string;
|
||||
}
|
||||
|
||||
static int owncloud_utimes(const char *uri, const struct timeval *times) {
|
||||
|
||||
ne_proppatch_operation ops[2];
|
||||
|
@ -2031,7 +2048,8 @@ csync_vio_method_t _method = {
|
|||
.chmod = owncloud_chmod,
|
||||
.chown = owncloud_chown,
|
||||
.utimes = owncloud_utimes,
|
||||
.set_property = owncloud_set_property
|
||||
.set_property = owncloud_set_property,
|
||||
.get_error_string = owncloud_error_string
|
||||
};
|
||||
|
||||
csync_vio_method_t *vio_module_init(const char *method_name, const char *args,
|
||||
|
@ -2059,6 +2077,7 @@ void vio_module_shutdown(csync_vio_method_t *method) {
|
|||
SAFE_FREE( dav_session.proxy_user );
|
||||
SAFE_FREE( dav_session.proxy_pwd );
|
||||
SAFE_FREE( dav_session.session_key);
|
||||
SAFE_FREE( dav_session.error_string );
|
||||
|
||||
SAFE_FREE( _lastDir );
|
||||
|
||||
|
|
|
@ -723,6 +723,7 @@ int csync_destroy(CSYNC *ctx) {
|
|||
SAFE_FREE(ctx->remote.uri);
|
||||
SAFE_FREE(ctx->options.config_dir);
|
||||
SAFE_FREE(ctx->statedb.file);
|
||||
SAFE_FREE(ctx->error_string);
|
||||
|
||||
#ifdef WITH_ICONV
|
||||
c_close_iconv();
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#define ERRNO_REDIRECT CSYNC_CUSTOM_ERRNO_BASE+10
|
||||
#define ERRNO_WRONG_CONTENT CSYNC_CUSTOM_ERRNO_BASE+11
|
||||
#define ERRNO_TIMEDELTA CSYNC_CUSTOM_ERRNO_BASE+12
|
||||
|
||||
#define ERRNO_ERROR_STRING CSYNC_CUSTOM_ERRNO_BASE+13
|
||||
|
||||
#endif /* _CSYNC_MACROS_H */
|
||||
/* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */
|
||||
|
|
|
@ -150,6 +150,7 @@ struct csync_s {
|
|||
|
||||
/* error code of the last operation */
|
||||
enum csync_error_codes_e error_code;
|
||||
char *error_string;
|
||||
|
||||
int status;
|
||||
};
|
||||
|
|
|
@ -670,4 +670,13 @@ int csync_vio_set_property(CSYNC* ctx, const char* key, void* data)
|
|||
return rc;
|
||||
}
|
||||
|
||||
|
||||
char *csync_vio_get_error_string(CSYNC *ctx)
|
||||
{
|
||||
if(ctx->error_string) {
|
||||
return ctx->error_string;
|
||||
}
|
||||
if(VIO_METHOD_HAS_FUNC(ctx->module.method, get_error_string)) {
|
||||
return ctx->module.method->get_error_string();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -65,4 +65,6 @@ int csync_vio_utimes(CSYNC *ctx, const char *uri, const struct timeval *times);
|
|||
|
||||
int csync_vio_set_property(CSYNC *ctx, const char *key, void *data);
|
||||
|
||||
char *csync_vio_get_error_string(CSYNC *ctx);
|
||||
|
||||
#endif /* _CSYNC_VIO_H */
|
||||
|
|
|
@ -80,6 +80,8 @@ typedef int (*csync_method_utimes_fn)(const char *uri, const struct timeval time
|
|||
|
||||
typedef int (*csync_method_set_property_fn)(const char *key, void *data);
|
||||
|
||||
typedef char* (*csync_method_get_error_string_fn)();
|
||||
|
||||
struct csync_vio_method_s {
|
||||
size_t method_table_size; /* Used for versioning */
|
||||
csync_method_get_capabilities_fn get_capabilities;
|
||||
|
@ -103,6 +105,7 @@ struct csync_vio_method_s {
|
|||
csync_method_utimes_fn utimes;
|
||||
csync_method_sendfile_fn sendfile;
|
||||
csync_method_set_property_fn set_property;
|
||||
csync_method_get_error_string_fn get_error_string;
|
||||
};
|
||||
|
||||
#endif /* _CSYNC_VIO_H */
|
||||
|
|
Loading…
Reference in a new issue