csync: Remove iconv depedency
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 3 Jul 2017 14:15:42 +0000 (16:15 +0200)
committerOlivier Goffart <olivier@woboq.com>
Thu, 13 Jul 2017 08:01:17 +0000 (10:01 +0200)
We use iconv to normalize the string on mac. But the iconv version
on mac does not support full unicode.
So we will use Qt to normalize the string

12 files changed:
cmake/modules/FindIconv.cmake [deleted file]
csync/CMakeLists.txt
csync/DefineOptions.cmake
csync/config_csync.h.cmake
csync/src/CMakeLists.txt
csync/src/csync.c
csync/src/csync.h
csync/src/csync_private.h
csync/src/std/CMakeLists.txt
csync/src/std/c_private.h
csync/src/std/c_string.c
csync/src/std/c_string.h

diff --git a/cmake/modules/FindIconv.cmake b/cmake/modules/FindIconv.cmake
deleted file mode 100644 (file)
index 46d99f0..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-# - Try to find Iconv
-# Once done this will define
-#
-#  ICONV_FOUND - system has Iconv
-#  ICONV_INCLUDE_DIRS - the Iconv include directory
-#  ICONV_LIBRARIES - Link these to use Iconv
-#  ICONV_DEFINITIONS - Compiler switches required for using Iconv
-#
-#  Copyright (c) 2013 Andreas Schneider <asn@cryptomilk.org>
-#
-#  Redistribution and use is allowed according to the terms of the New
-#  BSD license.
-#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-#
-
-include(CheckIncludeFile)
-include(CheckFunctionExists)
-include(CheckLibraryExists)
-include(CheckPrototypeDefinition)
-
-find_path(ICONV_INCLUDE_DIR
-    NAMES
-        iconv.h sys/iconv.h
-)
-
-set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
-check_include_file(iconv.h HAVE_ICONV_H)
-check_include_file(sys/iconv.h HAVE_SYS_ICONV_H)
-set(CMAKE_REQUIRED_INCLUDES)
-
-find_library(ICONV_LIBRARY
-    NAMES
-        iconv
-        libiconv
-    PATHS
-)
-
-if (ICONV_LIBRARY)
-    get_filename_component(_ICONV_NAME ${ICONV_LIBRARY} NAME)
-    get_filename_component(_ICONV_PATH ${ICONV_LIBRARY} PATH)
-    check_library_exists(${_ICONV_NAME} iconv ${_ICONV_PATH} HAVE_ICONV)
-else()
-    check_function_exists(iconv HAVE_ICONV)
-endif()
-
-if (HAVE_ICONV_H OR HAVE_SYS_ICONV_H)
-    if (HAVE_ICONV_H)
-        set(_ICONV_PROTO_INCLUDE "iconv.h")
-    endif (HAVE_ICONV_H)
-    if (HAVE_SYS_ICONV_H)
-        set(_ICONV_PROTO_INCLUDE "sys/iconv.h")
-    endif (HAVE_SYS_ICONV_H)
-
-    set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
-    check_prototype_definition(iconv
-        "size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)"
-        "-1"
-        ${_ICONV_PROTO_INCLUDE}
-        HAVE_ICONV_CONST)
-    set(CMAKE_REQUIRED_INCLUDES)
-endif (HAVE_ICONV_H OR HAVE_SYS_ICONV_H)
-
-set(ICONV_INCLUDE_DIRS
-    ${ICONV_INCLUDE_DIR}
-)
-
-if (ICONV_LIBRARY)
-    set(ICONV_LIBRARIES
-        ${ICONV_LIBRARIES}
-        ${ICONV_LIBRARY}
-    )
-endif (ICONV_LIBRARY)
-
-include(FindPackageHandleStandardArgs)
-if (ICONV_LIBRARIES)
-    find_package_handle_standard_args(Iconv DEFAULT_MSG ICONV_LIBRARIES ICONV_INCLUDE_DIRS)
-else()
-    find_package_handle_standard_args(Iconv DEFAULT_MSG ICONV_INCLUDE_DIRS)
-endif()
-
-# show the ICONV_INCLUDE_DIRS and ICONV_LIBRARIES variables only in the advanced view
-mark_as_advanced(ICONV_INCLUDE_DIRS ICONV_LIBRARIES)
index 2d4b94f2aa6bf35db923708c869323d41076384e..d5be43a29a4627abf46654bd472057eb0e5f8b74 100644 (file)
@@ -18,10 +18,6 @@ include(DefineInstallationPaths)
 include(MacroAddPlugin)
 include(MacroCopyFile)
 
