2011-09-01 22:00:20 +04:00
|
|
|
/*
|
|
|
|
* libcsync -- a library to sync a directory with another
|
|
|
|
*
|
2011-09-13 16:15:44 +04:00
|
|
|
* Copyright (c) 2011 by Andreas Schneider <asn@cryptomilk.org>
|
2012-02-02 18:50:44 +04:00
|
|
|
* Copyright (c) 2012 by Klaas Freitag <freitag@owncloud.com>
|
2011-09-01 22:00:20 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 17:50:31 +04:00
|
|
|
|
2013-05-08 15:12:01 +04:00
|
|
|
#include "csync_owncloud.h"
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2013-07-31 15:12:10 +04:00
|
|
|
#include <inttypes.h>
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
/*
|
|
|
|
* free the fetchCtx
|
|
|
|
*/
|
|
|
|
static void free_fetchCtx( struct listdir_context *ctx )
|
|
|
|
{
|
|
|
|
struct resource *newres, *res;
|
|
|
|
if( ! ctx ) return;
|
|
|
|
newres = ctx->list;
|
|
|
|
res = newres;
|
|
|
|
|
|
|
|
ctx->ref--;
|
|
|
|
if (ctx->ref > 0) return;
|
|
|
|
|
|
|
|
SAFE_FREE(ctx->target);
|
|
|
|
|
|
|
|
while( res ) {
|
|
|
|
SAFE_FREE(res->uri);
|
|
|
|
SAFE_FREE(res->name);
|
|
|
|
SAFE_FREE(res->md5);
|
|
|
|
|
|
|
|
newres = res->next;
|
|
|
|
SAFE_FREE(res);
|
|
|
|
res = newres;
|
|
|
|
}
|
|
|
|
SAFE_FREE(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/*
|
|
|
|
* local variables.
|
|
|
|
*/
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
struct dav_session_s dav_session; /* The DAV Session, initialised in dav_connect */
|
2012-04-27 18:33:31 +04:00
|
|
|
int _connected = 0; /* flag to indicate if a connection exists, ie.
|
2012-02-02 18:50:44 +04:00
|
|
|
the dav_session is valid */
|
2012-08-23 18:35:16 +04:00
|
|
|
|
2012-02-10 17:20:28 +04:00
|
|
|
csync_auth_callback _authcb;
|
2013-01-30 15:29:56 +04:00
|
|
|
long long chunked_total_size = 0;
|
|
|
|
long long chunked_done = 0;
|
2012-12-04 20:21:53 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
struct listdir_context *propfind_cache = 0;
|
2013-05-08 13:57:29 +04:00
|
|
|
|
|
|
|
bool is_first_propfind = true;
|
2013-05-08 15:12:01 +04:00
|
|
|
|
2013-05-08 13:57:29 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
csync_vio_file_stat_t _stat_cache;
|
2012-12-06 17:00:05 +04:00
|
|
|
/* id cache, cache the ETag: header of a GET request */
|
|
|
|
struct { char *uri; char *id; } _id_cache = { NULL, NULL };
|
|
|
|
|
|
|
|
static void clean_caches() {
|
2013-05-08 13:57:29 +04:00
|
|
|
clear_propfind_recursive_cache();
|
|
|
|
is_first_propfind = true;
|
|
|
|
|
2012-12-06 17:00:05 +04:00
|
|
|
free_fetchCtx(propfind_cache);
|
|
|
|
propfind_cache = NULL;
|
|
|
|
|
|
|
|
SAFE_FREE(_stat_cache.name);
|
|
|
|
SAFE_FREE(_stat_cache.md5 );
|
|
|
|
|
|
|
|
SAFE_FREE(_id_cache.uri);
|
|
|
|
SAFE_FREE(_id_cache.id);
|
|
|
|
}
|
2012-12-05 16:50:26 +04:00
|
|
|
|
|
|
|
|
2012-02-10 17:20:28 +04:00
|
|
|
|
2012-03-30 15:58:59 +04:00
|
|
|
#define PUT_BUFFER_SIZE 1024*5
|
|
|
|
|
|
|
|
char _buffer[PUT_BUFFER_SIZE];
|
|
|
|
|
2011-09-13 16:15:44 +04:00
|
|
|
|
2013-07-24 17:07:38 +04:00
|
|
|
/* Differance in usec between two time */
|
|
|
|
static int64_t _timediff(struct timeval x , struct timeval y)
|
|
|
|
{
|
|
|
|
return (y.tv_sec - x.tv_sec)*1000000 + (y.tv_usec - x.tv_usec);
|
|
|
|
}
|
2012-12-06 16:15:01 +04:00
|
|
|
|
2012-02-20 14:14:53 +04:00
|
|
|
/*
|
|
|
|
* helper method to build up a user text for SSL problems, called from the
|
|
|
|
* verify_sslcert callback.
|
|
|
|
*/
|
2012-02-20 00:50:12 +04:00
|
|
|
static void addSSLWarning( char *ptr, const char *warn, int len )
|
|
|
|
{
|
|
|
|
char *concatHere = ptr;
|
2012-02-20 14:14:53 +04:00
|
|
|
int remainingLen = 0;
|
2012-02-20 00:50:12 +04:00
|
|
|
|
|
|
|
if( ! (warn && ptr )) return;
|
2012-02-20 14:14:53 +04:00
|
|
|
remainingLen = len - strlen(ptr);
|
2012-02-22 20:23:08 +04:00
|
|
|
if( remainingLen <= 0 ) return;
|
2012-03-07 19:38:54 +04:00
|
|
|
concatHere = ptr + strlen(ptr); /* put the write pointer to the end. */
|
2012-02-20 00:50:12 +04:00
|
|
|
strncpy( concatHere, warn, remainingLen );
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:14:53 +04:00
|
|
|
/*
|
|
|
|
* Callback to verify the SSL certificate, called from libneon.
|
|
|
|
* It analyzes the SSL problem, creates a user information text and passes
|
|
|
|
* it to the csync callback to ask the user.
|
|
|
|
*/
|
2012-02-20 00:50:12 +04:00
|
|
|
#define LEN 4096
|
|
|
|
static int verify_sslcert(void *userdata, int failures,
|
2012-12-19 21:06:36 +04:00
|
|
|
const ne_ssl_certificate *certificate)
|
2012-02-20 00:50:12 +04:00
|
|
|
{
|
|
|
|
char problem[LEN];
|
2012-12-07 15:17:26 +04:00
|
|
|
char buf[MAX(NE_SSL_DIGESTLEN, NE_ABUFSIZ)];
|
2012-02-20 00:50:12 +04:00
|
|
|
int ret = -1;
|
2012-12-19 21:06:36 +04:00
|
|
|
const ne_ssl_certificate *cert = certificate;
|
2012-02-20 00:50:12 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
(void) userdata;
|
2012-02-20 00:50:12 +04:00
|
|
|
memset( problem, 0, LEN );
|
|
|
|
|
2012-12-19 21:06:36 +04:00
|
|
|
while( cert ) {
|
|
|
|
|
|
|
|
addSSLWarning( problem, "There are problems with the SSL certificate:\n", LEN );
|
|
|
|
if( failures & NE_SSL_NOTYETVALID ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The certificate is not yet valid.\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
|
|
|
if( failures & NE_SSL_EXPIRED ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The certificate has expired.\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
2012-02-20 00:50:12 +04:00
|
|
|
|
2012-12-19 21:06:36 +04:00
|
|
|
if( failures & NE_SSL_UNTRUSTED ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The certificate is not trusted!\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
|
|
|
if( failures & NE_SSL_IDMISMATCH ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The hostname for which the certificate was "
|
|
|
|
"issued does not match the hostname of the server\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
|
|
|
if( failures & NE_SSL_BADCHAIN ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The certificate chain contained a certificate other than the server cert\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
|
|
|
if( failures & NE_SSL_REVOKED ) {
|
2012-02-20 00:50:12 +04:00
|
|
|
addSSLWarning( problem, " * The server certificate has been revoked by the issuing authority.\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
2012-02-20 00:50:12 +04:00
|
|
|
|
2012-12-19 21:06:36 +04:00
|
|
|
if (ne_ssl_cert_digest(cert, buf) == 0) {
|
2012-12-07 15:17:26 +04:00
|
|
|
addSSLWarning( problem, "Certificate fingerprint: ", LEN );
|
|
|
|
addSSLWarning( problem, buf, LEN );
|
|
|
|
addSSLWarning( problem, "\n", LEN );
|
2012-12-19 21:06:36 +04:00
|
|
|
}
|
|
|
|
cert = ne_ssl_cert_signedby( cert );
|
2012-12-07 15:17:26 +04:00
|
|
|
}
|
2012-12-19 21:06:36 +04:00
|
|
|
addSSLWarning( problem, "Do you want to accept the certificate chain anyway?\nAnswer yes to do so and take the risk: ", LEN );
|
2012-02-20 00:50:12 +04:00
|
|
|
|
|
|
|
if( _authcb ){
|
|
|
|
/* call the csync callback */
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Call the csync callback for SSL problems");
|
2012-02-20 00:50:12 +04:00
|
|
|
memset( buf, 0, NE_ABUFSIZ );
|
2013-07-05 20:43:29 +04:00
|
|
|
(*_authcb) ( problem, buf, NE_ABUFSIZ-1, 1, 0, NULL );
|
2012-12-07 15:17:26 +04:00
|
|
|
if( buf[0] == 'y' || buf[0] == 'Y') {
|
2012-02-20 00:50:12 +04:00
|
|
|
ret = 0;
|
2012-06-13 13:26:37 +04:00
|
|
|
} else {
|
2012-12-14 19:48:47 +04:00
|
|
|
DEBUG_WEBDAV("Authentication callback replied %s", buf );
|
|
|
|
|
|
|
|
}
|
2012-02-20 00:50:12 +04:00
|
|
|
}
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("## VERIFY_SSL CERT: %d", ret );
|
2013-01-16 14:42:13 +04:00
|
|
|
return ret;
|
2012-02-20 00:50:12 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/*
|
|
|
|
* Authentication callback. Is set by ne_set_server_auth to be called
|
|
|
|
* from the neon lib to authenticate a request.
|
|
|
|
*/
|
|
|
|
static int ne_auth( void *userdata, const char *realm, int attempt,
|
|
|
|
char *username, char *password)
|
|
|
|
{
|
2012-02-10 17:20:28 +04:00
|
|
|
char buf[NE_ABUFSIZ];
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
(void) userdata;
|
|
|
|
(void) realm;
|
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
/* DEBUG_WEBDAV( "Authentication required %s", realm ); */
|
2012-02-02 18:50:44 +04:00
|
|
|
if( username && password ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV( "Authentication required %s", username );
|
2012-02-10 17:20:28 +04:00
|
|
|
if( dav_session.user ) {
|
|
|
|
/* allow user without password */
|
2012-08-08 17:45:00 +04:00
|
|
|
if( strlen( dav_session.user ) < NE_ABUFSIZ ) {
|
|
|
|
strcpy( username, dav_session.user );
|
|
|
|
}
|
|
|
|
if( dav_session.pwd && strlen( dav_session.pwd ) < NE_ABUFSIZ ) {
|
|
|
|
strcpy( password, dav_session.pwd );
|
2012-02-10 17:20:28 +04:00
|
|
|
}
|
|
|
|
} else if( _authcb != NULL ){
|
|
|
|
/* call the csync callback */
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Call the csync callback for %s", realm );
|
2012-02-10 17:20:28 +04:00
|
|
|
memset( buf, 0, NE_ABUFSIZ );
|
2013-07-05 20:43:29 +04:00
|
|
|
(*_authcb) ("Enter your username: ", buf, NE_ABUFSIZ-1, 1, 0, NULL );
|
2012-08-08 17:45:00 +04:00
|
|
|
if( strlen(buf) < NE_ABUFSIZ ) {
|
|
|
|
strcpy( username, buf );
|
|
|
|
}
|
2012-02-10 17:20:28 +04:00
|
|
|
memset( buf, 0, NE_ABUFSIZ );
|
2013-07-05 20:43:29 +04:00
|
|
|
(*_authcb) ("Enter your password: ", buf, NE_ABUFSIZ-1, 0, 0, NULL );
|
2012-08-08 17:45:00 +04:00
|
|
|
if( strlen(buf) < NE_ABUFSIZ) {
|
|
|
|
strcpy( password, buf );
|
|
|
|
}
|
2012-02-10 17:20:28 +04:00
|
|
|
} else {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("I can not authenticate!");
|
2012-02-10 17:20:28 +04:00
|
|
|
}
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
|
|
|
return attempt;
|
|
|
|
}
|
|
|
|
|
2012-07-31 18:59:15 +04:00
|
|
|
/*
|
|
|
|
* Authentication callback. Is set by ne_set_proxy_auth to be called
|
|
|
|
* from the neon lib to authenticate against a proxy. The data to authenticate
|
|
|
|
* against comes from mirall throught vio_module_init function.
|
|
|
|
*/
|
|
|
|
static int ne_proxy_auth( void *userdata, const char *realm, int attempt,
|
|
|
|
char *username, char *password)
|
|
|
|
{
|
|
|
|
(void) userdata;
|
|
|
|
(void) realm;
|
2012-08-08 17:45:00 +04:00
|
|
|
if( dav_session.proxy_user && strlen( dav_session.proxy_user ) < NE_ABUFSIZ) {
|
|
|
|
strcpy( username, dav_session.proxy_user );
|
|
|
|
if( dav_session.proxy_pwd && strlen( dav_session.proxy_pwd ) < NE_ABUFSIZ) {
|
|
|
|
strcpy( password, dav_session.proxy_pwd );
|
2012-07-31 18:59:15 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-14 16:09:35 +04:00
|
|
|
/* NTLM needs several attempts */
|
|
|
|
return (attempt < 3) ? 0 : -1;
|
2012-07-31 18:59:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the proxy depending on the variables */
|
|
|
|
static int configureProxy( ne_session *session )
|
|
|
|
{
|
|
|
|
int port = 8080;
|
|
|
|
int re = -1;
|
|
|
|
|
|
|
|
if( ! session ) return -1;
|
|
|
|
if( ! dav_session.proxy_type ) return 0; /* Go by NoProxy per default */
|
|
|
|
|
|
|
|
if( dav_session.proxy_port > 0 ) {
|
|
|
|
port = dav_session.proxy_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( c_streq(dav_session.proxy_type, "NoProxy" )) {
|
|
|
|
DEBUG_WEBDAV("No proxy configured.");
|
|
|
|
re = 0;
|
2012-10-08 23:26:12 +04:00
|
|
|
} else if( c_streq(dav_session.proxy_type, "DefaultProxy") ||
|
|
|
|
c_streq(dav_session.proxy_type, "HttpProxy") ||
|
2013-05-29 16:17:30 +04:00
|
|
|
c_streq(dav_session.proxy_type, "HttpCachingProxy") ||
|
|
|
|
c_streq(dav_session.proxy_type, "Socks5Proxy")) {
|
|
|
|
|
2012-07-31 18:59:15 +04:00
|
|
|
if( dav_session.proxy_host ) {
|
|
|
|
DEBUG_WEBDAV("%s at %s:%d", dav_session.proxy_type, dav_session.proxy_host, port );
|
2013-05-29 16:17:30 +04:00
|
|
|
if (c_streq(dav_session.proxy_type, "Socks5Proxy")) {
|
|
|
|
ne_session_socks_proxy(session, NE_SOCK_SOCKSV5, dav_session.proxy_host, port,
|
|
|
|
dav_session.proxy_user, dav_session.proxy_pwd);
|
|
|
|
} else {
|
|
|
|
ne_session_proxy(session, dav_session.proxy_host, port );
|
|
|
|
}
|
2012-07-31 18:59:15 +04:00
|
|
|
re = 2;
|
|
|
|
} else {
|
2012-10-08 23:26:12 +04:00
|
|
|
DEBUG_WEBDAV("%s requested but no proxy host defined.", dav_session.proxy_type );
|
|
|
|
/* we used to try ne_system_session_proxy here, but we should rather err out
|
|
|
|
to behave exactly like the caller. */
|
2012-07-31 18:59:15 +04:00
|
|
|
}
|
2013-05-29 16:17:30 +04:00
|
|
|
} else {
|
2012-07-31 18:59:15 +04:00
|
|
|
DEBUG_WEBDAV( "Unsupported Proxy: %s", dav_session.proxy_type );
|
|
|
|
}
|
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
2012-09-19 19:46:40 +04:00
|
|
|
/*
|
|
|
|
* This hook is called for with the response of a request. Here its checked
|
|
|
|
* if a Set-Cookie header is there for the PHPSESSID. The key is stored into
|
|
|
|
* the webdav session to be added to subsequent requests.
|
|
|
|
*/
|
|
|
|
static void post_request_hook(ne_request *req, void *userdata, const ne_status *status)
|
|
|
|
{
|
|
|
|
const char *set_cookie_header = NULL;
|
|
|
|
const char *sc = NULL;
|
|
|
|
char *key = NULL;
|
|
|
|
|
|
|
|
(void) userdata;
|
|
|
|
|
2013-02-06 15:32:48 +04:00
|
|
|
if (dav_session.session_key)
|
|
|
|
return; /* We already have a session cookie, and we should ignore other ones */
|
|
|
|
|
2012-09-19 19:46:40 +04:00
|
|
|
if(!(status && req)) return;
|
|
|
|
if( status->klass == 2 || status->code == 401 ) {
|
|
|
|
/* successful request */
|
|
|
|
set_cookie_header = ne_get_response_header( req, "Set-Cookie" );
|
|
|
|
if( set_cookie_header ) {
|
2012-09-20 12:28:54 +04:00
|
|
|
DEBUG_WEBDAV(" Set-Cookie found: %s", set_cookie_header);
|
2012-09-19 19:46:40 +04:00
|
|
|
/* try to find a ', ' sequence which is the separator of neon if multiple Set-Cookie
|
|
|
|
* headers are there.
|
|
|
|
* The following code parses a string like this:
|
2013-01-24 13:06:42 +04:00
|
|
|
* Set-Cookie: 50ace6bd8a669=p537brtt048jh8srlp2tuep7em95nh9u98mj992fbqc47d1aecp1;
|
|
|
|
*/
|
2012-09-19 19:46:40 +04:00
|
|
|
sc = set_cookie_header;
|
|
|
|
while(sc) {
|
2013-01-24 13:06:42 +04:00
|
|
|
const char *sc_val = sc;
|
|
|
|
const char *sc_end = sc_val;
|
|
|
|
int cnt = 0;
|
|
|
|
int len = strlen(sc_val); /* The length of the rest of the header string. */
|
|
|
|
|
|
|
|
while( cnt < len && *sc_end != ';' && *sc_end != ',') {
|
|
|
|
cnt++;
|
|
|
|
sc_end++;
|
|
|
|
}
|
|
|
|
if( cnt == len ) {
|
|
|
|
/* exit: We are at the end. */
|
|
|
|
sc = NULL;
|
|
|
|
} else if( *sc_end == ';' ) {
|
|
|
|
/* We are at the end of the session key. */
|
|
|
|
int keylen = sc_end-sc_val;
|
2013-02-06 15:32:48 +04:00
|
|
|
if( key ) {
|
|
|
|
int oldlen = strlen(key);
|
|
|
|
key = c_realloc(key, oldlen + 2 + keylen+1);
|
|
|
|
strcpy(key + oldlen, "; ");
|
|
|
|
strncpy(key + oldlen + 2, sc_val, keylen);
|
|
|
|
key[oldlen + 2 + keylen] = '\0';
|
|
|
|
} else {
|
|
|
|
key = c_malloc(keylen+1);
|
|
|
|
strncpy( key, sc_val, keylen );
|
|
|
|
key[keylen] = '\0';
|
|
|
|
}
|
2013-01-24 13:06:42 +04:00
|
|
|
|
|
|
|
/* now search for a ',' to find a potential other header entry */
|
|
|
|
while(cnt < len && *sc_end != ',') {
|
2012-09-19 19:46:40 +04:00
|
|
|
cnt++;
|
|
|
|
sc_end++;
|
|
|
|
}
|
|
|
|
if( cnt < len )
|
2013-01-24 13:06:42 +04:00
|
|
|
sc = sc_end+2; /* mind the space after the comma */
|
2012-09-19 19:46:40 +04:00
|
|
|
else
|
|
|
|
sc = NULL;
|
2013-01-24 13:06:42 +04:00
|
|
|
} else if( *sc_end == ',' ) {
|
|
|
|
/* A new entry is to check. */
|
|
|
|
if( *(sc_end + 1) == ' ') {
|
|
|
|
sc = sc_end+2;
|
|
|
|
} else {
|
|
|
|
/* error condition */
|
|
|
|
sc = NULL;
|
|
|
|
}
|
2012-09-19 19:46:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DEBUG_WEBDAV("Request failed, don't take session header.");
|
|
|
|
}
|
|
|
|
if( key ) {
|
|
|
|
DEBUG_WEBDAV("----> Session-key: %s", key);
|
|
|
|
SAFE_FREE(dav_session.session_key);
|
|
|
|
dav_session.session_key = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this hook is called just after a request has been created, before its sent.
|
|
|
|
* Here it is used to set the session cookie if available.
|
|
|
|
*/
|
|
|
|
static void request_created_hook(ne_request *req, void *userdata,
|
|
|
|
const char *method, const char *requri)
|
|
|
|
{
|
|
|
|
(void) userdata;
|
|
|
|
(void) method;
|
2012-09-20 12:28:54 +04:00
|
|
|
(void) requri;
|
2012-09-19 19:46:40 +04:00
|
|
|
|
|
|
|
if( !req ) return;
|
|
|
|
|
|
|
|
if(dav_session.session_key) {
|
2012-12-06 16:15:01 +04:00
|
|
|
/* DEBUG_WEBDAV("Setting PHPSESSID to %s", dav_session.session_key); */
|
2012-09-19 19:46:40 +04:00
|
|
|
ne_add_request_header(req, "Cookie", dav_session.session_key);
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:09:35 +04:00
|
|
|
if(dav_session.proxy_type) {
|
|
|
|
/* required for NTLM */
|
|
|
|
ne_add_request_header(req, "Proxy-Connection", "Keep-Alive");
|
|
|
|
}
|
2012-09-19 19:46:40 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 21:13:28 +04:00
|
|
|
/* called from neon */
|
2012-12-04 20:21:53 +04:00
|
|
|
static void ne_notify_status_cb (void *userdata, ne_session_status status,
|
|
|
|
const ne_session_status_info *info)
|
|
|
|
{
|
|
|
|
struct transfer_context *tc = (struct transfer_context*) userdata;
|
2013-07-24 17:07:38 +04:00
|
|
|
struct timeval now;
|
2013-07-25 17:36:46 +04:00
|
|
|
int bandwidth_limit = 0;
|
2012-12-04 20:21:53 +04:00
|
|
|
|
2013-07-25 17:36:46 +04:00
|
|
|
if ((status == ne_status_sending || status == ne_status_recving)) {
|
|
|
|
if (info->sr.total > 0) {
|
|
|
|
oc_notify_progress( tc->url, CSYNC_NOTIFY_PROGRESS,
|
2013-01-30 15:29:56 +04:00
|
|
|
chunked_done + info->sr.progress,
|
2013-07-25 17:36:46 +04:00
|
|
|
chunked_total_size ? chunked_total_size : info->sr.total );
|
|
|
|
}
|
2013-07-29 17:27:22 +04:00
|
|
|
if (chunked_total_size && info->sr.total > 0 && info->sr.total == info->sr.progress) {
|
2013-01-30 15:29:56 +04:00
|
|
|
chunked_done += info->sr.total;
|
2013-07-29 16:27:01 +04:00
|
|
|
DEBUG_WEBDAV("Chunk upload completed for '%s' (%lld bytes out of %lld)", tc->url , chunked_done, chunked_total_size);
|
2013-07-25 17:36:46 +04:00
|
|
|
}
|
2012-12-06 19:49:08 +04:00
|
|
|
}
|
2013-07-24 17:07:38 +04:00
|
|
|
|
|
|
|
/* throttle connection */
|
|
|
|
if (status == ne_status_sending) bandwidth_limit = dav_session.bandwidth_limit_upload;
|
|
|
|
if (status == ne_status_recving) bandwidth_limit = dav_session.bandwidth_limit_download;
|
|
|
|
if (bandwidth_limit > 0 && gettimeofday(&now, NULL) == 0) {
|
|
|
|
int64_t diff = _timediff(tc->last_time, now);
|
|
|
|
int64_t len = info->sr.progress - tc->last_progress;
|
|
|
|
if (len > 0 && diff > 0 && (1000000 * len / diff) > (int64_t)bandwidth_limit) {
|
2013-07-31 16:50:44 +04:00
|
|
|
int64_t wait_time = (1000000 * len / bandwidth_limit) - diff;
|
|
|
|
if (wait_time > 0) {
|
|
|
|
usleep(wait_time);
|
2013-07-24 17:07:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tc->last_progress = info->sr.progress;
|
|
|
|
gettimeofday(&tc->last_time, NULL);
|
2013-07-24 19:19:31 +04:00
|
|
|
} else if (bandwidth_limit < 0 && bandwidth_limit > -100 && gettimeofday(&now, NULL) == 0) {
|
|
|
|
int64_t diff = _timediff(tc->last_time, now);
|
|
|
|
if (diff > 0) {
|
|
|
|
// -bandwidth_limit is the % of bandwidth
|
2013-07-31 16:50:44 +04:00
|
|
|
int64_t wait_time = -diff * (1 + 100.0 / bandwidth_limit);
|
|
|
|
if (wait_time > 0) {
|
|
|
|
usleep(wait_time);
|
2013-07-24 19:19:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gettimeofday(&tc->last_time, NULL);
|
2013-07-24 17:07:38 +04:00
|
|
|
}
|
2012-12-04 20:21:53 +04:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:35:54 +04:00
|
|
|
// as per http://sourceforge.net/p/predef/wiki/OperatingSystems/
|
|
|
|
// extend as required
|
|
|
|
static const char* get_platform() {
|
|
|
|
#if defined (_WIN32)
|
|
|
|
return "Windows";
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
return "Macintosh";
|
|
|
|
#elif defined(__gnu_linux__)
|
|
|
|
return "Linux";
|
|
|
|
#elif defined(__DragonFly__)
|
|
|
|
/* might also define __FreeBSD__ */
|
|
|
|
return "DragonFlyBSD";
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
return "FreeBSD";
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
return "NetBSD";
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
return "OpenBSD";
|
|
|
|
#elif defined(sun) || defined(__sun)
|
|
|
|
return "Solaris";
|
|
|
|
#else
|
|
|
|
return "Unknown OS";
|
|
|
|
#endif
|
|
|
|
}
|
2012-12-04 20:21:53 +04:00
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/*
|
|
|
|
* Connect to a DAV server
|
|
|
|
* This function sets the flag _connected if the connection is established
|
|
|
|
* and returns if the flag is set, so calling it frequently is save.
|
|
|
|
*/
|
|
|
|
static int dav_connect(const char *base_url) {
|
2012-02-22 19:04:33 +04:00
|
|
|
int useSSL = 0;
|
2011-09-01 22:00:20 +04:00
|
|
|
int rc;
|
2012-08-08 17:45:00 +04:00
|
|
|
char protocol[6] = {'\0'};
|
2012-02-20 14:14:53 +04:00
|
|
|
char uaBuf[256];
|
2012-02-22 20:23:08 +04:00
|
|
|
char *path = NULL;
|
|
|
|
char *scheme = NULL;
|
|
|
|
char *host = NULL;
|
|
|
|
unsigned int port = 0;
|
2012-07-31 18:59:15 +04:00
|
|
|
int proxystate = -1;
|
2011-09-01 22:00:20 +04:00
|
|
|
|
|
|
|
if (_connected) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-22 20:23:08 +04:00
|
|
|
rc = c_parse_uri( base_url, &scheme, &dav_session.user, &dav_session.pwd, &host, &port, &path );
|
|
|
|
if( rc < 0 ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Failed to parse uri %s", base_url );
|
2011-09-01 22:00:20 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("* scheme %s", scheme );
|
|
|
|
DEBUG_WEBDAV("* host %s", host );
|
|
|
|
DEBUG_WEBDAV("* port %u", port );
|
|
|
|
DEBUG_WEBDAV("* path %s", path );
|
2012-02-11 01:02:21 +04:00
|
|
|
|
2012-02-22 20:23:08 +04:00
|
|
|
if( strcmp( scheme, "owncloud" ) == 0 ) {
|
2012-08-08 17:45:00 +04:00
|
|
|
strcpy( protocol, "http");
|
2012-02-22 20:23:08 +04:00
|
|
|
} else if( strcmp( scheme, "ownclouds" ) == 0 ) {
|
2012-08-08 17:45:00 +04:00
|
|
|
strcpy( protocol, "https");
|
2012-02-22 19:04:33 +04:00
|
|
|
useSSL = 1;
|
2012-02-20 00:50:12 +04:00
|
|
|
} else {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Invalid scheme %s, go outa here!", scheme );
|
2012-02-20 14:14:53 +04:00
|
|
|
rc = -1;
|
2012-02-20 00:50:12 +04:00
|
|
|
goto out;
|
2012-02-14 18:23:07 +04:00
|
|
|
}
|
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("* user %s", dav_session.user ? dav_session.user : "");
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-22 20:23:08 +04:00
|
|
|
if (port == 0) {
|
|
|
|
port = ne_uri_defaultport(protocol);
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = ne_sock_init();
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("ne_sock_init: %d", rc );
|
2011-09-01 22:00:20 +04:00
|
|
|
if (rc < 0) {
|
2012-02-11 01:02:21 +04:00
|
|
|
rc = -1;
|
|
|
|
goto out;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-22 20:23:08 +04:00
|
|
|
dav_session.ctx = ne_session_create( protocol, host, port);
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2011-09-13 16:15:44 +04:00
|
|
|
if (dav_session.ctx == NULL) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Session create with protocol %s failed", protocol );
|
2012-02-11 01:02:21 +04:00
|
|
|
rc = -1;
|
|
|
|
goto out;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:29:00 +04:00
|
|
|
if (dav_session.read_timeout == 0)
|
2013-04-09 17:18:26 +04:00
|
|
|
dav_session.read_timeout = 300; // set 300 seconds as default.
|
2012-12-05 20:29:00 +04:00
|
|
|
|
|
|
|
ne_set_read_timeout(dav_session.ctx, dav_session.read_timeout);
|
|
|
|
|
2013-05-28 21:35:54 +04:00
|
|
|
snprintf( uaBuf, sizeof(uaBuf), "Mozilla/5.0 (%s) csyncoC/%s",
|
|
|
|
get_platform(), CSYNC_STRINGIFY( LIBCSYNC_VERSION ));
|
2012-06-20 17:01:54 +04:00
|
|
|
ne_set_useragent( dav_session.ctx, uaBuf);
|
2012-02-02 18:50:44 +04:00
|
|
|
ne_set_server_auth(dav_session.ctx, ne_auth, 0 );
|
2012-02-22 18:18:22 +04:00
|
|
|
|
2012-02-22 19:04:33 +04:00
|
|
|
if( useSSL ) {
|
|
|
|
if (!ne_has_support(NE_FEATURE_SSL)) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Error: SSL is not enabled.");
|
2012-02-22 19:04:33 +04:00
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ne_ssl_trust_default_ca( dav_session.ctx );
|
|
|
|
ne_ssl_set_verify( dav_session.ctx, verify_sslcert, 0 );
|
|
|
|
}
|
2012-05-14 19:19:50 +04:00
|
|
|
ne_redirect_register( dav_session.ctx );
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-09-19 19:46:40 +04:00
|
|
|
/* Hook to get the Session ID */
|
|
|
|
ne_hook_post_headers( dav_session.ctx, post_request_hook, NULL );
|
|
|
|
/* Hook called when a request is built. It sets the PHPSESSID header */
|
|
|
|
ne_hook_create_request( dav_session.ctx, request_created_hook, NULL );
|
|
|
|
|
2012-07-31 18:59:15 +04:00
|
|
|
/* Proxy support */
|
|
|
|
proxystate = configureProxy( dav_session.ctx );
|
|
|
|
if( proxystate < 0 ) {
|
|
|
|
DEBUG_WEBDAV("Error: Proxy-Configuration failed.");
|
|
|
|
} else if( proxystate > 0 ) {
|
|
|
|
ne_set_proxy_auth( dav_session.ctx, ne_proxy_auth, 0 );
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:55:44 +04:00
|
|
|
/* Disable, it is broken right now */
|
|
|
|
dav_session.no_recursive_propfind = true;
|
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
_connected = 1;
|
|
|
|
rc = 0;
|
|
|
|
out:
|
2012-06-20 17:01:54 +04:00
|
|
|
SAFE_FREE(path);
|
|
|
|
SAFE_FREE(host);
|
|
|
|
SAFE_FREE(scheme);
|
2011-09-01 22:00:20 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/*
|
|
|
|
* result parsing list.
|
|
|
|
* This function is called to parse the result of the propfind request
|
|
|
|
* to list directories on the WebDAV server. I takes a single resource
|
|
|
|
* and fills a resource struct and stores it to the result list which
|
2012-02-08 17:53:24 +04:00
|
|
|
* is stored in the listdir_context.
|
2012-02-02 18:50:44 +04:00
|
|
|
*/
|
|
|
|
static void results(void *userdata,
|
|
|
|
const ne_uri *uri,
|
|
|
|
const ne_prop_result_set *set)
|
|
|
|
{
|
2012-02-08 17:53:24 +04:00
|
|
|
struct listdir_context *fetchCtx = userdata;
|
2012-02-02 18:50:44 +04:00
|
|
|
struct resource *newres = 0;
|
2012-02-08 17:53:24 +04:00
|
|
|
const char *clength, *modtime = NULL;
|
|
|
|
const char *resourcetype = NULL;
|
2012-07-24 11:36:06 +04:00
|
|
|
const char *md5sum = NULL;
|
2012-02-02 18:50:44 +04:00
|
|
|
const ne_status *status = NULL;
|
2012-02-13 16:57:44 +04:00
|
|
|
char *path = ne_path_unescape( uri->path );
|
2012-02-02 18:50:44 +04:00
|
|
|
|
|
|
|
(void) status;
|
2012-02-22 17:27:09 +04:00
|
|
|
if( ! fetchCtx ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("No valid fetchContext");
|
2012-02-22 17:27:09 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-02-22 13:42:56 +04:00
|
|
|
if( ! fetchCtx->target ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("error: target must not be zero!" );
|
2012-02-22 13:42:56 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-02-05 00:36:41 +04:00
|
|
|
/* Fill the resource structure with the data about the file */
|
2012-02-13 16:57:44 +04:00
|
|
|
newres = c_malloc(sizeof(struct resource));
|
|
|
|
newres->uri = path; /* no need to strdup because ne_path_unescape already allocates */
|
2012-02-05 00:36:41 +04:00
|
|
|
newres->name = c_basename( path );
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-02-08 17:53:24 +04:00
|
|
|
modtime = ne_propset_value( set, &ls_props[0] );
|
|
|
|
clength = ne_propset_value( set, &ls_props[1] );
|
|
|
|
resourcetype = ne_propset_value( set, &ls_props[2] );
|
2012-07-24 11:36:06 +04:00
|
|
|
md5sum = ne_propset_value( set, &ls_props[3] );
|
2012-02-02 18:50:44 +04:00
|
|
|
|
|
|
|
newres->type = resr_normal;
|
|
|
|
if( clength == NULL && resourcetype && strncmp( resourcetype, "<DAV:collection>", 16 ) == 0) {
|
|
|
|
newres->type = resr_collection;
|
|
|
|
}
|
|
|
|
|
2012-11-08 17:52:14 +04:00
|
|
|
if (modtime) {
|
|
|
|
newres->modtime = oc_httpdate_parse(modtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DEBUG_WEBDAV("Parsing Modtime: %s -> %llu", modtime, (unsigned long long) newres->modtime ); */
|
2012-02-02 18:50:44 +04:00
|
|
|
|
|
|
|
if (clength) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
newres->size = DAV_STRTOL(clength, &p, 10);
|
|
|
|
if (*p) {
|
|
|
|
newres->size = 0;
|
|
|
|
}
|
2012-11-22 18:25:27 +04:00
|
|
|
/* DEBUG_WEBDAV("Parsed File size for %s from %s: %lld", newres->name, clength, (long long)newres->size ); */
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:36:06 +04:00
|
|
|
if( md5sum ) {
|
2012-08-17 17:50:31 +04:00
|
|
|
int len = strlen(md5sum)-2;
|
|
|
|
if( len > 0 ) {
|
|
|
|
/* Skip the " around the string coming back from the ne_propset_value call */
|
|
|
|
newres->md5 = c_malloc(len+1);
|
|
|
|
strncpy( newres->md5, md5sum+1, len );
|
|
|
|
newres->md5[len] = '\0';
|
|
|
|
}
|
2012-07-24 11:36:06 +04:00
|
|
|
}
|
|
|
|
|
2012-02-22 20:36:21 +04:00
|
|
|
/* prepend the new resource to the result list */
|
2012-02-22 17:27:09 +04:00
|
|
|
newres->next = fetchCtx->list;
|
|
|
|
fetchCtx->list = newres;
|
2012-02-02 18:50:44 +04:00
|
|
|
fetchCtx->result_count = fetchCtx->result_count + 1;
|
2012-06-05 19:10:50 +04:00
|
|
|
/* DEBUG_WEBDAV( "results for URI %s: %d %d", newres->name, (int)newres->size, (int)newres->type ); */
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/*
|
2012-02-08 17:53:24 +04:00
|
|
|
* fetches a resource list from the WebDAV server. This is equivalent to list dir.
|
2012-02-02 18:50:44 +04:00
|
|
|
*/
|
2012-12-06 16:15:01 +04:00
|
|
|
static struct listdir_context *fetch_resource_list(const char *uri, int depth)
|
2012-02-02 18:50:44 +04:00
|
|
|
{
|
2012-12-05 16:50:26 +04:00
|
|
|
struct listdir_context *fetchCtx;
|
|
|
|
int ret = 0;
|
2012-07-03 16:38:43 +04:00
|
|
|
ne_propfind_handler *hdl = NULL;
|
|
|
|
ne_request *request = NULL;
|
2012-11-18 00:15:59 +04:00
|
|
|
const char *content_type = NULL;
|
2012-12-06 16:15:01 +04:00
|
|
|
char *curi = NULL;
|
2012-12-06 16:18:54 +04:00
|
|
|
const ne_status *req_status = NULL;
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-12-06 16:15:01 +04:00
|
|
|
curi = _cleanPath( uri );
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
if (propfind_cache) {
|
|
|
|
if (c_streq(curi, propfind_cache->target)) {
|
|
|
|
propfind_cache->ref++;
|
|
|
|
SAFE_FREE(curi);
|
|
|
|
return propfind_cache;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 15:26:59 +04:00
|
|
|
if (propfind_recursive_cache && !dav_session.no_recursive_propfind) {
|
2013-05-08 13:57:29 +04:00
|
|
|
fetchCtx = get_listdir_context_from_cache(curi);
|
|
|
|
if (fetchCtx) {
|
|
|
|
return fetchCtx;
|
|
|
|
} else {
|
|
|
|
/* Not found in the recursive cache, fetch some */
|
|
|
|
return fetch_resource_list_recursive(uri, curi);
|
|
|
|
}
|
2013-05-08 15:26:59 +04:00
|
|
|
} else if (!is_first_propfind && !dav_session.no_recursive_propfind) {
|
2013-05-08 13:57:29 +04:00
|
|
|
/* 2nd propfind */
|
|
|
|
return fetch_resource_list_recursive(uri, curi);
|
|
|
|
}
|
|
|
|
is_first_propfind = false;
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
fetchCtx = c_malloc( sizeof( struct listdir_context ));
|
|
|
|
if (!fetchCtx) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
SAFE_FREE(curi);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fetchCtx->list = NULL;
|
|
|
|
fetchCtx->target = curi;
|
|
|
|
fetchCtx->currResource = NULL;
|
|
|
|
fetchCtx->ref = 1;
|
|
|
|
|
2012-02-02 18:50:44 +04:00
|
|
|
/* do a propfind request and parse the results in the results function, set as callback */
|
2012-07-03 16:38:43 +04:00
|
|
|
hdl = ne_propfind_create(dav_session.ctx, curi, depth);
|
|
|
|
|
2012-12-06 16:15:01 +04:00
|
|
|
if(hdl) {
|
2012-08-09 15:11:54 +04:00
|
|
|
ret = ne_propfind_named(hdl, ls_props, results, fetchCtx);
|
2012-07-03 16:38:43 +04:00
|
|
|
request = ne_propfind_get_request( hdl );
|
2012-11-18 00:15:59 +04:00
|
|
|
req_status = ne_get_status( request );
|
2012-12-06 16:15:01 +04:00
|
|
|
}
|
2012-11-18 00:15:59 +04:00
|
|
|
|
2012-12-06 16:15:01 +04:00
|
|
|
if( ret == NE_OK ) {
|
|
|
|
fetchCtx->currResource = fetchCtx->list;
|
2012-11-18 00:15:59 +04:00
|
|
|
/* Check the request status. */
|
2013-04-08 11:07:19 +04:00
|
|
|
if( req_status && req_status->klass != 2 ) {
|
2012-12-04 20:03:00 +04:00
|
|
|
set_errno_from_http_errcode(req_status->code);
|
2012-11-18 00:15:59 +04:00
|
|
|
DEBUG_WEBDAV("ERROR: Request failed: status %d (%s)", req_status->code,
|
|
|
|
req_status->reason_phrase);
|
|
|
|
ret = NE_CONNECT;
|
2012-12-14 19:48:47 +04:00
|
|
|
set_error_message(req_status->reason_phrase);
|
2013-07-25 17:36:46 +04:00
|
|
|
oc_notify_progress( uri, CSYNC_NOTIFY_ERROR,
|
|
|
|
req_status->code,
|
2013-07-31 15:12:10 +04:00
|
|
|
(intptr_t)(req_status->reason_phrase) );
|
2012-11-18 00:15:59 +04:00
|
|
|
}
|
2012-11-19 15:11:26 +04:00
|
|
|
DEBUG_WEBDAV("Simple propfind result code %d.", req_status->code);
|
2012-12-04 20:03:00 +04:00
|
|
|
} else {
|
2012-12-06 16:15:01 +04:00
|
|
|
if( ret == NE_ERROR && req_status->code == 404) {
|
|
|
|
errno = ENOENT;
|
|
|
|
} else {
|
|
|
|
set_errno_from_neon_errcode(ret);
|
|
|
|
}
|
2012-11-18 00:15:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ret == NE_OK ) {
|
|
|
|
/* Check the content type. If the server has a problem, ie. database is gone or such,
|
|
|
|
* the content type is not xml but a html error message. Stop on processing if it's
|
|
|
|
* not XML.
|
|
|
|
* FIXME: Generate user error message from the reply content.
|
|
|
|
*/
|
|
|
|
content_type = ne_get_response_header( request, "Content-Type" );
|
|
|
|
if( !(content_type && c_streq(content_type, "application/xml; charset=utf-8") ) ) {
|
|
|
|
DEBUG_WEBDAV("ERROR: Content type of propfind request not XML: %s.",
|
|
|
|
content_type ? content_type: "<empty>");
|
2012-12-04 20:03:00 +04:00
|
|
|
errno = ERRNO_WRONG_CONTENT;
|
2012-12-14 19:48:47 +04:00
|
|
|
set_error_message("Server error: PROPFIND reply is not XML formatted!");
|
2012-11-18 00:15:59 +04:00
|
|
|
ret = NE_CONNECT;
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 16:38:43 +04:00
|
|
|
|
2012-11-18 00:15:59 +04:00
|
|
|
if( ret != NE_OK ) {
|
2012-12-03 22:40:06 +04:00
|
|
|
const char *err = NULL;
|
|
|
|
|
2012-08-09 15:11:54 +04:00
|
|
|
err = ne_get_error( dav_session.ctx );
|
|
|
|
DEBUG_WEBDAV("WRN: propfind named failed with %d, request error: %s", ret, err ? err : "<nil>");
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
2012-07-11 18:02:43 +04:00
|
|
|
|
2012-08-09 15:11:54 +04:00
|
|
|
if( hdl )
|
|
|
|
ne_propfind_destroy(hdl);
|
2012-07-03 16:38:43 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
if( ret == NE_REDIRECT ) {
|
|
|
|
const ne_uri *redir_ne_uri = NULL;
|
|
|
|
char *redir_uri = NULL;
|
|
|
|
redir_ne_uri = ne_redirect_location(dav_session.ctx);
|
|
|
|
if( redir_ne_uri ) {
|
|
|
|
redir_uri = ne_uri_unparse(redir_ne_uri);
|
|
|
|
DEBUG_WEBDAV("Permanently moved to %s", redir_uri);
|
2013-07-02 15:21:10 +04:00
|
|
|
SAFE_FREE(redir_uri);
|
2012-12-05 16:50:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ret != NE_OK ) {
|
|
|
|
free_fetchCtx(fetchCtx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_fetchCtx(propfind_cache);
|
|
|
|
propfind_cache = fetchCtx;
|
|
|
|
propfind_cache->ref++;
|
|
|
|
return fetchCtx;
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
|
|
|
|
2013-02-09 20:09:22 +04:00
|
|
|
static struct listdir_context *fetch_resource_list_attempts(const char *uri, int depth)
|
|
|
|
{
|
2013-02-10 19:43:38 +04:00
|
|
|
int i;
|
|
|
|
|
2013-02-09 20:09:22 +04:00
|
|
|
struct listdir_context *fetchCtx = NULL;
|
2013-02-10 19:43:38 +04:00
|
|
|
for(i = 0; i < 10; ++i) {
|
2013-02-09 20:09:22 +04:00
|
|
|
fetchCtx = fetch_resource_list(uri, depth);
|
|
|
|
if(fetchCtx) break;
|
2013-02-20 20:38:09 +04:00
|
|
|
/* only loop in case the content is not XML formatted. Otherwise for every
|
|
|
|
* non successful stat (for non existing directories) its tried 10 times. */
|
|
|
|
if( errno != ERRNO_WRONG_CONTENT ) break;
|
|
|
|
|
2013-02-09 20:09:22 +04:00
|
|
|
DEBUG_WEBDAV("=> Errno after fetch resource list for %s: %d", uri, errno);
|
|
|
|
DEBUG_WEBDAV(" New attempt %i", i);
|
|
|
|
}
|
|
|
|
return fetchCtx;
|
|
|
|
}
|
|
|
|
|
2012-08-28 16:59:33 +04:00
|
|
|
static void fill_stat_cache( csync_vio_file_stat_t *lfs ) {
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
if( _stat_cache.name ) SAFE_FREE(_stat_cache.name);
|
|
|
|
if( _stat_cache.md5 ) SAFE_FREE(_stat_cache.md5 );
|
2012-08-28 16:59:33 +04:00
|
|
|
|
|
|
|
if( !lfs) return;
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
_stat_cache.name = c_strdup(lfs->name);
|
|
|
|
_stat_cache.mtime = lfs->mtime;
|
|
|
|
_stat_cache.fields = lfs->fields;
|
|
|
|
_stat_cache.type = lfs->type;
|
|
|
|
_stat_cache.size = lfs->size;
|
2012-08-28 16:59:33 +04:00
|
|
|
if( lfs->md5 ) {
|
2012-12-05 16:50:26 +04:00
|
|
|
_stat_cache.md5 = c_strdup(lfs->md5);
|
2012-08-28 16:59:33 +04:00
|
|
|
}
|
|
|
|
}
|
2012-06-20 17:01:54 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
|
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
/*
|
|
|
|
* file functions
|
|
|
|
*/
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_stat(const char *uri, csync_vio_file_stat_t *buf) {
|
2012-02-13 18:07:01 +04:00
|
|
|
/* get props:
|
|
|
|
* modtime
|
|
|
|
* creattime
|
|
|
|
* size
|
|
|
|
*/
|
|
|
|
csync_vio_file_stat_t *lfs = NULL;
|
|
|
|
struct listdir_context *fetchCtx = NULL;
|
2012-03-12 21:11:47 +04:00
|
|
|
char *decodedUri = NULL;
|
2012-02-27 18:50:51 +04:00
|
|
|
int len = 0;
|
2013-01-16 19:25:51 +04:00
|
|
|
errno = 0;
|
2012-02-13 18:07:01 +04:00
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("owncloud_stat %s called", uri );
|
2012-02-13 18:07:01 +04:00
|
|
|
|
|
|
|
buf->name = c_basename(uri);
|
|
|
|
|
|
|
|
if (buf->name == NULL) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
if( _stat_cache.name && strcmp( buf->name, _stat_cache.name ) == 0 ) {
|
2012-02-13 18:07:01 +04:00
|
|
|
buf->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
buf->fields = _stat_cache.fields;
|
|
|
|
buf->type = _stat_cache.type;
|
|
|
|
buf->mtime = _stat_cache.mtime;
|
|
|
|
buf->size = _stat_cache.size;
|
|
|
|
buf->mode = _stat_perms( _stat_cache.type );
|
2012-08-26 22:06:53 +04:00
|
|
|
buf->md5 = NULL;
|
2012-12-05 16:50:26 +04:00
|
|
|
if( _stat_cache.md5 ) {
|
|
|
|
buf->md5 = c_strdup( _stat_cache.md5 );
|
2012-08-28 18:53:26 +04:00
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
2012-08-26 22:06:53 +04:00
|
|
|
}
|
2012-12-05 16:50:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-02-13 18:07:01 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
/* fetch data via a propfind call. */
|
2013-02-09 20:09:22 +04:00
|
|
|
/* fetchCtx = fetch_resource_list( uri, NE_DEPTH_ONE); */
|
|
|
|
fetchCtx = fetch_resource_list_attempts( uri, NE_DEPTH_ONE);
|
2012-12-06 16:15:01 +04:00
|
|
|
DEBUG_WEBDAV("=> Errno after fetch resource list for %s: %d", uri, errno);
|
2012-12-05 16:50:26 +04:00
|
|
|
if (!fetchCtx) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-12-04 20:03:00 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
if( fetchCtx ) {
|
|
|
|
struct resource *res = fetchCtx->list;
|
|
|
|
while( res ) {
|
|
|
|
/* remove trailing slashes */
|
|
|
|
len = strlen(res->uri);
|
|
|
|
while( len > 0 && res->uri[len-1] == '/' ) --len;
|
|
|
|
decodedUri = ne_path_unescape( fetchCtx->target ); /* allocates memory */
|
2012-02-13 18:07:01 +04:00
|
|
|
|
2012-12-14 03:04:56 +04:00
|
|
|
/* Only do the comparaison of the part of the string without the trailing
|
|
|
|
slashes, and make sure decodedUri is not too large */
|
|
|
|
if( strncmp(res->uri, decodedUri, len ) == 0 && decodedUri[len] == '\0') {
|
2012-03-12 21:11:47 +04:00
|
|
|
SAFE_FREE( decodedUri );
|
2012-12-05 16:50:26 +04:00
|
|
|
break;
|
2012-02-27 18:50:51 +04:00
|
|
|
}
|
2012-12-05 16:50:26 +04:00
|
|
|
res = res->next;
|
|
|
|
SAFE_FREE( decodedUri );
|
|
|
|
}
|
|
|
|
if( res ) {
|
|
|
|
DEBUG_WEBDAV("Working on file %s", res->name );
|
|
|
|
} else {
|
|
|
|
DEBUG_WEBDAV("ERROR: Result struct not valid!");
|
|
|
|
}
|
2012-08-20 20:09:24 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
lfs = resourceToFileStat( res );
|
|
|
|
if( lfs ) {
|
|
|
|
buf->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
|
|
|
|
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
2012-08-28 16:59:33 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
buf->fields = lfs->fields;
|
|
|
|
buf->type = lfs->type;
|
|
|
|
buf->mtime = lfs->mtime;
|
|
|
|
buf->size = lfs->size;
|
|
|
|
buf->mode = _stat_perms( lfs->type );
|
|
|
|
buf->md5 = NULL;
|
|
|
|
if( lfs->md5 ) {
|
|
|
|
buf->md5 = c_strdup( lfs->md5 );
|
2012-02-13 18:07:01 +04:00
|
|
|
}
|
2012-06-20 17:01:54 +04:00
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
/* fill the static stat buf as input for the stat function */
|
|
|
|
csync_vio_file_stat_destroy( lfs );
|
2012-02-13 18:07:01 +04:00
|
|
|
}
|
2012-12-05 16:50:26 +04:00
|
|
|
|
|
|
|
free_fetchCtx( fetchCtx );
|
2012-02-13 18:07:01 +04:00
|
|
|
}
|
2012-12-05 16:50:26 +04:00
|
|
|
DEBUG_WEBDAV("STAT result from propfind: %s, mtime: %llu", buf->name ? buf->name:"NULL",
|
|
|
|
(unsigned long long) buf->mtime );
|
2012-09-20 12:28:54 +04:00
|
|
|
|
2012-02-13 18:07:01 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static ssize_t owncloud_write(csync_vio_method_handle_t *fhandle, const void *buf, size_t count) {
|
2012-12-04 20:02:39 +04:00
|
|
|
(void) fhandle;
|
|
|
|
(void) buf;
|
|
|
|
(void) count;
|
2012-03-30 15:58:59 +04:00
|
|
|
|
2012-12-04 20:02:39 +04:00
|
|
|
return 0;
|
2012-02-22 13:42:56 +04:00
|
|
|
}
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-12-07 15:40:05 +04:00
|
|
|
static int content_reader(void *userdata, const char *buf, size_t len)
|
2012-03-27 18:46:27 +04:00
|
|
|
{
|
|
|
|
struct transfer_context *writeCtx = userdata;
|
2012-04-02 13:30:46 +04:00
|
|
|
size_t written = 0;
|
2012-03-27 18:46:27 +04:00
|
|
|
|
|
|
|
if( buf && writeCtx->fd ) {
|
2012-12-07 15:40:05 +04:00
|
|
|
/* DEBUG_WEBDAV("Writing %scompressed %d bytes", (writeCtx->decompress ? "" : "NON "), len); */
|
2012-04-15 16:35:38 +04:00
|
|
|
written = write(writeCtx->fd, buf, len);
|
2012-04-02 13:30:46 +04:00
|
|
|
if( len != written ) {
|
2013-07-26 15:43:02 +04:00
|
|
|
DEBUG_WEBDAV("WRN: content_reader wrote wrong num of bytes: %zu, %zu %d %d", len, written, errno, writeCtx->fd);
|
2012-04-02 13:30:46 +04:00
|
|
|
}
|
2013-07-26 15:43:02 +04:00
|
|
|
writeCtx->get_size += len;
|
2012-03-27 18:46:27 +04:00
|
|
|
return NE_OK;
|
2012-12-17 20:22:24 +04:00
|
|
|
} else {
|
|
|
|
errno = EBADF;
|
2012-03-27 18:46:27 +04:00
|
|
|
}
|
|
|
|
return NE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This hook is called after the response is here from the server, but before
|
|
|
|
* the response body is parsed. It decides if the response is compressed and
|
|
|
|
* if it is it installs the compression reader accordingly.
|
|
|
|
* If the response is not compressed, the normal response body reader is installed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void install_content_reader( ne_request *req, void *userdata, const ne_status *status )
|
|
|
|
{
|
|
|
|
const char *enc = NULL;
|
|
|
|
struct transfer_context *writeCtx = userdata;
|
|
|
|
|
2012-12-05 15:54:50 +04:00
|
|
|
(void) status;
|
|
|
|
|
2012-03-27 18:46:27 +04:00
|
|
|
if( !writeCtx ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Error: install_content_reader called without valid write context!");
|
2012-03-27 18:46:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
enc = ne_get_response_header( req, "Content-Encoding" );
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Content encoding ist <%s> with status %d", enc ? enc : "empty",
|
|
|
|
status ? status->code : -1 );
|
2012-03-27 18:46:27 +04:00
|
|
|
|
|
|
|
if( enc && c_streq( enc, "gzip" )) {
|
|
|
|
writeCtx->decompress = ne_decompress_reader( req, ne_accept_2xx,
|
2012-12-07 15:40:05 +04:00
|
|
|
content_reader, /* reader callback */
|
2012-03-27 18:46:27 +04:00
|
|
|
(void*) writeCtx ); /* userdata */
|
|
|
|
} else {
|
|
|
|
ne_add_response_body_reader( req, ne_accept_2xx,
|
2012-12-07 15:40:05 +04:00
|
|
|
content_reader,
|
2012-03-27 18:46:27 +04:00
|
|
|
(void*) writeCtx );
|
|
|
|
writeCtx->decompress = NULL;
|
|
|
|
}
|
2012-12-06 17:00:05 +04:00
|
|
|
|
|
|
|
enc = ne_get_response_header( req, "ETag" );
|
|
|
|
if (enc && *enc) {
|
|
|
|
SAFE_FREE(_id_cache.uri);
|
|
|
|
SAFE_FREE(_id_cache.id);
|
2013-01-29 17:02:51 +04:00
|
|
|
_id_cache.uri = c_strdup(writeCtx->url);
|
2012-12-06 17:00:05 +04:00
|
|
|
_id_cache.id = c_strdup(enc);
|
|
|
|
}
|
2012-03-27 18:46:27 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 22:02:59 +04:00
|
|
|
static char*_lastDir = NULL;
|
|
|
|
|
2012-07-04 15:56:24 +04:00
|
|
|
/* capabilities are currently:
|
2012-07-04 18:32:17 +04:00
|
|
|
* bool atomar_copy_support - oC provides atomar copy
|
|
|
|
* bool do_post_copy_stat - oC does not want the post copy check
|
|
|
|
* bool time_sync_required - oC does not require the time sync
|
|
|
|
* int unix_extensions - oC supports unix extensions.
|
2012-12-04 18:04:22 +04:00
|
|
|
* bool propagate_on_fd - oC supports the send_file method.
|
2012-07-04 15:56:24 +04:00
|
|
|
*/
|
2013-02-05 15:38:40 +04:00
|
|
|
static csync_vio_capabilities_t _owncloud_capabilities = { true, false, false, 0, true };
|
2012-07-04 15:56:24 +04:00
|
|
|
|
2012-08-23 18:35:16 +04:00
|
|
|
static csync_vio_capabilities_t *owncloud_capabilities(void)
|
2012-07-04 15:56:24 +04:00
|
|
|
{
|
2012-07-04 18:32:17 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
_owncloud_capabilities.unix_extensions = 0;
|
|
|
|
#endif
|
2012-07-04 15:56:24 +04:00
|
|
|
return &_owncloud_capabilities;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:50:31 +04:00
|
|
|
static const char* owncloud_file_id( const char *path )
|
|
|
|
{
|
|
|
|
ne_request *req = NULL;
|
|
|
|
const char *header = NULL;
|
|
|
|
char *uri = _cleanPath(path);
|
|
|
|
char *buf = NULL;
|
2012-08-28 18:53:26 +04:00
|
|
|
const char *cbuf = NULL;
|
2012-08-30 13:59:52 +04:00
|
|
|
csync_vio_file_stat_t *fs = NULL;
|
2012-12-07 12:02:42 +04:00
|
|
|
bool doHeadRequest = false;
|
2012-12-06 17:00:05 +04:00
|
|
|
|
|
|
|
if (_id_cache.uri && c_streq(path, _id_cache.uri)) {
|
2012-12-06 22:02:23 +04:00
|
|
|
header = _id_cache.id;
|
2012-12-06 17:00:05 +04:00
|
|
|
}
|
|
|
|
|
2012-12-07 12:02:42 +04:00
|
|
|
doHeadRequest= false; /* ownCloud server doesn't have good support for HEAD yet */
|
2012-08-17 17:50:31 +04:00
|
|
|
|
2012-12-06 22:02:23 +04:00
|
|
|
if( !header && doHeadRequest ) {
|
2012-12-05 15:55:05 +04:00
|
|
|
int neon_stat;
|
2012-09-26 14:44:17 +04:00
|
|
|
/* Perform an HEAD request to the resource. HEAD delivers the
|
|
|
|
* ETag header back. */
|
|
|
|
req = ne_request_create(dav_session.ctx, "HEAD", uri);
|
2012-12-05 15:55:05 +04:00
|
|
|
neon_stat = ne_request_dispatch(req);
|
2012-12-06 16:15:01 +04:00
|
|
|
set_errno_from_neon_errcode( neon_stat );
|
2012-08-17 17:50:31 +04:00
|
|
|
|
2012-09-26 14:44:17 +04:00
|
|
|
header = ne_get_response_header(req, "etag");
|
|
|
|
}
|
2012-08-20 20:09:24 +04:00
|
|
|
/* If the request went wrong or the server did not respond correctly
|
|
|
|
* (that can happen for collections) a stat call is done which translates
|
|
|
|
* into a PROPFIND request.
|
|
|
|
*/
|
2012-08-17 17:50:31 +04:00
|
|
|
if( ! header ) {
|
2012-09-24 16:45:11 +04:00
|
|
|
/* ... and do a stat call. */
|
2012-08-30 13:59:52 +04:00
|
|
|
fs = csync_vio_file_stat_new();
|
2012-08-28 18:53:26 +04:00
|
|
|
if(fs == NULL) {
|
|
|
|
DEBUG_WEBDAV( "owncloud_file_id: memory fault.");
|
|
|
|
errno = ENOMEM;
|
|
|
|
return NULL;
|
2012-08-30 13:59:52 +04:00
|
|
|
}
|
2012-08-28 18:53:26 +04:00
|
|
|
if( owncloud_stat( path, fs ) == 0 ) {
|
2012-08-30 13:59:52 +04:00
|
|
|
header = fs->md5;
|
2012-08-17 17:50:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 20:09:24 +04:00
|
|
|
/* In case the result is surrounded by "" cut them away. */
|
2012-08-17 17:50:31 +04:00
|
|
|
if( header ) {
|
|
|
|
if( header [0] == '"' && header[ strlen(header)-1] == '"') {
|
|
|
|
int len = strlen( header )-2;
|
2012-08-30 13:59:52 +04:00
|
|
|
buf = c_malloc( len+1 );
|
2012-08-17 17:50:31 +04:00
|
|
|
strncpy( buf, header+1, len );
|
|
|
|
buf[len] = '\0';
|
2012-08-28 18:53:26 +04:00
|
|
|
cbuf = buf;
|
2012-08-30 13:59:52 +04:00
|
|
|
/* do not free header here, as it belongs to the request */
|
2012-08-17 17:50:31 +04:00
|
|
|
} else {
|
2012-08-30 13:59:52 +04:00
|
|
|
cbuf = c_strdup(header);
|
2012-08-17 17:50:31 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 12:28:54 +04:00
|
|
|
DEBUG_WEBDAV("Get file ID for %s: %s", path, cbuf ? cbuf:"<null>");
|
2012-08-30 13:59:52 +04:00
|
|
|
if( fs ) csync_vio_file_stat_destroy(fs);
|
2012-09-26 14:44:17 +04:00
|
|
|
if( req ) ne_request_destroy(req);
|
2012-08-17 17:50:31 +04:00
|
|
|
SAFE_FREE(uri);
|
|
|
|
|
2012-08-28 18:53:26 +04:00
|
|
|
return cbuf;
|
2012-08-17 17:50:31 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static csync_vio_method_handle_t *owncloud_open(const char *durl,
|
2012-03-29 22:02:59 +04:00
|
|
|
int flags,
|
|
|
|
mode_t mode) {
|
2012-02-13 13:43:31 +04:00
|
|
|
char *uri = NULL;
|
2012-02-13 16:57:44 +04:00
|
|
|
char *dir = NULL;
|
2011-09-13 16:15:44 +04:00
|
|
|
int put = 0;
|
2012-02-13 13:43:31 +04:00
|
|
|
int rc = NE_OK;
|
2012-03-07 23:59:13 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
struct transfer_context *writeCtx = NULL;
|
2012-06-20 17:01:54 +04:00
|
|
|
csync_vio_file_stat_t statBuf;
|
2012-11-14 17:08:47 +04:00
|
|
|
ZERO_STRUCT(statBuf);
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-08 17:53:24 +04:00
|
|
|
(void) mode; /* unused on webdav server */
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV( "=> open called for %s", durl );
|
2012-02-13 16:57:44 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
uri = _cleanPath( durl );
|
|
|
|
if( ! uri ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Failed to clean path for %s", durl );
|
2012-02-28 17:58:30 +04:00
|
|
|
errno = EACCES;
|
2012-02-13 13:43:31 +04:00
|
|
|
rc = NE_ERROR;
|
2011-09-13 16:15:44 +04:00
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
|
|
|
|
if( rc == NE_OK )
|
|
|
|
dav_connect( durl );
|
2011-09-13 16:15:44 +04:00
|
|
|
|
|
|
|
if (flags & O_WRONLY) {
|
|
|
|
put = 1;
|
|
|
|
}
|
|
|
|
if (flags & O_RDWR) {
|
|
|
|
put = 1;
|
|
|
|
}
|
|
|
|
if (flags & O_CREAT) {
|
|
|
|
put = 1;
|
|
|
|
}
|
|
|
|
|
2012-02-13 18:07:01 +04:00
|
|
|
if( rc == NE_OK && put ) {
|
|
|
|
/* check if the dir name exists. Otherwise return ENOENT */
|
|
|
|
dir = c_dirname( durl );
|
2012-12-04 18:04:22 +04:00
|
|
|
if (dir == NULL) {
|
2012-03-03 14:22:03 +04:00
|
|
|
errno = ENOMEM;
|
2012-06-20 17:01:54 +04:00
|
|
|
SAFE_FREE(uri);
|
2012-12-04 18:04:22 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Stating directory %s", dir );
|
2012-03-29 22:02:59 +04:00
|
|
|
if( c_streq( dir, _lastDir )) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Dir %s is there, we know it already.", dir);
|
2012-02-13 18:07:01 +04:00
|
|
|
} else {
|
2012-06-20 17:19:05 +04:00
|
|
|
if( owncloud_stat( dir, &statBuf ) == 0 ) {
|
2012-06-20 17:01:54 +04:00
|
|
|
SAFE_FREE(statBuf.name);
|
2012-08-30 13:59:52 +04:00
|
|
|
SAFE_FREE(statBuf.md5);
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Directory of file to open exists.");
|
2012-03-29 22:02:59 +04:00
|
|
|
SAFE_FREE( _lastDir );
|
|
|
|
_lastDir = c_strdup(dir);
|
|
|
|
|
|
|
|
} else {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Directory %s of file to open does NOT exist.", dir );
|
2012-03-29 22:02:59 +04:00
|
|
|
/* the directory does not exist. That is an ENOENT */
|
|
|
|
errno = ENOENT;
|
2012-06-20 17:01:54 +04:00
|
|
|
SAFE_FREE(dir);
|
|
|
|
SAFE_FREE(uri);
|
|
|
|
SAFE_FREE(statBuf.name);
|
2012-03-29 22:02:59 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-13 18:07:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writeCtx = c_malloc( sizeof(struct transfer_context) );
|
2013-01-29 17:02:51 +04:00
|
|
|
writeCtx->url = c_strdup(durl);
|
|
|
|
writeCtx->req = NULL;
|
|
|
|
writeCtx->fd = -1;
|
2012-08-23 18:35:16 +04:00
|
|
|
|
2012-02-13 18:07:01 +04:00
|
|
|
if( rc == NE_OK && put) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("PUT request on %s!", uri);
|
2012-08-23 18:35:16 +04:00
|
|
|
writeCtx->method = "PUT";
|
2012-02-13 13:43:31 +04:00
|
|
|
}
|
2012-02-08 17:53:24 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc == NE_OK && ! put ) {
|
2012-03-27 18:46:27 +04:00
|
|
|
writeCtx->method = "GET";
|
2012-12-06 21:49:15 +04:00
|
|
|
DEBUG_WEBDAV("GET request on %s", uri );
|
2012-02-22 13:52:48 +04:00
|
|
|
}
|
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc != NE_OK ) {
|
|
|
|
SAFE_FREE( writeCtx );
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFE_FREE( uri );
|
2012-02-28 17:58:30 +04:00
|
|
|
SAFE_FREE( dir );
|
2012-02-13 13:43:31 +04:00
|
|
|
|
2012-02-08 15:32:29 +04:00
|
|
|
return (csync_vio_method_handle_t *) writeCtx;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static csync_vio_method_handle_t *owncloud_creat(const char *durl, mode_t mode) {
|
2012-02-22 13:47:31 +04:00
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
csync_vio_method_handle_t *handle = owncloud_open(durl, O_CREAT|O_WRONLY|O_TRUNC, mode);
|
2012-02-22 13:47:31 +04:00
|
|
|
|
|
|
|
/* on create, the file needs to be created empty */
|
2012-02-21 13:21:11 +04:00
|
|
|
owncloud_write( handle, NULL, 0 );
|
2012-02-22 13:47:31 +04:00
|
|
|
|
|
|
|
return handle;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2013-05-16 19:37:30 +04:00
|
|
|
static int _user_want_abort()
|
|
|
|
{
|
|
|
|
return csync_abort_requested(dav_session.csync_ctx);
|
|
|
|
}
|
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_handle_t *hdl ) {
|
2012-12-04 21:13:28 +04:00
|
|
|
int rc = 0;
|
|
|
|
int neon_stat;
|
2012-12-04 18:04:22 +04:00
|
|
|
const ne_status *status;
|
|
|
|
struct transfer_context *write_ctx = (struct transfer_context*) hdl;
|
|
|
|
fhandle_t *fh = (fhandle_t *) src;
|
2012-12-04 20:03:00 +04:00
|
|
|
int fd;
|
2012-12-10 19:50:51 +04:00
|
|
|
int error_code = 0;
|
2013-01-29 17:02:51 +04:00
|
|
|
char *clean_uri = NULL;
|
2013-07-30 18:19:12 +04:00
|
|
|
int64_t file_size;
|
2011-09-13 16:15:44 +04:00
|
|
|
|
2012-12-04 20:03:00 +04:00
|
|
|
if( ! write_ctx ) {
|
|
|
|
errno = EINVAL;
|
2012-12-04 21:13:28 +04:00
|
|
|
return -1;
|
2012-12-04 20:03:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !fh ) {
|
|
|
|
errno = EINVAL;
|
2012-12-04 21:13:28 +04:00
|
|
|
return -1;
|
2012-12-04 20:03:00 +04:00
|
|
|
}
|
|
|
|
fd = fh->fd;
|
|
|
|
|
2013-01-29 17:02:51 +04:00
|
|
|
clean_uri = _cleanPath( write_ctx->url );
|
|
|
|
|
2013-01-30 15:29:56 +04:00
|
|
|
chunked_total_size = 0;
|
|
|
|
chunked_done = 0;
|
|
|
|
|
2013-07-24 19:19:31 +04:00
|
|
|
gettimeofday(&write_ctx->last_time, NULL);
|
|
|
|
|
2013-07-16 11:19:36 +04:00
|
|
|
DEBUG_WEBDAV("Sendfile handling request type %s. fd %d", write_ctx->method, fd);
|
2012-10-18 15:25:22 +04:00
|
|
|
|
2013-04-16 18:27:40 +04:00
|
|
|
/*
|
|
|
|
* Copy from the file descriptor if method == PUT
|
2012-12-04 18:04:22 +04:00
|
|
|
* Copy to the file descriptor if method == GET
|
|
|
|
*/
|
2012-02-08 17:53:24 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
if( c_streq( write_ctx->method, "PUT") ) {
|
2013-04-16 18:27:40 +04:00
|
|
|
|
|
|
|
bool finished = true;
|
|
|
|
int attempts = 0;
|
|
|
|
/*
|
|
|
|
* do ten tries to upload the file chunked. Check the file size and mtime
|
|
|
|
* before submitting a chunk and after having submitted the last one.
|
|
|
|
* If the file has changed, retry.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
Hbf_State state = HBF_SUCCESS;
|
|
|
|
hbf_transfer_t *trans = hbf_init_transfer(clean_uri);
|
2013-07-10 13:51:52 +04:00
|
|
|
if (dav_session.hbf_block_size > 0) {
|
2013-07-22 12:45:49 +04:00
|
|
|
trans->threshold = trans->block_size = dav_session.hbf_block_size;
|
|
|
|
}
|
|
|
|
if (dav_session.hbf_threshold > 0) {
|
|
|
|
trans->threshold = dav_session.hbf_threshold;
|
2013-07-10 13:51:52 +04:00
|
|
|
}
|
2013-04-16 18:27:40 +04:00
|
|
|
finished = true;
|
|
|
|
|
|
|
|
if (!trans) {
|
|
|
|
DEBUG_WEBDAV("hbf_init_transfer failed");
|
|
|
|
rc = 1;
|
|
|
|
} else {
|
|
|
|
state = hbf_splitlist(trans, fd);
|
2013-07-26 15:43:02 +04:00
|
|
|
file_size = trans->stat_size;
|
2013-04-16 18:27:40 +04:00
|
|
|
|
|
|
|
/* Reuse chunk info that was stored in database if existing. */
|
|
|
|
if (dav_session.chunk_info && dav_session.chunk_info->transfer_id) {
|
|
|
|
DEBUG_WEBDAV("Existing chunk info %d %d ", dav_session.chunk_info->start_id, dav_session.chunk_info->transfer_id);
|
|
|
|
trans->start_id = dav_session.chunk_info->start_id;
|
|
|
|
trans->transfer_id = dav_session.chunk_info->transfer_id;
|
|
|
|
}
|
|
|
|
|
2013-07-25 17:36:46 +04:00
|
|
|
if (state == HBF_SUCCESS) {
|
2013-01-29 17:58:54 +04:00
|
|
|
ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx);
|
2013-07-25 17:36:46 +04:00
|
|
|
oc_notify_progress(write_ctx->url, CSYNC_NOTIFY_START_UPLOAD, 0, 0);
|
2013-04-16 18:27:40 +04:00
|
|
|
}
|
|
|
|
|
2013-05-16 19:37:30 +04:00
|
|
|
/* Register the abort callback */
|
|
|
|
hbf_set_abort_callback( trans, _user_want_abort );
|
|
|
|
|
2013-04-16 18:27:40 +04:00
|
|
|
if( state == HBF_SUCCESS ) {
|
|
|
|
chunked_total_size = trans->stat_size;
|
|
|
|
/* Transfer all the chunks through the HTTP session using PUT. */
|
|
|
|
state = hbf_transfer( dav_session.ctx, trans, "PUT" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle errors. */
|
|
|
|
if ( state != HBF_SUCCESS ) {
|
|
|
|
|
2013-05-16 19:37:30 +04:00
|
|
|
if( state == HBF_USER_ABORTED ) {
|
|
|
|
DEBUG_WEBDAV("User Aborted file upload!");
|
|
|
|
errno = ERRNO_USER_ABORT;
|
|
|
|
rc = -1;
|
|
|
|
}
|
2013-04-16 18:27:40 +04:00
|
|
|
/* If the source file changed during submission, lets try again */
|
|
|
|
if( state == HBF_SOURCE_FILE_CHANGE ) {
|
|
|
|
if( attempts++ < 30 ) { /* FIXME: How often do we want to try? */
|
|
|
|
finished = false; /* make it try again from scratch. */
|
|
|
|
DEBUG_WEBDAV("SOURCE file has changed during upload, retry #%d in two seconds!", attempts);
|
|
|
|
sleep(2);
|
|
|
|
}
|
2012-03-30 15:58:59 +04:00
|
|
|
}
|
2013-01-29 17:58:54 +04:00
|
|
|
|
2013-04-16 18:27:40 +04:00
|
|
|
if( finished ) {
|
2013-07-30 10:56:53 +04:00
|
|
|
SAFE_FREE(dav_session.error_string);
|
|
|
|
dav_session.error_string = c_strdup(hbf_error_string(trans, state));
|
2013-04-16 18:27:40 +04:00
|
|
|
error_code = hbf_fail_http_code(trans);
|
2013-07-30 10:56:53 +04:00
|
|
|
set_errno_from_http_errcode(error_code);
|
|
|
|
|
2013-04-16 18:27:40 +04:00
|
|
|
rc = 1;
|
|
|
|
if (dav_session.chunk_info) {
|
|
|
|
dav_session.chunk_info->start_id = trans->start_id;
|
|
|
|
dav_session.chunk_info->transfer_id = trans->transfer_id;
|
|
|
|
}
|
2013-01-29 17:58:54 +04:00
|
|
|
}
|
2013-04-16 18:27:40 +04:00
|
|
|
}
|
2012-12-04 20:21:53 +04:00
|
|
|
}
|
2013-04-16 18:27:40 +04:00
|
|
|
hbf_free_transfer(trans);
|
|
|
|
} while( !finished );
|
|
|
|
|
2013-07-25 17:36:46 +04:00
|
|
|
ne_set_notifier(dav_session.ctx, 0, 0);
|
|
|
|
if( rc == 0 ) {
|
2013-07-26 15:43:02 +04:00
|
|
|
oc_notify_progress(write_ctx->url, CSYNC_NOTIFY_FINISHED_UPLOAD, file_size, file_size);
|
2013-07-25 17:36:46 +04:00
|
|
|
} else {
|
2013-07-31 15:12:10 +04:00
|
|
|
oc_notify_progress(write_ctx->url, CSYNC_NOTIFY_ERROR, error_code, (intptr_t)(dav_session.error_string));
|
2013-04-16 18:27:40 +04:00
|
|
|
}
|
2012-12-04 18:04:22 +04:00
|
|
|
} else if( c_streq( write_ctx->method, "GET") ) {
|
2013-02-08 16:40:48 +04:00
|
|
|
/* GET a file to the file descriptor */
|
|
|
|
/* actually do the request */
|
|
|
|
int retry = 0;
|
|
|
|
DEBUG_WEBDAV(" -- GET on %s", write_ctx->url);
|
|
|
|
write_ctx->fd = fd;
|
2013-07-25 17:36:46 +04:00
|
|
|
ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx);
|
|
|
|
oc_notify_progress(write_ctx->url, CSYNC_NOTIFY_START_DOWNLOAD, 0 , 0);
|
2013-01-29 17:02:51 +04:00
|
|
|
|
2013-02-08 16:40:48 +04:00
|
|
|
do {
|
|
|
|
csync_stat_t sb;
|
|
|
|
|
|
|
|
if (write_ctx->req)
|
|
|
|
ne_request_destroy( write_ctx->req );
|
|
|
|
|
2013-05-16 19:37:30 +04:00
|
|
|
if( _user_want_abort() ) {
|
|
|
|
errno = ERRNO_USER_ABORT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:40:48 +04:00
|
|
|
write_ctx->req = ne_request_create(dav_session.ctx, "GET", clean_uri);;
|
2012-12-13 22:41:39 +04:00
|
|
|
|
|
|
|
/* Allow compressed content by setting the header */
|
|
|
|
ne_add_request_header( write_ctx->req, "Accept-Encoding", "gzip" );
|
|
|
|
|
2013-07-31 15:12:10 +04:00
|
|
|
if (_tfstat(fd, &sb) >= 0 && sb.st_size > 0) {
|
2013-02-08 16:40:48 +04:00
|
|
|
char brange[64];
|
2013-07-31 15:12:10 +04:00
|
|
|
snprintf(brange, sizeof brange, "bytes=%"PRId64"-", (int64_t) sb.st_size);
|
2013-02-08 16:40:48 +04:00
|
|
|
ne_add_request_header(write_ctx->req, "Range", brange);
|
|
|
|
ne_add_request_header(write_ctx->req, "Accept-Ranges", "bytes");
|
2013-07-16 11:19:36 +04:00
|
|
|
DEBUG_WEBDAV("Retry with range %s fd %d", brange, fd);
|
2013-02-08 16:40:48 +04:00
|
|
|
}
|
|
|
|
|
2012-12-13 22:41:39 +04:00
|
|
|
/* hook called before the content is parsed to set the correct reader,
|
|
|
|
* either the compressed- or uncompressed reader.
|
|
|
|
*/
|
|
|
|
ne_hook_post_headers( dav_session.ctx, install_content_reader, write_ctx );
|
|
|
|
|
2012-12-04 21:13:28 +04:00
|
|
|
neon_stat = ne_request_dispatch(write_ctx->req );
|
2012-12-04 18:04:22 +04:00
|
|
|
/* possible return codes are:
|
|
|
|
* NE_OK, NE_AUTH, NE_CONNECT, NE_TIMEOUT, NE_ERROR (from ne_request.h)
|
|
|
|
*/
|
2012-03-30 15:58:59 +04:00
|
|
|
|
2012-12-04 21:13:28 +04:00
|
|
|
if( neon_stat != NE_OK ) {
|
2013-02-08 16:40:48 +04:00
|
|
|
if (neon_stat == NE_TIMEOUT && (++retry) < 3)
|
|
|
|
continue;
|
|
|
|
|
2012-12-04 21:13:28 +04:00
|
|
|
set_errno_from_neon_errcode(neon_stat);
|
2012-12-11 00:15:08 +04:00
|
|
|
DEBUG_WEBDAV("Error GET: Neon: %d, errno %d", neon_stat, errno);
|
2013-03-02 17:30:35 +04:00
|
|
|
error_code = errno;
|
|
|
|
rc = 1;
|
2012-12-04 21:13:28 +04:00
|
|
|
} else {
|
|
|
|
status = ne_get_status( write_ctx->req );
|
2012-12-11 00:15:08 +04:00
|
|
|
DEBUG_WEBDAV("GET http result %d (%s)", status->code, status->reason_phrase ? status->reason_phrase : "<empty");
|
2012-12-04 21:13:28 +04:00
|
|
|
if( status->klass != 2 ) {
|
2012-12-06 16:15:01 +04:00
|
|
|
DEBUG_WEBDAV("sendfile request failed with http status %d!", status->code);
|
2012-12-04 21:13:28 +04:00
|
|
|
set_errno_from_http_errcode( status->code );
|
2012-12-05 17:19:22 +04:00
|
|
|
/* decide if soft error or hard error that stops the whole sync. */
|
2012-12-11 18:26:46 +04:00
|
|
|
/* Currently all problems concerning one file are soft errors */
|
2012-12-05 17:19:22 +04:00
|
|
|
if( status->klass == 4 /* Forbidden and stuff, soft error */ ) {
|
|
|
|
rc = 1;
|
2012-12-11 18:26:46 +04:00
|
|
|
} else if( status->klass == 5 /* Server errors and such */ ) {
|
2012-12-17 20:22:24 +04:00
|
|
|
rc = 1; /* No Abort on individual file errors. */
|
2012-12-05 17:19:22 +04:00
|
|
|
} else {
|
2012-12-11 18:26:46 +04:00
|
|
|
rc = 1;
|
2012-12-06 16:15:01 +04:00
|
|
|
}
|
2012-12-10 19:50:51 +04:00
|
|
|
error_code = status->code;
|
2013-07-30 10:56:53 +04:00
|
|
|
SAFE_FREE(dav_session.error_string);
|
|
|
|
dav_session.error_string = c_strdup(status->reason_phrase);
|
2012-12-06 16:15:01 +04:00
|
|
|
} else {
|
|
|
|
DEBUG_WEBDAV("http request all cool, result code %d", status->code);
|
2012-12-04 21:13:28 +04:00
|
|
|
}
|
2012-12-04 18:04:22 +04:00
|
|
|
}
|
2012-02-08 15:32:29 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
/* delete the hook again, otherwise they get chained as they are with the session */
|
|
|
|
ne_unhook_post_headers( dav_session.ctx, install_content_reader, write_ctx );
|
2012-11-16 15:31:09 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
/* if the compression handle is set through the post_header hook, delete it. */
|
|
|
|
if( write_ctx->decompress ) {
|
|
|
|
ne_decompress_destroy( write_ctx->decompress );
|
|
|
|
}
|
2013-02-08 16:40:48 +04:00
|
|
|
break;
|
|
|
|
} while (1);
|
2013-07-25 17:36:46 +04:00
|
|
|
|
|
|
|
ne_set_notifier(dav_session.ctx, 0, 0);
|
|
|
|
if( rc == 0 ) {
|
2013-07-26 15:43:02 +04:00
|
|
|
oc_notify_progress( write_ctx->url, CSYNC_NOTIFY_FINISHED_DOWNLOAD, write_ctx->get_size , write_ctx->get_size );
|
2013-07-25 17:36:46 +04:00
|
|
|
} else {
|
2013-07-31 15:12:10 +04:00
|
|
|
oc_notify_progress( write_ctx->url, CSYNC_NOTIFY_ERROR, error_code , (intptr_t)(dav_session.error_string));
|
2013-02-08 16:40:48 +04:00
|
|
|
}
|
2012-12-04 18:04:22 +04:00
|
|
|
} else {
|
|
|
|
DEBUG_WEBDAV("Unknown method!");
|
2013-07-30 10:56:53 +04:00
|
|
|
errno = ERRNO_GENERAL_ERROR;
|
2012-12-05 17:19:22 +04:00
|
|
|
rc = -1;
|
2012-12-04 18:04:22 +04:00
|
|
|
}
|
2012-03-30 15:58:59 +04:00
|
|
|
|
2013-01-30 15:29:56 +04:00
|
|
|
chunked_total_size = 0;
|
|
|
|
chunked_done = 0;
|
|
|
|
|
2013-01-29 17:02:51 +04:00
|
|
|
SAFE_FREE(clean_uri);
|
2012-12-04 18:04:22 +04:00
|
|
|
return rc;
|
|
|
|
}
|
2012-02-08 15:32:29 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
static int owncloud_close(csync_vio_method_handle_t *fhandle) {
|
|
|
|
struct transfer_context *writeCtx;
|
2012-11-16 15:31:09 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
int ret = 0;
|
2012-11-16 15:31:09 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
writeCtx = (struct transfer_context*) fhandle;
|
2012-08-30 13:59:52 +04:00
|
|
|
|
2012-12-04 18:04:22 +04:00
|
|
|
if (fhandle == NULL) {
|
2012-12-06 16:15:01 +04:00
|
|
|
DEBUG_WEBDAV("*** Close returns errno EBADF!");
|
2012-12-04 18:04:22 +04:00
|
|
|
errno = EBADF;
|
2012-12-05 17:19:22 +04:00
|
|
|
return -1;
|
2012-12-04 18:04:22 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:02:51 +04:00
|
|
|
if (writeCtx->req)
|
|
|
|
ne_request_destroy( writeCtx->req );
|
2012-02-08 15:32:29 +04:00
|
|
|
|
2012-12-06 17:00:05 +04:00
|
|
|
if( ret != -1 && strcmp( writeCtx->method, "PUT" ) == 0 ) {
|
|
|
|
// Clear the cache so get_id gets the updates
|
|
|
|
clean_caches();
|
|
|
|
}
|
|
|
|
|
2012-02-08 15:32:29 +04:00
|
|
|
/* free mem. Note that the request mem is freed by the ne_request_destroy call */
|
2013-01-29 17:02:51 +04:00
|
|
|
SAFE_FREE( writeCtx->url );
|
2012-02-08 15:32:29 +04:00
|
|
|
SAFE_FREE( writeCtx );
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-08 17:53:24 +04:00
|
|
|
return ret;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static ssize_t owncloud_read(csync_vio_method_handle_t *fhandle, void *buf, size_t count) {
|
2012-04-02 13:30:46 +04:00
|
|
|
size_t len = 0;
|
2012-12-04 18:04:22 +04:00
|
|
|
|
|
|
|
(void) fhandle;
|
|
|
|
(void) buf;
|
|
|
|
(void) count;
|
2012-02-08 15:32:29 +04:00
|
|
|
|
2011-09-13 16:15:44 +04:00
|
|
|
return len;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 18:19:12 +04:00
|
|
|
static int64_t owncloud_lseek(csync_vio_method_handle_t *fhandle, int64_t offset, int whence) {
|
2011-09-01 22:00:20 +04:00
|
|
|
(void) fhandle;
|
|
|
|
(void) offset;
|
|
|
|
(void) whence;
|
|
|
|
|
2011-09-13 16:15:44 +04:00
|
|
|
return -1;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* directory functions
|
|
|
|
*/
|
2012-02-21 13:21:11 +04:00
|
|
|
static csync_vio_method_handle_t *owncloud_opendir(const char *uri) {
|
2012-02-08 17:53:24 +04:00
|
|
|
struct listdir_context *fetchCtx = NULL;
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("opendir method called on %s", uri );
|
2012-02-02 18:50:44 +04:00
|
|
|
|
|
|
|
dav_connect( uri );
|
|
|
|
|
2013-02-09 20:09:22 +04:00
|
|
|
/* fetchCtx = fetch_resource_list( uri, NE_DEPTH_ONE ); */
|
|
|
|
fetchCtx = fetch_resource_list_attempts( uri, NE_DEPTH_ONE);
|
2012-12-05 16:50:26 +04:00
|
|
|
if( !fetchCtx ) {
|
2012-12-04 20:03:00 +04:00
|
|
|
/* errno is set properly in fetch_resource_list */
|
|
|
|
DEBUG_WEBDAV("Errno set to %d", errno);
|
2012-02-05 00:14:09 +04:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
fetchCtx->currResource = fetchCtx->list;
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("opendir returning handle %p", (void*) fetchCtx );
|
2012-02-05 00:14:09 +04:00
|
|
|
return fetchCtx;
|
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
/* no freeing of curi because its part of the fetchCtx and gets freed later */
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_closedir(csync_vio_method_handle_t *dhandle) {
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-08 17:53:24 +04:00
|
|
|
struct listdir_context *fetchCtx = dhandle;
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("closedir method called %p!", dhandle);
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-06-20 17:01:54 +04:00
|
|
|
free_fetchCtx(fetchCtx);
|
2012-02-13 13:43:31 +04:00
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static csync_vio_file_stat_t *owncloud_readdir(csync_vio_method_handle_t *dhandle) {
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-08 17:53:24 +04:00
|
|
|
struct listdir_context *fetchCtx = dhandle;
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2013-07-10 17:17:46 +04:00
|
|
|
if( fetchCtx == NULL) {
|
2012-06-05 19:10:50 +04:00
|
|
|
/* DEBUG_WEBDAV("An empty dir or at end"); */
|
2012-02-02 18:50:44 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:17:46 +04:00
|
|
|
while( fetchCtx->currResource ) {
|
2012-12-05 16:50:26 +04:00
|
|
|
resource* currResource = fetchCtx->currResource;
|
2012-12-06 16:18:54 +04:00
|
|
|
char *escaped_path = NULL;
|
2012-02-02 18:50:44 +04:00
|
|
|
|
2012-03-07 19:38:54 +04:00
|
|
|
/* set pointer to next element */
|
2012-02-02 18:50:44 +04:00
|
|
|
fetchCtx->currResource = fetchCtx->currResource->next;
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
/* It seems strange: first uri->path is unescaped to escape it in the next step again.
|
|
|
|
* The reason is that uri->path is not completely escaped (ie. it seems only to have
|
|
|
|
* spaces escaped), while the fetchCtx->target is fully escaped.
|
|
|
|
* See http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-613
|
|
|
|
*/
|
2012-12-06 16:18:54 +04:00
|
|
|
escaped_path = ne_path_escape( currResource->uri );
|
2012-12-05 16:50:26 +04:00
|
|
|
if (ne_path_compare(fetchCtx->target, escaped_path) != 0) {
|
|
|
|
csync_vio_file_stat_t* lfs = resourceToFileStat(currResource);
|
|
|
|
fill_stat_cache(lfs);
|
|
|
|
SAFE_FREE( escaped_path );
|
|
|
|
return lfs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the target URI */
|
|
|
|
SAFE_FREE( escaped_path );
|
2012-02-02 18:50:44 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
return NULL;
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_mkdir(const char *uri, mode_t mode) {
|
2012-02-13 13:43:31 +04:00
|
|
|
int rc = NE_OK;
|
2012-02-28 18:00:01 +04:00
|
|
|
int len = 0;
|
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
char *path = _cleanPath( uri );
|
2011-09-13 16:15:44 +04:00
|
|
|
(void) mode; /* unused */
|
|
|
|
|
2012-02-28 18:00:01 +04:00
|
|
|
if( ! path ) {
|
|
|
|
errno = EINVAL;
|
|
|
|
rc = -1;
|
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
rc = dav_connect(uri);
|
2011-09-13 16:15:44 +04:00
|
|
|
if (rc < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-02-27 18:50:51 +04:00
|
|
|
/* the uri path is required to have a trailing slash */
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc >= 0 ) {
|
2012-08-08 17:45:00 +04:00
|
|
|
len = strlen( path );
|
2012-12-14 03:04:56 +04:00
|
|
|
if( path[len-1] != '/' ) {
|
|
|
|
path = c_realloc(path, len+2);
|
|
|
|
path[len]= '/';
|
|
|
|
path[len+1] = 0;
|
2012-08-08 17:45:00 +04:00
|
|
|
}
|
2012-12-14 03:04:56 +04:00
|
|
|
DEBUG_WEBDAV("MKdir on %s", path );
|
2013-01-16 16:48:52 +04:00
|
|
|
|
2013-02-08 20:27:06 +04:00
|
|
|
rc = ne_mkcol(dav_session.ctx, path );
|
|
|
|
set_errno_from_neon_errcode(rc);
|
2013-01-16 19:25:51 +04:00
|
|
|
/* Special for mkcol: it returns 405 if the directory already exists.
|
|
|
|
* To keep csync vio_mkdirs working errno EEXIST has to be returned. */
|
2013-02-12 16:36:17 +04:00
|
|
|
if (errno == EPERM && http_result_code_from_session() == 405) {
|
2013-01-16 16:48:52 +04:00
|
|
|
errno = EEXIST;
|
2013-07-25 17:36:46 +04:00
|
|
|
} else if (rc != NE_OK) {
|
|
|
|
oc_notify_progress(uri, CSYNC_NOTIFY_ERROR, http_result_code_from_session(),
|
2013-07-31 15:12:10 +04:00
|
|
|
(intptr_t)(dav_session.error_string) );
|
2013-02-12 16:36:17 +04:00
|
|
|
}
|
2011-09-13 16:15:44 +04:00
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
SAFE_FREE( path );
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc < 0 || rc != NE_OK ) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-01 22:00:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_rmdir(const char *uri) {
|
2012-02-13 13:43:31 +04:00
|
|
|
int rc = NE_OK;
|
|
|
|
char* curi = _cleanPath( uri );
|
2011-09-13 16:15:44 +04:00
|
|
|
|
2013-04-08 14:27:27 +04:00
|
|
|
if( curi == NULL ) {
|
|
|
|
DEBUG_WEBDAV("Can not clean path for %s, bailing out.", uri ? uri:"<empty>");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
rc = dav_connect(uri);
|
2011-09-13 16:15:44 +04:00
|
|
|
if (rc < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc >= 0 ) {
|
|
|
|
rc = ne_delete(dav_session.ctx, curi);
|
2012-12-06 16:15:01 +04:00
|
|
|
set_errno_from_neon_errcode( rc );
|
2012-02-13 13:43:31 +04:00
|
|
|
}
|
|
|
|
SAFE_FREE( curi );
|
|
|
|
if( rc < 0 || rc != NE_OK ) {
|
2011-09-13 16:15:44 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2011-09-01 22:00:20 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_rename(const char *olduri, const char *newuri) {
|
2012-02-10 17:20:28 +04:00
|
|
|
char *src = NULL;
|
|
|
|
char *target = NULL;
|
2012-02-13 13:43:31 +04:00
|
|
|
int rc = NE_OK;
|
2011-09-13 16:15:44 +04:00
|
|
|
|
|
|
|
|
2012-02-10 17:20:28 +04:00
|
|
|
rc = dav_connect(olduri);
|
2011-09-13 16:15:44 +04:00
|
|
|
if (rc < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
|
|
|
|
src = _cleanPath( olduri );
|
|
|
|
target = _cleanPath( newuri );
|
|
|
|
|
|
|
|
if( rc >= 0 ) {
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("MOVE: %s => %s: %d", src, target, rc );
|
2012-02-13 13:43:31 +04:00
|
|
|
rc = ne_move(dav_session.ctx, 1, src, target );
|
2013-01-08 03:15:23 +04:00
|
|
|
if (rc == NE_ERROR && http_result_code_from_session() == 409) {
|
|
|
|
/* destination folder might not exist */
|
|
|
|
errno = ENOENT;
|
|
|
|
} else {
|
|
|
|
set_errno_from_neon_errcode(rc);
|
2013-07-25 17:36:46 +04:00
|
|
|
if (rc != NE_OK) {
|
|
|
|
oc_notify_progress(olduri, CSYNC_NOTIFY_ERROR, http_result_code_from_session(),
|
2013-07-31 15:12:10 +04:00
|
|
|
(intptr_t)(dav_session.error_string) );
|
2013-02-12 16:36:17 +04:00
|
|
|
}
|
2013-01-08 03:15:23 +04:00
|
|
|
}
|
2011-09-13 16:15:44 +04:00
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
SAFE_FREE( src );
|
|
|
|
SAFE_FREE( target );
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc != NE_OK )
|
2013-01-08 01:48:29 +04:00
|
|
|
return 1;
|
2011-09-01 22:00:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_unlink(const char *uri) {
|
2012-02-13 13:43:31 +04:00
|
|
|
int rc = NE_OK;
|
|
|
|
char *path = _cleanPath( uri );
|
2011-09-13 16:15:44 +04:00
|
|
|
|
2012-02-13 13:43:31 +04:00
|
|
|
if( ! path ) {
|
|
|
|
rc = NE_ERROR;
|
2011-09-13 16:15:44 +04:00
|
|
|
errno = EINVAL;
|
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc == NE_OK ) {
|
|
|
|
rc = dav_connect(uri);
|
|
|
|
if (rc < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
}
|
2011-09-13 16:15:44 +04:00
|
|
|
}
|
2012-02-13 13:43:31 +04:00
|
|
|
if( rc == NE_OK ) {
|
2012-02-13 16:57:44 +04:00
|
|
|
rc = ne_delete( dav_session.ctx, path );
|
2012-12-04 20:03:00 +04:00
|
|
|
set_errno_from_neon_errcode(rc);
|
2012-02-13 13:43:31 +04:00
|
|
|
}
|
|
|
|
SAFE_FREE( path );
|
2011-09-01 22:00:20 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_chmod(const char *uri, mode_t mode) {
|
2011-09-01 22:00:20 +04:00
|
|
|
(void) uri;
|
|
|
|
(void) mode;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_chown(const char *uri, uid_t owner, gid_t group) {
|
2011-09-01 22:00:20 +04:00
|
|
|
(void) uri;
|
|
|
|
(void) owner;
|
|
|
|
(void) group;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-14 19:48:47 +04:00
|
|
|
static char *owncloud_error_string()
|
|
|
|
{
|
|
|
|
return dav_session.error_string;
|
|
|
|
}
|
|
|
|
|
2013-04-22 15:51:44 +04:00
|
|
|
static void owncloud_commit() {
|
2013-04-22 17:17:45 +04:00
|
|
|
|
2013-04-22 15:51:44 +04:00
|
|
|
SAFE_FREE( _lastDir );
|
|
|
|
|
|
|
|
clean_caches();
|
|
|
|
|
|
|
|
if( dav_session.ctx )
|
|
|
|
ne_session_destroy( dav_session.ctx );
|
|
|
|
/* DEBUG_WEBDAV( "********** vio_module_shutdown" ); */
|
|
|
|
|
2013-05-13 19:46:21 +04:00
|
|
|
dav_session.ctx = 0;
|
|
|
|
|
2013-04-22 15:51:44 +04:00
|
|
|
ne_sock_exit();
|
|
|
|
_connected = 0; /* triggers dav_connect to go through the whole neon setup */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-21 13:21:11 +04:00
|
|
|
static int owncloud_utimes(const char *uri, const struct timeval *times) {
|
2011-09-01 22:00:20 +04:00
|
|
|
|
2012-02-06 16:34:21 +04:00
|
|
|
ne_proppatch_operation ops[2];
|
|
|
|
ne_propname pname;
|
|
|
|
int rc = NE_OK;
|
|
|
|
char val[255];
|
2012-05-21 11:44:23 +04:00
|
|
|
char *curi = NULL;
|
2012-07-04 18:32:17 +04:00
|
|
|
const struct timeval *modtime = times+1;
|
|
|
|
long newmodtime;
|
2012-02-14 17:29:07 +04:00
|
|
|
|
|
|
|
curi = _cleanPath( uri );
|
2012-02-06 16:34:21 +04:00
|
|
|
|
2012-02-20 14:58:50 +04:00
|
|
|
if( ! uri ) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if( !times ) {
|
|
|
|
errno = EACCES;
|
2012-03-07 19:38:54 +04:00
|
|
|
return -1; /* FIXME: Find good errno */
|
2012-02-06 16:34:21 +04:00
|
|
|
}
|
2012-07-20 12:51:39 +04:00
|
|
|
pname.nspace = "DAV:";
|
2012-09-28 19:36:04 +04:00
|
|
|
pname.name = "lastmodified";
|
2012-02-06 16:34:21 +04:00
|
|
|
|
2012-07-04 18:32:17 +04:00
|
|
|
newmodtime = modtime->tv_sec;
|
2012-08-30 13:59:52 +04:00
|
|
|
|
2012-07-04 18:32:17 +04:00
|
|
|
snprintf( val, sizeof(val), "%ld", newmodtime );
|
2012-06-05 19:10:50 +04:00
|
|
|
DEBUG_WEBDAV("Setting LastModified of %s to %s", curi, val );
|
2012-02-06 16:34:21 +04:00
|
|
|
|
|
|
|
ops[0].name = &pname;
|
|
|
|
ops[0].type = ne_propset;
|
|
|
|
ops[0].value = val;
|
|
|
|
|
|
|
|
ops[1].name = NULL;
|
|
|
|
|
2012-02-14 17:29:07 +04:00
|
|
|
rc = ne_proppatch( dav_session.ctx, curi, ops );
|
|
|
|
SAFE_FREE(curi);
|
|
|
|
|
2012-02-06 16:34:21 +04:00
|
|
|
if( rc != NE_OK ) {
|
2013-04-08 14:27:27 +04:00
|
|
|
const char *err = ne_get_error(dav_session.ctx);
|
2012-12-17 20:22:24 +04:00
|
|
|
set_errno_from_neon_errcode(rc);
|
2013-04-08 14:27:27 +04:00
|
|
|
|
|
|
|
DEBUG_WEBDAV("Error in propatch: %s", err == NULL ? "<empty err msg.>" : err);
|
2012-02-13 13:43:31 +04:00
|
|
|
return -1;
|
2012-02-06 16:34:21 +04:00
|
|
|
}
|
2012-12-06 17:00:05 +04:00
|
|
|
|
|
|
|
clean_caches();
|
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-05 16:50:26 +04:00
|
|
|
static int owncloud_set_property(const char *key, void *data) {
|
2012-12-04 18:31:22 +04:00
|
|
|
#define READ_STRING_PROPERTY(P) \
|
|
|
|
if (c_streq(key, #P)) { \
|
|
|
|
SAFE_FREE(dav_session.P); \
|
|
|
|
dav_session.P = c_strdup((const char*)data); \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
READ_STRING_PROPERTY(session_key)
|
|
|
|
READ_STRING_PROPERTY(proxy_type)
|
|
|
|
READ_STRING_PROPERTY(proxy_host)
|
|
|
|
READ_STRING_PROPERTY(proxy_user)
|
|
|
|
READ_STRING_PROPERTY(proxy_pwd)
|
|
|
|
#undef READ_STRING_PROPERTY
|
|
|
|
|
|
|
|
if (c_streq(key, "proxy_port")) {
|
|
|
|
dav_session.proxy_port = *(int*)(data);
|
2012-12-04 16:43:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-02-06 21:38:46 +04:00
|
|
|
if (c_streq(key, "read_timeout") || c_streq(key, "timeout")) {
|
2012-12-05 20:29:00 +04:00
|
|
|
dav_session.read_timeout = *(int*)(data);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-07 12:02:25 +04:00
|
|
|
if( c_streq(key, "csync_context")) {
|
|
|
|
dav_session.csync_ctx = data;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-11 22:02:18 +04:00
|
|
|
if( c_streq(key, "hbf_info")) {
|
|
|
|
dav_session.chunk_info = (csync_hbf_info_t *)(data);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-03 21:02:20 +04:00
|
|
|
if( c_streq(key, "get_dav_session")) {
|
|
|
|
/* Give the ne_session to the caller */
|
|
|
|
*(ne_session**)data = dav_session.ctx;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-08 15:26:59 +04:00
|
|
|
if( c_streq(key, "no_recursive_propfind")) {
|
|
|
|
dav_session.no_recursive_propfind = *(bool*)(data);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-10 13:51:52 +04:00
|
|
|
if( c_streq(key, "hbf_block_size")) {
|
2013-07-30 18:19:12 +04:00
|
|
|
dav_session.hbf_block_size = *(int64_t*)(data);
|
2013-07-10 13:51:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-22 12:45:49 +04:00
|
|
|
if( c_streq(key, "hbf_threshold")) {
|
2013-07-30 18:19:12 +04:00
|
|
|
dav_session.hbf_threshold = *(int64_t*)(data);
|
2013-07-22 12:45:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-24 17:07:38 +04:00
|
|
|
if( c_streq(key, "bandwidth_limit_upload")) {
|
|
|
|
dav_session.bandwidth_limit_upload = *(int*)(data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if( c_streq(key, "bandwidth_limit_download")) {
|
|
|
|
dav_session.bandwidth_limit_download = *(int*)(data);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-25 17:36:46 +04:00
|
|
|
if( c_streq(key, "overall_progress_data")) {
|
|
|
|
dav_session.overall_progress_data = (csync_overall_progress_t*)(data);
|
|
|
|
}
|
2012-12-04 18:31:22 +04:00
|
|
|
|
2012-12-04 16:43:15 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
csync_vio_method_t _method = {
|
|
|
|
.method_table_size = sizeof(csync_vio_method_t),
|
2012-08-23 18:35:16 +04:00
|
|
|
.get_capabilities = owncloud_capabilities,
|
2012-08-17 17:50:31 +04:00
|
|
|
.get_file_id = owncloud_file_id,
|
2012-02-21 13:21:11 +04:00
|
|
|
.open = owncloud_open,
|
|
|
|
.creat = owncloud_creat,
|
|
|
|
.close = owncloud_close,
|
|
|
|
.read = owncloud_read,
|
|
|
|
.write = owncloud_write,
|
2012-12-04 18:04:22 +04:00
|
|
|
.sendfile = owncloud_sendfile,
|
2012-02-21 13:21:11 +04:00
|
|
|
.lseek = owncloud_lseek,
|
|
|
|
.opendir = owncloud_opendir,
|
|
|
|
.closedir = owncloud_closedir,
|
|
|
|
.readdir = owncloud_readdir,
|
|
|
|
.mkdir = owncloud_mkdir,
|
|
|
|
.rmdir = owncloud_rmdir,
|
|
|
|
.stat = owncloud_stat,
|
|
|
|
.rename = owncloud_rename,
|
|
|
|
.unlink = owncloud_unlink,
|
|
|
|
.chmod = owncloud_chmod,
|
|
|
|
.chown = owncloud_chown,
|
2012-12-04 16:43:15 +04:00
|
|
|
.utimes = owncloud_utimes,
|
2012-12-14 19:48:47 +04:00
|
|
|
.set_property = owncloud_set_property,
|
2013-04-22 15:51:44 +04:00
|
|
|
.get_error_string = owncloud_error_string,
|
|
|
|
.commit = owncloud_commit
|
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
csync_vio_method_t *vio_module_init(const char *method_name, const char *args,
|
2012-02-02 18:50:44 +04:00
|
|
|
csync_auth_callback cb, void *userdata) {
|
2011-09-01 22:00:20 +04:00
|
|
|
(void) method_name;
|
|
|
|
(void) args;
|
2013-07-05 20:43:29 +04:00
|
|
|
(void) userdata;
|
2012-07-19 12:50:18 +04:00
|
|
|
|
2012-02-10 17:20:28 +04:00
|
|
|
_authcb = cb;
|
2012-04-27 18:33:31 +04:00
|
|
|
_connected = 0; /* triggers dav_connect to go through the whole neon setup */
|
|
|
|
|
2012-12-04 18:31:22 +04:00
|
|
|
memset(&dav_session, 0, sizeof(dav_session));
|
2012-07-31 18:59:15 +04:00
|
|
|
|
2011-09-01 22:00:20 +04:00
|
|
|
return &_method;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vio_module_shutdown(csync_vio_method_t *method) {
|
|
|
|
(void) method;
|
2012-02-11 01:02:21 +04:00
|
|
|
|
2013-05-13 19:46:21 +04:00
|
|
|
owncloud_commit();
|
|
|
|
|
2012-02-11 01:02:21 +04:00
|
|
|
SAFE_FREE( dav_session.user );
|
|
|
|
SAFE_FREE( dav_session.pwd );
|
|
|
|
|
2012-07-31 18:59:15 +04:00
|
|
|
SAFE_FREE( dav_session.proxy_type );
|
|
|
|
SAFE_FREE( dav_session.proxy_host );
|
|
|
|
SAFE_FREE( dav_session.proxy_user );
|
|
|
|
SAFE_FREE( dav_session.proxy_pwd );
|
2012-12-04 16:43:15 +04:00
|
|
|
SAFE_FREE( dav_session.session_key);
|
2012-12-14 19:48:47 +04:00
|
|
|
SAFE_FREE( dav_session.error_string );
|
2012-07-31 18:59:15 +04:00
|
|
|
|
2012-06-05 19:10:50 +04:00
|
|
|
/* DEBUG_WEBDAV( "********** vio_module_shutdown" ); */
|
2011-09-01 22:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=4 sw=4 et cindent: */
|