From 0e5fef36710bf696c70ad1c0c7228430282f38c3 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 1 Jun 2023 21:36:09 -0300 Subject: [PATCH] Since windows does not have version control in the system a new method was implemented to check if the lib3270 current revision can work with applications to avoid loading of an incomplete or incompatible version of lib3270. --- src/core/properties/signed.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/core/util.c | 4 ++++ src/include/lib3270.h | 20 ++++++++++++++++---- 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/src/core/properties/signed.c b/src/core/properties/signed.c index bba0dc8..514789d 100644 --- a/src/core/properties/signed.c +++ b/src/core/properties/signed.c @@ -38,14 +38,86 @@ static int lib3270_get_connection_state_as_int(const H3270 *hSession) { return (int) lib3270_get_connection_state(hSession); } +const char * lib3270_get_connection_state_as_string(const H3270 *hSession) { + + static const char * values[] = { + N_("Disconnected"), + N_("Connecting to host"), + N_("Connection pending"), + N_("Connected, no mode yet"), + N_("Connected in NVT ANSI mode"), + N_("Connected in old-style 3270 mode"), + N_("Connected in TN3270E mode, no negotiated"), + N_("Connected in TN3270E mode, NVT mode"), + N_("Connected in TN3270E mode, SSCP-LU mode"), + N_("Connected in TN3270E mode, 3270 mode") + }; + + size_t value = (size_t) lib3270_get_connection_state(hSession); + if(value < (sizeof(value)/sizeof(values[0]))) { + return dgettext(GETTEXT_PACKAGE,values[value]); + } + + return _( "Unknown" ); + +} + static int lib3270_get_program_message_as_int(const H3270 *hSession) { return (int) lib3270_get_program_message(hSession); } +const char * lib3270_get_program_message_as_string(const H3270 *hSession) { + + static const char * values[] = { + "", + N_( "X System" ), + N_( "X Wait" ), + N_( "X Connected" ), + N_( "X Not Connected" ), + N_( "X" ), + N_( "X -f" ), + N_( "X Protected" ), + N_( "X Numeric" ), + N_( "X Overflow" ), + N_( "X Inhibit" ), + N_( "X" ), + N_( "X" ), + N_( "X Resolving" ), + N_( "X Connecting" ) + }; + + size_t value = (size_t) lib3270_get_program_message(hSession); + if(value < (sizeof(value)/sizeof(values[0]))) { + return dgettext(GETTEXT_PACKAGE,values[value]); + } + + return _( "Unknown" ); + +} + static int lib3270_get_ssl_state_as_int(const H3270 * hSession) { return (int) lib3270_get_ssl_state(hSession); } +const char * lib3270_get_ssl_state_as_string(const H3270 * hSession) { + + static const char * values[] = { + N_("No secure connection"), + N_("Connection secure with CA check"), + N_("Connection secure, no CA, self-signed or expired CRL"), + N_("Negotiating SSL"), + N_("Verifying SSL (Getting CRL)"), + N_("Undefined") + }; + + size_t value = (size_t) lib3270_get_ssl_state(hSession); + if(value < (sizeof(value)/sizeof(values[0]))) { + return dgettext(GETTEXT_PACKAGE,values[value]); + } + + return _( "Unknown" ); +} + const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { static const LIB3270_INT_PROPERTY properties[] = { @@ -54,7 +126,8 @@ const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { .name = "cstate", // Property name. .description = N_( "Connection state" ), // Property description. .get = lib3270_get_connection_state_as_int, // Get value. - .set = NULL // Set value. + .set = NULL, // Set value. + .describe = lib3270_get_connection_state_as_string }, { @@ -62,28 +135,32 @@ const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { .group = LIB3270_ACTION_GROUP_ONLINE, // Property group. .description = N_( "Cursor address" ), // Property description. .get = lib3270_get_cursor_address, // Get value. - .set = lib3270_set_cursor_address // Set value. + .set = lib3270_set_cursor_address, // Set value. + .describe = NULL }, { - .name = "program_message", // Property name. - .description = N_( "Latest program message" ), // Property description. - .get = lib3270_get_program_message_as_int, // Get value. - .set = NULL // Set value. + .name = "program_message", // Property name. + .description = N_( "Latest program message" ), // Property description. + .get = lib3270_get_program_message_as_int, // Get value. + .set = NULL, // Set value. + .describe = lib3270_get_program_message_as_string }, { .name = "ssl_state", // Property name. .description = N_( "ID of the session security state" ), // Property description. .get = lib3270_get_ssl_state_as_int, // Get value. - .set = NULL // Set value. + .set = NULL, // Set value. + .describe = lib3270_get_ssl_state_as_string }, { .name = NULL, .description = NULL, .get = NULL, - .set = NULL + .set = NULL, // Set value. + .describe = NULL } }; diff --git a/src/core/util.c b/src/core/util.c index fe393ff..190b17f 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -239,6 +239,10 @@ LIB3270_EXPORT const char * lib3270_get_revision(void) { return RPQ_REVISION; } +LIB3270_EXPORT int lib3270_check_revision(const char GNUC_UNUSED(*revision)) { + return 0; +} + LIB3270_EXPORT const char * lib3270_get_product_name(void) { return LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME); } diff --git a/src/include/lib3270.h b/src/include/lib3270.h index bc0d54d..d9d55a9 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -94,6 +94,9 @@ #define LIB3270_STRINGIZE(x) #x #define LIB3270_STRINGIZE_VALUE_OF(x) LIB3270_STRINGIZE(x) +typedef struct _h3270 H3270; +typedef struct _h3270ft H3270FT; + /** * @brief BIND definitions. */ @@ -368,7 +371,8 @@ typedef enum _lib3270_action_group { const char * label; \ const char * icon; \ const char * summary; \ - const char * description; + const char * description; \ + const char * (*describe)(const H3270 *); typedef struct _lib3270_property { LIB3270_PROPERTY_HEAD @@ -393,9 +397,6 @@ typedef enum _lib3270_state { LIB3270_STATE_USER // Always the last one } LIB3270_STATE; -typedef struct _h3270 H3270; -typedef struct _h3270ft H3270FT; - /** * Get current screen size. * @@ -1490,6 +1491,17 @@ LIB3270_EXPORT const char * lib3270_get_version(void); */ LIB3270_EXPORT const char * lib3270_get_revision(void); +/** + * @brief Test if the revision is valid. + * + * @param revision Revision number to check. + * + * @return 0 if the supplied revision is valid to the current library. + * + */ +LIB3270_EXPORT int lib3270_check_revision(const char *revision); + + LIB3270_EXPORT char * lib3270_vsprintf(const char *fmt, va_list args); LIB3270_EXPORT char * lib3270_strdup_printf(const char *fmt, ...); -- libgit2 0.21.2