diff --git a/CMakeLists.txt b/CMakeLists.txt index c7429278f..a5eb52bab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 2.6) cmake_policy(VERSION 2.8.0) +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) +endif() project(client) @@ -57,7 +60,7 @@ endif() include(GNUInstallDirs) include(DefineInstallationPaths) - +include(GenerateExportHeader) include(GetGitRevisionDescription) @@ -166,6 +169,9 @@ find_package(SQLite3 3.8.0 REQUIRED) # On some OS, we want to use our own, not the system sqlite if (USE_OUR_OWN_SQLITE3) include_directories(BEFORE ${SQLITE3_INCLUDE_DIR}) + if (WIN32) + add_definitions(-DSQLITE_API=__declspec\(dllimport\)) + endif() endif() find_package(ZLIB) @@ -180,6 +186,7 @@ add_definitions(-DUNICODE) add_definitions(-D_UNICODE) if( WIN32 ) add_definitions( -D__USE_MINGW_ANSI_STDIO=1 ) +add_definitions( -DNOMINMAX ) endif( WIN32 ) # Handle Translations, pick all client_* files from trans directory. diff --git a/cmake/modules/Warnings.cmake b/cmake/modules/Warnings.cmake index 4ba425983..1ee7a9ea7 100644 --- a/cmake/modules/Warnings.cmake +++ b/cmake/modules/Warnings.cmake @@ -2,21 +2,23 @@ # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING* file. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -if(CMAKE_COMPILER_IS_GNUCXX) - execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion - OUTPUT_VARIABLE GCC_VERSION) - if(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") - else(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION) + if(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") + else(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") + endif(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) + else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") - endif(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") -endif(CMAKE_COMPILER_IS_GNUCXX) + endif() -if(DEFINED MIRALL_FATAL_WARNINGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") -endif(DEFINED MIRALL_FATAL_WARNINGS) + if(DEFINED MIRALL_FATAL_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + endif(DEFINED MIRALL_FATAL_WARNINGS) +endif() diff --git a/csync/src/CMakeLists.txt b/csync/src/CMakeLists.txt index 6f5fc6095..cb07377e9 100644 --- a/csync/src/CMakeLists.txt +++ b/csync/src/CMakeLists.txt @@ -81,6 +81,13 @@ set(csync_HDRS # Statically include sqlite if (USE_OUR_OWN_SQLITE3) list(APPEND csync_SRCS ${SQLITE3_SOURCE}) + if (WIN32) + # We want to export sqlite symbols from the ocsync DLL without + # having to patch both sqlite3.h and the amalgation sqlite3.c, + # so do the import/export magic manually through the build system. + remove_definitions(-DSQLITE_API=__declspec\(dllimport\)) + add_definitions(-DSQLITE_API=__declspec\(dllexport\)) + endif() endif() include_directories( @@ -91,6 +98,12 @@ include_directories( add_library(${CSYNC_LIBRARY} SHARED ${csync_SRCS}) #add_library(${CSYNC_LIBRARY}_static STATIC ${csync_SRCS}) +generate_export_header( ${CSYNC_LIBRARY} + BASE_NAME ${CSYNC_LIBRARY} + EXPORT_MACRO_NAME OCSYNC_EXPORT + EXPORT_FILE_NAME ocsynclib.h +) + target_link_libraries(${CSYNC_LIBRARY} ${CSYNC_LINK_LIBRARIES}) #target_link_libraries(${CSYNC_LIBRARY}_static ${CSYNC_LINK_LIBRARIES}) diff --git a/csync/src/csync.c b/csync/src/csync.c index 281a00ee9..78660955c 100644 --- a/csync/src/csync.c +++ b/csync/src/csync.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/csync/src/csync.h b/csync/src/csync.h index 678985d32..d731bb5d7 100644 --- a/csync/src/csync.h +++ b/csync/src/csync.h @@ -33,10 +33,10 @@ #define _CSYNC_H #include "std/c_private.h" +#include "ocsynclib.h" #include #include #include -#include #include #include @@ -229,14 +229,14 @@ struct csync_vio_file_stat_s { char *original_name; // only set if locale conversion fails }; -csync_vio_file_stat_t *csync_vio_file_stat_new(void); -csync_vio_file_stat_t *csync_vio_file_stat_copy(csync_vio_file_stat_t *file_stat); +csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_file_stat_new(void); +csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_file_stat_copy(csync_vio_file_stat_t *file_stat); -void csync_vio_file_stat_destroy(csync_vio_file_stat_t *fstat); +void OCSYNC_EXPORT csync_vio_file_stat_destroy(csync_vio_file_stat_t *fstat); -void csync_vio_file_stat_set_file_id( csync_vio_file_stat_t* dst, const char* src ); +void OCSYNC_EXPORT csync_vio_file_stat_set_file_id( csync_vio_file_stat_t* dst, const char* src ); -void csync_vio_set_file_id(char* dst, const char *src ); +void OCSYNC_EXPORT csync_vio_set_file_id(char* dst, const char *src ); /** @@ -317,7 +317,7 @@ typedef const char* (*csync_checksum_hook) ( * * @param csync The context variable to allocate. */ -void csync_create(CSYNC **csync, const char *local, const char *remote); +void OCSYNC_EXPORT csync_create(CSYNC **csync, const char *local, const char *remote); /** * @brief Initialize the file synchronizer. @@ -326,7 +326,7 @@ void csync_create(CSYNC **csync, const char *local, const char *remote); * * @param ctx The context to initialize. */ -void csync_init(CSYNC *ctx); +void OCSYNC_EXPORT csync_init(CSYNC *ctx); /** * @brief Update detection @@ -335,7 +335,7 @@ void csync_init(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_update(CSYNC *ctx); +int OCSYNC_EXPORT csync_update(CSYNC *ctx); /** * @brief Reconciliation @@ -344,7 +344,7 @@ int csync_update(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_reconcile(CSYNC *ctx); +int OCSYNC_EXPORT csync_reconcile(CSYNC *ctx); /** * @brief Re-initializes the csync context @@ -353,7 +353,7 @@ int csync_reconcile(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_commit(CSYNC *ctx); +int OCSYNC_EXPORT csync_commit(CSYNC *ctx); /** * @brief Destroy the csync context @@ -364,7 +364,7 @@ int csync_commit(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_destroy(CSYNC *ctx); +int OCSYNC_EXPORT csync_destroy(CSYNC *ctx); /** * @brief Get the userdata saved in the context. @@ -386,7 +386,7 @@ void *csync_get_userdata(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_set_userdata(CSYNC *ctx, void *userdata); +int OCSYNC_EXPORT csync_set_userdata(CSYNC *ctx, void *userdata); /** * @brief Get the authentication callback set. @@ -396,7 +396,7 @@ int csync_set_userdata(CSYNC *ctx, void *userdata); * @return The authentication callback set or NULL if an error * occurred. */ -csync_auth_callback csync_get_auth_callback(CSYNC *ctx); +csync_auth_callback OCSYNC_EXPORT csync_get_auth_callback(CSYNC *ctx); /** * @brief Set the authentication callback. @@ -407,7 +407,7 @@ csync_auth_callback csync_get_auth_callback(CSYNC *ctx); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb); +int OCSYNC_EXPORT csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb); /** * @brief Set the log level. @@ -416,14 +416,14 @@ int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb); * * @return 0 on success, < 0 if an error occurred. */ -int csync_set_log_level(int level); +int OCSYNC_EXPORT csync_set_log_level(int level); /** * @brief Get the log verbosity * * @return The log verbosity, -1 on error. */ -int csync_get_log_level(void); +int OCSYNC_EXPORT csync_get_log_level(void); /** * @brief Get the logging callback set. @@ -431,7 +431,7 @@ int csync_get_log_level(void); * @return The logging callback set or NULL if an error * occurred. */ -csync_log_callback csync_get_log_callback(void); +csync_log_callback OCSYNC_EXPORT csync_get_log_callback(void); /** * @brief Set the logging callback. @@ -440,14 +440,14 @@ csync_log_callback csync_get_log_callback(void); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_set_log_callback(csync_log_callback cb); +int OCSYNC_EXPORT csync_set_log_callback(csync_log_callback cb); /** * @brief get the userdata set for the logging callback. * * @return The userdata or NULL. */ -void *csync_get_log_userdata(void); +void OCSYNC_EXPORT *csync_get_log_userdata(void); /** * @brief Set the userdata passed to the logging callback. @@ -456,13 +456,13 @@ void *csync_get_log_userdata(void); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_set_log_userdata(void *data); +int OCSYNC_EXPORT csync_set_log_userdata(void *data); /* Used for special modes or debugging */ -CSYNC_STATUS csync_get_status(CSYNC *ctx); +CSYNC_STATUS OCSYNC_EXPORT csync_get_status(CSYNC *ctx); /* Used for special modes or debugging */ -int csync_set_status(CSYNC *ctx, int status); +int OCSYNC_EXPORT csync_set_status(CSYNC *ctx, int status); typedef int csync_treewalk_visit_func(TREE_WALK_FILE* ,void*); @@ -475,7 +475,7 @@ typedef int csync_treewalk_visit_func(TREE_WALK_FILE* ,void*); * * @return 0 on success, less than 0 if an error occurred. */ -int csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter); +int OCSYNC_EXPORT csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter); /** * @brief Walk the remote file tree and call a visitor function for each file. @@ -486,7 +486,7 @@ int csync_walk_local_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int fi * * @return 0 on success, less than 0 if an error occurred. */ -int csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter); +int OCSYNC_EXPORT csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int filter); /** * @brief Get the csync status string. @@ -495,7 +495,7 @@ int csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *visitor, int f * * @return A const pointer to a string with more precise status info. */ -const char *csync_get_status_string(CSYNC *ctx); +const char OCSYNC_EXPORT *csync_get_status_string(CSYNC *ctx); #ifdef WITH_ICONV /** @@ -505,7 +505,7 @@ const char *csync_get_status_string(CSYNC *ctx); * * @return 0 on success, or an iconv error number. */ -int csync_set_iconv_codec(const char *from); +int OCSYNC_EXPORT csync_set_iconv_codec(const char *from); #endif /** @@ -513,24 +513,24 @@ int csync_set_iconv_codec(const char *from); * * @param ctx The csync context. */ -void csync_request_abort(CSYNC *ctx); +void OCSYNC_EXPORT csync_request_abort(CSYNC *ctx); /** * @brief Clears the abort flag. Can be called from another thread. * * @param ctx The csync context. */ -void csync_resume(CSYNC *ctx); +void OCSYNC_EXPORT csync_resume(CSYNC *ctx); /** * @brief Checks for the abort flag, to be used from the modules. * * @param ctx The csync context. */ -int csync_abort_requested(CSYNC *ctx); +int OCSYNC_EXPORT csync_abort_requested(CSYNC *ctx); -char *csync_normalize_etag(const char *); -time_t oc_httpdate_parse( const char *date ); +char OCSYNC_EXPORT *csync_normalize_etag(const char *); +time_t OCSYNC_EXPORT oc_httpdate_parse( const char *date ); #ifdef __cplusplus } diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c index 4f106b66f..4a3a097d6 100644 --- a/csync/src/csync_exclude.c +++ b/csync/src/csync_exclude.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "c_lib.h" #include "c_private.h" @@ -37,6 +36,12 @@ #include "csync_exclude.h" #include "csync_misc.h" +#ifdef _WIN32 +#include +#else +#include +#endif + #define CSYNC_LOG_CATEGORY_NAME "csync.exclude" #include "csync_log.h" diff --git a/csync/src/csync_exclude.h b/csync/src/csync_exclude.h index 1fe970cdd..3e49a9291 100644 --- a/csync/src/csync_exclude.h +++ b/csync/src/csync_exclude.h @@ -21,6 +21,8 @@ #ifndef _CSYNC_EXCLUDE_H #define _CSYNC_EXCLUDE_H +#include "ocsynclib.h" + enum csync_exclude_type_e { CSYNC_NOT_EXCLUDED = 0, CSYNC_FILE_SILENTLY_EXCLUDED, @@ -46,7 +48,7 @@ int _csync_exclude_add(c_strlist_t **inList, const char *string); * * @return 0 on success, -1 if an error occurred with errno set. */ -int csync_exclude_load(const char *fname, c_strlist_t **list); +int OCSYNC_EXPORT csync_exclude_load(const char *fname, c_strlist_t **list); /** * @brief Check if the given path should be excluded in a traversal situation. @@ -72,7 +74,7 @@ CSYNC_EXCLUDE_TYPE csync_excluded_traversal(c_strlist_t *excludes, const char *p * @param filetype * @return */ -CSYNC_EXCLUDE_TYPE csync_excluded_no_ctx(c_strlist_t *excludes, const char *path, int filetype); +CSYNC_EXCLUDE_TYPE OCSYNC_EXPORT csync_excluded_no_ctx(c_strlist_t *excludes, const char *path, int filetype); #endif /* _CSYNC_EXCLUDE_H */ /** diff --git a/csync/src/csync_log.c b/csync/src/csync_log.c index d5f34aa12..159ce2a83 100644 --- a/csync/src/csync_log.c +++ b/csync/src/csync_log.c @@ -23,12 +23,6 @@ #include #include #include -#ifndef _WIN32 -#include -#else -#include -#endif -#include #include "csync_private.h" #include "csync_log.h" @@ -37,46 +31,11 @@ CSYNC_THREAD int csync_log_level; CSYNC_THREAD csync_log_callback csync_log_cb; CSYNC_THREAD void *csync_log_userdata; -static int current_timestring(int hires, char *buf, size_t len) -{ - char tbuf[64]; - struct timeval tv; - struct tm *tm; - time_t t; - - gettimeofday(&tv, NULL); - t = (time_t) tv.tv_sec; - - tm = localtime(&t); - if (tm == NULL) { - return -1; - } - - if (hires) { - strftime(tbuf, sizeof(tbuf) - 1, "%Y/%m/%d %H:%M:%S", tm); - snprintf(buf, len, "%s.%06ld", tbuf, (long) tv.tv_usec); - } else { - strftime(tbuf, sizeof(tbuf) - 1, "%Y/%m/%d %H:%M:%S", tm); - snprintf(buf, len, "%s", tbuf); - } - - return 0; -} - static void csync_log_stderr(int verbosity, const char *function, const char *buffer) { - char date[64] = {0}; - int rc; - - rc = current_timestring(1, date, sizeof(date)); - if (rc == 0) { - fprintf(stderr, "[%s, %d] %s:", date+5, verbosity, function); - } else { - fprintf(stderr, "[%d] %s", verbosity, function); - } - + fprintf(stderr, "[%d] %s", verbosity, function); fprintf(stderr, " %s\n", buffer); } static void csync_log_function(int verbosity, diff --git a/csync/src/csync_misc.c b/csync/src/csync_misc.c index a93d42213..d23236113 100644 --- a/csync/src/csync_misc.c +++ b/csync/src/csync_misc.c @@ -39,7 +39,6 @@ # include #else /* _WIN32 */ # include -# include #endif /* _WIN32 */ #include "c_lib.h" diff --git a/csync/src/csync_misc.h b/csync/src/csync_misc.h index 783ef4dd5..6b9f98418 100644 --- a/csync/src/csync_misc.h +++ b/csync/src/csync_misc.h @@ -36,7 +36,7 @@ #define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ #endif -int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags); +int csync_fnmatch(const char *pattern, const char *name, int flags); /** * @brief csync_errno_to_status - errno to csync status code diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h index 1ceede56d..0a5072466 100644 --- a/csync/src/csync_private.h +++ b/csync/src/csync_private.h @@ -224,9 +224,6 @@ struct _csync_treewalk_context_s }; typedef struct _csync_treewalk_context_s _csync_treewalk_context; - -time_t oc_httpdate_parse( const char *date ); - void set_errno_from_http_errcode( int err ); /** diff --git a/csync/src/csync_reconcile.h b/csync/src/csync_reconcile.h index 207727f45..f333adba6 100644 --- a/csync/src/csync_reconcile.h +++ b/csync/src/csync_reconcile.h @@ -50,7 +50,7 @@ * * @todo Add an argument to set the algorithm to use. */ -int csync_reconcile_updates(CSYNC *ctx); +int OCSYNC_EXPORT csync_reconcile_updates(CSYNC *ctx); /** * }@ diff --git a/csync/src/csync_rename.h b/csync/src/csync_rename.h index a4f50a0ac..8aa2e60c7 100644 --- a/csync/src/csync_rename.h +++ b/csync/src/csync_rename.h @@ -27,11 +27,11 @@ extern "C" { #endif /* Return the final destination path of a given patch in case of renames */ -char *csync_rename_adjust_path(CSYNC *ctx, const char *path); +char OCSYNC_EXPORT *csync_rename_adjust_path(CSYNC *ctx, const char *path); /* Return the source of a given path in case of renames */ -char *csync_rename_adjust_path_source(CSYNC *ctx, const char *path); -void csync_rename_destroy(CSYNC *ctx); -void csync_rename_record(CSYNC *ctx, const char *from, const char *to); +char OCSYNC_EXPORT *csync_rename_adjust_path_source(CSYNC *ctx, const char *path); +void OCSYNC_EXPORT csync_rename_destroy(CSYNC *ctx); +void OCSYNC_EXPORT csync_rename_record(CSYNC *ctx, const char *from, const char *to); #ifdef __cplusplus } diff --git a/csync/src/csync_statedb.c b/csync/src/csync_statedb.c index 519a45748..95b8e78e6 100644 --- a/csync/src/csync_statedb.c +++ b/csync/src/csync_statedb.c @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -53,7 +52,7 @@ #define sqlite_open(A, B) sqlite3_open_v2(A,B, SQLITE_OPEN_READONLY+SQLITE_OPEN_NOMUTEX, NULL) -#define SQLTM_TIME 150000 +#define SQLTM_TIME 150 #define SQLTM_COUNT 10 #define SQLITE_BUSY_HANDLED(F) if(1) { \ @@ -61,7 +60,7 @@ do { rc = F ; \ if( (rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED) ) { \ n++; \ - usleep(SQLTM_TIME); \ + csync_sleep(SQLTM_TIME); \ } \ }while( (n < SQLTM_COUNT) && ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED))); \ } @@ -519,8 +518,7 @@ c_strlist_t *csync_statedb_query(sqlite3 *db, /* compile SQL program into a virtual machine, reattempteing if busy */ do { if (busy_count) { - /* sleep 100 msec */ - usleep(100000); + csync_sleep(100); CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "sqlite3_prepare: BUSY counter: %zu", busy_count); } err = sqlite3_prepare(db, statement, -1, &stmt, &tail); @@ -547,8 +545,7 @@ c_strlist_t *csync_statedb_query(sqlite3 *db, CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Busy counter has reached its maximum. Aborting this sql statement"); break; } - /* sleep 100 msec */ - usleep(100000); + csync_sleep(100); CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "sqlite3_step: BUSY counter: %zu", busy_count); continue; } diff --git a/csync/src/csync_time.c b/csync/src/csync_time.c index 48e33c190..85bdd5ff4 100644 --- a/csync/src/csync_time.c +++ b/csync/src/csync_time.c @@ -31,6 +31,11 @@ #include "csync_time.h" #include "vio/csync_vio.h" +#ifndef _WIN32 +#include +#include +#endif + #define CSYNC_LOG_CATEGORY_NAME "csync.time" #include "csync_log.h" @@ -45,7 +50,13 @@ int csync_gettime(struct timespec *tp) { -#ifdef HAVE_CLOCK_GETTIME +#if defined(_WIN32) + __int64 wintime; + GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -= 116444736000000000ll; //1jan1601 to 1jan1970 + tp->tv_sec = wintime / 10000000ll; //seconds + tp->tv_nsec = wintime % 10000000ll * 100; //nano-seconds +#elif defined(HAVE_CLOCK_GETTIME) return clock_gettime(CSYNC_CLOCK, tp); #else struct timeval tv; @@ -62,4 +73,11 @@ int csync_gettime(struct timespec *tp) #undef CSYNC_CLOCK -/* vim: set ts=8 sw=2 et cindent: */ +void csync_sleep(unsigned int msecs) +{ +#if defined(_WIN32) + Sleep(msecs); +#else + usleep(msecs * 1000); +#endif +} diff --git a/csync/src/csync_time.h b/csync/src/csync_time.h index fe91baba5..1492bef8d 100644 --- a/csync/src/csync_time.h +++ b/csync/src/csync_time.h @@ -26,5 +26,6 @@ #include "csync_private.h" int csync_gettime(struct timespec *tp); +void csync_sleep(unsigned int msecs); #endif /* _CSYNC_TIME_H */ diff --git a/csync/src/csync_util.h b/csync/src/csync_util.h index f8d02df7e..f65ada592 100644 --- a/csync/src/csync_util.h +++ b/csync/src/csync_util.h @@ -26,9 +26,9 @@ #include "csync_private.h" -const char *csync_instruction_str(enum csync_instructions_e instr); +const char OCSYNC_EXPORT *csync_instruction_str(enum csync_instructions_e instr); -void csync_memstat_check(void); +void OCSYNC_EXPORT csync_memstat_check(void); -bool csync_file_locked_or_open( const char *dir, const char *fname); +bool OCSYNC_EXPORT csync_file_locked_or_open( const char *dir, const char *fname); #endif /* _CSYNC_UTIL_H */ diff --git a/csync/src/std/CMakeLists.txt b/csync/src/std/CMakeLists.txt index 88456f354..91b8843a8 100644 --- a/csync/src/std/CMakeLists.txt +++ b/csync/src/std/CMakeLists.txt @@ -26,6 +26,12 @@ set(cstdlib_SRCS c_time.c ) +if(NOT HAVE_ASPRINTF AND NOT HAVE___MINGW_ASPRINTF) + list(APPEND cstdlib_SRCS + asprintf.c + ) +endif() + include_directories( ${CSTDLIB_PUBLIC_INCLUDE_DIRS} ${CSTDLIB_PRIVATE_INCLUDE_DIRS} diff --git a/csync/src/std/asprintf.c b/csync/src/std/asprintf.c new file mode 100644 index 000000000..8738df973 --- /dev/null +++ b/csync/src/std/asprintf.c @@ -0,0 +1,90 @@ +/* + https://raw.githubusercontent.com/littlstar/asprintf.c/20ce5207a4ecb24017b5a17e6cd7d006e3047146/asprintf.c + + The MIT License (MIT) + + Copyright (c) 2014 Little Star Media, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * `asprintf.c' - asprintf + * + * copyright (c) 2014 joseph werle + */ + +#ifndef HAVE_ASPRINTF + +#include +#include +#include + +#include "asprintf.h" + +int +asprintf (char **str, const char *fmt, ...) { + int size = 0; + va_list args; + + // init variadic argumens + va_start(args, fmt); + + // format and get size + size = vasprintf(str, fmt, args); + + // toss args + va_end(args); + + return size; +} + +int +vasprintf (char **str, const char *fmt, va_list args) { + int size = 0; + va_list tmpa; + + // copy + va_copy(tmpa, args); + + // apply variadic arguments to + // sprintf with format to get size + size = vsnprintf(NULL, size, fmt, tmpa); + + // toss args + va_end(tmpa); + + // return -1 to be compliant if + // size is less than 0 + if (size < 0) { return -1; } + + // alloc with size plus 1 for `\0' + *str = (char *) malloc(size + 1); + + // return -1 to be compliant + // if pointer is `NULL' + if (NULL == *str) { return -1; } + + // format string with original + // variadic arguments and set new size + size = vsprintf(*str, fmt, args); + return size; +} + +#endif diff --git a/csync/src/std/asprintf.h b/csync/src/std/asprintf.h new file mode 100644 index 000000000..d6dd2e859 --- /dev/null +++ b/csync/src/std/asprintf.h @@ -0,0 +1,60 @@ +/* + https://raw.githubusercontent.com/littlstar/asprintf.c/20ce5207a4ecb24017b5a17e6cd7d006e3047146/asprintf.h + + The MIT License (MIT) + + Copyright (c) 2014 Little Star Media, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/** + * `asprintf.h' - asprintf.c + * + * copyright (c) 2014 joseph werle + */ + +#ifndef HAVE_ASPRINTF +#ifndef ASPRINTF_H +#define ASPRINTF_H 1 + +#include + +/** + * Sets `char **' pointer to be a buffer + * large enough to hold the formatted string + * accepting a `va_list' args of variadic + * arguments. + */ + +int +vasprintf (char **, const char *, va_list); + +/** + * Sets `char **' pointer to be a buffer + * large enough to hold the formatted + * string accepting `n' arguments of + * variadic arguments. + */ + +int +asprintf (char **, const char *, ...); + +#endif +#endif diff --git a/csync/src/std/c_private.h b/csync/src/std/c_private.h index a761506c5..09c1ea36b 100644 --- a/csync/src/std/c_private.h +++ b/csync/src/std/c_private.h @@ -31,14 +31,17 @@ #include #ifdef _WIN32 +#include #include #include #include +#else +#include #endif #include -#ifdef _WIN32 +#ifdef __MINGW32__ #define EDQUOT 0 #define ENODATA 0 #ifndef S_IRGRP @@ -65,6 +68,8 @@ #define nlink_t int #define getuid() 0 #define geteuid() 0 +#elif defined(_WIN32) +#define mode_t int #else #include #endif @@ -89,8 +94,12 @@ typedef struct stat csync_stat_t; #define ENODATA EBADF #endif -#if !defined(HAVE_ASPRINTF) && defined(HAVE___MINGW_ASPRINTF) +#if !defined(HAVE_ASPRINTF) +#if defined(HAVE___MINGW_ASPRINTF) #define asprintf __mingw_asprintf +#else +#include "asprintf.h" +#endif #endif #ifndef HAVE_STRERROR_R diff --git a/csync/src/std/c_time.c b/csync/src/std/c_time.c index 561cd4763..ad43fed02 100644 --- a/csync/src/std/c_time.c +++ b/csync/src/std/c_time.c @@ -25,6 +25,10 @@ #include "c_path.h" #include "c_time.h" +#ifndef _WIN32 +#include +#endif + struct timespec c_tspecdiff(struct timespec time1, struct timespec time0) { struct timespec ret; int xsec = 0; diff --git a/csync/src/std/c_time.h b/csync/src/std/c_time.h index a5718c1c9..aa8ef2f16 100644 --- a/csync/src/std/c_time.h +++ b/csync/src/std/c_time.h @@ -22,7 +22,6 @@ #define _C_TIME_H #include -#include /** * @brief Calculate time difference diff --git a/csync/src/vio/csync_vio_local.h b/csync/src/vio/csync_vio_local.h index dcd12ad6f..294383121 100644 --- a/csync/src/vio/csync_vio_local.h +++ b/csync/src/vio/csync_vio_local.h @@ -21,12 +21,10 @@ #ifndef _CSYNC_VIO_LOCAL_H #define _CSYNC_VIO_LOCAL_H -#include +csync_vio_handle_t OCSYNC_EXPORT *csync_vio_local_opendir(const char *name); +int OCSYNC_EXPORT csync_vio_local_closedir(csync_vio_handle_t *dhandle); +csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_local_readdir(csync_vio_handle_t *dhandle); -csync_vio_handle_t *csync_vio_local_opendir(const char *name); -int csync_vio_local_closedir(csync_vio_handle_t *dhandle); -csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle); - -int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf); +int OCSYNC_EXPORT csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf); #endif /* _CSYNC_VIO_LOCAL_H */ diff --git a/csync/src/vio/csync_vio_local_win.c b/csync/src/vio/csync_vio_local_win.c index b50d0ecf6..fc4eea512 100644 --- a/csync/src/vio/csync_vio_local_win.c +++ b/csync/src/vio/csync_vio_local_win.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include "windows.h" diff --git a/csync/tests/csync_tests/check_csync_exclude.c b/csync/tests/csync_tests/check_csync_exclude.c index 67b3fcb03..b788c1c3c 100644 --- a/csync/tests/csync_tests/check_csync_exclude.c +++ b/csync/tests/csync_tests/check_csync_exclude.c @@ -20,6 +20,7 @@ #include "config_csync.h" #include #include +#include #include "torture.h" diff --git a/csync/tests/csync_tests/check_csync_log.c b/csync/tests/csync_tests/check_csync_log.c index 61fb3aae2..a888447e3 100644 --- a/csync/tests/csync_tests/check_csync_log.c +++ b/csync/tests/csync_tests/check_csync_log.c @@ -19,7 +19,6 @@ */ #include #include -#include #include "torture.h" diff --git a/csync/tests/csync_tests/check_csync_statedb_load.c b/csync/tests/csync_tests/check_csync_statedb_load.c index 2b4a6bf93..c18c5a47e 100644 --- a/csync/tests/csync_tests/check_csync_statedb_load.c +++ b/csync/tests/csync_tests/check_csync_statedb_load.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include -#include #include "torture.h" diff --git a/csync/tests/std_tests/check_std_c_time.c b/csync/tests/std_tests/check_std_c_time.c index 01580083b..df1abbe05 100644 --- a/csync/tests/std_tests/check_std_c_time.c +++ b/csync/tests/std_tests/check_std_c_time.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include -#include #include "torture.h" diff --git a/csync/tests/vio_tests/check_vio.c b/csync/tests/vio_tests/check_vio.c index 745e5f3b1..e8d716f40 100644 --- a/csync/tests/vio_tests/check_vio.c +++ b/csync/tests/vio_tests/check_vio.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "torture.h" diff --git a/csync/tests/vio_tests/check_vio_ext.c b/csync/tests/vio_tests/check_vio_ext.c index 7d6663aad..5642d76fc 100644 --- a/csync/tests/vio_tests/check_vio_ext.c +++ b/csync/tests/vio_tests/check_vio_ext.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "torture.h" diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index fcfea2c7e..60f2aa5e0 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -41,6 +41,7 @@ #include #else #include +#include #endif using namespace OCC; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 5fc319b6f..af4c98ff9 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -70,9 +70,9 @@ set(client_SRCS activityitemdelegate.cpp selectivesyncdialog.cpp settingsdialog.cpp - share.cpp sharedialog.cpp sharelinkwidget.cpp + sharemanager.cpp shareusergroupwidget.cpp sharee.cpp socketapi.cpp diff --git a/src/gui/ocssharejob.h b/src/gui/ocssharejob.h index ebf1885e8..29c8184fe 100644 --- a/src/gui/ocssharejob.h +++ b/src/gui/ocssharejob.h @@ -15,7 +15,7 @@ #define OCSSHAREJOB_H #include "ocsjob.h" -#include "share.h" +#include "sharemanager.h" #include #include #include diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp index ba93eb5d9..343565b3b 100644 --- a/src/gui/sharelinkwidget.cpp +++ b/src/gui/sharelinkwidget.cpp @@ -17,7 +17,7 @@ #include "account.h" #include "capabilities.h" -#include "share.h" +#include "sharemanager.h" #include "QProgressIndicator.h" #include diff --git a/src/gui/share.cpp b/src/gui/sharemanager.cpp similarity index 98% rename from src/gui/share.cpp rename to src/gui/sharemanager.cpp index e3c659489..c407b159f 100644 --- a/src/gui/share.cpp +++ b/src/gui/sharemanager.cpp @@ -11,7 +11,7 @@ * for more details. */ -#include "share.h" +#include "sharemanager.h" #include "ocssharejob.h" #include "account.h" @@ -30,9 +30,9 @@ Q_DECLARE_METATYPE(CreateShare) namespace OCC { -Share::Share(AccountPtr account, - const QString& id, - const QString& path, +Share::Share(AccountPtr account, + const QString& id, + const QString& path, const ShareType shareType, const Permissions permissions, const QSharedPointer shareWith) @@ -100,7 +100,7 @@ void Share::slotDeleted() void Share::slotOcsError(int statusCode, const QString &message) { - emit serverError(statusCode, message); + emit serverError(statusCode, message); } QUrl LinkShare::getLink() const @@ -229,7 +229,7 @@ void ShareManager::slotLinkShareCreated(const QVariantMap &reply) if (code == 403) { emit linkShareRequiresPassword(message); return; - } + } //Parse share auto data = reply.value("ocs").toMap().value("data").toMap(); @@ -329,7 +329,7 @@ void ShareManager::slotSharesFetched(const QVariantMap &reply) newShare = parseShare(data); } - shares.append(QSharedPointer(newShare)); + shares.append(QSharedPointer(newShare)); } qDebug() << Q_FUNC_INFO << "Sending " << shares.count() << "shares"; @@ -371,7 +371,7 @@ QSharedPointer ShareManager::parseShare(const QVariantMap &data) QSharedPointer sharee(new Sharee(data.value("share_with").toString(), data.value("share_with_displayname").toString(), (Sharee::Type)data.value("share_type").toInt())); - + return QSharedPointer(new Share(_account, data.value("id").toString(), data.value("path").toString(), diff --git a/src/gui/share.h b/src/gui/sharemanager.h similarity index 99% rename from src/gui/share.h rename to src/gui/sharemanager.h index e022624b4..8c248c686 100644 --- a/src/gui/share.h +++ b/src/gui/sharemanager.h @@ -11,8 +11,8 @@ * for more details. */ -#ifndef SHARE_H -#define SHARE_H +#ifndef SHAREMANAGER_H +#define SHAREMANAGER_H #include "accountfwd.h" #include "sharee.h" @@ -127,7 +127,7 @@ private slots: class LinkShare : public Share { Q_OBJECT public: - + explicit LinkShare(AccountPtr account, const QString& id, const QString& path, @@ -154,7 +154,7 @@ public: * In case of a server error the serverError signal is emitted. */ void setPublicUpload(bool publicUpload); - + /* * Set the password * @@ -276,7 +276,6 @@ private: AccountPtr _account; }; - } -#endif // SHARE_H +#endif // SHAREMANAGER_H diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index b72de8ccc..546a796d6 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -24,8 +24,8 @@ #include "capabilities.h" #include "thumbnailjob.h" -#include "share.h" #include "sharee.h" +#include "sharemanager.h" #include "QProgressIndicator.h" #include diff --git a/src/libsync/CMakeLists.txt b/src/libsync/CMakeLists.txt index 450f73f2a..abfb2cfd9 100644 --- a/src/libsync/CMakeLists.txt +++ b/src/libsync/CMakeLists.txt @@ -1,6 +1,5 @@ project(libsync) set(CMAKE_AUTOMOC TRUE) -include(GenerateExportHeader) configure_file( version.h.in "${CMAKE_CURRENT_BINARY_DIR}/version.h" ) diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 2dd6b51dd..488d04f7b 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -29,10 +29,11 @@ #endif #ifdef Q_OS_WIN +#include #include #include #include - +#include #endif // We use some internals of csync: diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 2b46ff781..83bd15b5a 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef Q_OS_UNIX +#include +#endif + namespace OCC { // Always coming in with forward slashes. diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index b6929db91..76b2855a2 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -18,8 +18,7 @@ static const QUrl sRootUrl("owncloud://somehost/owncloud/remote.php/webdav/"); -namespace { -QString generateEtag() { +static QString generateEtag() { return QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch(), 16); } @@ -35,7 +34,6 @@ public: QString pathRoot() const { return first(); } QString fileName() const { return last(); } }; -} class FileModifier {