Commit c687f18f62076000f52fe7a847ffaa79ee449af9

Authored by perry.werneck@gmail.com
1 parent f5a322d8

Melhorando popup de erros de comunicação (socket & cia)

@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin 18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19 * St, Fifth Floor, Boston, MA 02110-1301 USA 19 * St, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 - * Este programa está nomeado como api.h e possui 444 linhas de código. 21 + * Este programa está nomeado como api.h e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
@@ -322,10 +322,6 @@ @@ -322,10 +322,6 @@
322 322
323 LOCAL_EXTERN const struct lib3270_option * get_3270_option_table(int sz); 323 LOCAL_EXTERN const struct lib3270_option * get_3270_option_table(int sz);
324 324
325 - /* Popups */  
326 - LOCAL_EXTERN void Error(H3270 *session, const char *fmt, ...);  
327 - LOCAL_EXTERN void Warning(H3270 *session, const char *fmt, ...);  
328 - LOCAL_EXTERN void show_3270_popup_dialog(H3270 *session, PW3270_DIALOG type, const char *title, const char *msg, const char *fmt, ...);  
329 325
330 /* Set/Get screen contents */ 326 /* Set/Get screen contents */
331 #define find_field_attribute(s,a) lib3270_field_addr(s,a) 327 #define find_field_attribute(s,a) lib3270_field_addr(s,a)
@@ -347,9 +343,6 @@ @@ -347,9 +343,6 @@
347 // LOCAL_EXTERN int Get3270Socket(void); 343 // LOCAL_EXTERN int Get3270Socket(void);
348 344
349 /* Misc calls */ 345 /* Misc calls */
350 - LOCAL_EXTERN void popup_an_error(H3270 *session, const char *fmt, ...);  
351 - LOCAL_EXTERN void popup_system_error(H3270 *session, const char *title, const char *message, const char *fmt, ...);  
352 - LOCAL_EXTERN void popup_a_sockerr(H3270 *session, char *fmt, ...);  
353 346
354 #define query_3270_terminal_status(void) lib3270_get_program_message(NULL) 347 #define query_3270_terminal_status(void) lib3270_get_program_message(NULL)
355 348
@@ -447,7 +447,7 @@ static int internal_event_dispatcher(H3270 *hSession, int block) @@ -447,7 +447,7 @@ static int internal_event_dispatcher(H3270 *hSession, int block)
447 if (ns < 0) 447 if (ns < 0)
448 { 448 {
449 if (errno != EINTR) 449 if (errno != EINTR)
450 - Warning(NULL, "process_events: select() failed" ); 450 + lib3270_popup_an_errno(hSession,errno,"%s",_( "select() failed when dispatching events"));
451 #endif 451 #endif
452 return processed_any; 452 return processed_any;
453 } 453 }
1 /* 1 /*
2 - * Copyright 1999, 2000 by Paul Mattes.  
3 - * Permission to use, copy, modify, and distribute this software and its  
4 - * documentation for any purpose and without fee is hereby granted,  
5 - * provided that the above copyright notice appear in all copies and that  
6 - * both that copyright notice and this permission notice appear in  
7 - * supporting documentation.  
8 - *  
9 - * c3270, s3270 and tcl3270 are distributed in the hope that they will  
10 - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of  
11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file LICENSE  
12 - * for more details. 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.
  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 popupsc.h 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 de Mendonça)
  27 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
13 */ 30 */
14 31
15 -/* Non-display version of popupsc.h */ 32 + /* Popup calls */
  33 +
  34 + #define popup_an_errno(hSession, errn, fmt, ...) lib3270_popup_an_errno(hSession, errn, fmt, __VA_ARGS__)
  35 +
  36 + LOCAL_EXTERN void popup_an_error(H3270 *session, const char *fmt, ...) printflike(2,3);
  37 + LOCAL_EXTERN void popup_system_error(H3270 *session, const char *title, const char *message, const char *fmt, ...) printflike(4,5);
  38 + LOCAL_EXTERN void popup_a_sockerr(H3270 *session, char *fmt, ...) printflike(2,3);
