From 796d2d6e2cb7b37fb5b4b92febd7badfbfc782ad Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 16 Aug 2019 14:37:17 -0300 Subject: [PATCH] IPC/D-Bus string should be in UTF-8, doing the necessary conversions. --- client/src/session/remote/properties.cc | 2 ++ client/src/testprogram/testprogram.cc | 2 +- server/src/core/methods/get.c | 6 ++++-- server/src/core/methods/set.c | 14 ++++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/client/src/session/remote/properties.cc b/client/src/session/remote/properties.cc index a2a7683..0d66126 100644 --- a/client/src/session/remote/properties.cc +++ b/client/src/session/remote/properties.cc @@ -96,6 +96,8 @@ } void IPC::Session::setCharSet(const char *charset) { + // D-Bus calls are always UTF-8 + Abstract::Session::setCharSet("UTF-8",charset); } unsigned short IPC::Session::getScreenWidth() const { diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index f29ce66..b5d6e04 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -96,7 +96,7 @@ << "\tRevision: " << host.getRevision() << std::endl; -// host.connect(nullptr); + host.connect(nullptr); cout << "Connection state is " << toCharString(host.getConnectionState()) << std::endl diff --git a/server/src/core/methods/get.c b/server/src/core/methods/get.c index 991aee5..2637452 100644 --- a/server/src/core/methods/get.c +++ b/server/src/core/methods/get.c @@ -29,7 +29,7 @@ #include "private.h" -int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) { +int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError **error) { H3270 *hSession = ipc3270_get_session(session); @@ -75,7 +75,9 @@ int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *resp if(!text) return errno; - ipc3270_response_append_string(response, text); + // Send response as UTF-8. + g_autofree gchar * converted = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,error); + ipc3270_response_append_string(response, converted); return 0; diff --git a/server/src/core/methods/set.c b/server/src/core/methods/set.c index 00938e7..d22c079 100644 --- a/server/src/core/methods/set.c +++ b/server/src/core/methods/set.c @@ -38,7 +38,6 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp gchar *text = NULL; g_variant_get(request, "(&s)", &text); - if(*error) return 0; @@ -50,7 +49,9 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp if(text) { - if(lib3270_input_string(hSession,(const unsigned char *) text, -1)) { + g_autofree gchar * converted = g_convert_with_fallback(text,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,error); + + if(lib3270_input_string(hSession,(const unsigned char *) converted, -1)) { debug("lib3270_input_string has failed: %s", strerror(errno)); return errno; } @@ -69,7 +70,9 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp if(text) { - if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) text, -1) < 0) + g_autofree gchar * converted = g_convert_with_fallback(text,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,error); + + if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0) return errno; } @@ -85,7 +88,9 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp if(text) { - if(lib3270_set_string_at(hSession, row, col, (unsigned char *) text, -1) < 0) + g_autofree gchar * converted = g_convert_with_fallback(text,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,error); + + if(lib3270_set_string_at(hSession, row, col, (unsigned char *) converted, -1) < 0) return errno; } @@ -94,6 +99,7 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp break; default: + g_message("setstring was called with %u arguments.",(unsigned int) g_variant_n_children(request)); return EINVAL; } -- libgit2 0.21.2