summaryrefslogtreecommitdiffstats
path: root/src/collectors/windows-events.plugin/windows-events-unicode.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:33:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:34:10 +0000
commit83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch)
tree2e69833b43f791ed253a7a20318b767ebe56cdb8 /src/collectors/windows-events.plugin/windows-events-unicode.c
parentReleasing debian version 1.47.5-1. (diff)
downloadnetdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz
netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/collectors/windows-events.plugin/windows-events-unicode.c')
-rw-r--r--src/collectors/windows-events.plugin/windows-events-unicode.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/collectors/windows-events.plugin/windows-events-unicode.c b/src/collectors/windows-events.plugin/windows-events-unicode.c
new file mode 100644
index 000000000..81da31107
--- /dev/null
+++ b/src/collectors/windows-events.plugin/windows-events-unicode.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "windows-events-unicode.h"
+
+inline void utf82unicode(wchar_t *dst, size_t dst_size, const char *src) {
+ if (src) {
+ // Convert from UTF-8 to wide char (UTF-16)
+ if (utf8_to_utf16(dst, dst_size, src, -1) == 0)
+ wcsncpy(dst, L"[failed conv.]", dst_size - 1);
+ }
+ else
+ wcsncpy(dst, L"[null]", dst_size - 1);
+}
+
+inline void unicode2utf8(char *dst, size_t dst_size, const wchar_t *src) {
+ if (src) {
+ if(WideCharToMultiByte(CP_UTF8, 0, src, -1, dst, (int)dst_size, NULL, NULL) == 0)
+ strncpyz(dst, "[failed conv.]", dst_size - 1);
+ }
+ else
+ strncpyz(dst, "[null]", dst_size - 1);
+}
+
+wchar_t *channel2unicode(const char *utf8str) {
+ static __thread wchar_t buffer[1024];
+ utf82unicode(buffer, _countof(buffer), utf8str);
+ return buffer;
+}
+
+char *channel2utf8(const wchar_t *channel) {
+ static __thread char buffer[1024];
+ unicode2utf8(buffer, sizeof(buffer), channel);
+ return buffer;
+}
+
+char *query2utf8(const wchar_t *query) {
+ static __thread char buffer[16384];
+ unicode2utf8(buffer, sizeof(buffer), query);
+ return buffer;
+}
+
+char *provider2utf8(const wchar_t *provider) {
+ static __thread char buffer[256];
+ unicode2utf8(buffer, sizeof(buffer), provider);
+ return buffer;
+}