OpenVPN output is not always a console.
I am not sure this patch is valid.

On Wed, Nov 23, 2011 at 4:15 PM, Heiko Hund <heiko.h...@sophos.com> wrote:
> 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.h...@sophos.com>
> ---
>  configure.ac |    1 +
>  openvpn.c    |    4 ++++
>  win32.c      |    8 +++++++-
>  3 files changed, 12 insertions(+), 1 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index a4d68e6..169d616 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -343,6 +343,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?])
> diff --git a/openvpn.c b/openvpn.c
> index 520fda1..611dffa 100644
> --- 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 cf6cc2d..0f4d11c 100644
> --- 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,10 +778,15 @@ get_console_input_win32 (const char *prompt, const bool 
> echo, char *input, const
>            is_console = 0;
>        }
>
> -      status = ReadFile (in, input, capacity, &len, NULL);
> +      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);
>       string_null_terminate (input, (int)len, capacity);
>       chomp (input);
> +      free (winput);
>
>       if (!echo)
>        WriteFile (err, "\r\n", 2, &len, NULL);
> --
> 1.7.5.4
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> Openvpn-devel mailing list
> Openvpn-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openvpn-devel
>

Reply via email to