From 13d1732bc9ffc14209f8980dd2b20ce81f23d9c7 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 14 Aug 2019 09:53:41 -0300 Subject: [PATCH] Adjustments in the API. --- src/core/ctlr.c | 16 +++++++++++----- src/include/lib3270.h | 16 +++++++++++----- src/ssl/negotiate.c | 41 ++++++++++++++--------------------------- src/ssl/state.c | 12 ++++++------ 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/core/ctlr.c b/src/core/ctlr.c index fce1bee..ac4f2e5 100644 --- a/src/core/ctlr.c +++ b/src/core/ctlr.c @@ -515,29 +515,35 @@ LIB3270_EXPORT int lib3270_field_addr(H3270 *hSession, int baddr) return -1; } -LIB3270_EXPORT int lib3270_get_field_attribute(H3270 *hSession, int baddr) +LIB3270_EXPORT LIB3270_FIELD_ATTRIBUTE lib3270_get_field_attribute(H3270 *hSession, int baddr) { int sbaddr; FAIL_IF_NOT_ONLINE(hSession); if(!hSession->formatted) - return errno = ENOTCONN; + { + errno = ENOTCONN; + return (LIB3270_FIELD_ATTRIBUTE) 0; + } + + if(baddr < 0) + baddr = lib3270_get_cursor_address(hSession); sbaddr = baddr; do { if(hSession->ea_buf[baddr].fa) - return hSession->ea_buf[baddr].fa; + return (LIB3270_FIELD_ATTRIBUTE) hSession->ea_buf[baddr].fa; + DEC_BA(baddr); } while (baddr != sbaddr); errno = EINVAL; - return -1; + return (LIB3270_FIELD_ATTRIBUTE) 0; } - /** * @brief Get the length of the field at given buffer address. * diff --git a/src/include/lib3270.h b/src/include/lib3270.h index e01a056..5a478c7 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -547,6 +547,14 @@ LIB3270_EXPORT int lib3270_get_secure_host(H3270 *hSession); /** + * @brief Get security state. + * + */ + LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_ssl_state(H3270 *session); + + LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *session); + + /** * @brief Get security state as text. * */ @@ -971,8 +979,6 @@ LIB3270_EXPORT int lib3270_is_secure(H3270 *h); LIB3270_EXPORT LIB3270_MESSAGE lib3270_lock_status(H3270 *h); - LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session); - LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *session); /** * Run main iteration. @@ -1176,11 +1182,11 @@ * @brief Get field attribute for a given buffer address. * * @param hSession Session handle. - * @param addr Buffer address of the field. + * @param addr Buffer address of the field (-1 to use the cursor address). * - * @return field attribute or -1 when failed (sets errno). + * @return field attribute or 0 when failed (sets errno). */ - LIB3270_EXPORT int lib3270_get_field_attribute(H3270 *hSession, int baddr); + LIB3270_EXPORT LIB3270_FIELD_ATTRIBUTE lib3270_get_field_attribute(H3270 *hSession, int baddr); /** * @brief Get the length of the field at given buffer address. diff --git a/src/ssl/negotiate.c b/src/ssl/negotiate.c index 42392f5..24d342d 100644 --- a/src/ssl/negotiate.c +++ b/src/ssl/negotiate.c @@ -434,30 +434,17 @@ void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) #endif /*]*/ -int popup_ssl_error(H3270 *hSession, int rc, const char *title, const char *summary, const char *body) +int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const char *title, const char *summary, const char *body) { -#ifdef SSL_ENABLE_NOTIFICATION_WHEN_FAILED - - lib3270_write_log(hSession, "SSL", "%s", summary ); - return hSession->cbk.popup_ssl_error(hSession,rc,title,summary,body); - -#else - - lib3270_autoptr(char) message = NULL; - - if(body && *body) - message = lib3270_strdup_printf("%s - rc=%d",body,rc); - else if(rc) - message = lib3270_strdup_printf("%s (rc=%d)",strerror(rc),rc); - else - message = lib3270_strdup_printf("rc=%d",rc); - #ifdef _WIN32 + lib3270_autoptr(char) rcMessage = lib3270_strdup_printf("The error code was %d",rc); + const char *outMsg[] = { title, summary, - message + (body ? body : ""), + rcMessage }; ReportEvent( @@ -466,7 +453,7 @@ int popup_ssl_error(H3270 *hSession, int rc, const char *title, const char *summ 1, 0, NULL, - 3, + (sizeof(outMsg)/sizeof(outMsg[0])), 0, outMsg, NULL @@ -474,18 +461,18 @@ int popup_ssl_error(H3270 *hSession, int rc, const char *title, const char *summ #else - lib3270_write_log( - hSession, - "SSL", - "%s - %s - %s", - title, - summary, - message - ); + lib3270_write_log(hSession, "SSL", "%s %s (rc=%d)", summary, (body ? body : ""), rc); #endif // _WIN32 +#ifdef SSL_ENABLE_NOTIFICATION_WHEN_FAILED + + return hSession->cbk.popup_ssl_error(hSession,rc,title,summary,body); + +#else + return 0; + #endif // SSL_ENABLE_NOTIFICATION_WHEN_FAILED } diff --git a/src/ssl/state.c b/src/ssl/state.c index 13a73e5..f5b6c18 100644 --- a/src/ssl/state.c +++ b/src/ssl/state.c @@ -47,7 +47,7 @@ LIB3270_EXPORT int lib3270_is_secure(H3270 *hSession) { - return lib3270_get_secure(hSession) == LIB3270_SSL_SECURE; + return lib3270_get_ssl_state(hSession) == LIB3270_SSL_SECURE; } LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *hSession) @@ -60,7 +60,7 @@ LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *hSession) return -1; } -LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *hSession) +LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_ssl_state(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); return hSession->ssl.state; @@ -365,7 +365,7 @@ void set_ssl_state(H3270 *hSession, LIB3270_SSL_STATE state) const char * lib3270_get_ssl_state_message(H3270 *hSession) { - if(lib3270_get_secure(hSession) != LIB3270_SSL_UNSECURE) + if(lib3270_get_ssl_state(hSession) != LIB3270_SSL_UNSECURE) { const struct ssl_status_msg *info = get_ssl_status_msg(hSession); if(info) @@ -378,7 +378,7 @@ void set_ssl_state(H3270 *hSession, LIB3270_SSL_STATE state) const char * lib3270_get_ssl_state_icon_name(H3270 *hSession) { - if(lib3270_get_secure(hSession) != LIB3270_SSL_UNSECURE) + if(lib3270_get_ssl_state(hSession) != LIB3270_SSL_UNSECURE) { const struct ssl_status_msg *info = get_ssl_status_msg(hSession); if(info) @@ -392,7 +392,7 @@ void set_ssl_state(H3270 *hSession, LIB3270_SSL_STATE state) const char * lib3270_get_ssl_state_description(H3270 *hSession) { - if(lib3270_get_secure(hSession) != LIB3270_SSL_UNSECURE) + if(lib3270_get_ssl_state(hSession) != LIB3270_SSL_UNSECURE) { const struct ssl_status_msg *info = get_ssl_status_msg(hSession); if(info) @@ -408,7 +408,7 @@ void set_ssl_state(H3270 *hSession, LIB3270_SSL_STATE state) LIB3270_NOTIFY lib3270_get_ssl_state_icon(H3270 *hSession) { - if(lib3270_get_secure(hSession) != LIB3270_SSL_UNSECURE) + if(lib3270_get_ssl_state(hSession) != LIB3270_SSL_UNSECURE) { const struct ssl_status_msg *info = get_ssl_status_msg(hSession); if(info) -- libgit2 0.21.2