diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 2d29f5529..290c84d75 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -14,6 +14,7 @@ set(MODULES_PUBLIC_INCLUDE_DIRS set(MODULES_PRIVATE_INCLUDE_DIRS ${CSTDLIB_PUBLIC_INCLUDE_DIRS} ${CSYNC_PUBLIC_INCLUDE_DIRS} + ${HTTPBF_PUBLIC_INCLUDE_DIRS} ) set(SMB_PLUGIN @@ -64,7 +65,7 @@ endif (LIBSSH_FOUND) if (NEON_FOUND) include_directories( ${NEON_INCLUDE_DIRS} ) macro_add_plugin(${OWNCLOUD_PLUGIN} csync_owncloud.c) - target_link_libraries(${OWNCLOUD_PLUGIN} ${CSYNC_LIBRARY} ${NEON_LIBRARIES}) + target_link_libraries(${OWNCLOUD_PLUGIN} ${CSYNC_LIBRARY} ${NEON_LIBRARIES} ${HTTPBF_LIBRARY}) install( TARGETS diff --git a/modules/csync_owncloud.c b/modules/csync_owncloud.c index 065c0a22d..c38eb31b0 100644 --- a/modules/csync_owncloud.c +++ b/modules/csync_owncloud.c @@ -48,6 +48,7 @@ #include "csync_misc.h" #include "csync_macros.h" #include "c_private.h" +#include "httpbf.h" #include "vio/csync_vio_module.h" #include "vio/csync_vio_file_stat.h" @@ -1571,23 +1572,25 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha */ if( c_streq( write_ctx->method, "PUT") ) { - /* Transmit a file through PUT */ - ne_request *request = ne_request_create(dav_session.ctx, "PUT", clean_uri); - write_ctx->req = request; - if( request ) { - /* stat the source-file to get the file size. */ - csync_stat_t sb; - if( fstat( fd, &sb ) == 0 ) { + /* stat the source-file to get the file size. */ + csync_stat_t sb; + if (_progresscb) { + ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx); + _progresscb(write_ctx->url, CSYNC_NOTIFY_START_UPLOAD, 0 , 0, dav_session.userdata); + } + if( fstat( fd, &sb ) != 0 ) { + DEBUG_WEBDAV("Could not stat file descriptor"); + rc = 1; + } else if (sb.st_size < 1024*1024*2) { + /* Transmit a file through PUT */ + ne_request *request = ne_request_create(dav_session.ctx, "PUT", clean_uri); + write_ctx->req = request; + if( request ) { /* Attach the request to the file descriptor */ ne_set_request_body_fd(request, fd, 0, sb.st_size); DEBUG_WEBDAV("Put file size: %lld, variable sizeof: %ld", (long long int) sb.st_size, sizeof(sb.st_size)); - if (_progresscb) { - ne_set_notifier(dav_session.ctx, ne_notify_status_cb, write_ctx); - _progresscb(write_ctx->url, CSYNC_NOTIFY_START_UPLOAD, 0 , 0, dav_session.userdata); - } - /* Start the request. */ neon_stat = ne_request_dispatch( write_ctx->req ); set_errno_from_neon_errcode( neon_stat ); @@ -1611,20 +1614,34 @@ static int owncloud_sendfile(csync_vio_method_handle_t *src, csync_vio_method_ha } else { DEBUG_WEBDAV("http request all cool, result code %d", status->code); } - - if (_progresscb) { - ne_set_notifier(dav_session.ctx, 0, 0); - _progresscb(write_ctx->url, rc != NE_OK ? CSYNC_NOTIFY_ERROR : - CSYNC_NOTIFY_FINISHED_UPLOAD, error_code, - (long long)(error_string), dav_session.userdata); - } } else { - DEBUG_WEBDAV("Could not stat file descriptor"); + DEBUG_WEBDAV("Did not find a valid request!"); rc = 1; } } else { - DEBUG_WEBDAV("Did not find a valid request!"); - rc = 1; + /* use httpbf */ + hbf_transfer_t *trans = hbf_init_transfer(clean_uri); + if (!trans) { + DEBUG_WEBDAV("hbf_init_transfer failed"); + rc = 1; + } else { + Hbf_State state = hbf_splitlist(trans, fd); + if( state == HBF_SUCCESS ) { + /* Transfer all the chunks through the HTTP session using PUT. */ + state = hbf_transfer( dav_session.ctx, trans, "PUT" ); + } + + if ( state != HBF_SUCCESS ) { + error_string = hbf_error_string(state); + rc = 1; + } + } + } + if (_progresscb) { + ne_set_notifier(dav_session.ctx, 0, 0); + _progresscb(write_ctx->url, rc != NE_OK ? CSYNC_NOTIFY_ERROR : + CSYNC_NOTIFY_FINISHED_UPLOAD, error_code, + (long long)(error_string), dav_session.userdata); } } else if( c_streq( write_ctx->method, "GET") ) { ne_request *request = ne_request_create(dav_session.ctx, "GET", clean_uri); diff --git a/src/httpbf/CMakeLists.txt b/src/httpbf/CMakeLists.txt index b21cffe1d..1d22f985b 100644 --- a/src/httpbf/CMakeLists.txt +++ b/src/httpbf/CMakeLists.txt @@ -1,7 +1,7 @@ project(httpbflib C) set(HTTPBF_PUBLIC_INCLUDE_DIRS - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src CACHE INTERNAL "httpbflib public include directories" ) diff --git a/tests/ownCloud/mocka/CMakeLists.txt b/tests/ownCloud/mocka/CMakeLists.txt index 338347850..ef0726f05 100644 --- a/tests/ownCloud/mocka/CMakeLists.txt +++ b/tests/ownCloud/mocka/CMakeLists.txt @@ -9,10 +9,11 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMOCKA_INCLUDE_DIRS} ${NEON_INCLUDE_DIRS} + ${HTTPBF_PUBLIC_INCLUDE_DIRS} ) add_executable(ocmod_test ocmod_test.c) -target_link_libraries(ocmod_test ${CMOCKA_LIBRARIES} ${NEON_LIBRARIES} ${CSYNC_LIBRARY} ) +target_link_libraries(ocmod_test ${CMOCKA_LIBRARIES} ${NEON_LIBRARIES} ${CSYNC_LIBRARY} ${HTTPBF_LIBRARY})