Commit 63cb8e62f509ee752fab886a995b41c0c3a581da

Authored by Perry Werneck
1 parent ca2f1d62

Refactoring popup engine.

src/core/session.c
... ... @@ -233,6 +233,18 @@ static void def_popup(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(type), const ch
233 233 #endif // ANDROID
234 234 }
235 235  
  236 +static int def_popup_show(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char GNUC_UNUSED wait)
  237 +{
  238 + lib3270_popup_dialog(
  239 + hSession,
  240 + popup->type,
  241 + popup->title,
  242 + popup->summary,
  243 + "%s", popup->body
  244 + );
  245 + return ENOTSUP;
  246 +}
  247 +
236 248 static int def_popup_ssl_error(H3270 *session, int GNUC_UNUSED(rc), const char *title, const char *summary, const char *body)
237 249 {
238 250 lib3270_popup_dialog(session, LIB3270_NOTIFY_ERROR, title, summary, "%s", body);
... ... @@ -305,8 +317,6 @@ void lib3270_reset_callbacks(H3270 *hSession)
305 317 hSession->cbk.update_selection = update_selection;
306 318 hSession->cbk.cursor = set_cursor;
307 319 hSession->cbk.message = message;
308   - hSession->cbk.popup = def_popup;
309   - hSession->cbk.popup_ssl_error = def_popup_ssl_error;
310 320 hSession->cbk.update_ssl = update_ssl;
311 321 hSession->cbk.display = screen_disp;
312 322 hSession->cbk.set_width = nop_int;
... ... @@ -319,6 +329,11 @@ void lib3270_reset_callbacks(H3270 *hSession)
319 329 hSession->cbk.set_peer_certificate = set_peer_certificate;
320 330 hSession->cbk.update_luname = default_update_luname;
321 331 hSession->cbk.update_url = default_update_url;
  332 +
  333 + hSession->cbk.popup = def_popup;
  334 + hSession->cbk.popup_ssl_error = def_popup_ssl_error;
  335 + hSession->cbk.popup_show = def_popup_show;
  336 +
322 337 }
323 338  
324 339 static void lib3270_session_init(H3270 *hSession, const char *model, const char *charset)
... ...
src/core/util.c
... ... @@ -305,6 +305,15 @@ LIB3270_EXPORT void lib3270_autoptr_cleanup_char(char **ptr)
305 305 }
306 306 }
307 307  
  308 +LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr)
  309 +{
  310 + if(ptr && *ptr)
  311 + {
  312 + free((void *) *ptr);
  313 + *ptr = NULL;
  314 + }
  315 +}
  316 +
308 317 LIB3270_EXPORT void * lib3270_realloc(void *p, int len)
309 318 {
310 319 p = realloc(p, len);
... ...
src/include/internals.h
... ... @@ -795,7 +795,7 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
795 795 DWORD lasterror;
796 796 #endif // _WIN32
797 797  
798   - const LIB3270_POPUP_DESCRIPTOR *popup; /// @brief Pointer to popup message.
  798 + const LIB3270_POPUP *popup; /// @brief Pointer to popup message.
799 799  
800 800 } SSL_ERROR_MESSAGE;
801 801  
... ...
src/include/lib3270/popup.h
... ... @@ -64,10 +64,10 @@
64 64 const char * summary; \
65 65 const char * body;
66 66  
67   - typedef struct _lib3270_popup_descriptor
  67 + typedef struct _LIB3270_POPUP
68 68 {
69 69 LIB3270_POPUP_HEAD
70   - } LIB3270_POPUP_DESCRIPTOR;
  70 + } LIB3270_POPUP;
71 71  
72 72 LIB3270_EXPORT void lib3270_set_popup_handler(H3270 *session, void (*handler)(H3270 *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list));
73 73  
... ... @@ -100,7 +100,13 @@
100 100 * @retval 0 User has confirmed, continue action.
101 101 * @retval ECANCELED Operation was cancelled.
102 102 */
103   - LIB3270_EXPORT int lib3270_emit_popup(H3270 *hSession, const LIB3270_POPUP_DESCRIPTOR *popup, unsigned char wait);
  103 + LIB3270_EXPORT int lib3270_popup_show(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char wait);
  104 +
  105 + /**
  106 + * @brief Auto cleanup method (for use with lib3270_autoptr).
  107 + *
  108 + */
  109 + LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr);
104 110  
105 111 #ifdef __cplusplus
106 112 }
... ...
src/include/lib3270/session.h
... ... @@ -82,8 +82,10 @@
82 82 int (*load)(H3270 *hSession, const char *filename);
83 83  
84 84 void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text);
  85 +
85 86 void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list);
86 87 int (*popup_ssl_error)(H3270 *session, int rc, const char *title, const char *summary, const char *body);
  88 + int (*popup_show)(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char wait);
