From c1df1fe6239073a5fa1e5d5151d1350c04e7c17c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 23 Jul 2020 12:13:49 -0300 Subject: [PATCH] Refactoring popup engine. --- src/core/popup.c | 22 ++++++++++++++++++++++ src/include/lib3270/popup.h | 11 +++++++++++ src/ssl/negotiate.c | 3 +-- src/ssl/notify.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- 4 files changed, 109 insertions(+), 24 deletions(-) diff --git a/src/core/popup.c b/src/core/popup.c index 501e051..073e9bb 100644 --- a/src/core/popup.c +++ b/src/core/popup.c @@ -116,3 +116,25 @@ LIB3270_EXPORT void lib3270_popup_va(H3270 *hSession, LIB3270_NOTIFY id , const hSession->cbk.popup_show(hSession,&popup,0); } + +LIB3270_POPUP * lib3270_popup_clone_printf(const LIB3270_POPUP *origin, const char *fmt, ...) +{ + va_list args; + + // Create body + lib3270_autoptr(char) body = NULL; + + va_start(args, fmt); + body = lib3270_vsprintf(fmt, args); + va_end(args); + + // Alocate new struct + LIB3270_POPUP * popup = lib3270_malloc(sizeof(LIB3270_POPUP)+strlen(body)+1); + + *popup = *origin; + + strcpy((char *)(popup+1),body); + popup->body = (char *)(popup+1); + return popup; +} + diff --git a/src/include/lib3270/popup.h b/src/include/lib3270/popup.h index 08627d8..a9077a5 100644 --- a/src/include/lib3270/popup.h +++ b/src/include/lib3270/popup.h @@ -90,6 +90,17 @@ LIB3270_EXPORT const char * lib3270_get_ssl_state_icon_name(const H3270 *hSession); /** + * @brief Clone popup object replacing the body contents. + * + * @param origin Original popup definition. + * @param fmt Printf formatting string. + * + * @return New popup object with the body replaced (release it with g_free). + * + */ + LIB3270_EXPORT LIB3270_POPUP * lib3270_popup_clone_printf(const LIB3270_POPUP *origin, const char *fmt, ...); + + /** * @brief Emit popup message. * * @param hSession TN3270 Session handle. diff --git a/src/ssl/negotiate.c b/src/ssl/negotiate.c index fe906c8..c92c55d 100644 --- a/src/ssl/negotiate.c +++ b/src/ssl/negotiate.c @@ -458,11 +458,10 @@ int ssl_negotiate(H3270 *hSession) rc = lib3270_run_task(hSession, background_ssl_negotiation, &msg); + debug("background_ssl_negotiation exits with rc=%d",rc); if(rc && msg.popup) { // SSL Negotiation has failed. - host_disconnect(hSession,1); // Disconnect with "failed" status. - if(popup_ssl_error(hSession,rc,&msg)) { host_disconnect(hSession,1); // Disconnect with "failed" status. diff --git a/src/ssl/notify.c b/src/ssl/notify.c index 75df4fe..f8d5534 100644 --- a/src/ssl/notify.c +++ b/src/ssl/notify.c @@ -57,44 +57,97 @@ static LIB3270_POPUP * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, { LIB3270_POPUP * popup; - if(msg->popup->body) + printf("\n\nMSG-CODE=%d\n\n",msg->code); + + if(msg->code) { - popup = lib3270_malloc(sizeof(LIB3270_POPUP)); - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP)); - popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body); + if(msg->popup->body) + { + popup = lib3270_popup_clone_printf( + msg->popup, + _( "%s\nThe SSL error message was \"%s\"(%d)" ), + dgettext(GETTEXT_PACKAGE,msg->popup->body), + ERR_reason_error_string(msg->code), + msg->code + ); + } + else + { + popup = lib3270_popup_clone_printf( + msg->popup, + _( "The SSL error message was \"%s\" (%d)" ), + ERR_reason_error_string(msg->code), + msg->code + ); + } + } - else +#ifdef _WIN32 + else if(msg->lasterror) { - lib3270_autoptr(char) body = NULL; - if(msg->code) + lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror); + + if(msg->popup->body) { - body = lib3270_strdup_printf(_( "%s (SSL error %d)" ),ERR_reason_error_string(msg->code),msg->code); + popup = lib3270_popup_clone_printf( + msg->popup, + _( "%s\nThe windows error was \"%s\" (%u)" ), + dgettext(GETTEXT_PACKAGE,msg->popup->body), + windows_error, + (unsigned int) msg->lasterror + ); } -#ifdef _WIN32 - else if(msg->lasterror) + else { - lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror); - body = lib3270_strdup_printf(_( "Windows error was \"%s\" (%u)" ), windows_error,(unsigned int) msg->lasterror); + popup = lib3270_popup_clone_printf( + msg->popup, + _( "Windows error was \"%s\" (%u)" ), + windows_error, + (unsigned int) msg->lasterror + ); } -#endif - else if(rc) { - body = lib3270_strdup_printf(_( "%s (rc=%d)" ),strerror(rc),rc); + + } +#endif // _WIN32 + else if(rc) + { + if(msg->popup->body) + { + popup = lib3270_popup_clone_printf( + msg->popup, + _( "%s\nThe operating system error was \"%s\" (%u)" ), + dgettext(GETTEXT_PACKAGE,msg->popup->body), + strerror(rc), + rc + ); + } + else + { + popup = lib3270_popup_clone_printf( + msg->popup, + _( "The operating system error was \"%s\" (%u)" ), + strerror(rc), + rc + ); } - popup = lib3270_malloc(sizeof(LIB3270_POPUP)+strlen(body)+1); - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP)); - popup->body = (char *) (popup+1); - strcpy((char *) (popup+1),body); + } + else + { + popup = lib3270_malloc(sizeof(LIB3270_POPUP)); + *popup = *msg->popup; + + if(msg->popup->body) + popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body); } - if(popup->summary) - popup->summary = dgettext(GETTEXT_PACKAGE,popup->summary); + popup->summary = dgettext(GETTEXT_PACKAGE,msg->popup->summary); if(popup->title) popup->title = dgettext(GETTEXT_PACKAGE,popup->title); else - popup->title = _("Security alert"); + popup->title = _("Your connection is not safe"); popup->label = _("Continue"); return popup; -- libgit2 0.21.2