Commit 7113c142cb2c8917b86f4dd25ef0ec7e7d2ccc4e
1 parent
ea9299e6
Exists in
master
and in
5 other branches
Melhorando tratamento de erros SSL
Showing
14 changed files
with
249 additions
and
119 deletions
Show diff stats
src/include/lib3270.h
| @@ -211,6 +211,22 @@ | @@ -211,6 +211,22 @@ | ||
| 211 | LIB3270_CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */ | 211 | LIB3270_CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */ |
| 212 | } LIB3270_CSTATE; | 212 | } LIB3270_CSTATE; |
| 213 | 213 | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * Notification message types. | ||
| 217 | + * | ||
| 218 | + */ | ||
| 219 | + typedef enum _LIB3270_NOTIFY | ||
| 220 | + { | ||
| 221 | + LIB3270_NOTIFY_INFO, /**< Simple information dialog */ | ||
| 222 | + LIB3270_NOTIFY_WARNING, | ||
| 223 | + LIB3270_NOTIFY_ERROR, | ||
| 224 | + LIB3270_NOTIFY_CRITICAL, /**< Critical error, user can abort application */ | ||
| 225 | + | ||
| 226 | + LIB3270_NOTIFY_USER /**< Reserved, always the last one */ | ||
| 227 | + } LIB3270_NOTIFY; | ||
| 228 | + | ||
| 229 | + | ||
| 214 | #ifdef __cplusplus | 230 | #ifdef __cplusplus |
| 215 | extern "C" { | 231 | extern "C" { |
| 216 | #endif | 232 | #endif |
src/include/lib3270/popup.h
| @@ -33,16 +33,6 @@ | @@ -33,16 +33,6 @@ | ||
| 33 | 33 | ||
| 34 | #define LIB3270_POPUP_INCLUDED 1 | 34 | #define LIB3270_POPUP_INCLUDED 1 |
| 35 | 35 | ||
| 36 | - typedef enum _LIB3270_NOTIFY | ||
| 37 | - { | ||
| 38 | - LIB3270_NOTIFY_INFO, /**< Simple information dialog */ | ||
| 39 | - LIB3270_NOTIFY_WARNING, | ||
| 40 | - LIB3270_NOTIFY_ERROR, | ||
| 41 | - LIB3270_NOTIFY_CRITICAL, /**< Critical error, user can abort application */ | ||
| 42 | - | ||
| 43 | - LIB3270_NOTIFY_USER /**< Reserver, always the last one */ | ||
| 44 | - } LIB3270_NOTIFY; | ||
| 45 | - | ||
| 46 | LIB3270_EXPORT void lib3270_set_popup_handler(int (*popup_handler)(H3270 *, void *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)); | 36 | LIB3270_EXPORT void lib3270_set_popup_handler(int (*popup_handler)(H3270 *, void *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)); |
| 47 | LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); | 37 | LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); |
| 48 | 38 |
src/include/lib3270/session.h
| @@ -36,6 +36,11 @@ | @@ -36,6 +36,11 @@ | ||
| 36 | #define LIB3270_LUNAME_LENGTH 16 | 36 | #define LIB3270_LUNAME_LENGTH 16 |
| 37 | #define LIB3270_FULL_MODEL_NAME_LENGTH 13 | 37 | #define LIB3270_FULL_MODEL_NAME_LENGTH 13 |
| 38 | 38 | ||
| 39 | + #if defined(HAVE_LIBSSL) | ||
| 40 | + #include <openssl/ssl.h> | ||
| 41 | + #include <openssl/err.h> | ||
| 42 | + #endif | ||
| 43 | + | ||
| 39 | /** extended attributes */ | 44 | /** extended attributes */ |
| 40 | struct ea | 45 | struct ea |
| 41 | { | 46 | { |
| @@ -71,11 +76,8 @@ | @@ -71,11 +76,8 @@ | ||
| 71 | int net_sock; | 76 | int net_sock; |
| 72 | LIB3270_CSTATE cstate; /**< Connection state */ | 77 | LIB3270_CSTATE cstate; /**< Connection state */ |
| 73 | 78 | ||
| 74 | - #if defined(_WIN32) | ||
| 75 | - HANDLE sock_handle; | ||
| 76 | - #endif | ||
| 77 | - | ||
| 78 | // flags | 79 | // flags |
| 80 | + int bgthread : 1; /**< Running on a background thread ? */ | ||
| 79 | int selected : 1; /**< Has selected region? */ | 81 | int selected : 1; /**< Has selected region? */ |
| 80 | int rectsel : 1; /**< Selected region is a rectangle ? */ | 82 | int rectsel : 1; /**< Selected region is a rectangle ? */ |
| 81 | 83 | ||
| @@ -155,6 +157,7 @@ | @@ -155,6 +157,7 @@ | ||
| 155 | 157 | ||
| 156 | #if defined(HAVE_LIBSSL) /*[*/ | 158 | #if defined(HAVE_LIBSSL) /*[*/ |
| 157 | unsigned long last_ssl_error; | 159 | unsigned long last_ssl_error; |
| 160 | + SSL * ssl_con; | ||
| 158 | #endif | 161 | #endif |
| 159 | 162 | ||
| 160 | // State change callbacks. | 163 | // State change callbacks. |
| @@ -183,6 +186,8 @@ | @@ -183,6 +186,8 @@ | ||
| 183 | void (*set_selection)(H3270 *session, unsigned char on); | 186 | void (*set_selection)(H3270 *session, unsigned char on); |
| 184 | void (*ctlr_done)(H3270 *session); | 187 | void (*ctlr_done)(H3270 *session); |
| 185 | 188 | ||
| 189 | + void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); | ||
| 190 | + | ||
| 186 | }; | 191 | }; |
| 187 | 192 | ||
| 188 | 193 |
src/lib3270/XtGlue.c
| @@ -985,9 +985,17 @@ LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 * | @@ -985,9 +985,17 @@ LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 * | ||
| 985 | 985 | ||
| 986 | lib3270_main_iterate(0); | 986 | lib3270_main_iterate(0); |
| 987 | if(callbacks->callthread) | 987 | if(callbacks->callthread) |
| 988 | + { | ||
| 989 | + h->bgthread = 1; | ||
| 990 | + trace("%s: background thread for %p starts",__FUNCTION__,h); | ||
| 988 | rc = callbacks->callthread(callback,h,parm); | 991 | rc = callbacks->callthread(callback,h,parm); |
| 992 | + trace("%s: background thread for %p ends",__FUNCTION__,h); | ||
| 993 | + h->bgthread = 0; | ||
| 994 | + } | ||
| 989 | else | 995 | else |
| 996 | + { | ||
| 990 | rc = callback(h,parm); | 997 | rc = callback(h,parm); |
| 998 | + } | ||
| 991 | lib3270_main_iterate(0); | 999 | lib3270_main_iterate(0); |
| 992 | 1000 | ||
| 993 | if(h->set_timer) | 1001 | if(h->set_timer) |
src/lib3270/init.c
| @@ -111,6 +111,13 @@ static void set_cursor(H3270 *session, LIB3270_CURSOR id) | @@ -111,6 +111,13 @@ static void set_cursor(H3270 *session, LIB3270_CURSOR id) | ||
| 111 | { | 111 | { |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | +static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text) | ||
| 115 | +{ | ||
| 116 | + lib3270_write_log(session,"%s",title); | ||
| 117 | + lib3270_write_log(session,"%s",message); | ||
| 118 | + lib3270_write_log(session,"%s",text); | ||
| 119 | +} | ||
| 120 | + | ||
| 114 | static void lib3270_session_init(H3270 *hSession, const char *model) | 121 | static void lib3270_session_init(H3270 *hSession, const char *model) |
| 115 | { | 122 | { |
| 116 | int ovc, ovr; | 123 | int ovc, ovr; |
| @@ -136,6 +143,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | @@ -136,6 +143,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) | ||
| 136 | hSession->update_oia = update_oia; | 143 | hSession->update_oia = update_oia; |
| 137 | hSession->update_selection = update_selection; | 144 | hSession->update_selection = update_selection; |
| 138 | hSession->cursor = set_cursor; | 145 | hSession->cursor = set_cursor; |
| 146 | + hSession->message = message; | ||
| 139 | 147 | ||
| 140 | hSession->sock = -1; | 148 | hSession->sock = -1; |
| 141 | hSession->model_num = -1; | 149 | hSession->model_num = -1; |
src/lib3270/screen.c
| @@ -596,6 +596,8 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit | @@ -596,6 +596,8 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit | ||
| 596 | { | 596 | { |
| 597 | CHECK_SESSION_HANDLE(session); | 597 | CHECK_SESSION_HANDLE(session); |
| 598 | 598 | ||
| 599 | + trace("%s: title=%s msg=%s",__FUNCTION__,title,msg); | ||
| 600 | + | ||
| 599 | if(!fmt) | 601 | if(!fmt) |
| 600 | fmt = ""; | 602 | fmt = ""; |
| 601 | 603 | ||
| @@ -618,6 +620,8 @@ void Error(H3270 *session, const char *fmt, ...) | @@ -618,6 +620,8 @@ void Error(H3270 *session, const char *fmt, ...) | ||
| 618 | 620 | ||
| 619 | CHECK_SESSION_HANDLE(session); | 621 | CHECK_SESSION_HANDLE(session); |
| 620 | 622 | ||
| 623 | + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt); | ||
| 624 | + | ||
| 621 | va_start(arg_ptr, fmt); | 625 | va_start(arg_ptr, fmt); |
| 622 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); | 626 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); |
| 623 | va_end(arg_ptr); | 627 | va_end(arg_ptr); |
| @@ -630,6 +634,8 @@ void Warning(H3270 *session, const char *fmt, ...) | @@ -630,6 +634,8 @@ void Warning(H3270 *session, const char *fmt, ...) | ||
| 630 | 634 | ||
| 631 | CHECK_SESSION_HANDLE(session); | 635 | CHECK_SESSION_HANDLE(session); |
| 632 | 636 | ||
| 637 | + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Warning",fmt); | ||
| 638 | + | ||
| 633 | va_start(arg_ptr, fmt); | 639 | va_start(arg_ptr, fmt); |
| 634 | popup_handler(session,session->widget,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); | 640 | popup_handler(session,session->widget,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); |
| 635 | va_end(arg_ptr); | 641 | va_end(arg_ptr); |
| @@ -643,6 +649,8 @@ extern void popup_an_error(H3270 *session, const char *fmt, ...) | @@ -643,6 +649,8 @@ extern void popup_an_error(H3270 *session, const char *fmt, ...) | ||
| 643 | 649 | ||
| 644 | CHECK_SESSION_HANDLE(session); | 650 | CHECK_SESSION_HANDLE(session); |
| 645 | 651 | ||
| 652 | + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt); | ||
| 653 | + | ||
| 646 | va_start(args, fmt); | 654 | va_start(args, fmt); |
| 647 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); | 655 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); |
| 648 | va_end(args); | 656 | va_end(args); |
| @@ -655,6 +663,8 @@ void popup_system_error(H3270 *session, const char *title, const char *message, | @@ -655,6 +663,8 @@ void popup_system_error(H3270 *session, const char *title, const char *message, | ||
| 655 | 663 | ||
| 656 | CHECK_SESSION_HANDLE(session); | 664 | CHECK_SESSION_HANDLE(session); |
| 657 | 665 | ||
| 666 | + trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message); | ||
| 667 | + | ||
| 658 | va_start(args, fmt); | 668 | va_start(args, fmt); |
| 659 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); | 669 | popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); |
| 660 | va_end(args); | 670 | va_end(args); |
| @@ -764,6 +774,8 @@ LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , con | @@ -764,6 +774,8 @@ LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , con | ||
| 764 | 774 | ||
| 765 | CHECK_SESSION_HANDLE(session); | 775 | CHECK_SESSION_HANDLE(session); |
| 766 | 776 | ||
| 777 | + trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message); | ||
| 778 | + | ||
| 767 | va_start(args, fmt); | 779 | va_start(args, fmt); |
| 768 | popup_handler(session,session->widget,id,title ? title : _( "3270 Error" ), message,fmt,args); | 780 | popup_handler(session,session->widget,id,title ? title : _( "3270 Error" ), message,fmt,args); |
| 769 | va_end(args); | 781 | va_end(args); |
src/lib3270/telnet.c
| @@ -61,10 +61,6 @@ | @@ -61,10 +61,6 @@ | ||
| 61 | #endif /*]*/ | 61 | #endif /*]*/ |
| 62 | #include <stdarg.h> | 62 | #include <stdarg.h> |
| 63 | 63 | ||
| 64 | -#if defined(HAVE_LIBSSL) /*[*/ | ||
| 65 | - #include <openssl/ssl.h> | ||
| 66 | - #include <openssl/err.h> | ||
| 67 | -#endif /*]*/ | ||
| 68 | #include "tn3270e.h" | 64 | #include "tn3270e.h" |
| 69 | #include "3270ds.h" | 65 | #include "3270ds.h" |
| 70 | 66 | ||
| @@ -196,7 +192,7 @@ static void net_rawout(unsigned const char *buf, int len); | @@ -196,7 +192,7 @@ static void net_rawout(unsigned const char *buf, int len); | ||
| 196 | static void check_in3270(void); | 192 | static void check_in3270(void); |
| 197 | static void store3270in(unsigned char c); | 193 | static void store3270in(unsigned char c); |
| 198 | static void check_linemode(Boolean init); | 194 | static void check_linemode(Boolean init); |
| 199 | -// static int non_blocking(Boolean on); | 195 | +static int non_blocking(Boolean on); |
| 200 | static void net_connected(H3270 *session); | 196 | static void net_connected(H3270 *session); |
| 201 | #if defined(X3270_TN3270E) /*[*/ | 197 | #if defined(X3270_TN3270E) /*[*/ |
| 202 | static int tn3270e_negotiate(void); | 198 | static int tn3270e_negotiate(void); |
| @@ -308,11 +304,13 @@ static const char *trsp_flag[2] = { "POSITIVE-RESPONSE", "NEGATIVE-RESPONSE" }; | @@ -308,11 +304,13 @@ static const char *trsp_flag[2] = { "POSITIVE-RESPONSE", "NEGATIVE-RESPONSE" }; | ||
| 308 | #define XMIT_COLS h3270.maxCOLS | 304 | #define XMIT_COLS h3270.maxCOLS |
| 309 | // #endif /*]*/ | 305 | // #endif /*]*/ |
| 310 | 306 | ||
| 307 | +// #if defined(HAVE_LIBSSL) | ||
| 308 | +// static SSL *ssl_con; | ||
| 309 | +// #endif | ||
| 310 | + | ||
| 311 | #if defined(HAVE_LIBSSL) /*[*/ | 311 | #if defined(HAVE_LIBSSL) /*[*/ |
| 312 | -static SSL_CTX *ssl_ctx; | ||
| 313 | -static SSL *ssl_con; | ||
| 314 | static Boolean need_tls_follows = False; | 312 | static Boolean need_tls_follows = False; |
| 315 | -static void ssl_init(void); | 313 | +static void ssl_init(H3270 *session); |
| 316 | #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ | 314 | #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ |
| 317 | #define INFO_CONST const | 315 | #define INFO_CONST const |
| 318 | #else /*][*/ | 316 | #else /*][*/ |
| @@ -600,14 +598,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -600,14 +598,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
| 600 | #endif | 598 | #endif |
| 601 | 599 | ||
| 602 | /* set the socket to be non-delaying */ | 600 | /* set the socket to be non-delaying */ |
| 603 | -/* | ||
| 604 | -#if defined(_WIN32) | ||
| 605 | - if (non_blocking(False) < 0) | ||
| 606 | -#else | ||
| 607 | if (non_blocking(True) < 0) | 601 | if (non_blocking(True) < 0) |
| 608 | -#endif | ||
| 609 | close_fail; | 602 | close_fail; |
| 610 | -*/ | ||
| 611 | 603 | ||
| 612 | #if !defined(_WIN32) | 604 | #if !defined(_WIN32) |
| 613 | /* don't share the socket with our children */ | 605 | /* don't share the socket with our children */ |
| @@ -616,26 +608,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -616,26 +608,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
| 616 | 608 | ||
| 617 | /* init ssl */ | 609 | /* init ssl */ |
| 618 | #if defined(HAVE_LIBSSL) | 610 | #if defined(HAVE_LIBSSL) |
| 619 | - session->last_ssl_error = 0; | 611 | + session->last_ssl_error = !0; |
| 620 | if (session->ssl_host) | 612 | if (session->ssl_host) |
| 621 | - ssl_init(); | 613 | + ssl_init(session); |
| 622 | #endif | 614 | #endif |
| 623 | 615 | ||
| 624 | /* connect */ | 616 | /* connect */ |
| 625 | status_connecting(session,1); | 617 | status_connecting(session,1); |
| 626 | 618 | ||
| 627 | - if(connect_sock(session, session->sock, &haddr.sa,ha_len) == 0) | ||
| 628 | - { | ||
| 629 | - trace_dsn("Connected.\n"); | ||
| 630 | - net_connected(session); | ||
| 631 | - } | ||
| 632 | - else | ||
| 633 | - { | ||
| 634 | - popup_a_sockerr(session, N_( "Can't connect to %s:%d" ),session->hostname, session->current_port); | ||
| 635 | - close_fail; | ||
| 636 | - } | ||
| 637 | - | ||
| 638 | -/* | ||
| 639 | switch(connect_sock(session, session->sock, &haddr.sa,ha_len)) | 619 | switch(connect_sock(session, session->sock, &haddr.sa,ha_len)) |
| 640 | { | 620 | { |
| 641 | case 0: // Connected | 621 | case 0: // Connected |
| @@ -650,9 +630,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -650,9 +630,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
| 650 | case SE_EINPROGRESS: | 630 | case SE_EINPROGRESS: |
| 651 | *pending = True; | 631 | *pending = True; |
| 652 | trace_dsn("Connection pending.\n"); | 632 | trace_dsn("Connection pending.\n"); |
| 653 | -#if !defined(_WIN32) | 633 | +// #if !defined(_WIN32) |
| 654 | output_id = AddOutput(session->sock, session, output_possible); | 634 | output_id = AddOutput(session->sock, session, output_possible); |
| 655 | -#endif | 635 | +// #endif |
| 656 | break; | 636 | break; |
| 657 | 637 | ||
| 658 | default: | 638 | default: |
| @@ -660,7 +640,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | @@ -660,7 +640,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo | ||
| 660 | close_fail; | 640 | close_fail; |
| 661 | 641 | ||
| 662 | } | 642 | } |
| 663 | -*/ | ||
| 664 | 643 | ||
| 665 | /* set up temporary termtype */ | 644 | /* set up temporary termtype */ |
| 666 | if (appres.termname == CN && session->std_ds_host) | 645 | if (appres.termname == CN && session->std_ds_host) |
| @@ -784,25 +763,40 @@ static void net_connected(H3270 *session) | @@ -784,25 +763,40 @@ static void net_connected(H3270 *session) | ||
| 784 | /* Set up SSL. */ | 763 | /* Set up SSL. */ |
| 785 | if(session->ssl_host && !session->secure_connection) | 764 | if(session->ssl_host && !session->secure_connection) |
| 786 | { | 765 | { |
| 787 | - if (SSL_set_fd(ssl_con, session->sock) != 1) | 766 | + int rc; |
| 767 | + | ||
| 768 | + if (SSL_set_fd(session->ssl_con, session->sock) != 1) | ||
| 788 | { | 769 | { |
| 789 | trace_dsn("Can't set fd!\n"); | 770 | trace_dsn("Can't set fd!\n"); |
| 771 | + popup_system_error(&h3270,_( "Connection failed error" ), _( "Can't set SSL socket file descriptor" ), "%s", SSL_state_string_long(session->ssl_con)); | ||
| 790 | } | 772 | } |
| 791 | 773 | ||
| 792 | - if (SSL_connect(ssl_con) != 1) | 774 | + non_blocking(False); |
| 775 | + rc = SSL_connect(session->ssl_con); | ||
| 776 | + | ||
| 777 | + if(rc != 1) | ||
| 793 | { | 778 | { |
| 794 | - unsigned long e = ERR_get_error(); | 779 | + unsigned long e = ERR_get_error(); |
| 780 | + const char * state = SSL_state_string_long(session->ssl_con); | ||
| 781 | + | ||
| 782 | + trace_dsn("TLS/SSL tunneled connection failed with error %ld, rc=%d and state=%s",e,rc,state); | ||
| 783 | + | ||
| 784 | + host_disconnect(session,True); | ||
| 785 | + | ||
| 795 | if(e != session->last_ssl_error) | 786 | if(e != session->last_ssl_error) |
| 796 | { | 787 | { |
| 797 | - popup_system_error(&h3270,_( "Connection failed error" ), _( "SSL negotiation failed" ), "%s", SSL_state_string_long(ssl_con)); | 788 | + session->message( &h3270, |
| 789 | + LIB3270_NOTIFY_ERROR, | ||
| 790 | + _( "Connection failed" ), | ||
| 791 | + _( "SSL negotiation failed" ), | ||
| 792 | + state); | ||
| 798 | session->last_ssl_error = e; | 793 | session->last_ssl_error = e; |
| 799 | } | 794 | } |
| 800 | - | ||
| 801 | - trace_dsn("TLS/SSL tunneled connection failed with error %ld.",e); | ||
| 802 | - trace("%s: SSL_connect failed with error %ld",__FUNCTION__,e); | ||
| 803 | - host_disconnect(session,True); | ||
| 804 | return; | 795 | return; |
| 796 | + | ||
| 805 | } | 797 | } |
| 798 | + non_blocking(True); | ||
| 799 | + | ||
| 806 | session->secure_connection = True; | 800 | session->secure_connection = True; |
| 807 | trace_dsn("TLS/SSL tunneled connection complete. Connection is now secure.\n"); | 801 | trace_dsn("TLS/SSL tunneled connection complete. Connection is now secure.\n"); |
| 808 | 802 | ||
| @@ -864,15 +858,11 @@ static void net_connected(H3270 *session) | @@ -864,15 +858,11 @@ static void net_connected(H3270 *session) | ||
| 864 | */ | 858 | */ |
| 865 | static void connection_complete(void) | 859 | static void connection_complete(void) |
| 866 | { | 860 | { |
| 867 | -/* | ||
| 868 | -#if !defined(_WIN32) | ||
| 869 | if (non_blocking(False) < 0) | 861 | if (non_blocking(False) < 0) |
| 870 | { | 862 | { |
| 871 | host_disconnect(&h3270,True); | 863 | host_disconnect(&h3270,True); |
| 872 | return; | 864 | return; |
| 873 | } | 865 | } |
| 874 | -#endif | ||
| 875 | -*/ | ||
| 876 | host_connected(&h3270); | 866 | host_connected(&h3270); |
| 877 | net_connected(&h3270); | 867 | net_connected(&h3270); |
| 878 | } | 868 | } |
| @@ -903,14 +893,14 @@ static void output_possible(H3270 *session) | @@ -903,14 +893,14 @@ static void output_possible(H3270 *session) | ||
| 903 | * net_disconnect | 893 | * net_disconnect |
| 904 | * Shut down the socket. | 894 | * Shut down the socket. |
| 905 | */ | 895 | */ |
| 906 | -void | ||
| 907 | -net_disconnect(void) | 896 | +void net_disconnect(void) |
| 908 | { | 897 | { |
| 909 | #if defined(HAVE_LIBSSL) /*[*/ | 898 | #if defined(HAVE_LIBSSL) /*[*/ |
| 910 | - if (ssl_con != NULL) { | ||
| 911 | - SSL_shutdown(ssl_con); | ||
| 912 | - SSL_free(ssl_con); | ||
| 913 | - ssl_con = NULL; | 899 | + if (h3270.ssl_con != NULL) |
| 900 | + { | ||
| 901 | + SSL_shutdown(h3270.ssl_con); | ||
| 902 | + SSL_free(h3270.ssl_con); | ||
| 903 | + h3270.ssl_con = NULL; | ||
| 914 | } | 904 | } |
| 915 | h3270.secure_connection = False; | 905 | h3270.secure_connection = False; |
| 916 | #endif /*]*/ | 906 | #endif /*]*/ |
| @@ -991,13 +981,13 @@ void net_input(H3270 *session) | @@ -991,13 +981,13 @@ void net_input(H3270 *session) | ||
| 991 | ansi_data = 0; | 981 | ansi_data = 0; |
| 992 | #endif /*]*/ | 982 | #endif /*]*/ |
| 993 | 983 | ||
| 994 | -#if defined(_WIN32) /*[*/ | ||
| 995 | - (void) ResetEvent(session->sock_handle); | ||
| 996 | -#endif /*]*/ | 984 | +// #if defined(_WIN32) |
| 985 | +// (void) ResetEvent(session->sock_handle); | ||
| 986 | +//#endif /*]*/ | ||
| 997 | 987 | ||
| 998 | #if defined(HAVE_LIBSSL) | 988 | #if defined(HAVE_LIBSSL) |
| 999 | - if (ssl_con != NULL) | ||
| 1000 | - nr = SSL_read(ssl_con, (char *) netrbuf, BUFSZ); | 989 | + if (session->ssl_con != NULL) |
| 990 | + nr = SSL_read(session->ssl_con, (char *) netrbuf, BUFSZ); | ||
| 1001 | else | 991 | else |
| 1002 | #endif // HAVE_LIBSSL | 992 | #endif // HAVE_LIBSSL |
| 1003 | /* | 993 | /* |
| @@ -1013,7 +1003,7 @@ void net_input(H3270 *session) | @@ -1013,7 +1003,7 @@ void net_input(H3270 *session) | ||
| 1013 | return; | 1003 | return; |
| 1014 | } | 1004 | } |
| 1015 | #if defined(HAVE_LIBSSL) /*[*/ | 1005 | #if defined(HAVE_LIBSSL) /*[*/ |
| 1016 | - if (ssl_con != NULL) | 1006 | + if(session->ssl_con != NULL) |
| 1017 | { | 1007 | { |
| 1018 | unsigned long e; | 1008 | unsigned long e; |
| 1019 | char err_buf[120]; | 1009 | char err_buf[120]; |
| @@ -1026,11 +1016,11 @@ void net_input(H3270 *session) | @@ -1026,11 +1016,11 @@ void net_input(H3270 *session) | ||
| 1026 | 1016 | ||
| 1027 | trace_dsn("RCVD SSL_read error %ld (%s)\n", e,err_buf); | 1017 | trace_dsn("RCVD SSL_read error %ld (%s)\n", e,err_buf); |
| 1028 | 1018 | ||
| 1029 | - lib3270_popup_dialog( session, | ||
| 1030 | - LIB3270_NOTIFY_CRITICAL, | ||
| 1031 | - N_( "SSL Error" ), | ||
| 1032 | - N_( "SSL Read error" ), | ||
| 1033 | - "%s", err_buf); | 1019 | + h3270.message( &h3270, |
| 1020 | + LIB3270_NOTIFY_ERROR, | ||
| 1021 | + _( "SSL Error" ), | ||
| 1022 | + _( "SSL Read error" ), | ||
| 1023 | + err_buf ); | ||
| 1034 | 1024 | ||
| 1035 | host_disconnect(session,True); | 1025 | host_disconnect(session,True); |
| 1036 | return; | 1026 | return; |
| @@ -1074,13 +1064,11 @@ void net_input(H3270 *session) | @@ -1074,13 +1064,11 @@ void net_input(H3270 *session) | ||
| 1074 | 1064 | ||
| 1075 | if (HALF_CONNECTED) | 1065 | if (HALF_CONNECTED) |
| 1076 | { | 1066 | { |
| 1077 | -/* | ||
| 1078 | if (non_blocking(False) < 0) | 1067 | if (non_blocking(False) < 0) |
| 1079 | { | 1068 | { |
| 1080 | host_disconnect(session,True); | 1069 | host_disconnect(session,True); |
| 1081 | return; | 1070 | return; |
| 1082 | } | 1071 | } |
| 1083 | -*/ | ||
| 1084 | host_connected(session); | 1072 | host_connected(session); |
| 1085 | net_connected(session); | 1073 | net_connected(session); |
| 1086 | } | 1074 | } |
| @@ -2022,8 +2010,8 @@ net_rawout(unsigned const char *buf, int len) | @@ -2022,8 +2010,8 @@ net_rawout(unsigned const char *buf, int len) | ||
| 2022 | # define n2w len | 2010 | # define n2w len |
| 2023 | #endif | 2011 | #endif |
| 2024 | #if defined(HAVE_LIBSSL) /*[*/ | 2012 | #if defined(HAVE_LIBSSL) /*[*/ |
| 2025 | - if (ssl_con != NULL) | ||
| 2026 | - nw = SSL_write(ssl_con, (const char *) buf, n2w); | 2013 | + if(h3270.ssl_con != NULL) |
| 2014 | + nw = SSL_write(h3270.ssl_con, (const char *) buf, n2w); | ||
| 2027 | else | 2015 | else |
| 2028 | #endif /*]*/ | 2016 | #endif /*]*/ |
| 2029 | 2017 | ||
| @@ -2037,7 +2025,8 @@ net_rawout(unsigned const char *buf, int len) | @@ -2037,7 +2025,8 @@ net_rawout(unsigned const char *buf, int len) | ||
| 2037 | nw = send(h3270.sock, (const char *) buf, n2w, 0); | 2025 | nw = send(h3270.sock, (const char *) buf, n2w, 0); |
| 2038 | if (nw < 0) { | 2026 | if (nw < 0) { |
| 2039 | #if defined(HAVE_LIBSSL) /*[*/ | 2027 | #if defined(HAVE_LIBSSL) /*[*/ |
| 2040 | - if (ssl_con != NULL) { | 2028 | + if (h3270.ssl_con != NULL) |
| 2029 | + { | ||
| 2041 | unsigned long e; | 2030 | unsigned long e; |
| 2042 | char err_buf[120]; | 2031 | char err_buf[120]; |
| 2043 | 2032 | ||
| @@ -3196,11 +3185,11 @@ net_snap_options(void) | @@ -3196,11 +3185,11 @@ net_snap_options(void) | ||
| 3196 | /* | 3185 | /* |
| 3197 | * Set blocking/non-blocking mode on the socket. On error, pops up an error | 3186 | * Set blocking/non-blocking mode on the socket. On error, pops up an error |
| 3198 | * message, but does not close the socket. | 3187 | * message, but does not close the socket. |
| 3199 | - */ /* | ||
| 3200 | -static int | ||
| 3201 | -non_blocking(Boolean on) | 3188 | + */ |
| 3189 | +static int non_blocking(Boolean on) | ||
| 3202 | { | 3190 | { |
| 3203 | #if !defined(BLOCKING_CONNECT_ONLY) | 3191 | #if !defined(BLOCKING_CONNECT_ONLY) |
| 3192 | + | ||
| 3204 | # if defined(FIONBIO) | 3193 | # if defined(FIONBIO) |
| 3205 | int i = on ? 1 : 0; | 3194 | int i = on ? 1 : 0; |
| 3206 | 3195 | ||
| @@ -3209,7 +3198,9 @@ non_blocking(Boolean on) | @@ -3209,7 +3198,9 @@ non_blocking(Boolean on) | ||
| 3209 | popup_a_sockerr(NULL, N_( "ioctl(%s)" ), "FIONBIO"); | 3198 | popup_a_sockerr(NULL, N_( "ioctl(%s)" ), "FIONBIO"); |
| 3210 | return -1; | 3199 | return -1; |
| 3211 | } | 3200 | } |
| 3201 | + | ||
| 3212 | # else | 3202 | # else |
| 3203 | + | ||
| 3213 | int f; | 3204 | int f; |
| 3214 | 3205 | ||
| 3215 | if ((f = fcntl(sock, F_GETFL, 0)) == -1) | 3206 | if ((f = fcntl(sock, F_GETFL, 0)) == -1) |
| @@ -3226,42 +3217,52 @@ non_blocking(Boolean on) | @@ -3226,42 +3217,52 @@ non_blocking(Boolean on) | ||
| 3226 | popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL"); | 3217 | popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL"); |
| 3227 | return -1; | 3218 | return -1; |
| 3228 | } | 3219 | } |
| 3229 | -# endif | ||
| 3230 | -#endif | 3220 | +#endif // FIONBIO |
| 3221 | + | ||
| 3222 | +#endif // !BLOCKING_CONNECT_ONLY | ||
| 3223 | + | ||
| 3231 | return 0; | 3224 | return 0; |
| 3232 | } | 3225 | } |
| 3233 | -*/ | ||
| 3234 | 3226 | ||
| 3235 | #if defined(HAVE_LIBSSL) /*[*/ | 3227 | #if defined(HAVE_LIBSSL) /*[*/ |
| 3236 | 3228 | ||
| 3237 | /* Initialize the OpenSSL library. */ | 3229 | /* Initialize the OpenSSL library. */ |
| 3238 | -static void ssl_init(void) | 3230 | +static void ssl_init(H3270 *session) |
| 3239 | { | 3231 | { |
| 3240 | - static Boolean ssl_initted = False; | 3232 | + static SSL_CTX *ssl_ctx = NULL; |
| 3241 | 3233 | ||
| 3242 | - if (!ssl_initted) { | 3234 | + if(ssl_ctx == NULL) |
| 3235 | + { | ||
| 3236 | + lib3270_write_log(session,"%s","Initializing SSL context"); | ||
| 3243 | SSL_load_error_strings(); | 3237 | SSL_load_error_strings(); |
| 3244 | SSL_library_init(); | 3238 | SSL_library_init(); |
| 3245 | - ssl_initted = True; | ||
| 3246 | ssl_ctx = SSL_CTX_new(SSLv23_method()); | 3239 | ssl_ctx = SSL_CTX_new(SSLv23_method()); |
| 3247 | - if (ssl_ctx == NULL) { | 3240 | + if(ssl_ctx == NULL) |
| 3241 | + { | ||
| 3248 | popup_an_error(NULL,"SSL_CTX_new failed"); | 3242 | popup_an_error(NULL,"SSL_CTX_new failed"); |
| 3249 | - h3270.ssl_host = False; | 3243 | + session->ssl_host = False; |
| 3250 | return; | 3244 | return; |
| 3251 | } | 3245 | } |
| 3252 | SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); | 3246 | SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); |
| 3247 | + SSL_CTX_set_info_callback(ssl_ctx, client_info_callback); | ||
| 3248 | + SSL_CTX_set_default_verify_paths(ssl_ctx); | ||
| 3253 | } | 3249 | } |
| 3254 | 3250 | ||
| 3255 | - ssl_con = SSL_new(ssl_ctx); | ||
| 3256 | - if (ssl_con == NULL) { | ||
| 3257 | - popup_an_error(NULL,"SSL_new failed"); | ||
| 3258 | - h3270.ssl_host = False; | 3251 | + if(session->ssl_con) |
| 3252 | + SSL_free(session->ssl_con); | ||
| 3253 | + | ||
| 3254 | + session->ssl_con = SSL_new(ssl_ctx); | ||
| 3255 | + if(session->ssl_con == NULL) | ||
| 3256 | + { | ||
| 3257 | + popup_an_error(session,"SSL_new failed"); | ||
| 3258 | + session->ssl_host = False; | ||
| 3259 | + return; | ||
| 3259 | } | 3260 | } |
| 3260 | - SSL_set_verify(ssl_con, 0/*xxx*/, NULL); | ||
| 3261 | 3261 | ||
| 3262 | - SSL_CTX_set_info_callback(ssl_ctx, client_info_callback); | 3262 | + SSL_set_verify(session->ssl_con, 0/*xxx*/, NULL); |
| 3263 | 3263 | ||
| 3264 | /* XXX: May need to get key file and password. */ | 3264 | /* XXX: May need to get key file and password. */ |
| 3265 | + /* | ||
| 3265 | if (appres.cert_file) | 3266 | if (appres.cert_file) |
| 3266 | { | 3267 | { |
| 3267 | if (!(SSL_CTX_use_certificate_chain_file(ssl_ctx, | 3268 | if (!(SSL_CTX_use_certificate_chain_file(ssl_ctx, |
| @@ -3277,8 +3278,7 @@ static void ssl_init(void) | @@ -3277,8 +3278,7 @@ static void ssl_init(void) | ||
| 3277 | appres.cert_file, err_buf); | 3278 | appres.cert_file, err_buf); |
| 3278 | } | 3279 | } |
| 3279 | } | 3280 | } |
| 3280 | - | ||
| 3281 | - SSL_CTX_set_default_verify_paths(ssl_ctx); | 3281 | + */ |
| 3282 | } | 3282 | } |
| 3283 | 3283 | ||
| 3284 | /* Callback for tracing protocol negotiation. */ | 3284 | /* Callback for tracing protocol negotiation. */ |
| @@ -3343,8 +3343,7 @@ static void client_info_callback(INFO_CONST SSL *s, int where, int ret) | @@ -3343,8 +3343,7 @@ static void client_info_callback(INFO_CONST SSL *s, int where, int ret) | ||
| 3343 | } | 3343 | } |
| 3344 | 3344 | ||
| 3345 | /* Process a STARTTLS subnegotiation. */ | 3345 | /* Process a STARTTLS subnegotiation. */ |
| 3346 | -static void | ||
| 3347 | -continue_tls(unsigned char *sbbuf, int len) | 3346 | +static void continue_tls(unsigned char *sbbuf, int len) |
| 3348 | { | 3347 | { |
| 3349 | int rv; | 3348 | int rv; |
| 3350 | 3349 | ||
| @@ -3364,15 +3363,17 @@ continue_tls(unsigned char *sbbuf, int len) | @@ -3364,15 +3363,17 @@ continue_tls(unsigned char *sbbuf, int len) | ||
| 3364 | trace_dsn("%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | 3363 | trace_dsn("%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); |
| 3365 | 3364 | ||
| 3366 | /* Initialize the SSL library. */ | 3365 | /* Initialize the SSL library. */ |
| 3367 | - ssl_init(); | ||
| 3368 | - if (ssl_con == NULL) { | 3366 | + ssl_init(&h3270); |
| 3367 | + if(h3270.ssl_con == NULL) | ||
| 3368 | + { | ||
| 3369 | /* Failed. */ | 3369 | /* Failed. */ |
| 3370 | net_disconnect(); | 3370 | net_disconnect(); |
| 3371 | return; | 3371 | return; |
| 3372 | } | 3372 | } |
| 3373 | 3373 | ||
| 3374 | /* Set up the TLS/SSL connection. */ | 3374 | /* Set up the TLS/SSL connection. */ |
| 3375 | - if (SSL_set_fd(ssl_con, h3270.sock) != 1) { | 3375 | + if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1) |
| 3376 | + { | ||
| 3376 | trace_dsn("Can't set fd!\n"); | 3377 | trace_dsn("Can't set fd!\n"); |
| 3377 | } | 3378 | } |
| 3378 | 3379 | ||
| @@ -3382,7 +3383,7 @@ continue_tls(unsigned char *sbbuf, int len) | @@ -3382,7 +3383,7 @@ continue_tls(unsigned char *sbbuf, int len) | ||
| 3382 | // (void) non_blocking(False); | 3383 | // (void) non_blocking(False); |
| 3383 | //#endif | 3384 | //#endif |
| 3384 | 3385 | ||
| 3385 | - rv = SSL_connect(ssl_con); | 3386 | + rv = SSL_connect(h3270.ssl_con); |
| 3386 | 3387 | ||
| 3387 | //#if defined(_WIN32) | 3388 | //#if defined(_WIN32) |
| 3388 | // // Make the socket non-blocking again for event processing | 3389 | // // Make the socket non-blocking again for event processing |
src/pw3270/v3270/genmarshal
src/pw3270/v3270/iocallback.c
| @@ -251,10 +251,10 @@ struct bgParameter | @@ -251,10 +251,10 @@ struct bgParameter | ||
| 251 | 251 | ||
| 252 | gpointer BgCall(struct bgParameter *p) | 252 | gpointer BgCall(struct bgParameter *p) |
| 253 | { | 253 | { |
| 254 | - trace("%s starts",__FUNCTION__); | 254 | +// trace("%s starts",__FUNCTION__); |
| 255 | p->rc = p->callback(p->session, p->parm); | 255 | p->rc = p->callback(p->session, p->parm); |
| 256 | p->running = FALSE; | 256 | p->running = FALSE; |
| 257 | - trace("%s ends",__FUNCTION__); | 257 | +// trace("%s ends",__FUNCTION__); |
| 258 | return 0; | 258 | return 0; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| @@ -263,7 +263,7 @@ static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *ses | @@ -263,7 +263,7 @@ static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *ses | ||
| 263 | struct bgParameter p = { TRUE, session, -1, callback, parm }; | 263 | struct bgParameter p = { TRUE, session, -1, callback, parm }; |
| 264 | GThread *thread; | 264 | GThread *thread; |
| 265 | 265 | ||
| 266 | - trace("Starting auxiliary thread for callback %p",callback); | 266 | +// trace("Starting auxiliary thread for callback %p",callback); |
| 267 | 267 | ||
| 268 | p.running = TRUE; | 268 | p.running = TRUE; |
| 269 | thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); | 269 | thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); |
src/pw3270/v3270/oia.c
| @@ -276,7 +276,7 @@ static void draw_undera(cairo_t *cr, H3270 *host, struct v3270_metrics *metrics, | @@ -276,7 +276,7 @@ static void draw_undera(cairo_t *cr, H3270 *host, struct v3270_metrics *metrics, | ||
| 276 | void v3270_draw_connection(cairo_t *cr, H3270 *host, struct v3270_metrics *metrics, GdkColor *color, GdkRectangle *rect) | 276 | void v3270_draw_connection(cairo_t *cr, H3270 *host, struct v3270_metrics *metrics, GdkColor *color, GdkRectangle *rect) |
| 277 | { | 277 | { |
| 278 | cairo_text_extents_t extents; | 278 | cairo_text_extents_t extents; |
| 279 | - gchar *str = "?"; | 279 | + const gchar *str; |
| 280 | 280 | ||
| 281 | gdk_cairo_set_source_color(cr,color+V3270_COLOR_OIA_FOREGROUND); | 281 | gdk_cairo_set_source_color(cr,color+V3270_COLOR_OIA_FOREGROUND); |
| 282 | cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); | 282 | cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height); |
| @@ -290,9 +290,11 @@ void v3270_draw_connection(cairo_t *cr, H3270 *host, struct v3270_metrics *metri | @@ -290,9 +290,11 @@ void v3270_draw_connection(cairo_t *cr, H3270 *host, struct v3270_metrics *metri | ||
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | if(lib3270_in_ansi(host)) | 292 | if(lib3270_in_ansi(host)) |
| 293 | - *str = 'N'; | 293 | + str = "N"; |
| 294 | else if(lib3270_in_sscp(host)) | 294 | else if(lib3270_in_sscp(host)) |
| 295 | - *str = 'S'; | 295 | + str = "S"; |
| 296 | + else | ||
| 297 | + str = "?"; | ||
| 296 | 298 | ||
| 297 | cairo_text_extents(cr,str,&extents); | 299 | cairo_text_extents(cr,str,&extents); |
| 298 | cairo_move_to(cr,rect->x+((rect->width/2)-(extents.width/2)),rect->y+extents.height+( (rect->height/2) - (extents.height/2))); | 300 | cairo_move_to(cr,rect->x+((rect->width/2)-(extents.width/2)),rect->y+extents.height+( (rect->height/2) - (extents.height/2))); |
src/pw3270/v3270/private.h
| @@ -53,6 +53,7 @@ G_BEGIN_DECLS | @@ -53,6 +53,7 @@ G_BEGIN_DECLS | ||
| 53 | void (*toggle_changed)(v3270 *widget,LIB3270_TOGGLE toggle_id,gboolean toggle_state,const gchar *toggle_name); | 53 | void (*toggle_changed)(v3270 *widget,LIB3270_TOGGLE toggle_id,gboolean toggle_state,const gchar *toggle_name); |
| 54 | void (*message_changed)(v3270 *widget, LIB3270_MESSAGE id); | 54 | void (*message_changed)(v3270 *widget, LIB3270_MESSAGE id); |
| 55 | void (*luname_changed)(GtkWidget *widget,const gchar *luname); | 55 | void (*luname_changed)(GtkWidget *widget,const gchar *luname); |
| 56 | + void (*popup_message)(GtkWidget *widget, LIB3270_NOTIFY id , const gchar *title, const gchar *message, const gchar *text); | ||
| 56 | gboolean (*keypress)(GtkWidget *widget,guint keyval,GdkModifierType state); | 57 | gboolean (*keypress)(GtkWidget *widget,guint keyval,GdkModifierType state); |
| 57 | 58 | ||
| 58 | }; | 59 | }; |
| @@ -79,6 +80,7 @@ G_BEGIN_DECLS | @@ -79,6 +80,7 @@ G_BEGIN_DECLS | ||
| 79 | SIGNAL_PASTENEXT, | 80 | SIGNAL_PASTENEXT, |
| 80 | SIGNAL_CLIPBOARD, | 81 | SIGNAL_CLIPBOARD, |
| 81 | SIGNAL_CHANGED, | 82 | SIGNAL_CHANGED, |
| 83 | + SIGNAL_MESSAGE, | ||
| 82 | 84 | ||
| 83 | LAST_SIGNAL | 85 | LAST_SIGNAL |
| 84 | }; | 86 | }; |
src/pw3270/v3270/v3270.h
| @@ -181,6 +181,7 @@ | @@ -181,6 +181,7 @@ | ||
| 181 | // Misc | 181 | // Misc |
| 182 | GtkIMContext * v3270_get_im_context(GtkWidget *widget); | 182 | GtkIMContext * v3270_get_im_context(GtkWidget *widget); |
| 183 | gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); | 183 | gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); |
| 184 | + void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type, const gchar *title, const gchar *message, const gchar *text); | ||
| 184 | 185 | ||
| 185 | void v3270_set_host(GtkWidget *widget, const gchar *uri); | 186 | void v3270_set_host(GtkWidget *widget, const gchar *uri); |
| 186 | 187 |
src/pw3270/v3270/widget.c
| @@ -215,6 +215,46 @@ static void get_preferred_width_for_height(GtkWidget *widget,gint height, gint * | @@ -215,6 +215,46 @@ static void get_preferred_width_for_height(GtkWidget *widget,gint height, gint * | ||
| 215 | 215 | ||
| 216 | #endif // GTK(3,0,0) | 216 | #endif // GTK(3,0,0) |
| 217 | 217 | ||
| 218 | +void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type , const gchar *title, const gchar *message, const gchar *text) | ||
| 219 | +{ | ||
| 220 | + GtkWidget * dialog; | ||
| 221 | + GtkWidget * toplevel = NULL; | ||
| 222 | + GtkMessageType msgtype = GTK_MESSAGE_WARNING; | ||
| 223 | + GtkButtonsType buttons = GTK_BUTTONS_OK; | ||
| 224 | + | ||
| 225 | + if(widget && GTK_IS_WIDGET(widget)) | ||
| 226 | + toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget)); | ||
| 227 | + | ||
| 228 | + if(type == LIB3270_NOTIFY_CRITICAL) | ||
| 229 | + { | ||
| 230 | + msgtype = GTK_MESSAGE_ERROR; | ||
| 231 | + buttons = GTK_BUTTONS_CLOSE; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + if(!title) | ||
| 235 | + title = _( "Error" ); | ||
| 236 | + | ||
| 237 | + if(message) | ||
| 238 | + { | ||
| 239 | + dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",message); | ||
| 240 | + if(text) | ||
| 241 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",text); | ||
| 242 | + } | ||
| 243 | + else if(text) | ||
| 244 | + { | ||
| 245 | + dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",text); | ||
| 246 | + } | ||
| 247 | + else | ||
| 248 | + { | ||
| 249 | + dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",title); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + gtk_window_set_title(GTK_WINDOW(dialog),title); | ||
| 253 | + gtk_widget_show_all(dialog); | ||
| 254 | + gtk_dialog_run(GTK_DIALOG (dialog)); | ||
| 255 | + gtk_widget_destroy(dialog); | ||
| 256 | +} | ||
| 257 | + | ||
| 218 | static void v3270_class_init(v3270Class *klass) | 258 | static void v3270_class_init(v3270Class *klass) |
| 219 | { | 259 | { |
| 220 | GObjectClass * gobject_class = G_OBJECT_CLASS(klass); | 260 | GObjectClass * gobject_class = G_OBJECT_CLASS(klass); |
| @@ -240,6 +280,7 @@ static void v3270_class_init(v3270Class *klass) | @@ -240,6 +280,7 @@ static void v3270_class_init(v3270Class *klass) | ||
| 240 | klass->toggle_changed = v3270_toggle_changed; | 280 | klass->toggle_changed = v3270_toggle_changed; |
| 241 | klass->message_changed = v3270_update_message; | 281 | klass->message_changed = v3270_update_message; |
| 242 | klass->luname_changed = v3270_update_luname; | 282 | klass->luname_changed = v3270_update_luname; |
| 283 | + klass->popup_message = v3270_popup_message; | ||
| 243 | 284 | ||
| 244 | #if GTK_CHECK_VERSION(3,0,0) | 285 | #if GTK_CHECK_VERSION(3,0,0) |
| 245 | 286 | ||
| @@ -443,6 +484,15 @@ static void v3270_class_init(v3270Class *klass) | @@ -443,6 +484,15 @@ static void v3270_class_init(v3270Class *klass) | ||
| 443 | pw3270_VOID__VOID_UINT_UINT, | 484 | pw3270_VOID__VOID_UINT_UINT, |
| 444 | G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); | 485 | G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); |
| 445 | 486 | ||
| 487 | + v3270_widget_signal[SIGNAL_MESSAGE] = | ||
| 488 | + g_signal_new( "popup_message", | ||
| 489 | + G_OBJECT_CLASS_TYPE (gobject_class), | ||
| 490 | + G_SIGNAL_RUN_FIRST, | ||
| 491 | + G_STRUCT_OFFSET (v3270Class, popup_message), | ||
| 492 | + NULL, NULL, | ||
| 493 | + pw3270_VOID__VOID_UINT_POINTER_POINTER_POINTER, | ||
| 494 | + G_TYPE_NONE, 4, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | ||
| 495 | + | ||
| 446 | } | 496 | } |
| 447 | 497 | ||
| 448 | void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) | 498 | void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) |
| @@ -677,6 +727,16 @@ static void update_selection(H3270 *session, int start, int end) | @@ -677,6 +727,16 @@ static void update_selection(H3270 *session, int start, int end) | ||
| 677 | 727 | ||
| 678 | } | 728 | } |
| 679 | 729 | ||
| 730 | +static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text) | ||
| 731 | +{ | ||
| 732 | + g_signal_emit( GTK_WIDGET(session->widget), v3270_widget_signal[SIGNAL_MESSAGE], 0, | ||
| 733 | + (int) id, | ||
| 734 | + (gchar *) title, | ||
| 735 | + (gchar *) message, | ||
| 736 | + (gchar *) text ); | ||
| 737 | + | ||
| 738 | +} | ||
| 739 | + | ||
| 680 | static void v3270_init(v3270 *widget) | 740 | static void v3270_init(v3270 *widget) |
| 681 | { | 741 | { |
| 682 | trace("%s",__FUNCTION__); | 742 | trace("%s",__FUNCTION__); |
| @@ -708,7 +768,7 @@ static void v3270_init(v3270 *widget) | @@ -708,7 +768,7 @@ static void v3270_init(v3270 *widget) | ||
| 708 | widget->host->update_model = update_model; | 768 | widget->host->update_model = update_model; |
| 709 | widget->host->changed = changed; | 769 | widget->host->changed = changed; |
| 710 | widget->host->ctlr_done = ctlr_done; | 770 | widget->host->ctlr_done = ctlr_done; |
| 711 | - | 771 | + widget->host->message = message; |
| 712 | 772 | ||
| 713 | // Setup input method | 773 | // Setup input method |
| 714 | widget->input_method = gtk_im_multicontext_new(); | 774 | widget->input_method = gtk_im_multicontext_new(); |
src/pw3270/window.c
| @@ -128,11 +128,25 @@ | @@ -128,11 +128,25 @@ | ||
| 128 | 128 | ||
| 129 | static int popup_handler(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) | 129 | static int popup_handler(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) |
| 130 | { | 130 | { |
| 131 | + if(fmt) | ||
| 132 | + { | ||
| 133 | + gchar *text = g_strdup_vprintf(fmt,args); | ||
| 134 | + v3270_popup_message(GTK_WIDGET(widget),type,title,msg,text); | ||
| 135 | + g_free(text); | ||
| 136 | + } | ||
| 137 | + else | ||
| 138 | + { | ||
| 139 | + v3270_popup_message(GTK_WIDGET(widget),type,title,msg,NULL); | ||
| 140 | + } | ||
| 141 | +/* | ||
| 131 | GtkWidget * dialog; | 142 | GtkWidget * dialog; |
| 132 | GtkWidget * toplevel = NULL; | 143 | GtkWidget * toplevel = NULL; |
| 133 | GtkMessageType msgtype = GTK_MESSAGE_WARNING; | 144 | GtkMessageType msgtype = GTK_MESSAGE_WARNING; |
| 134 | GtkButtonsType buttons = GTK_BUTTONS_OK; | 145 | GtkButtonsType buttons = GTK_BUTTONS_OK; |
| 135 | - gchar * text = g_strdup_vprintf(fmt,args); | 146 | + gchar * text = NULL; |
| 147 | + | ||
| 148 | + if(fmt) | ||
| 149 | + text = g_strdup_vprintf(fmt,args); | ||
| 136 | 150 | ||
| 137 | if(widget && GTK_IS_WIDGET(widget)) | 151 | if(widget && GTK_IS_WIDGET(widget)) |
| 138 | toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget)); | 152 | toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget)); |
| @@ -143,23 +157,33 @@ | @@ -143,23 +157,33 @@ | ||
| 143 | buttons = GTK_BUTTONS_CLOSE; | 157 | buttons = GTK_BUTTONS_CLOSE; |
| 144 | } | 158 | } |
| 145 | 159 | ||
| 160 | + if(!title) | ||
| 161 | + title = _( "Error" ); | ||
| 162 | + | ||
| 146 | if(msg) | 163 | if(msg) |
| 147 | { | 164 | { |
| 148 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",msg); | 165 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",msg); |
| 149 | - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",text); | 166 | + |
| 167 | + if(text) | ||
| 168 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",text); | ||
| 150 | } | 169 | } |
| 151 | - else | 170 | + else if(text) |
| 152 | { | 171 | { |
| 153 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",text); | 172 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",text); |
| 154 | } | 173 | } |
| 174 | + else | ||
| 175 | + { | ||
| 176 | + dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",title); | ||
| 177 | + } | ||
| 155 | 178 | ||
| 156 | - g_free(text); | ||
| 157 | - | ||
| 158 | - gtk_window_set_title(GTK_WINDOW(dialog),title ? title : "Error"); | 179 | + if(text) |
| 180 | + g_free(text); | ||
| 159 | 181 | ||
| 182 | + gtk_window_set_title(GTK_WINDOW(dialog),title); | ||
| 183 | + gtk_widget_show_all(dialog); | ||
| 160 | gtk_dialog_run(GTK_DIALOG (dialog)); | 184 | gtk_dialog_run(GTK_DIALOG (dialog)); |
| 161 | gtk_widget_destroy(dialog); | 185 | gtk_widget_destroy(dialog); |
| 162 | - | 186 | +*/ |
| 163 | return 0; | 187 | return 0; |
| 164 | } | 188 | } |
| 165 | 189 |