]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Windows UTF-8 input/output
authorHeiko Hund <heiko.hund@sophos.com>
Wed, 23 Nov 2011 18:08:34 +0000 (19:08 +0100)
committerDavid Sommerseth <davids@redhat.com>
Sat, 4 Feb 2012 11:49:03 +0000 (12:49 +0100)
This patch makes openvpn read unicode from the console and convert the input
to UTF-8. And then display UTF-8 output to the console correctly.

Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
configure.ac
openvpn.c
win32.c

index 19173e96d7904bea31038bb2e6f93bcb3b54bdb0..25dcc37223efa91f4c2077ccb0f55ad7bd46fc1d 100644 (file)
@@ -349,6 +349,7 @@ case "$host" in
        OPENVPN_ADD_LIBS(-lcrypt32)
        OPENVPN_ADD_LIBS(-liphlpapi)
        OPENVPN_ADD_LIBS(-lwinmm)
+       OPENVPN_ADD_LIBS(-lshell32)
        ;;
 *-*-dragonfly*)
        AC_DEFINE(TARGET_DRAGONFLY, 1, [Are we running on DragonFlyBSD?])
index b4d6fd2a8aa63f34226be5ae0c72fb9306707c78..f5f2bce052d1c9fe48a8d5a25c7fa9ee6cea63df 100644 (file)
--- a/openvpn.c
+++ b/openvpn.c
@@ -131,6 +131,10 @@ main (int argc, char *argv[])
   return 1;
 #endif
 
+#ifdef TARGET_WIN32
+  SetConsoleOutputCP (CP_UTF8);
+#endif
+
   CLEAR (c);
 
   /* signify first time for components which can
diff --git a/win32.c b/win32.c
index 416af86d666eff839544c657fcdffefa0e688b46..2cc8c2a2b495c46d8f873b1de16ec85c7bf3afa9 100644 (file)
--- a/win32.c
+++ b/win32.c
@@ -763,6 +763,7 @@ get_console_input_win32 (const char *prompt, const bool echo, char *input, const
       bool is_console = (GetFileType (in) == FILE_TYPE_CHAR);
       DWORD flags_save = 0;
       int status = 0;
+      WCHAR *winput;
 
       if (is_console)
        {
@@ -777,7 +778,18 @@ get_console_input_win32 (const char *prompt, const bool echo, char *input, const
            is_console = 0;
        }
 
-      status = ReadFile (in, input, capacity, &len, NULL);
+      if (is_console)
+        {
+          winput = malloc (capacity * sizeof (WCHAR));
+          if (winput == NULL)
+            return false;
+
+          status = ReadConsoleW (in, winput, capacity, &len, NULL);
+          WideCharToMultiByte (CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
+          free (winput);
+        }
+      else
+        status = ReadFile (in, input, capacity, &len, NULL);
 
       string_null_terminate (input, (int)len, capacity);
       chomp (input);