Commit 6d74787264ce5c12ad47a8dcabc0ddd6c9180ffe

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

Removing charset conversions from IPC server.

Adding some field methods.
common/src/include/lib3270/ipc-glib.h
@@ -95,42 +95,6 @@ @@ -95,42 +95,6 @@
95 void ipc3270_set_terminal_widget(GObject *object, GtkWidget *widget); 95 void ipc3270_set_terminal_widget(GObject *object, GtkWidget *widget);
96 void ipc3270_export_object(GObject *object, const char *name, GError **error); 96 void ipc3270_export_object(GObject *object, const char *name, GError **error);
97 97
98 - /**  
99 - * @brief Convert from native charset to lib3270 charset.  
100 - *  
101 - * @param object ipc3270 Object.  
102 - * @param string UTF-8 string to convert.  
103 - * @param error Pointer to error object.  
104 - *  
105 - * @return Converted string in lib3270 charset.  
106 - *  
107 - */  
108 - gchar * ipc3270_convert_to_3270(GObject *object, const gchar *string, GError **error);  
109 -  
110 - /**  
111 - * @brief Convert lib3270 received string to UTF-8.  
112 - *  
113 - * @param object ipc3270 object.  
114 - * @param string String received from lib3270.  
115 - * @param error Pointer to error object.  
116 - *  
117 - * @return The string converted to UTF-8.  
118 - *  
119 - */  
120 - gchar * ipc3270_convert_from_3270(GObject *object, const gchar *string, GError **error);  
121 -  
122 - /**  
123 - * @brief Create a GVariant from a lib3270 string.  
124 - *  
125 - * @param object ipc3270 object.  
126 - * @param string String received from lib3270.  
127 - * @param error Pointer to error object.  
128 - *  
129 - * @return GVariant with the string converted to UTF-8.  
130 - *  
131 - */  
132 - GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);  
133 -  
134 void ipc3270_add_terminal_introspection(GString *string); 98 void ipc3270_add_terminal_introspection(GString *string);
135 99
136 const gchar * ipc3270_get_display_charset(GObject *object); 100 const gchar * ipc3270_get_display_charset(GObject *object);
server/pw3270-plugin-ipc.cbp
@@ -63,9 +63,6 @@ @@ -63,9 +63,6 @@
63 <Unit filename="src/core/constants.c"> 63 <Unit filename="src/core/constants.c">
64 <Option compilerVar="CC" /> 64 <Option compilerVar="CC" />
65 </Unit> 65 </Unit>
66 - <Unit filename="src/core/convert.c">  
67 - <Option compilerVar="CC" />  
68 - </Unit>  
69 <Unit filename="src/core/getproperties.c"> 66 <Unit filename="src/core/getproperties.c">
70 <Option compilerVar="CC" /> 67 <Option compilerVar="CC" />
71 </Unit> 68 </Unit>
server/src/core/convert.c
@@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
1 -/*  
2 - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270  
3 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a  
4 - * aplicativos mainframe. Registro no INPI sob o nome G3270.  
5 - *  
6 - * Copyright (C) <2008> <Banco do Brasil S.A.>  
7 - *  
8 - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob  
9 - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela  
10 - * Free Software Foundation.  
11 - *  
12 - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER  
13 - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO  
14 - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para  
15 - * obter mais detalhes.  
16 - *  
17 - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este  
18 - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin  
19 - * St, Fifth Floor, Boston, MA 02110-1301 USA  
20 - *  
21 - * Este programa está nomeado como - e possui - linhas de código.  
22 - *  
23 - * Referências:  
24 - *  
25 - * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c  
26 - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c  
27 - *  
28 - * Contatos:  
29 - *  
30 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
31 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
32 - *  
33 - */  
34 -  
35 -#include <lib3270.h>  
36 -#include <lib3270/actions.h>  
37 -#include <lib3270/ipc-glib.h>  
38 -  
39 -gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error) {  
40 - return g_convert_with_fallback(string,-1,ipc3270_get_display_charset(object),"UTF-8","?",NULL,NULL,error);  
41 -}  
42 -  
43 -gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error) {  
44 - return g_convert_with_fallback(string,-1,"UTF-8",ipc3270_get_display_charset(object),"?",NULL,NULL,error);  
45 -}  
46 -  
47 -GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error) {  
48 -  
49 - if(string) {  
50 - g_autofree gchar * utfstring = ipc3270_convert_input_string(object,string,error);  
51 - lib3270_free(string);  
52 - return g_variant_new_string(utfstring);  
53 - }  
54 -  
55 - ipc3270_set_error(object,errno,error);  
56 - return g_variant_new_string("");  
57 -}  
58 -  
59 -  
server/src/core/linux/gobject.c
@@ -168,6 +168,9 @@ void ipc3270_add_terminal_introspection(GString *introspection) { @@ -168,6 +168,9 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
168 " <arg type='u' name='col' direction='in' />" \ 168 " <arg type='u' name='col' direction='in' />" \
169 " <arg type='s' name='text' direction='out' />" \ 169 " <arg type='s' name='text' direction='out' />" \
170 " </method>" \ 170 " </method>" \
  171 + " <method name= 'getFieldAttribute'>" \
  172 + " <arg type='u' name='attribute' direction='out' />" \
  173 + " </method>" \
171 " <method name= 'getFieldAttributeAt'>" \ 174 " <method name= 'getFieldAttributeAt'>" \
172 " <arg type='i' name='row' direction='in' />" \ 175 " <arg type='i' name='row' direction='in' />" \
173 " <arg type='i' name='col' direction='in' />" \ 176 " <arg type='i' name='col' direction='in' />" \
server/src/core/methods/field.c
@@ -29,10 +29,39 @@ @@ -29,10 +29,39 @@
29 29
30 #include "private.h" 30 #include "private.h"
31 31
32 -int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error) { 32 +int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) {
33 33
34 debug("%s childs=%u",__FUNCTION__,(unsigned int) g_variant_n_children(request)); 34 debug("%s childs=%u",__FUNCTION__,(unsigned int) g_variant_n_children(request));
35 35
36 - return ENOTSUP; 36 +
  37 + H3270 *hSession = ipc3270_get_session(session);
  38 + guint row = 0, col = 0;
  39 + gint baddr = -1;
  40 +
  41 + switch(g_variant_n_children(request)) {
  42 + case 0: // No arguments, get at the current cursor position
  43 + baddr = -1;
  44 + break;
  45 +
  46 + case 1: // address
  47 + g_variant_get(request, "(i)", &baddr);
  48 + break;
  49 +
  50 + case 2: // row, col
  51 + g_variant_get(request, "(ii)", &row, &col);
  52 + baddr = lib3270_translate_to_address(hSession,row,col);
  53 + break;
  54 +
  55 + default:
  56 + return EINVAL;
  57 + }
  58 +
  59 + LIB3270_FIELD_ATTRIBUTE attr = lib3270_get_field_attribute(hSession,baddr);
  60 + if(attr == LIB3270_FIELD_ATTRIBUTE_INVALID)
  61 + return errno;
  62 +
  63 + ipc3270_response_append_uint32(response, (guint32) attr);
  64 +
  65 + return 0;
37 } 66 }
38 67
server/src/core/methods/get.c
@@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
29 29
30 #include "private.h" 30 #include "private.h"
31 31
32 -int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError **error) { 32 +int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *response, GError G_GNUC_UNUSED(**error)) {
33 33
34 H3270 *hSession = ipc3270_get_session(session); 34 H3270 *hSession = ipc3270_get_session(session);
35 35
@@ -76,8 +76,7 @@ int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *resp @@ -76,8 +76,7 @@ int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *resp
76 if(!text) 76 if(!text)
77 return errno; 77 return errno;
78 78
79 - g_autofree gchar * converted = ipc3270_convert_from_3270(session,text,error);  
80 - ipc3270_response_append_string(response, converted); 79 + ipc3270_response_append_string(response, text);
81 80
82 return 0; 81 return 0;
83 82
server/src/core/methods/network.c
@@ -29,20 +29,15 @@ @@ -29,20 +29,15 @@
29 29
30 #include "private.h" 30 #include "private.h"
31 31
32 -int ipc3270_method_connect(GObject *session, GVariant *request, GObject *response, GError **error) { 32 +int ipc3270_method_connect(GObject *session, GVariant *request, GObject G_GNUC_UNUSED(*response), GError G_GNUC_UNUSED(**error)) {
33 33
34 gchar *text = NULL; 34 gchar *text = NULL;
35 g_variant_get(request, "(&s)", &text); 35 g_variant_get(request, "(&s)", &text);
36 36
37 - g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);  
38 -  
39 - if(!*error)  
40 - return lib3270_connect_url(ipc3270_get_session(session),converted,0);  
41 -  
42 - return 0; 37 + return lib3270_connect_url(ipc3270_get_session(session),text,0);
43 38
44 } 39 }
45 40
46 -int ipc3270_method_disconnect(GObject *session, GVariant *request, GObject *response, GError **error) { 41 +int ipc3270_method_disconnect(GObject *session, GVariant G_GNUC_UNUSED(*request), GObject G_GNUC_UNUSED(*response), GError G_GNUC_UNUSED(**error)) {
47 return lib3270_disconnect(ipc3270_get_session(session)); 42 return lib3270_disconnect(ipc3270_get_session(session));
48 } 43 }
server/src/core/methods/set.c
@@ -50,14 +50,11 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp @@ -50,14 +50,11 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp
50 50
51 if(text) { 51 if(text) {
52 52
53 - g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);  
54 -  
55 - debug("Converted: \"%s\"",converted);  
56 -  
57 - if(lib3270_input_string(hSession,(const unsigned char *) converted, -1)) { 53 + if(lib3270_input_string(hSession,(const unsigned char *) text, -1)) {
58 debug("lib3270_input_string has failed: %s", strerror(errno)); 54 debug("lib3270_input_string has failed: %s", strerror(errno));
59 return errno; 55 return errno;
60 } 56 }
  57 +
61 } 58 }
62 59
63 } 60 }
@@ -72,9 +69,7 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp @@ -72,9 +69,7 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp
72 69
73 if(text) { 70 if(text) {
74 71
75 - g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);  
76 -  
77 - if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0) 72 + if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) text, -1) < 0)
78 return errno; 73 return errno;
79 74
80 } 75 }
@@ -90,9 +85,7 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp @@ -90,9 +85,7 @@ int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *resp
90 85
91 if(text) { 86 if(text) {
92 87
93 - g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);  
94 -  
95 - if(lib3270_set_string_at(hSession, row, col, (unsigned char *) converted, -1) < 0) 88 + if(lib3270_set_string_at(hSession, row, col, (unsigned char *) text, -1) < 0)
96 return errno; 89 return errno;
97 90
98 } 91 }
server/src/core/methods/wait.c
@@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
29 29
30 #include "private.h" 30 #include "private.h"
31 31
32 -int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, GError **error) { 32 +int ipc3270_method_wait(GObject *session, GVariant *request, GObject G_GNUC_UNUSED(*response), GError G_GNUC_UNUSED(**error)) {
33 33
34 guint seconds = 1; 34 guint seconds = 1;
35 g_variant_get(request, "(u)", &seconds); 35 g_variant_get(request, "(u)", &seconds);
@@ -37,7 +37,7 @@ int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response, @@ -37,7 +37,7 @@ int ipc3270_method_wait(GObject *session, GVariant *request, GObject *response,
37 37
38 } 38 }
39 39
40 -int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *response, GError **error) { 40 +int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject G_GNUC_UNUSED(*response), GError G_GNUC_UNUSED(**error)) {
41 41
42 guint seconds = 1; 42 guint seconds = 1;
43 g_variant_get(request, "(u)", &seconds); 43 g_variant_get(request, "(u)", &seconds);
@@ -45,7 +45,7 @@ int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject * @@ -45,7 +45,7 @@ int ipc3270_method_wait_for_ready(GObject *session, GVariant *request, GObject *
45 45
46 } 46 }
47 47
48 -int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject *response, GError **error) { 48 +int ipc3270_method_wait_for_update(GObject *session, GVariant *request, GObject G_GNUC_UNUSED(*response), GError G_GNUC_UNUSED(**error)) {
49 49
50 guint seconds = 1; 50 guint seconds = 1;
51 g_variant_get(request, "(u)", &seconds); 51 g_variant_get(request, "(u)", &seconds);