Commit c1df1fe6239073a5fa1e5d5151d1350c04e7c17c
1 parent
3bacf3c5
Exists in
master
and in
3 other branches
Refactoring popup engine.
Showing
4 changed files
with
109 additions
and
24 deletions
Show diff stats
src/core/popup.c
| ... | ... | @@ -116,3 +116,25 @@ LIB3270_EXPORT void lib3270_popup_va(H3270 *hSession, LIB3270_NOTIFY id , const |
| 116 | 116 | hSession->cbk.popup_show(hSession,&popup,0); |
| 117 | 117 | |
| 118 | 118 | } |
| 119 | + | |
| 120 | +LIB3270_POPUP * lib3270_popup_clone_printf(const LIB3270_POPUP *origin, const char *fmt, ...) | |
| 121 | +{ | |
| 122 | + va_list args; | |
| 123 | + | |
| 124 | + // Create body | |
| 125 | + lib3270_autoptr(char) body = NULL; | |
| 126 | + | |
| 127 | + va_start(args, fmt); | |
| 128 | + body = lib3270_vsprintf(fmt, args); | |
| 129 | + va_end(args); | |
| 130 | + | |
| 131 | + // Alocate new struct | |
| 132 | + LIB3270_POPUP * popup = lib3270_malloc(sizeof(LIB3270_POPUP)+strlen(body)+1); | |
| 133 | + | |
| 134 | + *popup = *origin; | |
| 135 | + | |
| 136 | + strcpy((char *)(popup+1),body); | |
| 137 | + popup->body = (char *)(popup+1); | |
| 138 | + return popup; | |
| 139 | +} | |
| 140 | + | ... | ... |
src/include/lib3270/popup.h
| ... | ... | @@ -90,6 +90,17 @@ |
| 90 | 90 | LIB3270_EXPORT const char * lib3270_get_ssl_state_icon_name(const H3270 *hSession); |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | + * @brief Clone popup object replacing the body contents. | |
| 94 | + * | |
| 95 | + * @param origin Original popup definition. | |
| 96 | + * @param fmt Printf formatting string. | |
| 97 | + * | |
| 98 | + * @return New popup object with the body replaced (release it with g_free). | |
| 99 | + * | |
| 100 | + */ | |
| 101 | + LIB3270_EXPORT LIB3270_POPUP * lib3270_popup_clone_printf(const LIB3270_POPUP *origin, const char *fmt, ...); | |
| 102 | + | |
| 103 | + /** | |
| 93 | 104 | * @brief Emit popup message. |
| 94 | 105 | * |
| 95 | 106 | * @param hSession TN3270 Session handle. | ... | ... |
src/ssl/negotiate.c
| ... | ... | @@ -458,11 +458,10 @@ int ssl_negotiate(H3270 *hSession) |
| 458 | 458 | |
| 459 | 459 | rc = lib3270_run_task(hSession, background_ssl_negotiation, &msg); |
| 460 | 460 | |
| 461 | + debug("background_ssl_negotiation exits with rc=%d",rc); | |
| 461 | 462 | if(rc && msg.popup) |
| 462 | 463 | { |
| 463 | 464 | // SSL Negotiation has failed. |
| 464 | - host_disconnect(hSession,1); // Disconnect with "failed" status. | |
| 465 | - | |
| 466 | 465 | if(popup_ssl_error(hSession,rc,&msg)) |
| 467 | 466 | { |
| 468 | 467 | host_disconnect(hSession,1); // Disconnect with "failed" status. | ... | ... |
src/ssl/notify.c
| ... | ... | @@ -57,44 +57,97 @@ static LIB3270_POPUP * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, |
| 57 | 57 | { |
| 58 | 58 | LIB3270_POPUP * popup; |
| 59 | 59 | |
| 60 | - if(msg->popup->body) | |
| 60 | + printf("\n\nMSG-CODE=%d\n\n",msg->code); | |
| 61 | + | |
| 62 | + if(msg->code) | |
| 61 | 63 | { |
| 62 | - popup = lib3270_malloc(sizeof(LIB3270_POPUP)); | |
| 63 | - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP)); | |
| 64 | - popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body); | |
| 64 | + if(msg->popup->body) | |
| 65 | + { | |
| 66 | + popup = lib3270_popup_clone_printf( | |
| 67 | + msg->popup, | |
| 68 | + _( "%s\nThe SSL error message was \"%s\"(%d)" ), | |
| 69 | + dgettext(GETTEXT_PACKAGE,msg->popup->body), | |
| 70 | + ERR_reason_error_string(msg->code), | |
| 71 | + msg->code | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + else | |
| 75 | + { | |
| 76 | + popup = lib3270_popup_clone_printf( | |
| 77 | + msg->popup, | |
| 78 | + _( "The SSL error message was \"%s\" (%d)" ), | |
| 79 | + ERR_reason_error_string(msg->code), | |
| 80 | + msg->code | |
| 81 | + ); | |
| 82 | + } | |
| 83 | + | |
| 65 | 84 | } |
| 66 | - else | |
| 85 | +#ifdef _WIN32 | |
| 86 | + else if(msg->lasterror) | |
| 67 | 87 | { |
| 68 | - lib3270_autoptr(char) body = NULL; | |
| 69 | - if(msg->code) | |
| 88 | + lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror); | |
| 89 | + | |
| 90 | + if(msg->popup->body) | |
| 70 | 91 | { |
| 71 | - body = lib3270_strdup_printf(_( "%s (SSL error %d)" ),ERR_reason_error_string(msg->code),msg->code); | |
| 92 | + popup = lib3270_popup_clone_printf( | |
| 93 | + msg->popup, | |
| 94 | + _( "%s\nThe windows error was \"%s\" (%u)" ), | |
| 95 | + dgettext(GETTEXT_PACKAGE,msg->popup->body), | |
| 96 | + windows_error, | |
| 97 | + (unsigned int) msg->lasterror | |
| 98 | + ); | |
| 72 | 99 | } |
| 73 | -#ifdef _WIN32 | |
| 74 | - else if(msg->lasterror) | |
| 100 | + else | |
| 75 | 101 | { |
| 76 | - lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror); | |
| 77 | - body = lib3270_strdup_printf(_( "Windows error was \"%s\" (%u)" ), windows_error,(unsigned int) msg->lasterror); | |
| 102 | + popup = lib3270_popup_clone_printf( | |
| 103 | + msg->popup, | |
| 104 | + _( "Windows error was \"%s\" (%u)" ), | |
| 105 | + windows_error, | |
| 106 | + (unsigned int) msg->lasterror | |
| 107 | + ); | |
| 78 | 108 | } |
| 79 | -#endif | |
| 80 | - else if(rc) { | |
| 81 | - body = lib3270_strdup_printf(_( "%s (rc=%d)" ),strerror(rc),rc); | |
| 109 | + | |
| 110 | + } | |
| 111 | +#endif // _WIN32 | |
| 112 | + else if(rc) | |
| 113 | + { | |
| 114 | + if(msg->popup->body) | |
| 115 | + { | |
| 116 | + popup = lib3270_popup_clone_printf( | |
| 117 | + msg->popup, | |
| 118 | + _( "%s\nThe operating system error was \"%s\" (%u)" ), | |
| 119 | + dgettext(GETTEXT_PACKAGE,msg->popup->body), | |
| 120 | + strerror(rc), | |
| 121 | + rc | |
| 122 | + ); | |
| 123 | + } | |
| 124 | + else | |
| 125 | + { | |
| 126 | + popup = lib3270_popup_clone_printf( | |
| 127 | + msg->popup, | |
| 128 | + _( "The operating system error was \"%s\" (%u)" ), | |
| 129 | + strerror(rc), | |
| 130 | + rc | |
| 131 | + ); | |
| 82 | 132 | } |
| 83 | 133 | |
| 84 | - popup = lib3270_malloc(sizeof(LIB3270_POPUP)+strlen(body)+1); | |
| 85 | - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP)); | |
| 86 | - popup->body = (char *) (popup+1); | |
| 87 | - strcpy((char *) (popup+1),body); | |
| 134 | + } | |
| 135 | + else | |
| 136 | + { | |
| 137 | + popup = lib3270_malloc(sizeof(LIB3270_POPUP)); | |
| 138 | + *popup = *msg->popup; | |
| 139 | + | |
| 140 | + if(msg->popup->body) | |
| 141 | + popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body); | |
| 88 | 142 | |
| 89 | 143 | } |
| 90 | 144 | |
| 91 | - if(popup->summary) | |
| 92 | - popup->summary = dgettext(GETTEXT_PACKAGE,popup->summary); | |
| 145 | + popup->summary = dgettext(GETTEXT_PACKAGE,msg->popup->summary); | |
| 93 | 146 | |
| 94 | 147 | if(popup->title) |
| 95 | 148 | popup->title = dgettext(GETTEXT_PACKAGE,popup->title); |
| 96 | 149 | else |
| 97 | - popup->title = _("Security alert"); | |
| 150 | + popup->title = _("Your connection is not safe"); | |
| 98 | 151 | |
| 99 | 152 | popup->label = _("Continue"); |
| 100 | 153 | return popup; | ... | ... |