Commit c47c54666f731c3f68e8eeb8426a99d9dcf41b38

Authored by Perry Werneck
1 parent cf18786f
Exists in master and in 1 other branch develop

Fixing D-Bus method returns.

Showing 1 changed file with 26 additions and 40 deletions   Show diff stats
src/linux/methods.c
@@ -39,6 +39,25 @@ @@ -39,6 +39,25 @@
39 #include <dbus/dbus-glib.h> 39 #include <dbus/dbus-glib.h>
40 #include <dbus/dbus-glib-bindings.h> 40 #include <dbus/dbus-glib-bindings.h>
41 41
  42 +/// @brief Converts lib3270 string to UTF-8 sets the method response.
  43 +void g_dbus_method_invocation_return_tn3270_string(ipc3270 *obj, GDBusMethodInvocation *invocation, char *string) {
  44 +
  45 + if(!string) {
  46 + g_autoptr (GError) error = NULL;
  47 + g_set_error(&error,obj->error_domain,errno,"%s",strerror(errno));
  48 + g_dbus_method_invocation_return_gerror(invocation, error);
  49 + return;
  50 + }
  51 +
  52 + gchar * utftext = g_convert_with_fallback(string,-1,"UTF-8",lib3270_get_display_charset(obj->hSession),"?",NULL,NULL,NULL);
  53 +
  54 + g_dbus_method_invocation_return_value(invocation, g_variant_new ("(s)", utftext));
  55 +
  56 + lib3270_free(string);
  57 + g_free(utftext);
  58 +
  59 +}
  60 +
42 void 61 void
43 ipc3270_method_call (GDBusConnection *connection, 62 ipc3270_method_call (GDBusConnection *connection,
44 const gchar *sender, 63 const gchar *sender,
@@ -54,21 +73,11 @@ ipc3270_method_call (GDBusConnection *connection, @@ -54,21 +73,11 @@ ipc3270_method_call (GDBusConnection *connection,
54 size_t ix; 73 size_t ix;
55 g_autoptr (GError) error = NULL; 74 g_autoptr (GError) error = NULL;
56 75
  76 + debug("%s(%s)",__FUNCTION__,method_name);
  77 +
57 if(!g_ascii_strcasecmp(method_name,"getString")) 78 if(!g_ascii_strcasecmp(method_name,"getString"))
58 { 79 {
59 - char * text = lib3270_get_string_at_address(IPC3270(user_data)->hSession,0,-1,'\n');  
60 -  
61 - if(!text)  
62 - {  
63 - g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));  
64 - g_dbus_method_invocation_return_gerror(invocation, error);  
65 - }  
66 - else  
67 - {  
68 - g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));  
69 - lib3270_free(text);  
70 - }  
71 - 80 + g_dbus_method_invocation_return_tn3270_string(IPC3270(user_data), invocation, lib3270_get_string_at_address(IPC3270(user_data)->hSession,0,-1,'\n'));
72 return; 81 return;
73 } 82 }
74 else if(!g_ascii_strcasecmp(method_name,"setString")) 83 else if(!g_ascii_strcasecmp(method_name,"setString"))
@@ -116,20 +125,9 @@ ipc3270_method_call (GDBusConnection *connection, @@ -116,20 +125,9 @@ ipc3270_method_call (GDBusConnection *connection,
116 guchar lf; 125 guchar lf;
117 g_variant_get(parameters, "(iiy)", &row, &col, &len,&lf); 126 g_variant_get(parameters, "(iiy)", &row, &col, &len,&lf);
118 127
119 - char * text = lib3270_get_string_at(IPC3270(user_data)->hSession, row, col, len, lf);  
120 -  
121 - if(!text)  
122 - {  
123 - g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));  
124 - g_dbus_method_invocation_return_gerror(invocation, error);  
125 - }  
126 - else  
127 - {  
128 - g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));  
129 - lib3270_free(text);  
130 - }  
131 - 128 + g_dbus_method_invocation_return_tn3270_string(IPC3270(user_data), invocation, lib3270_get_string_at(IPC3270(user_data)->hSession, row, col, len, lf));
132 return; 129 return;
  130 +
133 } 131 }
134 else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress")) 132 else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress"))
135 { 133 {
@@ -157,19 +155,7 @@ ipc3270_method_call (GDBusConnection *connection, @@ -157,19 +155,7 @@ ipc3270_method_call (GDBusConnection *connection,
157 guchar lf; 155 guchar lf;
158 g_variant_get(parameters, "(iiy)", &addr, &len, &lf); 156 g_variant_get(parameters, "(iiy)", &addr, &len, &lf);
159 157
160 - char * text = lib3270_get_string_at_address(IPC3270(user_data)->hSession, addr, len, lf);  
161 -  
162 - if(!text)  
163 - {  
164 - g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));  
165 - g_dbus_method_invocation_return_gerror(invocation, error);  
166 - }  
167 - else  
168 - {  
169 - g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));  
170 - lib3270_free(text);  
171 - }  
172 - 158 + g_dbus_method_invocation_return_tn3270_string(IPC3270(user_data), invocation, lib3270_get_string_at_address(IPC3270(user_data)->hSession, addr, len, lf));
173 return; 159 return;
174 160
175 } 161 }
@@ -200,7 +186,7 @@ ipc3270_method_call (GDBusConnection *connection, @@ -200,7 +186,7 @@ ipc3270_method_call (GDBusConnection *connection,
200 // Check int methods 186 // Check int methods
201 const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); 187 const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods();
202 188
203 - for(ix = 0; ix < G_N_ELEMENTS(int_methods); ix++) 189 + for(ix = 0; int_methods[ix].name; ix++)
204 { 190 {
205 if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) { 191 if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) {
206 192