From e379fb019e155e8ba10ede5a11f2b9d5a441d36b Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 6 Aug 2012 19:48:06 +0000 Subject: [PATCH] Incluindo opcao de trace para alertar erros no manipulador de sessão --- ft_cut.c | 7 +++---- ft_dft.c | 8 ++++---- globals.h | 14 ++++++++++---- session.c | 19 ++++++++++++++++++- telnet.c | 2 +- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/ft_cut.c b/ft_cut.c index 37ef118..a8ac0b6 100644 --- a/ft_cut.c +++ b/ft_cut.c @@ -211,9 +211,8 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) /** * Convert a buffer for downloading (local->host). */ -static int download_convert(unsigned const char *buf, unsigned len, unsigned char *xobuf) +static int download_convert(H3270FT *ft, unsigned const char *buf, unsigned len, unsigned char *xobuf) { - H3270FT * ft = get_ft_handle(&h3270); unsigned char * ob0 = xobuf; unsigned char * ob = ob0; @@ -606,7 +605,7 @@ static int xlate_getc(H3270FT *ft) /* Expand it. */ if (ft->ascii_flag && ft->cr_flag && !ft->ft_last_cr && c == '\n') { - nc = download_convert((unsigned const char *)"\r", 1, cbuf); + nc = download_convert(ft,(unsigned const char *)"\r", 1, cbuf); } else { @@ -616,7 +615,7 @@ static int xlate_getc(H3270FT *ft) /* Convert it. */ cc = (unsigned char)c; - nc += download_convert(&cc, 1, &cbuf[nc]); + nc += download_convert(ft,&cc, 1, &cbuf[nc]); /* Return it and buffer what's left. */ r = cbuf[0]; diff --git a/ft_dft.c b/ft_dft.c index a370dfa..53a20a2 100644 --- a/ft_dft.c +++ b/ft_dft.c @@ -319,7 +319,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) if (l) { - rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); + rv = fwrite(s, l, (size_t)1,ft->local_file); if (rv == 0) break; ft->ft_length += l; @@ -330,7 +330,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) len -= l; } } else { - rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); + rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ft->local_file); ft->ft_length += my_length; } @@ -384,8 +384,8 @@ static void dft_get_request(H3270 *hSession) /* Read a buffer's worth. */ set_dft_buffersize(hSession); space3270out(hSession,hSession->dft_buffersize); - numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ - bufptr = h3270.obuf + 17; + numbytes = hSession->dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ + bufptr = hSession->obuf + 17; while (!ft->dft_eof && numbytes) { diff --git a/globals.h b/globals.h index 3764423..5abd741 100644 --- a/globals.h +++ b/globals.h @@ -127,9 +127,6 @@ extern char *strtok_r(char *str, const char *sep, char **last); #endif /*]*/ -#define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270; - - /* types of internal actions */ enum iaction { IA_STRING, IA_PASTE, IA_REDRAW, @@ -142,7 +139,7 @@ enum iaction { // LIB3270_INTERNAL int COLS; // LIB3270_INTERNAL int ROWS; -LIB3270_INTERNAL H3270 h3270; +// LIB3270_INTERNAL H3270 h3270; /* #if defined(X3270_DISPLAY) @@ -346,3 +343,12 @@ LIB3270_INTERNAL void remove_input_calls(H3270 *session); LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); + +#if defined(DEBUG) + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__); + LIB3270_INTERNAL void check_session_handle(H3270 **hSession, const char *fname); +#else + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x); + LIB3270_INTERNAL void check_session_handle(H3270 **hSession); +#endif // DEBUG + diff --git a/session.c b/session.c index 7a303a0..0a8fa84 100644 --- a/session.c +++ b/session.c @@ -47,7 +47,7 @@ /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ - H3270 h3270; + static H3270 h3270; /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ @@ -424,6 +424,23 @@ static int parse_model_number(H3270 *session, const char *m) } +#if defined(DEBUG) +void check_session_handle(H3270 **hSession, const char *fname) +#else +void check_session_handle(H3270 **hSession) +#endif // DEBUG +{ + if(*hSession) + return; + +#ifdef DEBUG + trace("** %s called with hSession == NULL",fname); +#endif + + *hSession = &h3270; +} + + LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) { return &h3270; diff --git a/telnet.c b/telnet.c index 9515564..f11c071 100644 --- a/telnet.c +++ b/telnet.c @@ -3119,7 +3119,7 @@ static void ssl_init(H3270 *session) /* Callback for tracing protocol negotiation. */ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) { - H3270 *hSession = &h3270; // TODO: Find a better way! + H3270 *hSession = lib3270_get_default_session_handle(); // TODO: Find a better way! switch(where) { -- libgit2 0.21.2