Commit 12c9a65eebe8cb012bf0684d18f27375c625a7e5

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

Refactoring IPC server.

client/src/core/host.cc
@@ -110,7 +110,7 @@ @@ -110,7 +110,7 @@
110 } 110 }
111 111
112 bool Host::isReady() const { 112 bool Host::isReady() const {
113 - this->session->waitForReady(this->timeout); 113 +// this->session->waitForReady(this->timeout);
114 return getProgramMessage() == MESSAGE_NONE; 114 return getProgramMessage() == MESSAGE_NONE;
115 } 115 }
116 116
client/src/include/ipc-client-internals.h
@@ -192,6 +192,7 @@ @@ -192,6 +192,7 @@
192 std::string getRevision() const override; 192 std::string getRevision() const override;
193 std::string getLUName() const override; 193 std::string getLUName() const override;
194 std::string getHostURL() const override; 194 std::string getHostURL() const override;
  195 + SSLState getSSLState() const override;
195 196
196 unsigned short getScreenWidth() const override; 197 unsigned short getScreenWidth() const override;
197 unsigned short getScreenHeight() const override; 198 unsigned short getScreenHeight() const override;
@@ -373,6 +374,7 @@ @@ -373,6 +374,7 @@
373 std::string getRevision() const override; 374 std::string getRevision() const override;
374 std::string getLUName() const override; 375 std::string getLUName() const override;
375 std::string getHostURL() const override; 376 std::string getHostURL() const override;
  377 + SSLState getSSLState() const override;
376 378
377 unsigned short getScreenWidth() const override; 379 unsigned short getScreenWidth() const override;
378 unsigned short getScreenHeight() const override; 380 unsigned short getScreenHeight() const override;
client/src/session/local/session.cc
@@ -695,6 +695,10 @@ @@ -695,6 +695,10 @@
695 return (unsigned short) lib3270_get_length(hSession); 695 return (unsigned short) lib3270_get_length(hSession);
696 } 696 }
697 697
  698 + TN3270::SSLState Local::Session::getSSLState() const override {
  699 + return lib3270_get_secure(hSession);
  700 + }
  701 +
698 } 702 }
699 703
700 704
client/src/session/remote/session.cc
@@ -447,6 +447,15 @@ @@ -447,6 +447,15 @@
447 int value; 447 int value;
448 getProperty("length",value); 448 getProperty("length",value);
449 return (unsigned short) value; 449 return (unsigned short) value;
  450 +
  451 + }
  452 +
  453 + TN3270::SSLState Local::Session::getSSLState() const override {
  454 +
  455 + int value;
  456 + getProperty("sslstate",value);
  457 + return (TN3270::SSLState) value;
  458 +
450 } 459 }
451 460
452 } 461 }
common/src/include/lib3270/ipc-glib.h
@@ -61,6 +61,25 @@ @@ -61,6 +61,25 @@
61 61
62 G_BEGIN_DECLS 62 G_BEGIN_DECLS
63 63
  64 + #define GLIB_TYPE_IPC3270_RESPONSE (ipc3270Response_get_type ())
  65 + #define IPC3270_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLIB_TYPE_IPC3270_RESPONSE, ipc3270Response))
  66 + #define IPC3270_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIB_TYPE_IPC3270_RESPONSE, ipc3270ResponseClass))
  67 + #define IS_IPC3270_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLIB_TYPE_IPC3270_RESPONSE))
  68 + #define IS_IPC3270_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLIB_TYPE_IPC3270_RESPONSE))
  69 + #define IPC3270_RESPONSE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS ((obj), GLIB_TYPE_IPC3270_RESPONSE, ipc3270ResponseClass))
  70 +
  71 + typedef struct _ipc3270Response ipc3270Response;
  72 + typedef struct _ipc3270ResponseClass ipc3270ResponseClass;
  73 +
  74 + GObject * ipc3270_response_new();
  75 +
  76 + void ipc3270_response_append_int32(GObject *object, gint32 value);
  77 + void ipc3270_response_append_uint32(GObject *object, guint32 value);
  78 + void ipc3270_response_append_3270_string(GObject *object, const char *text, GError **error);
  79 + gboolean ipc3270_response_has_values(GObject *object);
  80 + GVariant * ipc3270_response_steal_value(GObject *object);
  81 +
  82 +
