From: "cron2 (Code Review)"
Date: Sun, 22 Dec 2024 10:48:06 +0000
In-Reply-To:
References:
Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515...,
openvpn-devel@lists.sourceforge.net, frank@...2641...
Message-ID: <4d4b56348091358fa0cede8b76ab647e0f06a7e7-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="hDexAgVLbLw="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: service: add
utf8to16 function that takes a size
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: d12fk , plaisthos , flichtenheld
Cc: openvpn-devel
--hDexAgVLbLw=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 has uploaded a new patch set (#3) to the change originally created by=
d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=3Demail )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: service: add utf8to16 function that takes a size
......................................................................
service: add utf8to16 function that takes a size
utf8to16_size() takes the size of the to be converted string. This is
needed to convert MULTI_SZ strings, which contain inline NUL characters,
but can be useful in other cases as well.
Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Signed-off-by: Heiko Hund
Acked-by: Frank Lichtenheld
Acked-by: Gert Doering
Message-Id: <20241221224136.20984-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30=
158.html
Signed-off-by: Gert Doering
---
M src/openvpnserv/common.c
M src/openvpnserv/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/3
diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c
index 96bf800..61a7296 100644
--- a/src/openvpnserv/common.c
+++ b/src/openvpnserv/common.c
@@ -247,17 +247,16 @@
return error;
}
-/* Convert a utf8 string to utf16. Caller should free the result */
wchar_t *
-utf8to16(const char *utf8)
+utf8to16_size(const char *utf8, int size)
{
- int n =3D MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
+ int n =3D MultiByteToWideChar(CP_UTF8, 0, utf8, size, NULL, 0);
wchar_t *utf16 =3D malloc(n * sizeof(wchar_t));
if (!utf16)
{
return NULL;
}
- MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, n);
+ MultiByteToWideChar(CP_UTF8, 0, utf8, size, utf16, n);
return utf16;
}
diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h
index 6d0827d..6b559a5 100644
--- a/src/openvpnserv/service.h
+++ b/src/openvpnserv/service.h
@@ -89,8 +89,40 @@
DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...);
-/* Convert a utf8 string to utf16. Caller should free the result */
-wchar_t *utf8to16(const char *utf8);
+/**
+ * Convert a UTF-8 string to UTF-16
+ *
+ * The size parameter can be used to convert strings which contain inline =
NUL
+ * characters, like MULTI_SZ strings used as values in the registry do,
+ * or (sub)strings that are not zero terminated. If size is -1 the length
+ * of the string is determined automatically by the WIN32 API. Make sure
+ * you pass a terminated string or else bad things will happen. Note that
+ * the size you pass should always include the terminating zero as well.
+ *
+ * If the returned string is not NULL it must be freed by the caller.
+ *
+ * @param utf8 const string to be converted
+ * @param size the size of the string
+ *
+ * @return wchar_t* heap allocated result string
+ */
+wchar_t *utf8to16_size(const char *utf8, int size);
+
+/**
+ * Convert a zero terminated UTF-8 string to UTF-16
+ *
+ * This is just a wrapper function that always passes -1 as string size
+ * to \ref utf8to16_size.
+ *
+ * @param utf8 const string to be converted
+ *
+ * @return wchar_t* heap allocated result string
+ */
+static inline wchar_t *
+utf8to16(const char *utf8)
+{
+ return utf8to16_size(utf8, -1);
+}
/* return windows system directory as a pointer to a static string */
const wchar_t *get_win_sys_path(void);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk
Gerrit-Reviewer: cron2
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-MessageType: newpatchset
--hDexAgVLbLw=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 uploaded patch set #3 to the change originally cr=
eated by d12fk.
View Change
The following approvals got outdated and=
were removed:
Code-Review+2 by cron2
service: add utf8to16 function that takes a size
=
utf8to16_size() takes the size of the to be converted string. This isneeded to convert MULTI_SZ strings, which contain inline NUL characters,<=
br>but can be useful in other cases as well.
Change-Id: I6b4aa3d63c0=
b684bf95841271c04bc5d9c37793b
Signed-off-by: Heiko Hund <heiko@...2843...=
2...>
Acked-by: Frank Lichtenheld <frank@...2641...>
Acked-b=
y: Gert Doering <gert@...1296...>
Message-Id: <20241221224136.2=
0984-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-dev=
el@lists.sourceforge.net/msg30158.html
Signed-off-by: Gert Doering <g=
ert@...1296...>
---
M src/openvpnserv/common.c
M src/openvpnser=
v/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/3
=
diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c<=
br>index 96bf800..61a7296 100644
--- a/src/openvpnser=
v/common.c
+++ b/src/openvpnserv/common.c
@=
@ -247,17 +247,16 @@
return error;
}<=
/span>
-/* C=
onvert a utf8 string to utf16. Caller should free the result */
<=
span> wchar_t *
-utf8to=
16(const char *utf8)
=
+utf8to16_size(const char *utf8, int size)
{
- int n =3D MultiByteToWideChar(C=
P_UTF8, 0, utf8, -1, NULL, 0);
+ int n =3D MultiByteToWideChar(CP_UTF8, 0, utf8, size, NULL, =
0);
wchar_t *utf16 =3D malloc(n * sizeof(wchar_t));
if (!utf16)
{
=
return NULL;
}
- MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, n);<=
/span>
+ MultiByteToWideC=
har(CP_UTF8, 0, utf8, size, utf16, n);
return utf16;=
span>
}
diff --git a/src/openvp=
nserv/service.h b/src/openvpnserv/service.h
index 6d0827d..=
6b559a5 100644
--- a/src/openvpnserv/service.h
+++ b/src/openvpnserv/service.h
@@ -89,8 +89,40 @@
DWORD MsgToEventLog(DWORD flags, LPCTSTR lps=
zMsg, ...);
-/* Convert a utf8 string to utf16. Caller should free the result */=
-wchar_t *utf8to16(con=
st char *utf8);
+/**<=
/span>
+ * Convert a UTF-8 s=
tring to UTF-16
+ *=
span>
+ * The size parameter=
can be used to convert strings which contain inline NUL
+ * characters, like MULTI_SZ strings u=
sed as values in the registry do,
+ * or (sub)strings that are not zero terminated. If size is -=
1 the length
+ * of t=
he string is determined automatically by the WIN32 API. Make sure
+ * you pass a terminated stri=
ng or else bad things will happen. Note that
+ * the size you pass should always include the ter=
minating zero as well.
+ *
+ * If the retu=
rned string is not NULL it must be freed by the caller.
+ *
+ * @param utf8 const string to be converted
<=
span style=3D"color: hsl(120, 100%, 40%);">+ * @param size the size of the=
string
+ *
+ * @return wchar_t* heap allo=
cated result string
+=
*/
+wchar_t *utf8to1=
6_size(const char *utf8, int size);
+
+/**=
+ * Convert a zero t=
erminated UTF-8 string to UTF-16
+ *
+ * T=
his is just a wrapper function that always passes -1 as string size<=
br>+ * to \ref utf8to16_size.=
span>
+ *
+ * @param utf8 const string to be con=
verted
+ *
=
+ * @return wchar_t* heap alloc=
ated result string
+ =
*/
+static inline wch=
ar_t *
+utf8to16(cons=
t char *utf8)
+{
+ return utf8to16_size=
(utf8, -1);
+}=
/* return windows system directory as a pointe=
r to a static string */
const wchar_t *get_win_sys_path(vo=
id);
To view, visit change 836. To unsubscri=
be, or for help writing mail filters, visit settings.
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c0=
4bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <heiko@...515...> =
div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--hDexAgVLbLw=--