[Pkg-owncloud-commits] [owncloud-client] 272/498: Created two functions c_utf8_string_to_locale and c_utf8_path_to_locale.

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:57 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit d9b44b3a69aae40092cb6ca206c4298cf4fcf5d4
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jul 3 11:45:58 2015 +0200

    Created two functions c_utf8_string_to_locale and c_utf8_path_to_locale.
    
    Before we only had c_utf8_to_locale, but now functionality is needed to
    convert a path to UNC before converting it. That does c_utf8_path_to_locale
    now, while c_utf8_string_to_locale only converts the plain string, ie.
    to generate wide char strings for output.
---
 csync/src/csync_exclude.c                          |  2 +-
 csync/src/csync_misc.c                             |  6 +--
 csync/src/std/c_path.c                             | 17 +++++++++
 csync/src/std/c_path.h                             | 18 ++++++++-
 csync/src/std/c_string.c                           | 43 +++++++++-------------
 csync/src/std/c_string.h                           |  9 ++---
 csync/src/std/c_time.c                             |  6 +--
 csync/src/vio/csync_vio_local.c                    |  8 ++--
 csync/tests/csync_tests/check_csync_log.c          |  2 +-
 csync/tests/csync_tests/check_csync_statedb_load.c |  2 +-
 csync/tests/encoding_tests/check_encoding.c        |  6 +--
 csync/tests/vio_tests/check_vio.c                  |  4 +-
 csync/tests/vio_tests/check_vio_ext.c              |  6 +--
 13 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index b276f93..7a29e37 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -81,7 +81,7 @@ int csync_exclude_load(const char *fname, c_strlist_t **list) {
   _fmode = _O_BINARY;
 #endif
 
-  w_fname = c_utf8_to_locale(fname);
+  w_fname = c_utf8_path_to_locale(fname);
   if (w_fname == NULL) {
       return -1;
   }
diff --git a/csync/src/csync_misc.c b/csync/src/csync_misc.c
index 5a2100c..1c09d85 100644
--- a/csync/src/csync_misc.c
+++ b/csync/src/csync_misc.c
@@ -64,10 +64,10 @@ int csync_fnmatch(__const char *__pattern, __const char *__name, int __flags) {
 
     (void) __flags;
 
-    name = c_utf8_to_locale(__name);
-    pat = c_utf8_to_locale(__pattern);
+    name = c_utf8_path_to_locale(__name);
+    pat = c_utf8_string_to_locale(__pattern);
 
-    match = PathMatchSpec(name, pat);
+    match = PathMatchSpecW(name, pat);
 
     c_free_locale_string(pat);
     c_free_locale_string(name);
diff --git a/csync/src/std/c_path.c b/csync/src/std/c_path.c
index 6fe36b4..5bdb879 100644
--- a/csync/src/std/c_path.c
+++ b/csync/src/std/c_path.c
@@ -32,6 +32,7 @@
 #include "c_private.h"
 #include "c_alloc.h"
 #include "c_path.h"
+#include "c_string.h"
 
 /*
  * dirname - parse directory component.
@@ -434,3 +435,19 @@ int c_parse_uri(const char *uri,
      }
      return longStr;
  }
+
+ mbchar_t* c_utf8_path_to_locale(const char *str)
+ {
+     if( str == NULL ) {
+         return NULL;
+     } else {
+ #ifdef _WIN32
+         const char *unc_str = c_path_to_UNC(str);
+         mbchar_t *dst = c_utf8_string_to_locale(unc_str);
+         SAFE_FREE(unc_str);
+         return dst;
+ #else
+         return c_utf8_string_to_locale(str);
+ #endif
+     }
+ }
diff --git a/csync/src/std/c_path.h b/csync/src/std/c_path.h
index 00a3f64..42f30a5 100644
--- a/csync/src/std/c_path.h
+++ b/csync/src/std/c_path.h
@@ -33,6 +33,7 @@
 #define _C_PATH_H
 
 #include "c_macro.h"
+#include "c_private.h"
 
 /**
  * @brief Parse directory component.
@@ -96,9 +97,9 @@ int c_parse_uri(const char *uri, char **scheme, char **user, char **passwd,
  * @param directory '\0' terminated path including the final '/'
  *
  * @param filename '\0' terminated string
- * 
+ *
  * @param extension '\0' terminated string
- * 
+ *
  */
 typedef struct
 {
@@ -122,6 +123,19 @@ typedef struct
 const char *c_path_to_UNC(const char *str);
 
 /**
+ * @brief c_utf8_path_to_locale converts a unixoid path to the locale aware format
+ *
+ * On windows, it converts to UNC and multibyte.
+ * On Mac, it converts to the correct utf8 using iconv.
+ * On Linux, it returns utf8
+ *
+ * @param str The path to convert
+ *
+ * @return a pointer to the converted string. Caller has to free it.
+ */
+mbchar_t* c_utf8_path_to_locale(const char *str);
+
+/**
  * }@
  */
 #endif /* _C_PATH_H */
diff --git a/csync/src/std/c_string.c b/csync/src/std/c_string.c
index 0da268c..e248f6c 100644
--- a/csync/src/std/c_string.c
+++ b/csync/src/std/c_string.c
@@ -276,40 +276,33 @@ char* c_utf8_from_locale(const mbchar_t *wstr)
 }
 
 /* Convert a an UTF8 string to multibyte */
-mbchar_t* c_utf8_to_locale(const char *str)
+mbchar_t* c_utf8_string_to_locale(const char *str)
 {
-  mbchar_t *dst = NULL;
+    mbchar_t *dst = NULL;
 #ifdef _WIN32
-  size_t len = 0;
-  int size_needed = 0;
-  const char *longStr = NULL;
+    size_t len;
+    int size_needed;
 #endif
 
-  if (str == NULL ) {
-    return NULL;
-  }
+    if (str == NULL ) {
+        return NULL;
+    }
 
 #ifdef _WIN32
-  longStr = c_path_to_UNC(str);
-  if( longStr ) {
-      len = strlen(longStr);
-
-      size_needed = MultiByteToWideChar(CP_UTF8, 0, longStr, len, NULL, 0);
-      if (size_needed > 0) {
-          int size_char = (size_needed + 1) * sizeof(mbchar_t);
-          dst = c_malloc(size_char);
-          memset((void*)dst, 0, size_char);
-          MultiByteToWideChar(CP_UTF8, 0, longStr, -1, dst, size_needed);
-      }
-
-      SAFE_FREE(longStr);
-  }
+    len = strlen(str);
+    size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
+    if (size_needed > 0) {
+        int size_char = (size_needed + 1) * sizeof(mbchar_t);
+        dst = c_malloc(size_char);
+        memset((void*)dst, 0, size_char);
+        MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed);
+    }
 #else
 #ifdef WITH_ICONV
-  dst = c_iconv(str, iconv_to_native);
+    dst = c_iconv(str, iconv_to_native);
 #else
-  dst = (_TCHAR*) str;
+    dst = (_TCHAR*) str;
 #endif
 #endif
-  return dst;
+    return dst;
 }
diff --git a/csync/src/std/c_string.h b/csync/src/std/c_string.h
index c9e191c..640cb50 100644
--- a/csync/src/std/c_string.h
+++ b/csync/src/std/c_string.h
@@ -154,9 +154,6 @@ void c_strlist_destroy(c_strlist_t *strlist);
  */
  char*   c_utf8_from_locale(const mbchar_t *str);
 
-
- const char *makeLongWinPath(const char *str, int *mem_reserved);
-
 /**
  * @brief Convert a utf8 encoded string to platform specific locale.
  *
@@ -166,12 +163,14 @@ void c_strlist_destroy(c_strlist_t *strlist);
  * Instead of using the standard file operations the multi platform aliases
  * defined in c_private.h have to be used instead.
  *
- * To convert path names as input for the cross platform functions from the
+ * To convert strings as input for the cross platform functions from the
  * internally used utf8 format, this function has to be used.
  * The returned string has to be freed by c_free_locale_string(). On some
  * platforms this method allocates memory and on others not but it has never
  * sto be cared about.
  *
+ * If the string to convert is a path, consider using c_utf8_path_to_locale().
+ *
  * @param  str     The utf8 string to convert.
  *
  * @return The malloced converted multibyte string or NULL on error.
@@ -180,7 +179,7 @@ void c_strlist_destroy(c_strlist_t *strlist);
  * @see c_utf8_from_locale()
  *
  */
-mbchar_t* c_utf8_to_locale(const char *wstr);
+mbchar_t* c_utf8_string_to_locale(const char *wstr);
 
 #if defined(_WIN32) || defined(WITH_ICONV)
 
diff --git a/csync/src/std/c_time.c b/csync/src/std/c_time.c
index cf57a5e..561cd47 100644
--- a/csync/src/std/c_time.c
+++ b/csync/src/std/c_time.c
@@ -22,7 +22,7 @@
 #include "c_private.h"
 #include "c_string.h"
 
-#include "c_string.h"
+#include "c_path.h"
 #include "c_time.h"
 
 struct timespec c_tspecdiff(struct timespec time1, struct timespec time0) {
@@ -69,7 +69,7 @@ double c_secdiff(struct timespec clock1, struct timespec clock0) {
 
 #ifdef HAVE_UTIMES
 int c_utimes(const char *uri, const struct timeval *times) {
-    mbchar_t *wuri = c_utf8_to_locale(uri);
+    mbchar_t *wuri = c_utf8_path_to_locale(uri);
     int ret = utimes(wuri, times);
     c_free_locale_string(wuri);
     return ret;
@@ -97,7 +97,7 @@ int c_utimes(const char *uri, const struct timeval *times) {
     FILETIME LastModificationTime;
     HANDLE hFile;
 
-    mbchar_t *wuri = c_utf8_to_locale( uri );
+    mbchar_t *wuri = c_utf8_path_to_locale( uri );
 
     if(times) {
         UnixTimevalToFileTime(times[0], &LastAccessTime);
diff --git a/csync/src/vio/csync_vio_local.c b/csync/src/vio/csync_vio_local.c
index 6868256..2465774 100644
--- a/csync/src/vio/csync_vio_local.c
+++ b/csync/src/vio/csync_vio_local.c
@@ -71,7 +71,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
       strcpy( h, name);
       strcat(h, "/*");
 
-      dirname = c_utf8_to_locale(h);
+      dirname = c_utf8_path_to_locale(h);
       SAFE_FREE(h);
   }
 
@@ -89,7 +89,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
   handle->firstFind = 1; // Set a flag that there first fileinfo is available.
   // }
 #else
-  dirname = c_utf8_to_locale(name);
+  dirname = c_utf8_path_to_locale(name);
 
   handle->dh = _topendir( dirname );
   if (handle->dh == NULL) {
@@ -243,7 +243,7 @@ int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
     BY_HANDLE_FILE_INFORMATION fileInfo;
     WIN32_FIND_DATAW FindFileData;
     ULARGE_INTEGER FileIndex;
-    mbchar_t *wuri = c_utf8_to_locale( uri );
+    mbchar_t *wuri = c_utf8_path_to_locale( uri );
 
     h = CreateFileW( wuri, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                      FILE_ATTRIBUTE_NORMAL+FILE_FLAG_BACKUP_SEMANTICS, NULL );
@@ -336,7 +336,7 @@ int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
 int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
   csync_stat_t sb;
 
-  mbchar_t *wuri = c_utf8_to_locale( uri );
+  mbchar_t *wuri = c_utf8_path_to_locale( uri );
 
   if( _tstat(wuri, &sb) < 0) {
     c_free_locale_string(wuri);
diff --git a/csync/tests/csync_tests/check_csync_log.c b/csync/tests/csync_tests/check_csync_log.c
index 65a8ae9..69fa4e4 100644
--- a/csync/tests/csync_tests/check_csync_log.c
+++ b/csync/tests/csync_tests/check_csync_log.c
@@ -119,7 +119,7 @@ static void check_logging(void **state)
     int rc;
     csync_stat_t sb;
     mbchar_t *path;
-    path = c_utf8_to_locale("/tmp/check_csync1/cb_called");
+    path = c_utf8_path_to_locale("/tmp/check_csync1/cb_called");
 
     (void) state; /* unused */
 
diff --git a/csync/tests/csync_tests/check_csync_statedb_load.c b/csync/tests/csync_tests/check_csync_statedb_load.c
index f377abf..e6f9332 100644
--- a/csync/tests/csync_tests/check_csync_statedb_load.c
+++ b/csync/tests/csync_tests/check_csync_statedb_load.c
@@ -80,7 +80,7 @@ static void check_csync_statedb_close(void **state)
     CSYNC *csync = *state;
     csync_stat_t sb;
     time_t modtime;
-    mbchar_t *testdb = c_utf8_to_locale(TESTDB);
+    mbchar_t *testdb = c_utf8_path_to_locale(TESTDB);
     int rc;
 
     /* statedb not written */
diff --git a/csync/tests/encoding_tests/check_encoding.c b/csync/tests/encoding_tests/check_encoding.c
index 2d35c8e..6df73de 100644
--- a/csync/tests/encoding_tests/check_encoding.c
+++ b/csync/tests/encoding_tests/check_encoding.c
@@ -65,7 +65,7 @@ static void check_iconv_to_native_normalization(void **state)
     const char *exp_out = "\x48\xc3\xa4"; // UTF8
 #endif
 
-    out = c_utf8_to_locale(in);
+    out = c_utf8_path_to_locale(in);
     assert_string_equal(out, exp_out);
 
     c_free_locale_string(out);
@@ -127,8 +127,8 @@ static void check_to_multibyte(void **state)
 {
     int rc = -1;
 
-    mbchar_t *mb_string = c_utf8_to_locale( TESTSTRING );
-    mbchar_t *mb_null   = c_utf8_to_locale( NULL );
+    mbchar_t *mb_string = c_utf8_path_to_locale( TESTSTRING );
+    mbchar_t *mb_null   = c_utf8_path_to_locale( NULL );
 
     (void) state;
 
diff --git a/csync/tests/vio_tests/check_vio.c b/csync/tests/vio_tests/check_vio.c
index 9824a1d..bf5e599 100644
--- a/csync/tests/vio_tests/check_vio.c
+++ b/csync/tests/vio_tests/check_vio.c
@@ -59,7 +59,7 @@ static void setup(void **state)
 
 static void setup_dir(void **state) {
     int rc;
-    mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);
+    mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
 
     setup(state);
 
@@ -121,7 +121,7 @@ static void check_csync_vio_opendir_perm(void **state)
     CSYNC *csync = *state;
     csync_vio_handle_t *dh;
     int rc;
-    mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);
+    mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
 
     assert_non_null(dir);
 
diff --git a/csync/tests/vio_tests/check_vio_ext.c b/csync/tests/vio_tests/check_vio_ext.c
index 05e519c..a9913f6 100644
--- a/csync/tests/vio_tests/check_vio_ext.c
+++ b/csync/tests/vio_tests/check_vio_ext.c
@@ -57,7 +57,7 @@ static int wipe_testdir()
     */
    WIN32_FIND_DATA FindFileData;
 
-   mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);
+   mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
    HANDLE handle = FindFirstFile(dir, &FindFileData);
    c_free_locale_string(dir);
    int found = handle != INVALID_HANDLE_VALUE;
@@ -78,7 +78,7 @@ static void setup_testenv(void **state) {
     rc = wipe_testdir();
     assert_int_equal(rc, 0);
 
-    mbchar_t *dir = c_utf8_to_locale(CSYNC_TEST_DIR);
+    mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
 
     rc = _tmkdir(dir, MKDIR_MASK);
     assert_int_equal(rc, 0);
@@ -142,7 +142,7 @@ static void create_dirs( const char *path )
     if( *(p+i) == '/' ) {
       p[i] = '\0';
 
-      mbchar_t *mb_dir = c_utf8_to_locale(mypath);
+      mbchar_t *mb_dir = c_utf8_path_to_locale(mypath);
       /* wprintf(L"OOOO %ls (%ld)\n", mb_dir, strlen(mypath)); */
       rc = _tmkdir(mb_dir, MKDIR_MASK);
       c_free_locale_string(mb_dir);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list