64 #define GLIB_TYPE_IPC3270 (ipc3270_get_type ()) 83 #define GLIB_TYPE_IPC3270 (ipc3270_get_type ())
65 #define IPC3270(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLIB_TYPE_IPC3270, ipc3270)) 84 #define IPC3270(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLIB_TYPE_IPC3270, ipc3270))
66 #define IPC3270_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIB_TYPE_IPC3270, ipc3270Class)) 85 #define IPC3270_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIB_TYPE_IPC3270, ipc3270Class))
@@ -121,7 +140,7 @@ @@ -121,7 +140,7 @@
121 140
122 void ipc3270_set_error(GObject *object, int errcode, GError **error); 141 void ipc3270_set_error(GObject *object, int errcode, GError **error);
123 142
124 - GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error); 143 + void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error);
125 gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); 144 gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
126 GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error); 145 GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
127 146
common/src/include/lib3270/ipc.h
@@ -141,6 +141,14 @@ @@ -141,6 +141,14 @@
141 CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode 141 CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode
142 }; 142 };
143 143
  144 + enum SSLState : uint8_t {
  145 + SSL_UNSECURE = LIB3270_SSL_UNSECURE, ///< @brief No secure connection
  146 + SSL_SECURE = LIB3270_SSL_SECURE, ///< @brief Connection secure with CA check
  147 + SSL_NEGOTIATED = LIB3270_SSL_NEGOTIATED, ///< @brief Connection secure, no CA, self-signed or expired CRL
  148 + SSL_NEGOTIATING = LIB3270_SSL_NEGOTIATING, ///< @brief Negotiating SSL
  149 + SSL_UNDEFINED = LIB3270_SSL_UNDEFINED ///< @brief Undefined
  150 + };
  151 +
144 /// @brief PF Keys 152 /// @brief PF Keys
145 enum PFKey : uint8_t { 153 enum PFKey : uint8_t {
146 PF_1, 154 PF_1,
@@ -270,10 +278,20 @@ @@ -270,10 +278,20 @@
270 return getConnectionState(); 278 return getConnectionState();
271 } 279 }
272 280
273 - inline bool operator==(ConnectionState state) const noexcept { 281 + inline bool operator==(ConnectionState state) const {
274 return this->getConnectionState() == state; 282 return this->getConnectionState() == state;
275 } 283 }
276 284
  285 + virtual SSLState getSSLState() const = 0;
  286 +
  287 + inline operator SSLState() const {
  288 + return getSSLState();
  289 + }
  290 +
  291 + inline bool operator==(SSLState state) const {
  292 + return this->getSSLState() == state;
  293 + }
  294 +
277 // Set properties. 295 // Set properties.
278 virtual void setUnlockDelay(unsigned short delay = 350) = 0; 296 virtual void setUnlockDelay(unsigned short delay = 350) = 0;
279 void setCharSet(const char *charset); 297 void setCharSet(const char *charset);
@@ -335,6 +353,19 @@ @@ -335,6 +353,19 @@
335 /// @brief Wait for update. 353 /// @brief Wait for update.
336 virtual Session & wait_for_update(unsigned short seconds) = 0; 354 virtual Session & wait_for_update(unsigned short seconds) = 0;
337 355
  356 + /// @brief Wait for string.
  357 + ///
  358 + /// @return 0 if the string was found, error code if not.
  359 + int wait(int row, int col, const char *key, unsigned short seconds);
  360 + int wait(int baddr, const char *key, unsigned short seconds);
  361 +
  362 + /// @brief Search
  363 + size_t find(const char * str, size_t pos = 0) const;
  364 +
  365 + /// @brief Compare contents.
  366 + int compare(size_t baddr, const char* s, size_t len) const;
  367 + int compare(int row, int col, const char* s, size_t len) const;
  368 +
