Commit e379fb019e155e8ba10ede5a11f2b9d5a441d36b

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

Incluindo opcao de trace para alertar erros no manipulador de sessão

ft_cut.c
... ... @@ -211,9 +211,8 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len)
211 211 /**
212 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 216 unsigned char * ob0 = xobuf;
218 217 unsigned char * ob = ob0;
219 218  
... ... @@ -606,7 +605,7 @@ static int xlate_getc(H3270FT *ft)
606 605 /* Expand it. */
607 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 610 else
612 611 {
... ... @@ -616,7 +615,7 @@ static int xlate_getc(H3270FT *ft)
616 615  
617 616 /* Convert it. */
618 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 620 /* Return it and buffer what's left. */
622 621 r = cbuf[0];
... ...
ft_dft.c
... ... @@ -319,7 +319,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr)
319 319  
320 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 323 if (rv == 0)
324 324 break;
325 325 ft->ft_length += l;
... ... @@ -330,7 +330,7 @@ static void dft_data_insert(H3270 *hSession, struct data_buffer *data_bufr)
330 330 len -= l;
331 331 }
332 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 334 ft->ft_length += my_length;
335 335 }
336 336  
... ... @@ -384,8 +384,8 @@ static void dft_get_request(H3270 *hSession)
384 384 /* Read a buffer's worth. */
385 385 set_dft_buffersize(hSession);
386 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 390 while (!ft->dft_eof && numbytes)
391 391 {
... ...
globals.h
... ... @@ -127,9 +127,6 @@
127 127 extern char *strtok_r(char *str, const char *sep, char **last);
128 128 #endif /*]*/
129 129  
130   -#define CHECK_SESSION_HANDLE(x) if(!x) x = &h3270;
131   -
132   -
133 130 /* types of internal actions */
134 131 enum iaction {
135 132 IA_STRING, IA_PASTE, IA_REDRAW,
... ... @@ -142,7 +139,7 @@ enum iaction {
142 139 // LIB3270_INTERNAL int COLS;
143 140 // LIB3270_INTERNAL int ROWS;
144 141  
145   -LIB3270_INTERNAL H3270 h3270;
  142 +// LIB3270_INTERNAL H3270 h3270;
146 143  
147 144 /*
148 145 #if defined(X3270_DISPLAY)
... ... @@ -346,3 +343,12 @@ LIB3270_INTERNAL void remove_input_calls(H3270 *session);
346 343  
347 344 LIB3270_INTERNAL int lib3270_sock_send(H3270 *hSession, unsigned const char *buf, int len);
348 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 +
... ...
session.c
... ... @@ -47,7 +47,7 @@
47 47  
48 48 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
49 49  
50   - H3270 h3270;
  50 + static H3270 h3270;
51 51  
52 52 /*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/
53 53  
... ... @@ -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 444 LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void)
428 445 {
429 446 return &h3270;
... ...
telnet.c
... ... @@ -3119,7 +3119,7 @@ static void ssl_init(H3270 *session)
3119 3119 /* Callback for tracing protocol negotiation. */
3120 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 3124 switch(where)
3125 3125 {
... ...