-if (NOT WIN32)
-    find_package(Iconv)
-endif (NOT WIN32)
-
 find_package(SQLite3 3.8.0 REQUIRED)
 
 include(ConfigureChecks.cmake)
index 9ba14800d435ed3fcd1a71ed0fada8c3d61d7523..485e183221cbdff564d8aa974799dec8fa467a3c 100644 (file)
@@ -1,5 +1,2 @@
-if ( NOT WIN32 )
-    option(WITH_ICONV "Build csync with iconv support" ON)
-endif()
 option(UNIT_TESTING "Build with unit tests" OFF)
 option(MEM_NULL_TESTS "Enable NULL memory testing" OFF)
index 155329bbd753199117e83a27d78833bc336679b5..f5c9f09b2fca991fbf8ac10f841834362012e5c9 100644 (file)
@@ -9,19 +9,14 @@
 #cmakedefine HAVE_CLOCK_GETTIME
 
 #cmakedefine WITH_LOG4C 1
-#cmakedefine WITH_ICONV 1
 
 #cmakedefine HAVE_ARGP_H 1
-#cmakedefine HAVE_ICONV_H 1
-#cmakedefine HAVE_SYS_ICONV_H 1
 
 #cmakedefine HAVE_TIMEGM 1
 #cmakedefine HAVE_STRERROR_R 1
 #cmakedefine HAVE_UTIMES 1
 #cmakedefine HAVE_LSTAT 1
 #cmakedefine HAVE_FNMATCH 1
-#cmakedefine HAVE_ICONV 1
-#cmakedefine HAVE_ICONV_CONST 1
 
 #cmakedefine HAVE___MINGW_ASPRINTF 1
 #cmakedefine HAVE_ASPRINTF 1
index cb07377e90e5cbaea18f66123179d3c67869dfc8..8bce5f418de133ffa41f22cb87f343c3f47eade2 100644 (file)
@@ -28,11 +28,6 @@ set(CSYNC_LINK_LIBRARIES
   ${SQLITE3_LIBRARIES}
 )
 
-if(HAVE_ICONV AND WITH_ICONV)
-    list(APPEND CSYNC_PRIVATE_INCLUDE_DIRS ${ICONV_INCLUDE_DIR})
-    list(APPEND CSYNC_LINK_LIBRARIES ${ICONV_LIBRARIES})
-endif()
-
 # Specific option for builds tied to servers that do not support renaming extensions
 set(NO_RENAME_EXTENSION 0 CACHE BOOL "Do not issue rename if the extension changes")
 if(NO_RENAME_EXTENSION)
index 9af6f0fcf8762af0c6d30408a11621b195f46b61..1f75ac3bdb40491135590c4fe0920c94d22e029a 100644 (file)
 #include <sys/types.h>
 #include <stdbool.h>
 
-#ifdef HAVE_ICONV_H
-#include <iconv.h>
-#endif
-#ifdef HAVE_SYS_ICONV_H
-#include <sys/iconv.h>
-#endif
-
 #include "c_lib.h"
 #include "csync_private.h"
 #include "csync_exclude.h"
@@ -569,10 +562,6 @@ int csync_destroy(CSYNC *ctx) {
   SAFE_FREE(ctx->local.uri);
   SAFE_FREE(ctx->error_string);
 
-#ifdef WITH_ICONV
-  c_close_iconv();
-#endif
-
   SAFE_FREE(ctx);
 
   return rc;
@@ -626,19 +615,6 @@ const char *csync_get_status_string(CSYNC *ctx)
   return csync_vio_get_status_string(ctx);
 }
 
