Commit ac9261ce278c09f004368ba74fd16c02576e6867
1 parent
528adbf8
Exists in
master
and in
5 other branches
Incluindo opcao de trace para alertar erros no manipulador de sessão
Showing
5 changed files
with
36 additions
and
14 deletions
Show diff stats
src/lib3270/ft_cut.c
@@ -211,9 +211,8 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | @@ -211,9 +211,8 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) | ||
211 | /** | 211 | /** |
212 | * Convert a buffer for downloading (local->host). | 212 | * Convert a buffer for downloading (local->host). |
213 | */ | 213 | */ |
214 | -static int download_convert(unsigned const char *buf, unsigned len, unsigned char *xobuf) | 214 | +static int download_convert(H3270FT *ft, unsigned const char *buf, unsigned len, unsigned char *xobuf) |
215 | { | 215 | { |
216 | - H3270FT * ft = get_ft_handle(&h3270); | ||
217 | unsigned char * ob0 = xobuf; | 216 | unsigned char * ob0 = xobuf; |
218 | unsigned char * ob = ob0; | 217 | unsigned char * ob = ob0; |
219 | 218 | ||
@@ -606,7 +605,7 @@ static int xlate_getc(H3270FT *ft) | @@ -606,7 +605,7 @@ static int xlate_getc(H3270FT *ft) | ||
606 | /* Expand it. */ | 605 | /* Expand it. */ |
607 | if (ft->ascii_flag && ft->cr_flag && !ft->ft_last_cr && c == '\n') | 606 | if (ft->ascii_flag && ft->cr_flag && !ft->ft_last_cr && c == '\n') |
608 | { | 607 | { |
609 | - nc = download_convert((unsigned const char *)"\r", 1, cbuf); | 608 | + nc = download_convert(ft,(unsigned const char *)"\r", 1, cbuf); |
610 | } | 609 | } |
611 | else | 610 | else |
612 | { | 611 | { |
@@ -616,7 +615,7 @@ static int xlate_getc(H3270FT *ft) | @@ -616,7 +615,7 @@ static int xlate_getc(H3270FT *ft) | ||
616 | 615 | ||
617 | /* Convert it. */ | 616 | /* Convert it. */ |
618 | cc = (unsigned char)c; | 617 | cc = (unsigned char)c; |
619 | - nc += download_convert(&cc, 1, &cbuf[nc]); | 618 | + nc += download_convert(ft,&cc, 1, &cbuf[nc]); |
620 | 619 | ||
621 | /* Return it and buffer what's left. */ | 620 | /* Return it and buffer what's left. */ |
622 | r = cbuf[0]; | 621 | r = cbuf[0]; |
src/lib3270/ft_dft.c
@@ -319,7 +319,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -319,7 +319,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
319 | 319 | ||
320 | if (l) | 320 | if (l) |
321 | { | 321 | { |
322 | - rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); | 322 | + rv = fwrite(s, l, (size_t)1,ft->local_file); |
323 | if (rv == 0) | 323 | if (rv == 0) |
324 | break; | 324 | break; |
325 | ft->ft_length += l; | 325 | ft->ft_length += l; |
@@ -330,7 +330,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | @@ -330,7 +330,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr) | ||
330 | len -= l; | 330 | len -= l; |
331 | } | 331 | } |
332 | } else { | 332 | } else { |
333 | - rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); | 333 | + rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ft->local_file); |
334 | ft->ft_length += my_length; | 334 | ft->ft_length += my_length; |
335 | } | 335 | } |
336 | 336 | ||
@@ -384,8 +384,8 @@ static void dft_get_request(H3270 *hSession) | @@ -384,8 +384,8 @@ static void dft_get_request(H3270 *hSession) | ||
384 | /* Read a buffer's worth. */ | 384 | /* Read a buffer's worth. */ |
385 | set_dft_buffersize(hSession); | 385 | set_dft_buffersize(hSession); |
386 | space3270out(hSession,hSession->dft_buffersize); | 386 | space3270out(hSession,hSession->dft_buffersize); |
387 | - numbytes = h3270.dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ | ||
388 | - bufptr = h3270.obuf + 17; | 387 | + numbytes = hSession->dft_buffersize - 27; /* always read 5 bytes less than we're allowed */ |
388 | + bufptr = hSession->obuf + 17; | ||
389 | 389 | ||
390 | while (!ft->dft_eof && numbytes) | 390 | while (!ft->dft_eof && numbytes) |
391 | { | 391 | { |
src/lib3270/globals.h
@@ -127,9 +127,6 @@ | @@ -127,9 +127,6 @@ | ||
127 | extern char *strtok_r(char *str, const char *sep, char **last); | 127 | extern char *strtok_r(char *str, const char *sep, char **last); |
128 | #endif /*]*/ | 128 | #endif /*]*/ |
129 | 129 | ||
130 | -#define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270; | ||
131 | - | ||
132 | - | ||
133 | /* types of internal actions */ | 130 | /* types of internal actions */ |
134 | enum iaction { | 131 | enum iaction { |
135 | IA_STRING, IA_PASTE, IA_REDRAW, | 132 | IA_STRING, IA_PASTE, IA_REDRAW, |
@@ -142,7 +139,7 @@ enum iaction { | @@ -142,7 +139,7 @@ enum iaction { | ||
142 | // LIB3270_INTERNAL int COLS; | 139 | // LIB3270_INTERNAL int COLS; |
143 | // LIB3270_INTERNAL int ROWS; | 140 | // LIB3270_INTERNAL int ROWS; |
144 | 141 | ||
145 | -LIB3270_INTERNAL H3270 h3270; | 142 | +// LIB3270_INTERNAL H3270 h3270; |
146 | 143 | ||
147 | /* | 144 | /* |
148 | #if defined(X3270_DISPLAY) | 145 | #if defined(X3270_DISPLAY) |
@@ -346,3 +343,12 @@ LIB3270_INTERNAL void remove_input_calls(H3270 *session); | @@ -346,3 +343,12 @@ LIB3270_INTERNAL void remove_input_calls(H3270 *session); | ||
346 | 343 | ||
347 | LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); | 344 | LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len); |
348 | LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); | 345 | LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); |
346 | + | ||
347 | +#if defined(DEBUG) | ||
348 | + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__); | ||
349 | + LIB3270_INTERNAL void check_session_handle(H3270 **hSession, const char *fname); | ||
350 | +#else | ||
351 | + #define CHECK_SESSION_HANDLE(x) check_session_handle(&x); | ||
352 | + LIB3270_INTERNAL void check_session_handle(H3270 **hSession); | ||
353 | +#endif // DEBUG | ||
354 | + |
src/lib3270/session.c
@@ -47,7 +47,7 @@ | @@ -47,7 +47,7 @@ | ||
47 | 47 | ||
48 | /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ | 48 | /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ |
49 | 49 | ||
50 | - H3270 h3270; | 50 | + static H3270 h3270; |
51 | 51 | ||
52 | /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ | 52 | /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ |
53 | 53 | ||
@@ -424,6 +424,23 @@ static int parse_model_number(H3270 *session, const char *m) | @@ -424,6 +424,23 @@ static int parse_model_number(H3270 *session, const char *m) | ||
424 | 424 | ||
425 | } | 425 | } |
426 | 426 | ||
427 | +#if defined(DEBUG) | ||
428 | +void check_session_handle(H3270 **hSession, const char *fname) | ||
429 | +#else | ||
430 | +void check_session_handle(H3270 **hSession) | ||
431 | +#endif // DEBUG | ||
432 | +{ | ||
433 | + if(*hSession) | ||
434 | + return; | ||
435 | + | ||
436 | +#ifdef DEBUG | ||
437 | + trace("** %s called with hSession == NULL",fname); | ||
438 | +#endif | ||
439 | + | ||
440 | + *hSession = &h3270; | ||
441 | +} | ||
442 | + | ||
443 | + | ||
427 | LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) | 444 | LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) |
428 | { | 445 | { |
429 | return &h3270; | 446 | return &h3270; |
src/lib3270/telnet.c
@@ -3119,7 +3119,7 @@ static void ssl_init(H3270 *session) | @@ -3119,7 +3119,7 @@ static void ssl_init(H3270 *session) | ||
3119 | /* Callback for tracing protocol negotiation. */ | 3119 | /* Callback for tracing protocol negotiation. */ |
3120 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) | 3120 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) |
3121 | { | 3121 | { |
3122 | - H3270 *hSession = &h3270; // TODO: Find a better way! | 3122 | + H3270 *hSession = lib3270_get_default_session_handle(); // TODO: Find a better way! |
3123 | 3123 | ||
3124 | switch(where) | 3124 | switch(where) |
3125 | { | 3125 | { |