16 39
17 -LIB3270_INTERNAL void popup_an_errno(H3270 *session, int errn, const char *fmt, ...);  
18 -// LIB3270_INTERNAL void action_output(const char *fmt, ...); 40 + LOCAL_EXTERN void Error(H3270 *session, const char *fmt, ...);
  41 + LOCAL_EXTERN void Warning(H3270 *session, const char *fmt, ...);
@@ -612,22 +612,6 @@ void status_untiming(H3270 *session) @@ -612,22 +612,6 @@ void status_untiming(H3270 *session)
612 session->set_timer(session,0); 612 session->set_timer(session,0);
613 } 613 }
614 614
615 -void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, ...)  
616 -{  
617 - CHECK_SESSION_HANDLE(session);  
618 -  
619 - trace("%s: title=%s msg=%s",__FUNCTION__,title,msg);  
620 -  
621 - if(!fmt)  
622 - fmt = "";  
623 -  
624 - va_list arg_ptr;  
625 - va_start(arg_ptr, fmt);  
626 - popup_handler(session,session->widget,type,title,msg,fmt,arg_ptr);  
627 - va_end(arg_ptr);  
628 -  
629 -}  
630 -  
631 static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) 615 static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg)
632 { 616 {
633 #ifdef ANDROID 617 #ifdef ANDROID
@@ -45,6 +45,7 @@ @@ -45,6 +45,7 @@
45 #include "kybdc.h" 45 #include "kybdc.h"
46 #include "3270ds.h" 46 #include "3270ds.h"
47 #include "tablesc.h" 47 #include "tablesc.h"
  48 +#include "popupsc.h"
48 49
49 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ 50 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
50 51
@@ -413,7 +413,7 @@ static union { @@ -413,7 +413,7 @@ static union {
413 } haddr; 413 } haddr;
414 socklen_t ha_len = sizeof(haddr); 414 socklen_t ha_len = sizeof(haddr);
415 415
416 -void popup_a_sockerr(H3270 *session, char *fmt, ...) 416 +void popup_a_sockerr(H3270 *hSession, char *fmt, ...)
417 { 417 {
418 #if defined(_WIN32) 418 #if defined(_WIN32)
419 const char *msg = win32_strerror(socket_errno()); 419 const char *msg = win32_strerror(socket_errno());
@@ -421,14 +421,17 @@ void popup_a_sockerr(H3270 *session, char *fmt, ...) @@ -421,14 +421,17 @@ void popup_a_sockerr(H3270 *session, char *fmt, ...)
421 const char *msg = strerror(errno); 421 const char *msg = strerror(errno);
422 #endif // WIN32 422 #endif // WIN32
423 va_list args; 423 va_list args;
424 - char buffer[4096]; 424 + char *text;
425 425
426 va_start(args, fmt); 426 va_start(args, fmt);
427 - vsnprintf(buffer, 4095, fmt, args); 427 + text = lib3270_vsprintf(fmt, args);
428 va_end(args); 428 va_end(args);
429 429
430 - popup_system_error(session, N_( "Network error" ), buffer, "%s", msg); 430 + lib3270_write_log(hSession, "3270", "Network error:\n%s\n%s",text,msg);
431 431
  432 + lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, _( "Network error" ), text, "%s", msg);
  433 +
  434 + lib3270_free(text);
432 } 435 }
433 436
434 #pragma pack(1) 437 #pragma pack(1)
@@ -3031,7 +3034,7 @@ static int non_blocking(H3270 *session, Boolean on) @@ -3031,7 +3034,7 @@ static int non_blocking(H3270 *session, Boolean on)
3031 3034
3032 if (SOCK_IOCTL(session->sock, FIONBIO, (int *) &i) < 0) 3035 if (SOCK_IOCTL(session->sock, FIONBIO, (int *) &i) < 0)
3033 { 3036 {
3034 - popup_a_sockerr(session,N_( "ioctl(%s)" ), "FIONBIO"); 3037 + popup_a_sockerr(session,N_( "Error in ioctl(%s) when setting no blocking mode" ), "FIONBIO");
3035 return -1; 3038 return -1;
3036 } 3039 }
3037 3040
@@ -3041,7 +3044,7 @@ static int non_blocking(H3270 *session, Boolean on) @@ -3041,7 +3044,7 @@ static int non_blocking(H3270 *session, Boolean on)
3041 3044
3042 if ((f = fcntl(session->sock, F_GETFL, 0)) == -1) 3045 if ((f = fcntl(session->sock, F_GETFL, 0)) == -1)
3043 { 3046 {
3044 - popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL" ); 3047 + popup_an_errno(session,errno, _( "Error in fcntl(%s) when setting non blocking mode" ), "F_GETFL" );
3045 return -1; 3048 return -1;
3046 } 3049 }
3047 3050
@@ -3052,7 +3055,7 @@ static int non_blocking(H3270 *session, Boolean on) @@ -3052,7 +3055,7 @@ static int non_blocking(H3270 *session, Boolean on)
3052 3055
3053 if (fcntl(session->sock, F_SETFL, f) < 0) 3056 if (fcntl(session->sock, F_SETFL, f) < 0)
3054 { 3057 {
3055 - popup_an_errno(session,errno, N_( "fcntl(%s)" ), "F_GETFL"); 3058 + popup_an_errno(session,errno, _( "Error in fcntl(%s) when setting non blocking mode" ), "F_SETFL");
3056 return -1; 3059 return -1;
3057 } 3060 }
3058 3061
@@ -3174,7 +3177,7 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) @@ -3174,7 +3177,7 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret)
3174 3177
3175 trace_dsn(hSession,"SSL Connect error in %s\nState: %s\nAlert: %s\n",err_buf,SSL_state_string_long(s),SSL_alert_type_string_long(ret)); 3178 trace_dsn(hSession,"SSL Connect error in %s\nState: %s\nAlert: %s\n",err_buf,SSL_state_string_long(s),SSL_alert_type_string_long(ret));
3176 3179
3177 - show_3270_popup_dialog( hSession, // H3270 *session, 3180 + lib3270_popup_dialog( hSession, // H3270 *session,
3178 PW3270_DIALOG_CRITICAL, // PW3270_DIALOG type, 3181 PW3270_DIALOG_CRITICAL, // PW3270_DIALOG type,
3179 _( "SSL Connect error" ), // Title 3182 _( "SSL Connect error" ), // Title
3180 err_buf, // Message 3183 err_buf, // Message
@@ -980,8 +980,7 @@ LIB3270_EXPORT const char * lib3270_get_revision(void) @@ -980,8 +980,7 @@ LIB3270_EXPORT const char * lib3270_get_revision(void)
980 return build_rpq_revision; 980 return build_rpq_revision;
981 } 981 }
982 982
983 -/* Pop up an error dialog, based on an error number. */  
984 -void popup_an_errno(H3270 *session, int errn, const char *fmt, ...) 983 +void lib3270_popup_an_errno(H3270 *hSession, int errn, const char *fmt, ...)
985 { 984 {
986 va_list args; 985 va_list args;
987 char * text; 986 char * text;
@@ -990,11 +989,12 @@ void popup_an_errno(H3270 *session, int errn, const char *fmt, ...) @@ -990,11 +989,12 @@ void popup_an_errno(H3270 *session, int errn, const char *fmt, ...)
990 text = lib3270_vsprintf(fmt, args); 989 text = lib3270_vsprintf(fmt, args);
991 va_end(args); 990 va_end(args);
992 991
993 - lib3270_write_log(session, "3270", "Error Popup:\n%s\nrc=%d (%s)",text,errn,strerror(errn)); 992 + lib3270_write_log(hSession, "3270", "Error Popup:\n%s\nrc=%d (%s)",text,errn,strerror(errn));
994 993
995 - Error(session,text); 994 + lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, _( "Error" ), text, "%s (rc=%d)", errn, strerror(errn));
996 995
997 lib3270_free(text); 996 lib3270_free(text);
  997 +
998 } 998 }
999 999
1000 #if defined(_WIN32) 1000 #if defined(_WIN32)