-#ifdef WITH_ICONV
-int csync_set_iconv_codec(const char *from)
-{
-  c_close_iconv();
-
-  if (from != NULL) {
-    c_setup_iconv(from);
-  }
-
-  return 0;
-}
-#endif
-
 void csync_request_abort(CSYNC *ctx)
 {
   if (ctx != NULL) {
index 949c9efd237e6a80fe4ca710802cdffc035d1b06..b35d4601c17b21983ebab0d3b50e4cc0b94ddc67 100644 (file)
@@ -479,17 +479,6 @@ int OCSYNC_EXPORT csync_walk_remote_tree(CSYNC *ctx, csync_treewalk_visit_func *
  */
 const char OCSYNC_EXPORT *csync_get_status_string(CSYNC *ctx);
 
-#ifdef WITH_ICONV
-/**
- * @brief Set iconv source codec for filenames.
- *
- * @param from          Source codec.
- *
- * @return              0 on success, or an iconv error number.
- */
-int OCSYNC_EXPORT csync_set_iconv_codec(const char *from);
-#endif
-
 /**
  * @brief Aborts the current sync run as soon as possible. Can be called from another thread.
  *
index 11775f345db8971841d5f5bf3a48de3c7699ab01..2edc26019d4a5c817eeff4ca9f34c453ded7d5cd 100644 (file)
 #include "csync.h"
 #include "csync_misc.h"
 
-#ifdef WITH_ICONV
-#include <iconv.h>
-#endif
-
-#ifdef HAVE_ICONV_H
-#include <iconv.h>
-#endif
-#ifdef HAVE_SYS_ICONV_H
-#include <sys/iconv.h>
-#endif
-
 #include "csync_macros.h"
 
 /**
@@ -130,12 +119,6 @@ struct csync_s {
   } remote;
 
 
-#if defined(HAVE_ICONV) && defined(WITH_ICONV)
-  struct {
-    iconv_t iconv_cd;
-  } options;
-#endif
-
   /* replica we are currently walking */
   enum csync_replica_e current;
 
index 91b8843a85a5c1391de402c01b63f11bb7d76927..39b1fd550c5a40d067ca1e0f8ae3cd11cbbafdba 100644 (file)
@@ -5,10 +5,6 @@ set(CSTDLIB_PUBLIC_INCLUDE_DIRS
   CACHE INTERNAL "cstdlib public include directories"
 )
 
-set(CSTDLIB_PRIVATE_INCLUDE_DIRS
-  ${ICONV_INCLUDE_DIR}
-)
-
 set(CSTDLIB_LIBRARY
   cstdlib
   CACHE INTERNAL "cstdlib library"
@@ -34,7 +30,6 @@ endif()
 
 include_directories(
   ${CSTDLIB_PUBLIC_INCLUDE_DIRS}
-  ${CSTDLIB_PRIVATE_INCLUDE_DIRS}
 )
 
 add_library(${CSTDLIB_LIBRARY} STATIC ${cstdlib_SRCS})
index 09c1ea36b60520dbeb8e508adff49ee6d9ac5cb4..26bba70db547a57d07b0a51616fa844a97303690 100644 (file)
@@ -159,13 +159,6 @@ typedef char           mbchar_t;
 #define _tgetcwd       getcwd
 #endif
 
-#ifdef WITH_ICONV
-/** @internal */
-int c_setup_iconv(const char* to);
-/** @internal */
-int c_close_iconv(void);
-#endif
-
 /* FIXME: Implement TLS for OS X */
 #if defined(__GNUC__) && !defined(__APPLE__)
 # define CSYNC_THREAD __thread
index e21d4374e9453487db8cbf20e71b470831ed97fd..6bf2d77232df08bd8c50970160e96f9d29299d80 100644 (file)
 #include <windows.h>
 #endif
 
-#if defined(HAVE_ICONV) && defined(WITH_ICONV)
-# ifdef HAVE_ICONV_H
-#  include <iconv.h>
-# endif
-# ifdef HAVE_SYS_ICONV_H
-#  include <sys/iconv.h>
-# endif
-
-typedef struct {
-  iconv_t to;
-  iconv_t from;
-} iconv_conversions;
-
-CSYNC_THREAD iconv_conversions _iconvs = { NULL, NULL };
-
-int c_setup_iconv(const char* to) {
-  _iconvs.to = iconv_open(to, "UTF-8");
-  _iconvs.from = iconv_open("UTF-8", to);
-
-  if (_iconvs.to == (iconv_t)-1 || _iconvs.from == (iconv_t)-1)
-    return -1;
-
-  return 0;
-}
-
-int c_close_iconv() {
-    int ret_to = 0;
-    int ret_from = 0;
-    if( _iconvs.to != (iconv_t) NULL ) {
-        ret_to = iconv_close(_iconvs.to);
-    }
-    if( _iconvs.from != (iconv_t) NULL ) {
-        ret_from = iconv_close(_iconvs.from);
-    }
-
-  if (ret_to == -1 || ret_from == -1)
-    return -1;
-
-  _iconvs.to = (iconv_t) 0;
-  _iconvs.from = (iconv_t) 0;
-
-  return 0;
-}
-
-enum iconv_direction { iconv_from_native, iconv_to_native };
-
-static char *c_iconv(const char* str, enum iconv_direction dir)
-{
-#ifdef HAVE_ICONV_CONST
-    const char *in = str;
-#else
-    char *in = discard_const(str);
-#endif
-  size_t size;
-  size_t outsize;
-  char *out;
-  char *out_in;
-  size_t ret;
-
-  if (str == NULL) {
-    return NULL;
-  }
-
-  if(_iconvs.from == NULL && _iconvs.to == NULL) {
-#ifdef __APPLE__
-    c_setup_iconv("UTF-8-MAC");
-#else
-    return c_strdup(str);
-#endif
-  }
-
-  size = strlen(in);
-  outsize = size*2;
-  out = c_malloc(outsize);
-  out_in = out;
-
-  if (dir == iconv_to_native) {
-      ret = iconv(_iconvs.to, &in, &size, &out, &outsize);
-  } else {
-      ret = iconv(_iconvs.from, &in, &size, &out, &outsize);
-  }
-
-  if (ret == (size_t)-1) {
-      SAFE_FREE(out_in);
-      return NULL;
-  }
-
-  return out_in;
-}
-#endif /* defined(HAVE_ICONV) && defined(WITH_ICONV) */
-
 int c_strncasecmp(const char *a, const char *b, size_t n) {
 #ifdef _WIN32
     return _strnicmp(a, b, n);
@@ -285,11 +194,7 @@ char* c_utf8_from_locale(const mbchar_t *wstr)
     dst = mdst;
   }
 #else
-#ifdef WITH_ICONV
-  dst = c_iconv(wstr, iconv_from_native);
-#else
-  dst = (char*) wstr;
-#endif
+  dst = c_strdup(wstr);
 #endif
   return dst;
 }
@@ -317,11 +222,7 @@ mbchar_t* c_utf8_string_to_locale(const char *str)
         MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed);
     }
 #else
-#ifdef WITH_ICONV
-    dst = c_iconv(str, iconv_to_native);
-#else
-    dst = (_TCHAR*) str;
-#endif
+    dst = c_strdup(str);
 #endif
     return dst;
 }
index 60bc010da4b25ce104ec10286faa11e9d458ed43..304c598a23f002dbfac2e592129edff1fa6961cd 100644 (file)
@@ -194,8 +194,6 @@ void c_strlist_destroy(c_strlist_t *strlist);
  */
 mbchar_t* c_utf8_string_to_locale(const char *wstr);
 
-#if defined(_WIN32) || defined(WITH_ICONV)
-
 /**
  * @brief Free buffer malloced by c_utf8_from_locale or c_utf8_to_locale().
  *
@@ -214,9 +212,7 @@ mbchar_t* c_utf8_string_to_locale(const char *wstr);
  *
  */
 #define c_free_locale_string(x) SAFE_FREE(x)
-#else
-#define c_free_locale_string(x) (void)x
-#endif
+
 
 /**
  * }@