From 12c9a65eebe8cb012bf0684d18f27375c625a7e5 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 14 Aug 2019 13:23:52 -0300 Subject: [PATCH] Refactoring IPC server. --- client/src/core/host.cc | 2 +- client/src/include/ipc-client-internals.h | 2 ++ client/src/session/local/session.cc | 4 ++++ client/src/session/remote/session.cc | 9 +++++++++ common/src/include/lib3270/ipc-glib.h | 21 ++++++++++++++++++++- common/src/include/lib3270/ipc.h | 33 ++++++++++++++++++++++++++++++++- server/Makefile.in | 1 + server/pw3270-plugin-ipc.cbp | 5 ++++- server/src/core/linux/gobject.c | 27 ++++++++++++++------------- server/src/core/linux/start.c | 15 ++++++--------- server/src/core/methods.c | 223 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- server/src/core/methods/methods.c | 258 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ server/src/testprogram/testprogram.c | 1 + server/testscripts/introspect-plugin.sh | 7 ------- server/testscripts/introspect.sh | 7 +++++++ 15 files changed, 359 insertions(+), 256 deletions(-) delete mode 100644 server/src/core/methods.c create mode 100644 server/src/core/methods/methods.c delete mode 100755 server/testscripts/introspect-plugin.sh create mode 100755 server/testscripts/introspect.sh diff --git a/client/src/core/host.cc b/client/src/core/host.cc index 5dc5684..6748a61 100644 --- a/client/src/core/host.cc +++ b/client/src/core/host.cc @@ -110,7 +110,7 @@ } bool Host::isReady() const { - this->session->waitForReady(this->timeout); +// this->session->waitForReady(this->timeout); return getProgramMessage() == MESSAGE_NONE; } diff --git a/client/src/include/ipc-client-internals.h b/client/src/include/ipc-client-internals.h index 182f0f1..f96c2d7 100644 --- a/client/src/include/ipc-client-internals.h +++ b/client/src/include/ipc-client-internals.h @@ -192,6 +192,7 @@ std::string getRevision() const override; std::string getLUName() const override; std::string getHostURL() const override; + SSLState getSSLState() const override; unsigned short getScreenWidth() const override; unsigned short getScreenHeight() const override; @@ -373,6 +374,7 @@ std::string getRevision() const override; std::string getLUName() const override; std::string getHostURL() const override; + SSLState getSSLState() const override; unsigned short getScreenWidth() const override; unsigned short getScreenHeight() const override; diff --git a/client/src/session/local/session.cc b/client/src/session/local/session.cc index 99d7e2a..17d6522 100644 --- a/client/src/session/local/session.cc +++ b/client/src/session/local/session.cc @@ -695,6 +695,10 @@ return (unsigned short) lib3270_get_length(hSession); } + TN3270::SSLState Local::Session::getSSLState() const override { + return lib3270_get_secure(hSession); + } + } diff --git a/client/src/session/remote/session.cc b/client/src/session/remote/session.cc index 05a2a79..fad6a5e 100644 --- a/client/src/session/remote/session.cc +++ b/client/src/session/remote/session.cc @@ -447,6 +447,15 @@ int value; getProperty("length",value); return (unsigned short) value; + + } + + TN3270::SSLState Local::Session::getSSLState() const override { + + int value; + getProperty("sslstate",value); + return (TN3270::SSLState) value; + } } diff --git a/common/src/include/lib3270/ipc-glib.h b/common/src/include/lib3270/ipc-glib.h index 05881e7..7412103 100644 --- a/common/src/include/lib3270/ipc-glib.h +++ b/common/src/include/lib3270/ipc-glib.h @@ -61,6 +61,25 @@ G_BEGIN_DECLS + #define GLIB_TYPE_IPC3270_RESPONSE (ipc3270Response_get_type ()) + #define IPC3270_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLIB_TYPE_IPC3270_RESPONSE, ipc3270Response)) + #define IPC3270_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIB_TYPE_IPC3270_RESPONSE, ipc3270ResponseClass)) + #define IS_IPC3270_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLIB_TYPE_IPC3270_RESPONSE)) + #define IS_IPC3270_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLIB_TYPE_IPC3270_RESPONSE)) + #define IPC3270_RESPONSE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS ((obj), GLIB_TYPE_IPC3270_RESPONSE, ipc3270ResponseClass)) + + typedef struct _ipc3270Response ipc3270Response; + typedef struct _ipc3270ResponseClass ipc3270ResponseClass; + + GObject * ipc3270_response_new(); + + void ipc3270_response_append_int32(GObject *object, gint32 value); + void ipc3270_response_append_uint32(GObject *object, guint32 value); + void ipc3270_response_append_3270_string(GObject *object, const char *text, GError **error); + gboolean ipc3270_response_has_values(GObject *object); + GVariant * ipc3270_response_steal_value(GObject *object); + + #define GLIB_TYPE_IPC3270 (ipc3270_get_type ()) #define IPC3270(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLIB_TYPE_IPC3270, ipc3270)) #define IPC3270_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLIB_TYPE_IPC3270, ipc3270Class)) @@ -121,7 +140,7 @@ void ipc3270_set_error(GObject *object, int errcode, GError **error); - GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error); + void ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error); gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error); diff --git a/common/src/include/lib3270/ipc.h b/common/src/include/lib3270/ipc.h index 0e5f8c4..faac8ac 100644 --- a/common/src/include/lib3270/ipc.h +++ b/common/src/include/lib3270/ipc.h @@ -141,6 +141,14 @@ CONNECTED_TN3270E = LIB3270_CONNECTED_TN3270E, ///< @brief connected in TN3270E mode, 3270 mode }; + enum SSLState : uint8_t { + SSL_UNSECURE = LIB3270_SSL_UNSECURE, ///< @brief No secure connection + SSL_SECURE = LIB3270_SSL_SECURE, ///< @brief Connection secure with CA check + SSL_NEGOTIATED = LIB3270_SSL_NEGOTIATED, ///< @brief Connection secure, no CA, self-signed or expired CRL + SSL_NEGOTIATING = LIB3270_SSL_NEGOTIATING, ///< @brief Negotiating SSL + SSL_UNDEFINED = LIB3270_SSL_UNDEFINED ///< @brief Undefined + }; + /// @brief PF Keys enum PFKey : uint8_t { PF_1, @@ -270,10 +278,20 @@ return getConnectionState(); } - inline bool operator==(ConnectionState state) const noexcept { + inline bool operator==(ConnectionState state) const { return this->getConnectionState() == state; } + virtual SSLState getSSLState() const = 0; + + inline operator SSLState() const { + return getSSLState(); + } + + inline bool operator==(SSLState state) const { + return this->getSSLState() == state; + } + // Set properties. virtual void setUnlockDelay(unsigned short delay = 350) = 0; void setCharSet(const char *charset); @@ -335,6 +353,19 @@ /// @brief Wait for update. virtual Session & wait_for_update(unsigned short seconds) = 0; + /// @brief Wait for string. + /// + /// @return 0 if the string was found, error code if not. + int wait(int row, int col, const char *key, unsigned short seconds); + int wait(int baddr, const char *key, unsigned short seconds); + + /// @brief Search + size_t find(const char * str, size_t pos = 0) const; + + /// @brief Compare contents. + int compare(size_t baddr, const char* s, size_t len) const; + int compare(int row, int col, const char* s, size_t len) const; + }; /// @brief TN3270 Host diff --git a/server/Makefile.in b/server/Makefile.in index 4acf718..e89ae31 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -32,6 +32,7 @@ PACKAGE_NAME=@PACKAGE_NAME@ CORE_SOURCES= \ $(wildcard src/core/*.c) \ + $(wildcard src/core/methods/*.c) \ $(wildcard src/core/@OSNAME@/*.c) PLUGIN_SOURCES= \ diff --git a/server/pw3270-plugin-ipc.cbp b/server/pw3270-plugin-ipc.cbp index f3de793..7b92da2 100644 --- a/server/pw3270-plugin-ipc.cbp +++ b/server/pw3270-plugin-ipc.cbp @@ -73,13 +73,16 @@