Commit 533cb8166926d570dc3ad279273fac2f4fa9d70f
1 parent
63cb8e62
Exists in
master
and in
3 other branches
Refactoring "can't connect" popup message.
Showing
14 changed files
with
202 additions
and
219 deletions
Show diff stats
lib3270.cbp
... | ... | @@ -149,6 +149,9 @@ |
149 | 149 | <Unit filename="src/core/paste.c"> |
150 | 150 | <Option compilerVar="CC" /> |
151 | 151 | </Unit> |
152 | + <Unit filename="src/core/popup.c"> | |
153 | + <Option compilerVar="CC" /> | |
154 | + </Unit> | |
152 | 155 | <Unit filename="src/core/print.c"> |
153 | 156 | <Option compilerVar="CC" /> |
154 | 157 | </Unit> |
... | ... | @@ -357,10 +360,6 @@ |
357 | 360 | <Unit filename="src/testprogram/testprogram.c"> |
358 | 361 | <Option compilerVar="CC" /> |
359 | 362 | </Unit> |
360 | - <Extensions> | |
361 | - <code_completion /> | |
362 | - <envvars /> | |
363 | - <debugger /> | |
364 | - </Extensions> | |
363 | + <Extensions /> | |
365 | 364 | </Project> |
366 | 365 | </CodeBlocks_project_file> | ... | ... |
src/core/connect.c
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | #include <trace_dsc.h> |
38 | 38 | |
39 | 39 | #include "../ssl/crl.h" |
40 | +#include "utilc.h" | |
40 | 41 | |
41 | 42 | /*---[ Implement ]-------------------------------------------------------------------------------*/ |
42 | 43 | |
... | ... | @@ -70,13 +71,39 @@ |
70 | 71 | |
71 | 72 | #endif // HAVE_LIBSSL |
72 | 73 | |
74 | + void connection_failed(H3270 *hSession, const char *message) | |
75 | + { | |
76 | + lib3270_disconnect(hSession); | |
77 | + | |
78 | + lib3270_autoptr(char) summary = lib3270_strdup_printf( | |
79 | + _( "Can't connect to %s:%s"), | |
80 | + hSession->host.current, | |
81 | + hSession->host.srvc | |
82 | + ); | |
83 | + | |
84 | + LIB3270_POPUP popup = { | |
85 | + .name = "CantConnect", | |
86 | + .title = _( "Connection failed" ), | |
87 | + .type = LIB3270_NOTIFY_INFO, | |
88 | + .summary = summary, | |
89 | + .body = message | |
90 | + }; | |
91 | + | |
92 | + if(hSession->cbk.popup_show(hSession,&popup,lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT) && !hSession->auto_reconnect_inprogress) == 0) { | |
93 | + // Schedule an automatic reconnection. | |
94 | + hSession->auto_reconnect_inprogress = 1; | |
95 | + (void) AddTimer(RECONNECT_ERR_MS, hSession, lib3270_check_for_auto_reconnect); | |
96 | + } | |
97 | + | |
98 | + } | |
99 | + | |
73 | 100 | int lib3270_allow_reconnect(const H3270 *hSession) |
74 | 101 | { |
75 | 102 | // |
76 | 103 | // Can't reconnect if already reconnecting *OR* there's an open popup |
77 | 104 | // (to avoid open more than one connect error popup). |
78 | 105 | // |
79 | - if(hSession->auto_reconnect_inprogress || hSession->popups) | |
106 | + if(hSession->auto_reconnect_inprogress) | |
80 | 107 | { |
81 | 108 | errno = EBUSY; |
82 | 109 | return 0; | ... | ... |
src/core/host.c
... | ... | @@ -66,11 +66,13 @@ |
66 | 66 | */ |
67 | 67 | int lib3270_check_for_auto_reconnect(H3270 *hSession) |
68 | 68 | { |
69 | + /* | |
69 | 70 | if(hSession->popups) |
70 | 71 | { |
71 | 72 | lib3270_write_log(hSession,"3270","Delaying auto-reconnect. There's %u pending popup(s)",(unsigned int) hSession->popups); |
72 | 73 | return 1; |
73 | 74 | } |
75 | + */ | |
74 | 76 | |
75 | 77 | if(hSession->auto_reconnect_inprogress) |
76 | 78 | { | ... | ... |
src/core/linux/connect.c
... | ... | @@ -50,6 +50,7 @@ |
50 | 50 | #include "trace_dsc.h" |
51 | 51 | #include "telnetc.h" |
52 | 52 | #include "screen.h" |
53 | +#include "utilc.h" | |
53 | 54 | |
54 | 55 | #include <lib3270/internals.h> |
55 | 56 | #include <lib3270/log.h> |
... | ... | @@ -57,7 +58,6 @@ |
57 | 58 | |
58 | 59 | /*---[ Implement ]-------------------------------------------------------------------------------*/ |
59 | 60 | |
60 | - | |
61 | 61 | static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG GNUC_UNUSED(flag), void GNUC_UNUSED(*dunno)) |
62 | 62 | { |
63 | 63 | int err; |
... | ... | @@ -83,18 +83,8 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG |
83 | 83 | } |
84 | 84 | else if(err) |
85 | 85 | { |
86 | - char buffer[4096]; | |
87 | - | |
88 | - snprintf(buffer,4095,_( "Can't connect to %s" ), lib3270_get_url(hSession) ); | |
89 | - | |
90 | - lib3270_disconnect(hSession); | |
91 | - lib3270_popup_dialog( | |
92 | - hSession, | |
93 | - LIB3270_NOTIFY_ERROR, | |
94 | - _( "Connection failed" ), | |
95 | - buffer, | |
96 | - _( "%s" ), strerror(err) | |
97 | - ); | |
86 | + lib3270_autoptr(char) body = lib3270_strdup_printf(_("%s (rc=%d)"),strerror(err),err); | |
87 | + connection_failed(hSession,body); | |
98 | 88 | return; |
99 | 89 | } |
100 | 90 | |
... | ... | @@ -176,17 +166,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG |
176 | 166 | // Connect to host |
177 | 167 | if(lib3270_run_task(hSession, background_connect, &host) || hSession->connection.sock < 0) |
178 | 168 | { |
179 | - char buffer[4096]; | |
180 | - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc); | |
181 | - | |
182 | - lib3270_popup_dialog( hSession, | |
183 | - LIB3270_NOTIFY_ERROR, | |
184 | - _( "Connection error" ), | |
185 | - buffer, | |
186 | - "%s", | |
187 | - host.message); | |
188 | - | |
189 | - lib3270_set_disconnected(hSession); | |
169 | + connection_failed(hSession,host.message); | |
190 | 170 | return errno = ENOTCONN; |
191 | 171 | } |
192 | 172 | ... | ... |
... | ... | @@ -0,0 +1,118 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | +/** | |
31 | + * @file popup.c | |
32 | + * | |
33 | + * @brief A callback based popup dialog engine. | |
34 | + * | |
35 | + */ | |
36 | + | |
37 | +#include <config.h> | |
38 | +#include <internals.h> | |
39 | +#include <lib3270.h> | |
40 | +#include <lib3270/log.h> | |
41 | + | |
42 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
43 | + | |
44 | +/// @brief Pop up an error dialog. | |
45 | +void popup_an_error(H3270 *hSession, const char *fmt, ...) | |
46 | +{ | |
47 | + | |
48 | + lib3270_autoptr(char) summary = NULL; | |
49 | + | |
50 | + if(fmt) | |
51 | + { | |
52 | + va_list args; | |
53 | + va_start(args, fmt); | |
54 | + summary = lib3270_vsprintf(fmt,args); | |
55 | + va_end(args); | |
56 | + } | |
57 | + | |
58 | + LIB3270_POPUP popup = { | |
59 | + .type = LIB3270_NOTIFY_ERROR, | |
60 | + .summary = summary | |
61 | + }; | |
62 | + | |
63 | + hSession->cbk.popup_show(hSession,&popup,0); | |
64 | + | |
65 | +} | |
66 | + | |
67 | +void popup_system_error(H3270 *hSession, const char *title, const char *summary, const char *fmt, ...) | |
68 | +{ | |
69 | + | |
70 | + lib3270_autoptr(char) body = NULL; | |
71 | + | |
72 | + if(fmt) | |
73 | + { | |
74 | + va_list args; | |
75 | + va_start(args, fmt); | |
76 | + body = lib3270_vsprintf(fmt,args); | |
77 | + va_end(args); | |
78 | + } | |
79 | + | |
80 | + LIB3270_POPUP popup = { | |
81 | + .type = LIB3270_NOTIFY_ERROR, | |
82 | + .title = title, | |
83 | + .summary = summary, | |
84 | + .body = body | |
85 | + }; | |
86 | + | |
87 | + hSession->cbk.popup_show(hSession,&popup,0); | |
88 | + | |
89 | +} | |
90 | + | |
91 | +LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
92 | +{ | |
93 | + va_list args; | |
94 | + va_start(args, fmt); | |
95 | + lib3270_popup_va(session, id, title, message, fmt, args); | |
96 | + va_end(args); | |
97 | +} | |
98 | + | |
99 | +LIB3270_EXPORT void lib3270_popup_va(H3270 *hSession, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list args) | |
100 | +{ | |
101 | + CHECK_SESSION_HANDLE(hSession); | |
102 | + | |
103 | + lib3270_autoptr(char) body = NULL; | |
104 | + | |
105 | + if(fmt) { | |
106 | + body = lib3270_vsprintf(fmt,args); | |
107 | + } | |
108 | + | |
109 | + LIB3270_POPUP popup = { | |
110 | + .type = id, | |
111 | + .title = title, | |
112 | + .summary = message, | |
113 | + .body = body | |
114 | + }; | |
115 | + | |
116 | + hSession->cbk.popup_show(hSession,&popup,0); | |
117 | + | |
118 | +} | ... | ... |
src/core/screen.c
... | ... | @@ -726,115 +726,6 @@ static void status_3270_mode(H3270 *hSession, int GNUC_UNUSED(ignored), void GNU |
726 | 726 | |
727 | 727 | } |
728 | 728 | |
729 | -/* | |
730 | -static void status_printer(H3270 *session, int on, void *dunno) | |
731 | -{ | |
732 | - set_status(session,LIB3270_FLAG_PRINTER,on); | |
733 | -} | |
734 | -*/ | |
735 | - | |
736 | -/* | |
737 | -void status_timing(H3270 GNUC_UNUSED(*session), struct timeval GNUC_UNUSED(*t0), struct timeval GNUC_UNUSED(*t1)) | |
738 | -{ | |
739 | -} | |
740 | - | |
741 | -void status_untiming(H3270 *session) | |
742 | -{ | |
743 | - CHECK_SESSION_HANDLE(session); | |
744 | - | |
745 | - if(session->cbk.set_timer) | |
746 | - session->cbk.set_timer(session,0); | |
747 | -} | |
748 | -*/ | |
749 | - | |
750 | -/* | |
751 | -static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) | |
752 | -{ | |
753 | -#ifdef ANDROID | |
754 | - char *mask = xs_buffer("%s\n",fmt); | |
755 | - __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, mask, arg); | |
756 | - lib3270_free(mask); | |
757 | -#else | |
758 | - lib3270_write_log(session,"popup","%s",title); | |
759 | - lib3270_write_log(session,"popup","%s",msg); | |
760 | - lib3270_write_va_log(session,"popup",fmt,arg); | |
761 | -#endif // ANDROID | |
762 | - return 0; | |
763 | -} | |
764 | -*/ | |
765 | - | |
766 | -void Error(H3270 *session, const char *fmt, ...) | |
767 | -{ | |
768 | - va_list arg_ptr; | |
769 | - | |
770 | - CHECK_SESSION_HANDLE(session); | |
771 | - | |
772 | - trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt); | |
773 | - | |
774 | - va_start(arg_ptr, fmt); | |
775 | - | |
776 | - session->popups++; | |
777 | - session->cbk.popup(session,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); | |
778 | - session->popups--; | |
779 | - | |
780 | - va_end(arg_ptr); | |
781 | - | |
782 | -} | |
783 | - | |
784 | -void Warning(H3270 *session, const char *fmt, ...) | |
785 | -{ | |
786 | - va_list arg_ptr; | |
787 | - | |
788 | - CHECK_SESSION_HANDLE(session); | |
789 | - | |
790 | - trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Warning",fmt); | |
791 | - | |
792 | - va_start(arg_ptr, fmt); | |
793 | - | |
794 | - session->popups++; | |
795 | - session->cbk.popup(session,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); | |
796 | - session->popups--; | |
797 | - | |
798 | - va_end(arg_ptr); | |
799 | - | |
800 | -} | |
801 | - | |
802 | -/* Pop up an error dialog. */ | |
803 | -void popup_an_error(H3270 *session, const char *fmt, ...) | |
804 | -{ | |
805 | - va_list args; | |
806 | - | |
807 | - CHECK_SESSION_HANDLE(session); | |
808 | - | |
809 | - trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt); | |
810 | - | |
811 | - va_start(args, fmt); | |
812 | - | |
813 | - session->popups++; | |
814 | - session->cbk.popup(session,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); | |
815 | - session->popups--; | |
816 | - | |
817 | - va_end(args); | |
818 | - | |
819 | -} | |
820 | - | |
821 | -void popup_system_error(H3270 *session, const char *title, const char *message, const char *fmt, ...) | |
822 | -{ | |
823 | - va_list args; | |
824 | - | |
825 | - CHECK_SESSION_HANDLE(session); | |
826 | - | |
827 | - trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message); | |
828 | - | |
829 | - va_start(args, fmt); | |
830 | - | |
831 | - session->popups++; | |
832 | - session->cbk.popup(session,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); | |
833 | - session->popups--; | |
834 | - | |
835 | - va_end(args); | |
836 | -} | |
837 | - | |
838 | 729 | void mcursor_set(H3270 *hSession,LIB3270_POINTER m) |
839 | 730 | { |
840 | 731 | if(hSession->pointer != ((unsigned short) m)) { |
... | ... | @@ -961,20 +852,3 @@ LIB3270_EXPORT int lib3270_testpattern(H3270 *hSession) |
961 | 852 | return 0; |
962 | 853 | } |
963 | 854 | |
964 | -LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
965 | -{ | |
966 | - va_list args; | |
967 | - va_start(args, fmt); | |
968 | - lib3270_popup_va(session, id, title, message, fmt, args); | |
969 | - va_end(args); | |
970 | -} | |
971 | - | |
972 | -LIB3270_EXPORT void lib3270_popup_va(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list args) | |
973 | -{ | |
974 | - CHECK_SESSION_HANDLE(session); | |
975 | - | |
976 | - session->popups++; | |
977 | - session->cbk.popup(session,id,title ? title : _( "3270 Error" ), message,fmt,args); | |
978 | - session->popups--; | |
979 | - | |
980 | -} | ... | ... |
src/core/session.c
... | ... | @@ -220,28 +220,26 @@ static void message(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(id), const char * |
220 | 220 | #endif // ANDROID |
221 | 221 | } |
222 | 222 | |
223 | -static void def_popup(H3270 *session, LIB3270_NOTIFY GNUC_UNUSED(type), const char *title, const char *msg, const char *fmt, va_list arg) | |
223 | +static void def_popup(H3270 *hSession, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) | |
224 | 224 | { |
225 | -#ifdef ANDROID | |
226 | - char *mask = xs_buffer("%s\n",fmt); | |
227 | - __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, mask, arg); | |
228 | - lib3270_free(mask); | |
229 | -#else | |
230 | - lib3270_write_log(session,"popup","%s",title); | |
231 | - lib3270_write_log(session,"popup","%s",msg); | |
232 | - lib3270_write_va_log(session,"popup",fmt,arg); | |
233 | -#endif // ANDROID | |
225 | + lib3270_popup_va(hSession,type,title,msg,fmt,args); | |
234 | 226 | } |
235 | 227 | |
236 | 228 | static int def_popup_show(H3270 *hSession, const LIB3270_POPUP *popup, unsigned char GNUC_UNUSED wait) |
237 | 229 | { |
238 | - lib3270_popup_dialog( | |
239 | - hSession, | |
240 | - popup->type, | |
230 | + const char * text[] = { | |
241 | 231 | popup->title, |
242 | 232 | popup->summary, |
243 | - "%s", popup->body | |
244 | - ); | |
233 | + popup->body | |
234 | + }; | |
235 | + | |
236 | + size_t ix; | |
237 | + | |
238 | + for(ix = 0; ix < (sizeof(text)/sizeof(text[0])); ix++) | |
239 | + { | |
240 | + lib3270_write_log(hSession,"popup","%s",text[ix]); | |
241 | + } | |
242 | + | |
245 | 243 | return ENOTSUP; |
246 | 244 | } |
247 | 245 | ... | ... |
src/core/telnet.c
... | ... | @@ -859,7 +859,12 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) |
859 | 859 | } |
860 | 860 | else |
861 | 861 | { |
862 | - Warning(hSession, _( "EOR received when not in 3270 mode, ignored." )); | |
862 | + lib3270_popup_dialog( | |
863 | + hSession, | |
864 | + LIB3270_NOTIFY_WARNING,_("Warning"), | |
865 | + _( "EOR received when not in 3270 mode, ignored." ), | |
866 | + NULL | |
867 | + ); | |
863 | 868 | } |
864 | 869 | trace_dsn(hSession,"RCVD EOR\n"); |
865 | 870 | hSession->ibptr = hSession->ibuf; | ... | ... |
src/core/toggles/init.c
... | ... | @@ -98,7 +98,7 @@ static void toggle_keepalive(H3270 *session, const struct lib3270_toggle GNUC_UN |
98 | 98 | |
99 | 99 | static void toggle_connect(H3270 *hSession, const struct lib3270_toggle *toggle, LIB3270_TOGGLE_TYPE tt) |
100 | 100 | { |
101 | - if(tt != LIB3270_TOGGLE_TYPE_INITIAL && lib3270_is_disconnected(hSession) && !hSession->popups && toggle->value) | |
101 | + if(tt != LIB3270_TOGGLE_TYPE_INITIAL && lib3270_is_disconnected(hSession) && toggle->value) | |
102 | 102 | { |
103 | 103 | if(lib3270_reconnect(hSession,0)) |
104 | 104 | lib3270_write_log(hSession,"3270","Auto-connect fails: %s",strerror(errno)); | ... | ... |
src/core/util.c
... | ... | @@ -56,7 +56,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) |
56 | 56 | #if defined(HAVE_VASPRINTF) |
57 | 57 | |
58 | 58 | if(vasprintf(&r, fmt, args) < 0 || !r) |
59 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
59 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
60 | 60 | |
61 | 61 | #else |
62 | 62 | |
... | ... | @@ -66,7 +66,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) |
66 | 66 | nc = vsnprintf(buf, sizeof(buf), fmt, args); |
67 | 67 | if(nc < 0) |
68 | 68 | { |
69 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
69 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
70 | 70 | } |
71 | 71 | else if (nc < sizeof(buf)) |
72 | 72 | { |
... | ... | @@ -78,7 +78,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args) |
78 | 78 | { |
79 | 79 | r = lib3270_malloc(nc + 1); |
80 | 80 | if(vsnprintf(r, nc, fmt, args) < 0) |
81 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
81 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
82 | 82 | |
83 | 83 | } |
84 | 84 | |
... | ... | @@ -115,9 +115,10 @@ char * xs_buffer(const char *fmt, ...) |
115 | 115 | return r; |
116 | 116 | } |
117 | 117 | |
118 | -/* Common uses of xs_buffer. */ | |
119 | -void | |
120 | -xs_warning(const char *fmt, ...) | |
118 | +// Common uses of xs_buffer. | |
119 | + | |
120 | +/* | |
121 | +void xs_warning(const char *fmt, ...) | |
121 | 122 | { |
122 | 123 | va_list args; |
123 | 124 | char *r; |
... | ... | @@ -125,12 +126,11 @@ xs_warning(const char *fmt, ...) |
125 | 126 | va_start(args, fmt); |
126 | 127 | r = lib3270_vsprintf(fmt, args); |
127 | 128 | va_end(args); |
128 | - Warning(NULL,r); | |
129 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_WARNING,_("Warning"),r,NULL); | |
129 | 130 | lib3270_free(r); |
130 | 131 | } |
131 | 132 | |
132 | -void | |
133 | -xs_error(const char *fmt, ...) | |
133 | +void xs_error(const char *fmt, ...) | |
134 | 134 | { |
135 | 135 | va_list args; |
136 | 136 | char *r; |
... | ... | @@ -138,9 +138,10 @@ xs_error(const char *fmt, ...) |
138 | 138 | va_start(args, fmt); |
139 | 139 | r = lib3270_vsprintf(fmt, args); |
140 | 140 | va_end(args); |
141 | - Error(NULL,r); | |
141 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Error"),r,NULL); | |
142 | 142 | lib3270_free(r); |
143 | 143 | } |
144 | +*/ | |
144 | 145 | |
145 | 146 | /** |
146 | 147 | * @brief Expands a character in the manner of "cat -v". |
... | ... | @@ -318,7 +319,7 @@ LIB3270_EXPORT void * lib3270_realloc(void *p, int len) |
318 | 319 | { |
319 | 320 | p = realloc(p, len); |
320 | 321 | if(!p) |
321 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
322 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
322 | 323 | return p; |
323 | 324 | } |
324 | 325 | |
... | ... | @@ -334,7 +335,7 @@ LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr) |
334 | 335 | if(ptr) |
335 | 336 | memset(ptr,0,sz); |
336 | 337 | else |
337 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
338 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
338 | 339 | |
339 | 340 | return ptr; |
340 | 341 | } |
... | ... | @@ -346,7 +347,7 @@ LIB3270_EXPORT void * lib3270_malloc(int len) |
346 | 347 | r = malloc(len); |
347 | 348 | if (r == (char *)NULL) |
348 | 349 | { |
349 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
350 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
350 | 351 | return 0; |
351 | 352 | } |
352 | 353 | |
... | ... | @@ -361,7 +362,7 @@ LIB3270_EXPORT void * lib3270_strdup(const char *str) |
361 | 362 | r = strdup(str); |
362 | 363 | if (r == (char *)NULL) |
363 | 364 | { |
364 | - Error(NULL,"Out of memory in %s",__FUNCTION__); | |
365 | + lib3270_popup_dialog(lib3270_get_default_session_handle(),LIB3270_NOTIFY_ERROR,_("Internal error"),"Out of memory",NULL); | |
365 | 366 | return 0; |
366 | 367 | } |
367 | 368 | ... | ... |
src/core/windows/connect.c
... | ... | @@ -83,17 +83,9 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG |
83 | 83 | } |
84 | 84 | else if(err) |
85 | 85 | { |
86 | - char buffer[4096]; | |
87 | - snprintf(buffer,4095,_( "Can't connect to %s" ), lib3270_get_url(hSession) ); | |
86 | + lib3270_autoptr(char) body = lib3270_strdup_printf(_("%s (rc=%d)"),strerror(err),err); | |
88 | 87 | |
89 | - lib3270_disconnect(hSession); | |
90 | - lib3270_popup_dialog( hSession, | |
91 | - LIB3270_NOTIFY_ERROR, | |
92 | - _( "Connection failed" ), | |
93 | - buffer, | |
94 | - _( "%s (rc=%d)"), strerror(err), err | |
95 | - ); | |
96 | - trace("%s",__FUNCTION__); | |
88 | + connection_failed(hSession,body); | |
97 | 89 | return; |
98 | 90 | } |
99 | 91 | |
... | ... | @@ -229,10 +221,10 @@ int net_reconnect(H3270 *hSession, int seconds) |
229 | 221 | |
230 | 222 | if(lib3270_run_task(hSession, background_connect, &host) || hSession->connection.sock < 0) |
231 | 223 | { |
232 | - lib3270_autoptr(char) message = lib3270_strdup_printf(_( "Can't connect to %s"), lib3270_get_url(hSession)); | |
233 | - | |
234 | 224 | if(host.message) |
235 | 225 | { |
226 | + // Have windows message, convert charset. | |
227 | + | |
236 | 228 | char msg[4096]; |
237 | 229 | strncpy(msg,host.message,4095); |
238 | 230 | |
... | ... | @@ -289,24 +281,12 @@ int net_reconnect(H3270 *hSession, int seconds) |
289 | 281 | } |
290 | 282 | #endif // HAVE_ICONV |
291 | 283 | |
292 | - lib3270_popup_dialog( hSession, | |
293 | - LIB3270_NOTIFY_ERROR, | |
294 | - _( "Connection error" ), | |
295 | - message, | |
296 | - "%s (rc=%d)", | |
297 | - msg, | |
298 | - host.rc | |
299 | - ); | |
284 | + connection_failed(hSession,msg); | |
300 | 285 | |
301 | 286 | } |
302 | 287 | else |
303 | 288 | { |
304 | - lib3270_popup_dialog( hSession, | |
305 | - LIB3270_NOTIFY_ERROR, | |
306 | - _( "Connection error" ), | |
307 | - message, | |
308 | - "%s", | |
309 | - NULL); | |
289 | + connection_failed(hSession,NULL); | |
310 | 290 | } |
311 | 291 | |
312 | 292 | lib3270_set_disconnected(hSession); | ... | ... |
src/include/internals.h
... | ... | @@ -655,8 +655,6 @@ struct _h3270 |
655 | 655 | void * except; |
656 | 656 | } xio; |
657 | 657 | |
658 | - size_t popups; ///< @brief Count open popups. | |
659 | - | |
660 | 658 | #ifdef HAVE_LIBSSL |
661 | 659 | /// @brief SSL Data. |
662 | 660 | struct |
... | ... | @@ -753,6 +751,7 @@ LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block |
753 | 751 | |
754 | 752 | LIB3270_INTERNAL int do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect); |
755 | 753 | |
754 | +LIB3270_INTERNAL void connection_failed(H3270 *hSession, const char *message); | |
756 | 755 | |
757 | 756 | /** |
758 | 757 | * @brief Called from timer to attempt an automatic reconnection. |
... | ... | @@ -840,7 +839,6 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); |
840 | 839 | */ |
841 | 840 | LIB3270_INTERNAL void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg); |
842 | 841 | |
843 | - | |
844 | 842 | #endif |
845 | 843 | |
846 | 844 | /// @brief Clear element at adress. |
... | ... | @@ -866,4 +864,3 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); |
866 | 864 | |
867 | 865 | /// @brief Fire CState change. |
868 | 866 | LIB3270_INTERNAL int lib3270_set_cstate(H3270 *hSession, LIB3270_CSTATE cstate); |
869 | - | ... | ... |
src/include/lib3270/popup.h
... | ... | @@ -106,7 +106,7 @@ |
106 | 106 | * @brief Auto cleanup method (for use with lib3270_autoptr). |
107 | 107 | * |
108 | 108 | */ |
109 | - LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr); | |
109 | + LIB3270_EXPORT void lib3270_autoptr_cleanup_LIB3270_POPUP(LIB3270_POPUP **ptr); | |
110 | 110 | |
111 | 111 | #ifdef __cplusplus |
112 | 112 | } | ... | ... |
src/ssl/notify.c
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 | #include <config.h> |
37 | 37 | #include <internals.h> |
38 | 38 | #include <lib3270/log.h> |
39 | +#include <lib3270/popup.h> | |
39 | 40 | |
40 | 41 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
41 | 42 | |
... | ... | @@ -154,8 +155,9 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAG |
154 | 155 | |
155 | 156 | void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg) { |
156 | 157 | |
157 | - lib3270_autoptr(LIB3270_POPUP) * popup = translate_ssl_error_message(msg,0); | |
158 | + LIB3270_POPUP * popup = translate_ssl_error_message(msg,0); | |
158 | 159 | hSession->cbk.popup_show(hSession,popup,0); |
160 | + lib3270_free(popup); | |
159 | 161 | |
160 | 162 | } |
161 | 163 | ... | ... |