338 }; 369 };
339 370
340 /// @brief TN3270 Host 371 /// @brief TN3270 Host
server/Makefile.in
@@ -32,6 +32,7 @@ PACKAGE_NAME=@PACKAGE_NAME@ @@ -32,6 +32,7 @@ PACKAGE_NAME=@PACKAGE_NAME@
32 32
33 CORE_SOURCES= \ 33 CORE_SOURCES= \
34 $(wildcard src/core/*.c) \ 34 $(wildcard src/core/*.c) \
  35 + $(wildcard src/core/methods/*.c) \
35 $(wildcard src/core/@OSNAME@/*.c) 36 $(wildcard src/core/@OSNAME@/*.c)
36 37
37 PLUGIN_SOURCES= \ 38 PLUGIN_SOURCES= \
server/pw3270-plugin-ipc.cbp
@@ -73,13 +73,16 @@ @@ -73,13 +73,16 @@
73 <Option compilerVar="CC" /> 73 <Option compilerVar="CC" />
74 </Unit> 74 </Unit>
75 <Unit filename="src/core/linux/gobject.h" /> 75 <Unit filename="src/core/linux/gobject.h" />
  76 + <Unit filename="src/core/linux/response.c">
  77 + <Option compilerVar="CC" />
  78 + </Unit>
76 <Unit filename="src/core/linux/start.c"> 79 <Unit filename="src/core/linux/start.c">
77 <Option compilerVar="CC" /> 80 <Option compilerVar="CC" />
78 </Unit> 81 </Unit>
79 <Unit filename="src/core/linux/stop.c"> 82 <Unit filename="src/core/linux/stop.c">
80 <Option compilerVar="CC" /> 83 <Option compilerVar="CC" />
81 </Unit> 84 </Unit>
82 - <Unit filename="src/core/methods.c"> 85 + <Unit filename="src/core/methods/methods.c">
83 <Option compilerVar="CC" /> 86 <Option compilerVar="CC" />
84 </Unit> 87 </Unit>
85 <Unit filename="src/core/setproperties.c"> 88 <Unit filename="src/core/setproperties.c">
server/src/core/linux/gobject.c
@@ -133,7 +133,7 @@ void ipc3270_add_terminal_introspection(GString *introspection) { @@ -133,7 +133,7 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
133 " <arg type='s' name='text' direction='out' />" \ 133 " <arg type='s' name='text' direction='out' />" \
134 " </method>" \ 134 " </method>" \
135 " <method name='setStringAtAddress'>" \ 135 " <method name='setStringAtAddress'>" \
136 - " <arg type='u' name='addr' direction='in' />" \ 136 + " <arg type='i' name='addr' direction='in' />" \
137 " <arg type='s' name='text' direction='in' />" \ 137 " <arg type='s' name='text' direction='in' />" \
138 " <arg type='i' name='result' direction='out' />" \ 138 " <arg type='i' name='result' direction='out' />" \
139 " </method>" \ 139 " </method>" \
@@ -143,22 +143,14 @@ void ipc3270_add_terminal_introspection(GString *introspection) { @@ -143,22 +143,14 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
143 " <arg type='y' name='lf' direction='in' />" \ 143 " <arg type='y' name='lf' direction='in' />" \
144 " <arg type='s' name='text' direction='out' />" \ 144 " <arg type='s' name='text' direction='out' />" \
145 " </method>" \ 145 " </method>" \
146 - " <method name= 'getFieldAt'>" \  
147 - " <arg type='u' name='row' direction='in' />" \  
148 - " <arg type='u' name='col' direction='in' />" \  
149 - " <arg type='s' name='text' direction='out' />" \  
150 - " </method>" \  
151 - " <method name= 'getFieldAtAddress'>" \  
152 - " <arg type='u' name='addr' direction='in' />" \  
153 - " <arg type='s' name='text' direction='out' />" \  
154 - " </method>" \  
155 - " <method name= 'getFieldAtCursor'>" \  
156 - " <arg type='s' name='text' direction='out' />" \  
157 - " </method>" \  
158 " <method name= 'waitForReady'>" \ 146 " <method name= 'waitForReady'>" \
159 " <arg type='u' name='seconds' direction='in' />" \ 147 " <arg type='u' name='seconds' direction='in' />" \
160 " <arg type='i' name='result' direction='out' />" \ 148 " <arg type='i' name='result' direction='out' />" \
161 " </method>" \ 149 " </method>" \
  150 + " <method name= 'waitForUpdate'>" \
  151 + " <arg type='u' name='seconds' direction='in' />" \
  152 + " <arg type='i' name='result' direction='out' />" \
  153 + " </method>" \
162 " <method name= 'setCursorAddress'>" \ 154 " <method name= 'setCursorAddress'>" \
163 " <arg type='u' name='addr' direction='in' />" \ 155 " <arg type='u' name='addr' direction='in' />" \
164 " <arg type='s' name='text' direction='out' />" \ 156 " <arg type='s' name='text' direction='out' />" \
@@ -168,6 +160,15 @@ void ipc3270_add_terminal_introspection(GString *introspection) { @@ -168,6 +160,15 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
168 " <arg type='u' name='col' direction='in' />" \ 160 " <arg type='u' name='col' direction='in' />" \
169 " <arg type='s' name='text' direction='out' />" \ 161 " <arg type='s' name='text' direction='out' />" \
170 " </method>" \ 162 " </method>" \
  163 + " <method name= 'getFieldAttributeAt'>" \
  164 + " <arg type='u' name='row' direction='in' />" \
  165 + " <arg type='u' name='col' direction='in' />" \
  166 + " <arg type='u' name='attribute' direction='out' />" \
  167 + " </method>" \
  168 + " <method name= 'getFieldAttributeAtAddress'>" \
  169 + " <arg type='i' name='addr' direction='in' />" \
  170 + " <arg type='u' name='attribute' direction='out' />" \
  171 + " </method>" \
171 " <property type='s' name='version' access='read'/>" \ 172 " <property type='s' name='version' access='read'/>" \
172 " <property type='s' name='revision' access='read'/>" 173 " <property type='s' name='revision' access='read'/>"
173 ); 174 );
server/src/core/linux/start.c
@@ -50,28 +50,25 @@ static void @@ -50,28 +50,25 @@ static void
50 GDBusMethodInvocation *invocation, 50 GDBusMethodInvocation *invocation,
51 gpointer user_data) { 51 gpointer user_data) {
52 52
53 - g_autoptr (GError) error = NULL;  
54 - GVariant * rc; 53 + g_autoptr(GError) error = NULL;
  54 + g_autoptr(GObject) response = ipc3270_response_new();
55 55
56 debug("%s(%s,%s)",__FUNCTION__,interface_name,object_path); 56 debug("%s(%s,%s)",__FUNCTION__,interface_name,object_path);
57 57
58 - rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error); 58 + ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, response, &error);
59 59
60 if(error) { 60 if(error) {
61 61
62 - if(rc) {  
63 - g_variant_unref(rc);  
64 - }  
65 -  
66 g_dbus_method_invocation_return_gerror(invocation, error); 62 g_dbus_method_invocation_return_gerror(invocation, error);
67 63
68 - } else if(rc) { 64 + } else if(ipc3270_response_has_values(response)) {
69 65
70 // Convert rc to tuple. 66 // Convert rc to tuple.
71 // It is an error if parameters is not of the right format: it must be a tuple containing the out-parameters of the D-Bus method. 67 // It is an error if parameters is not of the right format: it must be a tuple containing the out-parameters of the D-Bus method.
72 // Even if the method has a single out-parameter, it must be contained in a tuple. 68 // Even if the method has a single out-parameter, it must be contained in a tuple.
73 69
74 - g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(&rc,1)); 70 + GVariant *values[] = { ipc3270_response_steal_value(response) };
  71 + g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(values,1));
75 72
76 } else { 73 } else {
77 74
server/src/core/methods.c
@@ -1,223 +0,0 @@ @@ -1,223 +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 <config.h>  
36 -#include <string.h>  
37 -#include <lib3270/ipc-glib.h>  
38 -#include <lib3270.h>  
39 -#include <lib3270/actions.h>  
40 -#include <lib3270/trace.h>  
41 -  
42 -// #include <dbus/dbus-glib.h>  
43 -// #include <dbus/dbus-glib-bindings.h>  
44 -  
45 -GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error)  
46 -{  
47 -  
48 - size_t ix;  
49 - H3270 * hSession = ipc3270_get_session(object);  
50 -  
51 - lib3270_trace_event(hSession,"Method %s called on session %c\n",method_name,lib3270_get_session_id(hSession));  
52 -  
53 - debug("%s(%s)",__FUNCTION__,method_name);  
54 -  
55 - if(!g_ascii_strcasecmp(method_name,"getString"))  
56 - {  
57 - return ipc3270_GVariant_from_input_string(object, lib3270_get_string_at_address(hSession,0,-1,'\n'), error);  
58 - }  
59 - else if(!g_ascii_strcasecmp(method_name,"setString"))  
60 - {  
61 - gchar *text = NULL;  
62 - g_variant_get(parameters, "(&s)", &text);  
63 -  
64 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
65 - if(lib3270_input_string(hSession,(const unsigned char *) converted, -1))  
66 - {  
67 - // Failed!  
68 - debug("%s failed: %s",method_name,strerror(errno));  
69 - ipc3270_set_error(object,errno,error);  
70 - return NULL;  
71 - }  
72 -  
73 - // Suceeded  
74 - debug("%s Suceeds",method_name);  
75 - return g_variant_new_int32(0);  
76 -  
77 - }  
78 - else if(!g_ascii_strcasecmp(method_name,"setStringAt"))  
79 - {  
80 - guint row,col;  
81 - gchar *text = NULL;  
82 - g_variant_get(parameters, "(ii&s)", &row, &col, &text);  
83 -  
84 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
85 - if(lib3270_set_string_at(hSession,row,col,(const unsigned char *) converted) < 0)  
86 - {  
87 - // Failed!  
88 - ipc3270_set_error(object,errno,error);  
89 - return NULL;  
90 - }  
91 -  
92 - // Suceeded  
93 - return g_variant_new_int32(0);  
94 -  
95 - }  
96 - else if(!g_ascii_strcasecmp(method_name,"getStringAt"))  
97 - {  
98 - guint row,col,len;  
99 - guchar lf;  
100 - g_variant_get(parameters, "(uuuy)", &row, &col, &len,&lf);  
101 -  
102 - return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at(hSession, row, col, len, lf),error);  
103 -  
104 - }  
105 - else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress"))  
106 - {  
107 - guint addr;  
108 - gchar *text = NULL;  
109 - g_variant_get(parameters, "(i&s)", &addr, &text);  
110 -  
111 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
112 - if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0)  
113 - {  
114 - // Failed!  
115 - ipc3270_set_error(object,errno,error);  
116 - return NULL;  
117 - }  
118 -  
119 - // Suceeded  
120 - return g_variant_new_int32(0);  
121 -  
122 - }  
123 - else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress"))  
124 - {  
125 - guint addr,len;  
126 - guchar lf;  
127 - g_variant_get(parameters, "(uuy)", &addr, &len, &lf);  
128 -  
129 - debug("lf=%02x",(int) lf);  
130 -  
131 - return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at_address(hSession, addr, len, lf),error);  
132 -  
133 - }  
134 - else if(!g_ascii_strcasecmp(method_name,"waitforready"))  
135 - {  
136 - guint timeout = 1;  
137 - if(parameters) {  
138 - g_variant_get(parameters, "(u)", &timeout);  
139 - }  
140 - return g_variant_new_int32((gint) lib3270_wait_for_ready(hSession,timeout));  
141 - }  
142 - else if(!g_ascii_strcasecmp(method_name,"connect"))  
143 - {  
144 - gchar *text = NULL;  
145 - g_variant_get(parameters, "(&s)", &text);  
146 -  
147 - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);  
148 - if(lib3270_connect_url(hSession,converted,0))  
149 - {  
150 - // Failed!  
151 - ipc3270_set_error(object,errno,error);  
152 - return NULL;  
153 - }  
154 -  
155 - // Suceeded  
156 - return g_variant_new_int32(0);  
157 -  
158 - }  
159 - else if(!g_ascii_strcasecmp(method_name,"disconnect"))  
160 - {  
161 - if(lib3270_disconnect(hSession))  
162 - {  
163 - // Failed!  
164 - ipc3270_set_error(object,errno,error);  
165 - return NULL;  
166 - }  
167 -  
168 - // Suceeded  
169 - return g_variant_new_int32(0);  
170 - }  
171 -  
172 -  
173 -  
174 - // Check action table.  
175 - const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();  
176 - for(ix = 0; actions[ix].name; ix++)  
177 - {  
178 - if(!g_ascii_strcasecmp(actions[ix].name,method_name)) {  
179 -  
180 - int rc = actions[ix].call(hSession);  
181 - if(rc)  
182 - {  
183 - // Failed  
184 - ipc3270_set_error(object,errno,error);  
185 - return NULL;  
186 - }  
187 -  
188 - // Suceeded  
189 - return g_variant_new_int32(0);  
190 -  
191 - }  
192 - }  
193 -  
194 - // Check int methods  
195 - const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods();  
196 -  
197 - for(ix = 0; int_methods[ix].name; ix++)  
198 - {  
199 - if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) {  
200 -  
201 - gint value;  
202 - g_variant_get(parameters, "(i)", &value);  
203 -  
204 - int rc = int_methods[ix].call(hSession, value);  
205 - if(rc)  
206 - {  
207 - // Failed  
208 - ipc3270_set_error(object,errno,error);  
209 - return NULL;  
210 - }  
211 -  
212 - // Suceeded  
213 - return g_variant_new_int32(0);  
214 -  
215 - }  
216 -  
217 - }  
218 -  
219 - g_message("Unknown method \"%s\"",method_name);  
220 -  
221 - return NULL;  
222 -  
223 -}  
server/src/core/methods/methods.c 0 → 100644
@@ -0,0 +1,258 @@ @@ -0,0 +1,258 @@
  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 <config.h>
  36 +#include <string.h>
  37 +#include <lib3270/ipc-glib.h>
  38 +#include <lib3270.h>
  39 +#include <lib3270/actions.h>
  40 +#include <lib3270/trace.h>
  41 +
  42 +void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error) {
  43 +
  44 + size_t ix;
  45 + H3270 * hSession = ipc3270_get_session(object);
  46 +
  47 + lib3270_trace_event(hSession,"Method %s called on session %c\n",method_name,lib3270_get_session_id(hSession));
  48 +
  49 + debug("%s(%s)",__FUNCTION__,method_name);
  50 +
  51 + if(!g_ascii_strcasecmp(method_name,"getString"))
  52 + {
  53 + lib3270_autoptr(char) str = lib3270_get_string_at_address(hSession,0,-1,'\n');
  54 + ipc3270_response_append_3270_string(response,str,error);
  55 + return;
  56 + }
  57 + else if(!g_ascii_strcasecmp(method_name,"setString"))
  58 + {
  59 + gchar *text = NULL;
  60 + g_variant_get(request, "(&s)", &text);
  61 +
  62 + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);
  63 + if(lib3270_input_string(hSession,(const unsigned char *) converted, -1))
  64 + {
  65 + // Failed!
  66 + debug("%s failed: %s",method_name,strerror(errno));
  67 + ipc3270_set_error(object,errno,error);
  68 + return;
  69 + }
  70 +
  71 + // Suceeded
  72 + debug("%s Suceeds",method_name);
  73 + ipc3270_response_append_int32(response, 0);
  74 + return;
  75 +
  76 + }
  77 + else if(!g_ascii_strcasecmp(method_name,"setStringAt"))
  78 + {
  79 + guint row,col;
  80 + gchar *text = NULL;
  81 + g_variant_get(request, "(ii&s)", &row, &col, &text);
  82 +
  83 + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);
  84 + if(lib3270_set_string_at(hSession,row,col,(const unsigned char *) converted) < 0)
  85 + {
  86 + // Failed!
  87 + ipc3270_set_error(object,errno,error);
  88 + return;
  89 + }
  90 +
  91 + // Suceeded
  92 + ipc3270_response_append_int32(response, 0);
  93 + return;
  94 +
  95 + }
  96 + else if(!g_ascii_strcasecmp(method_name,"getStringAt"))
  97 + {
  98 + guint row,col,len;
  99 + guchar lf;
  100 + g_variant_get(request, "(uuuy)", &row, &col, &len,&lf);
  101 +
  102 + lib3270_autoptr(char) str = lib3270_get_string_at(hSession, row, col, len, lf);
  103 + ipc3270_response_append_3270_string(response,str,error);
  104 + return;
  105 +
  106 + }
  107 + else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress"))
  108 + {
  109 + gint addr;
  110 + gchar *text = NULL;
  111 + g_variant_get(request, "(i&s)", &addr, &text);
  112 +
  113 + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);
  114 + if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0)
  115 + {
  116 + // Failed!
  117 + ipc3270_set_error(object,errno,error);
  118 + return;
  119 + }
  120 +
  121 + // Suceeded
  122 + ipc3270_response_append_int32(response, 0);
  123 + return;
  124 +
  125 + }
  126 + else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress"))
  127 + {
  128 + gint addr;
  129 + guint len;
  130 + guchar lf;
  131 + g_variant_get(request, "(iuy)", &addr, &len, &lf);
  132 +
  133 + debug("lf=%02x",(int) lf);
  134 +
  135 + lib3270_autoptr(char) str = lib3270_get_string_at_address(hSession, addr, len, lf);
  136 + ipc3270_response_append_3270_string(response,str,error);
  137 + return;
  138 +
  139 + }
  140 + else if(!g_ascii_strcasecmp(method_name,"waitforready"))
  141 + {
  142 + guint timeout = 1;
  143 + if(request) {
  144 + g_variant_get(request, "(u)", &timeout);
  145 + }
  146 + ipc3270_response_append_int32(response, lib3270_wait_for_ready(hSession,timeout));
  147 + return;
  148 +
  149 + }
  150 + else if(!g_ascii_strcasecmp(method_name,"connect"))
  151 + {
  152 + gchar *text = NULL;
  153 + g_variant_get(request, "(&s)", &text);
  154 +
  155 + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error);
  156 + if(lib3270_connect_url(hSession,converted,0))
  157 + {
  158 + // Failed!
  159 + ipc3270_set_error(object,errno,error);
  160 + return NULL;
  161 + }
  162 +
  163 + // Suceeded
  164 + ipc3270_response_append_int32(response, 0);
  165 + return;
  166 +
  167 + }
  168 + else if(!g_ascii_strcasecmp(method_name,"disconnect"))
  169 + {
  170 + if(lib3270_disconnect(hSession))
  171 + {
  172 + // Failed!
  173 + ipc3270_set_error(object,errno,error);
  174 + return;
  175 + }
  176 +
  177 + // Suceeded
  178 + ipc3270_response_append_int32(response, 0);
  179 + return;
  180 +
  181 + }
  182 + else if(!g_ascii_strcasecmp(method_name,"getFieldAttributeAt"))
  183 + {
  184 + guint row,col;
  185 + g_variant_get(request, "(uu)", &row, &col);
  186 + ipc3270_response_append_int32(response, lib3270_get_field_attribute(hSession,lib3270_translate_to_address(hSession,row,col)));
  187 + return;
  188 + }
  189 + else if(!g_ascii_strcasecmp(method_name,"getFieldAttributeAtAddress"))
  190 + {
  191 + gint addr;
  192 + g_variant_get(request, "(i)", &addr);
  193 +
  194 + ipc3270_response_append_int32(response, lib3270_get_field_attribute(hSession,addr));
  195 + return;
  196 + }
  197 + else if(!g_ascii_strcasecmp(method_name,"waitForUpdate"))
  198 + {
  199 + guint timeout = 1;
  200 + if(request) {
  201 + g_variant_get(request, "(u)", &timeout);
  202 + }
  203 +
  204 + ipc3270_response_append_int32(response, lib3270_wait_for_update(hSession,timeout));
  205 + return;
  206 + }
  207 +
  208 + // Check action table.
  209 + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
  210 + for(ix = 0; actions[ix].name; ix++)
  211 + {
  212 + if(!g_ascii_strcasecmp(actions[ix].name,method_name)) {
  213 +
  214 + int rc = actions[ix].call(hSession);
  215 + if(rc)
  216 + {
  217 + // Failed
  218 + ipc3270_set_error(object,errno,error);
  219 + return;
  220 + }
  221 +
  222 + // Suceeded
  223 + ipc3270_response_append_int32(response, 0);
  224 + return;
  225 +
  226 + }
  227 + }
  228 +
  229 + // Check int methods
  230 + const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods();
  231 +
  232 + for(ix = 0; int_methods[ix].name; ix++)
  233 + {
  234 + if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) {
  235 +
  236 + gint value;
  237 + g_variant_get(request, "(i)", &value);
  238 +
  239 + int rc = int_methods[ix].call(hSession, value);
  240 + if(rc)
  241 + {
  242 + // Failed
  243 + ipc3270_set_error(object,errno,error);
  244 + return;
  245 + }
  246 +
  247 + // Suceeded
  248 + ipc3270_response_append_int32(response, 0);
  249 + return;
  250 +
  251 + }
  252 +
  253 + }
  254 +
  255 + g_message("Unknown method \"%s\"",method_name);
  256 + ipc3270_set_error(object,ENOENT,error);
  257 +
  258 +}
server/src/testprogram/testprogram.c
@@ -127,6 +127,7 @@ @@ -127,6 +127,7 @@
127 GModule * module = NULL; 127 GModule * module = NULL;
128 128
129 gtk_widget_set_name(window,session_name); 129 gtk_widget_set_name(window,session_name);
  130 + v3270_set_session_name(terminal,session_name);
130 131
131 #ifdef _WIN32 132 #ifdef _WIN32
132 { 133 {
server/testscripts/introspect-plugin.sh
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -#!/bin/bash  
2 -gdbus \  
3 - introspect \  
4 - --session \  
5 - --dest=br.com.bb.pw3270.a \  
6 - --object-path=/br/com/bb/tn3270/session  
7 -  
server/testscripts/introspect.sh 0 → 100755
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +#!/bin/bash
  2 +gdbus \
  3 + introspect \
  4 + --session \
  5 + --dest=br.com.bb.pw3270.a \
  6 + --object-path=/br/com/bb/tn3270/session
  7 +