87 89  
88 90 #ifdef HAVE_LIBSSL
89 91 void (*set_peer_certificate)(const X509 *cert);
... ...
src/ssl/crl.c
... ... @@ -161,7 +161,7 @@ int lib3270_crl_new_from_x509(H3270 *hSession, void *ssl_error, X509 *cert)
161 161  
162 162 if(!dist_points)
163 163 {
164   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  164 + static const LIB3270_POPUP popup = {
165 165 .name = "SSL-NoDistPoints",
166 166 .type = LIB3270_NOTIFY_SECURE,
167 167 .summary = N_("Can't verify"),
... ...
src/ssl/linux/getcrl.c
... ... @@ -51,7 +51,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
51 51  
52 52 if(!(consturl && *consturl))
53 53 {
54   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  54 + static const LIB3270_POPUP popup = {
55 55 .type = LIB3270_NOTIFY_SECURE,
56 56 .name = "SSL-INVCRLURL",
57 57 .summary = N_( "Can't open CRL File" ),
... ... @@ -73,7 +73,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
73 73 // Can't open CRL File.
74 74 int err = errno;
75 75  
76   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  76 + static const LIB3270_POPUP popup = {
77 77 .type = LIB3270_NOTIFY_SECURE,
78 78 .name = "SSL-CRLOPEN",
79 79 .summary = N_( "Can't open CRL File" )
... ... @@ -91,7 +91,7 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
91 91 trace_ssl(hSession,"Loading CRL from %s\n",consturl+7);
92 92 if(d2i_X509_CRL_fp(hCRL, &x509_crl))
93 93 {
94   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  94 + static const LIB3270_POPUP popup = {
95 95 .type = LIB3270_NOTIFY_SECURE,
96 96 .name = "SSL-CRLDECODE",
97 97 .summary = N_( "Can't decode CRL" )
... ...
src/ssl/linux/init.c
... ... @@ -85,7 +85,7 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
85 85 ssl_ctx = SSL_CTX_new(SSLv23_method());
86 86 if(ssl_ctx == NULL)
87 87 {
88   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  88 + static const LIB3270_POPUP popup = {
89 89 .name = "SSL-CTXERROR",
90 90 .type = LIB3270_NOTIFY_SECURE,
91 91 .summary = N_( "Cant initialize the SSL context." )
... ...
src/ssl/linux/url.c
... ... @@ -63,7 +63,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
63 63  
64 64 if(!httpText)
65 65 {
66   - LIB3270_POPUP_DESCRIPTOR popup = {
  66 + LIB3270_POPUP popup = {
67 67 .type = LIB3270_NOTIFY_SECURE,
68 68 .name = "SSL-CantGetCRL",
69 69 .summary = N_( "Error getting certificate revocation list" ),
... ... @@ -82,7 +82,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
82 82 char * data = strstr((char *) httpText,":: ");
83 83 if(!data)
84 84 {
85   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  85 + static const LIB3270_POPUP popup = {
86 86 .type = LIB3270_NOTIFY_SECURE,
87 87 .summary = N_( "Got a bad formatted certificate revocation list from LDAP server" )
88 88 };
... ... @@ -104,7 +104,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
104 104  
105 105 if(!d2i_X509_CRL_bio(bio, &x509_crl))
106 106 {
107   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  107 + static const LIB3270_POPUP popup = {
108 108 .type = LIB3270_NOTIFY_SECURE,
109 109 .summary = N_( "Can't decode certificate revocation list got from LDAP server" )
110 110 };
... ... @@ -126,7 +126,7 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
126 126  
127 127 if(!d2i_X509_CRL(&x509_crl, &crl_data, szText))
128 128 {
129   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  129 + static const LIB3270_POPUP popup = {
130 130 .type = LIB3270_NOTIFY_SECURE,
131 131 .summary = N_( "Can't decode certificate revocation list" )
132 132 };
... ...
src/ssl/negotiate.c
... ... @@ -103,7 +103,7 @@ static int background_ssl_init(H3270 *hSession, void *message)
103 103 hSession->ssl.con = SSL_new(ssl_ctx);
104 104 if(hSession->ssl.con == NULL)
105 105 {
106   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  106 + static const LIB3270_POPUP popup = {
107 107 .type = LIB3270_NOTIFY_SECURE,
108 108 .summary = N_( "Cant create a new SSL structure for current connection." )
109 109 };
... ... @@ -242,7 +242,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
242 242 {
243 243 trace_ssl(hSession,"%s","SSL_set_fd failed!\n");
244 244  
245   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  245 + static const LIB3270_POPUP popup = {
246 246 .summary = N_( "SSL negotiation failed" ),
247 247 .body = N_( "Cant set the file descriptor for the input/output facility for the TLS/SSL (encrypted) side of ssl." )
248 248 };
... ... @@ -277,7 +277,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
277 277  
278 278 trace_ssl(hSession,"SSL_connect failed: %s %s\n",msg,ERR_reason_error_string(hSession->ssl.error));
279 279  
280   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  280 + static const LIB3270_POPUP popup = {
281 281 .type = LIB3270_NOTIFY_ERROR,
282 282 .summary = N_( "SSL Connect failed" ),
283 283 };
... ... @@ -375,7 +375,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
375 375 trace_ssl(hSession,"Unexpected or invalid TLS/SSL verify result %d\n",rv);
376 376 set_ssl_state(hSession,LIB3270_SSL_UNSECURE);
377 377  
378   - static LIB3270_POPUP_DESCRIPTOR popup = {
  378 + static LIB3270_POPUP popup = {
379 379 .summary = N_( "Can't verify." ),
380 380 .body = N_( "Unexpected or invalid TLS/SSL verify result" )
381 381 };
... ... @@ -400,7 +400,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
400 400 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED);
401 401  
402 402 #ifdef SSL_ENABLE_SELF_SIGNED_CERT_CHECK
403   - static const LIB3270_POPUP_DESCRIPTOR popup = {
  403 + static const LIB3270_POPUP popup = {
404 404 .name = "SelfSignedCert",
405 405 .type = LIB3270_NOTIFY_SECURE,
406 406 .summary = N_( "The SSL certificate for this host is not trusted." ),
... ... @@ -415,7 +415,7 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
415 415 default:
416 416 trace_ssl(hSession,"TLS/SSL verify result was %d (%s)\n", rv, msg->body);
417 417  
418   - ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP_DESCRIPTOR *) msg;
  418 + ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP *) msg;
419 419  
420 420 debug("message: %s",((SSL_ERROR_MESSAGE *) message)->popup->summary);
421 421 debug("description: %s",((SSL_ERROR_MESSAGE *) message)->popup->body);
... ... @@ -472,7 +472,7 @@ int ssl_negotiate(H3270 *hSession)
472 472 } else if(rc) {
473 473  
474 474 // SSL Negotiation has failed, no popup to present.
475   - const LIB3270_POPUP_DESCRIPTOR popup = {
  475 + const LIB3270_POPUP popup = {
476 476 .summary = N_("SSL negotiation has failed")
477 477 };
478 478  
... ... @@ -514,7 +514,7 @@ int ssl_init(H3270 *hSession) {
514 514 }
515 515 else
516 516 {
517   - LIB3270_POPUP_DESCRIPTOR popup = {
  517 + LIB3270_POPUP popup = {
518 518 .summary = N_("Unexpected error on SSL initialization")
519 519 };
520 520  
... ...
src/ssl/notify.c
... ... @@ -52,14 +52,14 @@
52 52 * @return Dynamically allocated popup description.
53 53 *
54 54 */
55   -static LIB3270_POPUP_DESCRIPTOR * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc)
  55 +static LIB3270_POPUP * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc)
56 56 {
57   - LIB3270_POPUP_DESCRIPTOR * popup;
  57 + LIB3270_POPUP * popup;
58 58  
59 59 if(msg->popup->body)
60 60 {
61   - popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR));
62   - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR));
  61 + popup = lib3270_malloc(sizeof(LIB3270_POPUP));
  62 + memcpy(popup,msg->popup,sizeof(LIB3270_POPUP));
63 63 popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body);
64 64 }
65 65 else
... ... @@ -80,8 +80,8 @@ static LIB3270_POPUP_DESCRIPTOR * translate_ssl_error_message(const SSL_ERROR_ME
80 80 body = lib3270_strdup_printf(_( "%s (rc=%d)" ),strerror(rc),rc);
81 81 }
82 82  
83   - popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR)+strlen(body)+1);
84   - memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR));
  83 + popup = lib3270_malloc(sizeof(LIB3270_POPUP)+strlen(body)+1);
  84 + memcpy(popup,msg->popup,sizeof(LIB3270_POPUP));
85 85 popup->body = (char *) (popup+1);
86 86 strcpy((char *) (popup+1),body);
87 87  
... ... @@ -103,7 +103,7 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAG
103 103 {
104 104 int response = 0;
105 105  
106   - LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0);
  106 + LIB3270_POPUP * popup = translate_ssl_error_message(msg,0);
107 107  
108 108 #ifdef _WIN32
109 109  
... ... @@ -154,17 +154,8 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAG
154 154  
155 155 void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg) {
156 156  
157   - LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0);
158   -
159   - lib3270_popup_dialog(
160   - hSession,
161   - popup->type,
162   - popup->title,
163   - popup->summary,
164   - "%s", popup->body
165   - );
166   -
167   - lib3270_free(popup);
  157 + lib3270_autoptr(LIB3270_POPUP) * popup = translate_ssl_error_message(msg,0);
  158 + hSession->cbk.popup_show(hSession,popup,0);
168 159  
169 160 }
170 161  
... ...