summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlon Bar-Lev <alon.barlev@gmail.com>2012-03-24 22:31:10 +0200
committerDavid Sommerseth <davids@redhat.com>2012-06-29 10:07:23 +0200
commit74370aa89df9285a95084616e9c2d3c8464760b9 (patch)
treea0f62d0a847e9163c9f7e08a8d89effc62ed9840 /src
parent5a57e201223f7265af0a56859b00a594b0d98f5b (diff)
downloadopenvpn-74370aa89df9285a95084616e9c2d3c8464760b9.tar.gz
openvpn-74370aa89df9285a95084616e9c2d3c8464760b9.tar.xz
openvpn-74370aa89df9285a95084616e9c2d3c8464760b9.zip
cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest
Discussed at [1]. Use wmain under windows, drop the custom parsing and shell32 linkage. There is no need for gc magic as this allocation is static. [1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433 Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com> Message-Id: 1332621070-28464-1-git-send-email-alon.barlev@gmail.com URL: http://article.gmane.org/gmane.network.openvpn.devel/6063 Tested-by: Samuli Seppänen <samuli@openvpn.net> Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/openvpn/Makefile.am6
-rw-r--r--src/openvpn/openvpn.c37
-rwxr-xr-x[-rw-r--r--]src/openvpn/openvpn.vcxproj10
-rw-r--r--src/openvpn/options.c27
4 files changed, 47 insertions, 33 deletions
diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am
index d090d67..5d38628 100644
--- a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am
@@ -27,6 +27,10 @@ AM_CFLAGS = \
$(OPTIONAL_CRYPTO_CFLAGS) \
$(OPTIONAL_LZO_CFLAGS) \
$(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
sbin_PROGRAMS = openvpn
@@ -118,5 +122,5 @@ openvpn_LDADD = \
$(OPTIONAL_DL_LIBS)
if WIN32
openvpn_SOURCES += openvpn_win32_resources.rc
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm
endif
diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index 75c751d..104c9e9 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
* @param argc - Commandline argument count.
* @param argv - Commandline argument values.
*/
+static
int
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])
{
struct context c;
@@ -289,3 +290,37 @@ main (int argc, char *argv[])
openvpn_exit (OPENVPN_EXIT_STATUS_GOOD); /* exit point */
return 0; /* NOTREACHED */
}
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+ char **argv;
+ int ret;
+ int i;
+
+ if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+ return 1;
+
+ for (i = 0; i < argc; i++)
+ {
+ int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+ argv[i] = malloc (n);
+ WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+ }
+
+ ret = openvpn_main(argc, argv);
+
+ for (i=0; i < argc; i++ )
+ {
+ free (argv[i]);
+ }
+ free(argv);
+
+ return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+ return openvpn_main(argc, argv);
+}
+#endif
diff --git a/src/openvpn/openvpn.vcxproj b/src/openvpn/openvpn.vcxproj
index 8ec8d90..3b2340e 100644..100755
--- a/src/openvpn/openvpn.vcxproj
+++ b/src/openvpn/openvpn.vcxproj
@@ -18,12 +18,12 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -56,12 +56,13 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
- <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
@@ -80,12 +81,13 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
- <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 367c1bc..bccdf0c 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3866,33 +3866,6 @@ parse_argv (struct options *options,
{
int i, j;
-#ifdef WIN32
- /*
- * Windows replaces Unicode characters in argv[] that are not present
- * in the current codepage with '?'. Get the wide char command line and
- * convert it to UTF-8 ourselves.
- */
- int wargc;
- WCHAR **wargv;
- char **uargv;
-
- wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
- if (wargv == NULL || wargc != argc)
- usage ();
-
- uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
- for (i = 0; i < wargc; i++)
- {
- int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
- uargv[i] = gc_malloc (n, false, &options->gc);
- WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
- }
-
- LocalFree (wargv);
- argv = uargv;
-#endif
-
/* usage message */
if (argc <= 1)
usage ();