diff --git a/src/core/session.c b/src/core/session.c index 7d920d2..f5e94d2 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -233,6 +233,18 @@ static void def_popup(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(type), const ch #endif // ANDROID } +static int def_popup_show(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char GNUC_UNUSED wait) +{ + lib3270_popup_dialog( + hSession, + popup->type, + popup->title, + popup->summary, + "%s", popup->body + ); + return ENOTSUP; +} + static int def_popup_ssl_error(H3270 *session, int GNUC_UNUSED(rc), const char *title, const char *summary, const char *body) { lib3270_popup_dialog(session, LIB3270_NOTIFY_ERROR, title, summary, "%s", body); @@ -305,8 +317,6 @@ void lib3270_reset_callbacks(H3270 *hSession) hSession->cbk.update_selection = update_selection; hSession->cbk.cursor = set_cursor; hSession->cbk.message = message; - hSession->cbk.popup = def_popup; - hSession->cbk.popup_ssl_error = def_popup_ssl_error; hSession->cbk.update_ssl = update_ssl; hSession->cbk.display = screen_disp; hSession->cbk.set_width = nop_int; @@ -319,6 +329,11 @@ void lib3270_reset_callbacks(H3270 *hSession) hSession->cbk.set_peer_certificate = set_peer_certificate; hSession->cbk.update_luname = default_update_luname; hSession->cbk.update_url = default_update_url; + + hSession->cbk.popup = def_popup; + hSession->cbk.popup_ssl_error = def_popup_ssl_error; + hSession->cbk.popup_show = def_popup_show; + } static void lib3270_session_init(H3270 *hSession, const char *model, const char *charset) diff --git a/src/core/util.c b/src/core/util.c index 65f964a..d164072 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -305,6 +305,15 @@ LIB3270_EXPORT void lib3270_autoptr_cleanup_char(char **ptr) } } +LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr) +{ + if(ptr && *ptr) + { + free((void *) *ptr); + *ptr = NULL; + } +} + LIB3270_EXPORT void * lib3270_realloc(void *p, int len) { p = realloc(p, len); diff --git a/src/include/internals.h b/src/include/internals.h index 94b83d2..a08358b 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -795,7 +795,7 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); DWORD lasterror; #endif // _WIN32 - const LIB3270_POPUP_DESCRIPTOR *popup; /// @brief Pointer to popup message. + const LIB3270_POPUP *popup; /// @brief Pointer to popup message. } SSL_ERROR_MESSAGE; diff --git a/src/include/lib3270/popup.h b/src/include/lib3270/popup.h index 330ea5f..de7edf8 100644 --- a/src/include/lib3270/popup.h +++ b/src/include/lib3270/popup.h @@ -64,10 +64,10 @@ const char * summary; \ const char * body; - typedef struct _lib3270_popup_descriptor + typedef struct _LIB3270_POPUP { LIB3270_POPUP_HEAD - } LIB3270_POPUP_DESCRIPTOR; + } LIB3270_POPUP; LIB3270_EXPORT void lib3270_set_popup_handler(H3270 *session, void (*handler)(H3270 *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)); @@ -100,7 +100,13 @@ * @retval 0 User has confirmed, continue action. * @retval ECANCELED Operation was cancelled. */ - LIB3270_EXPORT int lib3270_emit_popup(H3270 *hSession, const LIB3270_POPUP_DESCRIPTOR *popup, unsigned char wait); + LIB3270_EXPORT int lib3270_popup_show(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char wait); + + /** + * @brief Auto cleanup method (for use with lib3270_autoptr). + * + */ + LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr); #ifdef __cplusplus } diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 676e77f..523294d 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -82,8 +82,10 @@ int (*load)(H3270 *hSession, const char *filename); void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); + void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list); int (*popup_ssl_error)(H3270 *session, int rc, const char *title, const char *summary, const char *body); + int (*popup_show)(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char wait); #ifdef HAVE_LIBSSL void (*set_peer_certificate)(const X509 *cert); diff --git a/src/ssl/crl.c b/src/ssl/crl.c index c6b6683..f5e7aec 100644 --- a/src/ssl/crl.c +++ b/src/ssl/crl.c @@ -161,7 +161,7 @@ int lib3270_crl_new_from_x509(H3270 *hSession, void *ssl_error, X509 *cert) if(!dist_points) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .name = "SSL-NoDistPoints", .type = LIB3270_NOTIFY_SECURE, .summary = N_("Can't verify"), diff --git a/src/ssl/linux/getcrl.c b/src/ssl/linux/getcrl.c index a2d5e73..98f287c 100644 --- a/src/ssl/linux/getcrl.c +++ b/src/ssl/linux/getcrl.c @@ -51,7 +51,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co if(!(consturl && *consturl)) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .name = "SSL-INVCRLURL", .summary = N_( "Can't open CRL File" ), @@ -73,7 +73,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co // Can't open CRL File. int err = errno; - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .name = "SSL-CRLOPEN", .summary = N_( "Can't open CRL File" ) @@ -91,7 +91,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co trace_ssl(hSession,"Loading CRL from %s\n",consturl+7); if(d2i_X509_CRL_fp(hCRL, &x509_crl)) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .name = "SSL-CRLDECODE", .summary = N_( "Can't decode CRL" ) diff --git a/src/ssl/linux/init.c b/src/ssl/linux/init.c index f6f72a6..abc481d 100644 --- a/src/ssl/linux/init.c +++ b/src/ssl/linux/init.c @@ -85,7 +85,7 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) ssl_ctx = SSL_CTX_new(SSLv23_method()); if(ssl_ctx == NULL) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .name = "SSL-CTXERROR", .type = LIB3270_NOTIFY_SECURE, .summary = N_( "Cant initialize the SSL context." ) diff --git a/src/ssl/linux/url.c b/src/ssl/linux/url.c index 0e02e90..44809de 100644 --- a/src/ssl/linux/url.c +++ b/src/ssl/linux/url.c @@ -63,7 +63,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE if(!httpText) { - LIB3270_POPUP_DESCRIPTOR popup = { + LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .name = "SSL-CantGetCRL", .summary = N_( "Error getting certificate revocation list" ), @@ -82,7 +82,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE char * data = strstr((char *) httpText,":: "); if(!data) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .summary = N_( "Got a bad formatted certificate revocation list from LDAP server" ) }; @@ -104,7 +104,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE if(!d2i_X509_CRL_bio(bio, &x509_crl)) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .summary = N_( "Can't decode certificate revocation list got from LDAP server" ) }; @@ -126,7 +126,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE if(!d2i_X509_CRL(&x509_crl, &crl_data, szText)) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .summary = N_( "Can't decode certificate revocation list" ) }; diff --git a/src/ssl/negotiate.c b/src/ssl/negotiate.c index a222e59..fe906c8 100644 --- a/src/ssl/negotiate.c +++ b/src/ssl/negotiate.c @@ -103,7 +103,7 @@ static int background_ssl_init(H3270 *hSession, void *message) hSession->ssl.con = SSL_new(ssl_ctx); if(hSession->ssl.con == NULL) { - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_SECURE, .summary = N_( "Cant create a new SSL structure for current connection." ) }; @@ -242,7 +242,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) { trace_ssl(hSession,"%s","SSL_set_fd failed!\n"); - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .summary = N_( "SSL negotiation failed" ), .body = N_( "Cant set the file descriptor for the input/output facility for the TLS/SSL (encrypted) side of ssl." ) }; @@ -277,7 +277,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) trace_ssl(hSession,"SSL_connect failed: %s %s\n",msg,ERR_reason_error_string(hSession->ssl.error)); - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .type = LIB3270_NOTIFY_ERROR, .summary = N_( "SSL Connect failed" ), }; @@ -375,7 +375,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) trace_ssl(hSession,"Unexpected or invalid TLS/SSL verify result %d\n",rv); set_ssl_state(hSession,LIB3270_SSL_UNSECURE); - static LIB3270_POPUP_DESCRIPTOR popup = { + static LIB3270_POPUP popup = { .summary = N_( "Can't verify." ), .body = N_( "Unexpected or invalid TLS/SSL verify result" ) }; @@ -400,7 +400,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED); #ifdef SSL_ENABLE_SELF_SIGNED_CERT_CHECK - static const LIB3270_POPUP_DESCRIPTOR popup = { + static const LIB3270_POPUP popup = { .name = "SelfSignedCert", .type = LIB3270_NOTIFY_SECURE, .summary = N_( "The SSL certificate for this host is not trusted." ), @@ -415,7 +415,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message) default: trace_ssl(hSession,"TLS/SSL verify result was %d (%s)\n", rv, msg->body); - ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP_DESCRIPTOR *) msg; + ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP *) msg; debug("message: %s",((SSL_ERROR_MESSAGE *) message)->popup->summary); debug("description: %s",((SSL_ERROR_MESSAGE *) message)->popup->body); @@ -472,7 +472,7 @@ int ssl_negotiate(H3270 *hSession) } else if(rc) { // SSL Negotiation has failed, no popup to present. - const LIB3270_POPUP_DESCRIPTOR popup = { + const LIB3270_POPUP popup = { .summary = N_("SSL negotiation has failed") }; @@ -514,7 +514,7 @@ int ssl_init(H3270 *hSession) { } else { - LIB3270_POPUP_DESCRIPTOR popup = { + LIB3270_POPUP popup = { .summary = N_("Unexpected error on SSL initialization") }; diff --git a/src/ssl/notify.c b/src/ssl/notify.c index 6d1c3fd..f7f6c22 100644 --- a/src/ssl/notify.c +++ b/src/ssl/notify.c @@ -52,14 +52,14 @@ * @return Dynamically allocated popup description. * */ -static LIB3270_POPUP_DESCRIPTOR * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc) +static LIB3270_POPUP * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc) { - LIB3270_POPUP_DESCRIPTOR * popup; + LIB3270_POPUP * popup; if(msg->popup->body) { - popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR)); - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR)); + popup = lib3270_malloc(sizeof(LIB3270_POPUP)); + memcpy(popup,msg->popup,sizeof(LIB3270_POPUP)); popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body); } else @@ -80,8 +80,8 @@ static LIB3270_POPUP_DESCRIPTOR * translate_ssl_error_message(const SSL_ERROR_ME body = lib3270_strdup_printf(_( "%s (rc=%d)" ),strerror(rc),rc); } - popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR)+strlen(body)+1); - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR)); + 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); @@ -103,7 +103,7 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAG { int response = 0; - LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0); + LIB3270_POPUP * popup = translate_ssl_error_message(msg,0); #ifdef _WIN32 @@ -154,17 +154,8 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAG void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg) { - LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0); - - lib3270_popup_dialog( - hSession, - popup->type, - popup->title, - popup->summary, - "%s", popup->body - ); - - lib3270_free(popup); + lib3270_autoptr(LIB3270_POPUP) * popup = translate_ssl_error_message(msg,0); + hSession->cbk.popup_show(hSession,popup,0); } -- libgit2 0.21.2